2574 - ItemTag refactor sourceTable
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
fc957eda6c
commit
a325ef2a78
|
@ -722,7 +722,9 @@ INSERT INTO `vn`.`ink`(`id`, `name`, `picture`, `showOrder`, `hex`)
|
|||
('BLU', 'Blue', 1, 2, '5DADE2'),
|
||||
('RED', 'Red', 1, 3, 'EC7063'),
|
||||
('SLV', 'Silver', 1, 4, 'CACFD2'),
|
||||
('BRW', 'Brown', 1, 5, 'DC7633');
|
||||
('BRW', 'Brown', 1, 5, 'DC7633'),
|
||||
('BLK', 'Black', 1, 6, '000000'),
|
||||
('BAS', 'Blue/Silver', 1, 7, '5DADE2');
|
||||
|
||||
INSERT INTO `vn`.`origin`(`id`,`code`, `name`)
|
||||
VALUES
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
const ParameterizedSQL = require('loopback-connector').ParameterizedSQL;
|
||||
const mergeFilters = require('vn-loopback/util/filter').mergeFilters;
|
||||
|
||||
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`);
|
||||
|
||||
const where = filter.where;
|
||||
if (where && where.value) {
|
||||
filter.order = `value LIKE '${where.value}' DESC,
|
||||
value LIKE '${where.value}%' DESC`;
|
||||
|
||||
filter.where = {value: {like: `%${where.value}%`}};
|
||||
}
|
||||
} else
|
||||
stmt = new ParameterizedSQL(`SELECT value FROM itemTag`);
|
||||
|
||||
stmt.merge(conn.makeSuffix(filter));
|
||||
|
||||
return conn.executeStmt(stmt);
|
||||
};
|
||||
};
|
|
@ -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() {
|
||||
|
|
Loading…
Reference in New Issue