enabled routes module #616

This commit is contained in:
Joan Sanchez 2018-09-07 09:40:45 +02:00
parent 92b47466d7
commit a4c730cf65
34 changed files with 12 additions and 623 deletions

View File

@ -15,7 +15,7 @@
"url": "/index?q",
"state": "claim.index",
"component": "vn-claim-index",
"description": "Listado",
"description": "List",
"acl": ["salesAssistant"]
},
{

View File

@ -1 +1 @@
export * from './src/route';
export * from './src';

View File

@ -1,4 +1,4 @@
/* {
{
"module": "route",
"name": "Routes",
"icon" : "local_shipping",
@ -8,61 +8,15 @@
"url": "/routes",
"state": "routes",
"abstract": true,
"component": "ui-view"
"component": "ui-view",
"description": "Routes"
},
{
"url": "/list",
"url": "/index?q",
"state": "routes.index",
"component": "vn-route-index",
"description": "List",
"acl": ["developer"]
},
{
"url": "/create",
"state": "routes.create",
"component": "vn-route-create"
},
{
"url": "/:id",
"state": "routes.card",
"abstract": true,
"component": "vn-route-card"
},
{
"url": "/basicData",
"state": "routes.card.basicData",
"component": "vn-route-basic-data",
"params": {
"route": "$ctrl.route"
},
"menu": {
"description": "Basic data",
"icon": "person"
}
},
{
"url": "/logisticData",
"state": "routes.card.logisticData",
"component": "vn-route-logistic-data",
"acl": ["employee"],
"params": {
"route": "$ctrl.route"
},
"menu": {
"description": "Logistic data",
"icon": "local_shipping"
}
},
{
"url": "/tickets",
"state": "routes.card.tickets",
"component": "vn-route-tickets",
"params": {
"route": "$ctrl.route"
},
"menu": {
"description": "Assigned tickets",
"icon": "assignment"
}
}
]
} */
}

View File

@ -1,35 +0,0 @@
<vn-watcher
vn-id="watcher"
data="$ctrl.route"
form="form">
</vn-watcher>
<form name="form" pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Basic data</vn-title>
<vn-horizontal>
<vn-date-picker vn-one label="Date" model="$ctrl.route.date"></vn-date-picker>
<vn-autocomplete vn-one
label="Agency"
url="/route/api/Agencies"
field="$ctrl.route.agency">
</vn-autocomplete>
<vn-autocomplete vn-one
field="$ctrl.route.driver"
url="/route/api/Vehicles/activeDrivers"
label="Driver">
</vn-autocomplete>
<vn-autocomplete vn-one
field="$ctrl.route.vehicle"
url="/route/api/Vehicles/comboVehicles"
label="Vehicle"
order="tradeMark ASC"
filter="{where: {isActive: 1, warehouseFk: 1}}">
</vn-autocomplete>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -1,8 +0,0 @@
import ngModule from '../module';
ngModule.component('vnRouteBasicData', {
template: require('./basic-data.html'),
bindings: {
route: '<'
}
});

View File

@ -1,27 +0,0 @@
<vn-horizontal>
<mg-ajax
path="/route/api/Deliveries/{{edit.params.id}}"
actions="$ctrl.route = edit.model"
options="mgEdit">
</mg-ajax>
<vn-one style="min-width: 18em; padding-left: 1em; padding-bottom: 1em;">
<vn-card>
<vn-vertical class="margin-medium" pad-medium-top pad-medium-bottom>
<vn-horizontal>
<a vn-one ui-sref="routes.index">
<i class="material-icons descriptor-icon">local_shipping</i>
</a>
<vn-vertical vn-two>
<div class="margin-none"><span translate>Route</span> {{::$ctrl.route.id}}</div>
<div class="margin-none">{{$ctrl.route.date | date:'dd/MM/yyyy'}}</div>
</vn-vertical>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-left-menu></vn-left-menu>
</vn-one>
<vn-auto>
<vn-vertical style="max-width: 70em; margin: 0 auto;" ui-view></vn-vertical>
</vn-auto>
</vn-horizontal>

View File

@ -1,12 +0,0 @@
import ngModule from '../module';
class RouteCard {
constructor() {
this.route = null;
}
}
ngModule.component('vnRouteCard', {
template: require('./card.html'),
controller: RouteCard
});

View File

