From 05d91ed50ebb8d5c39356571ebd6faa0deaaf1c7 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 22 Feb 2023 15:12:25 +0100 Subject: [PATCH] feat: actualizada interfaz --- .../updateWorkerTimeControlMail.js | 2 - modules/worker/front/time-control/index.html | 14 +++- modules/worker/front/time-control/index.js | 74 ++++++++++++++----- .../worker/front/time-control/locale/es.yml | 4 +- modules/worker/front/time-control/style.scss | 12 ++- 5 files changed, 82 insertions(+), 24 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js index a8dc14bb1..dced6487b 100644 --- a/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js +++ b/modules/worker/back/methods/worker-time-control/updateWorkerTimeControlMail.js @@ -60,8 +60,6 @@ module.exports = Self => { const oldState = workerTimeControlMail.state; const oldReason = workerTimeControlMail.reason; - if (oldState == args.state) throw new UserError('Already has this status'); - await workerTimeControlMail.updateAttributes({ state: args.state, reason: args.reason || null diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index 0f6a99d36..937e9a581 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -78,15 +78,27 @@ - + + + + + diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 1126ac1e3..33a300ac7 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -294,11 +294,15 @@ class Controller extends Section { this.$.editEntry.show($event); } - getWeekNumber(currentDate) { - const startDate = new Date(currentDate.getFullYear(), 0, 1); - let days = Math.floor((currentDate - startDate) / - (24 * 60 * 60 * 1000)); - return Math.ceil(days / 7); + getWeekNumber(date) { + const tempDate = new Date(date); + let dayOfWeek = tempDate.getDay(); + dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek; + const firstDayOfWeek = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() - (dayOfWeek - 1)); + const firstDayOfYear = new Date(tempDate.getFullYear(), 0, 1); + const differenceInMilliseconds = firstDayOfWeek.getTime() - firstDayOfYear.getTime(); + const weekNumber = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 7)) + 1; + return weekNumber - 1; } isSatisfied() { @@ -312,6 +316,7 @@ class Controller extends Section { const query = `WorkerTimeControls/updateWorkerTimeControlMail`; this.$http.post(query, params).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); + this.$state.reload(); }); } @@ -327,6 +332,7 @@ class Controller extends Section { const query = `WorkerTimeControls/updateWorkerTimeControlMail`; this.$http.post(query, params).then(() => { this.vnApp.showSuccess(this.$t('Data saved!')); + this.$state.reload(); }); } @@ -348,13 +354,12 @@ class Controller extends Section { formatWeek($element) { let weekNumber = $element.firstElementChild; - let weekNumberValue = $element.firstElementChild.innerHTML; - console.log(weekNumberValue); + let weekNumberValue = $element.firstElementChild.innerHTML - 1; const filter = { where: { - workerFk: 9, - // year: this.date.getFullYear(), - // week: weekNumberValue - 1 + workerFk: this.$params.id, + year: this.date.getFullYear(), + week: weekNumberValue } }; // const filter = { @@ -366,18 +371,51 @@ class Controller extends Section { // ] // } // }; - console.log(filter); - this.$http.get('WorkerTimeControlMails', {filter}) + this.$http.get('WorkerTimeControlMails/findOne', {filter}) .then(res => { - console.log(res.data.state); const state = res.data.state; - if (state == 'CONFIRMED') weekNumber.style.color = '#97B92F'; - else if (state == 'REVISE') weekNumber.style.color = '#FF4444'; - else weekNumber.style.color = '#5151c0'; - // weekNumber.title = event.name; - // weekNumber.style.backgroundColor = event.color; + const currentWeekNumber = this.getWeekNumber(this.date); + if (currentWeekNumber == weekNumberValue) { + this.state = state; + this.reason = res.data.reason; + console.log(currentWeekNumber, weekNumberValue, this.state, this.reason); + } + if (state == 'CONFIRMED') { + weekNumber.classList.add('confirmed'); + weekNumber.setAttribute('vn-tooltip', 'Conforme'); + } + if (state == 'REVISE') weekNumber.style.color = '#FF4444'; + if (state == 'SENDED') weekNumber.style.color = '#E65F00'; }); } + + resendEmail() { + const filter = { + where: {userFk: this.$params.id}, + }; + this.$http.get('EmailUsers/findOne', {filter}) + .then(res => { + const timestamp = this.date.getTime() / 1000; + const url = `${window.location.origin}/#!/worker/${this.$params.id}/time-control?timestamp=${timestamp}`; + const weekNumber = this.getWeekNumber(this.date); + + const params = { + recipient: res.data.email, + week: weekNumber + 1, + year: this.date.getFullYear(), + url: url, + }; + this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params) + .then(res => { + this.vnApp.showSuccess(this.$t('Email sended')); + }); + }); + } + + getTime(timeString) { + const [hours, minutes, seconds] = timeString.split(':'); + return [parseInt(hours), parseInt(minutes), parseInt(seconds)]; + } } Controller.$inject = ['$element', '$scope', 'vnWeekDays']; diff --git a/modules/worker/front/time-control/locale/es.yml b/modules/worker/front/time-control/locale/es.yml index 2a3bffc00..2f9234738 100644 --- a/modules/worker/front/time-control/locale/es.yml +++ b/modules/worker/front/time-control/locale/es.yml @@ -13,4 +13,6 @@ Entry removed: Fichada borrada The entry type can't be empty: El tipo de fichada no puede quedar vacĂ­a Satisfied: Conforme Not satisfied: No conforme -Reason: Motivo \ No newline at end of file +Reason: Motivo +Resend: Reenviar +Email sended: Email enviado diff --git a/modules/worker/front/time-control/style.scss b/modules/worker/front/time-control/style.scss index 6a46921a7..d39f8418b 100644 --- a/modules/worker/front/time-control/style.scss +++ b/modules/worker/front/time-control/style.scss @@ -14,7 +14,7 @@ vn-worker-time-control { align-items: center; justify-content: center; padding: 4px 0; - + & > vn-icon { color: $color-font-secondary; padding-right: 1px; @@ -28,4 +28,12 @@ vn-worker-time-control { .edit-time-entry { width: 200px -} \ No newline at end of file +} + +.right { + float: right; + } + +.confirmed { + color: #97B92F; +}