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

76 lines
2.0 KiB
JavaScript
Raw Normal View History

2017-12-20 13:36:12 +00:00
import ngModule from '../module';
class Controller {
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: [
2018-04-16 11:47:16 +00:00
{relation: "itemType",
scope: {
fields: ['name', 'workerFk', 'warehouseFk'],
2018-04-16 11:47:16 +00:00
include: {
relation: 'worker',
fields: ['firstName', 'name']
}
}
},
2017-12-21 13:09:55 +00:00
{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
}
Controller.$inject = ['$http', '$state', '$timeout'];
2017-12-20 13:36:12 +00:00
ngModule.component('vnItemCard', {
template: require('./index.html'),
controller: Controller
2017-12-20 13:36:12 +00:00
});