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

40 lines
1.0 KiB
JavaScript
Raw Normal View History

import ngModule from '../module';
class Controller {
2018-02-20 13:30:02 +00:00
constructor($http, $state) {
this.$http = $http;
this.$state = $state;
}
2018-02-21 12:10:23 +00:00
_getBotanical() {
2018-02-20 13:30:02 +00:00
let filter = {
2018-02-21 07:44:00 +00:00
where: {itemFk: this.$state.params.id},
2018-02-20 13:30:02 +00:00
include: [{relation: 'genus'}, {relation: 'specie'}]
};
2018-02-21 07:44:00 +00:00
this.$http.get(`/item/api/ItemBotanicals?filter=${JSON.stringify(filter)}`)
2018-02-20 13:30:02 +00:00
.then(res => {
2018-02-21 07:44:00 +00:00
if (res.data.length) {
this.botanical = res.data[0];
} else {
this.botanical = {
itemFk: this.$state.params.id,
botanical: null,
genusFk: null,
specieFk: null
};
2018-02-20 13:30:02 +00:00
}
});
}
2018-02-21 12:10:23 +00:00
$onInit() {
this._getBotanical();
}
2018-02-20 13:30:02 +00:00
}
Controller.$inject = ['$http', '$state'];
2018-02-20 13:30:02 +00:00
ngModule.component('vnItemBotanical', {
template: require('./index.html'),
controller: Controller
});