From 30933220aca2d32dfddd1ee4a2129aea66c58f64 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Mon, 24 Oct 2022 09:37:17 +0200 Subject: [PATCH 1/6] #4507 greuge.js/json now insert userFk @2h --- modules/client/back/models/greuge.js | 15 +++++++++++++++ modules/client/back/models/greuge.json | 4 ++++ modules/client/front/greuge/index/index.html | 2 ++ modules/client/front/greuge/index/locale/es.yml | 3 ++- 4 files changed, 23 insertions(+), 1 deletion(-) diff --git a/modules/client/back/models/greuge.js b/modules/client/back/models/greuge.js index bd5f2865d..42820fd60 100644 --- a/modules/client/back/models/greuge.js +++ b/modules/client/back/models/greuge.js @@ -1,6 +1,21 @@ +const LoopBackContext = require('loopback-context'); + module.exports = function(Self) { require('../methods/greuge/sumAmount')(Self); + Self.observe('before save', function(ctx, next) { + const loopBackContext = LoopBackContext.getCurrentContext(); + + let userFk = loopBackContext.active.accessToken.userId; + + if (ctx.instance) + ctx.instance.userFk = userFk; + else + ctx.data.userFk = userFk; + + next(); + }); + Self.validatesLengthOf('description', { max: 45, message: 'Description should have maximum of 45 characters' diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index 918ff0ca5..e8790715a 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -34,6 +34,10 @@ "greugeTypeFk": { "type": "number", "required": true + }, + "userFk": { + "type": "number", + "required": true } }, diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index b48fe9466..cdc9c37d4 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -29,6 +29,7 @@ Date + Created by Comment Type Amount @@ -37,6 +38,7 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} + {{::greuge.userFk}} {{::greuge.description}} diff --git a/modules/client/front/greuge/index/locale/es.yml b/modules/client/front/greuge/index/locale/es.yml index 513e6ff7b..d1f202862 100644 --- a/modules/client/front/greuge/index/locale/es.yml +++ b/modules/client/front/greuge/index/locale/es.yml @@ -1,4 +1,5 @@ Date: Fecha Comment: Comentario Amount: Importe -Type: Tipo \ No newline at end of file +Type: Tipo +Created by: Creado por \ No newline at end of file From 1327f0ae9ddb550c8b0536f4f34eb4375851feac Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:18:05 +0100 Subject: [PATCH 2/6] Added requested changes, refs #4507 @1:20h --- .../10502-november/00-greuge.userFK_userFk.sql | 1 + modules/client/back/models/greuge.json | 16 ++++++++-------- modules/client/front/greuge/index/index.html | 2 +- modules/client/front/greuge/index/index.js | 6 ++++++ 4 files changed, 16 insertions(+), 9 deletions(-) create mode 100644 db/changes/10502-november/00-greuge.userFK_userFk.sql diff --git a/db/changes/10502-november/00-greuge.userFK_userFk.sql b/db/changes/10502-november/00-greuge.userFK_userFk.sql new file mode 100644 index 000000000..2a5323fa3 --- /dev/null +++ b/db/changes/10502-november/00-greuge.userFK_userFk.sql @@ -0,0 +1 @@ +ALTER TABLE vn.greuge CHANGE userFK userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index e8790715a..a694c7552 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -2,9 +2,9 @@ "name": "Greuge", "base": "Loggable", "log": { - "model": "ClientLog", - "relation": "client", - "showField": "description" + "model": "ClientLog", + "relation": "client", + "showField": "description" }, "options": { "mysql": { @@ -34,12 +34,7 @@ "greugeTypeFk": { "type": "number", "required": true - }, - "userFk": { - "type": "number", - "required": true } - }, "relations": { "client": { @@ -56,6 +51,11 @@ "type": "belongsTo", "model": "GreugeType", "foreignKey": "greugeTypeFk" + }, + "user": { + "type": "belongsTo", + "model": "Account", + "foreignKey": "userFK" } } } \ No newline at end of file diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index cdc9c37d4..44074ed1a 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -38,7 +38,7 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.userFk}} + {{::greuge.user.name}} {{::greuge.description}} diff --git a/modules/client/front/greuge/index/index.js b/modules/client/front/greuge/index/index.js index 2451167a4..7a5ccc531 100644 --- a/modules/client/front/greuge/index/index.js +++ b/modules/client/front/greuge/index/index.js @@ -8,6 +8,12 @@ class Controller extends Section { include: [ { relation: 'greugeType', + scope: { + fields: ['id', 'name'] + }, + }, + { + relation: 'user', scope: { fields: ['id', 'name'] } From c53e309071cadb12f1deca6fa7700248ba8d6afa Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:19:54 +0100 Subject: [PATCH 3/6] Fix typo --- modules/client/back/models/greuge.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/client/back/models/greuge.json b/modules/client/back/models/greuge.json index a694c7552..625bf4e28 100644 --- a/modules/client/back/models/greuge.json +++ b/modules/client/back/models/greuge.json @@ -55,7 +55,7 @@ "user": { "type": "belongsTo", "model": "Account", - "foreignKey": "userFK" + "foreignKey": "userFk" } } } \ No newline at end of file From 8dd6012b1f8e50cc98ae398e96d127fced675e86 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:27:47 +0100 Subject: [PATCH 4/6] Added worker descriptor popover --- modules/client/front/greuge/index/index.html | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index 44074ed1a..80e41e915 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -38,7 +38,8 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.user.name}} + {{::greuge.user.name}} {{::greuge.description}} @@ -59,3 +60,4 @@ vn-bind="+" fixed-bottom-right> + \ No newline at end of file From 8b06243041112365aa58f2f17470af11068c9357 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Thu, 10 Nov 2022 08:36:26 +0100 Subject: [PATCH 5/6] Fix link being the whole column --- modules/client/front/greuge/index/index.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index 80e41e915..459d92fc7 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -38,8 +38,8 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.user.name}} + {{::greuge.user.name}} {{::greuge.description}} From 7b3a1bfb22bff5082626b9929ba1bb8b7b3354a0 Mon Sep 17 00:00:00 2001 From: Pau Navarro Date: Wed, 16 Nov 2022 08:28:12 +0100 Subject: [PATCH 6/6] requested changes --- db/changes/10502-november/00-greuge.userFK_userFk.sql | 1 - db/changes/10503-november/00-greuge.userFK_userFk.sql | 1 + 2 files changed, 1 insertion(+), 1 deletion(-) delete mode 100644 db/changes/10502-november/00-greuge.userFK_userFk.sql create mode 100644 db/changes/10503-november/00-greuge.userFK_userFk.sql diff --git a/db/changes/10502-november/00-greuge.userFK_userFk.sql b/db/changes/10502-november/00-greuge.userFK_userFk.sql deleted file mode 100644 index 2a5323fa3..000000000 --- a/db/changes/10502-november/00-greuge.userFK_userFk.sql +++ /dev/null @@ -1 +0,0 @@ -ALTER TABLE vn.greuge CHANGE userFK userFk int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file diff --git a/db/changes/10503-november/00-greuge.userFK_userFk.sql b/db/changes/10503-november/00-greuge.userFK_userFk.sql new file mode 100644 index 000000000..ec4bf3146 --- /dev/null +++ b/db/changes/10503-november/00-greuge.userFK_userFk.sql @@ -0,0 +1 @@ +ALTER TABLE `vn`.`greuge` CHANGE `userFK` `userFk` int(10) unsigned DEFAULT NULL NULL; \ No newline at end of file