import ngModule from '../module'; import Component from 'core/src/lib/component'; import './style.scss'; class Controller extends Component { constructor($element, $scope, $http, $timeout) { super($element, $scope); this.$http = $http; this.$timeout = $timeout; this._quicklinks = {}; this.isTooltip = true; this.clear(); } set quicklinks(value = {}) { this._quicklinks = Object.assign(value, this._quicklinks); } get quicklinks() { return this._quicklinks; } clear() { this.item = null; this.tags = {}; this.itemTags = null; } show() { this.$.popover.parent = this.parent; this.$.popover.show(); } _getTags() { this.$http.get(`/item/api/Tags`).then(response => { response.data.forEach(tag => { this.tags[tag.id] = Object.assign({}, tag); }); this.$.popover.relocate(); }); } _getItem() { let filter = { fields: ['id', 'name', 'image'], include: [ { relation: 'itemType', scope: { fields: ['workerFk'], include: { relation: 'worker', scope: { fields: ['firstName', 'name'] } } } }, { relation: 'tags', scope: { fields: ['value', 'tagFk'], order: 'priority ASC', include: { relation: 'tag', scope: { fields: ['name'] } } } } ] }; let json = encodeURIComponent(JSON.stringify(filter)); this.$http.get(`/item/api/Items/${this._itemFk}?filter=${json}`) .then(res => { if (!res.data) return; this.item = res.data; this.itemTags = this.item.tags; this.$.popover.relocate(); } ); } set itemFk(id) { this._itemFk = id; if (id) { this._getItem(); this._getTags(); } else this.clear(); } } Controller.$inject = ['$element', '$scope', '$http', '$timeout']; ngModule.component('vnItemDescriptorPopover', { template: require('./index.html'), bindings: { itemFk: '<', quicklinks: '<' }, controller: Controller });