Merge branch '1944-ticket-summary' of verdnatura/salix into dev
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat Exposito 2020-02-06 07:01:24 +00:00 committed by Gitea
commit 2186cfc959
9 changed files with 254 additions and 5 deletions

View File

@ -314,7 +314,7 @@ export default {
ticketSummary: { ticketSummary: {
header: 'vn-ticket-summary > vn-card > h5', header: 'vn-ticket-summary > vn-card > h5',
state: 'vn-ticket-summary vn-label-value[label="State"] > section > span', state: 'vn-ticket-summary vn-label-value[label="State"] > section > span',
route: 'vn-ticket-summary vn-label-value[label="Route"] > section > span > a', route: 'vn-ticket-summary vn-label-value[label="Route"] > section > span > span',
total: 'vn-ticket-summary vn-one.taxes > p:nth-child(3) > strong', total: 'vn-ticket-summary vn-one.taxes > p:nth-child(3) > strong',
sale: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr', sale: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr',
firstSaleItemId: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span', firstSaleItemId: 'vn-ticket-summary [name="sales"] vn-table > div > vn-tbody > vn-tr > vn-td:nth-child(2) > span',

View File

@ -0,0 +1,12 @@
<vn-popover vn-id="popover">
<vn-spinner
ng-if="$ctrl.route == null"
style="padding: 1em;"
enable="true">
</vn-spinner>
<vn-route-descriptor
ng-if="$ctrl.route"
route="$ctrl.route"
quicklinks="$ctrl.quicklinks">
</vn-route-descriptor>
</vn-popover>

View File

@ -0,0 +1,130 @@
import ngModule from '../module';
import Component from 'core/lib/component';
import './style.scss';
class Controller extends Component {
constructor($element, $scope, $http, $timeout, $q) {
super($element, $scope);
this.$timeout = $timeout;
this.$http = $http;
this.$q = $q;
this.route = null;
this._quicklinks = {};
}
set routeFk(id) {
if (id == this._routeFk) return;
this._routeFk = id;
this.route = null;
this.getCard();
}
get routeFk() {
return this._routeFk;
}
set route(value) {
this._route = value;
this.$timeout(() => this.$.popover.relocate());
}
get route() {
return this._route;
}
get quicklinks() {
return this._quicklinks;
}
set quicklinks(value = {}) {
Object.keys(value).forEach(key => {
this._quicklinks[key] = value[key];
});
}
show() {
this.$.popover.parent = this.parent;
this.$.popover.show();
}
getCard() {
if (this.canceler)
this.canceler.resolve();
this.canceler = this.$q.defer();
let query = 'Routes/findOne';
let filter = {
fields: [
'id',
'workerFk',
'agencyModeFk',
'created',
'm3',
'warehouseFk',
'description',
'vehicleFk',
'kmStart',
'kmEnd',
'started',
'finished',
'cost',
'zoneFk'
],
include: [
{
relation: 'agencyMode',
scope: {
fields: ['id', 'name']
}
}, {
relation: 'vehicle',
scope: {
fields: ['id', 'm3']
}
}, {
relation: 'zone',
scope: {
fields: ['id', 'name']
}
},
{
relation: 'worker',
scope: {
fields: ['userFk'],
include: {
relation: 'user',
scope: {
fields: ['id'],
include: {
relation: 'emailUser',
scope: {
fields: ['email']
}
}
}
}
}
}
]
};
this.$http.get(query, {params: {filter}}).then(res => {
this.route = res.data;
this.$.$applyAsync(() => {
this.$.popover.relocate();
});
});
}
}
Controller.$inject = ['$element', '$scope', '$http', '$timeout', '$q'];
ngModule.component('vnRouteDescriptorPopover', {
template: require('./index.html'),
controller: Controller,
bindings: {
routeFk: '<',
quicklinks: '<'
}
});

View File

@ -0,0 +1,77 @@
import './index';
describe('vnRouteDescriptorPopover', () => {
let $httpBackend;
let $scope;
let controller;
let $element;
let $timeout;
beforeEach(ngModule('route'));
beforeEach(angular.mock.inject(($componentController, $rootScope, _$httpBackend_, _$timeout_) => {
$httpBackend = _$httpBackend_;
$timeout = _$timeout_;
$element = angular.element(`<div></div>`);
$scope = $rootScope.$new();
$scope.popover = {relocate: () => {}, show: () => {}};
controller = $componentController('vnRouteDescriptorPopover', {$scope, $element});
}));
describe('routeFk()', () => {
it(`should do nothing if the received id isn't a new one`, () => {
controller.route = 'I exist!';
controller._routeFk = 1;
spyOn(controller, 'getCard');
controller.routeFk = 1;
expect(controller.route).toEqual('I exist!');
expect(controller._routeFk).toEqual(1);
expect(controller.getCard).not.toHaveBeenCalled();
});
it(`should set the received id, set the route null and then call getCard()`, () => {
controller.route = `Please don't`;
controller._routeFk = 1;
spyOn(controller, 'getCard');
controller.routeFk = 999;
expect(controller.route).toBeNull();
expect(controller._routeFk).toEqual(999);
expect(controller.getCard).toHaveBeenCalledWith();
});
});
describe('route()', () => {
it(`should save the client on the controller and then call relocate()`, () => {
spyOn(controller.$.popover, 'relocate');
let route = `i'm the route!`;
controller.route = route;
$timeout.flush();
expect(controller.route).toEqual(route);
expect(controller.$.popover.relocate).toHaveBeenCalledWith();
});
});
describe('show()', () => {
it(`should call the popover show() method`, () => {
spyOn(controller.$.popover, 'show');
controller.show();
expect(controller.$.popover.show).toHaveBeenCalledWith();
});
});
describe('getCard()', () => {
it(`should perform a get query to store the client data into the controller`, () => {
let response = {the: 'route'};
$httpBackend.whenRoute('GET', 'Routes/findOne').respond(response);
controller.routeFk = 1;
$httpBackend.flush();
expect(controller.route).toEqual(response);
});
});
});

View File

@ -0,0 +1,9 @@
vn-route-descriptor-popover {
vn-route-descriptor {
display: block;
width: 16em;
& > vn-card{
margin: 0!important;
}
}
}

View File

@ -4,6 +4,7 @@ import './main';
import './index/'; import './index/';
import './search-panel'; import './search-panel';
import './descriptor'; import './descriptor';
import './descriptor-popover';
import './summary'; import './summary';
import './card'; import './card';
import './create'; import './create';

View File

@ -3,7 +3,7 @@
"name": "Tickets", "name": "Tickets",
"icon": "icon-ticket", "icon": "icon-ticket",
"validations": true, "validations": true,
"dependencies": ["worker", "item", "client"], "dependencies": ["worker", "item", "client", "route"],
"menus": { "menus": {
"main": [ "main": [
{"state": "ticket.index", "icon": "icon-ticket"}, {"state": "ticket.index", "icon": "icon-ticket"},

View File

@ -42,9 +42,11 @@
value="{{$ctrl.summary.landed | date: 'dd/MM/yyyy'}}"> value="{{$ctrl.summary.landed | date: 'dd/MM/yyyy'}}">
</vn-label-value> </vn-label-value>
<vn-label-value label="Route"> <vn-label-value label="Route">
<a ui-sref="route.card.summary({id: $ctrl.summary.routeFk})"> <span
ng-click="$ctrl.showRouteDescriptor($event)"
class="link">
{{$ctrl.summary.routeFk}} {{$ctrl.summary.routeFk}}
</a> </span>
</vn-label-value> </vn-label-value>
<vn-label-value label="Package size" <vn-label-value label="Package size"
value="{{$ctrl.summary.packages}}"> value="{{$ctrl.summary.packages}}">
@ -199,7 +201,6 @@
</span> </span>
</vn-td> </vn-td>
<vn-td number> <vn-td number>
<vn-check vn-one <vn-check vn-one
ng-model="::request.isOk" ng-model="::request.isOk"
triple-state="true" triple-state="true"
@ -213,6 +214,10 @@
</vn-auto> </vn-auto>
</vn-horizontal> </vn-horizontal>
</vn-card> </vn-card>
<vn-route-descriptor-popover
vn-id="route-descriptor"
quicklinks="$ctrl.routeQuicklinks">
</vn-route-descriptor-popover>
<vn-item-descriptor-popover <vn-item-descriptor-popover
vn-id="descriptor" vn-id="descriptor"
quicklinks="$ctrl.quicklinks"> quicklinks="$ctrl.quicklinks">

View File

@ -36,6 +36,21 @@ class Controller {
}); });
} }
showRouteDescriptor(event) {
this.routeQuicklinks = {
btnThree: {
icon: 'icon-delivery',
state: `route.card.summary({
id: ${this.summary.routeFk},
})`,
tooltip: 'Route summary'
}
};
this.$scope.routeDescriptor.routeFk = this.summary.routeFk;
this.$scope.routeDescriptor.parent = event.target;
this.$scope.routeDescriptor.show();
}
showDescriptor(event, itemFk) { showDescriptor(event, itemFk) {
this.quicklinks = { this.quicklinks = {
btnThree: { btnThree: {