#1222 Activar log en el modulo ítem
gitea/salix/dev This commit looks good Details

This commit is contained in:
Gerard 2019-03-12 11:47:53 +01:00
parent df48041444
commit fb75ff0eae
15 changed files with 141 additions and 89 deletions

View File

@ -0,0 +1,4 @@
USE `vn`;
ALTER TABLE vn.itemLog MODIFY COLUMN userFk int(10) unsigned NULL;
ALTER TABLE vn.itemLog MODIFY COLUMN id int(11) NOT NULL AUTO_INCREMENT;

View File

@ -4,7 +4,12 @@ describe('item new()', () => {
let item; let item;
afterAll(async done => { afterAll(async done => {
await app.models.Item.destroyById(item.id); let sql = 'DELETE FROM vn.itemLog WHERE originFk = ?';
await app.models.Item.rawSql(sql, [item.id]);
sql = 'DELETE FROM vn.item WHERE id = ?';
await app.models.Item.rawSql(sql, [item.id]);
done(); done();
}); });

View File

@ -27,7 +27,7 @@ module.exports = Self => {
if (!tax.taxClassFk) if (!tax.taxClassFk)
throw new UserError('Tax class cannot be blank'); throw new UserError('Tax class cannot be blank');
promises.push(Self.app.models.ItemTaxCountry.updateAll( promises.push(Self.app.models.ItemTaxCountry.update(
{id: tax.id}, {id: tax.id},
{taxClassFk: tax.taxClassFk} {taxClassFk: tax.taxClassFk}
)); ));

View File

@ -1,6 +1,11 @@
{ {
"name": "ItemBarcode", "name": "ItemBarcode",
"base": "VnModel", "base": "Loggable",
"log": {
"model": "ItemLog",
"relation": "item",
"changedModelValue": "code"
},
"options": { "options": {
"mysql": { "mysql": {
"table": "itemBarcode" "table": "itemBarcode"

View File

@ -1,6 +1,11 @@
{ {
"name": "ItemBotanical", "name": "ItemBotanical",
"base": "VnModel", "base": "Loggable",
"log": {
"model": "ItemLog",
"relation": "item",
"changedModelValue": "botanical"
},
"options": { "options": {
"mysql": { "mysql": {
"table": "itemBotanical" "table": "itemBotanical"

View File

@ -8,38 +8,48 @@
}, },
"properties": { "properties": {
"id": { "id": {
"type": "Number",
"id": true, "id": true,
"description": "Identifier" "type": "Number",
"forceId": false
},
"originFk": {
"type": "Number",
"required": true
},
"userFk": {
"type": "Number"
},
"action": {
"type": "String",
"required": true
},
"changedModel": {
"type": "String"
},
"oldInstance": {
"type": "Object"
},
"newInstance": {
"type": "Object"
}, },
"creationDate": { "creationDate": {
"type": "Date" "type": "Date"
}, },
"description": { "changedModelId": {
"type": "Number"
},
"changedModelValue": {
"type": "String" "type": "String"
}, },
"action": { "description": {
"type": "String" "type": "String"
} }
}, },
"relations": { "relations": {
"item": {
"type": "belongsTo",
"model": "Item",
"foreignKey": "originFk"
},
"user": { "user": {
"type": "belongsTo", "type": "belongsTo",
"model": "Account", "model": "Account",
"foreignKey": "userFk" "foreignKey": "userFk"
} }
},
"acls": [
{
"accessType": "READ",
"principalType": "ROLE",
"principalId": "$everyone",
"permission": "ALLOW"
} }
]
} }

View File

@ -1,6 +1,11 @@
{ {
"name": "ItemNiche", "name": "ItemNiche",
"base": "VnModel", "base": "Loggable",
"log": {
"model": "ItemLog",
"relation": "item",
"changedModelValue": "code"
},
"options": { "options": {
"mysql": { "mysql": {
"table": "itemPlacement" "table": "itemPlacement"

View File

@ -1,6 +1,11 @@
{ {
"name": "ItemTag", "name": "ItemTag",
"base": "VnModel", "base": "Loggable",
"log": {
"model": "ItemLog",
"relation": "item",
"changedModelValue": "value"
},
"options": { "options": {
"mysql": { "mysql": {
"table": "itemTag" "table": "itemTag"

View File

@ -1,6 +1,9 @@
{ {
"name": "Item", "name": "Item",
"base": "VnModel", "base": "Loggable",
"log": {
"model":"ItemLog"
},
"options": { "options": {
"mysql": { "mysql": {
"table": "item" "table": "item"

View File

@ -1,33 +0,0 @@
<vn-crud-model
vn-id="model"
url="/item/api/ItemLogs"
filter="::$ctrl.filter"
link="{originFk: $ctrl.$stateParams.id}"
limit="20"
data="logs" auto-load="false">
</vn-crud-model>
<vn-vertical>
<vn-card pad-large>
<vn-vertical>
<vn-table model="model">
<vn-thead>
<vn-tr>
<vn-th field="description">Description</vn-th>
<vn-th field="action">Action</vn-th>
<vn-th field="userFk">Changed by</vn-th>
<vn-th field="creationDate" default-order="DESC">Date</vn-th>
</vn-tr>
</vn-thead>
<vn-tbody>
<vn-tr ng-repeat="itemLog in logs">
<vn-td>{{::itemLog.description}}</vn-td>
<vn-td>{{::itemLog.action}}</vn-td>
<vn-td>{{::itemLog.user.name}}</vn-td>
<vn-td>{{::itemLog.creationDate | dateTime:'dd/MM/yyyy HH:mm'}}</vn-td>
</vn-tr>
</vn-tbody>
</vn-table>
</vn-vertical>
<vn-pagination model="model"></vn-pagination>
</vn-card>
</vn-vertical>

View File

@ -1,25 +0,0 @@
import ngModule from '../module';
class Controller {
constructor($stateParams) {
this.$stateParams = $stateParams;
this.filter = {
include: [{
relation: "item"
},
{
relation: "user",
scope: {
fields: ["name"]
}
}]
};
}
}
Controller.$inject = ['$stateParams'];
ngModule.component('vnItemHistory', {
template: require('./index.html'),
controller: Controller
});

View File

@ -11,7 +11,7 @@ import './data';
import './fetched-tags'; import './fetched-tags';
import './tags'; import './tags';
import './tax'; import './tax';
// import './history'; import './log';
import './last-entries'; import './last-entries';
import './niche'; import './niche';
import './botanical'; import './botanical';

View File

@ -0,0 +1,9 @@
<vn-crud-model
vn-id="model"
url="/api/ItemLogs"
link="{originFk: $ctrl.$stateParams.id}"
filter="$ctrl.filter"
limit="20"
data="$ctrl.logs" auto-load="false">
</vn-crud-model>
<vn-log model="model"></vn-log>

View File

@ -0,0 +1,53 @@
import ngModule from '../module';
class Controller {
constructor($scope, $stateParams) {
this.$scope = $scope;
this.$stateParams = $stateParams;
this.filter = {
include: [{
relation: 'user',
scope: {
fields: ['name'],
},
}],
};
}
get logs() {
return this._logs;
}
set logs(value) {
this._logs = value;
if (this.logs) {
this.logs.forEach(log => {
log.oldProperties = this.getInstance(log.oldInstance);
log.newProperties = this.getInstance(log.newInstance);
});
}
}
getInstance(instance) {
let validDate = /^(-?(?:[1-9][0-9]*)?[0-9]{4})-(1[0-2]|0[1-9])-(3[01]|0[1-9]|[12][0-9])T(2[0-3]|[01][0-9]):([0-5][0-9]):([0-5][0-9])(.[0-9]+)?(Z)?$/;
const properties = [];
if (typeof instance == 'object' && instance != null) {
Object.keys(instance).forEach(property => {
if (validDate.test(instance[property]))
instance[property] = new Date(instance[property]).toLocaleString('es-ES');
properties.push({key: property, value: instance[property]});
});
return properties;
}
return null;
}
}
Controller.$inject = ['$scope', '$stateParams'];
ngModule.component('vnItemLog', {
template: require('./index.html'),
controller: Controller,
});

View File

@ -12,7 +12,8 @@
{"state": "item.card.botanical", "icon": "local_florist"}, {"state": "item.card.botanical", "icon": "local_florist"},
{"state": "item.card.itemBarcode", "icon": "icon-barcode"}, {"state": "item.card.itemBarcode", "icon": "icon-barcode"},
{"state": "item.card.diary", "icon": "icon-transaction"}, {"state": "item.card.diary", "icon": "icon-transaction"},
{"state": "item.card.last-entries", "icon": "icon-regentry"} {"state": "item.card.last-entries", "icon": "icon-regentry"},
{"state": "item.card.log", "icon": "history"}
], ],
"keybindings": [ "keybindings": [
{"key": "a", "state": "item.index"} {"key": "a", "state": "item.index"}
@ -116,6 +117,11 @@
"item": "$ctrl.item" "item": "$ctrl.item"
}, },
"acl": ["employee"] "acl": ["employee"]
}, {
"url" : "/log",
"state": "item.card.log",
"component": "vn-item-log",
"description": "Log"
} }
] ]
} }