Code linting, code clean

This commit is contained in:
Juan 2018-07-06 16:32:23 +02:00
parent 354c2a8369
commit 96d755cd21
14 changed files with 94 additions and 118 deletions

View File

@ -19,7 +19,7 @@ export default class CrudModel extends ModelProxy {
this.refresh();
}
refresh(usFilter, usData) {
refresh(usFilter) {
if (!this.url) return;
let myFilter = {
@ -47,9 +47,16 @@ export default class CrudModel extends ModelProxy {
sendRequest(filter, append) {
this.cancelRequest();
this.canceler = this.$q.defer();
let options = {timeout: this.canceler.promise};
let json = encodeURIComponent(JSON.stringify(filter));
return this.$http.get(`${this.url}?filter=${json}`, options).then(
let options = {
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.onRemoteError(json)
);
@ -118,7 +125,7 @@ export default class CrudModel extends ModelProxy {
return changes;
}
save(ignoreChanges) {
save() {
let changes = this.getChanges();
if (!changes)

View File

@ -105,14 +105,34 @@ export default class Controller extends Component {
}
pushFilterToState(filter) {
let history = window.history || {pushState: () => {
console.error('Error in history.pushState(): Browser incompatibility error');
}};
let aux = window.location.hash.split('?q=');
if (Object.keys(filter).length)
history.pushState({}, null, `${aux[0]}?q=${encodeURIComponent(JSON.stringify(filter))}`);
else
history.pushState({}, null, aux[0]);
let state = window.location.hash.split('?')[0];
let keys = Object.keys(filter);
if (keys.length) {
let hashFilter = {};
keys.forEach(key => {
let value = filter[key];
if (value instanceof Date)
hashFilter[key] = value;
else
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);
}
/**

View File

@ -1,6 +1,6 @@
<vn-crud-model
vn-id="model"
url="/item/api/Items"
url="/item/api/Items/filter"
filter="::$ctrl.filter"
limit="8"
data="items"

View File

@ -11,7 +11,8 @@ class Controller {
this.filter = {
include: [
{relation: 'itemType',
{
relation: 'itemType',
scope: {
fields: ['name', 'workerFk'],
include: {
@ -37,6 +38,9 @@ class Controller {
case 'id':
case 'typeFk':
return {[param]: value};
case 'tags':
this.$.model.userParams = {tags: value};
break;
}
}

View File

@ -8,12 +8,12 @@ class ItemProduct {
clone(event) {
event.preventDefault();
this.ItemList.cloneItem(this.item);
this.index.cloneItem(this.item);
}
preview(event) {
event.preventDefault();
this.ItemList.showItemPreview(this.item);
this.index.showItemPreview(this.item);
}
}
@ -24,6 +24,6 @@ ngModule.component('vnItemProduct', {
},
controller: ItemProduct,
require: {
ItemList: '^vnItemIndex'
index: '^vnItemIndex'
}
});

View File

@ -30,7 +30,6 @@
model="filter.description">
</vn-textfield>
</vn-horizontal>
<!--
<vn-horizontal ng-repeat="itemTag in filter.tags">
<vn-autocomplete
vn-id="tag"
@ -76,7 +75,6 @@
ng-click="filter.tags.push({})">
</vn-icon-button>
</vn-horizontal>
-->
<vn-horizontal margin-large-top>
<vn-submit label="Search"></vn-submit>
</vn-horizontal>

View File

@ -39,16 +39,16 @@
class="{{::$ctrl.compareDate(ticket.shipped)}} clickable"
ui-sref="ticket.card.summary({id: {{::ticket.id}}})">
<th number>{{::ticket.id}}</th>
<td >{{::ticket.client.salesPerson.name | dashIfEmpty}}</td>
<td >{{::ticket.shipped | date:'dd/MM/yyyy'}}</td>
<td >{{::ticket.shipped | date:'HH:MM'}}</td>
<td >{{::ticket.nickname}}</td>
<td >{{::ticket.address.province.name}}</td>
<td >{{::ticket.tracking.state.name}}</td>
<td >{{::ticket.agencyMode.name}}</td>
<td >{{::ticket.warehouse.name}}</td>
<td number >{{::ticket.refFk | dashIfEmpty}}</td>
<td number >{{::ticket.routeFk | dashIfEmpty}}</td>
<td>{{::ticket.client.salesPerson.name | dashIfEmpty}}</td>
<td>{{::ticket.shipped | date:'dd/MM/yyyy'}}</td>
<td>{{::ticket.shipped | date:'HH:MM'}}</td>
<td>{{::ticket.nickname}}</td>
<td>{{::ticket.address.province.name}}</td>
<td>{{::ticket.tracking.state.name}}</td>
<td>{{::ticket.agencyMode.name}}</td>
<td>{{::ticket.warehouse.name}}</td>
<td number>{{::ticket.refFk | dashIfEmpty}}</td>
<td number>{{::ticket.routeFk | dashIfEmpty}}</td>
<td>
<vn-icon-button
ng-click="$ctrl.preview($event, ticket)"

View File

@ -58,7 +58,7 @@ describe('Client', () => {
.waitToClick(selectors.clientPayMethod.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual(jasmine.arrayContaining(['requires an IBAN']));
expect(result).toEqual(jasmine.arrayContaining(['That payment method requires an IBAN']));
});
});

View File

@ -65,7 +65,7 @@ describe('Client', () => {
.waitToClick(selectors.clientAddresses.saveButton)
.waitForSnackbar()
.then(result => {
expect(result).toEqual(jasmine.arrayContaining(['type cannot be blank']));
expect(result).toEqual(jasmine.arrayContaining(['Observation type cannot be blank']));
});
});

View File

@ -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);
}));
};
};

View File

@ -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);
});
});

View File

@ -1,6 +1,4 @@
module.exports = Self => {
require('../methods/client-contact/crud')(Self);
Self.validatesPresenceOf('name', {
message: 'Name cannot be blank'
});

View File

@ -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);
};
};

View File

@ -1,6 +1,7 @@
let UserError = require('../helpers').UserError;
module.exports = Self => {
require('../methods/item/filter')(Self);
require('../methods/item/clone')(Self);
require('../methods/item/updateTaxes')(Self);
require('../methods/item/getDiary')(Self);