2874 - Edit time entry direction
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2021-06-17 15:09:04 +02:00
parent cf1fde6892
commit bb80621890
14 changed files with 339 additions and 128 deletions

View File

@ -1,6 +1,12 @@
<div
ng-transclude="prepend"
class="prepend"></div>
<div ng-transclude></div> <div ng-transclude></div>
<div
ng-transclude="append"
class="append"></div>
<vn-icon <vn-icon
ng-click="$ctrl.onRemove()" ng-click="$ctrl.onRemove($event)"
ng-if="$ctrl.removable" ng-if="$ctrl.removable"
icon="cancel" icon="cancel"
tabindex="0"> tabindex="0">

View File

@ -3,16 +3,19 @@ import Component from '../../lib/component';
import './style.scss'; import './style.scss';
export default class Chip extends Component { export default class Chip extends Component {
onRemove() { onRemove($event) {
if (!this.disabled) this.emit('remove'); if (!this.disabled) this.emit('remove', {$event});
} }
} }
Chip.$inject = ['$element', '$scope', '$transclude']; Chip.$inject = ['$element', '$scope', '$transclude'];
ngModule.vnComponent('vnChip', { ngModule.vnComponent('vnChip', {
template: require('./index.html'), template: require('./index.html'),
transclude: {
prepend: '?prepend',
append: '?append'
},
controller: Chip, controller: Chip,
transclude: true,
bindings: { bindings: {
disabled: '<?', disabled: '<?',
removable: '<?' removable: '<?'

View File

@ -1,4 +1,5 @@
@import "variables"; @import "variables";
@import "effects";
vn-chip { vn-chip {
border-radius: 16px; border-radius: 16px;
@ -24,25 +25,47 @@ vn-chip {
&.transparent { &.transparent {
background-color: transparent; background-color: transparent;
} }
&.colored { &.colored,
&.colored.clickable:hover,
&.colored.clickable:focus {
background-color: $color-main; background-color: $color-main;
color: $color-font-bg; color: $color-font-bg;
} }
&.notice {
background-color: $color-notice-medium &.notice,
&.notice.clickable:hover,
&.notice.clickable:focus {
background-color: $color-notice-medium;
} }
&.success { &.success,
&.success.clickable:hover,
&.success.clickable:focus {
background-color: $color-success-medium; background-color: $color-success-medium;
} }
&.warning { &.warning,
&.warning.clickable:hover,
&.warning.clickable:focus {
background-color: $color-main-medium; background-color: $color-main-medium;
} }
&.alert { &.alert,
&.alert.clickable:hover,
&.alert.clickable:focus {
background-color: $color-alert-medium; background-color: $color-alert-medium;
} }
&.message { &.message,
&.message.clickable:hover,
&.message.clickable:focus {
color: $color-font-dark; color: $color-font-dark;
background-color: $color-bg-dark background-color: $color-bg-dark;
}
&.clickable {
@extend %clickable;
opacity: 0.8;
&:hover,
&:focus {
opacity: 1;
}
} }
& > div { & > div {
@ -75,6 +98,20 @@ vn-chip {
opacity: 1; opacity: 1;
} }
} }
& > .prepend {
padding: 0 5px;
padding-right: 0;
&:empty {display:none;}
}
& > .append {
padding: 0 5px;
padding-left: 0;
&:empty {display:none;}
}
} }
vn-avatar { vn-avatar {

View File

@ -5,38 +5,54 @@ module.exports = Self => {
description: 'Adds a new hour registry', description: 'Adds a new hour registry',
accessType: 'WRITE', accessType: 'WRITE',
accepts: [{ accepts: [{
arg: 'data', arg: 'id',
type: 'object', type: 'number',
required: true, description: 'The worker id',
description: 'workerFk, timed', http: {source: 'path'}
http: {source: 'body'} },
{
arg: 'timed',
type: 'date',
required: true
},
{
arg: 'direction',
type: 'string',
required: true
}], }],
returns: [{ returns: [{
type: 'Object', type: 'Object',
root: true root: true
}], }],
http: { http: {
path: `/addTimeEntry`, path: `/:id/addTimeEntry`,
verb: 'POST' verb: 'POST'
} }
}); });
Self.addTimeEntry = async(ctx, data) => { Self.addTimeEntry = async(ctx, workerId, options) => {
const Worker = Self.app.models.Worker; const models = Self.app.models;
const myUserId = ctx.req.accessToken.userId; const args = ctx.args;
const myWorker = await Worker.findOne({where: {userFk: myUserId}}); const currentUserId = ctx.req.accessToken.userId;
const isSubordinate = await Worker.isSubordinate(ctx, data.workerFk);
const isTeamBoss = await Self.app.models.Account.hasRole(myUserId, 'teamBoss');
if (isSubordinate === false || (isSubordinate && myWorker.id == data.workerFk && !isTeamBoss)) let myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const isSubordinate = await models.Worker.isSubordinate(ctx, workerId, myOptions);
const isTeamBoss = await models.Account.hasRole(currentUserId, 'teamBoss', myOptions);
const isHimself = currentUserId == workerId;
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
throw new UserError(`You don't have enough privileges`); throw new UserError(`You don't have enough privileges`);
const subordinate = await Worker.findById(data.workerFk); const timed = new Date(args.timed);
const timed = new Date(data.timed);
let [result] = await Self.rawSql('SELECT vn.workerTimeControl_add(?, ?, ?, ?) AS id', [ return models.WorkerTimeControl.create({
subordinate.userFk, null, timed, true]); userFk: workerId,
direction: args.direction,
return result; timed: timed,
manual: true
}, myOptions);
}; };
}; };

View File

@ -21,21 +21,24 @@ module.exports = Self => {
} }
}); });
Self.deleteTimeEntry = async(ctx, id) => { Self.deleteTimeEntry = async(ctx, id, options) => {
const currentUserId = ctx.req.accessToken.userId; const currentUserId = ctx.req.accessToken.userId;
const workerModel = Self.app.models.Worker; const models = Self.app.models;
const targetTimeEntry = await Self.findById(id); let myOptions = {};
const isSubordinate = await workerModel.isSubordinate(ctx, targetTimeEntry.userFk);
const isTeamBoss = await Self.app.models.Account.hasRole(currentUserId, 'teamBoss'); if (typeof options == 'object')
Object.assign(myOptions, options);
const targetTimeEntry = await Self.findById(id, null, myOptions);
const isSubordinate = await models.Worker.isSubordinate(ctx, targetTimeEntry.userFk, myOptions);
const isTeamBoss = await models.Account.hasRole(currentUserId, 'teamBoss', myOptions);
const isHimself = currentUserId == targetTimeEntry.userFk; const isHimself = currentUserId == targetTimeEntry.userFk;
const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss); if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
if (notAllowed)
throw new UserError(`You don't have enough privileges`); throw new UserError(`You don't have enough privileges`);
return Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [ return Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [
targetTimeEntry.userFk, targetTimeEntry.timed]); targetTimeEntry.userFk, targetTimeEntry.timed], myOptions);
}; };
}; };