@ -1,43 +0,0 @@
<mg-ajax path="/route/api/Delivery/createRoute" options="vnPost"></mg-ajax>
<vn-watcher
vn-id="watcher"
data="$ctrl.delivery"
form="form"
save="post">
</vn-watcher>
<form name="form" ng-submit="$ctrl.onSubmit()" margin-medium>
<div style="max-width: 70em; margin: 0 auto;">
<vn-card>
<vn-vertical pad-large>
<vn-title>Create Route</vn-title>
<vn-horizontal>
<vn-date-picker vn-one label="Date" model="$ctrl.delivery.date"></vn-date-picker>
<vn-autocomplete
vn-one
label="Agency"
url="/route/api/Agencies"
field="$ctrl.delivery.agency">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-autocomplete vn-one
field="$ctrl.delivery.driver"
url="/route/api/Vehicles/activeDrivers"
label="Driver"></vn-autocomplete>
<vn-autocomplete vn-one
field="$ctrl.delivery.vehicle"
url="/route/api/Vehicles/comboVehicles"
label="Vehicle"
order="tradeMark ASC"
filter="{where: {isActive:1, warehouseFk:1}}">
</vn-autocomplete>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Create and edit"></vn-submit>
<vn-button label="Create" ng-click="watcher.submitBack()"></vn-button>
</vn-button-bar>
</div>
</form>

View File

@ -1,20 +0,0 @@
import ngModule from '../module';
class RouteCreate {
constructor($scope, $state) {
this.$ = $scope;
this.$state = $state;
this.delivery = {};
}
onSubmit() {
this.$.watcher.submit().then(
json => this.$state.go('routes.card.basicData', {id: json.data.id})
);
}
}
RouteCreate.$inject = ['$scope', '$state'];
ngModule.component('vnRouteCreate', {
template: require('./create.html'),
controller: RouteCreate
});

View File

@ -0,0 +1,3 @@
export * from './module';
// import components

View File

@ -1,12 +0,0 @@
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 48 48" version="1.1" width="528" height="528">
<g id="surface1">
<path style=" fill:#1C9957;" d="M 42 39 L 42 9 C 42 7.34375 40.65625 6 39 6 L 9 6 C 7.34375 6 6 7.34375 6 9 L 6 39 C 6 40.65625 7.34375 42 9 42 L 39 42 C 40.65625 42 42 40.65625 42 39 Z "/>
<path style=" fill:#3E7BF1;" d="M 9 42 L 39 42 C 40.65625 42 24 26 24 26 C 24 26 7.34375 42 9 42 Z "/>
<path style=" fill:#CBCCC9;" d="M 42 39 L 42 9 C 42 7.34375 26 24 26 24 C 26 24 42 40.65625 42 39 Z "/>
<path style=" fill:#EFEFEF;" d="M 39 42 C 40.65625 42 42 40.65625 42 39 L 42 38.753906 L 26.246094 23 L 23 26.246094 L 38.753906 42 Z "/>
<path style=" fill:#FFD73D;" d="M 42 9 C 42 7.34375 40.65625 6 39 6 L 38.753906 6 L 6 38.753906 L 6 39 C 6 40.65625 7.34375 42 9 42 L 9.246094 42 L 42 9.246094 Z "/>
<path style=" fill:#D73F35;" d="M 36 2 C 30.476563 2 26 6.476563 26 12 C 26 18.8125 33.664063 21.296875 35.332031 31.851563 C 35.441406 32.53125 35.449219 33 36 33 C 36.550781 33 36.558594 32.53125 36.667969 31.851563 C 38.335938 21.296875 46 18.8125 46 12 C 46 6.476563 41.523438 2 36 2 Z "/>
<path style=" fill:#752622;" d="M 39.5 12 C 39.5 13.933594 37.933594 15.5 36 15.5 C 34.066406 15.5 32.5 13.933594 32.5 12 C 32.5 10.066406 34.066406 8.5 36 8.5 C 37.933594 8.5 39.5 10.066406 39.5 12 Z "/>
<path style=" fill:#FFFFFF;" d="M 14.492188 12.53125 L 14.492188 14.632813 L 17.488281 14.632813 C 17.09375 15.90625 16.03125 16.816406 14.492188 16.816406 C 12.660156 16.816406 11.175781 15.332031 11.175781 13.5 C 11.175781 11.664063 12.660156 10.179688 14.492188 10.179688 C 15.316406 10.179688 16.070313 10.484375 16.648438 10.980469 L 18.195313 9.433594 C 17.21875 8.542969 15.921875 8 14.492188 8 C 11.453125 8 8.992188 10.464844 8.992188 13.5 C 8.992188 16.535156 11.453125 19 14.492188 19 C 19.304688 19 20.128906 14.683594 19.675781 12.539063 Z "/>
</g>
</svg>

View File

