#762 refactor componente fetched tags

This commit is contained in:
Gerard 2018-11-06 10:49:38 +01:00
parent 35e6132b17
commit e06798cf90
24 changed files with 109 additions and 195 deletions

View File

@ -1,10 +1,10 @@
<vn-horizontal>
<vn-one>{{::$ctrl.concept}}</vn-one>
<vn-one>{{::$ctrl.item.name}}</vn-one>
<vn-auto>
<section
class="inline-tag ellipsize" ng-class="{'empty': !fetchedTag.value}"
ng-repeat="fetchedTag in $ctrl.tags track by $index"
vn-tooltip="{{::fetchedTag.tag.name}}: {{::fetchedTag.value}}">
vn-tooltip="{{::fetchedTag.name}}: {{::fetchedTag.value}}">
{{::fetchedTag.value}}
</section>
</vn-auto>

View File

@ -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: '<'
}
});

View File

@ -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;

View File

@ -20,7 +20,7 @@
<vn-label-value label="Buyer"
value="{{::$ctrl.item.firstName}} {{::$ctrl.item.worker}}">
</vn-label-value>
<vn-fetched-tags tags="$ctrl.item.tags"/>
<vn-fetched-tags max-length="4" item="$ctrl.item" class="noTitle"/>
</vn-one>
<vn-horizontal class="buttons">
<vn-icon

View File

@ -47,7 +47,7 @@
{{("000000"+row.itemFk).slice(-6)}}
</span>
</vn-td>
<vn-td><vn-fetched-tags concept="row.item.name" tags="row.item.tags"/></vn-td>
<vn-td><vn-fetched-tags max-length="6" item="row.item"/></vn-td>
<vn-td>{{row.warehouse.name}}</vn-td>
<vn-td>{{row.shipped | dashIfEmpty}}</vn-td>
<vn-td number>{{row.quantity}}</vn-td>

View File

@ -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'}]
};

View File

@ -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'}]
};

View File

@ -76,7 +76,7 @@
{{("000000"+row.itemFk).slice(-6)}}
</span>
</td>
<td><vn-fetched-tags concept="row.item.name" tags="row.item.tags"/></td>
<td><vn-fetched-tags max-length="6" item="row.item"/></td>
<td number>{{::row.quantity}}</td>
<td number>{{::row.price | currency:'€':2}}</td>
<td number>{{::row.quantity * row.price | currency:'€':2}}</td>

View File

@ -39,7 +39,7 @@
{{::row.itemFk}}
</span>
</vn-td>
<vn-td><vn-fetched-tags concept="row.item.name" tags="row.item.tags"/></vn-td>
<vn-td><vn-fetched-tags max-length="6" item="row.item"/></vn-td>
<vn-td number>{{::row.quantity}}</vn-td>
<vn-td number>{{::row.volume | number:3}}</vn-td>
</vn-tr>

View File

@ -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) {

View File

@ -51,7 +51,7 @@
</td>
<td rowspan="{{
::sale.components.length + 1
}}"><vn-fetched-tags concept="sale.concept" tags="sale.item.tags"/></td>
}}"><vn-fetched-tags max-length="6" item="sale.item"/></td>
<td rowspan="{{
::sale.components.length + 1
}}" number>{{::sale.quantity}}</td>

View File

@ -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;
}

View File

@ -16,7 +16,7 @@
<tbody>
<tr ng-repeat="sale in $ctrl.ticket.sale.items track by sale.id">
<td number>{{("000000"+sale.itemFk).slice(-6)}}</td>
<td><vn-fetched-tags concept="sale.concept" tags="sale.item.tags"/></td>
<td><vn-fetched-tags max-length="6" item="sale.item"/></td>
<td number>{{::sale.quantity}}</td>
<td number>{{::sale.price | currency: '€': 2}}</td>
<td number>{{::sale.component.newPrice | currency: '€': 2}}</td>

View File

@ -34,7 +34,7 @@
{{("000000"+sale.itemFk).slice(-6)}}
</span>
</vn-td>
<vn-td><vn-fetched-tags concept="sale.concept" tags="sale.item.tags"/></vn-td>
<vn-td><vn-fetched-tags max-length="6" item="sale.item"/></vn-td>
<vn-td number>{{::sale.quantity}}</vn-td>
</vn-tr>
</vn-tbody>

View File

@ -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',

View File

@ -39,7 +39,7 @@
{{("000000"+sale.itemFk).slice(-6)}}
</span>
</vn-td>
<vn-td><vn-fetched-tags concept="sale.concept" tags="sale.item.tags"/></vn-td>
<vn-td><vn-fetched-tags max-length="6" item="sale.item"/></vn-td>
<vn-td>{{::sale.quantity}}</vn-td>
<vn-td>{{::sale.originalQuantity}}</vn-td>
<vn-td title="{{::sale.firstName}} {{::sale.name}}"

View File

@ -82,7 +82,7 @@
{{("000000"+sale.itemFk).slice(-6)}}
</span>
</td>
<td><vn-fetched-tags concept="sale.concept" tags="sale.item.tags"/></td>
<td><vn-fetched-tags max-length="6" item="sale.item"/></td>
<td number>{{::sale.quantity}}</td>
<td number>{{::sale.price | currency:'€':2}}</td>
<td number>{{::sale.discount}} %</td>

View File

@ -39,7 +39,7 @@
{{("000000"+sale.itemFk).slice(-6)}}
</span>
</vn-td>
<vn-td><vn-fetched-tags concept="sale.concept" tags="sale.item.tags"/></vn-td>
<vn-td><vn-fetched-tags max-length="6" item="sale.item"/></vn-td>
<vn-td number>{{::sale.quantity}}</vn-td>
<vn-td number>{{::sale.volume.m3 | number:3}}</vn-td>
</vn-tr>

View File

@ -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) {

View File

@ -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 = {};

View File

@ -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']
}
}]
};

View File

@ -75,6 +75,18 @@
},
"value8": {
"type": "String"
},
"tag9": {
"type": "String"
},
"value9": {
"type": "String"
},
"tag10": {
"type": "String"
},
"value10": {
"type": "String"
}
},
"relations": {

View File

@ -59,12 +59,7 @@ module.exports = Self => {
relation: 'rows',
scope: {
include: {
relation: 'item',
scope: {
include: {
relation: 'tags'
}
}
relation: 'item'
}
}
}

View File

@ -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}