Changed the location of the function
This commit is contained in:
parent
28bd535e2b
commit
ca53ec7c23
|
@ -4,35 +4,29 @@ module.exports = Self => {
|
|||
Self.remoteMethodCtx('sendSms', {
|
||||
description: 'Sends a SMS to each client of the routes, each client only recieves the SMS once',
|
||||
accessType: 'WRITE',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'string',
|
||||
required: true,
|
||||
description: 'The routes Ids, is separated by commas',
|
||||
http: {source: 'path'}
|
||||
},
|
||||
{
|
||||
arg: 'destination',
|
||||
type: 'string',
|
||||
description: 'A comma separated string of destinations',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'message',
|
||||
type: 'string',
|
||||
required: true,
|
||||
}],
|
||||
accepts: [
|
||||
{
|
||||
arg: 'destination',
|
||||
type: 'string',
|
||||
description: 'A comma separated string of destinations',
|
||||
required: true,
|
||||
},
|
||||
{
|
||||
arg: 'message',
|
||||
type: 'string',
|
||||
required: true,
|
||||
}],
|
||||
returns: {
|
||||
type: 'object',
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/sendSms`,
|
||||
path: `/sendSms`,
|
||||
verb: 'POST'
|
||||
}
|
||||
});
|
||||
|
||||
Self.sendSms = async(ctx, id, destination, message) => {
|
||||
Self.sendSms = async(ctx, destination, message) => {
|
||||
const targetClients = destination.split(',');
|
||||
|
||||
const allSms = [];
|
||||
|
|
|
@ -7,6 +7,29 @@
|
|||
model="model"
|
||||
options="$ctrl.smartTableOptions"
|
||||
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>
|
||||
<table model="model">
|
||||
<thead>
|
||||
|
@ -160,42 +183,6 @@
|
|||
|
||||
<div fixed-bottom-right>
|
||||
<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="+">
|
||||
<vn-button class="round md vn-mb-sm"
|
||||
icon="add"
|
||||
|
@ -206,13 +193,6 @@
|
|||
</vn-vertical>
|
||||
</div>
|
||||
|
||||
<!-- Send SmS dialog -->
|
||||
|
||||
<vn-route-sms
|
||||
vn-id="sms"
|
||||
sms="$ctrl.newSMS">
|
||||
</vn-route-sms>
|
||||
|
||||
<!-- Clonation dialog -->
|
||||
<vn-dialog class="edit"
|
||||
vn-id="clonationDialog"
|
||||
|
|
|
@ -132,66 +132,6 @@ export default class Controller extends Section {
|
|||
for (let routeId of routes)
|
||||
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'];
|
||||
|
|
|
@ -1,19 +1,10 @@
|
|||
<vn-dialog
|
||||
vn-id="SMSDialog"
|
||||
on-accept="$ctrl.onResponse()"
|
||||
message="Send SMS">
|
||||
message="Send SMS to the selected tickets">
|
||||
<tpl-body>
|
||||
<section class="SMSDialog">
|
||||
<!--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-horizontal>
|
||||
<vn-textarea vn-one
|
||||
vn-id="message"
|
||||
label="Message"
|
||||
|
|
|
@ -25,7 +25,7 @@ class Controller extends Component {
|
|||
if (this.charactersRemaining() < 0)
|
||||
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!'));
|
||||
|
||||
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
|
||||
Message: Mensaje
|
||||
SMS sent!: ¡SMS enviado!
|
||||
|
|
|
@ -29,13 +29,18 @@
|
|||
disabled="!$ctrl.isChecked"
|
||||
ng-click="$ctrl.deletePriority()"
|
||||
vn-tooltip="Delete priority"
|
||||
icon="filter_alt_off">
|
||||
icon="filter_alt">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
ng-click="$ctrl.setOrderedPriority($ctrl.tickets)"
|
||||
vn-tooltip="Renumber all tickets in the order you see on the screen"
|
||||
icon="format_list_numbered">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
icon="sms"
|
||||
vn-tooltip="Send SMS to all clients"
|
||||
ng-click="$ctrl.sendSms()">
|
||||
</vn-button>
|
||||
</vn-tool-bar>
|
||||
<vn-table class="vn-pt-md" model="model" auto-load="false" vn-droppable="$ctrl.onDrop($event)">
|
||||
<vn-thead>
|
||||
|
@ -149,19 +154,29 @@
|
|||
route="$ctrl.$params"
|
||||
parent-reload="$ctrl.$.model.refresh()">
|
||||
</vn-route-ticket-popup>
|
||||
|
||||
<vn-float-button
|
||||
icon="add"
|
||||
ng-click="$ctrl.$.ticketPopup.show()"
|
||||
vn-tooltip="Add ticket"
|
||||
vn-acl="delivery"
|
||||
vn-acl-action="remove"
|
||||
vn-bind="+"
|
||||
fixed-bottom-right>
|
||||
</vn-float-button>
|
||||
<div fixed-bottom-right>
|
||||
<vn-vertical style="align-items: center;">
|
||||
<a vn-bind="+">
|
||||
<vn-button
|
||||
class="round md vn-mb-sm"
|
||||
ng-click="$ctrl.$.ticketPopup.show()"
|
||||
icon="add"
|
||||
vn-tooltip="Add ticket"
|
||||
vn-acl="delivery"
|
||||
vn-acl-action="remove"
|
||||
tooltip-position="left">
|
||||
</vn-button>
|
||||
</a>
|
||||
</vn-vertical>
|
||||
</div>
|
||||
<vn-ticket-descriptor-popover
|
||||
vn-id="ticket-descriptor">
|
||||
</vn-ticket-descriptor-popover>
|
||||
<vn-client-descriptor-popover
|
||||
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;
|
||||
});
|
||||
}
|
||||
|
||||
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', {
|
||||
|
|
Loading…
Reference in New Issue