From 5d9220c5c0f3292d000da42799b232d6f65ad49a Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 27 Feb 2023 08:39:46 +0100 Subject: [PATCH 1/6] refs #5287 locker added --- CHANGELOG.md | 2 ++ db/changes/230801/.gitkeep | 0 db/changes/230801/00-workerLocker.sql | 1 + e2e/helpers/selectors.js | 2 ++ e2e/paths/03-worker/01_summary.spec.js | 3 +- e2e/paths/03-worker/02_basicData.spec.js | 2 ++ loopback/locale/es.json | 3 +- modules/worker/back/models/worker.js | 4 +++ modules/worker/back/models/worker.json | 3 ++ modules/worker/front/basic-data/index.html | 19 +++++++----- modules/worker/front/basic-data/locale/es.yml | 3 +- modules/worker/front/summary/index.html | 31 ++++++++++--------- modules/worker/front/summary/locale/es.yml | 3 +- 13 files changed, 51 insertions(+), 25 deletions(-) delete mode 100644 db/changes/230801/.gitkeep create mode 100644 db/changes/230801/00-workerLocker.sql diff --git a/CHANGELOG.md b/CHANGELOG.md index 17259f545..3388ceb73 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - (Client -> Descriptor) Nuevo icono $ con barrotes para los clientes con impago +- (Trabajador -> Datos Básicos) Añadido nuevo campo Taquilla +- (Trabajador -> PDA) Nueva sección ### Changed - diff --git a/db/changes/230801/.gitkeep b/db/changes/230801/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/db/changes/230801/00-workerLocker.sql b/db/changes/230801/00-workerLocker.sql new file mode 100644 index 000000000..1a7c2e98e --- /dev/null +++ b/db/changes/230801/00-workerLocker.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`worker` ADD locker INT UNSIGNED NULL UNIQUE; diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index efaa13ee3..a96b7fd51 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -973,6 +973,7 @@ export default { id: 'vn-worker-summary vn-one:nth-child(1) > vn-label-value:nth-child(3) > section > span', email: 'vn-worker-summary vn-one:nth-child(1) > vn-label-value:nth-child(4) > section > span', department: 'vn-worker-summary vn-one:nth-child(1) > vn-label-value:nth-child(5) > section > span', + locker: 'vn-worker-summary vn-one:nth-child(1) > vn-label-value:nth-child(10) > section > span', userId: 'vn-worker-summary vn-one:nth-child(2) > vn-label-value:nth-child(2) > section > span', userName: 'vn-worker-summary vn-one:nth-child(2) > vn-label-value:nth-child(3) > section > span', role: 'vn-worker-summary vn-one:nth-child(2) > vn-label-value:nth-child(4) > section > span', @@ -983,6 +984,7 @@ export default { name: 'vn-worker-basic-data vn-textfield[ng-model="$ctrl.worker.firstName"]', surname: 'vn-worker-basic-data vn-textfield[ng-model="$ctrl.worker.lastName"]', phone: 'vn-worker-basic-data vn-textfield[ng-model="$ctrl.worker.phone"]', + locker: 'vn-worker-basic-data vn-input-number[ng-model="$ctrl.worker.locker"]', saveButton: 'vn-worker-basic-data button[type=submit]' }, workerPbx: { diff --git a/e2e/paths/03-worker/01_summary.spec.js b/e2e/paths/03-worker/01_summary.spec.js index 4e5b0cfa9..bcb6ad848 100644 --- a/e2e/paths/03-worker/01_summary.spec.js +++ b/e2e/paths/03-worker/01_summary.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -describe('Worker summary path', () => { +fdescribe('Worker summary path', () => { const workerId = 3; let browser; let page; @@ -29,5 +29,6 @@ describe('Worker summary path', () => { expect(await page.getProperty(selectors.workerSummary.userName, 'innerText')).toEqual('agency'); expect(await page.getProperty(selectors.workerSummary.role, 'innerText')).toEqual('agency'); expect(await page.getProperty(selectors.workerSummary.extension, 'innerText')).toEqual('1101'); + expect(await page.getProperty(selectors.workerSummary.locker, 'innerText')).toEqual('-'); }); }); diff --git a/e2e/paths/03-worker/02_basicData.spec.js b/e2e/paths/03-worker/02_basicData.spec.js index 66a597dd1..381375dc7 100644 --- a/e2e/paths/03-worker/02_basicData.spec.js +++ b/e2e/paths/03-worker/02_basicData.spec.js @@ -25,6 +25,7 @@ describe('Worker basic data path', () => { await page.overwrite(selectors.workerBasicData.name, 'David C.'); await page.overwrite(selectors.workerBasicData.surname, 'H.'); await page.overwrite(selectors.workerBasicData.phone, '444332211'); + await page.overwrite(selectors.workerBasicData.locker, '1'); await page.click(selectors.workerBasicData.saveButton); const message = await page.waitForSnackbar(); @@ -36,5 +37,6 @@ describe('Worker basic data path', () => { expect(await page.waitToGetProperty(selectors.workerBasicData.name, 'value')).toEqual('David C.'); expect(await page.waitToGetProperty(selectors.workerBasicData.surname, 'value')).toEqual('H.'); expect(await page.waitToGetProperty(selectors.workerBasicData.phone, 'value')).toEqual('444332211'); + expect(await page.waitToGetProperty(selectors.workerBasicData.locker, 'value')).toEqual('1'); }); }); diff --git a/loopback/locale/es.json b/loopback/locale/es.json index ad6d53d64..10db9a54f 100644 --- a/loopback/locale/es.json +++ b/loopback/locale/es.json @@ -263,6 +263,7 @@ "It is not possible to modify sales that their articles are from Floramondo": "No es posible modificar líneas de pedido cuyos artículos sean de Floramondo", "It is not possible to modify cloned sales": "No es posible modificar líneas de pedido clonadas", "A supplier with the same name already exists. Change the country.": "Un proveedor con el mismo nombre ya existe. Cambie el país.", - "There is no assigned email for this client": "No hay correo asignado para este cliente" + "There is no assigned email for this client": "No hay correo asignado para este cliente", + "This locker has already been assigned": "Esta taquilla ya ha sido asignada" } diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index e66259cd0..68baec6ca 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -14,4 +14,8 @@ module.exports = Self => { require('../methods/worker/holidays')(Self); require('../methods/worker/activeContract')(Self); require('../methods/worker/new')(Self); + + Self.validatesUniquenessOf('locker', { + message: 'This locker has already been assigned' + }); }; diff --git a/modules/worker/back/models/worker.json b/modules/worker/back/models/worker.json index e3a941dd3..d21094f26 100644 --- a/modules/worker/back/models/worker.json +++ b/modules/worker/back/models/worker.json @@ -55,6 +55,9 @@ }, "code": { "type" : "string" + }, + "locker": { + "type" : "number" } }, "relations": { diff --git a/modules/worker/front/basic-data/index.html b/modules/worker/front/basic-data/index.html index 5a3acdde5..d89d88f2e 100644 --- a/modules/worker/front/basic-data/index.html +++ b/modules/worker/front/basic-data/index.html @@ -11,7 +11,7 @@ @@ -24,14 +24,14 @@ @@ -73,11 +73,16 @@ + + diff --git a/modules/worker/front/basic-data/locale/es.yml b/modules/worker/front/basic-data/locale/es.yml index a83c30d99..edf08de90 100644 --- a/modules/worker/front/basic-data/locale/es.yml +++ b/modules/worker/front/basic-data/locale/es.yml @@ -5,4 +5,5 @@ SSN: NSS Married: Casado/a Single: Soltero/a Business phone: Teléfono de empresa -Mobile extension: Extensión móvil \ No newline at end of file +Mobile extension: Extensión móvil +Locker: Taquilla diff --git a/modules/worker/front/summary/index.html b/modules/worker/front/summary/index.html index 0a6bec822..72b8e729a 100644 --- a/modules/worker/front/summary/index.html +++ b/modules/worker/front/summary/index.html @@ -11,23 +11,23 @@

