From 6605e5ae4cbbde79e568544b710b8b1730765b25 Mon Sep 17 00:00:00 2001 From: bernat Date: Wed, 2 Dec 2020 12:05:47 +0100 Subject: [PATCH 1/5] zoneLog --- db/changes/10260-december/00-zoneLog.sql | 18 ++++++ modules/zone/back/model-config.json | 3 + modules/zone/back/models/zone-log.json | 58 ++++++++++++++++++++ modules/zone/back/models/zone-warehouse.json | 6 +- modules/zone/back/models/zone.json | 6 +- modules/zone/front/index.js | 1 + modules/zone/front/log/index.html | 1 + modules/zone/front/log/index.js | 7 +++ modules/zone/front/routes.json | 6 ++ 9 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 db/changes/10260-december/00-zoneLog.sql create mode 100644 modules/zone/back/models/zone-log.json create mode 100644 modules/zone/front/log/index.html create mode 100644 modules/zone/front/log/index.js diff --git a/db/changes/10260-december/00-zoneLog.sql b/db/changes/10260-december/00-zoneLog.sql new file mode 100644 index 000000000..13d81bc92 --- /dev/null +++ b/db/changes/10260-december/00-zoneLog.sql @@ -0,0 +1,18 @@ +CREATE TABLE `vn`.`zoneLog` ( + `id` int(11) unsigned NOT NULL AUTO_INCREMENT, + `originFk` int(10) NOT NULL, + `userFk` int(10) unsigned DEFAULT NULL, + `action` set('insert','update','delete') COLLATE utf8_unicode_ci NOT NULL, + `creationDate` timestamp NULL DEFAULT current_timestamp(), + `description` text CHARACTER SET utf8 DEFAULT NULL, + `changedModel` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + `oldInstance` text COLLATE utf8_unicode_ci DEFAULT NULL, + `newInstance` text COLLATE utf8_unicode_ci DEFAULT NULL, + `changedModelId` int(11) DEFAULT NULL, + `changedModelValue` varchar(45) COLLATE utf8_unicode_ci DEFAULT NULL, + PRIMARY KEY (`id`), + KEY `originFk` (`originFk`), + KEY `userFk` (`userFk`), + CONSTRAINT `zoneLog_ibfk_1` FOREIGN KEY (`originFk`) REFERENCES `vn`.`zone` (`id`) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT `zoneLog_ibfk_2` FOREIGN KEY (`userFk`) REFERENCES `account`.`user` (`id`) ON DELETE CASCADE ON UPDATE CASCADE +) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci; \ No newline at end of file diff --git a/modules/zone/back/model-config.json b/modules/zone/back/model-config.json index f353be088..05da8b2c3 100644 --- a/modules/zone/back/model-config.json +++ b/modules/zone/back/model-config.json @@ -31,5 +31,8 @@ }, "ZoneEstimatedDelivery": { "dataSource": "vn" + }, + "ZoneLog": { + "dataSource": "vn" } } diff --git a/modules/zone/back/models/zone-log.json b/modules/zone/back/models/zone-log.json new file mode 100644 index 000000000..ddca9261b --- /dev/null +++ b/modules/zone/back/models/zone-log.json @@ -0,0 +1,58 @@ +{ + "name": "ZoneLog", + "base": "VnModel", + "options": { + "mysql": { + "table": "zoneLog" + } + }, + "properties": { + "id": { + "id": true, + "type": "Number", + "forceId": false + }, + "originFk": { + "type": "Number", + "required": true + }, + "userFk": { + "type": "Number" + }, + "action": { + "type": "String", + "required": true + }, + "changedModel": { + "type": "String" + }, + "oldInstance": { + "type": "Object" + }, + "newInstance": { + "type": "Object" + }, + "creationDate": { + "type": "Date" + }, + "changedModelId": { + "type": "String" + }, + "changedModelValue": { + "type": "String" + }, + "description": { + "type": "String" + } + }, + "relations": { + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFk" + } + }, + "scope": { + "order": ["creationDate DESC", "id DESC"] + } +} diff --git a/modules/zone/back/models/zone-warehouse.json b/modules/zone/back/models/zone-warehouse.json index 14c4e84a4..0f0e43f4a 100644 --- a/modules/zone/back/models/zone-warehouse.json +++ b/modules/zone/back/models/zone-warehouse.json @@ -1,6 +1,10 @@ { "name": "ZoneWarehouse", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ZoneLog", + "relation": "zone" + }, "options": { "mysql": { "table": "zoneWarehouse" diff --git a/modules/zone/back/models/zone.json b/modules/zone/back/models/zone.json index e94146946..1d1ccfd90 100644 --- a/modules/zone/back/models/zone.json +++ b/modules/zone/back/models/zone.json @@ -1,6 +1,10 @@ { "name": "Zone", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ZoneLog", + "showField": "name" + }, "options": { "mysql": { "table": "zone" diff --git a/modules/zone/front/index.js b/modules/zone/front/index.js index 26c491709..dc20eea47 100644 --- a/modules/zone/front/index.js +++ b/modules/zone/front/index.js @@ -16,3 +16,4 @@ import './calendar'; import './location'; import './calendar'; import './upcoming-deliveries'; +import './log'; diff --git a/modules/zone/front/log/index.html b/modules/zone/front/log/index.html new file mode 100644 index 000000000..539afda82 --- /dev/null +++ b/modules/zone/front/log/index.html @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/modules/zone/front/log/index.js b/modules/zone/front/log/index.js new file mode 100644 index 000000000..8c3be2423 --- /dev/null +++ b/modules/zone/front/log/index.js @@ -0,0 +1,7 @@ +import ngModule from '../module'; +import Section from 'salix/components/section'; + +ngModule.vnComponent('vnZoneLog', { + template: require('./index.html'), + controller: Section, +}); diff --git a/modules/zone/front/routes.json b/modules/zone/front/routes.json index 6c799dcc8..0134c3b78 100644 --- a/modules/zone/front/routes.json +++ b/modules/zone/front/routes.json @@ -14,6 +14,7 @@ {"state": "zone.card.basicData", "icon": "settings"}, {"state": "zone.card.location", "icon": "my_location"}, {"state": "zone.card.warehouses", "icon": "home"}, + {"state": "zone.card.log", "icon": "history"}, {"state": "zone.card.events", "icon": "today"} ] }, @@ -84,6 +85,11 @@ "params": { "zone": "$ctrl.zone" } + }, { + "url" : "/log", + "state": "zone.card.log", + "component": "vn-zone-log", + "description": "Log" } ] } \ No newline at end of file From 6eeecc553ba9fc301104dfa213a14946a419d6d9 Mon Sep 17 00:00:00 2001 From: bernat Date: Wed, 2 Dec 2020 12:49:50 +0100 Subject: [PATCH 2/5] zoneLog calendar --- modules/zone/back/models/zone-event.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/modules/zone/back/models/zone-event.json b/modules/zone/back/models/zone-event.json index 9ac1007b5..54c9c4a7d 100644 --- a/modules/zone/back/models/zone-event.json +++ b/modules/zone/back/models/zone-event.json @@ -1,6 +1,10 @@ { "name": "ZoneEvent", - "base": "VnModel", + "base": "Loggable", + "log": { + "model":"ZoneLog", + "relation": "zone" + }, "options": { "mysql": { "table": "zoneEvent" From 2886e02328db37fea4dc01fa39bed770a984a6f7 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 29 Dec 2020 08:50:12 +0100 Subject: [PATCH 3/5] Enabled loggable for locations --- .../{10260-december => 10260-holidays}/00-zoneLog.sql | 0 modules/zone/back/models/zone-included.json | 7 ++++++- modules/zone/back/models/zone.json | 5 ----- 3 files changed, 6 insertions(+), 6 deletions(-) rename db/changes/{10260-december => 10260-holidays}/00-zoneLog.sql (100%) diff --git a/db/changes/10260-december/00-zoneLog.sql b/db/changes/10260-holidays/00-zoneLog.sql similarity index 100% rename from db/changes/10260-december/00-zoneLog.sql rename to db/changes/10260-holidays/00-zoneLog.sql diff --git a/modules/zone/back/models/zone-included.json b/modules/zone/back/models/zone-included.json index 9f9508824..e462b7a65 100644 --- a/modules/zone/back/models/zone-included.json +++ b/modules/zone/back/models/zone-included.json @@ -1,6 +1,11 @@ { "name": "ZoneIncluded", - "base": "VnModel", + "base": "Loggable", + "log": { + "model": "ZoneLog", + "relation": "zone", + "showField": "isIncluded" + }, "options": { "mysql": { "table": "zoneIncluded" diff --git a/modules/zone/back/models/zone.json b/modules/zone/back/models/zone.json index 1d1ccfd90..bafef0a95 100644 --- a/modules/zone/back/models/zone.json +++ b/modules/zone/back/models/zone.json @@ -43,11 +43,6 @@ } }, "relations": { - "geolocations": { - "type": "hasMany", - "model": "ZoneGeo", - "foreignKey": "zoneFk" - }, "agencyMode": { "type": "belongsTo", "model": "AgencyMode", From 20862db8546bae63d37f037917430982fef9ecaf Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 29 Dec 2020 13:39:10 +0100 Subject: [PATCH 4/5] 2690 - Duplicated foreign key fix --- loopback/common/models/vn-model.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/loopback/common/models/vn-model.js b/loopback/common/models/vn-model.js index f56183df2..56fb7e656 100644 --- a/loopback/common/models/vn-model.js +++ b/loopback/common/models/vn-model.js @@ -146,8 +146,14 @@ module.exports = function(Self) { function replaceErr(err, replaceErrFunc) { if (Array.isArray(err)) { let errs = []; - for (let e of err) - errs.push(replaceErrFunc(e)); + const errors = err.filter(error => { + return error != undefined && error != null; + }); + for (let e of errors) { + if (!(e instanceof UserError)) + errs.push(replaceErrFunc(e)); + else errs.push(e); + } return errs; } return replaceErrFunc(err); From edd25a347bd6c04806f84767b57f1983bd9cf3db Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 29 Dec 2020 13:44:12 +0100 Subject: [PATCH 5/5] Moved line --- loopback/common/models/vn-model.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/loopback/common/models/vn-model.js b/loopback/common/models/vn-model.js index 56fb7e656..cc3eede8e 100644 --- a/loopback/common/models/vn-model.js +++ b/loopback/common/models/vn-model.js @@ -145,10 +145,10 @@ module.exports = function(Self) { rewriteDbError(replaceErrFunc) { function replaceErr(err, replaceErrFunc) { if (Array.isArray(err)) { - let errs = []; const errors = err.filter(error => { return error != undefined && error != null; }); + let errs = []; for (let e of errors) { if (!(e instanceof UserError)) errs.push(replaceErrFunc(e));