@ -1,23 +0,0 @@
<mg-ajax path="/route/api/Deliveries/filter" options="mgIndex"></mg-ajax>
<div margin-medium>
<div style="max-width: 40em; margin: 0 auto;">
<vn-card>
<vn-horizontal pad-medium>
<vn-searchbar vn-auto
index="index"
on-search="$ctrl.search(index)"
advanced="true"
search="$ctrl.model.search"
popover="vn-route-search-panel">
</vn-searchbar>
</vn-horizontal>
</vn-card>
<vn-card margin-medium-top>
<vn-item-route ng-repeat="route in index.model.instances" title="View Route" route="route"></vn-item-route>
</vn-card>
<vn-paging index="index" total="index.model.count"></vn-paging>
</div>
<a ui-sref="routes.create" vn-bind="+" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>
</div>

View File

@ -1,18 +0,0 @@
import ngModule from '../module';
import './style.css';
import './item-route';
export default class Controller {
constructor() {
this.model = {};
}
search(index) {
index.filter.search = this.model.search;
index.accept();
}
}
ngModule.component('vnRouteIndex', {
template: require('./index.html'),
controller: Controller
});

View File

@ -1,21 +0,0 @@
<a vn-horizontal ui-sref="routes.card.basicData({id: {{$ctrl.route.id}} })" pad-medium border-solid-bottom>
<vn-one>
<vn-vertical>
<vn-one>
<span translate>ID_RUTA</span>:
<strong>{{$ctrl.route.id}}</strong>
</vn-one>
<vn-one>
<span translate>Fecha</span>:
<strong>{{$ctrl.route.date | date:'dd/MM/yyyy'}}</strong>
</vn-one>
<vn-one>
<span>m<sup>3</sup></span>:
<strong>{{$ctrl.route.m3}}</strong>
</vn-one>
</vn-vertical>
</vn-one>
<vn-none pad-medium-top>
<vn-icon icon="print"></vn-icon>
</vn-none>
</a>

View File