- Basic data

-

Basic data

- - - - - - + + +

User data

- - - -
- - \ No newline at end of file + diff --git a/modules/worker/front/summary/locale/es.yml b/modules/worker/front/summary/locale/es.yml index e9c8e5583..fb9d2e2ca 100644 --- a/modules/worker/front/summary/locale/es.yml +++ b/modules/worker/front/summary/locale/es.yml @@ -1,3 +1,4 @@ Business phone: Teléfono de empresa Personal phone: Teléfono personal -Mobile extension: Extensión móvil \ No newline at end of file +Mobile extension: Extensión móvil +Locker: Taquilla -- 2.40.1 From 5b7306a9caf365284a48cab85132af18ca097f50 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 27 Feb 2023 08:41:27 +0100 Subject: [PATCH 2/6] refs #5287 f describe --- e2e/paths/03-worker/01_summary.spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/e2e/paths/03-worker/01_summary.spec.js b/e2e/paths/03-worker/01_summary.spec.js index bcb6ad848..51992b41d 100644 --- a/e2e/paths/03-worker/01_summary.spec.js +++ b/e2e/paths/03-worker/01_summary.spec.js @@ -1,7 +1,7 @@ import selectors from '../../helpers/selectors.js'; import getBrowser from '../../helpers/puppeteer'; -fdescribe('Worker summary path', () => { +describe('Worker summary path', () => { const workerId = 3; let browser; let page; -- 2.40.1 From 94901d5b1f38604cd918f6f979edfc9f7aea8394 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Feb 2023 07:49:34 +0100 Subject: [PATCH 3/6] refs #5287 pda section added, tests added --- db/changes/230801/00-workerLocker.sql | 8 +++ db/dump/fixtures.sql | 27 +++++++ e2e/helpers/selectors.js | 6 ++ e2e/paths/03-worker/07_pda.spec.js | 41 +++++++++++ front/salix/locale/es.yml | 1 + .../worker/back/methods/worker/allocatePDA.js | 66 +++++++++++++++++ .../back/methods/worker/deallocatePDA.js | 53 ++++++++++++++ .../methods/worker/specs/allocatePDA.spec.js | 46 ++++++++++++ .../worker/specs/deallocatePDA.spec.js | 26 +++++++ modules/worker/back/model-config.json | 12 ++++ .../back/models/device-production-models.json | 15 ++++ .../back/models/device-production-state.json | 18 +++++ .../back/models/device-production-user.json | 33 +++++++++ .../worker/back/models/device-production.json | 54 ++++++++++++++ modules/worker/back/models/worker.js | 2 + modules/worker/front/index.js | 1 + modules/worker/front/locale/es.yml | 9 ++- modules/worker/front/pda/index.html | 48 +++++++++++++ modules/worker/front/pda/index.js | 53 ++++++++++++++ modules/worker/front/pda/index.spec.js | 72 +++++++++++++++++++ modules/worker/front/pda/style.scss | 6 ++ modules/worker/front/routes.json | 8 +++ 22 files changed, 604 insertions(+), 1 deletion(-) create mode 100644 e2e/paths/03-worker/07_pda.spec.js create mode 100644 modules/worker/back/methods/worker/allocatePDA.js create mode 100644 modules/worker/back/methods/worker/deallocatePDA.js create mode 100644 modules/worker/back/methods/worker/specs/allocatePDA.spec.js create mode 100644 modules/worker/back/methods/worker/specs/deallocatePDA.spec.js create mode 100644 modules/worker/back/models/device-production-models.json create mode 100644 modules/worker/back/models/device-production-state.json create mode 100644 modules/worker/back/models/device-production-user.json create mode 100644 modules/worker/back/models/device-production.json create mode 100644 modules/worker/front/pda/index.html create mode 100644 modules/worker/front/pda/index.js create mode 100644 modules/worker/front/pda/index.spec.js create mode 100644 modules/worker/front/pda/style.scss diff --git a/db/changes/230801/00-workerLocker.sql b/db/changes/230801/00-workerLocker.sql index 1a7c2e98e..1fcea50ac 100644 --- a/db/changes/230801/00-workerLocker.sql +++ b/db/changes/230801/00-workerLocker.sql @@ -1 +1,9 @@ ALTER TABLE `vn`.`worker` ADD locker INT UNSIGNED NULL UNIQUE; +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('DeviceProduction', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('DeviceProductionModels', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('DeviceProductionState', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('DeviceProductionUser', '*', '*', 'ALLOW', 'ROLE', 'employee'), + ('Worker', 'deallocatePDA', '*', 'ALLOW', 'ROLE', 'employee'), + ('Worker', 'allocatePDA', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 8fb12e822..c0989f1ed 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2787,3 +2787,30 @@ INSERT INTO `vn`.`workerConfig` (`id`, `businessUpdated`, `roleFk`) VALUES (1, NULL, 1); +INSERT INTO `vn`.`deviceProductionModels` (`code`) + VALUES + ('BLACKVIEW'), + ('DODGEE'), + ('ZEBRA'); + +INSERT INTO `vn`.`deviceProductionState` (`code`, `description`) + VALUES + ('active', 'activo'), + ('idle', 'inactivo'), + ('lost', 'perdida'), + ('repair', 'reparación'), + ('retired', 'retirada'); + +INSERT INTO `vn`.`deviceProduction` (`imei`, `modelFk`, `macWifi`, `serialNumber`, `android_id`, `purchased`, `stateFk`, `isInScalefusion`, `description`) + VALUES + ('ime1', 'BLACKVIEW', 'macWifi1', 'serialNumber1', 'android_id1', util.VN_NOW(), 'active', 0, NULL), + ('ime2', 'DODGEE', 'macWifi2', 'serialNumber2', 'android_id2', util.VN_NOW(), 'idle', 0, NULL), + ('ime3', 'ZEBRA', 'macWifi3', 'serialNumber3', 'android_id3', util.VN_NOW(), 'active', 0, NULL), + ('ime4', 'BLACKVIEW', 'macWifi4', 'serialNumber4', 'android_id4', util.VN_NOW(), 'idle', 0, NULL); + +INSERT INTO `vn`.`deviceProductionUser` (`deviceProductionFk`, `userFk`, `created`) + VALUES + (1, 1, util.VN_NOW()), + (3, 3, util.VN_NOW()); + + diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index a96b7fd51..e32bab57d 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -1042,6 +1042,12 @@ export default { switft: 'vn-worker-create vn-autocomplete[ng-model="$ctrl.worker.bankEntityFk"]', createButton: 'vn-worker-create vn-submit[label="Create"]', }, + workerPda: { + currentPDA: 'vn-worker-pda vn-textfield[ng-model="$ctrl.currentPDA.description"]', + newPDA: 'vn-worker-pda vn-autocomplete[ng-model="$ctrl.newPDA"]', + delete: 'vn-worker-pda vn-icon-button[icon=delete]', + submit: 'vn-worker-pda vn-submit[label="Assign"]', + }, invoiceOutIndex: { topbarSearch: 'vn-searchbar', searchResult: 'vn-invoice-out-index vn-card > vn-table > div > vn-tbody > a.vn-tr', diff --git a/e2e/paths/03-worker/07_pda.spec.js b/e2e/paths/03-worker/07_pda.spec.js new file mode 100644 index 000000000..f583a9e4f --- /dev/null +++ b/e2e/paths/03-worker/07_pda.spec.js @@ -0,0 +1,41 @@ +import selectors from '../../helpers/selectors.js'; +import getBrowser from '../../helpers/puppeteer'; + +describe('Worker pda path', () => { + let browser; + let page; + beforeAll(async() => { + browser = await getBrowser(); + page = browser.page; + await page.loginAndModule('employee', 'worker'); + await page.accessToSearchResult('employeeNick'); + await page.accessToSection('worker.card.pda'); + }); + + afterAll(async() => { + await browser.close(); + }); + + it('should check if worker has already a PDA allocated', async() => { + expect(await page.waitToGetProperty(selectors.workerPda.currentPDA, 'value')).toContain('serialNumber1'); + }); + + it('should deallocate the PDA', async() => { + await page.waitToClick(selectors.workerPda.delete); + let message = await page.waitForSnackbar(); + + expect(message.text).toContain('PDA deallocated'); + }); + + it('should allocate a new PDA', async() => { + await page.autocompleteSearch(selectors.workerPda.newPDA, 'serialNumber2'); + await page.waitToClick(selectors.workerPda.submit); + let message = await page.waitForSnackbar(); + + expect(message.text).toContain('PDA allocated'); + }); + + it('should check if a new PDA has been allocated', async() => { + expect(await page.waitToGetProperty(selectors.workerPda.currentPDA, 'value')).toContain('serialNumber2'); + }); +}); diff --git a/front/salix/locale/es.yml b/front/salix/locale/es.yml index d92c32b33..bed41c63b 100644 --- a/front/salix/locale/es.yml +++ b/front/salix/locale/es.yml @@ -23,6 +23,7 @@ There is a new version, click here to reload: Hay una nueva versión, pulse aqu Back: Volver Save: Guardar +Assign: Asignar Create: Crear Send: Enviar Delete: Eliminar diff --git a/modules/worker/back/methods/worker/allocatePDA.js b/modules/worker/back/methods/worker/allocatePDA.js new file mode 100644 index 000000000..096718c80 --- /dev/null +++ b/modules/worker/back/methods/worker/allocatePDA.js @@ -0,0 +1,66 @@ +const UserError = require('vn-loopback/util/user-error'); + +module.exports = Self => { + Self.remoteMethodCtx('allocatePDA', { + description: 'Deallocate the worker\'s PDA', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The worker id', + http: {source: 'path'} + }, { + arg: 'pda', + type: 'number', + required: true, + description: 'The pda id' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/:id/allocatePDA`, + verb: 'POST' + } + }); + + Self.allocatePDA = async(ctx, options) => { + const models = Self.app.models; + const args = ctx.args; + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const pda = await models.DeviceProduction.findById(args.pda, myOptions); + if (pda.stateFk != 'idle') throw new UserError(`The PDA state is not idle`); + await pda.updateAttributes({stateFk: 'active'}, myOptions); + await models.DeviceProductionUser.create({ + deviceProductionFk: args.pda, + userFk: args.id, + created: new Date() + }, myOptions); + + if (tx) await tx.commit(); + + return { + deviceProductionFk: pda.id, + deviceProduction: { + modelFk: pda.modelFk, + serialNumber: pda.serialNumber + } + }; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/worker/back/methods/worker/deallocatePDA.js b/modules/worker/back/methods/worker/deallocatePDA.js new file mode 100644 index 000000000..7fa7855d1 --- /dev/null +++ b/modules/worker/back/methods/worker/deallocatePDA.js @@ -0,0 +1,53 @@ +module.exports = Self => { + Self.remoteMethodCtx('deallocatePDA', { + description: 'Deallocate the worker\'s PDA', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The worker id', + http: {source: 'path'} + }, { + arg: 'pda', + type: 'number', + required: true, + description: 'The pda id' + }], + returns: { + type: ['object'], + root: true + }, + http: { + path: `/:id/deallocatePDA`, + verb: 'POST' + } + }); + + Self.deallocatePDA = async(ctx, options) => { + const models = Self.app.models; + const args = ctx.args; + let tx; + const myOptions = {}; + + if (typeof options == 'object') + Object.assign(myOptions, options); + + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } + + try { + const pda = await models.DeviceProduction.findById(args.pda, myOptions); + await pda.updateAttributes({stateFk: 'idle'}, myOptions); + await models.DeviceProductionUser.destroyAll({userFk: args.id, deviceProductionFk: args.pda}, myOptions); + + if (tx) await tx.commit(); + + return pda; + } catch (e) { + if (tx) await tx.rollback(); + throw e; + } + }; +}; diff --git a/modules/worker/back/methods/worker/specs/allocatePDA.spec.js b/modules/worker/back/methods/worker/specs/allocatePDA.spec.js new file mode 100644 index 000000000..5c80b6408 --- /dev/null +++ b/modules/worker/back/methods/worker/specs/allocatePDA.spec.js @@ -0,0 +1,46 @@ +const models = require('vn-loopback/server/server').models; + +describe('Worker allocatePDA()', () => { + it('should allocate a new worker\'s PDA', async() => { + const tx = await models.Worker.beginTransaction({}); + try { + const workerWithoutPDA = 1101; + const PDAWithIdleState = 4; + const options = {transaction: tx}; + const ctx = {args: {id: workerWithoutPDA, pda: PDAWithIdleState}}; + + await models.Worker.allocatePDA(ctx, options); + const deviceProduction = await models.DeviceProduction.findById(PDAWithIdleState, null, options); + const deviceProductionUser = await models.DeviceProductionUser + .findById(PDAWithIdleState, null, options); + + expect(deviceProduction.stateFk).toEqual('active'); + expect(deviceProductionUser).not.toBeNull(); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); + + it('should throw error trying to allocate a non idle PDA', async() => { + const tx = await models.Worker.beginTransaction({}); + let error; + try { + const workerWithoutPDA = 1101; + const PDAWithActiveState = 1; + const options = {transaction: tx}; + const ctx = {args: {id: workerWithoutPDA, pda: PDAWithActiveState}}; + + await models.Worker.allocatePDA(ctx, options); + + await tx.rollback(); + } catch (e) { + error = e; + await tx.rollback(); + } + + expect(error).toBeDefined(); + }); +}); diff --git a/modules/worker/back/methods/worker/specs/deallocatePDA.spec.js b/modules/worker/back/methods/worker/specs/deallocatePDA.spec.js new file mode 100644 index 000000000..bddd017cd --- /dev/null +++ b/modules/worker/back/methods/worker/specs/deallocatePDA.spec.js @@ -0,0 +1,26 @@ +const models = require('vn-loopback/server/server').models; + +describe('Worker deallocatePDA()', () => { + it('should deallocate a worker\'s PDA', async() => { + const tx = await models.Worker.beginTransaction({}); + try { + const workerWithPDA = 1; + const PDAWithActiveState = 1; + const options = {transaction: tx}; + const ctx = {args: {id: workerWithPDA, pda: PDAWithActiveState}}; + + await models.Worker.deallocatePDA(ctx, options); + const deviceProduction = await models.DeviceProduction.findById(PDAWithActiveState, null, options); + const deviceProductionUser = await models.DeviceProductionUser + .findById(PDAWithActiveState, null, options); + + expect(deviceProduction.stateFk).toEqual('idle'); + expect(deviceProductionUser).toBe(null); + + await tx.rollback(); + } catch (e) { + await tx.rollback(); + throw e; + } + }); +}); diff --git a/modules/worker/back/model-config.json b/modules/worker/back/model-config.json index 7e03c8a23..8079bd165 100644 --- a/modules/worker/back/model-config.json +++ b/modules/worker/back/model-config.json @@ -20,6 +20,18 @@ "Device": { "dataSource": "vn" }, + "DeviceProduction": { + "dataSource": "vn" + }, + "DeviceProductionModels": { + "dataSource": "vn" + }, + "DeviceProductionState": { + "dataSource": "vn" + }, + "DeviceProductionUser": { + "dataSource": "vn" + }, "EducationLevel": { "dataSource": "vn" }, diff --git a/modules/worker/back/models/device-production-models.json b/modules/worker/back/models/device-production-models.json new file mode 100644 index 000000000..dcf447520 --- /dev/null +++ b/modules/worker/back/models/device-production-models.json @@ -0,0 +1,15 @@ +{ + "name": "DeviceProductionModels", + "base": "VnModel", + "options": { + "mysql": { + "table": "deviceProductionModels" + } + }, + "properties": { + "code": { + "type": "string", + "id": true + } + } +} diff --git a/modules/worker/back/models/device-production-state.json b/modules/worker/back/models/device-production-state.json new file mode 100644 index 000000000..32695621a --- /dev/null +++ b/modules/worker/back/models/device-production-state.json @@ -0,0 +1,18 @@ +{ + "name": "DeviceProductionState", + "base": "VnModel", + "options": { + "mysql": { + "table": "deviceProductionState" + } + }, + "properties": { + "code": { + "type": "string", + "id": true + }, + "description": { + "type": "string" + } + } +} diff --git a/modules/worker/back/models/device-production-user.json b/modules/worker/back/models/device-production-user.json new file mode 100644 index 000000000..568e79413 --- /dev/null +++ b/modules/worker/back/models/device-production-user.json @@ -0,0 +1,33 @@ +{ + "name": "DeviceProductionUser", + "base": "VnModel", + "options": { + "mysql": { + "table": "deviceProductionUser" + } + }, + "properties": { + "deviceProductionFk": { + "type": "number", + "id": true + }, + "userFk": { + "type": "number" + }, + "created": { + "type": "date" + } + }, + "relations": { + "deviceProduction": { + "type": "belongsTo", + "model": "DeviceProduction", + "foreignKey": "deviceProductionFk" + }, + "user": { + "type": "belongsTo", + "model": "User", + "foreignKey": "userFk" + } + } +} diff --git a/modules/worker/back/models/device-production.json b/modules/worker/back/models/device-production.json new file mode 100644 index 000000000..63672500b --- /dev/null +++ b/modules/worker/back/models/device-production.json @@ -0,0 +1,54 @@ +{ + "name": "DeviceProduction", + "base": "VnModel", + "options": { + "mysql": { + "table": "deviceProduction" + } + }, + "properties": { + "id": { + "type": "number", + "id": true + }, + "imei": { + "type": "string" + }, + "modelFk": { + "type": "number" + }, + "macWifi": { + "type" : "string" + }, + "serialNumber": { + "type" : "string" + }, + "android_id": { + "type" : "string" + }, + "purchased": { + "type" : "date" + }, + "stateFk": { + "type" : "string" + }, + "isInScaleFusion": { + "type" : "boolean" + }, + "description": { + "type" : "string" + } + }, + "relations": { + "model": { + "type": "belongsTo", + "model": "DeviceProductionModels", + "foreignKey": "modelFk" + }, + "state": { + "type": "belongsTo", + "model": "DeviceProductionState", + "foreignKey": "stateFk" + } + } +} diff --git a/modules/worker/back/models/worker.js b/modules/worker/back/models/worker.js index 68baec6ca..fa17640a8 100644 --- a/modules/worker/back/models/worker.js +++ b/modules/worker/back/models/worker.js @@ -14,6 +14,8 @@ module.exports = Self => { require('../methods/worker/holidays')(Self); require('../methods/worker/activeContract')(Self); require('../methods/worker/new')(Self); + require('../methods/worker/deallocatePDA')(Self); + require('../methods/worker/allocatePDA')(Self); Self.validatesUniquenessOf('locker', { message: 'This locker has already been assigned' diff --git a/modules/worker/front/index.js b/modules/worker/front/index.js index 97126407c..657f6a8c6 100644 --- a/modules/worker/front/index.js +++ b/modules/worker/front/index.js @@ -10,6 +10,7 @@ import './descriptor-popover'; import './search-panel'; import './basic-data'; import './pbx'; +import './pda'; import './department'; import './calendar'; import './time-control'; diff --git a/modules/worker/front/locale/es.yml b/modules/worker/front/locale/es.yml index 672f4c52f..b5bcfefa4 100644 --- a/modules/worker/front/locale/es.yml +++ b/modules/worker/front/locale/es.yml @@ -23,4 +23,11 @@ worker: trabajador 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 +This user can't be disabled: Fijado para no deshabilitar +Model: Modelo +Serial Number: Número de serie +Current PDA: PDA Actual +Deallocate PDA: Desasignar PDA +PDA deallocated: PDA desasignada +PDA allocated: PDA asignada +New PDA: Nueva PDA diff --git a/modules/worker/front/pda/index.html b/modules/worker/front/pda/index.html new file mode 100644 index 000000000..b102f616a --- /dev/null +++ b/modules/worker/front/pda/index.html @@ -0,0 +1,48 @@ +
+ + + + + + + + + + +
+
+ + + + + ID: {{id}} + + {{'Model' | translate}}: {{modelFk}} + + {{'Serial Number' | translate}}: {{serialNumber}} + + + + + + + + +
diff --git a/modules/worker/front/pda/index.js b/modules/worker/front/pda/index.js new file mode 100644 index 000000000..885261e5c --- /dev/null +++ b/modules/worker/front/pda/index.js @@ -0,0 +1,53 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; +import './style.scss'; + +class Controller extends Section { + constructor($element, $) { + super($element, $); + const filter = { + where: {userFk: this.$params.id}, + include: {relation: 'deviceProduction'} + }; + this.$http.get('DeviceProductionUsers', {filter}). + then(res => { + if (res.data && res.data.length > 0) + this.setCurrentPDA(res.data[0]); + }); + } + + deallocatePDA() { + this.$http.post(`Workers/${this.$params.id}/deallocatePDA`, {pda: this.currentPDA.deviceProductionFk}) + .then(() => { + this.vnApp.showSuccess(this.$t('PDA deallocated')); + delete this.currentPDA; + }); + } + + allocatePDA() { + this.$http.post(`Workers/${this.$params.id}/allocatePDA`, {pda: this.newPDA}) + .then(res => { + if (res.data) + this.setCurrentPDA(res.data); + + this.vnApp.showSuccess(this.$t('PDA allocated')); + delete this.newPDA; + }); + } + + setCurrentPDA(data) { + this.currentPDA = data; + this.currentPDA.description = []; + this.currentPDA.description.push(`ID: ${this.currentPDA.deviceProductionFk}`); + this.currentPDA.description.push(`${this.$t('Model')}: ${this.currentPDA.deviceProduction.modelFk}`); + this.currentPDA.description.push(`${this.$t('Serial Number')}: ${this.currentPDA.deviceProduction.serialNumber}`); + this.currentPDA.description = this.currentPDA.description.join(' '); + } +} + +Controller.$inject = ['$element', '$scope']; + +ngModule.vnComponent('vnWorkerPda', { + template: require('./index.html'), + controller: Controller, +}); diff --git a/modules/worker/front/pda/index.spec.js b/modules/worker/front/pda/index.spec.js new file mode 100644 index 000000000..a0540af45 --- /dev/null +++ b/modules/worker/front/pda/index.spec.js @@ -0,0 +1,72 @@ +import './index'; + +describe('Worker', () => { + describe('Component vnWorkerPda', () => { + let $httpBackend; + let $scope; + let $element; + let controller; + + beforeEach(ngModule('worker')); + + beforeEach(inject(($componentController, $rootScope, _$httpBackend_) => { + $httpBackend = _$httpBackend_; + $scope = $rootScope.$new(); + $element = angular.element(''); + controller = $componentController('vnWorkerPda', {$element, $scope}); + $httpBackend.expectGET(`DeviceProductionUsers`).respond(); + })); + + describe('deallocatePDA()', () => { + it('should make an HTTP Post query to deallocatePDA', () => { + jest.spyOn(controller.vnApp, 'showSuccess'); + controller.currentPDA = {deviceProductionFk: 1}; + controller.$params.id = 1; + + $httpBackend + .expectPOST(`Workers/${controller.$params.id}/deallocatePDA`, + {pda: controller.currentPDA.deviceProductionFk}) + .respond(); + controller.deallocatePDA(); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.currentPDA).toBeUndefined(); + }); + }); + + describe('allocatePDA()', () => { + it('should make an HTTP Post query to allocatePDA', () => { + jest.spyOn(controller.vnApp, 'showSuccess'); + controller.newPDA = 4; + controller.$params.id = 1; + + $httpBackend + .expectPOST(`Workers/${controller.$params.id}/allocatePDA`, + {pda: controller.newPDA}) + .respond(); + controller.allocatePDA(); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalled(); + expect(controller.newPDA).toBeUndefined(); + }); + }); + + describe('setCurrentPDA()', () => { + it('should set CurrentPDA', () => { + const data = { + deviceProductionFk: 1, + deviceProduction: { + modelFk: 1, + serialNumber: 1 + } + }; + controller.setCurrentPDA(data); + + expect(controller.currentPDA).toBeDefined(); + expect(controller.currentPDA.description).toBeDefined(); + }); + }); + }); +}); diff --git a/modules/worker/front/pda/style.scss b/modules/worker/front/pda/style.scss new file mode 100644 index 000000000..4d9d70953 --- /dev/null +++ b/modules/worker/front/pda/style.scss @@ -0,0 +1,6 @@ +span.separator{ + border-left: 1px solid black; + height: 100%; + margin: 0 10px; +} + diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index dad55512b..1433485c0 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -15,6 +15,7 @@ {"state": "worker.card.calendar", "icon": "icon-calendar"}, {"state": "worker.card.timeControl", "icon": "access_time"}, {"state": "worker.card.dms.index", "icon": "cloud_upload"}, + {"state": "worker.card.pda", "icon": "contact_support"}, { "icon": "icon-wiki", "external":true, @@ -141,6 +142,13 @@ "component": "vn-worker-create", "description": "New worker", "acl": ["hr"] + }, + { + "url": "/pda", + "state": "worker.card.pda", + "component": "vn-worker-pda", + "description": "PDA", + "acl": ["employee"] } ] } -- 2.40.1 From 7a04b0b3de993d3ca557bfa850b5f6584138bbff Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Feb 2023 08:00:18 +0100 Subject: [PATCH 4/6] refs #5287 icon added --- modules/worker/front/routes.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index 1433485c0..329c10818 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -11,11 +11,11 @@ ], "card": [ {"state": "worker.card.basicData", "icon": "settings"}, + {"state": "worker.card.pda", "icon": "phone_android"}, {"state": "worker.card.pbx", "icon": "icon-pbx"}, {"state": "worker.card.calendar", "icon": "icon-calendar"}, {"state": "worker.card.timeControl", "icon": "access_time"}, {"state": "worker.card.dms.index", "icon": "cloud_upload"}, - {"state": "worker.card.pda", "icon": "contact_support"}, { "icon": "icon-wiki", "external":true, -- 2.40.1 From 96e103d76e4823c5a2d8bf7dae59815325ed1d7e Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Feb 2023 08:37:17 +0100 Subject: [PATCH 5/6] refs #5287 sections sorted --- modules/worker/back/methods/worker/allocatePDA.js | 2 +- modules/worker/front/routes.json | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker/allocatePDA.js b/modules/worker/back/methods/worker/allocatePDA.js index 096718c80..8d0d25d2d 100644 --- a/modules/worker/back/methods/worker/allocatePDA.js +++ b/modules/worker/back/methods/worker/allocatePDA.js @@ -2,7 +2,7 @@ const UserError = require('vn-loopback/util/user-error'); module.exports = Self => { Self.remoteMethodCtx('allocatePDA', { - description: 'Deallocate the worker\'s PDA', + description: 'Deallocate the PDA of the worker', accepts: [{ arg: 'id', type: 'number', diff --git a/modules/worker/front/routes.json b/modules/worker/front/routes.json index 329c10818..b96d713ac 100644 --- a/modules/worker/front/routes.json +++ b/modules/worker/front/routes.json @@ -11,10 +11,10 @@ ], "card": [ {"state": "worker.card.basicData", "icon": "settings"}, + {"state": "worker.card.timeControl", "icon": "access_time"}, + {"state": "worker.card.calendar", "icon": "icon-calendar"}, {"state": "worker.card.pda", "icon": "phone_android"}, {"state": "worker.card.pbx", "icon": "icon-pbx"}, - {"state": "worker.card.calendar", "icon": "icon-calendar"}, - {"state": "worker.card.timeControl", "icon": "access_time"}, {"state": "worker.card.dms.index", "icon": "cloud_upload"}, { "icon": "icon-wiki", -- 2.40.1 From d5ea59e284834451385de0c1657eb93ac37b3fd3 Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 28 Feb 2023 12:46:48 +0100 Subject: [PATCH 6/6] =?UTF-8?q?refs=20#5287=20permisos=20a=C3=B1adidos?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- db/changes/230801/00-workerLocker.sql | 18 ++++++++++++------ e2e/paths/03-worker/07_pda.spec.js | 2 +- modules/worker/front/pda/index.html | 3 ++- modules/worker/front/routes.json | 2 +- 4 files changed, 16 insertions(+), 9 deletions(-) diff --git a/db/changes/230801/00-workerLocker.sql b/db/changes/230801/00-workerLocker.sql index 1fcea50ac..0a72cca1e 100644 --- a/db/changes/230801/00-workerLocker.sql +++ b/db/changes/230801/00-workerLocker.sql @@ -1,9 +1,15 @@ ALTER TABLE `vn`.`worker` ADD locker INT UNSIGNED NULL UNIQUE; INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) VALUES - ('DeviceProduction', '*', '*', 'ALLOW', 'ROLE', 'employee'), - ('DeviceProductionModels', '*', '*', 'ALLOW', 'ROLE', 'employee'), - ('DeviceProductionState', '*', '*', 'ALLOW', 'ROLE', 'employee'), - ('DeviceProductionUser', '*', '*', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'deallocatePDA', '*', 'ALLOW', 'ROLE', 'employee'), - ('Worker', 'allocatePDA', '*', 'ALLOW', 'ROLE', 'employee'); + ('DeviceProduction', '*', '*', 'ALLOW', 'ROLE', 'hr'), + ('DeviceProductionModels', '*', '*', 'ALLOW', 'ROLE', 'hr'), + ('DeviceProductionState', '*', '*', 'ALLOW', 'ROLE', 'hr'), + ('DeviceProductionUser', '*', '*', 'ALLOW', 'ROLE', 'hr'), + ('DeviceProduction', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), + ('DeviceProductionModels', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), + ('DeviceProductionState', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), + ('DeviceProductionUser', '*', '*', 'ALLOW', 'ROLE', 'productionAssi'), + ('Worker', 'deallocatePDA', '*', 'ALLOW', 'ROLE', 'hr'), + ('Worker', 'allocatePDA', '*', 'ALLOW', 'ROLE', 'hr'), + ('Worker', 'deallocatePDA', '*', 'ALLOW', 'ROLE', 'productionAssi'), + ('Worker', 'allocatePDA', '*', 'ALLOW', 'ROLE', 'productionAssi'); diff --git a/e2e/paths/03-worker/07_pda.spec.js b/e2e/paths/03-worker/07_pda.spec.js index f583a9e4f..2b743823e 100644 --- a/e2e/paths/03-worker/07_pda.spec.js +++ b/e2e/paths/03-worker/07_pda.spec.js @@ -7,7 +7,7 @@ describe('Worker pda path', () => { beforeAll(async() => { browser = await getBrowser(); page = browser.page; - await page.loginAndModule('employee', 'worker'); + await page.loginAndModule('hr', 'worker'); await page.accessToSearchResult('employeeNick'); await page.accessToSection('worker.card.pda'); }); diff --git a/modules/worker/front/pda/index.html b/modules/worker/front/pda/index.html index b102f616a..2f1626ba8 100644 --- a/modules/worker/front/pda/index.html +++ b/modules/worker/front/pda/index.html @@ -10,7 +10,7 @@ icon="delete" vn-tooltip="Deallocate PDA" ng-click="$ctrl.deallocatePDA()" - vn-acl="employee"> + vn-acl="hr, productionAssi"> @@ -21,6 +21,7 @@