salix/client/item/src/summary/summary.js

95 lines
2.5 KiB
JavaScript
Raw Normal View History

2018-02-20 11:33:17 +00:00
import ngModule from '../module';
class ItemSummary {
constructor($http) {
this.$http = $http;
}
_getTags() {
let filter = {
where: {
itemFk: this.item.id
}
};
this.tags = [];
this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(Object.assign({}, filter, {include: {relation: 'tag'}}))}`).then(res => {
this.tags = res.data;
});
}
2018-03-08 08:47:56 +00:00
_getTaxes() {
let filter = {
fields: ['id', 'countryFk', 'taxClassFk'],
include: [{
relation: 'country',
scope: {fields: ['country']}
}, {
relation: 'taxClass',
scope: {fields: ['id', 'description']}
}]
};
let urlFilter = encodeURIComponent(JSON.stringify(filter));
let url = `/item/api/Items/${this.item.id}/taxes?filter=${urlFilter}`;
this.$http.get(url).then(json => {
this.taxes = json.data;
});
}
2018-02-20 11:33:17 +00:00
_getBotanical() {
let filter = {
2018-02-21 07:44:00 +00:00
where: {itemFk: this.item.id},
2018-02-20 11:33:17 +00:00
include: [{relation: 'genus'}, {relation: 'specie'}]
};
this.item.botanical = {};
2018-02-21 07:44:00 +00:00
this.$http.get(`/item/api/ItemBotanicals?filter=${JSON.stringify(filter)}`)
2018-02-20 11:33:17 +00:00
.then(res => {
2018-02-21 07:44:00 +00:00
if (res.data.length) {
this.item.botanical = res.data[0];
2018-02-20 11:33:17 +00:00
}
});
}
2018-02-20 13:51:46 +00:00
_getNiches() {
let filter = {
where: {itemFk: this.item.id},
include: {relation: 'warehouse'}
};
this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => {
this.niches = response.data;
});
}
2018-02-20 11:33:17 +00:00
_getBarcodes() {
let filter = {
where: {
itemFk: this.item.id
}
};
this.barcodes = [];
this.$http.get(`/item/api/ItemBarcodes?filter=${JSON.stringify(filter)}`).then(response => {
this.barcodes = response.data;
});
}
$onChanges() {
if (this.item && this.item.id) {
this._getTags();
2018-02-20 13:51:46 +00:00
this._getBarcodes();
this._getNiches();
2018-03-08 08:47:56 +00:00
this._getTaxes();
2018-02-20 11:33:17 +00:00
if (!this.item.botanical)
this._getBotanical();
}
}
}
ItemSummary.$inject = ['$http'];
ngModule.component('vnItemSummary', {
2018-04-04 17:59:03 +00:00
template: require('./summary.html'),
2018-02-20 11:33:17 +00:00
controller: ItemSummary,
bindings: {
item: '<'
}
});