import ngModule from '../module'; class Controller { 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", scope: { fields: ['name', 'workerFk', 'warehouseFk'], include: { relation: 'worker', fields: ['firstName', 'name'] } } }, {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(); } } Controller.$inject = ['$http', '$state', '$timeout']; ngModule.component('vnItemCard', { template: require('./index.html'), controller: Controller });