import ngModule from '../module'; class ItemCard { constructor($http, $state, $timeout) { this.$http = $http; this.$state = $state; this.$timeout = $timeout; this.item = null; this.tags = {}; this.itemTags = null; } _getItemTags() { let filter = { where: {itemFk: this.$state.params.id}, order: "priority ASC", include: {relation: "tag"} }; this.$http.get(`/item/api/ItemTags?filter=${JSON.stringify(filter)}`).then(response => { this.itemTags = response.data; }); } _getTags() { this.$http.get(`/item/api/Tags`).then(response => { response.data.forEach(tag => { this.tags[tag.id] = Object.assign({}, tag); }); }); } _getItem() { let filter = { include: [ {relation: "itemType"}, {relation: "origin"}, {relation: "ink"}, {relation: "producer"}, {relation: "intrastat"}, {relation: "expence"} ] }; this.$http.get(`/item/api/Items/${this.$state.params.id}?filter=${JSON.stringify(filter)}`) .then(res => { if (res.data && res.data.id) { this.$timeout(() => { this.item = res.data; }); } } ); } $onInit() { this._getItem(); this._getTags(); this._getItemTags(); } } ItemCard.$inject = ['$http', '$state', '$timeout']; ngModule.component('vnItemCard', { template: require('./card.html'), controller: ItemCard });