salix/modules/route/front/index/index.js

152 lines
4.5 KiB
JavaScript
Raw Permalink Normal View History

2019-03-21 12:46:14 +00:00
import ngModule from '../module';
2020-03-17 14:24:55 +00:00
import Section from 'salix/components/section';
2019-03-21 12:46:14 +00:00
2020-03-17 14:24:55 +00:00
export default class Controller extends Section {
2020-08-25 08:00:21 +00:00
constructor($element, $, vnReport) {
super($element, $);
this.vnReport = vnReport;
this.droppableElement = 'a.vn-tr';
2020-08-25 08:00:21 +00:00
}
preview(route) {
2019-03-21 12:46:14 +00:00
this.routeSelected = route;
2019-03-22 10:10:23 +00:00
this.$.summary.show();
2019-03-21 12:46:14 +00:00
}
2020-08-25 08:00:21 +00:00
showTicketPopup(route) {
this.routeSelected = route;
this.$.ticketPopup.show();
}
2020-08-25 08:00:21 +00:00
get checked() {
const rows = this.$.model.data || [];
const checkedRows = [];
for (let row of rows) {
if (row.checked)
checkedRows.push(row);
}
return checkedRows;
}
get totalChecked() {
return this.checked.length;
}
showRouteReport() {
const routesIds = [];
2024-03-28 06:22:28 +00:00
const access_token = this.vnToken.tokenMultimedia;
2020-08-25 08:00:21 +00:00
for (let route of this.checked)
routesIds.push(route.id);
const stringRoutesIds = routesIds.join(',');
2020-08-25 08:00:21 +00:00
if (this.checked.length <= 1) {
2024-03-28 06:22:28 +00:00
const url = `api/Routes/${stringRoutesIds}/driver-route-pdf?access_token=${access_token}`;
window.open(url, '_blank');
} else {
const serializedParams = this.$httpParamSerializer({
2024-03-28 06:22:28 +00:00
access_token,
id: stringRoutesIds
});
const url = `api/Routes/downloadZip?${serializedParams}`;
window.open(url, '_blank');
}
2020-08-25 08:00:21 +00:00
}
2020-12-24 10:31:20 +00:00
openClonationDialog() {
this.$.clonationDialog.show();
2023-01-16 14:18:24 +00:00
this.createdDate = Date.vnNew();
2020-12-24 10:31:20 +00:00
}
cloneSelectedRoutes() {
2021-03-30 07:55:51 +00:00
try {
if (!this.createdDate)
throw new Error(`The date can't be empty`);
2020-12-24 10:31:20 +00:00
2021-03-30 07:55:51 +00:00
const routesIds = [];
for (let route of this.checked)
routesIds.push(route.id);
return this.$http.post('Routes/clone', {ids: routesIds, created: this.createdDate}).then(() => {
this.$.model.refresh();
this.vnApp.showSuccess(this.$t('Data saved!'));
});
} catch (e) {
this.vnApp.showError(this.$t(e.message));
}
2020-12-24 10:31:20 +00:00
}
onDrop($event) {
const target = $event.target;
const droppable = target.closest(this.droppableElement);
const ticketId = $event.dataTransfer.getData('Text');
const routeId = droppable.id;
if (isNaN(ticketId)) {
const regexp = new RegExp(/\/ticket\/([0-9]+)\//i);
const matches = ticketId.match(regexp);
if (matches && matches.length)
this.insert(routeId, matches[1]);
else
this.vnApp.showError(this.$t('Ticket not found'));
}
if (!isNaN(ticketId))
this.insert(routeId, ticketId);
}
insert(routeId, ticketId) {
routeId = parseInt(routeId);
ticketId = parseInt(ticketId);
const query = `Routes/${routeId}/insertTicket`;
return this.$http.patch(query, {ticketId}).then(() => {
this.vnApp.showSuccess(this.$t('Data saved!'));
this.$.model.refresh();
}).catch(error => {
if (error.status == 404)
return this.vnApp.showError(this.$t('Ticket not found'));
throw error;
});
}
2022-06-23 12:14:13 +00:00
updateAttributes(route) {
if (route.started == null || route.finished == null)
return this.vnApp.showError(this.$t('You must select a valid time'));
if (route.created == null)
return this.vnApp.showError(this.$t('You must select a valid date'));
const params = {
workerFk: route.workerFk,
agencyModeFk: route.agencyModeFk,
vehicleFk: route.vehicleFk,
created: route.created,
description: route.description,
started: route.started,
finished: route.finished
};
const query = `Routes/${route.id}/`;
this.$http.patch(query, params).then(res => {
this.vnApp.showSuccess(this.$t('Data saved!'));
});
}
2022-09-13 11:34:32 +00:00
markAsServed() {
const routes = [];
for (let route of this.checked)
routes.push(route.id);
const params = {isOk: true};
for (let routeId of routes)
this.$http.patch(`Routes/${routeId}`, params);
}
2019-03-21 12:46:14 +00:00
}
2020-08-25 08:00:21 +00:00
Controller.$inject = ['$element', '$scope', 'vnReport'];
ngModule.vnComponent('vnRouteIndex', {
2019-03-21 12:46:14 +00:00
template: require('./index.html'),
controller: Controller
});