@ -1,8 +0,0 @@
import ngModule from '../module';
ngModule.component('vnItemRoute', {
template: require('./item-route.html'),
bindings: {
route: '<'
}
});

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 30.3 26.6" style="enable-background:new 0 0 30.3 26.6;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
.st1{fill:#F7931E;}
</style>
<rect width="30.3" height="26.6"/>
<g>
<path class="st0" d="M24.9,9.7h-3.7v-5H4c-1.4,0-2.5,1.1-2.5,2.5v13.5H4c0,2,1.6,3.7,3.7,3.7s3.7-1.6,3.7-3.7h7.4
c0,2,1.6,3.7,3.7,3.7s3.7-1.6,3.7-3.7h2.5v-6.1L24.9,9.7z M7.7,22.5c-1,0-1.8-0.8-1.8-1.8s0.8-1.8,1.8-1.8s1.8,0.8,1.8,1.8
S8.7,22.5,7.7,22.5z M24.2,11.5l2.4,3.1h-5.5v-3.1H24.2z M22.4,22.5c-1,0-1.8-0.8-1.8-1.8s0.8-1.8,1.8-1.8s1.8,0.8,1.8,1.8
C24.2,21.7,23.4,22.5,22.4,22.5z"/>
<path class="st1" d="M12,7.2c-3,0-5.5,2.5-5.5,5.5S9,18.2,12,18.2s5.5-2.5,5.5-5.5S15,7.2,12,7.2z M14.8,13.3h-2.2v2.2h-1.1v-2.2
H9.3v-1.1h2.2V9.9h1.1v2.2h2.2V13.3z"/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Generator: Adobe Illustrator 21.1.0, SVG Export Plug-In . SVG Version: 6.00 Build 0) -->
<svg version="1.1" id="Capa_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
viewBox="0 0 30.3 26.6" style="enable-background:new 0 0 30.3 26.6;" xml:space="preserve">
<style type="text/css">
.st0{fill:#FFFFFF;}
.st1{fill:#F7931E;}
</style>
<rect width="30.3" height="26.6"/>
<g>
<path class="st0" d="M24.9,9.7h-3.7V4.7H4c-1.4,0-2.5,1.1-2.5,2.5v13.5H4c0,2,1.6,3.7,3.7,3.7s3.7-1.6,3.7-3.7h7.4
c0,2,1.6,3.7,3.7,3.7s3.7-1.6,3.7-3.7h2.5v-6.1L24.9,9.7z M7.7,22.5c-1,0-1.8-0.8-1.8-1.8c0-1,0.8-1.8,1.8-1.8s1.8,0.8,1.8,1.8
C9.5,21.7,8.7,22.5,7.7,22.5z M24.2,11.5l2.4,3.1h-5.5v-3.1H24.2z M22.4,22.5c-1,0-1.8-0.8-1.8-1.8c0-1,0.8-1.8,1.8-1.8
c1,0,1.8,0.8,1.8,1.8C24.2,21.7,23.4,22.5,22.4,22.5z"/>
<path class="st1" d="M12,7.2c-3,0-5.5,2.5-5.5,5.5s2.5,5.5,5.5,5.5s5.5-2.5,5.5-5.5S15,7.2,12,7.2z M14.7,13.3H9.2v-1.1h5.5V13.3z"
/>
</g>
</svg>

Before

Width:  |  Height:  |  Size: 1.0 KiB

View File

@ -1,12 +0,0 @@
vn-item-route {
display: block;
}
vn-item-route a {
display: block;
text-decoration: none;
color: inherit;
}
vn-item-route a:hover {
color: white;
background-color: #424242;
}

View File

@ -1,26 +0,0 @@
<vn-watcher
vn-id="watcher"
data="$ctrl.route"
form="form">
</vn-watcher>
<form name="form" pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Logistic data</vn-title>
<vn-horizontal>
<vn-date-picker vn-one label="Start Hour" model="$ctrl.route.startHour" ini-options="{enableTime: true, noCalendar: true, enableSeconds: false, dateFormat: 'H:i'}"></vn-date-picker>
<vn-date-picker vn-one label="End Hour" model="$ctrl.route.endHour" ini-options="{enableTime: true, noCalendar: true, enableSeconds: false, dateFormat: 'H:i'}"></vn-date-picker>
<vn-textfield vn-one label="Start Km" model="$ctrl.route.starKm"></vn-textfield>
<vn-textfield vn-one label="End Km" model="$ctrl.route.endKm"></vn-textfield>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Packages" model="$ctrl.route.packages"></vn-textfield>
<vn-textfield vn-one label="M3" model="$ctrl.route.m3"></vn-textfield>
<vn-one></vn-one>
</vn-horizontal>
</vn-vertical>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -1,8 +0,0 @@
import ngModule from '../module';
ngModule.component('vnRouteLogisticData', {
template: require('./logistic-data.html'),
bindings: {
route: '<'
}
});

View File

@ -1,10 +0,0 @@
export * from './module';
// import components
import './index/index';
import './search-panel/search-panel';
import './create/create';
import './card/card';
import './basic-data/basic-data';
import './logistic-data/logistic-data';
import './tickets/tickets';

View File

@ -1,8 +0,0 @@
Client id: Id cliente
Tax number: NIF/CIF
Name: Nombre
Social name: Razon social
Town/City: Ciudad
Postcode: Código postal
Email: Correo electrónico
Phone: Teléfono

View File

@ -1,21 +0,0 @@
<div pad-large style="min-width: 30em">
<form ng-submit="$ctrl.onSearch()">
<vn-horizontal>
<vn-date-picker vn-one label="Date" model="$ctrl.filter.date"></vn-date-picker>
<vn-autocomplete
vn-one
label="Zone"
field="$ctrl.filter.zone"
url="/route/api/Zones"
order="printingOrder ASC">
</vn-autocomplete>
</vn-horizontal>
<vn-horizontal>
<vn-textfield vn-one label="Postcode" model="$ctrl.filter.postcode"></vn-textfield>
<vn-textfield vn-one label="Route_Id" model="$ctrl.filter.id"></vn-textfield>
</vn-horizontal>
<vn-horizontal margin-large-top>
<vn-submit label="Search"></vn-submit>
</vn-horizontal>
</form>
</div>

View File

@ -1,27 +0,0 @@
import ngModule from '../module';
export default class Controller {
constructor($window) {
this.$window = $window;
// onSubmit() is defined by @vnSearchbar
this.onSubmit = () => {};
}
onSearch() {
this.setStorageValue();
this.onSubmit(this.filter);
}
$onChanges() {
var value = JSON.parse(this.$window.sessionStorage.getItem('filter'));
if (value !== undefined)
this.filter = value;
}
setStorageValue() {
this.$window.sessionStorage.setItem('filter', JSON.stringify(this.filter));
}
}
Controller.$inject = ['$window'];
ngModule.component('vnRouteSearchPanel', {
template: require('./search-panel.html'),
controller: Controller
});

View File

@ -1,7 +0,0 @@
<vn-one pad-medium>
<vn-card>
<vn-vertical pad-large>
<vn-title>Assigned tickets</vn-title>
</vn-vertical>
</vn-card>
</vn-one>

View File

@ -1,8 +0,0 @@
import ngModule from '../module';
ngModule.component('vnRouteTickets', {
template: require('./tickets.html'),
bindings: {
route: '<'
}
});

View File

@ -15,7 +15,7 @@
"url": "/index?q",
"state": "ticket.index",
"component": "vn-ticket-index",
"description": "Listado"
"description": "List"
},
{
"url": "/:id",

View File

@ -1,42 +0,0 @@
module.exports = Self => {
Self.remoteMethod('comboVehicles', {
description: 'returns list of vehicles',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
required: false,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}],
returns: {
arg: 'data',
type: 'Vehicle',
root: true
},
http: {
path: `/comboVehicles`,
verb: 'get'
}
});
Self.comboVehicles = (filter, callback) => {
Self.find(filter, (_, instances) => {
callback(null, formatOutput(instances));
});
};
function formatOutput(instances) {
let results = [];
for (let instance of instances) {
let numberPlate = ` ${instance.numberPlate}` || '';
results.push({
id: instance.id,
name: `${instance.tradeMark} ${instance.model}${numberPlate}`
});
}
return results;
}
};

View File

@ -1,79 +0,0 @@
module.exports = Self => {
Self.remoteMethod('activeDrivers', {
description: 'returns actives workers with driver role',
accessType: 'READ',
accepts: [{
arg: 'filter',
type: 'Object',
required: false,
description: 'Filter defining where and paginated data',
http: {source: 'query'}
}],
returns: {
arg: 'data',
type: 'Worker',
root: true
},
http: {
path: `/activeDrivers`,
verb: 'get'
}
});
Self.activeDrivers = (filter, callback) => {
let skip = filter.skip || 0;
let limit = filter.limit || 10;
let where = getCondition(filter.where);
// TODO: change salesPerson role to Driver role when it will be created
let query = `SELECT em.id, em.firstName, em.name
FROM worker em
JOIN account.user ac ON em.userFk = ac.id
JOIN account.role r ON r.id = ac.roleFK
WHERE ac.active AND r.\`name\` = 'salesPerson' ${where}
ORDER BY em.name ASC
LIMIT ${limit} OFFSET ${skip}`;
Self.rawSql(query, [], callback)
.then(response => {
callback(null, formatDriver(response));
})
.catch(reject => {
callback(reject, null);
});
};
function getCondition(where) {
let out = [];
if (typeof where === 'object') {
Object.keys(where).forEach(k => {
let value = where[k];
if (typeof value === 'number') {
out.push(`em.${k}=${value}`);
} else if (typeof value === 'string') {
out.push(`em.${k}='${value}'`);
} else if (typeof value === 'boolean' || value === null) {
out.push(`em.${k} IS ${String(value).toUpperCase()}`);
} else if (Object.keys(value).length) {
let firstProperty = Object.keys(value)[0];
out.push(`em.${k} ${firstProperty} '${value[firstProperty]}'`);
} else {
throw new Error('Error: unexpected type');
}
});
}
return out.length ? `AND (${out.join(' AND ')})` : '';
}
function formatDriver(response) {
let results = [];
response.forEach(person => {
results.push({
id: person.id,
name: `${person.firstName} ${person.name}`
});
});
return results;
}
};

View File

@ -1,48 +0,0 @@
module.exports = function(Self) {
Self.installMethod('filter', filterRoutes);
function filterRoutes(params) {
if (params.search)
return searchWhere(params);
return andWhere(params);
}
function searchWhere(params) {
return {
where: {
or: [
{id: params.search},
{name: {regexp: params.search}}
]
},
skip: (parseInt(params.page, 10) - 1) * parseInt(params.size, 10),
limit: parseInt(params.size, 10)
};
}
function andWhere(params) {
let filters = {
where: {},
skip: (parseInt(params.page, 10) - 1) * parseInt(params.size, 10),
limit: parseInt(params.size, 10)
};
delete params.page;
delete params.size;
if (params.phone) {
filters.where.or = [
{phone: params.phone},
{mobile: params.phone}
];
delete params.phone;
}
Object.keys(params).forEach(
key => {
filters.where[key] = {regexp: params[key]};
}
);
return filters;
}
};

View File

@ -1,4 +0,0 @@
module.exports = function(Self) {
require('../methods/filterRoutes.js')(Self);
};

View File

@ -1,5 +0,0 @@
module.exports = function(Self) {
require('../methods/comboVehicles.js')(Self);
require('../methods/drivers.js')(Self);
};