Merge branch 'dev' of https://git.verdnatura.es/salix into dev

This commit is contained in:
Juan 2018-10-30 16:03:53 +01:00
commit 31b86fce6d
10 changed files with 264 additions and 29 deletions

View File

@ -133,6 +133,8 @@ export default class ArrayModel extends ModelProxy {
if (this.getChanges())
this.orgData = this.data;
super.save();
return this.$q.resolve();
}
@ -152,7 +154,7 @@ export default class ArrayModel extends ModelProxy {
let aType = typeof a;
if (aType === typeof b) {
if (aType === typeof b)
switch (aType) {
case 'string':
return a.localeCompare(b);
@ -164,7 +166,6 @@ export default class ArrayModel extends ModelProxy {
if (a instanceof Date && b instanceof Date)
return a.getTime() - b.getTime();
}
}
if (a === undefined)
return -1;
@ -182,12 +183,11 @@ export default class ArrayModel extends ModelProxy {
let mergedWhere = [];
let wheres = [dst.where, src.where];
for (let where of wheres) {
for (let where of wheres)
if (Array.isArray(where))
mergedWhere = mergedWhere.concat(where);
else if (where)
mergedWhere.push(where);
}
switch (mergedWhere.length) {
case 0:
@ -220,6 +220,7 @@ ngModule.component('vnArrayModel', {
link: '<?',
order: '@?',
limit: '<?',
autoLoad: '<?'
autoLoad: '<?',
autoSave: '<?'
}
});

View File

@ -144,7 +144,7 @@ export default class CrudModel extends ModelProxy {
for (let row of this.removed)
remove.push(row.$orgRow[pk]);
for (let row of this._data) {
for (let row of this._data)
if (row.$isNew) {
let data = {};
for (let prop in row)
@ -160,7 +160,6 @@ export default class CrudModel extends ModelProxy {
where: {[pk]: row.$orgRow[pk]}
});
}
}
let changes = {
create: create,
@ -184,7 +183,10 @@ export default class CrudModel extends ModelProxy {
let url = this.saveUrl ? this.saveUrl : `${this._url}/crud`;
return this.$http.post(url, changes)
.then(() => this.applyChanges());
.then(() => {
this.applyChanges();
super.save();
});
}
buildParams() {
@ -220,9 +222,9 @@ export default class CrudModel extends ModelProxy {
onRemoteDone(json, filter, append) {
let data = json.data;
if (append) {
if (append)
this.orgData = this.orgData.concat(data);
} else {
else {
this.orgData = data;
this.currentFilter = filter;
}
@ -267,6 +269,7 @@ ngModule.component('vnCrudModel', {
userFilter: '<?',
userParams: '<?',
primaryKey: '@?',
autoLoad: '<?'
autoLoad: '<?',
autoSave: '<?'
}
});

View File

@ -11,7 +11,9 @@ export class DataModel extends Component {
/**
* @type {Array<Object>} A JavaScript array with the model data.
*/
get data() {}
get data() {
return null;
}
/**
* Refresh the model data.
@ -43,11 +45,13 @@ ngModule.component('vnDataModel', {
* It internally uses the JavaScript Proxy to track changes
* made in model rows.
*
* @property {Boolean} autoSave Whether to save data automatically when model is modified
* @event dataChange Emitted when data property changes
* @event dataUpdate Emitted when data property changes
* @event rowInsert Emitted when new row is inserted
* @event rowRemove Emitted when row is removed
* @event rowChange Emitted when row property is changed
* @event save Emitted when data is saved
*/
export default class ModelProxy extends DataModel {
constructor($element, $scope) {
@ -107,6 +111,8 @@ export default class ModelProxy extends DataModel {
this.isChanged = true;
this.emit('rowRemove', index);
this.emit('dataUpdate');
if (this.autoSave)
this.save();
}
/**
@ -139,16 +145,25 @@ export default class ModelProxy extends DataModel {
});
return new Proxy(obj, {
set: (obj, prop, value) => {
if (prop.charAt(0) !== '$' && value !== obj[prop] && !obj.$isNew) {
let changed = prop.charAt(0) !== '$' && value !== obj[prop] && !obj.$isNew;
if (changed) {
if (!obj.$oldData)
obj.$oldData = {};
if (!obj.$oldData[prop])
obj.$oldData[prop] = value;
this.isChanged = true;
}
let ret = Reflect.set(obj, prop, value);
if (changed) {
this.emit('rowChange', {obj, prop, value});
this.emit('dataUpdate');
if (this.autoSave)
this.save();
}
return Reflect.set(obj, prop, value);
return ret;
}
});
}
@ -171,7 +186,7 @@ export default class ModelProxy extends DataModel {
let orgData = this.orgData;
if (!data) return;
for (let row of data) {
for (let row of data)
if (row.$isNew) {
let orgRow = {};
for (let prop in row)
@ -183,7 +198,6 @@ export default class ModelProxy extends DataModel {
} else if (row.$oldData)
for (let prop in row.$oldData)
row.$orgRow[prop] = row[prop];
}
let removed = this.removed;
@ -197,6 +211,13 @@ export default class ModelProxy extends DataModel {
this.resetChanges();
}
/**
* Should be implemented by child classes.
*/
save() {
this.emit('save');
}
/**
* Undoes all changes made to the model data.
*/
@ -290,12 +311,16 @@ export class Paginable {
/**
* @type {Boolean} Whether the model is loading.
*/
get isLoading() {}
get isLoading() {
return false;
}
/**
* @type {Boolean} Whether the data is paginated and there are more rows to load.
*/
get moreRows() {}
get moreRows() {
return false;
}
/**
* When limit is enabled, loads the next set of rows.

View File

@ -212,6 +212,24 @@
"menu": {
"icon": "image"
}
},
{
"url" : "/log",
"state": "ticket.card.log",
"component": "vn-ticket-log",
"description": "Log",
"menu": {
"icon": "history"
}
},
{
"url" : "/weekly",
"state": "ticket.weekly",
"component": "vn-ticket-weekly",
"description": "Weekly",
"menu": {
"icon": "history"
}
}
]
}

View File

@ -20,3 +20,5 @@ import './sale-checked';
import './component';
import './sale-tracking';
import './picture';
// import './log';
import './weekly';

View File

@ -0,0 +1,84 @@
<vn-crud-model
vn-id="model"
url="/ticket/api/TicketWeeklies"
filter="::$ctrl.filter"
limit="20"
data="weeklies"
primary-key="ticketFk"
auto-save="true"
on-save="$ctrl.onSave()">
</vn-crud-model>
<vn-watcher
vn-id="watcher"
data="weeklies"
form="form">
</vn-watcher>
<form name="form">
<div margin-medium>
<vn-card margin-medium-v pad-medium>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th number field="ticketFk">Ticket ID</vn-th>
<vn-th field="weekDay">Client</vn-th>
<vn-th>Turn</vn-th>
<vn-th>Warehouse</vn-th>
<vn-th>Salesperson</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="weekly in weeklies" class="clickable">
<vn-td number>
<span class="link"
ng-click="$ctrl.showTicketDescriptor($event, weekly.ticketFk)">
{{weekly.ticketFk}}
</span>
</vn-td>
<vn-td>
<span class="link" ng-click="$ctrl.showClientDescriptor($event, weekly.ticket.client.id)">
{{::weekly.ticket.client.name}}
</span>
</vn-td>
<vn-td>
<vn-autocomplete
vn-one
field="weekly.weekDay"
data="$ctrl.weekdays"
show-field="name"
translate-fields="['name']"
value-field="id"
order="id">
</vn-autocomplete>
</vn-td>
<vn-td>{{::weekly.ticket.warehouse.name}}</vn-td>
<vn-td>{{::weekly.ticket.client.salesPerson.firstName}} {{::weekly.ticket.client.salesPerson.name}}</vn-td>
<vn-td>
<vn-icon-button
icon="delete"
ng-click="model.remove($index)"
vn-tooltip="Delete">
</vn-icon-button>
</vn-td>
</vn-tr>
</vn-tbody>
<vn-empty-rows ng-if="model.data.length === 0" translate>
No results
</vn-empty-rows>
</vn-table>
</vn-card>
<vn-pagination
model="model"
scroll-selector="ui-view">
</vn-pagination>
</div>
</form>
<vn-client-descriptor-popover vn-id="clientDescriptor"></vn-client-descriptor-popover>
<vn-ticket-descriptor-popover
vn-id="ticketDescriptor">
</vn-ticket-descriptor-popover>
<vn-confirm
vn-id="deleteWeekly"
on-response="$ctrl.returnDialog(response)"
question="Delete weekly"
message="Are you sure you want to delete this weekly?">
</vn-confirm>

View File

@ -0,0 +1,83 @@
import ngModule from '../module';
import './style.scss';
export default class Controller {
constructor($scope) {
this.$scope = $scope;
this.ticketSelected = null;
this.filter = {
include: [
{relation: 'ticket',
scope: {
fields: ['id', 'clientFk', 'companyFk', 'warehouseFk'],
include: [
{relation: 'client',
scope: {
fields: ['salesPersonFk', 'name'],
include: {
relation: 'salesPerson',
fields: ['firstName', 'name']
}
}
},
{relation: 'warehouse'}
]
}
}
]
};
this.weekdays = [
{id: 0, name: 'Monday'},
{id: 1, name: 'Tuesday'},
{id: 2, name: 'Wednesday'},
{id: 3, name: 'Thursday'},
{id: 4, name: 'Friday'},
{id: 5, name: 'Saturday'},
{id: 6, name: 'Sunday'}
];
}
onSave() {
this.$scope.watcher.notifySaved();
}
showClientDescriptor(event, clientFk) {
this.$scope.clientDescriptor.clientFk = clientFk;
this.$scope.clientDescriptor.parent = event.target;
this.$scope.clientDescriptor.show();
event.preventDefault();
event.stopImmediatePropagation();
}
showTicketDescriptor(event, ticketFk) {
this.$scope.ticketDescriptor.ticketFk = ticketFk;
this.$scope.ticketDescriptor.parent = event.target;
this.$scope.ticketDescriptor.show();
event.preventDefault();
event.stopImmediatePropagation();
}
onDescriptorLoad() {
this.$scope.popover.relocate();
}
deleteWeekly(expedition) {
this.expeditionId = expedition.id;
this.$scope.deleteWeekly.show();
}
onSubmit() {
this.$scope.watcher.check();
this.$scope.model.save().then(() => {
this.$scope.watcher.notifySaved();
this.$scope.model.refresh();
});
}
}
Controller.$inject = ['$scope'];
ngModule.component('vnTicketWeekly', {
template: require('./index.html'),
controller: Controller
});

View File

@ -0,0 +1,2 @@
Turn: Turno
Ticket ID: ID Ticket

View File

@ -0,0 +1,17 @@
vn-ticket-weekly {
vn-card {
margin: auto;
max-width: 880px;
}
vn-autocomplete {
div.mdl-textfield {
padding: 0px !important;
}
label.mdl-textfield__label:after {
bottom: 0;
}
div.icons {
display: none !important;
}
}
}

View File

@ -2,24 +2,24 @@
"name": "TicketWeekly",
"base": "VnModel",
"options": {
"mysql": {
"table": "ticketWeekly"
}
"mysql": {
"table": "ticketWeekly"
}
},
"properties": {
"weekDay": {
"type": "Number"
},
"ticketFk": {
"id": true,
"type": "Number"
"id": true,
"type": "Number"
},
"weekDay": {
"type": "Number"
}
},
"relations": {
"ticket": {
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketFk"
"type": "belongsTo",
"model": "Ticket",
"foreignKey": "ticketFk"
}
}
}