salix/client/item/src/last-entries/index.js

48 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-06-20 09:39:29 +00:00
import ngModule from '../module';
import './style.scss';
class Controller {
constructor($scope, $http) {
this.$ = $scope;
this.$http = $http;
this.entries = [];
}
set item(value) {
this._item = value;
2018-06-20 10:29:30 +00:00
this._defaultEntriesDate();
this._getLastEntries();
2018-06-20 09:39:29 +00:00
}
get item() {
return this._item;
}
_defaultEntriesDate() {
let defaultDate;
defaultDate = new Date();
defaultDate.setDate(defaultDate.getDate() - 75);
2018-06-20 10:29:30 +00:00
defaultDate.setHours(0, 0, 0, 0);
2018-06-20 09:39:29 +00:00
this.entriesDate = defaultDate;
}
2018-06-20 10:29:30 +00:00
_getLastEntries() {
if (!this.entriesDate || !this.item)
2018-06-20 09:39:29 +00:00
return;
2018-06-20 10:29:30 +00:00
let filter = {itemFk: this.item.id, date: this.entriesDate};
2018-06-20 09:39:29 +00:00
this.$http.get(`/item/api/Items/getLastEntries?filter=${JSON.stringify(filter)}`).then(res => {
this.entries = res.data;
});
}
}
Controller.$inject = ['$scope', '$http'];
ngModule.component('vnItemLastEntries', {
template: require('./index.html'),
controller: Controller,
bindings: {
item: '<'
}
});