merge de rutas

This commit is contained in:
Javi Gallego 2018-03-20 13:53:01 +01:00
commit c0014ef468
34 changed files with 745 additions and 187 deletions

View File

@ -54,6 +54,7 @@
<mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax> <mg-ajax path="/client/api/ObservationTypes" options="mgIndex as observationsTypes"></mg-ajax>
<vn-horizontal ng-repeat="observation in $ctrl.observations track by $index"> <vn-horizontal ng-repeat="observation in $ctrl.observations track by $index">
<vn-autocomplete <vn-autocomplete
ng-if="!observation.id"
vn-one vn-one
initial-data="observation.observationType" initial-data="observation.observationType"
field="observation.observationTypeFk" field="observation.observationTypeFk"
@ -61,6 +62,13 @@
show-field="description" show-field="description"
label="Observation type"> label="Observation type">
</vn-autocomplete> </vn-autocomplete>
<vn-textfield
ng-if="observation.id"
vn-one
label="Observation type"
model="observation.observationType.description"
disabled="true">
</vn-textfield>
<vn-textfield <vn-textfield
vn-two vn-two
margin-large-right margin-large-right

View File

@ -13,8 +13,8 @@ export default class Controller {
id: parseInt($state.params.addressId) id: parseInt($state.params.addressId)
}; };
this.observations = []; this.observations = [];
this.observationsOld = {}; this.oldObservations = {};
this.observationsRemoved = []; this.removedObservations = [];
} }
_setDirtyForm() { _setDirtyForm() {
@ -22,6 +22,7 @@ export default class Controller {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
} }
} }
_unsetDirtyForm() { _unsetDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setPristine(); this.$scope.form.$setPristine();
@ -37,16 +38,17 @@ export default class Controller {
if (item) { if (item) {
this.observations.splice(index, 1); this.observations.splice(index, 1);
if (item.id) { if (item.id) {
this.observationsRemoved.push(item.id); this.removedObservations.push(item.id);
this._setDirtyForm(); this._setDirtyForm();
} }
} }
if (this.observations.length === 0 && Object.keys(this.observationsOld).length === 0) { if (this.observations.length === 0 && Object.keys(this.oldObservations).length === 0) {
this._unsetDirtyForm(); this._unsetDirtyForm();
} }
} }
_submitObservations(objectObservations) {
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, objectObservations); _submitObservations(observationsObject) {
return this.$http.post(`/client/api/AddressObservations/crudAddressObservations`, observationsObject);
} }
_observationsEquals(ob1, ob2) { _observationsEquals(ob1, ob2) {
@ -58,12 +60,12 @@ export default class Controller {
return false; return false;
} }
let canWatcherSubmit = this.$scope.watcher.dataChanged(); let canSubmitWatcher = this.$scope.watcher.dataChanged();
let canObservationsSubmit; let canSubmitObservations;
let repeatedTypes = false; let repeatedTypes = false;
let types = []; let types = [];
let observationsObj = { let observationsObj = {
delete: this.observationsRemoved, delete: this.removedObservations,
create: [], create: [],
update: [] update: []
}; };
@ -82,26 +84,26 @@ export default class Controller {
if (isNewObservation && observation.observationTypeFk && observation.description) { if (isNewObservation && observation.observationTypeFk && observation.description) {
observationsObj.create.push(observation); observationsObj.create.push(observation);
} else if (!isNewObservation && !this._observationsEquals(this.observationsOld[observation.id], observation)) { } else if (!isNewObservation && !this._observationsEquals(this.oldObservations[observation.id], observation)) {
observationsObj.update.push(observation); observationsObj.update.push(observation);
} }
} }
canObservationsSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0; canSubmitObservations = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
if (repeatedTypes) { if (repeatedTypes) {
this.vnApp.showMessage( this.vnApp.showMessage(
this.$translate.instant('The observation type must be unique') this.$translate.instant('The observation type must be unique')
); );
} else if (canWatcherSubmit && !canObservationsSubmit) { } else if (canSubmitWatcher && !canSubmitObservations) {
this.$scope.watcher.submit().then(() => { this.$scope.watcher.submit().then(() => {
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id}); this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
}); });
} else if (!canWatcherSubmit && canObservationsSubmit) { } else if (!canSubmitWatcher && canSubmitObservations) {
this._submitObservations(observationsObj).then(() => { this._submitObservations(observationsObj).then(() => {
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id}); this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
}); });
} else if (canWatcherSubmit && canObservationsSubmit) { } else if (canSubmitWatcher && canSubmitObservations) {
this.$q.all([this.$scope.watcher.submit(), this._submitObservations(observationsObj)]).then(() => { this.$q.all([this.$scope.watcher.submit(), this._submitObservations(observationsObj)]).then(() => {
this.$state.go('clientCard.addresses.list', {id: this.$state.params.id}); this.$state.go('clientCard.addresses.list', {id: this.$state.params.id});
}); });
@ -113,7 +115,7 @@ export default class Controller {
this._unsetDirtyForm(); this._unsetDirtyForm();
} }
$onInit() { _getAddressNotes() {
let filter = { let filter = {
where: {addressFk: this.address.id}, where: {addressFk: this.address.id},
include: {relation: 'observationType'} include: {relation: 'observationType'}
@ -121,10 +123,14 @@ export default class Controller {
this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => { this.$http.get(`/client/api/AddressObservations?filter=${JSON.stringify(filter)}`).then(res => {
this.observations = res.data; this.observations = res.data;
res.data.forEach(item => { res.data.forEach(item => {
this.observationsOld[item.id] = Object.assign({}, item); this.oldObservations[item.id] = Object.assign({}, item);
}); });
}); });
} }
$onInit() {
this._getAddressNotes();
}
} }
Controller.$inject = ['$state', '$scope', '$http', '$q', '$translate', 'vnApp']; Controller.$inject = ['$state', '$scope', '$http', '$q', '$translate', 'vnApp'];

View File

@ -89,13 +89,20 @@
</vn-check> </vn-check>
<vn-check <vn-check
vn-one vn-one
label="Frozen"
field="$ctrl.client.isFreezed"
vn-acl="administrative, salesAssistant, salesPerson"
acl-conditional-to-salesPerson="{{!$ctrl.client.isTaxDataChecked}}">
</vn-check>
<vn-check
vn-two
label="Invoice by address" label="Invoice by address"
field="$ctrl.client.hasToInvoiceByAddress" field="$ctrl.client.hasToInvoiceByAddress"
vn-acl="administrative, salesAssistant, salesPerson" vn-acl="administrative, salesAssistant, salesPerson"
acl-conditional-to-salesPerson="{{!$ctrl.client.isTaxDataChecked}}"> acl-conditional-to-salesPerson="{{!$ctrl.client.isTaxDataChecked}}">
</vn-check> </vn-check>
<vn-check <vn-check
vn-one vn-two
label="Verified data" label="Verified data"
field="$ctrl.client.isTaxDataChecked" field="$ctrl.client.isTaxDataChecked"
vn-acl="administrative, salesAssistant, salesAssistant"> vn-acl="administrative, salesAssistant, salesAssistant">

View File

@ -16,8 +16,8 @@
</div> </div>
<label class="mdl-textfield__label" translate>{{::$ctrl.label}}</label> <label class="mdl-textfield__label" translate>{{::$ctrl.label}}</label>
</div> </div>
<vn-drop-down
vn-id="drop-down"
on-select="$ctrl.onDropDownSelect(value)">
</vn-drop-down>
</div> </div>
<vn-drop-down
vn-id="drop-down"
on-select="$ctrl.onDropDownSelect(value)">
</vn-drop-down>

View File

