Changed the location of the function
This commit is contained in:
parent
28bd535e2b
commit
ca53ec7c23
|
@ -4,13 +4,7 @@ module.exports = Self => {
|
||||||
Self.remoteMethodCtx('sendSms', {
|
Self.remoteMethodCtx('sendSms', {
|
||||||
description: 'Sends a SMS to each client of the routes, each client only recieves the SMS once',
|
description: 'Sends a SMS to each client of the routes, each client only recieves the SMS once',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [{
|
accepts: [
|
||||||
arg: 'id',
|
|
||||||
type: 'string',
|
|
||||||
required: true,
|
|
||||||
description: 'The routes Ids, is separated by commas',
|
|
||||||
http: {source: 'path'}
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
arg: 'destination',
|
arg: 'destination',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
|
@ -27,12 +21,12 @@ module.exports = Self => {
|
||||||
root: true
|
root: true
|
||||||
},
|
},
|
||||||
http: {
|
http: {
|
||||||
path: `/:id/sendSms`,
|
path: `/sendSms`,
|
||||||
verb: 'POST'
|
verb: 'POST'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.sendSms = async(ctx, id, destination, message) => {
|
Self.sendSms = async(ctx, destination, message) => {
|
||||||
const targetClients = destination.split(',');
|
const targetClients = destination.split(',');
|
||||||
|
|
||||||
const allSms = [];
|
const allSms = [];
|
||||||
|
|
|
@ -7,6 +7,29 @@
|
||||||
model="model"
|
model="model"
|
||||||
options="$ctrl.smartTableOptions"
|
options="$ctrl.smartTableOptions"
|
||||||
expr-builder="$ctrl.exprBuilder(param, value)">
|
expr-builder="$ctrl.exprBuilder(param, value)">
|
||||||
|
<slot-actions>
|
||||||
|
<section class="header">
|
||||||
|
<vn-tool-bar class="vn-mb-md">
|
||||||
|
<vn-button
|
||||||
|
icon="icon-clone"
|
||||||
|
ng-show="$ctrl.totalChecked > 0"
|
||||||
|
ng-click="$ctrl.openClonationDialog()"
|
||||||
|
vn-tooltip="Clone selected routes">
|
||||||
|
</vn-button>
|
||||||
|
<vn-button
|
||||||
|
icon="cloud_download"
|
||||||
|
ng-show="$ctrl.totalChecked > 0"
|
||||||
|
ng-click="$ctrl.showRouteReport()"
|
||||||
|
vn-tooltip="Download selected routes as PDF">
|
||||||
|
</vn-button>
|
||||||
|
<vn-button
|
||||||
|
icon="check"
|
||||||
|
ng-show="$ctrl.totalChecked > 0"
|
||||||
|
ng-click="$ctrl.markAsServed()"
|
||||||
|
vn-tooltip="Mark as served">
|
||||||
|
</vn-button>
|
||||||
|
</section>
|
||||||
|
</slot-actions>
|
||||||
<slot-table>
|
<slot-table>
|
||||||
<table model="model">
|
<table model="model">
|
||||||
<thead>
|
<thead>
|
||||||
|
@ -160,42 +183,6 @@
|
||||||
|
|
||||||
<div fixed-bottom-right>
|
<div fixed-bottom-right>
|
||||||
<vn-vertical style="align-items: center;">
|
<vn-vertical style="align-items: center;">
|
||||||
<a vn-bind="+">
|
|
||||||
<vn-button class="round md vn-mb-sm"
|
|
||||||
icon="icon-clone"
|
|
||||||
vn-tooltip="Clone selected routes"
|
|
||||||
ng-click="$ctrl.openClonationDialog()"
|
|
||||||
ng-show="$ctrl.totalChecked > 0"
|
|
||||||
tooltip-position="left">
|
|
||||||
</vn-button>
|
|
||||||
</a>
|
|
||||||
<a vn-bind="+">
|
|
||||||
<vn-button class="round md vn-mb-sm"
|
|
||||||
icon="cloud_download"
|
|
||||||
vn-tooltip="Download selected routes as PDF"
|
|
||||||
ng-click="$ctrl.showRouteReport()"
|
|
||||||
ng-show="$ctrl.totalChecked > 0"
|
|
||||||
tooltip-position="left">
|
|
||||||
</vn-button>
|
|
||||||
</a>
|
|
||||||
<a vn-bind="+">
|
|
||||||
<vn-button class="round md vn-mb-sm"
|
|
||||||
icon="sms"
|
|
||||||
vn-tooltip="Send SMS to all clients"
|
|
||||||
ng-click="$ctrl.sendSms()"
|
|
||||||
ng-show="$ctrl.totalChecked > 0"
|
|
||||||
tooltip-position="left">
|
|
||||||
</vn-button>
|
|
||||||
</a>
|
|
||||||
<a vn-bind="+">
|
|
||||||
<vn-button class="round md vn-mb-sm"
|
|
||||||
icon="check"
|
|
||||||
vn-tooltip="Mark as served"
|
|
||||||
ng-click="$ctrl.markAsServed()"
|
|
||||||
ng-show="$ctrl.totalChecked > 0"
|
|
||||||
tooltip-position="left">
|
|
||||||
</vn-button>
|
|
||||||
</a>
|
|
||||||
<a ui-sref="route.create" vn-bind="+">
|
<a ui-sref="route.create" vn-bind="+">
|
||||||
<vn-button class="round md vn-mb-sm"
|
<vn-button class="round md vn-mb-sm"
|
||||||
icon="add"
|
icon="add"
|
||||||
|
@ -206,13 +193,6 @@
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- Send SmS dialog -->
|
|
||||||
|
|
||||||
<vn-route-sms
|
|
||||||
vn-id="sms"
|
|
||||||
sms="$ctrl.newSMS">
|
|
||||||
</vn-route-sms>
|
|
||||||
|
|
||||||
<!-- Clonation dialog -->
|
<!-- Clonation dialog -->
|
||||||
<vn-dialog class="edit"
|
<vn-dialog class="edit"
|
||||||
vn-id="clonationDialog"
|
vn-id="clonationDialog"
|
||||||
|
|
|
@ -132,66 +132,6 @@ export default class Controller extends Section {
|
||||||
for (let routeId of routes)
|
for (let routeId of routes)
|
||||||
this.$http.patch(`Routes/${routeId}`, params);
|
this.$http.patch(`Routes/${routeId}`, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
async sendSms() {
|
|
||||||
this.vnApp.showMessage(this.$t('Retrieving data from the routes'));
|
|
||||||
try {
|
|
||||||
const routes = [];
|
|
||||||
const tickets = [];
|
|
||||||
const clientsFk = [];
|
|
||||||
const clients = [];
|
|
||||||
|
|
||||||
for (let route of this.checked)
|
|
||||||
routes.push((route.id));
|
|
||||||
|
|
||||||
for (let route of routes) {
|
|
||||||
let filter = {where: {routeFk: route}};
|
|
||||||
let currentTickets = await this.$http.get(`Tickets?filter=${JSON.stringify(filter)}`);
|
|
||||||
for (let ticket of currentTickets.data)
|
|
||||||
tickets.push(ticket);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let ticket of tickets) {
|
|
||||||
if (!clientsFk.filter(e => e === ticket.clientFk).length > 0)
|
|
||||||
clientsFk.push(ticket.clientFk);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let client of clientsFk) {
|
|
||||||
let currentClient = await this.$http.get(`Clients/${client}`);
|
|
||||||
clients.push(currentClient.data);
|
|
||||||
}
|
|
||||||
|
|
||||||
let destination = '';
|
|
||||||
let destinationFk = '';
|
|
||||||
let routesId = '';
|
|
||||||
|
|
||||||
for (let client of clients) {
|
|
||||||
if (destination !== '')
|
|
||||||
destination = destination + ',';
|
|
||||||
if (destinationFk !== '')
|
|
||||||
destinationFk = destinationFk + ',';
|
|
||||||
destination = destination + client.phone;
|
|
||||||
destinationFk = destinationFk + client.id;
|
|
||||||
}
|
|
||||||
|
|
||||||
for (let route of routes) {
|
|
||||||
if (routesId !== '')
|
|
||||||
routesId = routesId + ',';
|
|
||||||
routesId = routesId + route;
|
|
||||||
}
|
|
||||||
this.newSMS = Object.assign({
|
|
||||||
routesId: routesId,
|
|
||||||
destinationFk: destinationFk,
|
|
||||||
destination: destination
|
|
||||||
});
|
|
||||||
|
|
||||||
this.$.sms.open();
|
|
||||||
return true;
|
|
||||||
} catch (e) {
|
|
||||||
this.vnApp.showError(this.$t(e.message));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$element', '$scope', 'vnReport'];
|
Controller.$inject = ['$element', '$scope', 'vnReport'];
|
||||||
|
|
|
@ -1,19 +1,10 @@
|
||||||
<vn-dialog
|
<vn-dialog
|
||||||
vn-id="SMSDialog"
|
vn-id="SMSDialog"
|
||||||
on-accept="$ctrl.onResponse()"
|
on-accept="$ctrl.onResponse()"
|
||||||
message="Send SMS">
|
message="Send SMS to the selected tickets">
|
||||||
<tpl-body>
|
<tpl-body>
|
||||||
<section class="SMSDialog">
|
<section class="SMSDialog">
|
||||||
<!--vn-horizontal>
|
<vn-horizontal>
|
||||||
<vn-textfield
|
|
||||||
vn-one
|
|
||||||
label="Routes to notify"
|
|
||||||
ng-model="$ctrl.sms.routesId"
|
|
||||||
required="true"
|
|
||||||
rule>
|
|
||||||
</vn-textfield>
|
|
||||||
</vn-horizontal-->
|
|
||||||
<vn-horizontal >
|
|
||||||
<vn-textarea vn-one
|
<vn-textarea vn-one
|
||||||
vn-id="message"
|
vn-id="message"
|
||||||
label="Message"
|
label="Message"
|
||||||
|
|
|
@ -25,7 +25,7 @@ class Controller extends Component {
|
||||||
if (this.charactersRemaining() < 0)
|
if (this.charactersRemaining() < 0)
|
||||||
throw new Error(`The message it's too long`);
|
throw new Error(`The message it's too long`);
|
||||||
|
|
||||||
this.$http.post(`Routes/${this.sms.routesId}/sendSms`, this.sms).then(res => {
|
this.$http.post(`Routes/sendSms`, this.sms).then(res => {
|
||||||
this.vnApp.showMessage(this.$t('SMS sent!'));
|
this.vnApp.showMessage(this.$t('SMS sent!'));
|
||||||
|
|
||||||
if (res.data) this.emit('send', {response: res.data});
|
if (res.data) this.emit('send', {response: res.data});
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
Send SMS: Enviar SMS
|
Send SMS to the selected tickets: Enviar SMS a los tickets seleccionados
|
||||||
Routes to notify: Rutas a notificar
|
Routes to notify: Rutas a notificar
|
||||||
Message: Mensaje
|
Message: Mensaje
|
||||||
SMS sent!: ¡SMS enviado!
|
SMS sent!: ¡SMS enviado!
|
||||||
|
|
|
@ -29,13 +29,18 @@
|
||||||
disabled="!$ctrl.isChecked"
|
disabled="!$ctrl.isChecked"
|
||||||
ng-click="$ctrl.deletePriority()"
|
ng-click="$ctrl.deletePriority()"
|
||||||
vn-tooltip="Delete priority"
|
vn-tooltip="Delete priority"
|
||||||
icon="filter_alt_off">
|
icon="filter_alt">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
<vn-button
|
<vn-button
|
||||||
ng-click="$ctrl.setOrderedPriority($ctrl.tickets)"
|
ng-click="$ctrl.setOrderedPriority($ctrl.tickets)"
|
||||||
vn-tooltip="Renumber all tickets in the order you see on the screen"
|
vn-tooltip="Renumber all tickets in the order you see on the screen"
|
||||||
icon="format_list_numbered">
|
icon="format_list_numbered">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
|
<vn-button
|
||||||
|
icon="sms"
|
||||||
|
vn-tooltip="Send SMS to all clients"
|
||||||
|
ng-click="$ctrl.sendSms()">
|
||||||
|
</vn-button>
|
||||||
</vn-tool-bar>
|
</vn-tool-bar>
|
||||||
<vn-table class="vn-pt-md" model="model" auto-load="false" vn-droppable="$ctrl.onDrop($event)">
|
<vn-table class="vn-pt-md" model="model" auto-load="false" vn-droppable="$ctrl.onDrop($event)">
|
||||||
<vn-thead>
|
<vn-thead>
|
||||||
|
@ -149,19 +154,29 @@
|
||||||
route="$ctrl.$params"
|
route="$ctrl.$params"
|
||||||
parent-reload="$ctrl.$.model.refresh()">
|
parent-reload="$ctrl.$.model.refresh()">
|
||||||
</vn-route-ticket-popup>
|
</vn-route-ticket-popup>
|
||||||
|
<div fixed-bottom-right>
|
||||||
<vn-float-button
|
<vn-vertical style="align-items: center;">
|
||||||
icon="add"
|
<a vn-bind="+">
|
||||||
|
<vn-button
|
||||||
|
class="round md vn-mb-sm"
|
||||||
ng-click="$ctrl.$.ticketPopup.show()"
|
ng-click="$ctrl.$.ticketPopup.show()"
|
||||||
|
icon="add"
|
||||||
vn-tooltip="Add ticket"
|
vn-tooltip="Add ticket"
|
||||||
vn-acl="delivery"
|
vn-acl="delivery"
|
||||||
vn-acl-action="remove"
|
vn-acl-action="remove"
|
||||||
vn-bind="+"
|
tooltip-position="left">
|
||||||
fixed-bottom-right>
|
</vn-button>
|
||||||
</vn-float-button>
|
</a>
|
||||||
|
</vn-vertical>
|
||||||
|
</div>
|
||||||
<vn-ticket-descriptor-popover
|
<vn-ticket-descriptor-popover
|
||||||
vn-id="ticket-descriptor">
|
vn-id="ticket-descriptor">
|
||||||
</vn-ticket-descriptor-popover>
|
</vn-ticket-descriptor-popover>
|
||||||
<vn-client-descriptor-popover
|
<vn-client-descriptor-popover
|
||||||
vn-id="client-descriptor">
|
vn-id="client-descriptor">
|
||||||
</vn-client-descriptor-popover>
|
</vn-client-descriptor-popover>
|
||||||
|
<!-- SMS Dialog -->
|
||||||
|
<vn-route-sms
|
||||||
|
vn-id="sms"
|
||||||
|
sms="$ctrl.newSMS">
|
||||||
|
</vn-route-sms>
|
|
@ -161,6 +161,37 @@ class Controller extends Section {
|
||||||
throw error;
|
throw error;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async sendSms() {
|
||||||
|
try {
|
||||||
|
const clientsFk = [];
|
||||||
|
const clientsName = [];
|
||||||
|
const clients = [];
|
||||||
|
|
||||||
|
const selectedTickets = this.getSelectedItems(this.$.$ctrl.tickets);
|
||||||
|
|
||||||
|
for (let ticket of selectedTickets) {
|
||||||
|
clientsFk.push(ticket.clientFk);
|
||||||
|
let userContact = await this.$http.get(`Clients/${ticket.clientFk}`);
|
||||||
|
clientsName.push(userContact.data.name);
|
||||||
|
clients.push(userContact.data.phone);
|
||||||
|
}
|
||||||
|
|
||||||
|
const destinationFk = String(clientsFk);
|
||||||
|
const destination = String(clients);
|
||||||
|
|
||||||
|
this.newSMS = Object.assign({
|
||||||
|
destinationFk: destinationFk,
|
||||||
|
destination: destination
|
||||||
|
});
|
||||||
|
|
||||||
|
this.$.sms.open();
|
||||||
|
return true;
|
||||||
|
} catch (e) {
|
||||||
|
this.vnApp.showError(this.$t(e.message));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ngModule.vnComponent('vnRouteTickets', {
|
ngModule.vnComponent('vnRouteTickets', {
|
||||||
|
|
Loading…
Reference in New Issue