From 1d8fb253254962613d1ac2e7f879a4e3ad74186e Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Tue, 18 Oct 2022 10:25:54 +0200 Subject: [PATCH] Refactored according to the suggested changes --- .../methods/worker/workerDisableExcluded.js | 30 ------------- .../worker/workerExcludeFromDisable.js | 45 ------------------- modules/worker/back/models/worker.js | 2 - modules/worker/front/descriptor/index.html | 11 +++-- modules/worker/front/descriptor/index.js | 24 ++++++---- modules/worker/front/locale/es.yml | 5 ++- 6 files changed, 24 insertions(+), 93 deletions(-) delete mode 100644 modules/worker/back/methods/worker/workerDisableExcluded.js delete mode 100644 modules/worker/back/methods/worker/workerExcludeFromDisable.js diff --git a/modules/worker/back/methods/worker/workerDisableExcluded.js b/modules/worker/back/methods/worker/workerDisableExcluded.js deleted file mode 100644 index 017e044c2..000000000 --- a/modules/worker/back/methods/worker/workerDisableExcluded.js +++ /dev/null @@ -1,30 +0,0 @@ - -module.exports = Self => { - Self.remoteMethod('workerDisableExcluded', { - description: 'Check if the worker can be disabled', - accessType: 'READ', - accepts: { - arg: 'id', - type: 'Number', - required: true, - description: `The worker id`, - http: {source: 'path'} - }, - returns: { - type: 'boolean', - root: true - }, - http: { - path: `/workerDisableExcluded/:id`, - verb: 'GET' - } - }); - - Self.workerDisableExcluded = async id => { - let result; - const query = `Select * from vn.workerDisableExcluded where workerFk like ${id}`; - let sqlResult = await Self.rawSql(query); - sqlResult.length == 0 ? result = false : result = true; - return result; - }; -}; diff --git a/modules/worker/back/methods/worker/workerExcludeFromDisable.js b/modules/worker/back/methods/worker/workerExcludeFromDisable.js deleted file mode 100644 index 86d940862..000000000 --- a/modules/worker/back/methods/worker/workerExcludeFromDisable.js +++ /dev/null @@ -1,45 +0,0 @@ -module.exports = Self => { - Self.remoteMethod('workerExcludeFromDisable', { - description: 'Change the status of the worker between can be disabled and cant be disabled', - accessType: 'READ', - accepts: [{ - arg: 'id', - type: 'Number', - required: true, - description: `The worker id`, - http: {source: 'path'} - }, - { - arg: 'currValue', - type: 'Boolean', - required: true, - description: `The current value of workerDisableExcluded`, - http: {source: 'path'} - }], - returns: { - type: 'boolean', - root: true - }, - http: { - path: `/workerExcludeFromDisable/:id/:currValue`, - verb: 'GET' - } - }); - - Self.workerExcludeFromDisable = async(id, currValue) => { - const models = Self.app.models; - - if (!currValue) { - await models.WorkerDisableExcluded.create({ - workerFk: id, - dated: new Date() - }); - } else { - await models.WorkerDisableExcluded.remove({ - workerFk: id - }); - } - - return false; - }; -}; diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index c90729779..ec6c4af28 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -13,6 +13,4 @@ module.exports = Self => { require('../methods/worker/contracts')(Self); require('../methods/worker/holidays')(Self); require('../methods/worker/activeContract')(Self); - require('../methods/worker/workerDisableExcluded')(Self); - require('../methods/worker/workerExcludeFromDisable')(Self); }; diff --git a/modules/worker/front/descriptor/index.html b/modules/worker/front/descriptor/index.html index c60801bb9..58ac3d9e6 100644 --- a/modules/worker/front/descriptor/index.html +++ b/modules/worker/front/descriptor/index.html @@ -15,18 +15,17 @@ - - Marcar para no deshabilitar + Click to exclude the user from getting disabled - Marcar como deshabilitable + Click to allow the user to be disabled @@ -54,7 +53,7 @@
diff --git a/modules/worker/front/descriptor/index.js b/modules/worker/front/descriptor/index.js index 7a3922a08..2ff032def 100644 --- a/modules/worker/front/descriptor/index.js +++ b/modules/worker/front/descriptor/index.js @@ -5,7 +5,6 @@ class Controller extends Descriptor { constructor($element, $, $rootScope) { super($element, $); this.$rootScope = $rootScope; - this.canBeExcluded(); } get worker() { @@ -14,6 +13,9 @@ class Controller extends Descriptor { set worker(value) { this.entity = value; + + if (value) + this.getIsExcluded(); } get excluded() { @@ -22,18 +24,22 @@ class Controller extends Descriptor { set excluded(value) { this.entity.excluded = value; - this.$rootScope.$apply(); } - async canBeExcluded() { - await new Promise(r => setTimeout(r, 500)); - let data = await this.$http.get(`Workers/workerDisableExcluded/${this.entity.id}`); - this.excluded = data.data; + getIsExcluded() { + this.$http.get(`workerDisableExcludeds/${this.entity.id}/exists`).then(data => { + this.excluded = data.data.exists; + }); } - async setExcluded() { - await this.$http.get(`Workers/workerExcludeFromDisable/${this.entity.id}/${this.entity.excluded}`); - this.excluded = !this.entity.excluded; + handleExcluded() { + if (this.excluded) { + this.$http.delete(`workerDisableExcludeds/${this.entity.id}`); + this.excluded = false; + } else { + this.$http.post(`workerDisableExcludeds`, {workerFk: this.entity.id, dated: new Date}); + this.excluded = true; + } } loadData() { diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index 1414d089b..672f4c52f 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -20,4 +20,7 @@ View worker: Ver trabajador Worker id: Id trabajador Workers: Trabajadores worker: trabajador -Go to the worker: Ir al trabajador \ No newline at end of file +Go to the worker: Ir al trabajador +Click to exclude the user from getting disabled: Marcar para no deshabilitar +Click to allow the user to be disabled: Marcar para deshabilitar +This user can't be disabled: Fijado para no deshabilitar \ No newline at end of file