salix/client/item/src/card/card.js

66 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-12-20 13:36:12 +00:00
import ngModule from '../module';
class ItemCard {
2018-02-20 13:30:02 +00:00
constructor($http, $state, $timeout) {
2017-12-21 13:09:55 +00:00
this.$http = $http;
this.$state = $state;
2018-02-20 13:30:02 +00:00
this.$timeout = $timeout;
2018-02-20 10:10:54 +00:00
2018-02-20 13:30:02 +00:00
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;
});
2017-12-20 13:36:12 +00:00
}
2017-12-21 13:09:55 +00:00
_getTags() {
this.$http.get(`/item/api/Tags`).then(response => {
response.data.forEach(tag => {
this.tags[tag.id] = Object.assign({}, tag);
});
});
}
_getItem() {
2017-12-21 13:09:55 +00:00
let filter = {
include: [
{relation: "itemType"},
{relation: "origin"},
{relation: "ink"},
{relation: "producer"},
2018-01-30 07:59:43 +00:00
{relation: "intrastat"},
{relation: "expence"}
2017-12-21 13:09:55 +00:00
]
};
2018-02-20 10:10:54 +00:00
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;
});
2018-02-20 10:10:54 +00:00
}
}
2017-12-21 13:09:55 +00:00
);
}
$onInit() {
this._getItem();
this._getTags();
this._getItemTags();
}
2017-12-20 13:36:12 +00:00
}
2018-02-20 13:30:02 +00:00
ItemCard.$inject = ['$http', '$state', '$timeout'];
2017-12-20 13:36:12 +00:00
ngModule.component('vnItemCard', {
2018-04-04 17:59:03 +00:00
template: require('./card.html'),
2017-12-20 13:36:12 +00:00
controller: ItemCard
});