From 19371fbb419c0ec86c4d719f7520eb73ab275ded Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Tue, 19 Nov 2019 14:52:38 +0100 Subject: [PATCH 1/4] 1772-campaign_metrics refactor --- print/boot.js | 1 - print/templates/email/printer-setup/printer-setup.js | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/print/boot.js b/print/boot.js index 4067c9e7b..ae604db2c 100644 --- a/print/boot.js +++ b/print/boot.js @@ -19,7 +19,6 @@ module.exports = app => { require('./core/database').init(); // Init SMTP Instance require('./core/smtp').init(); - // require('./core/mixins'); require('./core/filters'); require('./core/directives'); diff --git a/print/templates/email/printer-setup/printer-setup.js b/print/templates/email/printer-setup/printer-setup.js index 12a2b14c9..86ae0044a 100755 --- a/print/templates/email/printer-setup/printer-setup.js +++ b/print/templates/email/printer-setup/printer-setup.js @@ -29,7 +29,7 @@ module.exports = { LEFT JOIN worker w ON w.id = c.salesPersonFk LEFT JOIN account.user wu ON wu.id = w.userFk WHERE c.id = ?`, [clientId]); - }, + } }, components: { 'email-header': emailHeader.build(), From 52a8d5e0c2bcb2300a1b0cb5a6323115e76c3266 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 21 Nov 2019 09:19:03 +0100 Subject: [PATCH 2/4] #1891 tests for worker time control function --- .../00-workerTimeControlAdd.sql | 73 +++++++++++++++++++ db/dump/fixtures.sql | 10 +-- .../worker-time-control/addTimeEntry.js | 4 +- .../specs/timeEntry.spec.js | 19 ++--- 4 files changed, 87 insertions(+), 19 deletions(-) create mode 100644 db/changes/10110-postCampaign/00-workerTimeControlAdd.sql diff --git a/db/changes/10110-postCampaign/00-workerTimeControlAdd.sql b/db/changes/10110-postCampaign/00-workerTimeControlAdd.sql new file mode 100644 index 000000000..c2091ff83 --- /dev/null +++ b/db/changes/10110-postCampaign/00-workerTimeControlAdd.sql @@ -0,0 +1,73 @@ +DROP function IF EXISTS `vn`.`workerTimeControl_add`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` FUNCTION `vn`.`workerTimeControl_add`( vUserFk INT, vWarehouseFk INT, vTimed DATETIME, vIsManual BOOL) RETURNS int(11) + DETERMINISTIC +BEGIN + DECLARE vDirection VARCHAR(6); + DECLARE vLastIn DATETIME; + DECLARE vDayStayMax INT; + DECLARE vHasDirectionOut INT; + DECLARE vLastInsertedId INT; + + SELECT dayStayMax INTO vDayStayMax + FROM workerTimeControlParams; + + SELECT timeWorkerControl_getDirection(vUserFk,vTimed) INTO vDirection; + + IF vDirection = 'out' THEN + + SELECT MAX(timed) INTO vLastIn + FROM workerTimeControl + WHERE userFk = vUserFk + AND direction = 'in' + AND timed < vTimed; + + UPDATE workerTimeControl wtc + SET wtc.direction = 'middle' + WHERE userFk = vUserFk + AND direction = 'out' + AND timed BETWEEN vLastIn AND vTimed; + + ELSE IF vDirection = 'in' THEN + + SELECT COUNT(*) INTO vHasDirectionOut + FROM workerTimeControl wtc + WHERE userFk = vUserFk + AND direction = 'out' + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + + UPDATE workerTimeControl wtc + SET wtc.direction = IF (vHasDirectionOut,'middle','out') + WHERE userFk = vUserFk + AND direction = 'in' + AND timed BETWEEN vTimed AND TIMESTAMPADD(SECOND, 50400, vTimed); + + END IF; + END IF; + + INSERT INTO workerTimeControl(userFk, timed, warehouseFk, direction, manual) + VALUES(vUserFk, vTimed, vWarehouseFk, vDirection, vIsManual); + + SET vLastInsertedId = LAST_INSERT_ID(); + + CALL workerTimeControlSOWP(vUserFk, vTimed); + + RETURN vLastInsertedId; +END$$ + +DELIMITER ; + + + +DROP procedure IF EXISTS `vn`.`workerTimeControl_add`; + +DELIMITER $$ +CREATE DEFINER=`root`@`%` PROCEDURE `vn`.`workerTimeControl_add`(IN vUserFk INT, IN vWarehouseFk INT, IN vTimed DATETIME, IN vIsManual BOOL) +BEGIN + + + SELECT workerTimeControl_add(vUserFk,vWarehouseFk,vTimed,vIsManual); +END$$ + +DELIMITER ; \ No newline at end of file diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 21413d329..ea13c8763 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1830,12 +1830,12 @@ INSERT INTO `vn`.`zoneEvent`(`zoneFk`, `type`, `dated`) (8, 'day', DATE_ADD(CURDATE(), INTERVAL +5 DAY)), (8, 'day', DATE_ADD(CURDATE(), INTERVAL +6 DAY)); -INSERT INTO `vn`.`workerTimeControl`(`userFk`,`timed`,`manual`, `direction`) +INSERT INTO `vn`.`workerTimeControl`(`userFk`, `timed`, `order`, `manual`, `direction`) VALUES - (106, CONCAT(CURDATE(), ' 07:00'), TRUE, 'in'), - (106, CONCAT(CURDATE(), ' 10:00'), TRUE, 'middle'), - (106, CONCAT(CURDATE(), ' 10:10'), TRUE, 'middle'), - (106, CONCAT(CURDATE(), ' 15:00'), TRUE, 'out'); + (106, CONCAT(CURDATE(), ' 07:00'), 1, TRUE, 'in'), + (106, CONCAT(CURDATE(), ' 10:00'), 2, TRUE, 'middle'), + (106, CONCAT(CURDATE(), ' 10:10'), 3, TRUE, 'middle'), + (106, CONCAT(CURDATE(), ' 15:00'), 4, TRUE, 'out'); INSERT INTO `vn`.`dmsType`(`id`, `name`, `path`, `readRoleFk`, `writeRoleFk`, `code`) VALUES diff --git a/modules/worker/back/methods/worker-time-control/addTimeEntry.js b/modules/worker/back/methods/worker-time-control/addTimeEntry.js index 649364151..86030d713 100644 --- a/modules/worker/back/methods/worker-time-control/addTimeEntry.js +++ b/modules/worker/back/methods/worker-time-control/addTimeEntry.js @@ -34,7 +34,9 @@ module.exports = Self => { const subordinate = await Worker.findById(data.workerFk); const timed = new Date(data.timed); - return Self.rawSql('CALL vn.workerTimeControl_add(?, ?, ?, ?)', [ + let [result] = await Self.rawSql('SELECT vn.workerTimeControl_add(?, ?, ?, ?) AS id', [ subordinate.userFk, null, timed, true]); + + return result; }; }; diff --git a/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js b/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js index bcc15225a..ff5e13a2d 100644 --- a/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/timeEntry.spec.js @@ -1,7 +1,8 @@ const app = require('vn-loopback/server/server'); describe('workerTimeControl addTimeEntry()', () => { - let insertedTime; + let timeEntry; + let createdTimeEntry; it('should fail to add a time entry if the target user is not a subordinate', async() => { let error; @@ -52,11 +53,9 @@ describe('workerTimeControl addTimeEntry()', () => { timed: todayAtSix }; - await app.models.WorkerTimeControl.addTimeEntry(ctx, data); + timeEntry = await app.models.WorkerTimeControl.addTimeEntry(ctx, data); - insertedTime = await app.models.WorkerTimeControl.findOne({where: {timed: data.timed}}); - - let createdTimeEntry = await app.models.WorkerTimeControl.findById(insertedTime.id); + createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); expect(createdTimeEntry).toBeDefined(); }); @@ -66,10 +65,6 @@ describe('workerTimeControl addTimeEntry()', () => { let teamBossId = 13; let ctx = {req: {accessToken: {userId: teamBossId}}}; - let createdTimeEntry = await app.models.WorkerTimeControl.findById(insertedTime.id); - - expect(createdTimeEntry).toBeDefined(); - try { await app.models.WorkerTimeControl.deleteTimeEntry(ctx, createdTimeEntry.id); } catch (e) { @@ -85,14 +80,12 @@ describe('workerTimeControl addTimeEntry()', () => { let HHRRId = 37; let ctx = {req: {accessToken: {userId: HHRRId}}}; - let createdTimeEntry = await app.models.WorkerTimeControl.findById(insertedTime.id); - expect(createdTimeEntry).toBeDefined(); ctx.req.accessToken.userId = HHRRId; - await app.models.WorkerTimeControl.deleteTimeEntry(ctx, insertedTime.id); + await app.models.WorkerTimeControl.deleteTimeEntry(ctx, timeEntry.id); - createdTimeEntry = await app.models.WorkerTimeControl.findById(insertedTime.id); + createdTimeEntry = await app.models.WorkerTimeControl.findById(timeEntry.id); expect(createdTimeEntry).toBeNull(); }); From 6a0783d22fdc522b85432619469a22ced8988666 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 21 Nov 2019 11:16:10 +0100 Subject: [PATCH 3/4] #1891 tests for worker time control function --- front/core/components/tooltip/tooltip.spec.js | 26 +++++++++++-------- modules/worker/front/time-control/index.html | 7 +++-- modules/worker/front/time-control/style.scss | 1 + 3 files changed, 19 insertions(+), 15 deletions(-) diff --git a/front/core/components/tooltip/tooltip.spec.js b/front/core/components/tooltip/tooltip.spec.js index 15595c61b..feec7c62a 100644 --- a/front/core/components/tooltip/tooltip.spec.js +++ b/front/core/components/tooltip/tooltip.spec.js @@ -1,7 +1,6 @@ import './tooltip'; -// #1615 migrar karma a jest -xdescribe('Component vnTooltip', () => { +describe('Component vnTooltip', () => { let $element; let controller; let $parent; @@ -21,8 +20,8 @@ xdescribe('Component vnTooltip', () => { $parent.css({ backgroundColor: 'red', position: 'absolute', - width: '10px', - height: '10px', + width: '100px', + height: '100px', top: '0', left: '0' }); @@ -36,13 +35,13 @@ xdescribe('Component vnTooltip', () => { describe('show()', () => { it(`should check that tooltip is visible into the screen`, () => { + expect(element.classList).not.toContain('show'); + controller.show($parent[0]); let rect = element.getBoundingClientRect(); - let style = window.getComputedStyle(element); - expect(style.visibility).toEqual('visible'); - expect(style.display).not.toEqual('none'); + expect(element.classList).toContain('show'); expect(0).toBeLessThanOrEqual(rect.top); expect(0).toBeLessThanOrEqual(rect.left); @@ -54,14 +53,16 @@ xdescribe('Component vnTooltip', () => { describe('hide()', () => { it(`should check that tooltip is not visible`, () => { controller.show($parent[0]); - controller.hide(); - let style = window.getComputedStyle(element); - expect(style.display).toEqual('none'); + expect(element.classList).toContain('show'); + controller.hide(); + + expect(element.classList).not.toContain('show'); }); }); - describe('relocate()', () => { + // #1892 reparar unitarios front tooltip.js + xdescribe('relocate()', () => { it(`should reallocate tooltip on top-left`, () => { controller.show($parent[0]); let rect = element.getBoundingClientRect(); @@ -117,3 +118,6 @@ xdescribe('Component vnTooltip', () => { }); }); }); + +['onafterprint', 'onbeforeprint', 'onbeforeunload', 'onhashchange', 'onlanguagechange', 'onmessage', 'onmessageerror', 'onoffline', 'ononline', 'onpagehide', 'onpageshow', 'onpopstate', 'onrejectionhandled', 'onstorage', 'onunhandledrejection', 'onunload', 'onblur', 'onerror', 'onfocus', 'onload', 'onresize', 'onscroll', 'onabort', 'onautocomplete', 'onautocompleteerror', 'oncancel', 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick', 'onclose', 'oncontextmenu', 'oncuechange', 'ondblclick', 'ondrag', 'ondragend', 'ondragenter', 'ondragexit', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended', 'oninput', 'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup', 'onloadeddata', 'onloadedmetadata', 'onloadstart', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onwheel', 'onpause', 'onplay', 'onplaying', 'onprogress', 'onratechange', 'onreset', 'onsecuritypolicyviolation', 'onseeked', 'onseeking', 'onselect', 'onsort', 'onstalled', 'onsubmit', 'onsuspend', 'ontimeupdate', 'ontoggle', 'onvolumechange', 'onwaiting', '_registeredHandlers', '_eventHandlers', '_globalProxy', '_document', '_sessionHistory', '_virtualConsole', '_runScripts', '_top', '_parent', '_frameElement', '_length', '_pretendToBeVisual', '_storageQuota', '_commonForOrigin', '_currentOriginData', '_localStorage', '_sessionStorage', 'length', 'window', 'frameElement', 'frames', 'self', 'parent', 'top', 'document', 'external', 'location', 'history', 'navigator', 'locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', 'toolbar', 'performance', 'screen', 'localStorage', 'sessionStorage', 'addEventListener', 'removeEventListener', 'dispatchEvent', 'setTimeout', 'setInterval', 'clearInterval', 'clearTimeout', 'requestAnimationFrame', 'cancelAnimationFrame', '__stopAllTimers', 'postMessage', 'atob', 'btoa', 'FileReader', 'WebSocket', 'AbortSignal', 'AbortController', 'XMLHttpRequest', 'ArrayBuffer', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'stop', 'close', 'getComputedStyle', 'captureEvents', 'releaseEvents', 'console', 'name', 'devicePixelRatio', 'innerWidth', 'innerHeight', 'outerWidth', 'outerHeight', 'pageXOffset', 'pageYOffset', 'screenX', 'screenY', 'scrollX', 'scrollY', 'screenLeft', 'screenTop', 'alert', 'blur', 'confirm', 'focus', 'moveBy', 'moveTo', 'open', 'print', 'prompt', 'resizeBy', 'resizeTo', 'scroll', 'scrollBy', 'scrollTo', 'process', 'DTRACE_NET_SERVER_CONNECTION', 'DTRACE_NET_STREAM_END', 'DTRACE_HTTP_SERVER_REQUEST', 'DTRACE_HTTP_SERVER_RESPONSE', 'DTRACE_HTTP_CLIENT_REQUEST', 'DTRACE_HTTP_CLIENT_RESPONSE', 'Buffer', 'setImmediate', 'clearImmediate', 'describe', 'xdescribe', 'fdescribe', 'it', 'xit', 'fit', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll', 'pending', 'fail', 'spyOn', 'jsApiReporter', 'jasmine', 'test', 'xtest', 'expect', 'angular', 'module', 'inject', 'browserTrigger', '__core-js_shared__', 'core', 'parseInt', 'parseFloat', 'regeneratorRuntime', '_babelPolyfill', 'magicCrudAngular', 'ngModule'] +; diff --git a/modules/worker/front/time-control/index.html b/modules/worker/front/time-control/index.html index c3700992b..10691d301 100644 --- a/modules/worker/front/time-control/index.html +++ b/modules/worker/front/time-control/index.html @@ -4,7 +4,7 @@ filter="::$ctrl.filter" data="$ctrl.hours"> - + @@ -31,8 +31,8 @@ - -
+ +
{{::hour.timed | date: 'HH:mm'}} diff --git a/modules/worker/front/time-control/style.scss b/modules/worker/front/time-control/style.scss index 5d82c6d31..8555e827b 100644 --- a/modules/worker/front/time-control/style.scss +++ b/modules/worker/front/time-control/style.scss @@ -12,6 +12,7 @@ vn-worker-time-control { & > section { display: flex; align-items: center; + justify-content: center; padding: .3em 0; & > vn-icon { From ac2bab69421b54748bec4522ca48f770bc942219 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez Ruiz Date: Thu, 21 Nov 2019 11:28:35 +0100 Subject: [PATCH 4/4] removed unused code --- front/core/components/tooltip/tooltip.spec.js | 3 --- 1 file changed, 3 deletions(-) diff --git a/front/core/components/tooltip/tooltip.spec.js b/front/core/components/tooltip/tooltip.spec.js index feec7c62a..74cb410ff 100644 --- a/front/core/components/tooltip/tooltip.spec.js +++ b/front/core/components/tooltip/tooltip.spec.js @@ -118,6 +118,3 @@ describe('Component vnTooltip', () => { }); }); }); - -['onafterprint', 'onbeforeprint', 'onbeforeunload', 'onhashchange', 'onlanguagechange', 'onmessage', 'onmessageerror', 'onoffline', 'ononline', 'onpagehide', 'onpageshow', 'onpopstate', 'onrejectionhandled', 'onstorage', 'onunhandledrejection', 'onunload', 'onblur', 'onerror', 'onfocus', 'onload', 'onresize', 'onscroll', 'onabort', 'onautocomplete', 'onautocompleteerror', 'oncancel', 'oncanplay', 'oncanplaythrough', 'onchange', 'onclick', 'onclose', 'oncontextmenu', 'oncuechange', 'ondblclick', 'ondrag', 'ondragend', 'ondragenter', 'ondragexit', 'ondragleave', 'ondragover', 'ondragstart', 'ondrop', 'ondurationchange', 'onemptied', 'onended', 'oninput', 'oninvalid', 'onkeydown', 'onkeypress', 'onkeyup', 'onloadeddata', 'onloadedmetadata', 'onloadstart', 'onmousedown', 'onmouseenter', 'onmouseleave', 'onmousemove', 'onmouseout', 'onmouseover', 'onmouseup', 'onwheel', 'onpause', 'onplay', 'onplaying', 'onprogress', 'onratechange', 'onreset', 'onsecuritypolicyviolation', 'onseeked', 'onseeking', 'onselect', 'onsort', 'onstalled', 'onsubmit', 'onsuspend', 'ontimeupdate', 'ontoggle', 'onvolumechange', 'onwaiting', '_registeredHandlers', '_eventHandlers', '_globalProxy', '_document', '_sessionHistory', '_virtualConsole', '_runScripts', '_top', '_parent', '_frameElement', '_length', '_pretendToBeVisual', '_storageQuota', '_commonForOrigin', '_currentOriginData', '_localStorage', '_sessionStorage', 'length', 'window', 'frameElement', 'frames', 'self', 'parent', 'top', 'document', 'external', 'location', 'history', 'navigator', 'locationbar', 'menubar', 'personalbar', 'scrollbars', 'statusbar', 'toolbar', 'performance', 'screen', 'localStorage', 'sessionStorage', 'addEventListener', 'removeEventListener', 'dispatchEvent', 'setTimeout', 'setInterval', 'clearInterval', 'clearTimeout', 'requestAnimationFrame', 'cancelAnimationFrame', '__stopAllTimers', 'postMessage', 'atob', 'btoa', 'FileReader', 'WebSocket', 'AbortSignal', 'AbortController', 'XMLHttpRequest', 'ArrayBuffer', 'Int8Array', 'Uint8Array', 'Uint8ClampedArray', 'Int16Array', 'Uint16Array', 'Int32Array', 'Uint32Array', 'Float32Array', 'Float64Array', 'stop', 'close', 'getComputedStyle', 'captureEvents', 'releaseEvents', 'console', 'name', 'devicePixelRatio', 'innerWidth', 'innerHeight', 'outerWidth', 'outerHeight', 'pageXOffset', 'pageYOffset', 'screenX', 'screenY', 'scrollX', 'scrollY', 'screenLeft', 'screenTop', 'alert', 'blur', 'confirm', 'focus', 'moveBy', 'moveTo', 'open', 'print', 'prompt', 'resizeBy', 'resizeTo', 'scroll', 'scrollBy', 'scrollTo', 'process', 'DTRACE_NET_SERVER_CONNECTION', 'DTRACE_NET_STREAM_END', 'DTRACE_HTTP_SERVER_REQUEST', 'DTRACE_HTTP_SERVER_RESPONSE', 'DTRACE_HTTP_CLIENT_REQUEST', 'DTRACE_HTTP_CLIENT_RESPONSE', 'Buffer', 'setImmediate', 'clearImmediate', 'describe', 'xdescribe', 'fdescribe', 'it', 'xit', 'fit', 'beforeEach', 'afterEach', 'beforeAll', 'afterAll', 'pending', 'fail', 'spyOn', 'jsApiReporter', 'jasmine', 'test', 'xtest', 'expect', 'angular', 'module', 'inject', 'browserTrigger', '__core-js_shared__', 'core', 'parseInt', 'parseFloat', 'regeneratorRuntime', '_babelPolyfill', 'magicCrudAngular', 'ngModule'] -;