import ngModule from '../module'; import Descriptor from 'salix/components/descriptor'; class Controller extends Descriptor { get route() { return this.entity; } set route(value) { this.entity = value; } showRouteReport() { this.showReport('driver-route', { clientId: this.vnConfig.storage.currentUserWorkerId, routeId: this.id }); } sendRouteReport() { const params = { recipient: user.emailUser.email, clientId: this.vnConfig.storage.currentUserWorkerId, routeId: this.id }; return this.$http.get(`email/driver-route`, {params}) .then(() => this.vnApp.showSuccess(this.$t('Report sent'))); } updateVolume() { this.$http.post(`Routes/${this.id}/updateVolume`) .then(() => { if (this.cardReload) this.cardReload(); this.vnApp.showSuccess(this.$t('Volume updated')); }); } loadData() { const filter = { fields: [ 'id', 'workerFk', 'agencyModeFk', 'created', 'm3', 'warehouseFk', 'description', 'vehicleFk', 'kmStart', 'kmEnd', 'started', 'finished', 'cost', 'zoneFk' ], include: [ { relation: 'agencyMode', scope: { fields: ['id', 'name'] } }, { relation: 'vehicle', scope: { fields: ['id', 'm3'] } }, { relation: 'zone', scope: { fields: ['id', 'name'] } }, { relation: 'worker', scope: { fields: ['userFk'], include: { relation: 'user', scope: { fields: ['id'], include: { relation: 'emailUser', scope: { fields: ['email'] } } } } } } ] }; return this.getData(`Routes/${this.id}`, {filter}) .then(res => this.entity = res.data); } } ngModule.vnComponent('vnRouteDescriptor', { template: require('./index.html'), controller: Controller, bindings: { route: '<', cardReload: '&?' } });