View File

@ -1,5 +1,6 @@
const app = require('vn-loopback/server/server'); const app = require('vn-loopback/server/server');
const LoopBackContext = require('loopback-context'); const LoopBackContext = require('loopback-context');
const models = app.models;
describe('workerTimeControl add/delete timeEntry()', () => { describe('workerTimeControl add/delete timeEntry()', () => {
const HHRRId = 37; const HHRRId = 37;
@ -12,19 +13,6 @@ describe('workerTimeControl add/delete timeEntry()', () => {
}; };
let ctx = {req: activeCtx}; let ctx = {req: activeCtx};
let timeEntry;
let createdTimeEntry;
afterEach(async() => {
if (createdTimeEntry) {
try {
await app.models.WorkerTimeControl.destroyById(createdTimeEntry.id);
} catch (error) {
console.error(error);
}
}
});
beforeAll(() => { beforeAll(() => {
spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({ spyOn(LoopBackContext, 'getCurrentContext').and.returnValue({
active: activeCtx active: activeCtx
@ -33,14 +21,13 @@ describe('workerTimeControl add/delete timeEntry()', () => {
it('should fail to add a time entry if the target user is not a subordinate', async() => { it('should fail to add a time entry if the target user is not a subordinate', async() => {
activeCtx.accessToken.userId = employeeId; activeCtx.accessToken.userId = employeeId;
const workerId = 2;
let error; let error;
let data = {
workerFk: 2,
timed: new Date()
};
try { try {
await app.models.WorkerTimeControl.addTimeEntry(ctx, data); ctx.args = {timed: new Date(), direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
} catch (e) { } catch (e) {
error = e; error = e;
} }
@ -52,14 +39,12 @@ describe('workerTimeControl add/delete timeEntry()', () => {
it('should fail to add if the current and the target user are the same and is not team boss', async() => { it('should fail to add if the current and the target user are the same and is not team boss', async() => {
activeCtx.accessToken.userId = employeeId; activeCtx.accessToken.userId = employeeId;
const workerId = employeeId;
let error; let error;
let data = {
workerFk: 1,
timed: new Date()
};
try { try {
await app.models.WorkerTimeControl.addTimeEntry(ctx, data); ctx.args = {timed: new Date(), direction: 'in'};
await models.WorkerTimeControl.addTimeEntry(ctx, workerId);
} catch (e) { } catch (e) {
error = e; error = e;
} }
@ -71,41 +56,49 @@ describe('workerTimeControl add/delete timeEntry()', () => {
it('should add if the current user is team boss and the target user is a himself', async() => { it('should add if the current user is team boss and the target user is a himself', async() => {
activeCtx.accessToken.userId = teamBossId; activeCtx.accessToken.userId = teamBossId;
let todayAtSix = new Date(); const workerId = teamBossId;
todayAtSix.setHours(18, 30, 0, 0);
let data = { const tx = await models.WorkerTimeControl.beginTransaction({});
workerFk: teamBossId, try {
timed: todayAtSix const options = {transaction: tx};
};
timeEntry = await app.models.WorkerTimeControl.addTimeEntry(ctx, data); const todayAtSix = new Date();
todayAtSix.setHours(18, 30, 0, 0);
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); ctx.args = {timed: todayAtSix, direction: 'in'};
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
expect(createdTimeEntry).toBeDefined(); expect(createdTimeEntry.id).toBeDefined();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
}); });
it('should try but fail to delete his own time entry', async() => { it('should try but fail to delete his own time entry', async() => {
activeCtx.accessToken.userId = salesBossId; activeCtx.accessToken.userId = salesBossId;
const workerId = salesBossId;
let error; let error;
let todayAtSeven = new Date(); const tx = await models.WorkerTimeControl.beginTransaction({});
todayAtSeven.setHours(19, 30, 0, 0);
let data = {
workerFk: salesPersonId,
timed: todayAtSeven
};
timeEntry = await app.models.WorkerTimeControl.addTimeEntry(ctx, data);
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id);
try { try {
const options = {transaction: tx};
const todayAtSeven = new Date();
todayAtSeven.setHours(19, 30, 0, 0);
ctx.args = {timed: todayAtSeven, direction: 'in'};
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
activeCtx.accessToken.userId = salesPersonId; activeCtx.accessToken.userId = salesPersonId;
await app.models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id); await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
await tx.rollback();
} catch (e) { } catch (e) {
error = e; error = e;
await tx.rollback();
} }
expect(error).toBeDefined(); expect(error).toBeDefined();
@ -115,49 +108,86 @@ describe('workerTimeControl add/delete timeEntry()', () => {
it('should delete the created time entry for the team boss as himself', async() => { it('should delete the created time entry for the team boss as himself', async() => {
activeCtx.accessToken.userId = teamBossId; activeCtx.accessToken.userId = teamBossId;
const workerId = teamBossId;
let todayAtFive = new Date(); const tx = await models.WorkerTimeControl.beginTransaction({});
todayAtFive.setHours(17, 30, 0, 0); try {
const options = {transaction: tx};
let data = { const todayAtFive = new Date();
workerFk: teamBossId, todayAtFive.setHours(17, 30, 0, 0);
timed: todayAtFive
};
timeEntry = await app.models.WorkerTimeControl.addTimeEntry(ctx, data); ctx.args = {timed: todayAtFive, direction: 'in'};
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); expect(createdTimeEntry.id).toBeDefined();
expect(createdTimeEntry).toBeDefined(); await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
await app.models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id); const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); expect(deletedTimeEntry).toBeNull();
await tx.rollback();
expect(createdTimeEntry).toBeNull(); } catch (e) {
await tx.rollback();
throw e;
}
}); });
it('should delete the created time entry for the team boss as HHRR', async() => { it('should delete the created time entry for the team boss as HHRR', async() => {
activeCtx.accessToken.userId = HHRRId; activeCtx.accessToken.userId = HHRRId;
const workerId = teamBossId;
let todayAtFive = new Date(); const tx = await models.WorkerTimeControl.beginTransaction({});
todayAtFive.setHours(17, 30, 0, 0); try {
const options = {transaction: tx};
let data = { const todayAtFive = new Date();
workerFk: teamBossId, todayAtFive.setHours(17, 30, 0, 0);
timed: todayAtFive
};
timeEntry = await app.models.WorkerTimeControl.addTimeEntry(ctx, data); ctx.args = {timed: todayAtFive, direction: 'in'};
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); expect(createdTimeEntry.id).toBeDefined();
expect(createdTimeEntry).toBeDefined(); await models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id, options);
await app.models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id); const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); expect(deletedTimeEntry).toBeNull();
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
});
expect(createdTimeEntry).toBeNull(); it('should edit the created time entry for the team boss as HHRR', async() => {
activeCtx.accessToken.userId = HHRRId;
const workerId = teamBossId;
const tx = await models.WorkerTimeControl.beginTransaction({});
try {
const options = {transaction: tx};
const todayAtFive = new Date();
todayAtFive.setHours(17, 30, 0, 0);
ctx.args = {timed: todayAtFive, direction: 'in'};
const createdTimeEntry = await models.WorkerTimeControl.addTimeEntry(ctx, workerId, options);
expect(createdTimeEntry.id).toBeDefined();
ctx.args = {direction: 'out'};
const updatedTimeEntry = await models.WorkerTimeControl.updateTimeEntry(ctx, createdTimeEntry.id, options);
// const deletedTimeEntry = await models.WorkerTimeControl.findById(createdTimeEntry.id, null, options);
expect(updatedTimeEntry.direction).toEqual('out');
await tx.rollback();
} catch (e) {
await tx.rollback();
throw e;
}
}); });
}); });

View File

@ -0,0 +1,53 @@
const UserError = require('vn-loopback/util/user-error');
module.exports = Self => {
Self.remoteMethodCtx('updateTimeEntry', {
description: 'Updates a time entry for a worker if the user role is above the worker',
accessType: 'READ',
accepts: [{
arg: 'id',
type: 'number',
required: true,
description: 'The time entry id',
http: {source: 'path'}
},
{
arg: 'direction',
type: 'string',
required: true
}],
returns: {
type: 'boolean',
root: true
},
http: {
path: `/:id/updateTimeEntry`,
verb: 'POST'
}
});
Self.updateTimeEntry = async(ctx, id, options) => {
const currentUserId = ctx.req.accessToken.userId;
const models = Self.app.models;
const args = ctx.args;
let myOptions = {};
if (typeof options == 'object')
Object.assign(myOptions, options);
const targetTimeEntry = await Self.findById(id, null, myOptions);
const isSubordinate = await models.Worker.isSubordinate(ctx, targetTimeEntry.userFk, myOptions);
const isTeamBoss = await models.Account.hasRole(currentUserId, 'teamBoss', myOptions);
const isHimself = currentUserId == targetTimeEntry.userFk;
const notAllowed = isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss);
if (notAllowed)
throw new UserError(`You don't have enough privileges`);
return targetTimeEntry.updateAttributes({
direction: args.direction
}, myOptions);
};
};

View File

@ -4,6 +4,7 @@ module.exports = Self => {
require('../methods/worker-time-control/filter')(Self); require('../methods/worker-time-control/filter')(Self);
require('../methods/worker-time-control/addTimeEntry')(Self); require('../methods/worker-time-control/addTimeEntry')(Self);
require('../methods/worker-time-control/deleteTimeEntry')(Self); require('../methods/worker-time-control/deleteTimeEntry')(Self);
require('../methods/worker-time-control/updateTimeEntry')(Self);
Self.rewriteDbError(function(err) { Self.rewriteDbError(function(err) {
if (err.code === 'ER_DUP_ENTRY') if (err.code === 'ER_DUP_ENTRY')

View File

@ -9,16 +9,16 @@
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number" "type": "number"
}, },
"timed": { "timed": {
"type": "Date" "type": "date"
}, },
"manual": { "manual": {
"type": "Boolean" "type": "boolean"
}, },
"order": { "order": {
"type": "Number" "type": "number"
}, },
"direction": { "direction": {
"type": "string" "type": "string"

View File

@ -23,7 +23,7 @@
<vn-side-menu side="right"> <vn-side-menu side="right">
<div class="vn-pa-md"> <div class="vn-pa-md">
<div class="totalBox vn-mb-sm" style="text-align: center;"> <div class="totalBox vn-mb-sm" style="text-align: center;">
<h6>{{'Contract' | translate}} ID: {{$ctrl.businessId}}</h6> <h6>{{'Contract' | translate}} #{{$ctrl.businessId}}</h6>
<div> <div>
{{'Used' | translate}} {{$ctrl.contractHolidays.holidaysEnjoyed}} {{'Used' | translate}} {{$ctrl.contractHolidays.holidaysEnjoyed}}
{{'of' | translate}} {{$ctrl.contractHolidays.totalHolidays || 0}} {{'days' | translate}} {{'of' | translate}} {{$ctrl.contractHolidays.totalHolidays || 0}} {{'days' | translate}}
@ -55,7 +55,7 @@
order="businessFk DESC" order="businessFk DESC"
limit="5"> limit="5">
<tpl-item> <tpl-item>
<div>ID: {{businessFk}}</div> <div>#{{businessFk}}</div>
<div class="text-caption text-secondary"> <div class="text-caption text-secondary">
{{started | date: 'dd/MM/yyyy'}} - {{ended ? (ended | date: 'dd/MM/yyyy') : 'Indef.'}} {{started | date: 'dd/MM/yyyy'}} - {{ended ? (ended | date: 'dd/MM/yyyy') : 'Indef.'}}
</div> </div>

View File

@ -43,9 +43,16 @@
ng-class="::{'invisible': hour.direction == 'middle'}"> ng-class="::{'invisible': hour.direction == 'middle'}">
</vn-icon> </vn-icon>
<vn-chip <vn-chip
ng-class="::{'colored': hour.manual}" ng-class="::{'colored': hour.manual, 'clickable': true}"
removable="::hour.manual" removable="::hour.manual"
on-remove="$ctrl.showDeleteDialog(hour)"> on-remove="$ctrl.showDeleteDialog($event, hour)"
ng-click="$ctrl.edit($event, hour)"
>
<prepend>
<vn-icon icon="edit"
vn-tooltip="Edit">
</vn-icon>
</prepend>
{{::hour.timed | date: 'HH:mm'}} {{::hour.timed | date: 'HH:mm'}}
</vn-chip> </vn-chip>
</section> </section>
@ -97,10 +104,20 @@
<tpl-body> <tpl-body>
<vn-input-time <vn-input-time
vn-one vn-one
ng-model="$ctrl.newTime" vn-focus
ng-model="$ctrl.newTimeEntry.timed"
label="Hour" label="Hour"
vn-focus> required="true">
</vn-input-time> </vn-input-time>
<vn-autocomplete
label="Type"
ng-model="$ctrl.newTimeEntry.direction"
data="$ctrl.entryDirections"
select-fields="['code','description']"
show-field="description"
value-field="code"
required="true">
</vn-autocomplete>
</tpl-body> </tpl-body>
<tpl-buttons> <tpl-buttons>
<input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/> <input type="button" response="cancel" translate-attr="{value: 'Cancel'}"/>
@ -112,4 +129,22 @@
on-accept="$ctrl.deleteTimeEntry()" on-accept="$ctrl.deleteTimeEntry()"
message="This time entry will be deleted" message="This time entry will be deleted"
question="Are you sure you want to delete this entry?"> question="Are you sure you want to delete this entry?">
</vn-confirm> </vn-confirm>
<!-- Edit entry Popover -->
<vn-popover vn-id="editEntry">
<vn-horizontal class="vn-pa-sm edit-entry">
<vn-autocomplete class="dense" style="width: 200px"
ng-model="$ctrl.selectedRow.direction"
data="$ctrl.entryDirections"
select-fields="['code','description']"
show-field="description"
value-field="code">
</vn-autocomplete>
<vn-icon-button vn-none
icon="check"
vn-tooltip="Save"
ng-click="$ctrl.save()">
</vn-icon-button>
</vn-horizontal>
</vn-popover>

View File

@ -7,6 +7,11 @@ class Controller extends Section {
super($element, $); super($element, $);
this.weekDays = []; this.weekDays = [];
this.weekdayNames = vnWeekDays.locales; this.weekdayNames = vnWeekDays.locales;
this.entryDirections = [
{code: 'in', description: this.$t('In')},
{code: 'middle', description: this.$t('Intermediate')},
{code: 'out', description: this.$t('Out')}
];
} }
$postLink() { $postLink() {
@ -241,21 +246,23 @@ class Controller extends Section {
const timed = new Date(weekday.dated.getTime()); const timed = new Date(weekday.dated.getTime());
timed.setHours(0, 0, 0, 0); timed.setHours(0, 0, 0, 0);
this.newTime = timed; this.newTimeEntry = {
workerFk: this.$params.id,
timed: timed
};
this.selectedWeekday = weekday; this.selectedWeekday = weekday;
this.$.addTimeDialog.show(); this.$.addTimeDialog.show();
} }
addTime() { addTime() {
let data = { const query = `WorkerTimeControls/${this.worker.id}/addTimeEntry`;
workerFk: this.$params.id, this.$http.post(query, this.newTimeEntry)
timed: this.newTime
};
this.$http.post(`WorkerTimeControls/addTimeEntry`, data)
.then(() => this.fetchHours()); .then(() => this.fetchHours());
} }
showDeleteDialog(hour) { showDeleteDialog($event, hour) {
$event.preventDefault();
this.timeEntryToDelete = hour; this.timeEntryToDelete = hour;
this.$.deleteEntryDialog.show(); this.$.deleteEntryDialog.show();
} }
@ -268,6 +275,22 @@ class Controller extends Section {
this.vnApp.showSuccess(this.$t('Entry removed')); this.vnApp.showSuccess(this.$t('Entry removed'));
}); });
} }
edit($event, hour) {
if ($event.defaultPrevented) return;
this.selectedRow = hour;
this.$.editEntry.show($event);
}
save() {
const entry = this.selectedRow;
const query = `WorkerTimeControls/${entry.id}/updateTimeEntry`;
this.$http.post(query, {direction: entry.direction})
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
.then(() => this.$.editEntry.hide())
.then(() => this.fetchHours());
}
} }
Controller.$inject = ['$element', '$scope', 'vnWeekDays']; Controller.$inject = ['$element', '$scope', 'vnWeekDays'];

View File

@ -1,5 +1,6 @@
In: Entrada In: Entrada
Out: Salida Out: Salida
Intermediate: Intermedio
Hour: Hora Hour: Hora
Hours: Horas Hours: Horas
Add time: Añadir hora Add time: Añadir hora

View File

@ -24,4 +24,7 @@ vn-worker-time-control {
.totalBox { .totalBox {
max-width: none max-width: none
} }
.edit-entry {
width: 150px
}
} }