Merge branch 'dev' of https://gitea.verdnatura.es/verdnatura/salix into 2575-image_download
This commit is contained in:
commit
1e95f0105a
|
@ -24,8 +24,6 @@ module.exports = Self => {
|
|||
const conn = Self.dataSource.connector;
|
||||
const minDate = new Date();
|
||||
minDate.setFullYear(minDate.getFullYear() - 1);
|
||||
minDate.setMonth(0);
|
||||
minDate.setDate(1);
|
||||
|
||||
const where = {dated: {gte: minDate}};
|
||||
filter = mergeFilters(filter, {where});
|
||||
|
|
|
@ -718,11 +718,13 @@ INSERT INTO `vn`.`itemType`(`id`, `code`, `name`, `categoryFk`, `life`,`workerFk
|
|||
|
||||
INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`)
|
||||
VALUES
|
||||
('YEL', 'Yellow', 1, 1, 'F4D03F'),
|
||||
('BLU', 'Blue', 1, 2, '5DADE2'),
|
||||
('RED', 'Red', 1, 3, 'EC7063'),
|
||||
('SLV', 'Silver', 1, 4, 'CACFD2'),
|
||||
('BRW', 'Brown', 1, 5, 'DC7633');
|
||||
('YEL', 'Yellow', 1, 1, 'F4D03F'),
|
||||
('BLU', 'Blue', 1, 2, '5DADE2'),
|
||||
('RED', 'Red', 1, 3, 'EC7063'),
|
||||
('SLV', 'Silver', 1, 4, 'CACFD2'),
|
||||
('BRW', 'Brown', 1, 5, 'DC7633'),
|
||||
('BLK', 'Black', 1, 6, '000000'),
|
||||
('BAS', 'Blue/Silver', 1, 7, '5DADE2');
|
||||
|
||||
INSERT INTO `vn`.`origin`(`id`,`code`, `name`)
|
||||
VALUES
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -69,12 +69,14 @@
|
|||
<vn-date-picker
|
||||
vn-one
|
||||
label="From"
|
||||
ng-model="filter.from">
|
||||
ng-model="filter.from"
|
||||
on-change="$ctrl.onChangeDate(value)">
|
||||
</vn-date-picker>
|
||||
<vn-date-picker
|
||||
vn-one
|
||||
label="To"
|
||||
ng-model="filter.to">
|
||||
ng-model="filter.to"
|
||||
on-change="$ctrl.onChangeDate(value)">
|
||||
</vn-date-picker>
|
||||
</vn-horizontal>
|
||||
<vn-horizontal class="vn-mt-lg">
|
||||
|
|
|
@ -5,16 +5,34 @@ class Controller extends SearchPanel {
|
|||
constructor($, $element) {
|
||||
super($, $element);
|
||||
|
||||
this.getUpcomingCampaing();
|
||||
this.filter = this.$.filter;
|
||||
|
||||
if (!this.dateParams)
|
||||
this.getUpcomingCampaing();
|
||||
}
|
||||
|
||||
get dateParams() {
|
||||
if (this.$params.q) {
|
||||
const params = JSON.parse(this.$params.q);
|
||||
|
||||
if (params.from || params.to)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
getUpcomingCampaing() {
|
||||
this.$http.get('Campaigns/upcoming').then(res => {
|
||||
const filter = this.$.filter;
|
||||
filter.campaign = res.data.id;
|
||||
this.filter.campaign = res.data.id;
|
||||
});
|
||||
}
|
||||
|
||||
onChangeDate(value) {
|
||||
if (value)
|
||||
this.filter.campaign = null;
|
||||
}
|
||||
|
||||
get campaignSelection() {
|
||||
return this._campaignSelection;
|
||||
}
|
||||
|
@ -22,14 +40,13 @@ class Controller extends SearchPanel {
|
|||
set campaignSelection(value) {
|
||||
this._campaignSelection = value;
|
||||
|
||||
if (!value) return;
|
||||
if (value) {
|
||||
const from = new Date(value.dated);
|
||||
from.setDate(from.getDate() - value.scopeDays);
|
||||
|
||||
const filter = this.$.filter;
|
||||
const from = new Date(value.dated);
|
||||
from.setDate(from.getDate() - value.scopeDays);
|
||||
|
||||
filter.to = value.dated;
|
||||
filter.from = from;
|
||||
this.filter.to = value.dated;
|
||||
this.filter.from = from;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -13,6 +13,10 @@ class Controller extends Section {
|
|||
}
|
||||
};
|
||||
|
||||
this.setDefaultFilter();
|
||||
}
|
||||
|
||||
setDefaultFilter() {
|
||||
const minDate = new Date();
|
||||
minDate.setHours(0, 0, 0, 0);
|
||||
minDate.setMonth(minDate.getMonth() - 2);
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
|
||||
module.exports = Self => {
|
||||
Self.remoteMethod('filterValue', {
|
||||
description: 'Returns a list of tag values',
|
||||
accepts: [{
|
||||
arg: 'id',
|
||||
type: 'Number',
|
||||
required: true,
|
||||
description: 'The tag id',
|
||||
http: {source: 'path'}
|
||||
}, {
|
||||
arg: 'filter',
|
||||
type: 'Object',
|
||||
description: `Filter defining where, order, offset, and limit - must be a JSON-encoded string`
|
||||
}],
|
||||
returns: {
|
||||
type: ['object'],
|
||||
root: true
|
||||
},
|
||||
http: {
|
||||
path: `/:id/filterValue`,
|
||||
verb: 'GET'
|
||||
}
|
||||
});
|
||||
|
||||
Self.filterValue = async(id, filter) => {
|
||||
const conn = Self.dataSource.connector;
|
||||
const tag = await Self.findById(id);
|
||||
|
||||
let stmt;
|
||||
if (!tag.isFree && tag.sourceTable) {
|
||||
stmt = new ParameterizedSQL(
|
||||
`SELECT value FROM (
|
||||
SELECT name AS value FROM ${tag.sourceTable}) v`);
|
||||
} else
|
||||
stmt = new ParameterizedSQL(`SELECT value FROM itemTag`);
|
||||
|
||||
let where = filter.where;
|
||||
if (where && where.value) {
|
||||
stmt.merge(conn.makeWhere({value: {like: `%${where.value}%`}}));
|
||||
stmt.merge(`
|
||||
ORDER BY value LIKE '${where.value}' DESC,
|
||||
value LIKE '${where.value}%' DESC`);
|
||||
}
|
||||
|
||||
stmt.merge(conn.makeLimit(filter));
|
||||
|
||||
return conn.executeStmt(stmt);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,37 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
|
||||
describe('tag filterValue()', () => {
|
||||
const colorTagId = 1;
|
||||
it('should return a list of color values', async() => {
|
||||
const filter = {limit: 5};
|
||||
const result = await app.models.Tag.filterValue(colorTagId, filter);
|
||||
|
||||
expect(result.length).toEqual(5);
|
||||
});
|
||||
|
||||
it('should return the values matching color "Blue"', async() => {
|
||||
const filter = {where: {value: 'Blue'}, limit: 5};
|
||||
const result = await app.models.Tag.filterValue(colorTagId, filter);
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
expect(result[0].value).toEqual('Blue');
|
||||
expect(result[1].value).toEqual('Blue/Silver');
|
||||
});
|
||||
|
||||
it('should return the values matching color "Blue/Silver"', async() => {
|
||||
const filter = {where: {value: 'Blue/Silver'}, limit: 5};
|
||||
const result = await app.models.Tag.filterValue(colorTagId, filter);
|
||||
|
||||
expect(result.length).toEqual(1);
|
||||
expect(result[0].value).toEqual('Blue/Silver');
|
||||
});
|
||||
|
||||
it('should return the values matching color "Silver"', async() => {
|
||||
const filter = {where: {value: 'Silver'}, limit: 5};
|
||||
const result = await app.models.Tag.filterValue(colorTagId, filter);
|
||||
|
||||
expect(result.length).toEqual(2);
|
||||
expect(result[0].value).toEqual('Silver');
|
||||
expect(result[1].value).toEqual('Blue/Silver');
|
||||
});
|
||||
});
|
|
@ -0,0 +1,3 @@
|
|||
module.exports = Self => {
|
||||
require('../methods/tag/filterValue')(Self);
|
||||
};
|
|
@ -40,12 +40,12 @@
|
|||
</vn-textfield>
|
||||
<vn-autocomplete vn-three
|
||||
ng-show="tag.selection.isFree === false"
|
||||
url="{{$ctrl.sourceTables[itemTag.id].url}}"
|
||||
search-function="{name: {like: $search +'%'}}"
|
||||
url="{{'Tags/' + itemTag.tagFk + '/filterValue'}}"
|
||||
search-function="{value: $search}"
|
||||
label="Value"
|
||||
ng-model="itemTag.value"
|
||||
show-field="{{$ctrl.sourceTables[itemTag.id].field}}"
|
||||
value-field="{{$ctrl.sourceTables[itemTag.id].field}}"
|
||||
show-field="value"
|
||||
value-field="value"
|
||||
rule>
|
||||
</vn-autocomplete>
|
||||
<vn-input-number vn-one
|
||||
|
|
|
@ -10,40 +10,6 @@ class Controller extends Section {
|
|||
fields: ['id', 'name', 'isFree', 'sourceTable']
|
||||
}
|
||||
};
|
||||
this.sourceTables = {};
|
||||
}
|
||||
|
||||
set itemTags(value) {
|
||||
if (value) {
|
||||
value.forEach(tag => {
|
||||
this.getSourceTable(tag);
|
||||
});
|
||||
|
||||
this._itemTags = value;
|
||||
}
|
||||
}
|
||||
|
||||
get itemTags() {
|
||||
return this._itemTags;
|
||||
}
|
||||
|
||||
getSourceTable(obj) {
|
||||
let sourceTable;
|
||||
this.sourceTables[obj.id] = {};
|
||||
let tag = obj.tag || obj.selection;
|
||||
|
||||
if (!tag || !tag.sourceTable && (tag.isFree === true || tag.isFree === undefined))
|
||||
sourceTable = null;
|
||||
else if (tag.sourceTable) {
|
||||
sourceTable = '' + tag.sourceTable.charAt(0).toUpperCase() +
|
||||
tag.sourceTable.substring(1) + 's';
|
||||
this.sourceTables[obj.id].field = 'name';
|
||||
} else {
|
||||
sourceTable = `ItemTags/filterItemTags/${tag.id}`;
|
||||
this.sourceTables[obj.id].field = 'value';
|
||||
}
|
||||
|
||||
this.sourceTables[obj.id].url = sourceTable;
|
||||
}
|
||||
|
||||
add() {
|
||||
|
|
|
@ -16,46 +16,6 @@ describe('Item', () => {
|
|||
controller = $componentController('vnItemTags', {$element, $scope});
|
||||
}));
|
||||
|
||||
describe('itemTags setter', () => {
|
||||
it('should call getSourceTable one time for each element in the value array', () => {
|
||||
jest.spyOn(controller, 'getSourceTable');
|
||||
let itemTags = [
|
||||
{id: 1},
|
||||
{id: 2},
|
||||
{id: 3},
|
||||
{id: 4}
|
||||
];
|
||||
|
||||
controller.itemTags = itemTags;
|
||||
|
||||
expect(controller.getSourceTable.mock.calls.length).toEqual(4);
|
||||
expect(controller.itemTags).toEqual(itemTags);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSourceTable', () => {
|
||||
it('should return null when the property isFree equals true', () => {
|
||||
let tag = {id: 1};
|
||||
controller.getSourceTable(tag);
|
||||
|
||||
expect(controller.sourceTables[1].url).toBe(null);
|
||||
});
|
||||
|
||||
it('should return the route of the model in loopback with the first char of the string uppercase and adding a s', () => {
|
||||
let tag = {id: 1, tag: {sourceTable: 'ink'}};
|
||||
controller.getSourceTable(tag);
|
||||
|
||||
expect(controller.sourceTables[1].url).toBe('Inks');
|
||||
});
|
||||
|
||||
it('should return the route filteritemtags with the id of the selection', () => {
|
||||
let tag = {id: 1, tag: {id: 3, sourceTable: null, isFree: false}};
|
||||
controller.getSourceTable(tag);
|
||||
|
||||
expect(controller.sourceTables[1].url).toBe('ItemTags/filterItemTags/3');
|
||||
});
|
||||
});
|
||||
|
||||
describe('getHighestPriority', () => {
|
||||
it('should return the highest priority value + 1 from the array', () => {
|
||||
let result = controller.getHighestPriority();
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
<vn-autocomplete
|
||||
vn-one
|
||||
ng-show="tag.selection.isFree == false"
|
||||
url="{{$ctrl.getSourceTable(tag.selection)}}"
|
||||
url="{{'Tags/' + tag.selection.id + '/filterValue'}}"
|
||||
search-function="{value: $search}"
|
||||
label="Value"
|
||||
ng-model="tagValue.value"
|
||||
show-field="name"
|
||||
value-field="name">
|
||||
show-field="value"
|
||||
value-field="value">
|
||||
</vn-autocomplete>
|
||||
<vn-icon-button
|
||||
vn-none
|
||||
|
|
|
@ -21,18 +21,6 @@ class Controller extends SearchPanel {
|
|||
this.$.filter = value;
|
||||
}
|
||||
|
||||
getSourceTable(selection) {
|
||||
if (!selection || selection.isFree == true)
|
||||
return null;
|
||||
|
||||
if (selection.sourceTable) {
|
||||
return ''
|
||||
+ selection.sourceTable.charAt(0).toUpperCase()
|
||||
+ selection.sourceTable.substring(1) + 's';
|
||||
} else if (selection.sourceTable == null)
|
||||
return `ItemTags/filterItemTags/${selection.id}`;
|
||||
}
|
||||
|
||||
addValue() {
|
||||
this.filter.values.push({});
|
||||
setTimeout(() => this.popover.relocate());
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue