Merge branch 'dev' of https://git.verdnatura.es/salix into dev
This commit is contained in:
commit
4cf74664d5
|
@ -75,12 +75,13 @@ class Controller {
|
|||
}
|
||||
|
||||
setClaimDestination(id, claimDestinationFk) {
|
||||
let params = {id: id, claimDestinationFk: claimDestinationFk};
|
||||
let query = `claim/api/ClaimEnds/`;
|
||||
this.$http.patch(query, params).then(() => {
|
||||
this.$.model.refresh();
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
});
|
||||
if (claimDestinationFk) {
|
||||
let params = {id: id, claimDestinationFk: claimDestinationFk};
|
||||
let query = `claim/api/ClaimEnds/`;
|
||||
this.$http.patch(query, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$translate.instant('Data saved!'));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
calculateTotals() {
|
||||
|
|
|
@ -1,11 +1,11 @@
|
|||
<vn-horizontal>
|
||||
<vn-one>{{::$ctrl.concept}}</vn-one>
|
||||
<vn-auto class="tags">
|
||||
<vn-two>
|
||||
<section
|
||||
class="inline-tag ellipsize" ng-class="{'empty': !fetchedTag.value}"
|
||||
ng-repeat="fetchedTag in $ctrl.tags track by $index"
|
||||
vn-tooltip="{{::fetchedTag.tag.name}}: {{::fetchedTag.value}}">
|
||||
{{::fetchedTag.value}}
|
||||
</section>
|
||||
</vn-auto>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
|
@ -1,4 +1,4 @@
|
|||
import ngModule from '../module';
|
||||
import ngModule from '../../module';
|
||||
import './style.scss';
|
||||
|
||||
ngModule.component('vnFetchedTags', {
|
|
@ -0,0 +1,58 @@
|
|||
@import "colors";
|
||||
|
||||
vn-fetched-tags {
|
||||
@media screen and (max-width: 1600px){
|
||||
& vn-horizontal {
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
|
||||
& > vn-one {
|
||||
padding: 0 0 0.2em 0;
|
||||
}
|
||||
|
||||
& > vn-two {
|
||||
text-align: center;
|
||||
margin: 0 auto
|
||||
}
|
||||
|
||||
.inline-tag {
|
||||
font-size: 0.7em;
|
||||
padding: 0.3em
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1200px){
|
||||
& vn-horizontal {
|
||||
.inline-tag {
|
||||
font-size: 0.6em;
|
||||
padding: 0.2em
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
& vn-one {
|
||||
padding-top: 0.2em
|
||||
}
|
||||
|
||||
& vn-two {
|
||||
white-space: nowrap
|
||||
}
|
||||
|
||||
& .inline-tag {
|
||||
background-color: $secondary-font-color;
|
||||
display: inline-block;
|
||||
color: $color-white;
|
||||
margin-right: 0.4em;
|
||||
text-align: center;
|
||||
font-size: 0.8em;
|
||||
height: 1.25em;
|
||||
padding: 0.4em;
|
||||
width: 5em
|
||||
}
|
||||
|
||||
& .inline-tag.empty {
|
||||
background-color: $main-bg
|
||||
}
|
||||
}
|
|
@ -41,3 +41,4 @@ import './input-range';
|
|||
import './chip';
|
||||
import './input-number';
|
||||
import './input-time';
|
||||
import './fetched-tags';
|
||||
|
|
|
@ -1,19 +1,13 @@
|
|||
describe('Directive bind', () => {
|
||||
let $scope;
|
||||
let element;
|
||||
let compile;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
beforeEach(ngModule('client'));
|
||||
|
||||
compile = _element => {
|
||||
inject(($compile, $rootScope, _$timeout_, _$httpBackend_) => {
|
||||
$scope = $rootScope.$new();
|
||||
element = angular.element(_element);
|
||||
_$httpBackend_.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({});
|
||||
$compile(element)($scope);
|
||||
$scope.$digest();
|
||||
compile = html => {
|
||||
inject(($compile, $rootScope) => {
|
||||
let $element = $compile(html)($rootScope);
|
||||
$rootScope.$digest();
|
||||
$element.remove();
|
||||
});
|
||||
};
|
||||
|
||||
|
|
|
@ -3,29 +3,24 @@
|
|||
translate-attr="{title: 'View item'}"
|
||||
class="vn-list-item">
|
||||
<vn-horizontal ng-click="$ctrl.onClick($event)">
|
||||
<vn-auto class="image" margin-medium-right>
|
||||
<img
|
||||
ng-src="//verdnatura.es/vn-image-data/catalog/200x200/{{$ctrl.item.image}}"
|
||||
zoom-image="//verdnatura.es/vn-image-data/catalog/1600x900/{{::$ctrl.item.image}}"
|
||||
on-error-src/>
|
||||
|
||||
<vn-auto margin-medium-right>
|
||||
<vn-one>
|
||||
<img
|
||||
class="image"
|
||||
ng-src="//verdnatura.es/vn-image-data/catalog/200x200/{{::$ctrl.item.image}}"
|
||||
zoom-image="//verdnatura.es/vn-image-data/catalog/1600x900/{{::$ctrl.item.image}}" on-error-src/>
|
||||
</vn-one>
|
||||
</vn-auto>
|
||||
<vn-one>
|
||||
<h6 translate>{{::$ctrl.item.name}}</h6>
|
||||
<vn-label-value label="Id"
|
||||
value="{{::$ctrl.item.id}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Description"
|
||||
value="{{::$ctrl.item.description}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Size"
|
||||
value="{{::$ctrl.item.size}}">
|
||||
</vn-label-value>
|
||||
<h6>{{::$ctrl.item.id}} - {{::$ctrl.item.name}}</h6>
|
||||
<vn-label-value label="Type"
|
||||
value="{{::$ctrl.item.type}}">
|
||||
</vn-label-value>
|
||||
<vn-label-value label="Buyer"
|
||||
value="{{::$ctrl.item.firstName}} {{::$ctrl.item.worker}}">
|
||||
</vn-label-value>
|
||||
<vn-fetched-tags tags="$ctrl.item.tags"/>
|
||||
</vn-one>
|
||||
<vn-horizontal class="buttons">
|
||||
<vn-icon
|
||||
|
|
|
@ -6,6 +6,26 @@ class ItemProduct {
|
|||
event.stopImmediatePropagation();
|
||||
}
|
||||
|
||||
set item(value) {
|
||||
if (value) {
|
||||
let tags = [];
|
||||
for (let i = 5; i < 9; i++) {
|
||||
if (value['tag' + i]) {
|
||||
let tagValue = value['value' + i];
|
||||
let tagKey = value['tag' + i];
|
||||
tags.push({tag: {name: tagKey}, value: tagValue});
|
||||
}
|
||||
}
|
||||
value.tags = tags;
|
||||
}
|
||||
|
||||
this._item = value;
|
||||
}
|
||||
|
||||
get item() {
|
||||
return this._item;
|
||||
}
|
||||
|
||||
clone(event) {
|
||||
event.preventDefault();
|
||||
this.index.cloneItem(this.item);
|
||||
|
|
|
@ -1,8 +1,13 @@
|
|||
@import "./colors";
|
||||
@import 'colors';
|
||||
|
||||
vn-item-product {
|
||||
display: block;
|
||||
|
||||
.id {
|
||||
background-color: $main-01;
|
||||
color: white;
|
||||
margin-bottom: 0em;
|
||||
}
|
||||
.image {
|
||||
height: 7em;
|
||||
width: 7em;
|
||||
|
@ -13,4 +18,10 @@ vn-item-product {
|
|||
border-radius: .2em;
|
||||
}
|
||||
}
|
||||
vn-label-value:first-of-type section{
|
||||
margin-top: 0.6em;
|
||||
}
|
||||
vn-fetched-tags vn-horizontal{
|
||||
margin-top: 0.9em;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,49 +0,0 @@
|
|||
@import "colors";
|
||||
|
||||
vn-fetched-tags {
|
||||
& > vn-horizontal {
|
||||
align-items: center;
|
||||
|
||||
& > .tags {
|
||||
padding: 0;
|
||||
max-width: 500px;
|
||||
}
|
||||
.inline-tag {
|
||||
background-color: $secondary-font-color;
|
||||
display: inline-block;
|
||||
color: $color-white;
|
||||
margin-right: .4em;
|
||||
text-align: center;
|
||||
font-size: .8em;
|
||||
height: 1.25em;
|
||||
padding: 0.4em;
|
||||
width: 5em
|
||||
}
|
||||
.inline-tag.empty {
|
||||
background-color: $main-bg
|
||||
}
|
||||
}
|
||||
|
||||
@media screen and (max-width: 1600px){
|
||||
& > vn-horizontal {
|
||||
flex-direction: column;
|
||||
text-align: center;
|
||||
|
||||
.tags {
|
||||
padding-top: 0.2em
|
||||
}
|
||||
.inline-tag {
|
||||
font-size: .7em;
|
||||
padding: .3em
|
||||
}
|
||||
}
|
||||
}
|
||||
@media screen and (max-width: 1200px){
|
||||
vn-horizontal {
|
||||
.inline-tag {
|
||||
font-size: .6em;
|
||||
padding: .2em
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -16,7 +16,6 @@ import './sale';
|
|||
import './sale/editDiscount';
|
||||
import './tracking/index';
|
||||
import './tracking/edit';
|
||||
import './fetched-tags';
|
||||
import './sale-checked';
|
||||
import './component';
|
||||
import './sale-tracking';
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
{
|
||||
"name": "ClientContact",
|
||||
"description": "Client phone contacts",
|
||||
"base": "VnModel",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"changedModelValue": "name"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientContact",
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
{
|
||||
"name": "ClientObservation",
|
||||
"description": "Client notes",
|
||||
"base": "VnModel",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientObservation"
|
||||
|
@ -32,9 +36,9 @@
|
|||
"foreignKey": "workerFk"
|
||||
},
|
||||
"client": {
|
||||
"type": "hasOne",
|
||||
"type": "belongsTo",
|
||||
"model": "Client",
|
||||
"foreignKey": "id"
|
||||
"foreignKey": "clientFk"
|
||||
}
|
||||
},
|
||||
"scope": {
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
{
|
||||
"name": "ClientSample",
|
||||
"base": "VnModel",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"changedModelValue": "type"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "clientSample"
|
||||
|
|
|
@ -1,6 +1,11 @@
|
|||
{
|
||||
"name": "Greuge",
|
||||
"base": "VnModel",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"changedModelValue": "description"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "greuge"
|
||||
|
|
|
@ -1,6 +1,10 @@
|
|||
{
|
||||
"name": "Recovery",
|
||||
"base": "VnModel",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "recovery"
|
||||
|
|
|
@ -43,7 +43,7 @@ module.exports = function(Self) {
|
|||
countryFk: data.countryFk,
|
||||
isEqualizated: data.isEqualizated
|
||||
};
|
||||
newClient = await Self.create(client);
|
||||
newClient = await Self.create(client, {transaction});
|
||||
await transaction.commit();
|
||||
return newClient;
|
||||
} catch (e) {
|
||||
|
|
|
@ -30,7 +30,9 @@ module.exports = Self => {
|
|||
|
||||
Self.filter = async(filter, tags) => {
|
||||
let stmt = new ParameterizedSQL(
|
||||
`SELECT i.id, i.image, i.name, i.description, i.size,
|
||||
`SELECT i.id, i.image, i.name, i.description,
|
||||
i.size, i.tag5, i.value5, i.tag6, i.value6,
|
||||
i.tag7, i.value7, i.tag8, i.value8,
|
||||
t.name type, w.firstName, w.name worker
|
||||
FROM item i
|
||||
JOIN itemType t ON t.id = i.typeFk
|
||||
|
|
|
@ -63,7 +63,7 @@ module.exports = Self => {
|
|||
await model.Sale.updateAll(
|
||||
{id: {inq: selectedSalesId}},
|
||||
{ticketFk: newTicket.id},
|
||||
{transaction: transaction});
|
||||
{transaction});
|
||||
|
||||
await transaction.commit();
|
||||
|
||||
|
|
|
@ -1,7 +1,12 @@
|
|||
{
|
||||
"name": "Address",
|
||||
"description": "Client addresses",
|
||||
"base": "VnModel",
|
||||
"base": "Loggable",
|
||||
"log": {
|
||||
"model": "ClientLog",
|
||||
"relation": "client",
|
||||
"changedModelValue": "nickname"
|
||||
},
|
||||
"options": {
|
||||
"mysql": {
|
||||
"table": "address"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
"required": true
|
||||
},
|
||||
"changedModel": {
|
||||
"type": "Object"
|
||||
"type": "String"
|
||||
},
|
||||
"oldInstance": {
|
||||
"type": "Object"
|
||||
|
@ -39,7 +39,7 @@
|
|||
"type": "Number"
|
||||
},
|
||||
"changedModelValue": {
|
||||
"type": "Number"
|
||||
"type": "String"
|
||||
}
|
||||
},
|
||||
"relations": {
|
||||
|
|
|
@ -6,7 +6,7 @@ module.exports = function(Self) {
|
|||
Self.super_.setup.call(this);
|
||||
};
|
||||
|
||||
/* Self.observe('after save', async function(ctx) {
|
||||
Self.observe('after save', async function(ctx) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
await logInModel(ctx, loopBackContext);
|
||||
});
|
||||
|
@ -15,10 +15,15 @@ module.exports = function(Self) {
|
|||
let oldInstance;
|
||||
let oldInstanceFk;
|
||||
let newInstance;
|
||||
|
||||
if (ctx.data) {
|
||||
oldInstanceFk = pick(ctx.currentInstance, Object.keys(ctx.data));
|
||||
newInstance = await fkToValue(ctx.data, ctx);
|
||||
oldInstance = await fkToValue(oldInstanceFk, ctx);
|
||||
if (ctx.where && !ctx.currentInstance) {
|
||||
let fields = Object.keys(ctx.data);
|
||||
ctx.oldInstances = await Self.modelBuilder.models[ctx.Model.definition.name].find({where: ctx.where, fields: fields});
|
||||
}
|
||||
}
|
||||
if (ctx.isNewInstance) {
|
||||
newInstance = await fkToValue(ctx.instance.__data, ctx);
|
||||
|
@ -28,53 +33,79 @@ module.exports = function(Self) {
|
|||
});
|
||||
|
||||
Self.observe('before delete', async function(ctx) {
|
||||
let oldInstance;
|
||||
// console.log(ctx.where);
|
||||
if (ctx.where) {
|
||||
let affectedModel = ctx.Model.definition.name;
|
||||
// console.log(affectedModel);
|
||||
let definition = ctx.Model.definition;
|
||||
let deletedInstances = await Self.modelBuilder.models[affectedModel].find({where: ctx.where});
|
||||
// console.log(deletedInstances);
|
||||
let relation = definition.settings.log.relation;
|
||||
|
||||
let arrangedDeletedInstances = [];
|
||||
deletedInstances.forEach(async element => {
|
||||
console.log(element);
|
||||
arrangedDeletedInstances.push(await fkToValue(element, ctx));
|
||||
});
|
||||
if (relation) {
|
||||
let primaryKey = ctx.Model.relations[relation].keyFrom;
|
||||
|
||||
console.log(arrangedDeletedInstances);
|
||||
// let deletedIntancesData = await fkToValue(deletedInstances, ctx);
|
||||
// console.log(deletedIntancesData);
|
||||
// oldInstanceFk = pick(ctx.currentInstance, Object.keys(ctx.data));
|
||||
// oldInstance = await fkToValue(oldInstanceFk, ctx);
|
||||
let arrangedDeletedInstances = [];
|
||||
for (let i = 0; i < deletedInstances.length; i++) {
|
||||
if (primaryKey)
|
||||
deletedInstances[i].originFk = deletedInstances[i][primaryKey];
|
||||
let arrangedInstance = await fkToValue(deletedInstances[i], ctx);
|
||||
arrangedDeletedInstances[i] = arrangedInstance;
|
||||
}
|
||||
ctx.hookState.oldInstance = arrangedDeletedInstances;
|
||||
}
|
||||
}
|
||||
ctx.hookState.oldInstance = oldInstance;
|
||||
});
|
||||
|
||||
Self.observe('after delete', async function(ctx) {
|
||||
const loopBackContext = LoopBackContext.getCurrentContext();
|
||||
await logInModel(ctx, loopBackContext);
|
||||
}); */
|
||||
if (ctx.hookState.oldInstance)
|
||||
logDeletedInstances(ctx, loopBackContext);
|
||||
});
|
||||
|
||||
async function logDeletedInstances(ctx, loopBackContext) {
|
||||
ctx.hookState.oldInstance.forEach(async instance => {
|
||||
let userFk;
|
||||
if (loopBackContext)
|
||||
userFk = loopBackContext.active.accessToken.userId;
|
||||
|
||||
let definition = ctx.Model.definition;
|
||||
|
||||
let changedModelValue = definition.settings.log.changedModelValue;
|
||||
let logRecord = {
|
||||
originFk: instance.originFk,
|
||||
userFk: userFk,
|
||||
action: 'delete',
|
||||
changedModel: ctx.Model.definition.name,
|
||||
changedModelId: instance.id,
|
||||
changedModelValue: instance[changedModelValue],
|
||||
oldInstance: instance,
|
||||
newInstance: {}
|
||||
};
|
||||
|
||||
let transaction = {};
|
||||
if (ctx.options && ctx.options.transaction) {
|
||||
transaction = ctx.options.transaction;
|
||||
}
|
||||
|
||||
let logModel = definition.settings.log.model;
|
||||
await Self.modelBuilder.models[logModel].create(logRecord, transaction);
|
||||
});
|
||||
}
|
||||
|
||||
async function fkToValue(instance, ctx) {
|
||||
let cleanInstance = JSON.parse(JSON.stringify(instance));
|
||||
let result = {};
|
||||
for (let key in instance) {
|
||||
if (key == 'id') continue;
|
||||
let val = instance[key];
|
||||
console.log(val);
|
||||
for (let key in cleanInstance) {
|
||||
let val = cleanInstance[key];
|
||||
if (val === undefined || val === null) continue;
|
||||
for (let key1 in ctx.Model.relations) {
|
||||
let val1 = ctx.Model.relations[key1];
|
||||
if (val1.keyFrom == key) {
|
||||
if (val1.keyFrom == key && key != 'id') {
|
||||
let recordSet = await val1.modelTo.findById(val);
|
||||
val = recordSet.name; // FIXME preparar todos los modelos con campo name
|
||||
console.log(val);
|
||||
break;
|
||||
}
|
||||
}
|
||||
result[key] = val;
|
||||
}
|
||||
// console.log(result);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
@ -111,8 +142,6 @@ module.exports = function(Self) {
|
|||
changedModelId = ctx.currentInstance.id;
|
||||
}
|
||||
|
||||
// console.log(ctx.instance, ctx.where, ctx.currentInstance);
|
||||
|
||||
// Sets the changedModelValue to save and the instances changed in case its an updateAll
|
||||
let changedModelValue = definition.settings.log.changedModelValue;
|
||||
if (changedModelValue && (!ctx.instance || !ctx.instance[changedModelValue])) {
|
||||
|
@ -126,7 +155,6 @@ module.exports = function(Self) {
|
|||
} else if (ctx.hookState.oldInstance) {
|
||||
where = ctx.instance[changedModelValue];
|
||||
}
|
||||
// console.log(where);
|
||||
|
||||
// Set oldInstance, newInstance, userFk and action
|
||||
let oldInstance = {};
|
||||
|
@ -156,7 +184,7 @@ module.exports = function(Self) {
|
|||
newInstance: newInstance
|
||||
};
|
||||
|
||||
let logsToSave = setLogsToSave(where, changedModelId, logRecord);
|
||||
let logsToSave = setLogsToSave(where, changedModelId, logRecord, ctx);
|
||||
|
||||
let logModel = definition.settings.log.model;
|
||||
|
||||
|
@ -165,17 +193,18 @@ module.exports = function(Self) {
|
|||
transaction = ctx.options.transaction;
|
||||
}
|
||||
|
||||
// console.log(logsToSave);
|
||||
await Self.modelBuilder.models[logModel].create(logsToSave, transaction);
|
||||
}
|
||||
|
||||
// this function retuns all the instances changed in case this is an updateAll
|
||||
function setLogsToSave(changedInstances, changedInstancesIds, logRecord) {
|
||||
function setLogsToSave(changedInstances, changedInstancesIds, logRecord, ctx) {
|
||||
let promises = [];
|
||||
if (changedInstances && typeof changedInstances == "object") {
|
||||
for (let i = 0; i < changedInstances.length; i++) {
|
||||
logRecord.changedModelId = changedInstancesIds[i];
|
||||
logRecord.changedModelValue = changedInstances[i];
|
||||
if (ctx.oldInstances)
|
||||
logRecord.oldInstance = ctx.oldInstances[i];
|
||||
promises.push(JSON.parse(JSON.stringify(logRecord)));
|
||||
}
|
||||
} else {
|
||||
|
|
Loading…
Reference in New Issue