Code linting, code clean
This commit is contained in:
parent
354c2a8369
commit
96d755cd21
|
@ -19,7 +19,7 @@ export default class CrudModel extends ModelProxy {
|
||||||
this.refresh();
|
this.refresh();
|
||||||
}
|
}
|
||||||
|
|
||||||
refresh(usFilter, usData) {
|
refresh(usFilter) {
|
||||||
if (!this.url) return;
|
if (!this.url) return;
|
||||||
|
|
||||||
let myFilter = {
|
let myFilter = {
|
||||||
|
@ -47,9 +47,16 @@ export default class CrudModel extends ModelProxy {
|
||||||
sendRequest(filter, append) {
|
sendRequest(filter, append) {
|
||||||
this.cancelRequest();
|
this.cancelRequest();
|
||||||
this.canceler = this.$q.defer();
|
this.canceler = this.$q.defer();
|
||||||
let options = {timeout: this.canceler.promise};
|
|
||||||
let json = encodeURIComponent(JSON.stringify(filter));
|
let options = {
|
||||||
return this.$http.get(`${this.url}?filter=${json}`, options).then(
|
timeout: this.canceler.promise,
|
||||||
|
params: {filter: filter}
|
||||||
|
};
|
||||||
|
|
||||||
|
if (this.userParams instanceof Object)
|
||||||
|
Object.assign(options.params, this.userParams);
|
||||||
|
|
||||||
|
return this.$http.get(this.url, options).then(
|
||||||
json => this.onRemoteDone(json, filter, append),
|
json => this.onRemoteDone(json, filter, append),
|
||||||
json => this.onRemoteError(json)
|
json => this.onRemoteError(json)
|
||||||
);
|
);
|
||||||
|
@ -118,7 +125,7 @@ export default class CrudModel extends ModelProxy {
|
||||||
return changes;
|
return changes;
|
||||||
}
|
}
|
||||||
|
|
||||||
save(ignoreChanges) {
|
save() {
|
||||||
let changes = this.getChanges();
|
let changes = this.getChanges();
|
||||||
|
|
||||||
if (!changes)
|
if (!changes)
|
||||||
|
|
|
@ -105,14 +105,34 @@ export default class Controller extends Component {
|
||||||
}
|
}
|
||||||
|
|
||||||
pushFilterToState(filter) {
|
pushFilterToState(filter) {
|
||||||
let history = window.history || {pushState: () => {
|
let state = window.location.hash.split('?')[0];
|
||||||
console.error('Error in history.pushState(): Browser incompatibility error');
|
let keys = Object.keys(filter);
|
||||||
}};
|
|
||||||
let aux = window.location.hash.split('?q=');
|
if (keys.length) {
|
||||||
if (Object.keys(filter).length)
|
let hashFilter = {};
|
||||||
history.pushState({}, null, `${aux[0]}?q=${encodeURIComponent(JSON.stringify(filter))}`);
|
|
||||||
|
keys.forEach(key => {
|
||||||
|
let value = filter[key];
|
||||||
|
|
||||||
|
if (value instanceof Date)
|
||||||
|
hashFilter[key] = value;
|
||||||
else
|
else
|
||||||
history.pushState({}, null, aux[0]);
|
switch (typeof value) {
|
||||||
|
case 'number':
|
||||||
|
case 'string':
|
||||||
|
case 'boolean':
|
||||||
|
hashFilter[key] = value;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
let search = encodeURIComponent(JSON.stringify(hashFilter));
|
||||||
|
state += `?q=${search}`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!window.history)
|
||||||
|
throw new Error('Browser incompatibility: window.history not found');
|
||||||
|
|
||||||
|
window.history.pushState({}, null, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
<vn-crud-model
|
<vn-crud-model
|
||||||
vn-id="model"
|
vn-id="model"
|
||||||
url="/item/api/Items"
|
url="/item/api/Items/filter"
|
||||||
filter="::$ctrl.filter"
|
filter="::$ctrl.filter"
|
||||||
limit="8"
|
limit="8"
|
||||||
data="items"
|
data="items"
|
||||||
|
|
|
@ -11,7 +11,8 @@ class Controller {
|
||||||
|
|
||||||
this.filter = {
|
this.filter = {
|
||||||
include: [
|
include: [
|
||||||
{relation: 'itemType',
|
{
|
||||||
|
relation: 'itemType',
|
||||||
scope: {
|
scope: {
|
||||||
fields: ['name', 'workerFk'],
|
fields: ['name', 'workerFk'],
|
||||||
include: {
|
include: {
|
||||||
|
@ -37,6 +38,9 @@ class Controller {
|
||||||
case 'id':
|
case 'id':
|
||||||
case 'typeFk':
|
case 'typeFk':
|
||||||
return {[param]: value};
|
return {[param]: value};
|
||||||
|
case 'tags':
|
||||||
|
this.$.model.userParams = {tags: value};
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,12 +8,12 @@ class ItemProduct {
|
||||||
|
|
||||||
clone(event) {
|
clone(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.ItemList.cloneItem(this.item);
|
this.index.cloneItem(this.item);
|
||||||
}
|
}
|
||||||
|
|
||||||
preview(event) {
|
preview(event) {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
this.ItemList.showItemPreview(this.item);
|
this.index.showItemPreview(this.item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,6 +24,6 @@ ngModule.component('vnItemProduct', {
|
||||||
},
|
},
|
||||||
controller: ItemProduct,
|
controller: ItemProduct,
|
||||||
require: {
|
require: {
|
||||||
ItemList: '^vnItemIndex'
|
index: '^vnItemIndex'
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -30,7 +30,6 @@
|
||||||
model="filter.description">
|
model="filter.description">
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
<!--
|
|
||||||
<vn-horizontal ng-repeat="itemTag in filter.tags">
|
<vn-horizontal ng-repeat="itemTag in filter.tags">
|
||||||
<vn-autocomplete
|
<vn-autocomplete
|
||||||
vn-id="tag"
|
vn-id="tag"
|
||||||
|
@ -76,7 +75,6 @@
|
||||||
ng-click="filter.tags.push({})">
|
ng-click="filter.tags.push({})">
|
||||||
</vn-icon-button>
|
</vn-icon-button>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
-->
|
|
||||||
<vn-horizontal margin-large-top>
|
<vn-horizontal margin-large-top>
|
||||||
<vn-submit label="Search"></vn-submit>
|
<vn-submit label="Search"></vn-submit>
|
||||||
</vn-horizontal>
|
</vn-horizontal>
|
||||||
|
|
|
@ -39,16 +39,16 @@
|
||||||
class="{{::$ctrl.compareDate(ticket.shipped)}} clickable"
|
class="{{::$ctrl.compareDate(ticket.shipped)}} clickable"
|
||||||
ui-sref="ticket.card.summary({id: {{::ticket.id}}})">
|
ui-sref="ticket.card.summary({id: {{::ticket.id}}})">
|
||||||
<th number>{{::ticket.id}}</th>
|
<th number>{{::ticket.id}}</th>
|
||||||
<td >{{::ticket.client.salesPerson.name | dashIfEmpty}}</td>
|
<td>{{::ticket.client.salesPerson.name | dashIfEmpty}}</td>
|
||||||
<td >{{::ticket.shipped | date:'dd/MM/yyyy'}}</td>
|
<td>{{::ticket.shipped | date:'dd/MM/yyyy'}}</td>
|
||||||
<td >{{::ticket.shipped | date:'HH:MM'}}</td>
|
<td>{{::ticket.shipped | date:'HH:MM'}}</td>
|
||||||
<td >{{::ticket.nickname}}</td>
|
<td>{{::ticket.nickname}}</td>
|
||||||
<td >{{::ticket.address.province.name}}</td>
|
<td>{{::ticket.address.province.name}}</td>
|
||||||
<td >{{::ticket.tracking.state.name}}</td>
|
<td>{{::ticket.tracking.state.name}}</td>
|
||||||
<td >{{::ticket.agencyMode.name}}</td>
|
<td>{{::ticket.agencyMode.name}}</td>
|
||||||
<td >{{::ticket.warehouse.name}}</td>
|
<td>{{::ticket.warehouse.name}}</td>
|
||||||
<td number >{{::ticket.refFk | dashIfEmpty}}</td>
|
<td number>{{::ticket.refFk | dashIfEmpty}}</td>
|
||||||
<td number >{{::ticket.routeFk | dashIfEmpty}}</td>
|
<td number>{{::ticket.routeFk | dashIfEmpty}}</td>
|
||||||
<td>
|
<td>
|
||||||
<vn-icon-button
|
<vn-icon-button
|
||||||
ng-click="$ctrl.preview($event, ticket)"
|
ng-click="$ctrl.preview($event, ticket)"
|
||||||
|
|
|
@ -58,7 +58,7 @@ describe('Client', () => {
|
||||||
.waitToClick(selectors.clientPayMethod.saveButton)
|
.waitToClick(selectors.clientPayMethod.saveButton)
|
||||||
.waitForSnackbar()
|
.waitForSnackbar()
|
||||||
.then(result => {
|
.then(result => {
|
||||||
expect(result).toEqual(jasmine.arrayContaining(['requires an IBAN']));
|
expect(result).toEqual(jasmine.arrayContaining(['That payment method requires an IBAN']));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -65,7 +65,7 @@ describe('Client', () => {
|
||||||
.waitToClick(selectors.clientAddresses.saveButton)
|
.waitToClick(selectors.clientAddresses.saveButton)
|
||||||
.waitForSnackbar()
|
.waitForSnackbar()
|
||||||
.then(result => {
|
.then(result => {
|
||||||
expect(result).toEqual(jasmine.arrayContaining(['type cannot be blank']));
|
expect(result).toEqual(jasmine.arrayContaining(['Observation type cannot be blank']));
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,32 +0,0 @@
|
||||||
module.exports = Self => {
|
|
||||||
Self.remoteMethod('crud', {
|
|
||||||
description: 'Client contact crud',
|
|
||||||
accepts: [{
|
|
||||||
arg: 'data',
|
|
||||||
type: 'object',
|
|
||||||
http: {source: 'body'}
|
|
||||||
}],
|
|
||||||
returns: {
|
|
||||||
root: true,
|
|
||||||
type: 'boolean'
|
|
||||||
},
|
|
||||||
http: {
|
|
||||||
verb: 'post',
|
|
||||||
path: '/crud'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
Self.crud = async data => {
|
|
||||||
let models = Self.app.models;
|
|
||||||
|
|
||||||
await Promise.all(data.delete.map(contactId => {
|
|
||||||
return models.ClientContact.destroyById(contactId);
|
|
||||||
}));
|
|
||||||
|
|
||||||
let upsert = data.update.concat(data.create);
|
|
||||||
|
|
||||||
await Promise.all(upsert.map(contact => {
|
|
||||||
return models.ClientContact.upsert(contact);
|
|
||||||
}));
|
|
||||||
};
|
|
||||||
};
|
|
|
@ -1,52 +0,0 @@
|
||||||
const app = require(`${servicesDir}/client/server/server`);
|
|
||||||
|
|
||||||
describe('Client crud', () => {
|
|
||||||
afterAll(async() => {
|
|
||||||
await app.models.ClientContact.destroyById(4113);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should perfom a query to create new contacts', async() => {
|
|
||||||
let data = {
|
|
||||||
delete: [],
|
|
||||||
create: [
|
|
||||||
{id: 4113, clientFk: 101, name: 'My contact', phone: '111111111'}
|
|
||||||
],
|
|
||||||
update: []
|
|
||||||
};
|
|
||||||
|
|
||||||
await app.models.ClientContact.crud(data);
|
|
||||||
let contacts = await app.models.ClientContact.find();
|
|
||||||
|
|
||||||
expect(contacts.length).toEqual(5);
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should perfom a query to update contacts', async() => {
|
|
||||||
let data = {
|
|
||||||
delete: [],
|
|
||||||
create: [],
|
|
||||||
update: [
|
|
||||||
{id: 4113, name: 'My contact 2 updated', phone: '222222222'}
|
|
||||||
]
|
|
||||||
};
|
|
||||||
|
|
||||||
await app.models.ClientContact.crud(data);
|
|
||||||
let contacts = await app.models.ClientContact.findById(4113);
|
|
||||||
|
|
||||||
expect(contacts.name).toEqual('My contact 2 updated');
|
|
||||||
expect(contacts.phone).toEqual('222222222');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should perfom a query to delete contacts', async() => {
|
|
||||||
let data = {
|
|
||||||
delete: [4113],
|
|
||||||
create: [],
|
|
||||||
update: []
|
|
||||||
};
|
|
||||||
|
|
||||||
await app.models.ClientContact.crud(data);
|
|
||||||
|
|
||||||
let contacts = await app.models.ClientContact.find();
|
|
||||||
|
|
||||||
expect(contacts.length).toEqual(4);
|
|
||||||
});
|
|
||||||
});
|
|
|
@ -1,6 +1,4 @@
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
require('../methods/client-contact/crud')(Self);
|
|
||||||
|
|
||||||
Self.validatesPresenceOf('name', {
|
Self.validatesPresenceOf('name', {
|
||||||
message: 'Name cannot be blank'
|
message: 'Name cannot be blank'
|
||||||
});
|
});
|
||||||
|
|
|
@ -0,0 +1,32 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethod('filter', {
|
||||||
|
description: 'Find all instances of the model matched by filter from the data source.',
|
||||||
|
accessType: 'READ',
|
||||||
|
accepts: [
|
||||||
|
{
|
||||||
|
arg: 'filter',
|
||||||
|
type: 'Object',
|
||||||
|
description: 'Filter defining fields, where, include, order, offset, and limit - must be a JSON-encoded string ({"something":"value"})',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}, {
|
||||||
|
arg: 'tags',
|
||||||
|
type: ['Object'],
|
||||||
|
description: 'List of tags to filter with',
|
||||||
|
http: {source: 'query'}
|
||||||
|
}
|
||||||
|
],
|
||||||
|
returns: {
|
||||||
|
type: ['Object'],
|
||||||
|
root: true
|
||||||
|
},
|
||||||
|
http: {
|
||||||
|
path: `/filter`,
|
||||||
|
verb: 'GET'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.filter = async(filter, tags) => {
|
||||||
|
console.log(tags);
|
||||||
|
return await Self.find(filter);
|
||||||
|
};
|
||||||
|
};
|
|
@ -1,6 +1,7 @@
|
||||||
let UserError = require('../helpers').UserError;
|
let UserError = require('../helpers').UserError;
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
|
require('../methods/item/filter')(Self);
|
||||||
require('../methods/item/clone')(Self);
|
require('../methods/item/clone')(Self);
|
||||||
require('../methods/item/updateTaxes')(Self);
|
require('../methods/item/updateTaxes')(Self);
|
||||||
require('../methods/item/getDiary')(Self);
|
require('../methods/item/getDiary')(Self);
|
||||||
|
|
Loading…
Reference in New Issue