Bug #211 Forzar a ciertos tags
This commit is contained in:
parent
85a5d986b9
commit
1e15826f8d
|
@ -40,7 +40,7 @@ export default class DropDown extends Component {
|
|||
|
||||
set search(value) {
|
||||
value = value == '' || value == null ? null : value;
|
||||
if (value === this._search) return;
|
||||
if (value === this._search && this.$.model.data != null) return;
|
||||
|
||||
this._search = value;
|
||||
this.$.model.clear();
|
||||
|
|
|
@ -13,6 +13,17 @@ export default class Model {
|
|||
return this.canceler != null;
|
||||
}
|
||||
|
||||
set url(url) {
|
||||
if (this._url != url) {
|
||||
this._url = url;
|
||||
this.clear();
|
||||
}
|
||||
}
|
||||
|
||||
get url() {
|
||||
return this._url;
|
||||
}
|
||||
|
||||
loadMore() {
|
||||
if (this.moreRows) {
|
||||
let filter = Object.assign({}, this.myFilter);
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
import './model.js';
|
||||
|
||||
describe('Component vnModel', () => {
|
||||
let $componentController;
|
||||
let $httpBackend;
|
||||
let controller;
|
||||
|
||||
beforeEach(() => {
|
||||
angular.mock.module('client');
|
||||
});
|
||||
|
||||
beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => {
|
||||
$componentController = _$componentController_;
|
||||
controller = $componentController('vnModel', {$httpBackend});
|
||||
}));
|
||||
|
||||
describe('set url', () => {
|
||||
it(`should call clear function when the controller _url is undefined`, () => {
|
||||
spyOn(controller, 'clear');
|
||||
controller.url = 'localhost';
|
||||
|
||||
expect(controller._url).toEqual('localhost');
|
||||
expect(controller.clear).toHaveBeenCalledWith();
|
||||
});
|
||||
|
||||
it(`should do nothing when the url is matching`, () => {
|
||||
controller._url = 'localhost';
|
||||
spyOn(controller, 'clear');
|
||||
controller.url = 'localhost';
|
||||
|
||||
expect(controller.clear).not.toHaveBeenCalledWith();
|
||||
});
|
||||
});
|
||||
});
|
|
@ -6,32 +6,41 @@
|
|||
<form name="form" ng-submit="$ctrl.submit()">
|
||||
<vn-card pad-large>
|
||||
<vn-title>Item tags</vn-title>
|
||||
<vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags track by $index">
|
||||
<vn-horizontal ng-repeat="itemTag in $ctrl.instancedItemTags">
|
||||
<vn-autocomplete
|
||||
ng-if="!itemTag.id"
|
||||
vn-id="tag"
|
||||
vn-one
|
||||
initial-data="itemTag.tag"
|
||||
field="itemTag.tagFk"
|
||||
data="tags.model"
|
||||
show-field="name"
|
||||
label="Tag"
|
||||
vn-acl="buyer">
|
||||
on-change="$ctrl.checkAutocompleteChanges(itemTag)"
|
||||
vn-acl="buyer"
|
||||
vn-focus
|
||||
disabled="itemTag.id != null">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
ng-if="itemTag.id"
|
||||
vn-one
|
||||
label="Tag"
|
||||
model="itemTag.tag.name"
|
||||
disabled="true">
|
||||
</vn-textfield>
|
||||
<vn-textfield
|
||||
ng-show="tag.selection.isFree || tag.selection.isFree == undefined"
|
||||
vn-id="text"
|
||||
vn-three
|
||||
label="Value"
|
||||
model="itemTag.value"
|
||||
rule="itemTag.value"
|
||||
vn-acl="buyer">
|
||||
</vn-textfield>
|
||||
<vn-autocomplete
|
||||
ng-show="tag.selection.isFree === false"
|
||||
vn-three
|
||||
url="{{$ctrl.getSourceTable(tag.selection)}}"
|
||||
label="Value"
|
||||
field="itemTag.value"
|
||||
show-field="name"
|
||||
value-field="name"
|
||||
vn-acl="buyer">
|
||||
</vn-autocomplete>
|
||||
<vn-textfield
|
||||
vn-tab-index="-1"
|
||||
vn-one
|
||||
type="number"
|
||||
label="Relevancy"
|
||||
|
@ -39,25 +48,24 @@
|
|||
rule="itemTag.priority"
|
||||
vn-acl="buyer">
|
||||
</vn-textfield>
|
||||
<vn-one pad-medium-top></vn-one>
|
||||
<vn-icon
|
||||
pointer
|
||||
pad-medium-top
|
||||
pointer
|
||||
medium-grey
|
||||
vn-tooltip="Remove tag"
|
||||
tooltip-position="left"
|
||||
icon="remove_circle_outline"
|
||||
ng-click="$ctrl.removeItemTag($index)"
|
||||
vn-acl="buyer">
|
||||
ng-click="$ctrl.removeItemTag($index)">
|
||||
</vn-icon>
|
||||
<vn-icon
|
||||
pointer
|
||||
margin-medium-left
|
||||
orange
|
||||
icon="add_circle"
|
||||
ng-if="itemTag.showAddIcon && tags.model.length > $ctrl.instancedItemTags.length"
|
||||
ng-click="$ctrl.addItemTag()"
|
||||
vn-acl="buyer">
|
||||
</vn-icon>
|
||||
</vn-one>
|
||||
</vn-horizontal>
|
||||
<vn-one>
|
||||
<vn-icon-button
|
||||
vn-tooltip="Add tag"
|
||||
tooltip-position="right"
|
||||
icon="add_circle"
|
||||
ng-click="$ctrl.addItemTag()">
|
||||
</vn-icon-button>
|
||||
</vn-one>
|
||||
</vn-card>
|
||||
<vn-button-bar>
|
||||
<vn-submit label="Save"></vn-submit>
|
||||
|
|
|
@ -20,10 +20,9 @@ class ItemTags {
|
|||
return true;
|
||||
});
|
||||
this.instancedItemTags[this.instancedItemTags.length - 1].showAddIcon = true;
|
||||
} else {
|
||||
this.addItemTag();
|
||||
}
|
||||
}
|
||||
|
||||
_setDirtyForm() {
|
||||
if (this.$scope.form) {
|
||||
this.$scope.form.$setDirty();
|
||||
|
@ -35,9 +34,13 @@ class ItemTags {
|
|||
}
|
||||
}
|
||||
|
||||
checkAutocompleteChanges(itemTag) {
|
||||
itemTag.value = null;
|
||||
}
|
||||
|
||||
addItemTag() {
|
||||
if (this.instancedItemTags) {
|
||||
this.instancedItemTags.push({value: null, itemFk: this.params.id, tagFk: null, priority: this.getMaxPriority(this.instancedItemTags) + 1, showAddIcon: true});
|
||||
this.instancedItemTags.push({value: null, itemFk: this.params.id, tagFk: null, priority: this.getHighestPriority(this.instancedItemTags), showAddIcon: true});
|
||||
this._setIconAdd();
|
||||
}
|
||||
}
|
||||
|
@ -54,13 +57,25 @@ class ItemTags {
|
|||
}
|
||||
}
|
||||
|
||||
getMaxPriority(instancedItemTags) {
|
||||
getHighestPriority(instancedItemTags) {
|
||||
let max = 0;
|
||||
instancedItemTags.forEach(tag => {
|
||||
if (tag.priority > max)
|
||||
max = tag.priority;
|
||||
});
|
||||
return max;
|
||||
return max + 1;
|
||||
}
|
||||
|
||||
getSourceTable(selection) {
|
||||
if (!selection || selection.isFree === true)
|
||||
return null;
|
||||
|
||||
if (selection.sourceTable) {
|
||||
return "/api/" + selection.sourceTable.charAt(0).toUpperCase() +
|
||||
selection.sourceTable.substring(1) + 's';
|
||||
} else if (selection.sourceTable == null) {
|
||||
return `/api/ItemTags/filterItemTags/${selection.id}`;
|
||||
}
|
||||
}
|
||||
|
||||
_equalItemTags(oldTag, newTag) {
|
||||
|
@ -147,6 +162,7 @@ ngModule.component('vnItemTags', {
|
|||
template: require('./tags.html'),
|
||||
controller: ItemTags,
|
||||
bindings: {
|
||||
itemTags: '='
|
||||
itemTags: '=',
|
||||
selection: '<?'
|
||||
}
|
||||
});
|
||||
|
|
|
@ -50,6 +50,45 @@ describe('Item', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('getHighestPriority', () => {
|
||||
it('should return the highest priority value + 1 from the array', () => {
|
||||
let tags = [{priority: 1}, {priority: 2}, {priority: 1}];
|
||||
let result = controller.getHighestPriority(tags);
|
||||
|
||||
expect(result).toEqual(3);
|
||||
});
|
||||
|
||||
it('should return 1 when there is no priority defined', () => {
|
||||
let tags = [];
|
||||
let result = controller.getHighestPriority(tags);
|
||||
|
||||
expect(result).toEqual(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getSourceTable', () => {
|
||||
it('should return null when the property isFree equals true', () => {
|
||||
let selection = {isFree: true};
|
||||
let result = controller.getSourceTable(selection);
|
||||
|
||||
expect(result).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 selection = {sourceTable: "ink"};
|
||||
let result = controller.getSourceTable(selection);
|
||||
|
||||
expect(result).toBe("/api/Inks");
|
||||
});
|
||||
|
||||
it('should return the route filteritemtags with the id of the selection', () => {
|
||||
let selection = {id: 3, sourceTable: null, isFree: false};
|
||||
let result = controller.getSourceTable(selection);
|
||||
|
||||
expect(result).toBe("/api/ItemTags/filterItemTags/3");
|
||||
});
|
||||
});
|
||||
|
||||
describe('_equalItemTags()', () => {
|
||||
it('should return true if two tags are equals independent of control attributes', () => {
|
||||
let tag1 = {id: 1, typeFk: 1, value: '1111', showAddIcon: true};
|
||||
|
|
|
@ -0,0 +1,26 @@
|
|||
module.exports = Self => {
|
||||
Self.remoteMethod('filterItemTags', {
|
||||
description: 'Returns the distinct values of a tag property',
|
||||
accessType: 'READ',
|
||||
accepts: [{
|
||||
arg: 'tagFk',
|
||||
type: 'number',
|
||||
required: true,
|
||||
description: 'The foreign key from tag table',
|
||||
http: {source: 'path'}
|
||||
}],
|
||||
returns: {
|
||||
root: true,
|
||||
type: ['object']
|
||||
},
|
||||
http: {
|
||||
path: `/filterItemTags/:tagFk`,
|
||||
verb: 'get'
|
||||
}
|
||||
});
|
||||
|
||||
Self.filterItemTags = async tagFk => {
|
||||
let query = `SELECT DISTINCT(value) AS name FROM vn.itemTag WHERE tagFk = ?`;
|
||||
return await Self.rawSql(query, [tagFk]);
|
||||
};
|
||||
};
|
|
@ -0,0 +1,9 @@
|
|||
const app = require(`${servicesDir}/item/server/server`);
|
||||
|
||||
describe('item filterItemTags()', () => {
|
||||
it('should call the filterItemTags method', async() => {
|
||||
let [result] = await app.models.ItemTag.filterItemTags(1);
|
||||
|
||||
expect(result.name).toEqual('Yellow');
|
||||
});
|
||||
});
|
|
@ -1,3 +1,4 @@
|
|||
module.exports = function(Self) {
|
||||
require('../methods/item-tag/crudItemTags.js')(Self);
|
||||
require('../methods/item-tag/filterItemTags.js')(Self);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue