salix/modules/travel/front/summary/index.js

78 lines
1.8 KiB
JavaScript

import ngModule from '../module';
import './style.scss';
import Component from 'core/lib/component';
class Controller extends Component {
constructor($element, $, $httpParamSerializer) {
super($element, $);
this.entries = [];
this.$httpParamSerializer = $httpParamSerializer;
}
get travel() {
return this._travel;
}
set travel(value) {
this._travel = value;
if (value && value.id) {
this.getTravel();
this.getEntries();
this.getThermographs();
}
}
getTravel() {
return this.$http.get(`/api/Travels/${this.travel.id}/getTravel`).then(response => {
this.travelData = response.data;
});
}
getEntries() {
return this.$http.get(`/api/Travels/${this.travel.id}/getEntries`).then(response => {
this.entries = response.data;
});
}
getThermographs() {
const params = {
filter: {
include: {
relation: 'warehouse',
scope: {
fields: ['id', 'name']
}
},
where: {
travelFk: this.travel.id
}
}
};
const serializedParams = this.$httpParamSerializer(params);
return this.$http.get(`TravelThermographs?${serializedParams}`).then(res => {
this.travelThermographs = res.data;
});
}
total(field) {
let total = 0;
for (let entry of this.entries)
total += entry[field];
return total;
}
}
Controller.$inject = ['$element', '$scope', '$httpParamSerializer'];
ngModule.component('vnTravelSummary', {
template: require('./index.html'),
controller: Controller,
bindings: {
travel: '<'
}
});