From 57123f4887cbaaff54078ab9a41f899d345be084 Mon Sep 17 00:00:00 2001 From: Carlos Jimenez <=> Date: Thu, 26 Apr 2018 16:41:08 +0200 Subject: [PATCH] #266 popover for item descriptor on ticket section plus some minor refactors on inte tags relations --- client/item/routes.json | 31 +++--- client/item/src/card/card.html | 7 +- .../descriptor-popover.html | 7 ++ .../descriptor-popover/descriptor-popover.js | 96 +++++++++++++++++++ client/item/src/descriptor-popover/style.scss | 11 +++ client/item/src/descriptor/descriptor.html | 14 +-- client/item/src/descriptor/style.scss | 13 ++- client/item/src/item.js | 1 + client/modules.yml | 2 +- .../ticket/src/fetched-tags/fetched-tags.html | 4 +- .../ticket/src/fetched-tags/fetched-tags.js | 1 - client/ticket/src/sale/sale.html | 12 ++- client/ticket/src/sale/sale.js | 19 ++-- .../loopback/common/methods/item/clone.js | 2 +- .../loopback/common/methods/sale/filter.js | 2 +- .../loopback/common/methods/sale/price-gap.js | 2 +- .../methods/sale/saleComponentFilter.js | 2 +- .../loopback/common/methods/ticket/summary.js | 4 +- services/loopback/common/models/item.json | 2 +- 19 files changed, 182 insertions(+), 50 deletions(-) create mode 100644 client/item/src/descriptor-popover/descriptor-popover.html create mode 100644 client/item/src/descriptor-popover/descriptor-popover.js create mode 100644 client/item/src/descriptor-popover/style.scss diff --git a/client/item/routes.json b/client/item/routes.json index b269df1a86..a6028871ca 100644 --- a/client/item/routes.json +++ b/client/item/routes.json @@ -9,24 +9,20 @@ "state": "item", "abstract": true, "component": "ui-view" - }, - { + }, { "url": "/list?q", "state": "item.index", "component": "vn-item-list" - }, - { + }, { "url": "/create", "state": "item.create", "component": "vn-item-create" - }, - { + }, { "url": "/:id", "state": "item.card", "abstract": true, "component": "vn-item-card" - }, - { + }, { "url" : "/data", "state": "item.card.data", "component": "vn-item-data", @@ -38,8 +34,7 @@ "icon": "settings" }, "acl": ["buyer"] - }, - { + }, { "url" : "/tags", "state": "item.card.tags", "component": "vn-item-tags", @@ -51,8 +46,7 @@ "icon": "icon-tags" }, "acl": ["buyer"] - }, - { + }, { "url" : "/tax", "state": "item.card.tax", "component": "vn-item-tax", @@ -61,8 +55,7 @@ "icon": "icon-tax" }, "acl": ["administrative","salesAssistant"] - }, - { + }, { "url" : "/history", "state": "item.card.history", "component": "vn-item-history", @@ -73,8 +66,7 @@ "description": "History", "icon": "history" } - }, - { + }, { "url" : "/niche", "state": "item.card.niche", "component": "vn-item-niche", @@ -86,8 +78,7 @@ "icon": "place" }, "acl": ["buyer","replenisher"] - }, - { + }, { "url" : "/botanical", "state": "item.card.botanical", "component": "vn-item-botanical", @@ -99,7 +90,7 @@ "icon": "local_florist" }, "acl": ["buyer"] - },{ + }, { "url" : "/barcode", "state": "item.card.itemBarcode", "component": "vn-item-barcode", @@ -111,7 +102,7 @@ "icon": "icon-barcode" }, "acl": ["buyer","replenisher"] - },{ + }, { "url" : "/summary", "state": "item.card.summary", "component": "vn-item-summary", diff --git a/client/item/src/card/card.html b/client/item/src/card/card.html index 34ecff4a58..40d69c8b32 100644 --- a/client/item/src/card/card.html +++ b/client/item/src/card/card.html @@ -1,7 +1,12 @@ - + + diff --git a/client/item/src/descriptor-popover/descriptor-popover.html b/client/item/src/descriptor-popover/descriptor-popover.html new file mode 100644 index 0000000000..965612408a --- /dev/null +++ b/client/item/src/descriptor-popover/descriptor-popover.html @@ -0,0 +1,7 @@ + + + + diff --git a/client/item/src/descriptor-popover/descriptor-popover.js b/client/item/src/descriptor-popover/descriptor-popover.js new file mode 100644 index 0000000000..31e3bede1e --- /dev/null +++ b/client/item/src/descriptor-popover/descriptor-popover.js @@ -0,0 +1,96 @@ +import ngModule from '../module'; +import Component from 'core/src/lib/component'; +import './style.scss'; + +class Controller extends Component { + constructor($element, $scope, $http, $timeout) { + super($element, $scope); + this.$http = $http; + this.$timeout = $timeout; + + this.isTooltip = true; + this.clear(); + } + + clear() { + this.item = null; + this.tags = {}; + this.itemTags = null; + } + + show() { + this.$.popover.parent = this.parent; + this.$.popover.show(); + } + + _getTags() { + this.$http.get(`/item/api/Tags`).then(response => { + response.data.forEach(tag => { + this.tags[tag.id] = Object.assign({}, tag); + }); + + this.$.popover.relocate(); + }); + } + + _getItem() { + let filter = { + fields: ['id', 'name', 'image'], + include: [ + { + relation: 'itemType', + scope: { + fields: ['workerFk'], + include: { + relation: 'worker', + scope: { + fields: ['firstName', 'name'] + } + } + } + }, { + relation: 'tags', + scope: { + fields: ['value', 'tagFk'], + order: 'priority ASC', + include: { + relation: 'tag', + scope: { + fields: ['name'] + } + } + } + } + ] + }; + + let json = encodeURIComponent(JSON.stringify(filter)); + this.$http.get(`/item/api/Items/${this._itemFk}?filter=${json}`) + .then(res => { + if (!res.data) return; + this.item = res.data; + this.itemTags = this.item.tags; + this.$.popover.relocate(); + } + ); + } + + set itemFk(id) { + this._itemFk = id; + + if (id) { + this._getItem(); + this._getTags(); + } else + this.clear(); + } +} +Controller.$inject = ['$element', '$scope', '$http', '$timeout']; + +ngModule.component('vnItemDescriptorPopover', { + template: require('./descriptor-popover.html'), + bindings: { + itemFk: '<' + }, + controller: Controller +}); diff --git a/client/item/src/descriptor-popover/style.scss b/client/item/src/descriptor-popover/style.scss new file mode 100644 index 0000000000..839fc992f7 --- /dev/null +++ b/client/item/src/descriptor-popover/style.scss @@ -0,0 +1,11 @@ +vn-item-descriptor-popover { + vn-item-descriptor { + display: block; + width: 16em; + min-height: 28em; + + .header > a:first-child { + display: none + } + } +} \ No newline at end of file diff --git a/client/item/src/descriptor/descriptor.html b/client/item/src/descriptor/descriptor.html index 0767453d07..6af33ca244 100644 --- a/client/item/src/descriptor/descriptor.html +++ b/client/item/src/descriptor/descriptor.html @@ -1,20 +1,20 @@ - + - + - + - diff --git a/client/item/src/descriptor/style.scss b/client/item/src/descriptor/style.scss index db4db097f2..28a1d4203f 100644 --- a/client/item/src/descriptor/style.scss +++ b/client/item/src/descriptor/style.scss @@ -1,4 +1,9 @@ -img[ng-src] { - height: 100%; - width: 100%; - } \ No newline at end of file + +vn-item-descriptor { + display: block; + + img[ng-src] { + height: 100%; + width: 100%; + } +} diff --git a/client/item/src/item.js b/client/item/src/item.js index 477173e79e..e0450d3771 100644 --- a/client/item/src/item.js +++ b/client/item/src/item.js @@ -14,4 +14,5 @@ import './niche/niche'; import './botanical/botanical'; import './barcode/barcode'; import './summary/summary'; +import './descriptor-popover/descriptor-popover'; diff --git a/client/modules.yml b/client/modules.yml index f71f90ae6e..aff4e715b9 100644 --- a/client/modules.yml +++ b/client/modules.yml @@ -6,4 +6,4 @@ locator: [] production: [] salix: [] route: [] -ticket: [] +ticket: [item] diff --git a/client/ticket/src/fetched-tags/fetched-tags.html b/client/ticket/src/fetched-tags/fetched-tags.html index 9402a318d6..d9b47107b3 100644 --- a/client/ticket/src/fetched-tags/fetched-tags.html +++ b/client/ticket/src/fetched-tags/fetched-tags.html @@ -1,8 +1,8 @@ {{::$ctrl.sale.concept}} - - {{::fetchedTag.tag.name}} {{::fetchedTag.value}} + + {{::fetchedTag.tag.name}} {{::fetchedTag.value}} \ No newline at end of file diff --git a/client/ticket/src/fetched-tags/fetched-tags.js b/client/ticket/src/fetched-tags/fetched-tags.js index 81031d7644..e993aba115 100644 --- a/client/ticket/src/fetched-tags/fetched-tags.js +++ b/client/ticket/src/fetched-tags/fetched-tags.js @@ -1,7 +1,6 @@ import ngModule from '../module'; class Controller {} -Controller.$inject = []; ngModule.component('vnFetchedTags', { template: require('./fetched-tags.html'), diff --git a/client/ticket/src/sale/sale.html b/client/ticket/src/sale/sale.html index 5f2ab24ad9..94b6d06dad 100644 --- a/client/ticket/src/sale/sale.html +++ b/client/ticket/src/sale/sale.html @@ -1,4 +1,4 @@ - + @@ -16,7 +16,12 @@ - {{::sale.itemFk}} + + {{::sale.itemFk}} + {{::sale.quantity}} {{::sale.price | currency:'€':2}} @@ -27,4 +32,7 @@ + + + diff --git a/client/ticket/src/sale/sale.js b/client/ticket/src/sale/sale.js index ddf0ee7edc..71c8fb7ba9 100644 --- a/client/ticket/src/sale/sale.js +++ b/client/ticket/src/sale/sale.js @@ -1,15 +1,22 @@ import ngModule from '../module'; -import FilterTicketList from '../filter-ticket-list'; -class Controller extends FilterTicketList { - constructor($scope, $timeout, $state) { - super($scope, $timeout, $state); +class Controller { + constructor($scope, $timeout) { + this.$ = $scope; + this.$timeout = $timeout; + } - this.onOrder('quantity', 'ASC'); + showDescriptor(event, itemFk) { + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); + } + onDescriptorLoad() { + this.$.popover.relocate(); } } -Controller.$inject = ['$scope', '$timeout', '$state']; +Controller.$inject = ['$scope', '$timeout']; ngModule.component('vnTicketSale', { template: require('./sale.html'), diff --git a/services/loopback/common/methods/item/clone.js b/services/loopback/common/methods/item/clone.js index f0a66d0d9d..5655367398 100644 --- a/services/loopback/common/methods/item/clone.js +++ b/services/loopback/common/methods/item/clone.js @@ -27,7 +27,7 @@ module.exports = Self => { id: itemId }, include: [ - {relation: 'itemTag', scope: {order: 'priority ASC', include: {relation: 'tag'}}} + {relation: 'tags', scope: {order: 'priority ASC', include: {relation: 'tag'}}} ] }; diff --git a/services/loopback/common/methods/sale/filter.js b/services/loopback/common/methods/sale/filter.js index 23688b3411..5c1a322d08 100644 --- a/services/loopback/common/methods/sale/filter.js +++ b/services/loopback/common/methods/sale/filter.js @@ -13,7 +13,7 @@ module.exports = Self => { relation: 'item', scope: { include: { - relation: 'itemTag', + relation: 'tags', scope: { fields: ['tagFk', 'value'], include: { diff --git a/services/loopback/common/methods/sale/price-gap.js b/services/loopback/common/methods/sale/price-gap.js index 779be32328..88af90c17e 100644 --- a/services/loopback/common/methods/sale/price-gap.js +++ b/services/loopback/common/methods/sale/price-gap.js @@ -29,7 +29,7 @@ module.exports = Self => { relation: 'item', scope: { include: { - relation: 'itemTag', + relation: 'tags', scope: { fields: ['tagFk', 'value'], include: { diff --git a/services/loopback/common/methods/sale/saleComponentFilter.js b/services/loopback/common/methods/sale/saleComponentFilter.js index 7d730514b5..ea829cf24a 100644 --- a/services/loopback/common/methods/sale/saleComponentFilter.js +++ b/services/loopback/common/methods/sale/saleComponentFilter.js @@ -13,7 +13,7 @@ module.exports = Self => { relation: 'item', scope: { include: { - relation: 'itemTag', + relation: 'tags', scope: { fields: ['tagFk', 'value'], include: { diff --git a/services/loopback/common/methods/ticket/summary.js b/services/loopback/common/methods/ticket/summary.js index 8e59d22d46..83eb9f416c 100644 --- a/services/loopback/common/methods/ticket/summary.js +++ b/services/loopback/common/methods/ticket/summary.js @@ -83,7 +83,7 @@ module.exports = Self => { relation: 'item', scope: { include: { - relation: 'itemTag', + relation: 'tags', scope: { fields: ['tagFk', 'value'], include: { @@ -107,7 +107,7 @@ module.exports = Self => { let subTotal = 0.00; sales.forEach(sale => { - subTotal+= sale.quantity * sale.price; + subTotal += sale.quantity * sale.price; }); return subTotal; diff --git a/services/loopback/common/models/item.json b/services/loopback/common/models/item.json index ddb8ff4d35..f167d16c4f 100644 --- a/services/loopback/common/models/item.json +++ b/services/loopback/common/models/item.json @@ -75,7 +75,7 @@ "model": "Expence", "foreignKey": "expenceFk" }, - "itemTag": { + "tags": { "type": "hasMany", "model": "ItemTag", "foreignKey": "itemFk"