Ticket packaging
This commit is contained in:
parent
9df0312c80
commit
ff047559e3
|
@ -2,7 +2,7 @@
|
|||
"module": "ticket",
|
||||
"name": "Tickets",
|
||||
"icon": "icon-ticket",
|
||||
"validations": false,
|
||||
"validations": true,
|
||||
"routes": [
|
||||
{
|
||||
"url": "/ticket",
|
||||
|
|
|
@ -1,56 +1,68 @@
|
|||
<mg-ajax
|
||||
path="/ticket/api/Tickets/{{index.params.id}}/packages"
|
||||
options="mgIndex">
|
||||
options="mgIndex" actions="$ctrl.getPackages()">
|
||||
</mg-ajax>
|
||||
|
||||
<vn-card pad-large>
|
||||
<vn-title>Packages</vn-title>
|
||||
<vn-one>
|
||||
<vn-horizontal ng-repeat="package in index.model track by package.id">
|
||||
<vn-autocomplete vn-one
|
||||
margin-large-right
|
||||
url="/ticket/api/Packagings/listPackaging"
|
||||
label="Package"
|
||||
show-field="name"
|
||||
value-field="packagingFk"
|
||||
field="package.packagingFk">
|
||||
<tpl-item>{{id}} : {{name}}</tpl-item>
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
margin-large-right
|
||||
label="Quantity"
|
||||
model="package.quantity">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
margin-large-right
|
||||
label="Added"
|
||||
model="package.created | date: 'dd/MM/yyyy'"
|
||||
disabled="true"
|
||||
ng-readonly="true">
|
||||
</vn-textfield>
|
||||
<vn-auto pad-medium-top>
|
||||
<vn-icon
|
||||
pointer
|
||||
medium-grey
|
||||
vn-tooltip="Remove package"
|
||||
tooltip-position = "left"
|
||||
icon="remove_circle_outline"
|
||||
ng-click="$ctrl.removePackage($index)">
|
||||
</vn-icon>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-icon
|
||||
pointer
|
||||
margin-medium-left
|
||||
vn-tooltip="Add package"
|
||||
tooltip-position = "right"
|
||||
orange
|
||||
icon="add_circle"
|
||||
ng-click="$ctrl.addPackage()">
|
||||
</vn-icon>
|
||||
</vn-one>
|
||||
</vn-card>
|
||||
<vn-watcher
|
||||
vn-id="watcher"
|
||||
data="$ctrl.packages"
|
||||
form="form">
|
||||
</vn-watcher>
|
||||
|
||||
<form name="form" ng-submit="$ctrl.submit()">
|
||||
<vn-card pad-large>
|
||||
<vn-title>Packages</vn-title>
|
||||
<vn-one>
|
||||
<vn-horizontal ng-repeat="package in index.model track by $index">
|
||||
<vn-autocomplete vn-one
|
||||
margin-large-right
|
||||
url="/ticket/api/Packagings/listPackaging"
|
||||
label="Package"
|
||||
show-field="name"
|
||||
value-field="packagingFk"
|
||||
field="package.packagingFk">
|
||||
<tpl-item>{{id}} : {{name}}</tpl-item>
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
margin-large-right
|
||||
label="Quantity"
|
||||
model="package.quantity"
|
||||
rule="TicketPackaging.quantity">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
vn-one
|
||||
margin-large-right
|
||||
label="Added"
|
||||
model="package.created | date: 'dd/MM/yyyy'"
|
||||
disabled="true"
|
||||
ng-readonly="true">
|
||||
</vn-textfield>
|
||||
<vn-auto pad-medium-top>
|
||||
<vn-icon
|
||||
pointer
|
||||
medium-grey
|
||||
vn-tooltip="Remove package"
|
||||
tooltip-position = "left"
|
||||
icon="remove_circle_outline"
|
||||
ng-click="$ctrl.removePackage($index)">
|
||||
</vn-icon>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
</vn-one>
|
||||
<vn-one>
|
||||
<vn-icon
|
||||
pointer
|
||||
margin-medium-left
|
||||
vn-tooltip="Add package"
|
||||
tooltip-position = "right"
|
||||
orange
|
||||
icon="add_circle"
|
||||
ng-click="$ctrl.addPackage()">
|
||||
</vn-icon>
|
||||
</vn-one>
|
||||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit label="Save"></vn-submit>
|
||||
</vn-button-bar>
|
||||
</form>
|
|
@ -2,9 +2,63 @@ import ngModule from '../../module';
|
|||
|
||||
class Controller {
|
||||
|
||||
construct($http, $scope) {
|
||||
constructor($http, $scope, $translate, vnApp) {
|
||||
this.$http = $http;
|
||||
this.$ = $scope;
|
||||
this.$translate = $translate;
|
||||
this.vnApp = vnApp;
|
||||
this.removedPackages = [];
|
||||
this.updatedPackages = [];
|
||||
}
|
||||
|
||||
submit() {
|
||||
let query = `/ticket/api/TicketPackagings/crudTicketPackaging`;
|
||||
let packagesObj = {
|
||||
delete: this.removedPackages,
|
||||
create: [],
|
||||
update: []
|
||||
};
|
||||
|
||||
this.packages.forEach(item => {
|
||||
if (typeof item.id === 'undefined')
|
||||
packagesObj.create.push(item);
|
||||
|
||||
if (typeof item.id !== 'undefined' && angular.equals(item, this.oldPackages[item.id]))
|
||||
packagesObj.update.push(item);
|
||||
});
|
||||
|
||||
this.$http.post(query, packagesObj).then(res => {
|
||||
this.$.index.accept();
|
||||
});
|
||||
}
|
||||
|
||||
removePackage(index) {
|
||||
if (this.packages[index] && this.packages[index].id)
|
||||
this.removedPackages.push(this.packages[index].id);
|
||||
|
||||
this.packages.splice(index, 1);
|
||||
}
|
||||
|
||||
addPackage() {
|
||||
let data = {
|
||||
packagingFk: null,
|
||||
quantity: null,
|
||||
created: Date.now(),
|
||||
ticketFk: this.ticket.id
|
||||
};
|
||||
this.packages.push(data);
|
||||
}
|
||||
|
||||
getPackages() {
|
||||
this.packages = this.$.index.model;
|
||||
this.setOldPackages();
|
||||
}
|
||||
|
||||
setOldPackages() {
|
||||
this.oldPackages = [];
|
||||
this.packages.forEach(item => {
|
||||
this.oldPackages[item.id] = item;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,59 @@
|
|||
import './package-list.js';
|
||||
|
||||
describe('Ticket', () => {
|
||||
describe('Component vnTicketPackageList', () => {
|
||||
let $componentController;
|
||||
let controller;
|
||||
let $httpBackend;
|
||||
let $scope;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('ticket');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_, $rootScope) => {
|
||||
$componentController = _$componentController_;
|
||||
$httpBackend = _$httpBackend_;
|
||||
$scope = {
|
||||
index: {
|
||||
accept: function() {}
|
||||
}
|
||||
};
|
||||
controller = $componentController('vnTicketPackageList', {$scope: $scope});
|
||||
}));
|
||||
|
||||
describe('removePackage()', () => {
|
||||
it('should push a package to removedPackages in the controller', () => {
|
||||
controller.packages = [{id: 1}, {id: 2}];
|
||||
controller.removePackage(0);
|
||||
|
||||
expect(controller.removedPackages).toEqual([1]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('submit()', () => {
|
||||
it('should perform a post', () => {
|
||||
spyOn(angular, 'equals').and.returnValue(true);
|
||||
let query = '/ticket/api/TicketPackagings/crudTicketPackaging';
|
||||
controller.removedPackages = [];
|
||||
controller.oldPackages = [
|
||||
{id: 1, quantity: 5, ticketFk: 1}
|
||||
];
|
||||
controller.packages = [
|
||||
{quantity: 5, ticketFk: 1},
|
||||
{id: 1, quantity: 25, ticketFk: 1}
|
||||
];
|
||||
let packagesObj = {
|
||||
delete: controller.removedPackages,
|
||||
create: [],
|
||||
update: []
|
||||
};
|
||||
|
||||
$httpBackend.whenPOST(query, packagesObj).respond('omg YEAH');
|
||||
$httpBackend.expectPOST(query, packagesObj);
|
||||
controller.submit();
|
||||
$httpBackend.flush();
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
|
@ -5,5 +5,6 @@
|
|||
"The default consignee can not be unchecked": "The default consignee can not be unchecked",
|
||||
"Unable to default a disabled consignee": "Unable to default a disabled consignee",
|
||||
"El método de pago seleccionado requiere que se especifique el IBAN": "El método de pago seleccionado requiere que se especifique el IBAN",
|
||||
"Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre"
|
||||
"Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre",
|
||||
"Quantity cannot be zero": "Quantity cannot be zero"
|
||||
}
|
|
@ -8,7 +8,6 @@
|
|||
"can't be blank": "can't be blank",
|
||||
"DNI Incorrecto": "DNI Incorrecto",
|
||||
"Ya existe un usuario con ese nombre": "Ya existe un usuario con ese nombre",
|
||||
"ValidationError: The `Item` instance is not valid. Details: `originFk` Cannot be blank (value: undefined).": "ValidationError: The `Item` instance is not valid. Details: `originFk` Cannot be blank (value: undefined).",
|
||||
"Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE)": "Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `Articles_ibfk_5` FOREIGN KEY (`tipo_id`) REFERENCES `Tipos` (`tipo_id`) ON UPDATE CASCADE)",
|
||||
"Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE)": "Error: ER_NO_REFERENCED_ROW_2: Cannot add or update a child row: a foreign key constraint fails (`vn2008`.`Articles`, CONSTRAINT `expenceFk` FOREIGN KEY (`expenceFk`) REFERENCES `Gastos` (`Id_Gasto`) ON UPDATE CASCADE)"
|
||||
"is invalid": "is invalid",
|
||||
"Quantity cannot be zero": "La cantidad no puede ser cero"
|
||||
}
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
Self.installCrudModel('crudTicketPackaging');
|
||||
};
|
|
@ -0,0 +1,15 @@
|
|||
module.exports = function(Self) {
|
||||
require('../methods/packaging/crudTicketPackaging')(Self);
|
||||
|
||||
Self.validateBinded('quantity', validateQuantity, {
|
||||
message: 'Quantity cannot be zero',
|
||||
allowNull: false,
|
||||
allowBlank: false
|
||||
});
|
||||
|
||||
function validateQuantity(quantity) {
|
||||
return quantity != 0;
|
||||
}
|
||||
|
||||
Self.validatesPresenceOf('packagingFk', {message: 'Package cannot be blank'});
|
||||
};
|
Loading…
Reference in New Issue