From e06798cf9042a3f4c53d4256b454335973739769 Mon Sep 17 00:00:00 2001 From: Gerard Date: Tue, 6 Nov 2018 10:49:38 +0100 Subject: [PATCH] #762 refactor componente fetched tags --- .../src/components/fetched-tags/index.html | 4 +- .../core/src/components/fetched-tags/index.js | 47 ++++++++++++++++++- .../src/components/fetched-tags/style.scss | 4 ++ client/item/src/index/product.html | 2 +- client/order/src/line/index.html | 2 +- client/order/src/line/index.js | 17 +------ client/order/src/line/index.spec.js | 17 +------ client/order/src/summary/index.html | 2 +- client/order/src/volume/index.html | 2 +- client/order/src/volume/index.js | 36 ++++---------- client/ticket/src/component/index.html | 2 +- client/ticket/src/component/index.js | 31 ++++-------- client/ticket/src/data/step-two/index.html | 2 +- client/ticket/src/sale-checked/index.html | 2 +- client/ticket/src/sale-checked/index.js | 18 +------ client/ticket/src/sale-tracking/index.html | 2 +- client/ticket/src/summary/index.html | 2 +- client/ticket/src/volume/index.html | 2 +- client/ticket/src/volume/index.js | 37 ++++----------- .../common/methods/sale/priceDifference.js | 20 +------- .../loopback/common/methods/ticket/summary.js | 16 ------- services/loopback/common/models/item.json | 12 +++++ .../order/common/methods/order/summary.js | 7 +-- .../methods/sale-tracking/listSaleTracking.js | 18 +------ 24 files changed, 109 insertions(+), 195 deletions(-) diff --git a/client/core/src/components/fetched-tags/index.html b/client/core/src/components/fetched-tags/index.html index 88bade0d3..84b3a2130 100644 --- a/client/core/src/components/fetched-tags/index.html +++ b/client/core/src/components/fetched-tags/index.html @@ -1,10 +1,10 @@ - {{::$ctrl.concept}} + {{::$ctrl.item.name}}
+ vn-tooltip="{{::fetchedTag.name}}: {{::fetchedTag.value}}"> {{::fetchedTag.value}}
diff --git a/client/core/src/components/fetched-tags/index.js b/client/core/src/components/fetched-tags/index.js index 3e206275e..6b7ce2a46 100644 --- a/client/core/src/components/fetched-tags/index.js +++ b/client/core/src/components/fetched-tags/index.js @@ -1,10 +1,53 @@ import ngModule from '../../module'; import './style.scss'; +export default class FetchedTags { + set item(value) { + if (value) { + let tags = []; + for (let i = 5; i < 5 + this.maxLength; i++) + if (value['tag' + i]) { + let tagValue = value['value' + i]; + let tagKey = value['tag' + i]; + tags.push({name: tagKey, value: tagValue, position: i - 5}); + } + this.tags = tags; + } + this._item = value; + } + + get item() { + return this._item; + } + + set tags(value) { + if (value) { + let organizedTags = new Array(parseInt(this.maxLength)); + for (let i = 0; i < this.maxLength; i++) { + let organizedTag = {}; + for (let j = 0; j < value.length; j++) { + if (value[j].position === i) { + organizedTag.name = value[j].name; + organizedTag.value = value[j].value; + } + organizedTags[i] = JSON.parse(JSON.stringify(organizedTag)); + } + } + this._tags = organizedTags; + } + } + + get tags() { + return this._tags; + } +} + + ngModule.component('vnFetchedTags', { template: require('./index.html'), + controller: FetchedTags, bindings: { - concept: '<', - tags: '<' + maxLength: '<', + item: '<' } }); diff --git a/client/core/src/components/fetched-tags/style.scss b/client/core/src/components/fetched-tags/style.scss index 70a92d21f..0523d3eaa 100644 --- a/client/core/src/components/fetched-tags/style.scss +++ b/client/core/src/components/fetched-tags/style.scss @@ -1,6 +1,10 @@ @import "colors"; vn-fetched-tags { + &.noTitle vn-one { + display: none !important; + } + @media screen and (max-width: 1600px){ & vn-horizontal { flex-direction: column; diff --git a/client/item/src/index/product.html b/client/item/src/index/product.html index fac1bcc46..6c1b0d4d7 100644 --- a/client/item/src/index/product.html +++ b/client/item/src/index/product.html @@ -20,7 +20,7 @@ - + - + {{row.warehouse.name}} {{row.shipped | dashIfEmpty}} {{row.quantity}} diff --git a/client/order/src/line/index.js b/client/order/src/line/index.js index 68d71c9ae..fdfa4f8a2 100644 --- a/client/order/src/line/index.js +++ b/client/order/src/line/index.js @@ -20,22 +20,7 @@ class Controller { let filter = { where: {orderFk: this.$state.params.id}, include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - } - } - }, - fields: ['itemFk', 'name', 'image'] - } + relation: 'item' }, {relation: 'warehouse'}] }; diff --git a/client/order/src/line/index.spec.js b/client/order/src/line/index.spec.js index 1a3332994..279d10d40 100644 --- a/client/order/src/line/index.spec.js +++ b/client/order/src/line/index.spec.js @@ -29,22 +29,7 @@ describe('Order', () => { let filter = { where: {orderFk: controller.$state.params.id}, include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - } - } - }, - fields: ['itemFk', 'name', 'image'] - } + relation: 'item' }, {relation: 'warehouse'}] }; diff --git a/client/order/src/summary/index.html b/client/order/src/summary/index.html index 261a8b965..b6d46a512 100644 --- a/client/order/src/summary/index.html +++ b/client/order/src/summary/index.html @@ -76,7 +76,7 @@ {{("000000"+row.itemFk).slice(-6)}} - + {{::row.quantity}} {{::row.price | currency:'€':2}} {{::row.quantity * row.price | currency:'€':2}} diff --git a/client/order/src/volume/index.html b/client/order/src/volume/index.html index 73be7062c..73a6f2d65 100644 --- a/client/order/src/volume/index.html +++ b/client/order/src/volume/index.html @@ -39,7 +39,7 @@ {{::row.itemFk}} - + {{::row.quantity}} {{::row.volume | number:3}} diff --git a/client/order/src/volume/index.js b/client/order/src/volume/index.js index a5b7df2fb..3275b0b5c 100644 --- a/client/order/src/volume/index.js +++ b/client/order/src/volume/index.js @@ -8,23 +8,7 @@ class Controller { this.$stateParams = $stateParams; this.filter = { include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } + relation: 'item' }] }; this.order = {}; @@ -33,17 +17,15 @@ class Controller { onDataChange() { this.$http.get(`/order/api/Orders/${this.$stateParams.id}/getVolumes`) - .then(response => { - if (response.data) { - this.$scope.model.data.forEach(order => { - response.data.volumes.forEach(volume => { - if (order.itemFk === volume.itemFk) { - order.volume = volume.volume; - } + .then(response => { + if (response.data) + this.$scope.model.data.forEach(order => { + response.data.volumes.forEach(volume => { + if (order.itemFk === volume.itemFk) + order.volume = volume.volume; + }); }); - }); - } - }); + }); } showDescriptor(event, itemFk) { diff --git a/client/ticket/src/component/index.html b/client/ticket/src/component/index.html index 3c24259af..046c8060e 100644 --- a/client/ticket/src/component/index.html +++ b/client/ticket/src/component/index.html @@ -51,7 +51,7 @@ + }}"> {{::sale.quantity}} diff --git a/client/ticket/src/component/index.js b/client/ticket/src/component/index.js index 1d54d7598..eb4fe55e2 100644 --- a/client/ticket/src/component/index.js +++ b/client/ticket/src/component/index.js @@ -9,22 +9,6 @@ class Controller { order: 'concept ASC', include: [{ relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } }, { relation: 'components', @@ -52,9 +36,10 @@ class Controller { let sum = 0; if (!sales) return; - for (let sale of sales) + for (let sale of sales) { for (let component of sale.components) sum += sale.quantity * component.value; + } return sum; } @@ -65,10 +50,12 @@ class Controller { if (!sales) return; - for (let sale of sales) - for (let component of sale.components) + for (let sale of sales) { + for (let component of sale.components) { if (component.componentRate.name == 'valor de compra') sum += sale.quantity * component.value; + } + } return sum; } @@ -79,10 +66,12 @@ class Controller { if (!sales) return; - for (let sale of sales) - for (let component of sale.components) + for (let sale of sales) { + for (let component of sale.components) { if (component.componentRate.name != 'valor de compra') sum += sale.quantity * component.value; + } + } return sum; } diff --git a/client/ticket/src/data/step-two/index.html b/client/ticket/src/data/step-two/index.html index 2da46cbc8..cb68694a6 100644 --- a/client/ticket/src/data/step-two/index.html +++ b/client/ticket/src/data/step-two/index.html @@ -16,7 +16,7 @@ {{("000000"+sale.itemFk).slice(-6)}} - + {{::sale.quantity}} {{::sale.price | currency: '€': 2}} {{::sale.component.newPrice | currency: '€': 2}} diff --git a/client/ticket/src/sale-checked/index.html b/client/ticket/src/sale-checked/index.html index 1dde0152c..c1b73ab38 100644 --- a/client/ticket/src/sale-checked/index.html +++ b/client/ticket/src/sale-checked/index.html @@ -34,7 +34,7 @@ {{("000000"+sale.itemFk).slice(-6)}} - + {{::sale.quantity}} diff --git a/client/ticket/src/sale-checked/index.js b/client/ticket/src/sale-checked/index.js index 2f69aec4d..08157bc9d 100644 --- a/client/ticket/src/sale-checked/index.js +++ b/client/ticket/src/sale-checked/index.js @@ -6,23 +6,7 @@ class Controller { this.$stateParams = $stateParams; this.filter = { include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } + relation: 'item' }, { relation: 'isChecked', diff --git a/client/ticket/src/sale-tracking/index.html b/client/ticket/src/sale-tracking/index.html index 6f3ce16e6..7f52cba71 100644 --- a/client/ticket/src/sale-tracking/index.html +++ b/client/ticket/src/sale-tracking/index.html @@ -39,7 +39,7 @@ {{("000000"+sale.itemFk).slice(-6)}} - + {{::sale.quantity}} {{::sale.originalQuantity}} - + {{::sale.quantity}} {{::sale.price | currency:'€':2}} {{::sale.discount}} % diff --git a/client/ticket/src/volume/index.html b/client/ticket/src/volume/index.html index 83da50ce7..8fdddb051 100644 --- a/client/ticket/src/volume/index.html +++ b/client/ticket/src/volume/index.html @@ -39,7 +39,7 @@ {{("000000"+sale.itemFk).slice(-6)}} - + {{::sale.quantity}} {{::sale.volume.m3 | number:3}} diff --git a/client/ticket/src/volume/index.js b/client/ticket/src/volume/index.js index cc69ca3b3..cbdb91559 100644 --- a/client/ticket/src/volume/index.js +++ b/client/ticket/src/volume/index.js @@ -8,23 +8,7 @@ class Controller { this.$stateParams = $stateParams; this.filter = { include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } + relation: 'item' }] }; @@ -33,17 +17,16 @@ class Controller { onDataChange() { this.$http.get(`/api/tickets/${this.ticket.id}/getVolume`) - .then(response => { - if (response.data) { - this.$scope.model.data.forEach(sale => { - response.data.volumes.forEach(volume => { - if (sale.id === volume.saleFk) { - sale.volume = volume; - } + .then(response => { + if (response.data) { + this.$scope.model.data.forEach(sale => { + response.data.volumes.forEach(volume => { + if (sale.id === volume.saleFk) + sale.volume = volume; + }); }); - }); - } - }); + } + }); } showDescriptor(event, itemFk) { diff --git a/services/loopback/common/methods/sale/priceDifference.js b/services/loopback/common/methods/sale/priceDifference.js index e2731958d..33958d2f4 100644 --- a/services/loopback/common/methods/sale/priceDifference.js +++ b/services/loopback/common/methods/sale/priceDifference.js @@ -25,30 +25,14 @@ module.exports = Self => { } }); - Self.priceDifference = async(ticketFk, data) => { + Self.priceDifference = async (ticketFk, data) => { let filter = { where: { ticketFk: ticketFk }, order: 'concept ASC', include: [{ - relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } + relation: 'item' }] }; let salesObj = {}; diff --git a/services/loopback/common/methods/ticket/summary.js b/services/loopback/common/methods/ticket/summary.js index 6f24988f0..e4314024b 100644 --- a/services/loopback/common/methods/ticket/summary.js +++ b/services/loopback/common/methods/ticket/summary.js @@ -92,22 +92,6 @@ module.exports = Self => { order: 'itemFk ASC', include: [{ relation: 'item', - scope: { - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - }, - fields: ['itemFk', 'name'] - } }] }; diff --git a/services/loopback/common/models/item.json b/services/loopback/common/models/item.json index ca8585c06..08cefab2e 100644 --- a/services/loopback/common/models/item.json +++ b/services/loopback/common/models/item.json @@ -75,6 +75,18 @@ }, "value8": { "type": "String" + }, + "tag9": { + "type": "String" + }, + "value9": { + "type": "String" + }, + "tag10": { + "type": "String" + }, + "value10": { + "type": "String" } }, "relations": { diff --git a/services/order/common/methods/order/summary.js b/services/order/common/methods/order/summary.js index 6a1cfeacb..e860209b4 100644 --- a/services/order/common/methods/order/summary.js +++ b/services/order/common/methods/order/summary.js @@ -59,12 +59,7 @@ module.exports = Self => { relation: 'rows', scope: { include: { - relation: 'item', - scope: { - include: { - relation: 'tags' - } - } + relation: 'item' } } } diff --git a/services/ticket/common/methods/sale-tracking/listSaleTracking.js b/services/ticket/common/methods/sale-tracking/listSaleTracking.js index 9a6b024e1..1d74fce58 100644 --- a/services/ticket/common/methods/sale-tracking/listSaleTracking.js +++ b/services/ticket/common/methods/sale-tracking/listSaleTracking.js @@ -46,23 +46,7 @@ module.exports = Self => { let salesFilter = { include: [ { - relation: 'item', - scope: { - fields: ['itemFk', 'name'], - include: { - relation: 'tags', - scope: { - fields: ['tagFk', 'value'], - include: { - relation: 'tag', - scope: { - fields: ['name'] - } - }, - limit: 6 - } - } - } + relation: 'item' } ], where: {ticketFk: filter.where.ticketFk}