From 993ae11277c7a96171a0408a0f9231b699f58172 Mon Sep 17 00:00:00 2001 From: Juan Ferrer Toribio Date: Wed, 9 Nov 2022 09:19:56 +0100 Subject: [PATCH 1/6] refs #3302 --- front/salix/components/log/index.html | 55 ++++++++++++--------------- front/salix/components/log/index.js | 31 ++++++++++++--- front/salix/components/log/style.scss | 18 ++++++++- 3 files changed, 68 insertions(+), 36 deletions(-) diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index 0a0449038..ecee89097 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -1,10 +1,10 @@ - @@ -13,12 +13,11 @@ Date - Author + User Model Action Name - Before - After + Changes @@ -62,27 +61,23 @@ {{::log.changedModelValue}} - - -
- - -
-
-
- -
- - -
-
+ + + + + + + + + + + + + + + +
FieldBeforeAfter
{{prop.name}}{{::$ctrl.formatValue(prop.old)}}{{::$ctrl.formatValue(prop.new)}}
{{::log.description}} @@ -96,4 +91,4 @@ - \ No newline at end of file + diff --git a/front/salix/components/log/index.js b/front/salix/components/log/index.js index c5a4febcc..d7619e34c 100644 --- a/front/salix/components/log/index.js +++ b/front/salix/components/log/index.js @@ -33,12 +33,33 @@ export default class Controller extends Section { set logs(value) { this._logs = value; + if (!this.logs) return; + for (const log of value) { + // log.oldProperties = this.getInstance(log.oldInstance); + // log.newProperties = this.getInstance(log.newInstance); - if (this.logs) { - this.logs.forEach(log => { - log.oldProperties = this.getInstance(log.oldInstance); - log.newProperties = this.getInstance(log.newInstance); - }); + let props = [].concat( + Object.keys(log.oldInstance), + Object.keys(log.newInstance) + ); + props = [...new Set(props)]; + log.props = []; + for (const prop of props) { + log.props.push({ + name: prop, + old: log.oldInstance[prop], + new: log.newInstance[prop] + }); + } + } + } + + formatValue(value) { + switch (typeof value) { + case 'boolean': + return value ? '✓' : '✗'; + default: + return value; } } diff --git a/front/salix/components/log/style.scss b/front/salix/components/log/style.scss index ca1de113a..58e4b8e3f 100644 --- a/front/salix/components/log/style.scss +++ b/front/salix/components/log/style.scss @@ -23,6 +23,22 @@ vn-log { display: block; } } + .attributes { + width: 100%; + + tr { + height: 10px; + + & > td { + padding: 2px; + width: 33%; + } + & > td.field, + & > th.field { + color: gray; + } + } + } } .ellipsis { white-space: nowrap; @@ -40,4 +56,4 @@ vn-log { .alignSpan { overflow: hidden; display: inline-block; -} \ No newline at end of file +} -- 2.40.1 From 569a0e8cc9bfd84b1f5cda385d212e86862f1501 Mon Sep 17 00:00:00 2001 From: alexandre Date: Mon, 5 Dec 2022 15:30:41 +0100 Subject: [PATCH 2/6] refs #3302 log modified and fixed e2e tests --- db/dump/fixtures.sql | 6 +-- e2e/helpers/selectors.js | 21 ++++---- .../02-client/07_edit_web_access.spec.js | 24 ++++----- e2e/paths/02-client/13_log.spec.js | 4 +- .../05-ticket/02_expeditions_and_log.spec.js | 11 +++-- e2e/paths/05-ticket/17_log.spec.js | 2 +- e2e/paths/13-supplier/02_basic_data.spec.js | 4 +- front/salix/components/log/index.html | 49 ++++++------------- front/salix/components/log/index.js | 20 ++++---- front/salix/components/log/locale/es.yml | 3 +- 10 files changed, 65 insertions(+), 79 deletions(-) diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 92b84be43..fe05faadd 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1332,9 +1332,9 @@ INSERT INTO `vn`.`itemTypeTag`(`id`, `itemTypeFk`, `tagFk`, `priority`) CALL `vn`.`itemRefreshTags`(NULL); -INSERT INTO `vn`.`itemLog` (`id`, `originFk`, `userFk`, `action`, `description`) +INSERT INTO `vn`.`itemLog` (`id`, `originFk`, `userFk`, `action`, `description`, `changedModel`, `oldInstance`, `newInstance`, `changedModelId`, `changedModelValue`) VALUES - ('1', '1', '1', 'insert', 'We made a change!'); + ('1', '1', '1', 'insert', 'We made a change!', 'Item', '{}', '{}', 1, '1'); INSERT INTO `vn`.`recovery`(`id`, `clientFk`, `started`, `finished`, `amount`, `period`) VALUES @@ -2731,4 +2731,4 @@ INSERT INTO `vn`.`osTicketConfig` (`id`, `host`, `user`, `password`, `oldStatus` INSERT INTO `vn`.`ticketLog` (`id`, `originFk`, `userFk`, `action`, `changedModel`, `oldInstance`, `newInstance`, `changedModelId`) VALUES - (1, 1, 9, 'insert', 'Ticket', '{}', '{"clientFk":1, "nickname": "Bat cave"}', 1); \ No newline at end of file + (1, 1, 9, 'insert', 'Ticket', '{}', '{"clientFk":1, "nickname": "Bat cave"}', 1); diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index f550e3a9d..e374e266e 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -311,10 +311,12 @@ export default { firstMandateText: 'vn-client-mandate vn-card vn-table vn-tbody > vn-tr' }, clientLog: { - lastModificationPreviousValue: 'vn-client-log vn-table vn-td.before', - lastModificationCurrentValue: 'vn-client-log vn-table vn-td.after', - penultimateModificationPreviousValue: 'vn-client-log vn-table vn-tr:nth-child(2) vn-td.before', - penultimateModificationCurrentValue: 'vn-client-log vn-table vn-tr:nth-child(2) vn-td.after' + lastModificationPreviousValue: 'vn-client-log vn-tr table tr td.before', + lastModificationCurrentValue: 'vn-client-log vn-tr table tr td.after', + namePreviousValue: 'vn-client-log vn-tr table tr:nth-child(1) td.before', + nameCurrentValue: 'vn-client-log vn-tr table tr:nth-child(1) td.after', + activePreviousValue: 'vn-client-log vn-tr:nth-child(2) table tr:nth-child(2) td.before', + activeCurrentValue: 'vn-client-log vn-tr:nth-child(2) table tr:nth-child(2) td.after' }, clientBalance: { @@ -518,7 +520,7 @@ export default { }, itemLog: { anyLineCreated: 'vn-item-log > vn-log vn-tbody > vn-tr', - fifthLineCreatedProperty: 'vn-item-log > vn-log vn-tbody > vn-tr:nth-child(5) > vn-td > vn-one:nth-child(3) > div span:nth-child(2)', + fifthLineCreatedProperty: 'vn-item-log > vn-log vn-tbody > vn-tr:nth-child(5) table tr:nth-child(3) td.after', }, ticketSummary: { header: 'vn-ticket-summary > vn-card > h5', @@ -711,9 +713,10 @@ export default { ticketLog: { firstTD: 'vn-ticket-log vn-table vn-td:nth-child(1)', logButton: 'vn-left-menu a[ui-sref="ticket.card.log"]', - firstLogEntry: 'vn-ticket-log vn-data-viewer vn-tbody vn-tr', - changes: 'vn-ticket-log vn-data-viewer vn-tbody > vn-tr > vn-td:nth-child(7)', - id: 'vn-ticket-log vn-tr:nth-child(1) vn-one:nth-child(1) span' + user: 'vn-ticket-log vn-tbody vn-tr vn-td:nth-child(2)', + action: 'vn-ticket-log vn-tbody vn-tr vn-td:nth-child(4)', + changes: 'vn-ticket-log vn-data-viewer vn-tbody vn-tr table tr:nth-child(2) td.after', + id: 'vn-ticket-log vn-tr:nth-child(1) table tr:nth-child(1) td.before' }, ticketService: { addServiceButton: 'vn-ticket-service vn-icon-button[vn-tooltip="Add service"] > button', @@ -1100,7 +1103,7 @@ export default { undoChanges: 'vn-travel-basic-data vn-button[label="Undo changes"]' }, travelLog: { - firstLogFirstTD: 'vn-travel-log vn-tbody > vn-tr > vn-td:nth-child(1) > div' + firstLogFirstTD: 'vn-travel-log vn-tbody > vn-tr > vn-td:nth-child(5)' }, travelThermograph: { add: 'vn-travel-thermograph-index vn-float-button[icon="add"]', diff --git a/e2e/paths/02-client/07_edit_web_access.spec.js b/e2e/paths/02-client/07_edit_web_access.spec.js index 3d9ccee62..29b39f788 100644 --- a/e2e/paths/02-client/07_edit_web_access.spec.js +++ b/e2e/paths/02-client/07_edit_web_access.spec.js @@ -67,22 +67,22 @@ describe('Client Edit web access path', () => { }); it(`should confirm the last log shows the updated client name and no modifications on active checkbox`, async() => { - let lastModificationPreviousValue = await page - .waitToGetProperty(selectors.clientLog.lastModificationPreviousValue, 'innerText'); - let lastModificationCurrentValue = await page - .waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText'); + let namePreviousValue = await page + .waitToGetProperty(selectors.clientLog.namePreviousValue, 'innerText'); + let nameCurrentValue = await page + .waitToGetProperty(selectors.clientLog.nameCurrentValue, 'innerText'); - expect(lastModificationPreviousValue).toEqual('name MaxEisenhardt active false'); - expect(lastModificationCurrentValue).toEqual('name Legion active false'); + expect(namePreviousValue).toEqual('MaxEisenhardt'); + expect(nameCurrentValue).toEqual('Legion'); }); it(`should confirm the penultimate log shows the updated active and no modifications on client name`, async() => { - let penultimateModificationPreviousValue = await page - .waitToGetProperty(selectors.clientLog.penultimateModificationPreviousValue, 'innerText'); - let penultimateModificationCurrentValue = await page - .waitToGetProperty(selectors.clientLog.penultimateModificationCurrentValue, 'innerText'); + let activePreviousValue = await page + .waitToGetProperty(selectors.clientLog.activePreviousValue, 'innerText'); + let activeCurrentValue = await page + .waitToGetProperty(selectors.clientLog.activeCurrentValue, 'innerText'); - expect(penultimateModificationPreviousValue).toEqual('name MaxEisenhardt active true'); - expect(penultimateModificationCurrentValue).toEqual('name MaxEisenhardt active false'); + expect(activePreviousValue).toEqual('✓'); + expect(activeCurrentValue).toEqual('✗'); }); }); diff --git a/e2e/paths/02-client/13_log.spec.js b/e2e/paths/02-client/13_log.spec.js index 9b047a47c..8f186d842 100644 --- a/e2e/paths/02-client/13_log.spec.js +++ b/e2e/paths/02-client/13_log.spec.js @@ -43,7 +43,7 @@ describe('Client log path', () => { let lastModificationCurrentValue = await page. waitToGetProperty(selectors.clientLog.lastModificationCurrentValue, 'innerText'); - expect(lastModificationPreviousValue).toEqual('name DavidCharlesHaller'); - expect(lastModificationCurrentValue).toEqual('name this is a test'); + expect(lastModificationPreviousValue).toEqual('DavidCharlesHaller'); + expect(lastModificationCurrentValue).toEqual('this is a test'); }); }); diff --git a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js index f970247e5..ae5e2fb0c 100644 --- a/e2e/paths/05-ticket/02_expeditions_and_log.spec.js +++ b/e2e/paths/05-ticket/02_expeditions_and_log.spec.js @@ -32,14 +32,17 @@ describe('Ticket expeditions and log path', () => { it(`should confirm the expedition deleted is shown now in the ticket log`, async() => { await page.accessToSection('ticket.card.log'); - const firstLogEntry = await page - .waitToGetProperty(selectors.ticketLog.firstLogEntry, 'innerText'); + const user = await page + .waitToGetProperty(selectors.ticketLog.user, 'innerText'); + + const action = await page + .waitToGetProperty(selectors.ticketLog.action, 'innerText'); const id = await page .waitToGetProperty(selectors.ticketLog.id, 'innerText'); - expect(firstLogEntry).toContain('production'); - expect(firstLogEntry).toContain('Deletes'); + expect(user).toContain('production'); + expect(action).toContain('Deletes'); expect(id).toEqual('2'); }); }); diff --git a/e2e/paths/05-ticket/17_log.spec.js b/e2e/paths/05-ticket/17_log.spec.js index 399eb647b..32829ee74 100644 --- a/e2e/paths/05-ticket/17_log.spec.js +++ b/e2e/paths/05-ticket/17_log.spec.js @@ -55,6 +55,6 @@ describe('Ticket log path', () => { const result = await page.waitToGetProperty(selectors.ticketLog.firstTD, 'innerText'); - expect(result.length).toBeGreaterThan('20'); + expect(result.length).toBeGreaterThan('15'); }); }); diff --git a/e2e/paths/13-supplier/02_basic_data.spec.js b/e2e/paths/13-supplier/02_basic_data.spec.js index 4f3c49512..9d86e11d4 100644 --- a/e2e/paths/13-supplier/02_basic_data.spec.js +++ b/e2e/paths/13-supplier/02_basic_data.spec.js @@ -70,8 +70,8 @@ describe('Supplier basic data path', () => { }); it('should check the changes have been recorded', async() => { - const result = await page.waitToGetProperty('#newInstance:nth-child(3)', 'innerText'); + const result = await page.waitToGetProperty('vn-tr table tr:nth-child(3) td.after', 'innerText'); - expect(result).toEqual('note Some notes'); + expect(result).toEqual('Some notes'); }); }); diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index ecee89097..0b4dabf74 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -13,10 +13,10 @@ Date - User - Model - Action - Name + User + Model + Action + Name Changes @@ -24,57 +24,36 @@ {{::log.creationDate | date:'dd/MM/yyyy HH:mm'}} -
-
- Changed by: - {{::log.user.name || 'System' | translate}} - -
-
- Model: - {{::log.changedModel | dashIfEmpty}} -
-
- Action: - {{::$ctrl.actionsText[log.action] | dashIfEmpty}} -
-
- Name: - {{::log.changedModelValue | dashIfEmpty}} -
-
- + {{::log.user.name || 'System' | translate}} - + {{::log.changedModel}} - + {{::$ctrl.actionsText[log.action]}} - + {{::log.changedModelValue}} - + - - - + + + - - + +
FieldBeforeAfterFieldBeforeAfter
{{prop.name}}{{::$ctrl.formatValue(prop.old)}}{{::$ctrl.formatValue(prop.new)}}{{::$ctrl.formatValue(prop.old)}}{{::$ctrl.formatValue(prop.new)}}
diff --git a/front/salix/components/log/index.js b/front/salix/components/log/index.js index 5546668d2..decdfbc3a 100644 --- a/front/salix/components/log/index.js +++ b/front/salix/components/log/index.js @@ -34,21 +34,22 @@ export default class Controller extends Section { set logs(value) { this._logs = value; if (!this.logs) return; + const validations = window.validations; for (const log of value) { - // log.oldProperties = this.getInstance(log.oldInstance); - // log.newProperties = this.getInstance(log.newInstance); - - let props = [].concat( - Object.keys(log.oldInstance), - Object.keys(log.newInstance) - ); + const locale = validations[log.changedModel] && validations[log.changedModel].locale + ? validations[log.changedModel].locale : {}; + log.oldProperties = this.getInstance(log.oldInstance, locale); + log.newProperties = this.getInstance(log.newInstance, locale); + let props = [].concat(log.oldProperties.map(p => p.key), log.newProperties.map(p => p.key)); props = [...new Set(props)]; log.props = []; for (const prop of props) { + const matchOldProp = log.oldProperties.find(p => p.key === prop); + const matchNewProp = log.newProperties.find(p => p.key === prop); log.props.push({ name: prop, - old: log.oldInstance[prop], - new: log.newInstance[prop] + old: matchOldProp ? matchOldProp.value : null, + new: matchNewProp ? matchNewProp.value : null, }); } } @@ -71,7 +72,6 @@ export default class Controller extends Section { Object.keys(instance).forEach(property => { if (validDate.test(instance[property])) instance[property] = new Date(instance[property]).toLocaleString('es-ES'); - const key = locale[property] || property; properties.push({key, value: instance[property]}); }); diff --git a/front/salix/components/log/locale/es.yml b/front/salix/components/log/locale/es.yml index f483bea5e..d341095d8 100644 --- a/front/salix/components/log/locale/es.yml +++ b/front/salix/components/log/locale/es.yml @@ -11,4 +11,5 @@ Updates: Actualiza Deletes: Elimina Views: Visualiza System: Sistema -note: nota \ No newline at end of file +note: nota +Changes: Cambios -- 2.40.1 From 92a961ecc92456b67c2c5567985a820f149923cc Mon Sep 17 00:00:00 2001 From: alexandre Date: Thu, 15 Dec 2022 14:24:57 +0100 Subject: [PATCH 3/6] refs #3302 refactor --- front/salix/components/log/index.html | 12 +++---- front/salix/components/log/index.js | 48 ++++++++++++--------------- 2 files changed, 26 insertions(+), 34 deletions(-) diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index 0b4dabf74..eb6e4223e 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -52,16 +52,14 @@ {{prop.name}} - {{::$ctrl.formatValue(prop.old)}} - {{::$ctrl.formatValue(prop.new)}} + {{prop.old}} + {{prop.new}} - -
- {{::log.description}} -
-
+
+ {{::log.description}} +
diff --git a/front/salix/components/log/index.js b/front/salix/components/log/index.js index decdfbc3a..75249d1ee 100644 --- a/front/salix/components/log/index.js +++ b/front/salix/components/log/index.js @@ -2,6 +2,8 @@ import ngModule from '../../module'; import Section from '../section'; import './style.scss'; +const validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; + export default class Controller extends Section { constructor($element, $) { super($element, $); @@ -10,7 +12,7 @@ export default class Controller extends Section { 'update': 'Updates', 'delete': 'Deletes', 'select': 'Views' - }; ``; + }; this.filter = { include: [{ relation: 'user', @@ -34,52 +36,44 @@ export default class Controller extends Section { set logs(value) { this._logs = value; if (!this.logs) return; + const empty = {}; const validations = window.validations; for (const log of value) { - const locale = validations[log.changedModel] && validations[log.changedModel].locale - ? validations[log.changedModel].locale : {}; - log.oldProperties = this.getInstance(log.oldInstance, locale); - log.newProperties = this.getInstance(log.newInstance, locale); - let props = [].concat(log.oldProperties.map(p => p.key), log.newProperties.map(p => p.key)); + const oldValues = log.oldInstance || empty; + const newValues = log.newInstance || empty; + const locale = validations[log.changedModel]?.locale || empty; + + let props = Object.keys(oldValues).concat(Object.keys(newValues)); props = [...new Set(props)]; + log.props = []; for (const prop of props) { - const matchOldProp = log.oldProperties.find(p => p.key === prop); - const matchNewProp = log.newProperties.find(p => p.key === prop); log.props.push({ - name: prop, - old: matchOldProp ? matchOldProp.value : null, - new: matchNewProp ? matchNewProp.value : null, + name: locale[prop] || prop, + old: this.formatValue(oldValues[prop]), + new: this.formatValue(newValues[prop]) }); } } } formatValue(value) { + if (typeof value === 'string' && validDate.test(value)) + value = new Date(value); + switch (typeof value) { case 'boolean': return value ? '✓' : '✗'; + case 'object': + if (value instanceof Date) + return this.$filter('date')(value, 'dd/MM/yyyy HH:mm:ss'); + else + return value; default: return value; } } - getInstance(instance, locale) { - const properties = []; - let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/; - - if (typeof instance == 'object' && instance != null) { - Object.keys(instance).forEach(property => { - if (validDate.test(instance[property])) - instance[property] = new Date(instance[property]).toLocaleString('es-ES'); - const key = locale[property] || property; - properties.push({key, value: instance[property]}); - }); - return properties; - } - return null; - } - showWorkerDescriptor(event, workerId) { if (!workerId) return; this.$.workerDescriptor.show(event.target, workerId); -- 2.40.1 From 27e0c2d0be012d2630af1012d786ee8801c484bf Mon Sep 17 00:00:00 2001 From: alexandre Date: Tue, 20 Dec 2022 14:23:47 +0100 Subject: [PATCH 4/6] refs #3302 where with changedModel and changedModelId --- front/salix/components/log/index.html | 10 ++++++---- front/salix/components/log/index.js | 6 ++++++ 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index eb6e4223e..45074bea3 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -3,6 +3,8 @@ url="{{$ctrl.url}}" filter="$ctrl.filter" link="{originFk: $ctrl.originId}" + where="{changedModel: $ctrl.changedModel, + changedModelId: $ctrl.changedModelId}" data="$ctrl.logs" limit="20" auto-load="true"> @@ -14,9 +16,9 @@ Date User - Model + Model Action - Name + Name Changes @@ -31,13 +33,13 @@ translate>{{::log.user.name || 'System' | translate}} - + {{::log.changedModel}} {{::$ctrl.actionsText[log.action]}} - + {{::log.changedModelValue}} diff --git a/front/salix/components/log/index.js b/front/salix/components/log/index.js index 75249d1ee..f0306fed6 100644 --- a/front/salix/components/log/index.js +++ b/front/salix/components/log/index.js @@ -57,6 +57,10 @@ export default class Controller extends Section { } } + get showModelName() { + return !(this.changedModel && this.changedModelId); + } + formatValue(value) { if (typeof value === 'string' && validDate.test(value)) value = new Date(value); @@ -86,6 +90,8 @@ ngModule.vnComponent('vnLog', { bindings: { model: '<', originId: '<', + changedModel: ' Date: Tue, 20 Dec 2022 15:29:21 +0100 Subject: [PATCH 5/6] refs #3302 fixed scss --- front/salix/components/log/index.html | 6 +++--- front/salix/components/log/style.scss | 8 +++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/front/salix/components/log/index.html b/front/salix/components/log/index.html index 45074bea3..79dfcef8c 100644 --- a/front/salix/components/log/index.html +++ b/front/salix/components/log/index.html @@ -16,7 +16,7 @@ Date User - Model + Model Action Name Changes @@ -36,10 +36,10 @@ {{::log.changedModel}} - + {{::$ctrl.actionsText[log.action]}} - + {{::log.changedModelValue}} diff --git a/front/salix/components/log/style.scss b/front/salix/components/log/style.scss index 58e4b8e3f..bc943996d 100644 --- a/front/salix/components/log/style.scss +++ b/front/salix/components/log/style.scss @@ -31,12 +31,18 @@ vn-log { & > td { padding: 2px; - width: 33%; } & > td.field, & > th.field { + width: 20%; color: gray; } + & > td.before, + & > th.before, + & > td.after, + & > th.after { + width: 40%; + } } } } -- 2.40.1 From c34c23937518ab3c010f319c3ec9a210053baf98 Mon Sep 17 00:00:00 2001 From: alexandre Date: Fri, 23 Dec 2022 08:13:08 +0100 Subject: [PATCH 6/6] refs #3302 corrections --- front/salix/components/log/index.js | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/front/salix/components/log/index.js b/front/salix/components/log/index.js index f0306fed6..1c54aa9b8 100644 --- a/front/salix/components/log/index.js +++ b/front/salix/components/log/index.js @@ -8,10 +8,10 @@ export default class Controller extends Section { constructor($element, $) { super($element, $); this.actionsText = { - 'insert': 'Creates', - 'update': 'Updates', - 'delete': 'Deletes', - 'select': 'Views' + insert: 'Creates', + update: 'Updates', + delete: 'Deletes', + select: 'Views' }; this.filter = { include: [{ @@ -62,15 +62,25 @@ export default class Controller extends Section { } formatValue(value) { - if (typeof value === 'string' && validDate.test(value)) - value = new Date(value); + let type = typeof value; - switch (typeof value) { + if (type === 'string' && validDate.test(value)) { + value = new Date(value); + type = typeof value; + } + + switch (type) { case 'boolean': return value ? '✓' : '✗'; case 'object': - if (value instanceof Date) - return this.$filter('date')(value, 'dd/MM/yyyy HH:mm:ss'); + if (value instanceof Date) { + const hasZeroTime = + value.getHours() === 0 && + value.getMinutes() === 0 && + value.getSeconds() === 0; + const format = hasZeroTime ? 'dd/MM/yyyy' : 'dd/MM/yyyy HH:mm:ss'; + return this.$filter('date')(value, format); + } else return value; default: -- 2.40.1