This commit is contained in:
parent
32555c47d0
commit
bb5c81a3e9
|
@ -311,9 +311,10 @@ export default {
|
|||
searchButton: 'vn-ticket-index vn-searchbar vn-icon[icon="search"]',
|
||||
moreMenu: 'vn-ticket-index vn-icon-menu[vn-id="more-button"] > div > vn-icon',
|
||||
moreMenuTurns: 'vn-ticket-index vn-icon-menu vn-drop-down > vn-popover li:nth-child(2)',
|
||||
sixthWeeklyTicketTurn: 'vn-ticket-weekly > form > div > vn-card > div > vn-table > div > vn-tbody > vn-tr:nth-child(6) > vn-td:nth-child(3) > vn-autocomplete > div > div > input',
|
||||
sixthWeeklyTicketTurn: 'vn-ticket-weekly vn-table vn-tr:nth-child(6) vn-autocomplete[field="weekly.weekDay"] input',
|
||||
weeklyTicket: 'vn-ticket-weekly vn-table > div > vn-tbody > vn-tr',
|
||||
sixthWeeklyTicketDeleteIcon: 'vn-ticket-weekly > form vn-tbody > vn-tr:nth-child(6) > vn-td:nth-child(6) > vn-icon-button[icon="delete"]'
|
||||
sixthWeeklyTicketDeleteIcon: 'vn-ticket-weekly vn-tr:nth-child(6) vn-icon-button[icon="delete"]',
|
||||
acceptDeleteTurn: 'vn-ticket-weekly > vn-confirm[vn-id="deleteWeekly"] button[response="ACCEPT"]'
|
||||
},
|
||||
createTicketView: {
|
||||
clientAutocomplete: 'vn-ticket-create vn-autocomplete[field="$ctrl.clientFk"]',
|
||||
|
|
|
@ -49,7 +49,7 @@ describe('Ticket descriptor path', () => {
|
|||
expect(url.hash).toContain('/summary');
|
||||
});
|
||||
|
||||
it('should add the ticket to thirsday turn using the descriptor more menu', async() => {
|
||||
it('should add the ticket to thursday turn using the descriptor more menu', async() => {
|
||||
const result = await nightmare
|
||||
.waitToClick(selectors.ticketDescriptor.moreMenu)
|
||||
.waitToClick(selectors.ticketDescriptor.moreMenuAddToTurn)
|
||||
|
@ -142,6 +142,7 @@ describe('Ticket descriptor path', () => {
|
|||
it('should delete the weekly ticket 11', async() => {
|
||||
const result = await nightmare
|
||||
.waitToClick(selectors.ticketsIndex.sixthWeeklyTicketDeleteIcon)
|
||||
.waitToClick(selectors.ticketsIndex.acceptDeleteTurn)
|
||||
.waitForLastSnackbar();
|
||||
|
||||
expect(result).toEqual('Data saved!');
|
||||
|
|
|
@ -0,0 +1,70 @@
|
|||
|
||||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const buildFilter = require('vn-loopback/util/filter').buildFilter;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethodCtx('filter', {
|
||||
description: 'Find all instances of the model matched by filter from the data source.',
|
||||
accessType: 'READ',
|
||||
accepts: [
|
||||
{
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: 'Filter defining where, order, offset, and limit - must be a JSON-encoded string',
|
||||
http: {source: 'query'}
|
||||
}, {
|
||||
arg: 'search',
|
||||
type: 'String',
|
||||
description: `If it's and integer searchs by id, otherwise it searchs by client id`,
|
||||
http: {source: 'query'}
|
||||
}
|
||||
],
|
||||
returns: {
|
||||
type: ['Object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/filter`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.filter = async(ctx, filter) => {
|
||||
let conn = Self.dataSource.connector;
|
||||
|
||||
let where = buildFilter(ctx.args, (param, value) => {
|
||||
switch (param) {
|
||||
case 'search':
|
||||
return {or: [
|
||||
{ticketFk: value},
|
||||
{clientFk: value}
|
||||
]};
|
||||
}
|
||||
});
|
||||
|
||||
filter = mergeFilters(ctx.args.filter, {where});
|
||||
|
||||
let stmts = [];
|
||||
let stmt;
|
||||
|
||||
stmt = new ParameterizedSQL(
|
||||
`SELECT t.id AS ticketFk, c.id AS clientFk, c.name AS clientName, tw.weekDay,
|
||||
wh.name AS warehouseName, w.id AS workerFk, u.nickName
|
||||
FROM ticketWeekly tw
|
||||
JOIN ticket t ON t.id = tw.ticketFk
|
||||
JOIN client c ON c.id = t.clientFk
|
||||
JOIN worker w ON w.id = c.salesPersonFk
|
||||
JOIN account.user u ON u.id = w.userFk
|
||||
JOIN warehouse wh ON wh.id = t.warehouseFk`
|
||||
);
|
||||
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
let itemsIndex = stmts.push(stmt) - 1;
|
||||
|
||||
let sql = ParameterizedSQL.join(stmts, ';');
|
||||
let result = await conn.executeStmt(sql);
|
||||
return itemsIndex === 0 ? result : result[itemsIndex];
|
||||
};
|
||||
};
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/ticket-weekly/filter')(Self);
|
||||
};
|
|
@ -181,7 +181,7 @@
|
|||
"component": "vn-ticket-log",
|
||||
"description": "Log"
|
||||
}, {
|
||||
"url" : "/weekly",
|
||||
"url" : "/weekly?q",
|
||||
"state": "ticket.weekly",
|
||||
"component": "vn-ticket-weekly",
|
||||
"description": "Weekly"
|
||||
|
|
|
@ -1,14 +1,25 @@
|
|||
<vn-crud-model auto-load="false"
|
||||
vn-id="model"
|
||||
url="/ticket/api/TicketWeeklies"
|
||||
url="/ticket/api/TicketWeeklies/filter"
|
||||
filter="::$ctrl.filter"
|
||||
limit="20"
|
||||
data="weeklies"
|
||||
primary-key="ticketFk"
|
||||
auto-save="true"
|
||||
on-save="$ctrl.onSave()">
|
||||
primary-key="ticketFk">
|
||||
</vn-crud-model>
|
||||
<form name="form">
|
||||
<div class="content-block">
|
||||
<div class="vn-list">
|
||||
<vn-card pad-medium-h>
|
||||
<vn-horizontal>
|
||||
<vn-searchbar
|
||||
vn-id="turnSearchbar"
|
||||
style="width: 100%"
|
||||
on-search="$ctrl.onSearch($params)"
|
||||
info="Search turns by id or client id"
|
||||
vn-focus>
|
||||
</vn-searchbar>
|
||||
</vn-horizontal>
|
||||
</vn-card>
|
||||
</div>
|
||||
<div margin-medium>
|
||||
<vn-card margin-medium-v pad-medium>
|
||||
<vn-table model="model">
|
||||
|
@ -30,27 +41,35 @@
|
|||
</span>
|
||||
</vn-td>
|
||||
<vn-td>
|
||||
<span class="link" ng-click="$ctrl.showClientDescriptor($event, weekly.ticket.client.id)">
|
||||
{{::weekly.ticket.client.name}}
|
||||
<span class="link"
|
||||
ng-click="$ctrl.showClientDescriptor($event, weekly.clientFk)"
|
||||
title ="{{::weekly.clientName}}">
|
||||
{{::weekly.clientName}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td ng-click="$ctrl.preventNavigation($event)">
|
||||
<vn-autocomplete
|
||||
vn-one
|
||||
<vn-autocomplete vn-one
|
||||
vn-id="weekday"
|
||||
field="weekly.weekDay"
|
||||
data="$ctrl.weekdays"
|
||||
show-field="name"
|
||||
translate-fields="['name']"
|
||||
value-field="id"
|
||||
on-change="$ctrl.onWeekdayUpdate(weekly.ticketFk, weekday.selection.id)"
|
||||
order="id">
|
||||
</vn-autocomplete>
|
||||
</vn-td>
|
||||
<vn-td>{{::weekly.ticket.warehouse.name}}</vn-td>
|
||||
<vn-td>{{::weekly.ticket.client.salesPerson.firstName}} {{::weekly.ticket.client.salesPerson.name}}</vn-td>
|
||||
<vn-td>{{::weekly.warehouseName}}</vn-td>
|
||||
<vn-td>
|
||||
<span class="link"
|
||||
ng-click="$ctrl.showWorkerDescriptor($event, weekly.workerFk)">
|
||||
{{::weekly.nickName}}
|
||||
</span>
|
||||
</vn-td>
|
||||
<vn-td>
|
||||
<vn-icon-button
|
||||
icon="delete"
|
||||
ng-click="model.remove($index)"
|
||||
ng-click="$ctrl.deleteWeekly($index)"
|
||||
vn-tooltip="Delete">
|
||||
</vn-icon-button>
|
||||
</vn-td>
|
||||
|
@ -60,14 +79,17 @@
|
|||
</vn-card>
|
||||
<vn-pagination model="model"></vn-pagination>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
<vn-client-descriptor-popover vn-id="clientDescriptor"></vn-client-descriptor-popover>
|
||||
<vn-ticket-descriptor-popover
|
||||
<vn-ticket-descriptor-popover
|
||||
vn-id="ticketDescriptor">
|
||||
</vn-ticket-descriptor-popover>
|
||||
<vn-worker-descriptor-popover
|
||||
vn-id="workerDescriptor">
|
||||
</vn-worker-descriptor-popover>
|
||||
<vn-confirm
|
||||
vn-id="deleteWeekly"
|
||||
on-response="$ctrl.returnDialog(response)"
|
||||
question="Delete weekly"
|
||||
message="Are you sure you want to delete this weekly?">
|
||||
</vn-confirm>
|
||||
question="You are going to delete this turn"
|
||||
message="This turn will be removed! Continue anyway?">
|
||||
</vn-confirm>
|
||||
|
|
|
@ -2,35 +2,13 @@ import ngModule from '../module';
|
|||
import './style.scss';
|
||||
|
||||
export default class Controller {
|
||||
constructor($scope, vnApp, $translate) {
|
||||
this.$scope = $scope;
|
||||
constructor($scope, vnApp, $translate, $http) {
|
||||
this.$ = $scope;
|
||||
this.vnApp = vnApp;
|
||||
this._ = $translate;
|
||||
this.$translate = $translate;
|
||||
this.$http = $http;
|
||||
|
||||
this.ticketSelected = null;
|
||||
this.filter = {
|
||||
include: {
|
||||
relation: 'ticket',
|
||||
scope: {
|
||||
fields: ['id', 'clientFk', 'companyFk', 'warehouseFk'],
|
||||
include: [
|
||||
{
|
||||
relation: 'client',
|
||||
scope: {
|
||||
fields: ['salesPersonFk', 'name'],
|
||||
include: {
|
||||
relation: 'salesPerson',
|
||||
scope: {
|
||||
fields: ['id', 'firstName', 'name']
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
{relation: 'warehouse'}
|
||||
]
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.weekdays = [
|
||||
{id: 0, name: 'Monday'},
|
||||
|
@ -43,28 +21,53 @@ export default class Controller {
|
|||
];
|
||||
}
|
||||
|
||||
onSave() {
|
||||
this.vnApp.showSuccess(this._.instant('Data saved!'));
|
||||
onWeekdayUpdate(ticketFk, weekDay) {
|
||||
const params = {ticketFk, weekDay};
|
||||
this.$http.patch('/ticket/api/TicketWeeklies/', params).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
});
|
||||
}
|
||||
|
||||
deleteWeekly(index) {
|
||||
this.ticketIndex = index;
|
||||
this.$.deleteWeekly.show();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
onSearch(params) {
|
||||
if (params)
|
||||
this.$.model.applyFilter(null, params);
|
||||
else
|
||||
this.$.model.clear();
|
||||
}
|
||||
|
||||
|
||||
showClientDescriptor(event, clientFk) {
|
||||
this.$scope.clientDescriptor.clientFk = clientFk;
|
||||
this.$scope.clientDescriptor.parent = event.target;
|
||||
this.$scope.clientDescriptor.show();
|
||||
this.$.clientDescriptor.clientFk = clientFk;
|
||||
this.$.clientDescriptor.parent = event.target;
|
||||
this.$.clientDescriptor.show();
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
showTicketDescriptor(event, ticketFk) {
|
||||
this.$scope.ticketDescriptor.ticketFk = ticketFk;
|
||||
this.$scope.ticketDescriptor.parent = event.target;
|
||||
this.$scope.ticketDescriptor.show();
|
||||
this.$.ticketDescriptor.ticketFk = ticketFk;
|
||||
this.$.ticketDescriptor.parent = event.target;
|
||||
this.$.ticketDescriptor.show();
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
showWorkerDescriptor(event, workerFk) {
|
||||
this.$.workerDescriptor.workerFk = workerFk;
|
||||
this.$.workerDescriptor.parent = event.target;
|
||||
this.$.workerDescriptor.show();
|
||||
event.preventDefault();
|
||||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
onDescriptorLoad() {
|
||||
this.$scope.popover.relocate();
|
||||
this.$.popover.relocate();
|
||||
}
|
||||
|
||||
preventNavigation(event) {
|
||||
|
@ -72,13 +75,19 @@ export default class Controller {
|
|||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
deleteWeekly(expedition) {
|
||||
this.expeditionId = expedition.id;
|
||||
this.$scope.deleteWeekly.show();
|
||||
returnDialog(response) {
|
||||
const ticket = this.$.model.data[this.ticketIndex];
|
||||
if (response === 'ACCEPT') {
|
||||
this.$http.delete(`/ticket/api/TicketWeeklies/${ticket.ticketFk}`).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
this.$.model.remove(this.ticketIndex);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$scope', 'vnApp', '$translate'];
|
||||
|
||||
Controller.$inject = ['$scope', 'vnApp', '$translate', '$http'];
|
||||
|
||||
ngModule.component('vnTicketWeekly', {
|
||||
template: require('./index.html'),
|
||||
|
|
|
@ -1,2 +1,6 @@
|
|||
Turn: Turno
|
||||
Ticket ID: ID Ticket
|
||||
Weekly: Turnos
|
||||
You are going to delete this turn: Vas a eliminar este turno
|
||||
This turn will be removed! Continue anyway?: Se eliminará este turno! ¿Continuar de todas formas?
|
||||
Search turns by id or client id: Busca turnos por el identificador o el identificador del cliente
|
Loading…
Reference in New Issue