@ -45,6 +45,9 @@ export default class DropDown extends Component {
this._search = value; this._search = value;
this.$.model.clear(); this.$.model.clear();
if (value != null)
this._activeOption = 0;
this.$timeout.cancel(this.searchTimeout); this.$timeout.cancel(this.searchTimeout);
this.searchTimeout = this.$timeout(() => { this.searchTimeout = this.$timeout(() => {
this.refreshModel(); this.refreshModel();
@ -86,8 +89,8 @@ export default class DropDown extends Component {
* @param {String} search The initial search term or %null * @param {String} search The initial search term or %null
*/ */
show(search) { show(search) {
this.search = search;
this._activeOption = -1; this._activeOption = -1;
this.search = search;
this.buildList(); this.buildList();
this.$.popover.parent = this.parent; this.$.popover.parent = this.parent;
this.$.popover.show(); this.$.popover.show();
@ -101,7 +104,7 @@ export default class DropDown extends Component {
} }
/** /**
* Activates a option and scrolls the drop-down to that option. * Activates an option and scrolls the drop-down to that option.
* *
* @param {Number} option The option index * @param {Number} option The option index
*/ */
@ -122,7 +125,7 @@ export default class DropDown extends Component {
} }
/** /**
* Activates a option. * Activates an option.
* *
* @param {Number} option The option index * @param {Number} option The option index
*/ */
@ -146,10 +149,11 @@ export default class DropDown extends Component {
* @param {Number} option The option index * @param {Number} option The option index
*/ */
selectOption(option) { selectOption(option) {
if (option != -1) { let data = this.$.model.data;
let data = this.$.model.data; let item = option != -1 && data ? data[option] : null;
let item = data ? data[option] : null;
let value = item ? item[this.valueField] : null; if (item) {
let value = item[this.valueField];
if (this.multiple) { if (this.multiple) {
if (!Array.isArray(this.selection)) { if (!Array.isArray(this.selection)) {
@ -252,6 +256,9 @@ export default class DropDown extends Component {
let nOpts = data ? data.length - 1 : 0; let nOpts = data ? data.length - 1 : 0;
switch (event.keyCode) { switch (event.keyCode) {
case 9: // Tab
this.selectOption(option);
return;
case 13: // Enter case 13: // Enter
this.selectOption(option); this.selectOption(option);
break; break;

View File

@ -32,14 +32,21 @@ export default class Popover extends Component {
this.content = this.element.querySelector('.content'); this.content = this.element.querySelector('.content');
} }
set child(value) { /**
this.content.appendChild(value); * @type {HTMLElement} The popover child.
} */
get child() { get child() {
return this.content.firstChild; return this.content.firstChild;
} }
set child(value) {
this.content.innerHTML = '';
this.content.appendChild(value);
}
/**
* @type {Boolean} Wether to show or hide the popover.
*/
get shown() { get shown() {
return this._shown; return this._shown;
} }
@ -88,6 +95,9 @@ export default class Popover extends Component {
this.showTimeout = this.$timeout(() => { this.showTimeout = this.$timeout(() => {
this.element.style.display = 'none'; this.element.style.display = 'none';
this.showTimeout = null; this.showTimeout = null;
if (this.onClose)
this.onClose();
}, 250); }, 250);
this.document.removeEventListener('keydown', this.docKeyDownHandler); this.document.removeEventListener('keydown', this.docKeyDownHandler);
@ -95,12 +105,6 @@ export default class Popover extends Component {
if (this.deregisterCallback) if (this.deregisterCallback)
this.deregisterCallback(); this.deregisterCallback();
if (this.parent)
this.parent.focus();
if (this.onClose)
this.onClose();
} }
/** /**
@ -189,35 +193,3 @@ ngModule.component('vnPopover', {
onClose: '&?' onClose: '&?'
} }
}); });
class PopoverService {
constructor($document, $compile, $transitions, $rootScope) {
this.$compile = $compile;
this.$rootScope = $rootScope;
this.$document = $document;
this.stack = [];
}
show(child, parent, $scope) {
let element = this.$compile('<vn-popover/>')($scope || this.$rootScope)[0];
let popover = element.$ctrl;
popover.parent = parent;
popover.child = child;
popover.show();
popover.onClose = () => {
this.$document[0].body.removeChild(element);
if ($scope) $scope.$destroy();
};
this.$document[0].body.appendChild(element);
return popover;
}
showComponent(componentTag, $scope, parent) {
let $newScope = $scope.$new();
let childElement = this.$compile(`<${componentTag}/>`)($newScope)[0];
this.show(childElement, parent, $newScope);
return childElement;
}
}
PopoverService.$inject = ['$document', '$compile', '$transitions', '$rootScope'];
ngModule.service('vnPopover', PopoverService);

View File

@ -13,6 +13,7 @@ export default class Controller {
this.removedBarcodes = []; this.removedBarcodes = [];
this.oldBarcodes = {}; this.oldBarcodes = {};
} }
_setIconAdd() { _setIconAdd() {
if (this.barcodes.length) { if (this.barcodes.length) {
this.barcodes.map(element => { this.barcodes.map(element => {
@ -30,11 +31,13 @@ export default class Controller {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
} }
} }
_unsetDirtyForm() { _unsetDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setPristine(); this.$scope.form.$setPristine();
} }
} }
_equalBarcodes(oldBarcode, newBarcode) { _equalBarcodes(oldBarcode, newBarcode) {
return oldBarcode.id === newBarcode.id && oldBarcode.code === newBarcode.code; return oldBarcode.id === newBarcode.id && oldBarcode.code === newBarcode.code;
} }

View File

@ -8,7 +8,8 @@
<vn-title>Item Niches</vn-title> <vn-title>Item Niches</vn-title>
<vn-horizontal ng-repeat="itemNiche in $ctrl.niches track by $index"> <vn-horizontal ng-repeat="itemNiche in $ctrl.niches track by $index">
<vn-autocomplete <vn-autocomplete
vn-three ng-if="!itemNiche.id"
vn-one
data="$ctrl.warehouses" data="$ctrl.warehouses"
show-field="name" show-field="name"
value-field="id" value-field="id"
@ -18,7 +19,14 @@
vn-acl="buyer,replenisher"> vn-acl="buyer,replenisher">
</vn-autocomplete> </vn-autocomplete>
<vn-textfield <vn-textfield
vn-three ng-if="itemNiche.id"
vn-one
label="Warehouse"
model="itemNiche.warehouse.name"
disabled="true">
</vn-textfield>
<vn-textfield
vn-two
label="code" label="code"
model="itemNiche.code" model="itemNiche.code"
rule="itemNiche.code" rule="itemNiche.code"

View File

@ -31,6 +31,7 @@ export default class Controller {
this.$scope.form.$setDirty(); this.$scope.form.$setDirty();
} }
} }
_unsetDirtyForm() { _unsetDirtyForm() {
if (this.$scope.form) { if (this.$scope.form) {
this.$scope.form.$setPristine(); this.$scope.form.$setPristine();
@ -70,6 +71,7 @@ export default class Controller {
where: {itemFk: this.params.id}, where: {itemFk: this.params.id},
include: {relation: 'warehouse'} include: {relation: 'warehouse'}
}; };
this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => { this.$http.get(`/item/api/ItemNiches?filter=${JSON.stringify(filter)}`).then(response => {
this.niches = response.data; this.niches = response.data;
this.setOldNiches(response); this.setOldNiches(response);
@ -95,6 +97,7 @@ export default class Controller {
create: [], create: [],
update: [] update: []
}; };
this.niches.forEach(niche => { this.niches.forEach(niche => {
let isNewNiche = !niche.id; let isNewNiche = !niche.id;

View File

@ -92,7 +92,7 @@ describe('Item', () => {
}); });
describe('submit()', () => { describe('submit()', () => {
it("should return an error message 'The niche must be unique' when the niche code isnt unique", () => { it("should return an error message 'The niche must be unique' when the niche warehouse isnt unique", () => {
controller.$scope.form = {}; controller.$scope.form = {};
spyOn(controller.vnApp, 'showMessage').and.callThrough(); spyOn(controller.vnApp, 'showMessage').and.callThrough();
controller.niches = [ controller.niches = [

View File

@ -8,6 +8,7 @@
<vn-title>Item tags</vn-title> <vn-title>Item tags</vn-title>
<vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags track by $index"> <vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags track by $index">
<vn-autocomplete <vn-autocomplete
ng-if="!itemTag.id"
vn-one vn-one
initial-data="itemTag.tag" initial-data="itemTag.tag"
field="itemTag.tagFk" field="itemTag.tagFk"
@ -16,6 +17,13 @@
label="Tag" label="Tag"
vn-acl="buyer"> vn-acl="buyer">
</vn-autocomplete> </vn-autocomplete>
<vn-textfield
ng-if="itemTag.id"
vn-one
label="Tag"
model="itemTag.tag.name"
disabled="true">
</vn-textfield>
<vn-textfield <vn-textfield
vn-three vn-three
label="Value" label="Value"

View File

@ -1,14 +1,18 @@
<form ng-submit="$ctrl.onSubmit()"> <form ng-submit="$ctrl.onSubmit()">
<vn-horizontal> <vn-horizontal>
<vn-textfield vn-one label="Search" model="$ctrl.stringSearch"></vn-textfield> <vn-textfield vn-one label="Search" model="$ctrl.stringSearch"></vn-textfield>
<vn-icon <vn-icon
pad-medium-top pad-medium-top
ng-if="$ctrl.advanced" ng-if="$ctrl.advanced"
ng-click="$ctrl.onpenFilters($event)" ng-click="$ctrl.onpenFilters($event)"
icon="keyboard_arrow_down" icon="keyboard_arrow_down"
style="cursor: pointer;"> style="cursor: pointer;">
</vn-icon> </vn-icon>
<vn-button ng-if="$ctrl.label" vn-none label="{{$ctrl.label}}"></vn-button> <vn-button ng-if="$ctrl.label" vn-none label="{{$ctrl.label}}"></vn-button>
<vn-icon-button ng-if="!$ctrl.label" icon="search" ng-click="$ctrl.clearFilter()"></vn-icon-button> <vn-icon-button ng-if="!$ctrl.label" icon="search" ng-click="$ctrl.clearFilter()"></vn-icon-button>
</vn-horizontal> </vn-horizontal>
</form> </form>
<vn-popover
vn-id="popover"
on-close="$ctrl.onPopoverClose()">
</vn-popover>

View File

@ -1,12 +1,10 @@
import ngModule from '../../module'; import ngModule from '../../module';
export default class Controller { export default class Controller {
constructor($element, $scope, $document, $compile, vnPopover, $timeout, $state, $transitions) { constructor($element, $scope, $compile, $timeout, $state, $transitions) {
this.element = $element[0]; this.element = $element[0];
this.$scope = $scope; this.$ = $scope;
this.$document = $document;
this.$compile = $compile; this.$compile = $compile;
this.vnPopover = vnPopover;
this.$timeout = $timeout; this.$timeout = $timeout;
this.stringSearch = ''; this.stringSearch = '';
this.$state = $state; this.$state = $state;
@ -91,23 +89,32 @@ export default class Controller {
filter = this.getFiltersFromString(this.stringSearch); filter = this.getFiltersFromString(this.stringSearch);
} }
this.child = this.vnPopover.showComponent(this.popover, this.$scope, this.element); this.$child = this.$compile(`<${this.popover}/>`)(this.$.$new());
// XXX: ¿Existe una forma más adecuada de acceder al controlador de un componente? var childCtrl = this.$child.isolateScope().$ctrl;
var childCtrl = angular.element(this.child).isolateScope().$ctrl;
childCtrl.filter = Object.assign({}, filter); childCtrl.filter = Object.assign({}, filter);
childCtrl.onSubmit = filter => this.onChildSubmit(filter); childCtrl.onSubmit = filter => this.onChildSubmit(filter);
if (this.data) if (this.data)
childCtrl.data = Object.assign({}, this.data); childCtrl.data = Object.assign({}, this.data);
event.preventDefault(); event.preventDefault();
this.$.popover.parent = this.element;
this.$.popover.child = this.$child[0];
this.$.popover.show();
}
onPopoverClose() {
this.$child.scope().$destroy();
this.$child.remove();
this.$child = null;
} }
onChildSubmit(filter) { onChildSubmit(filter) {
this.$.popover.hide();
this.stringSearch = this.createStringFromObject(filter); this.stringSearch = this.createStringFromObject(filter);
this.clearFilter(); this.clearFilter();
this.$timeout(() => { this.$timeout(() => this.onSubmit());
this.onSubmit();
});
} }
onSubmit() { onSubmit() {
@ -120,12 +127,6 @@ export default class Controller {
if (this.onSearch) if (this.onSearch)
this.onSearch(); this.onSearch();
if (angular.element(this.child)) {
if (angular.element(this.child).scope())
angular.element(this.child).scope().$destroy();
angular.element(this.child).remove();
}
delete this.child;
this.pushFiltersToState(filter); this.pushFiltersToState(filter);
} }
@ -139,12 +140,10 @@ export default class Controller {
let filter = JSON.parse(decodeURIComponent(this.$state.params.q)); let filter = JSON.parse(decodeURIComponent(this.$state.params.q));
this.stringSearch = this.createStringFromObject(filter); this.stringSearch = this.createStringFromObject(filter);
} }
this.$timeout(() => { this.$timeout(() => this.onSubmit());
this.onSubmit();
});
} }
} }
Controller.$inject = ['$element', '$scope', '$document', '$compile', 'vnPopover', '$timeout', '$state', '$transitions']; Controller.$inject = ['$element', '$scope', '$compile', '$timeout', '$state', '$transitions'];
ngModule.component('vnSearchbar', { ngModule.component('vnSearchbar', {
template: require('./searchbar.html'), template: require('./searchbar.html'),

View File

@ -46,6 +46,18 @@
"icon": "settings" "icon": "settings"
} }
}, },
{
"url": "/observations",
"state": "ticket.card.observations",
"component": "vn-ticket-observations",
"params": {
"ticket": "$ctrl.ticket"
},
"menu": {
"description": "Notes",
"icon": "insert_drive_file"
}
},
{ {
"url" : "/package", "url" : "/package",
"abstract": true, "abstract": true,
@ -64,6 +76,18 @@
"icon": "icon-bucket" "icon": "icon-bucket"
} }
}, },
{
"url" : "/review",
"state": "ticket.card.review",
"component": "vn-ticket-review",
"params": {
"ticket": "$ctrl.ticket"
},
"menu": {
"description": "Review",
"icon": "remove_red_eye"
}
},
{ {
"url" : "/sale", "url" : "/sale",
"state": "ticket.card.sale", "state": "ticket.card.sale",

View File

@ -1 +1,6 @@
Tickets: Tickets Tickets: Tickets
Notes: Notas
Observation type: Tipo de observación
Description: Descripción
The observation type must be unique: El tipo de observación debe ser único
Some fields are invalid: Algunos campos no son válidos

View File

@ -0,0 +1,60 @@
<vn-watcher
vn-id="watcher"
url="/client/api/Addresses"
id-field="id"
data="$ctrl.address"
form="form">
</vn-watcher>
<form name="form" ng-submit="$ctrl.submit()">
<vn-card pad-large>
<vn-one margin-medium-top>
<vn-title>Notes</vn-title>
<mg-ajax path="/ticket/api/ObservationTypes" options="mgIndex as observationTypes"></mg-ajax>
<vn-horizontal ng-repeat="ticketObservation in $ctrl.ticketObservations track by $index">
<vn-autocomplete
ng-if="!ticketObservation.id"
vn-one
initial-data="ticketObservation.observationType"
field="ticketObservation.observationTypeFk"
data="observationTypes.model"
show-field="description"
label="Observation type">
</vn-autocomplete>
<vn-textfield
ng-if="ticketObservation.id"
vn-one
label="Observation type"
model="ticketObservation.observationType.description"
disabled="true">
</vn-textfield>
<vn-textfield
vn-two
margin-large-right
label="Description"
model="ticketObservation.description">
</vn-textfield>
<vn-auto pad-medium-top>
<vn-icon
pointer
medium-grey
vn-tooltip="Remove note"
tooltip-position="left"
icon="remove_circle_outline"
ng-click="$ctrl.removeObservation($index)">
</vn-icon>
</vn-auto>
</vn-horizontal>
</vn-one>
<vn-one>
<vn-icon
pointer margin-medium-left vn-tooltip="Add note"
tooltip-position="right" orange icon="add_circle"
ng-if="observationTypes.model.length > $ctrl.ticketObservations.length"
ng-click="$ctrl.addObservation()">
</vn-icon>
</vn-one>
</vn-card>
<vn-button-bar>
<vn-submit label="Save"></vn-submit>
</vn-button-bar>
</form>

View File

@ -0,0 +1,140 @@
import ngModule from '../module';
class TicketObservations {
constructor($stateParams, $scope, $http, $translate, vnApp) {
this.params = $stateParams;
this.$scope = $scope;
this.$http = $http;
this.$translate = $translate;
this.vnApp = vnApp;
this.ticketObservations = [];
this.oldObservations = {};
this.removedObservations = [];
}
_setIconAdd() {
if (this.ticketObservations.length) {
this.ticketObservations.map(element => {
element.showAddIcon = false;
return true;
});
this.ticketObservations[this.ticketObservations.length - 1].showAddIcon = true;
}
}
_setDirtyForm() {
if (this.$scope.form) {
this.$scope.form.$setDirty();
}
}
_unsetDirtyForm() {
if (this.$scope.form) {
this.$scope.form.$setPristine();
}
}
addObservation() {
this.ticketObservations.push({description: null, ticketFk: this.params.id, showAddIcon: true});
this._setIconAdd();
}
removeObservation(index) {
let item = this.ticketObservations[index];
if (item) {
this.ticketObservations.splice(index, 1);
this._setIconAdd();
if (item.id) {
this.removedObservations.push(item.id);
this._setDirtyForm();
}
}
}
_equalObservations(oldObservation, newObservation) {
return oldObservation.id === newObservation.id && oldObservation.observationTypeFk === newObservation.observationTypeFk && oldObservation.description === newObservation.description;
}
setOldObservations(response) {
this._setIconAdd();
response.data.forEach(observation => {
this.oldObservations[observation.id] = Object.assign({}, observation);
});
}
getObservations() {
let filter = {
where: {ticketFk: this.params.id},
include: ['observationType']
};
this.$http.get(`/ticket/api/TicketObservations?filter=${JSON.stringify(filter)}`).then(response => {
this.ticketObservations = response.data;
this.setOldObservations(response);
});
}
submit() {
let typesDefined = [];
let repeatedType = false;
let canSubmit;
let observationsObj = {
delete: this.removedObservations,
create: [],
update: []
};
this.ticketObservations.forEach(observation => {
let isNewObservation = !observation.id;
delete observation.showAddIcon;
if (typesDefined.indexOf(observation.observationTypeFk) !== -1) {
repeatedType = true;
return;
}
typesDefined.push(observation.observationTypeFk);
if (isNewObservation && observation.description && observation.observationTypeFk) {
observationsObj.create.push(observation);
}
if (!isNewObservation && !this._equalObservations(this.oldObservations[observation.id], observation)) {
observationsObj.update.push(observation);
}
});
if (this.$scope.form.$invalid) {
return this.vnApp.showMessage(this.$translate.instant('Some fields are invalid'));
}
if (repeatedType) {
return this.vnApp.showMessage(this.$translate.instant('The observation type must be unique'));
}
canSubmit = observationsObj.update.length > 0 || observationsObj.create.length > 0 || observationsObj.delete.length > 0;
if (canSubmit) {
return this.$http.post(`/ticket/api/TicketObservations/crudTicketObservations`, observationsObj).then(() => {
this.getObservations();
this._unsetDirtyForm();
});
}
this.vnApp.showMessage(this.$translate.instant('No changes to save'));
}
$onInit() {
this.getObservations();
}
}
TicketObservations.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp'];
ngModule.component('vnTicketObservations', {
template: require('./ticket-observations.html'),
controller: TicketObservations,
bindings: {
ticket: '<'
}
});

View File

@ -0,0 +1,143 @@
import './ticket-observations.js';
describe('ticket', () => {
describe('Component vnTicketObservations', () => {
let $componentController;
let $state;
let controller;
let $httpBackend;
beforeEach(() => {
angular.mock.module('ticket');
});
beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_) => {
$componentController = _$componentController_;
$state = _$state_;
$httpBackend = _$httpBackend_;
controller = $componentController('vnTicketObservations', {$state: $state});
}));
describe('add / remove observation', () => {
it('should add one empty observation into controller observations collection and call _setIconAdd()', () => {
controller.ticketObservations = [];
spyOn(controller, '_setIconAdd').and.callThrough();
controller.addObservation();
expect(controller._setIconAdd).toHaveBeenCalledWith();
expect(controller.ticketObservations.length).toEqual(1);
expect(controller.ticketObservations[0].id).toBe(undefined);
expect(controller.ticketObservations[0].showAddIcon).toBeTruthy();
});
it('should remove an observation that occupies the position in the index given and call _setIconAdd()', () => {
let index = 2;
controller.ticketObservations = [
{id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false},
{id: 2, observationTypeFk: 2, description: 'two', showAddIcon: false},
{id: 3, observationTypeFk: 3, description: 'three', showAddIcon: true}
];
spyOn(controller, '_setIconAdd').and.callThrough();
controller.removeObservation(index);
expect(controller._setIconAdd).toHaveBeenCalledWith();
expect(controller.ticketObservations.length).toEqual(2);
expect(controller.ticketObservations[0].showAddIcon).toBeFalsy();
expect(controller.ticketObservations[1].showAddIcon).toBeTruthy();
expect(controller.ticketObservations[index]).toBe(undefined);
});
});
describe('_equalObservations()', () => {
it('should return true if two observations are equals independent of control attributes', () => {
let observationOne = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: true};
let observationTwo = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false};
let equals = controller._equalObservations(observationOne, observationTwo);
expect(equals).toBeTruthy();
});
it('should return false if two observations aint equals independent of control attributes', () => {
let observationOne = {id: 1, observationTypeFk: 1, description: 'one', showAddIcon: true};
let observationTwo = {id: 1, observationTypeFk: 1, description: 'two', showAddIcon: true};
let equals = controller._equalObservations(observationOne, observationTwo);
expect(equals).toBeFalsy();
});
});
describe('get Observations()', () => {
it('should perform a GET query to receive the ticket observations', () => {
let res = [{id: 1, observationTypeFk: 1, description: 'one'}];
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond(res);
$httpBackend.expectGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`);
controller.getObservations();
$httpBackend.flush();
});
});
describe('submit()', () => {
it("should return an error message 'The observation type must be unique'", () => {
controller.$scope.form = {};
spyOn(controller.vnApp, 'showMessage').and.callThrough();
controller.ticketObservations = [
{id: 1, observationTypeFk: 1, description: 'one', itemFk: 1},
{observationTypeFk: 1, description: 'one', itemFk: 1}
];
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one', itemFk: 1}};
controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('The observation type must be unique');
});
it("should perfom a query to delete observations", () => {
controller.$scope.form = {$setPristine: () => {}};
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
controller.ticketObservations = [];
controller.removedObservations = [1];
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
controller.submit();
$httpBackend.flush();
});
it("should perfom a query to update observations", () => {
controller.$scope.form = {$setPristine: () => {}};
controller.ticketObservations = [{id: 1, observationTypeFk: 1, description: 'number one!'}];
controller.oldObservations = {1: {id: 1, observationTypeFk: 1, description: 'one'}};
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
controller.submit();
$httpBackend.flush();
});
it("should perfom a query to create new observation", () => {
controller.$scope.form = {$setPristine: () => {}};
controller.ticketObservations = [{observationTypeFk: 2, description: 'two'}];
$httpBackend.whenGET(`/ticket/api/TicketObservations?filter={"where":{},"include":["observationType"]}`).respond([]);
$httpBackend.expectPOST(`/ticket/api/TicketObservations/crudTicketObservations`).respond('ok!');
controller.submit();
$httpBackend.flush();
});
it("should return a message 'No changes to save' when there are no changes to apply", () => {
controller.$scope.form = {$setPristine: () => {}};
spyOn(controller.vnApp, 'showMessage').and.callThrough();
controller.oldObservations = [
{id: 1, observationTypeFk: 1, description: 'one', showAddIcon: false},
{id: 2, observationTypeFk: 2, description: 'two', showAddIcon: true}
];
controller.ticketObservations = [];
controller.submit();
expect(controller.vnApp.showMessage).toHaveBeenCalledWith('No changes to save');
});
});
});
});

View File

@ -0,0 +1,4 @@
date : Fecha
Employee : Empleado
State: Estado
Review: Revision

View File

@ -0,0 +1,23 @@
<mg-ajax path="" options="vnIndexNonAuto"></mg-ajax>
<vn-vertical pad-medium>
<vn-card pad-large>
<vn-vertical>
<vn-title>Review</vn-title>
<vn-grid-header on-order="$ctrl.onOrder(field, order)">
<vn-column-header vn-one pad-medium-h field="date" text="date"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="employee" text="Employee" default-order="ASC"></vn-column-header>
<vn-column-header vn-two pad-medium-h field="state" text="State" order-locked></vn-column-header>
</vn-grid-header>
<vn-one class="list list-content">
</vn-horizontal>
</vn-one>
<vn-one class="text-center pad-small-v" ng-if="index.model.count === 0" translate>No results</vn-one>
<vn-horizontal vn-one class="list list-footer"></vn-horizontal>
<vn-paging vn-one margin-large-top index="index" total="index.model.count"></vn-paging>
</vn-vertical>
</vn-card>
</vn-vertical>
<a ui-sref="clientCard.ticket.create" fixed-bottom-right>
<vn-float-button icon="add"></vn-float-button>
</a>

View File

@ -0,0 +1,18 @@
import ngModule from '../module';
class ticketReview {
construct($http, $scope) {
this.$http = $http;
this.$ = $scope;
}
}
ticketReview.$inject = ['$http', '$scope'];
ngModule.component('vnTicketReview', {
template: require('./review.html'),
controller: ticketReview,
bindings: {
ticket: '<'
}
});

View File

@ -5,5 +5,7 @@ import './create/ticket-create';
import './card/ticket-card'; import './card/ticket-card';
import './summary/ticket-summary'; import './summary/ticket-summary';
import './data/ticket-data'; import './data/ticket-data';
import './notes/ticket-observations';
import './package/list/package-list'; import './package/list/package-list';
import './sale/sale'; import './sale/sale';
import './review/review';

View File

@ -11,7 +11,8 @@ export default {
}, },
moduleAccessView: { moduleAccessView: {
clientsSectionButton: `${components.vnModuleContainer}[ui-sref="clients"]`, clientsSectionButton: `${components.vnModuleContainer}[ui-sref="clients"]`,
itemsSectionButton: `${components.vnModuleContainer}[ui-sref="item.index"]` itemsSectionButton: `${components.vnModuleContainer}[ui-sref="item.index"]`,
ticketsSectionButton: `${components.vnModuleContainer}[ui-sref="ticket.list"]`
}, },
clientsIndex: { clientsIndex: {
searchClientInput: `${components.vnTextfield}`, searchClientInput: `${components.vnTextfield}`,
@ -56,9 +57,10 @@ export default {
provinceFifthOption: `${components.vnAutocomplete}[field="$ctrl.client.provinceFk"] vn-drop-down ul > li:nth-child(5)`, provinceFifthOption: `${components.vnAutocomplete}[field="$ctrl.client.provinceFk"] vn-drop-down ul > li:nth-child(5)`,
countryInput: `${components.vnAutocomplete}[field="$ctrl.client.countryFk"] input`, countryInput: `${components.vnAutocomplete}[field="$ctrl.client.countryFk"] input`,
countryThirdOption: `${components.vnAutocomplete}[field="$ctrl.client.countryFk"] vn-drop-down ul > li:nth-child(3)`, countryThirdOption: `${components.vnAutocomplete}[field="$ctrl.client.countryFk"] vn-drop-down ul > li:nth-child(3)`,
activeCheckboxLabel: `${components.vnCheck}[label='Active'] > label`, activeCheckboxLabel: `${components.vnCheck}[label="Active"] > label`,
frozenCheckboxLabel: `${components.vnCheck}[label="Frozen"] > label`,
invoiceByAddressCheckboxInput: `${components.vnCheck}[label='Invoice by address'] > label > input`, invoiceByAddressCheckboxInput: `${components.vnCheck}[label='Invoice by address'] > label > input`,
verifiedDataCheckboxInput: `${components.vnCheck}[label='Verified data'] > label > input`, verifiedDataCheckboxInput: `${components.vnCheck}[label="Verified data"] > label > input`,
hasToInvoiceCheckboxLabel: `${components.vnCheck}[label='Has to invoice'] > label`, hasToInvoiceCheckboxLabel: `${components.vnCheck}[label='Has to invoice'] > label`,
invoiceByMailCheckboxLabel: `${components.vnCheck}[label='Invoice by mail'] > label`, invoiceByMailCheckboxLabel: `${components.vnCheck}[label='Invoice by mail'] > label`,
viesCheckboxInput: `${components.vnCheck}[label='Vies'] > label > input`, viesCheckboxInput: `${components.vnCheck}[label='Vies'] > label > input`,
@ -188,24 +190,29 @@ export default {
itemTags: { itemTags: {
goToItemIndexButton: 'vn-item-descriptor [ui-sref="item.index"]', goToItemIndexButton: 'vn-item-descriptor [ui-sref="item.index"]',
tagsButton: `${components.vnMenuItem}[ui-sref="item.card.tags"]`, tagsButton: `${components.vnMenuItem}[ui-sref="item.card.tags"]`,
firstRemoveTagButton: `vn-item-tags vn-horizontal:nth-child(2) > ${components.vnIcon}[icon="remove_circle_outline"]`,
firstTagSelect: `vn-item-tags vn-horizontal:nth-child(2) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`, firstTagSelect: `vn-item-tags vn-horizontal:nth-child(2) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`,
firstTagDisabled: `vn-item-tags vn-horizontal:nth-child(2) > vn-textfield[label="Tag"] > div > input`,
firstTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(2) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`, firstTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(2) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`,
firstValueInput: `vn-item-tags vn-horizontal:nth-child(2) > vn-textfield[label="Value"] > div > input`, firstValueInput: `vn-item-tags vn-horizontal:nth-child(2) > vn-textfield[label="Value"] > div > input`,
firstRelevancyInput: `vn-horizontal:nth-child(2) > vn-textfield[label="Relevancy"] > div > input`, firstRelevancyInput: `vn-horizontal:nth-child(2) > vn-textfield[label="Relevancy"] > div > input`,
secondTagSelect: `vn-item-tags vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`, secondTagSelect: `vn-item-tags vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`,
secondTagDisabled: `vn-item-tags vn-horizontal:nth-child(3) > vn-textfield[label="Tag"] > div > input`,
secondTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`, secondTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`,
secondValueInput: `vn-item-tags vn-horizontal:nth-child(3) > vn-textfield[label="Value"] > div > input`, secondValueInput: `vn-item-tags vn-horizontal:nth-child(3) > vn-textfield[label="Value"] > div > input`,
secondRelevancyInput: `vn-horizontal:nth-child(3) > vn-textfield[label="Relevancy"] > div > input`, secondRelevancyInput: `vn-horizontal:nth-child(3) > vn-textfield[label="Relevancy"] > div > input`,
thirdTagSelect: `vn-item-tags vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`, thirdTagSelect: `vn-item-tags vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`,
thirdTagDisabled: `vn-item-tags vn-horizontal:nth-child(4) > vn-textfield[label="Tag"] > div > input`,
thirdTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`, thirdTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`,
thirdValueInput: `vn-item-tags vn-horizontal:nth-child(4) > vn-textfield[label="Value"] > div > input`, thirdValueInput: `vn-item-tags vn-horizontal:nth-child(4) > vn-textfield[label="Value"] > div > input`,
thirdRelevancyInput: `vn-horizontal:nth-child(4) > vn-textfield[label="Relevancy"] > div > input`, thirdRelevancyInput: `vn-horizontal:nth-child(4) > vn-textfield[label="Relevancy"] > div > input`,
fourthTagSelect: `vn-item-tags vn-horizontal:nth-child(5) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`, fourthTagSelect: `vn-item-tags vn-horizontal:nth-child(5) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`,
fourthTagDisabled: `vn-item-tags vn-horizontal:nth-child(5) > vn-textfield[label="Tag"] > div > input`,
fourthTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(5) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`, fourthTagSelectOptionOne: `vn-item-tags vn-horizontal:nth-child(5) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(1)`,
fourthValueInput: `vn-item-tags vn-horizontal:nth-child(5) > vn-textfield[label="Value"] > div > input`, fourthValueInput: `vn-item-tags vn-horizontal:nth-child(5) > vn-textfield[label="Value"] > div > input`,
fourthRelevancyInput: `vn-horizontal:nth-child(5) > vn-textfield[label="Relevancy"] > div > input`, fourthRelevancyInput: `vn-horizontal:nth-child(5) > vn-textfield[label="Relevancy"] > div > input`,
fifthRemoveTagButton: `vn-item-tags vn-horizontal:nth-child(6) > ${components.vnIcon}[icon="remove_circle_outline"]`,
fifthTagSelect: `vn-item-tags vn-horizontal:nth-child(6) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`, fifthTagSelect: `vn-item-tags vn-horizontal:nth-child(6) > ${components.vnAutocomplete}[field="itemTag.tagFk"] input`,
fifthTagDisabled: `vn-item-tags vn-horizontal:nth-child(6) > vn-textfield[label="Tag"] > div > input`,
fifthTagSelectOptionFive: `vn-item-tags vn-horizontal:nth-child(6) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(5)`, fifthTagSelectOptionFive: `vn-item-tags vn-horizontal:nth-child(6) > ${components.vnAutocomplete}[field="itemTag.tagFk"] vn-drop-down ul > li:nth-child(5)`,
fifthValueInput: `vn-item-tags vn-horizontal:nth-child(6) > vn-textfield[label="Value"] > div > input`, fifthValueInput: `vn-item-tags vn-horizontal:nth-child(6) > vn-textfield[label="Value"] > div > input`,
fifthRelevancyInput: `vn-horizontal:nth-child(6) > vn-textfield[label="Relevancy"] > div > input`, fifthRelevancyInput: `vn-horizontal:nth-child(6) > vn-textfield[label="Relevancy"] > div > input`,
@ -233,14 +240,17 @@ export default {
nicheButton: `${components.vnMenuItem}[ui-sref="item.card.niche"]`, nicheButton: `${components.vnMenuItem}[ui-sref="item.card.niche"]`,
addNicheButton: `${components.vnIcon}[icon="add_circle"]`, addNicheButton: `${components.vnIcon}[icon="add_circle"]`,
firstWarehouseSelect: `${components.vnAutocomplete}[field="itemNiche.warehouseFk"] input`, firstWarehouseSelect: `${components.vnAutocomplete}[field="itemNiche.warehouseFk"] input`,
firstWarehouseDisabled: `vn-horizontal:nth-child(2) > vn-textfield[label="Warehouse"] > div > input`,
firstWarehouseSelectSecondOption: `${components.vnAutocomplete}[field="itemNiche.warehouseFk"] vn-drop-down ul > li:nth-child(2)`, firstWarehouseSelectSecondOption: `${components.vnAutocomplete}[field="itemNiche.warehouseFk"] vn-drop-down ul > li:nth-child(2)`,
firstCodeInput: `vn-horizontal:nth-child(2) > vn-textfield[label="code"] > div > input`,
secondWarehouseSelect: `vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemNiche.warehouseFk"] input`, secondWarehouseSelect: `vn-horizontal:nth-child(3) > ${components.vnAutocomplete}[field="itemNiche.warehouseFk"] input`,
thirdWarehouseSelect: `vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemNiche.warehouseFk"] input`, secondWarehouseDisabled: `vn-horizontal:nth-child(3) > vn-textfield[label="Warehouse"] > div > input`,
thirdWarehouseSelectFourthOption: `vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemNiche.warehouseFk"] vn-drop-down ul > li:nth-child(4)`, secondCodeInput: `vn-horizontal:nth-child(3) > vn-textfield[label="code"] > div > input`,
secondNicheRemoveButton: `vn-horizontal:nth-child(3) > vn-one > ${components.vnIcon}[icon="remove_circle_outline"]`, secondNicheRemoveButton: `vn-horizontal:nth-child(3) > vn-one > ${components.vnIcon}[icon="remove_circle_outline"]`,
firstCodeInput: `vn-horizontal:nth-child(2) > ${components.vnTextfield}`, thirdWarehouseSelect: `vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemNiche.warehouseFk"] input`,
secondCodeInput: `vn-horizontal:nth-child(3) > ${components.vnTextfield}`, thirdWarehouseDisabled: `vn-horizontal:nth-child(4) > vn-textfield[label="Warehouse"] > div > input`,
thirdCodeInput: `vn-horizontal:nth-child(4) > ${components.vnTextfield}`, thirdWarehouseSelectFourthOption: `vn-horizontal:nth-child(4) > ${components.vnAutocomplete}[field="itemNiche.warehouseFk"] vn-drop-down ul > li:nth-child(4)`,
thirdCodeInput: `vn-horizontal:nth-child(4) > vn-textfield[label="code"] > div > input`,
submitNichesButton: `${components.vnSubmit}` submitNichesButton: `${components.vnSubmit}`
}, },
itemBotanical: { itemBotanical: {
@ -261,5 +271,25 @@ export default {
niche: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(2) > vn-vertical > p:nth-child(2)`, niche: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(2) > vn-vertical > p:nth-child(2)`,
botanical: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(3) > vn-vertical > p`, botanical: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(3) > vn-vertical > p`,
barcode: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(4) > vn-vertical > p` barcode: `${components.vnItemSummary} > vn-horizontal:nth-child(2) > vn-one:nth-child(4) > vn-vertical > p`
},
ticketsIndex: {
createTicketButton: `${components.vnFloatButton}`,
searchResult: `vn-ticket-item a`,
searchTicketInput: `${components.vnTextfield}`,
searchButton: `${components.vnSearchBar} > vn-icon-button > button`
},
ticketNotes: {
notesButton: `${components.vnMenuItem}[ui-sref="ticket.card.observations"]`,
firstNoteRemoveButton: `${components.vnIcon}[icon="remove_circle_outline"]`,
addNoteButton: `${components.vnIcon}[icon="add_circle"]`,
firstNoteSelect: `${components.vnAutocomplete}[field="ticketObservation.observationTypeFk"] input`,
firstNoteSelectSecondOption: `${components.vnAutocomplete}[field="ticketObservation.observationTypeFk"] vn-drop-down ul > li:nth-child(2)`,
firstNoteDisabled: `vn-textfield[label="Observation type"] > div > input`,
firstDescriptionInput: `vn-textfield[label="Description"] > div > input`,
submitNotesButton: `${components.vnSubmit}`
},
ticketPackages: {
packagesButton: `${components.vnMenuItem}[ui-sref="ticket.card.package.list"]`,
firstPackageSelect: `${components.vnAutocomplete}[label="Package"] input`
} }
}; };

View File

@ -99,6 +99,7 @@ describe('Edit fiscalData path', () => {
.waitToClick(selectors.clientFiscalData.provinceInput) .waitToClick(selectors.clientFiscalData.provinceInput)
.waitToClick(selectors.clientFiscalData.provinceFifthOption) .waitToClick(selectors.clientFiscalData.provinceFifthOption)
.waitToClick(selectors.clientFiscalData.activeCheckboxLabel) .waitToClick(selectors.clientFiscalData.activeCheckboxLabel)
.waitToClick(selectors.clientFiscalData.frozenCheckboxLabel)
.waitToClick(selectors.clientFiscalData.invoiceByAddressCheckboxInput) .waitToClick(selectors.clientFiscalData.invoiceByAddressCheckboxInput)
.waitToClick(selectors.clientFiscalData.verifiedDataCheckboxInput) .waitToClick(selectors.clientFiscalData.verifiedDataCheckboxInput)
.waitToClick(selectors.clientFiscalData.hasToInvoiceCheckboxLabel) .waitToClick(selectors.clientFiscalData.hasToInvoiceCheckboxLabel)
@ -227,6 +228,16 @@ describe('Edit fiscalData path', () => {
}); });
}); });
it('should confirm frozen checkbox is unchecked', () => {
return nightmare
.evaluate(selector => {
return document.querySelector(selector).checked;
}, selectors.clientFiscalData.frozenCheckboxLabel)
.then(value => {
expect(value).toBeFalsy();
});
});
it('should confirm invoice by address checkbox is unchecked', () => { it('should confirm invoice by address checkbox is unchecked', () => {
return nightmare return nightmare
.evaluate(selector => { .evaluate(selector => {

View File

@ -61,7 +61,7 @@ describe('lock verified data path', () => {
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput) .wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate(selector => { .evaluate(selector => {
return document.querySelector(selector).className; return document.querySelector(selector).className;
}, 'body > vn-app > vn-vertical > vn-vertical > vn-client-card > vn-main-block > vn-horizontal > vn-one > vn-vertical > vn-client-fiscal-data > form > vn-card > div > vn-horizontal:nth-child(5) > vn-check:nth-child(3) > label') }, 'body > vn-app > vn-vertical > vn-vertical > vn-client-card > vn-main-block > vn-horizontal > vn-one > vn-vertical > vn-client-fiscal-data > form > vn-card > div > vn-horizontal:nth-child(5) > vn-check:nth-child(4) > label')
.then(result => { .then(result => {
expect(result).toContain('is-disabled'); expect(result).toContain('is-disabled');
}); });
@ -452,7 +452,7 @@ describe('lock verified data path', () => {
.wait(selectors.clientFiscalData.verifiedDataCheckboxInput) .wait(selectors.clientFiscalData.verifiedDataCheckboxInput)
.evaluate(selector => { .evaluate(selector => {
return document.querySelector(selector).className; return document.querySelector(selector).className;
}, 'body > vn-app > vn-vertical > vn-vertical > vn-client-card > vn-main-block > vn-horizontal > vn-one > vn-vertical > vn-client-fiscal-data > form > vn-card > div > vn-horizontal:nth-child(5) > vn-check:nth-child(3) > label') }, 'body > vn-app > vn-vertical > vn-vertical > vn-client-card > vn-main-block > vn-horizontal > vn-one > vn-vertical > vn-client-fiscal-data > form > vn-card > div > vn-horizontal:nth-child(5) > vn-check:nth-child(4) > label')
.then(result => { .then(result => {
expect(result).toContain('is-disabled'); expect(result).toContain('is-disabled');
}); });

View File

@ -66,9 +66,10 @@ describe('edit item basic data path', () => {
it(`should confirm the item name was edited`, () => { it(`should confirm the item name was edited`, () => {
return nightmare return nightmare
.click(selectors.itemNiches.firstCodeInput) .click(selectors.itemNiches.nicheButton)
.wait(selectors.itemNiches.firstCodeInput) .wait(selectors.itemNiches.firstWarehouseDisabled)
.waitToClick(selectors.itemBasicData.basicDataButton) .waitToClick(selectors.itemBasicData.basicDataButton)
.waitForTextInInput(selectors.itemBasicData.nameInput, 'Rose of Purity')
.getInputValue(selectors.itemBasicData.nameInput) .getInputValue(selectors.itemBasicData.nameInput)
.then(result => { .then(result => {
expect(result).toEqual('Rose of Purity'); expect(result).toEqual('Rose of Purity');

View File

@ -61,7 +61,7 @@ describe('add item tax path', () => {
it(`should confirm the item tax class was edited`, () => { it(`should confirm the item tax class was edited`, () => {
return nightmare return nightmare
.click(selectors.itemTags.tagsButton) .click(selectors.itemTags.tagsButton)
.wait(selectors.itemTags.firstTagSelect) .wait(selectors.itemTags.firstTagDisabled)
.waitToClick(selectors.itemTax.taxButton) .waitToClick(selectors.itemTax.taxButton)
.waitForTextInInput(selectors.itemTax.firstClassSelect, 'general') .waitForTextInInput(selectors.itemTax.firstClassSelect, 'general')
.getInputValue(selectors.itemTax.firstClassSelect) .getInputValue(selectors.itemTax.firstClassSelect)

View File

@ -43,22 +43,14 @@ describe('create item tags path', () => {
}); });
}); });
it(`should create a new tag, edit another and delete a former one`, () => { it(`should create a new tag and delete a former one`, () => {
return nightmare return nightmare
.waitToClick(selectors.itemTags.firstTagSelect) .waitToClick(selectors.itemTags.firstRemoveTagButton)
.waitToClick(selectors.itemTags.firstTagSelectOptionOne)
.clearInput(selectors.itemTags.firstValueInput)
.type(selectors.itemTags.firstValueInput, 'Dark Blue')
.clearInput(selectors.itemTags.firstRelevancyInput)
.type(selectors.itemTags.firstRelevancyInput, '2')
.waitToClick(selectors.itemTags.fifthRemoveTagButton)
.waitToClick(selectors.itemTags.addItemTagButton) .waitToClick(selectors.itemTags.addItemTagButton)
.waitToClick(selectors.itemTags.fifthTagSelect) .waitToClick(selectors.itemTags.fifthTagSelect)
.waitToClick(selectors.itemTags.fifthTagSelectOptionFive) .waitToClick(selectors.itemTags.fifthTagSelectOptionFive)
.type(selectors.itemTags.fifthValueInput, 'Thanos') .type(selectors.itemTags.fifthValueInput, 'Thanos')
.type(selectors.itemTags.fifthRelevancyInput, '1') .type(selectors.itemTags.fifthRelevancyInput, '1')
.clearInput(selectors.itemTags.secondRelevancyInput)
.type(selectors.itemTags.secondRelevancyInput, '5')
.click(selectors.itemTags.submitItemTagsButton) .click(selectors.itemTags.submitItemTagsButton)
.waitForSnackbar() .waitForSnackbar()
.then(result => { .then(result => {
@ -71,8 +63,8 @@ describe('create item tags path', () => {
.click(selectors.itemBasicData.basicDataButton) .click(selectors.itemBasicData.basicDataButton)
.wait(selectors.itemBasicData.nameInput) .wait(selectors.itemBasicData.nameInput)
.click(selectors.itemTags.tagsButton) .click(selectors.itemTags.tagsButton)
.waitForTextInInput(selectors.itemTags.firstTagSelect, 'Owner') .waitForTextInInput(selectors.itemTags.firstTagDisabled, 'Owner')
.getInputValue(selectors.itemTags.firstTagSelect) .getInputValue(selectors.itemTags.firstTagDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Owner'); expect(result).toEqual('Owner');
}); });
@ -98,19 +90,19 @@ describe('create item tags path', () => {
it(`should confirm the second select is the expected one`, () => { it(`should confirm the second select is the expected one`, () => {
return nightmare return nightmare
.waitForTextInInput(selectors.itemTags.secondTagSelect, 'Color') .waitForTextInInput(selectors.itemTags.secondTagDisabled, 'Location')
.getInputValue(selectors.itemTags.secondTagSelect) .getInputValue(selectors.itemTags.secondTagDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Color'); expect(result).toEqual('Location');
}); });
}); });
it(`should confirm the second value is the expected one`, () => { it(`should confirm the second value is the expected one`, () => {
return nightmare return nightmare
.waitForTextInInput(selectors.itemTags.secondValueInput, 'Dark Blue') .waitForTextInInput(selectors.itemTags.secondValueInput, 'Gamoras hideout')
.getInputValue(selectors.itemTags.secondValueInput) .getInputValue(selectors.itemTags.secondValueInput)
.then(result => { .then(result => {
expect(result).toEqual('Dark Blue'); expect(result).toEqual('Gamoras hideout');
}); });
}); });
@ -125,8 +117,8 @@ describe('create item tags path', () => {
it(`should confirm the third select is the expected one`, () => { it(`should confirm the third select is the expected one`, () => {
return nightmare return nightmare
.waitForTextInInput(selectors.itemTags.thirdTagSelect, 'Shape') .waitForTextInInput(selectors.itemTags.thirdTagDisabled, 'Shape')
.getInputValue(selectors.itemTags.thirdTagSelect) .getInputValue(selectors.itemTags.thirdTagDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Shape'); expect(result).toEqual('Shape');
}); });
@ -152,8 +144,8 @@ describe('create item tags path', () => {
it(`should confirm the fourth select is the expected one`, () => { it(`should confirm the fourth select is the expected one`, () => {
return nightmare return nightmare
.waitForTextInInput(selectors.itemTags.fourthTagSelect, 'Power') .waitForTextInInput(selectors.itemTags.fourthTagDisabled, 'Power')
.getInputValue(selectors.itemTags.fourthTagSelect) .getInputValue(selectors.itemTags.fourthTagDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Power'); expect(result).toEqual('Power');
}); });
@ -179,19 +171,19 @@ describe('create item tags path', () => {
it(`should confirm the fifth select is the expected one`, () => { it(`should confirm the fifth select is the expected one`, () => {
return nightmare return nightmare
.waitForTextInInput(selectors.itemTags.fifthTagSelect, 'Location') .waitForTextInInput(selectors.itemTags.fifthTagDisabled, 'Color')
.getInputValue(selectors.itemTags.fifthTagSelect) .getInputValue(selectors.itemTags.fifthTagDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Location'); expect(result).toEqual('Color');
}); });
}); });
it(`should confirm the fifth value is the expected one`, () => { it(`should confirm the fifth value is the expected one`, () => {
return nightmare return nightmare
.waitForTextInInput(selectors.itemTags.fifthValueInput, 'Gamoras hideout') .waitForTextInInput(selectors.itemTags.fifthValueInput, 'Yellow')
.getInputValue(selectors.itemTags.fifthValueInput) .getInputValue(selectors.itemTags.fifthValueInput)
.then(result => { .then(result => {
expect(result).toEqual('Gamoras hideout'); expect(result).toEqual('Yellow');
}); });
}); });

View File

@ -43,13 +43,9 @@ describe('create item niche path', () => {
}); });
}); });
it(`should click create a new niche, edit another and delete a former one`, () => { it(`should click create a new niche and delete a former one`, () => {
return nightmare return nightmare
.waitToClick(selectors.itemNiches.addNicheButton) .waitToClick(selectors.itemNiches.addNicheButton)
.waitToClick(selectors.itemNiches.firstWarehouseSelect)
.waitToClick(selectors.itemNiches.firstWarehouseSelectSecondOption)
.clearInput(selectors.itemNiches.firstCodeInput)
.type(selectors.itemNiches.firstCodeInput, 'A2')
.waitToClick(selectors.itemNiches.secondNicheRemoveButton) .waitToClick(selectors.itemNiches.secondNicheRemoveButton)
.waitToClick(selectors.itemNiches.thirdWarehouseSelect) .waitToClick(selectors.itemNiches.thirdWarehouseSelect)
.waitToClick(selectors.itemNiches.thirdWarehouseSelectFourthOption) .waitToClick(selectors.itemNiches.thirdWarehouseSelectFourthOption)
@ -66,21 +62,21 @@ describe('create item niche path', () => {
.click(selectors.itemBasicData.basicDataButton) .click(selectors.itemBasicData.basicDataButton)
.wait(selectors.itemBasicData.nameInput) .wait(selectors.itemBasicData.nameInput)
.click(selectors.itemNiches.nicheButton) .click(selectors.itemNiches.nicheButton)
.waitForTextInInput(selectors.itemNiches.firstWarehouseSelect, 'Warehouse Two') .waitForTextInInput(selectors.itemNiches.firstWarehouseDisabled, 'Warehouse One')
.getInputValue(selectors.itemNiches.firstWarehouseSelect) .getInputValue(selectors.itemNiches.firstWarehouseDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Warehouse Two'); expect(result).toEqual('Warehouse One');
return nightmare return nightmare
.getInputValue(selectors.itemNiches.firstCodeInput); .getInputValue(selectors.itemNiches.firstCodeInput);
}) })
.then(result => { .then(result => {
expect(result).toEqual('A2'); expect(result).toEqual('A1');
}); });
}); });
it(`should confirm the second niche is the expected one`, () => { it(`should confirm the second niche is the expected one`, () => {
return nightmare return nightmare
.getInputValue(selectors.itemNiches.secondWarehouseSelect) .getInputValue(selectors.itemNiches.secondWarehouseDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Warehouse Three'); expect(result).toEqual('Warehouse Three');
return nightmare return nightmare
@ -93,7 +89,7 @@ describe('create item niche path', () => {
it(`should confirm the third niche is the expected one`, () => { it(`should confirm the third niche is the expected one`, () => {
return nightmare return nightmare
.getInputValue(selectors.itemNiches.thirdWarehouseSelect) .getInputValue(selectors.itemNiches.thirdWarehouseDisabled)
.then(result => { .then(result => {
expect(result).toEqual('Warehouse Four'); expect(result).toEqual('Warehouse Four');
return nightmare return nightmare

View File

@ -0,0 +1,77 @@
import selectors from '../../helpers/selectors.js';
import createNightmare from '../../helpers/helpers';
describe('create item niche path', () => {
const nightmare = createNightmare();
beforeAll(() => {
return nightmare
.waitForLogin('developer');
});
it('should access to the tickets index by clicking the tickets button', () => {
return nightmare
.click(selectors.moduleAccessView.ticketsSectionButton)
.wait(selectors.ticketsIndex.createTicketButton)
.parsedUrl()
.then(url => {
expect(url.hash).toEqual('#!/ticket/list');
});
});
it('should search for the ticket with id 1', () => {
return nightmare
.wait(selectors.ticketsIndex.searchTicketInput)
.type(selectors.ticketsIndex.searchTicketInput, '1')
.click(selectors.ticketsIndex.searchButton)
.waitForNumberOfElements(selectors.ticketsIndex.searchResult, 1)
.countSearchResults(selectors.ticketsIndex.searchResult)
.then(result => {
expect(result).toEqual(1);
});
});
it(`should click on the search result to access to the ticket notes`, () => {
return nightmare
.waitForTextInElement(selectors.ticketsIndex.searchResult, '1')
.waitToClick(selectors.ticketsIndex.searchResult)
.waitToClick(selectors.ticketNotes.notesButton)
.waitForURL('observations')
.url()
.then(url => {
expect(url).toContain('observations');
});
});
it(`should click create a new note and delete a former one`, () => {
return nightmare
.waitToClick(selectors.ticketNotes.firstNoteRemoveButton)
.waitToClick(selectors.ticketNotes.addNoteButton)
.waitToClick(selectors.ticketNotes.firstNoteSelect)
.waitForTextInElement(selectors.ticketNotes.firstNoteSelectSecondOption, 'observation two')
.waitToClick(selectors.ticketNotes.firstNoteSelectSecondOption)
.type(selectors.ticketNotes.firstDescriptionInput, 'description')
.click(selectors.ticketNotes.submitNotesButton)
.waitForSnackbar()
.then(result => {
expect(result).toContain('Data saved!');
});
});
it(`should confirm the note is the expected one`, () => {
return nightmare
.click(selectors.ticketPackages.packagesButton)
.wait(selectors.ticketPackages.firstPackageSelect)
.click(selectors.ticketNotes.notesButton)
.waitForTextInInput(selectors.ticketNotes.firstNoteDisabled, 'observation two')
.getInputValue(selectors.ticketNotes.firstNoteDisabled)
.then(result => {
expect(result).toEqual('observation two');
return nightmare
.getInputValue(selectors.ticketNotes.firstDescriptionInput);
})
.then(result => {
expect(result).toEqual('description');
});
});
});

View File

@ -0,0 +1,3 @@
module.exports = Self => {
Self.installCrudModel('crudTicketObservations');
};

View File

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

View File

@ -2,33 +2,34 @@
"name": "TicketObservation", "name": "TicketObservation",
"base": "VnModel", "base": "VnModel",
"options": { "options": {
"mysql": { "mysql": {
"table": "ticketObservation" "table": "ticketObservation",
} "database": "vn"
}
}, },
"properties": { "properties": {
"id": { "id": {
"id": true, "id": true,
"type": "Number", "type": "Number",
"description": "Identifier" "description": "Identifier"
}, },
"description": { "description": {
"type": "String", "type": "String",
"required": true "required": true
} }
}, },
"relations": { "relations": {
"ticket": { "ticket": {
"type": "belongsTo", "type": "belongsTo",
"model": "Ticket", "model": "Ticket",
"foreignKey": "ticketFk", "foreignKey": "ticketFk",
"required": true "required": true
}, },
"observationType": { "observationType": {
"type": "belongsTo", "type": "belongsTo",
"model": "ObservationType", "model": "ObservationType",
"foreignKey": "observationTypeFk", "foreignKey": "observationTypeFk",
"required": true "required": true
} }
} }
} }