Merge branch '845-order_catalog_datalist' of verdnatura/salix into dev
gitea/salix/dev This commit looks good
Details
gitea/salix/dev This commit looks good
Details
This commit is contained in:
commit
7e38100d05
|
@ -621,8 +621,8 @@ export default {
|
||||||
plantRealmButton: 'vn-order-catalog > vn-side-menu vn-icon[icon="icon-plant"]',
|
plantRealmButton: 'vn-order-catalog > vn-side-menu vn-icon[icon="icon-plant"]',
|
||||||
type: 'vn-autocomplete[data="$ctrl.itemTypes"]',
|
type: 'vn-autocomplete[data="$ctrl.itemTypes"]',
|
||||||
itemId: 'vn-order-catalog > vn-side-menu vn-textfield[ng-model="$ctrl.itemId"]',
|
itemId: 'vn-order-catalog > vn-side-menu vn-textfield[ng-model="$ctrl.itemId"]',
|
||||||
itemTagValue: 'vn-order-catalog > vn-side-menu vn-textfield[ng-model="$ctrl.value"]',
|
itemTagValue: 'vn-order-catalog > vn-side-menu vn-datalist[ng-model="$ctrl.value"]',
|
||||||
openTagSearch: 'vn-order-catalog > vn-side-menu > div > vn-vertical > vn-textfield[ng-model="$ctrl.value"] .append i',
|
openTagSearch: 'vn-order-catalog > vn-side-menu > div > vn-vertical > vn-datalist[ng-model="$ctrl.value"] .append i',
|
||||||
tag: 'vn-order-catalog-search-panel vn-autocomplete[ng-model="filter.tagFk"]',
|
tag: 'vn-order-catalog-search-panel vn-autocomplete[ng-model="filter.tagFk"]',
|
||||||
tagValue: 'vn-order-catalog-search-panel vn-textfield[ng-model="filter.value"]',
|
tagValue: 'vn-order-catalog-search-panel vn-textfield[ng-model="filter.value"]',
|
||||||
searchTagButton: 'vn-order-catalog-search-panel button[type=submit]',
|
searchTagButton: 'vn-order-catalog-search-panel button[type=submit]',
|
||||||
|
|
|
@ -3,6 +3,7 @@ import ArrayModel from '../array-model/array-model';
|
||||||
import CrudModel from '../crud-model/crud-model';
|
import CrudModel from '../crud-model/crud-model';
|
||||||
import {mergeWhere} from 'vn-loopback/util/filter';
|
import {mergeWhere} from 'vn-loopback/util/filter';
|
||||||
import Textfield from '../textfield/textfield';
|
import Textfield from '../textfield/textfield';
|
||||||
|
import './style.scss';
|
||||||
|
|
||||||
export default class Datalist extends Textfield {
|
export default class Datalist extends Textfield {
|
||||||
constructor($element, $scope, $compile, $transclude) {
|
constructor($element, $scope, $compile, $transclude) {
|
||||||
|
@ -12,7 +13,6 @@ export default class Datalist extends Textfield {
|
||||||
this._selection = null;
|
this._selection = null;
|
||||||
|
|
||||||
this.buildInput('text');
|
this.buildInput('text');
|
||||||
|
|
||||||
this.input.setAttribute('autocomplete', 'off');
|
this.input.setAttribute('autocomplete', 'off');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -157,8 +157,6 @@ export default class Datalist extends Textfield {
|
||||||
this.destroyList();
|
this.destroyList();
|
||||||
} else
|
} else
|
||||||
this.buildList();
|
this.buildList();
|
||||||
|
|
||||||
this.emit('select', {selection});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
@import "effects";
|
||||||
|
|
||||||
|
vn-datalist {
|
||||||
|
input::-webkit-calendar-picker-indicator {
|
||||||
|
display: none
|
||||||
|
}
|
||||||
|
}
|
|
@ -162,6 +162,7 @@ module.exports = Self => {
|
||||||
`SELECT
|
`SELECT
|
||||||
it.tagFk,
|
it.tagFk,
|
||||||
it.itemFk,
|
it.itemFk,
|
||||||
|
it.value,
|
||||||
t.name
|
t.name
|
||||||
FROM tmp.ticketCalculateItem tci
|
FROM tmp.ticketCalculateItem tci
|
||||||
JOIN vn.itemTag it ON it.itemFk = tci.itemFk
|
JOIN vn.itemTag it ON it.itemFk = tci.itemFk
|
||||||
|
|
|
@ -85,12 +85,15 @@
|
||||||
<vn-icon icon="icon-item"></vn-icon>
|
<vn-icon icon="icon-item"></vn-icon>
|
||||||
</prepend>
|
</prepend>
|
||||||
</vn-textfield>
|
</vn-textfield>
|
||||||
<vn-textfield
|
|
||||||
vn-one
|
<vn-datalist vn-one
|
||||||
vn-id="search"
|
vn-id="search"
|
||||||
|
data="$ctrl.tagValues"
|
||||||
|
ng-model="$ctrl.value"
|
||||||
ng-keyUp="$ctrl.onSearchByTag($event)"
|
ng-keyUp="$ctrl.onSearchByTag($event)"
|
||||||
label="Search tag"
|
show-field="value"
|
||||||
ng-model="$ctrl.value">
|
value-field="value"
|
||||||
|
label="Search tag">
|
||||||
<prepend>
|
<prepend>
|
||||||
<vn-icon icon="search"></vn-icon>
|
<vn-icon icon="search"></vn-icon>
|
||||||
</prepend>
|
</prepend>
|
||||||
|
@ -101,7 +104,7 @@
|
||||||
style="cursor: pointer;">
|
style="cursor: pointer;">
|
||||||
</vn-icon>
|
</vn-icon>
|
||||||
</append>
|
</append>
|
||||||
</vn-textfield>
|
</vn-datalist>
|
||||||
</vn-vertical>
|
</vn-vertical>
|
||||||
<vn-popover
|
<vn-popover
|
||||||
vn-id="popover"
|
vn-id="popover"
|
||||||
|
|
|
@ -19,7 +19,7 @@ class Controller {
|
||||||
];
|
];
|
||||||
this.defaultOrderFields = [
|
this.defaultOrderFields = [
|
||||||
{field: 'relevancy DESC, name', name: 'Relevancy'},
|
{field: 'relevancy DESC, name', name: 'Relevancy'},
|
||||||
{field: 'showOrder, price', name: 'Color'},
|
{field: 'showOrder, price', name: 'Color and price'},
|
||||||
{field: 'name', name: 'Name'},
|
{field: 'name', name: 'Name'},
|
||||||
{field: 'price', name: 'Price'}
|
{field: 'price', name: 'Price'}
|
||||||
];
|
];
|
||||||
|
@ -69,37 +69,8 @@ class Controller {
|
||||||
|
|
||||||
if (!value) return;
|
if (!value) return;
|
||||||
|
|
||||||
const newFilterList = [];
|
this.buildTagsFilter(value);
|
||||||
value.forEach(item => {
|
this.buildOrderFilter(value);
|
||||||
// Add new tag filters
|
|
||||||
item.tags.forEach(itemTag => {
|
|
||||||
const alreadyAdded = newFilterList.findIndex(filter => {
|
|
||||||
return filter.field == itemTag.tagFk;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (alreadyAdded == -1) {
|
|
||||||
newFilterList.push({
|
|
||||||
name: itemTag.name,
|
|
||||||
field: itemTag.tagFk,
|
|
||||||
isTag: true
|
|
||||||
});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
// Add default filters - Replaces tags with same name
|
|
||||||
this.defaultOrderFields.forEach(orderField => {
|
|
||||||
const index = newFilterList.findIndex(newfield => {
|
|
||||||
return newfield.name == orderField.name;
|
|
||||||
});
|
|
||||||
|
|
||||||
if (index > -1)
|
|
||||||
newFilterList[index] = orderField;
|
|
||||||
else
|
|
||||||
newFilterList.push(orderField);
|
|
||||||
});
|
|
||||||
|
|
||||||
this.orderFields = newFilterList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
get categoryId() {
|
get categoryId() {
|
||||||
|
@ -273,6 +244,43 @@ class Controller {
|
||||||
|
|
||||||
this.$state.go(this.$state.current.name, params);
|
this.$state.go(this.$state.current.name, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
buildTagsFilter(items) {
|
||||||
|
const tagValues = [];
|
||||||
|
items.forEach(item => {
|
||||||
|
item.tags.forEach(itemTag => {
|
||||||
|
const alreadyAdded = tagValues.findIndex(tag => {
|
||||||
|
return tag.value == itemTag.value;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (alreadyAdded == -1)
|
||||||
|
tagValues.push(itemTag);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
this.tagValues = tagValues;
|
||||||
|
}
|
||||||
|
|
||||||
|
buildOrderFilter(items) {
|
||||||
|
const tags = [];
|
||||||
|
items.forEach(item => {
|
||||||
|
item.tags.forEach(itemTag => {
|
||||||
|
const alreadyAdded = tags.findIndex(tag => {
|
||||||
|
return tag.field == itemTag.tagFk;
|
||||||
|
});
|
||||||
|
|
||||||
|
if (alreadyAdded == -1) {
|
||||||
|
tags.push({
|
||||||
|
name: itemTag.name,
|
||||||
|
field: itemTag.tagFk,
|
||||||
|
isTag: true
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
let newFilterList = [].concat(this.defaultOrderFields);
|
||||||
|
newFilterList = newFilterList.concat(tags);
|
||||||
|
this.orderFields = newFilterList;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Controller.$inject = ['$http', '$scope', '$state', '$compile', '$transitions'];
|
Controller.$inject = ['$http', '$scope', '$state', '$compile', '$transitions'];
|
||||||
|
|
|
@ -37,16 +37,19 @@ describe('Order', () => {
|
||||||
|
|
||||||
describe('items() setter', () => {
|
describe('items() setter', () => {
|
||||||
it(`should return an object with order params`, () => {
|
it(`should return an object with order params`, () => {
|
||||||
let expectedResult = [{field: 'showOrder, price', name: 'Color'}];
|
spyOn(controller, 'buildTagsFilter');
|
||||||
let unexpectedResult = [{tagFk: 5, name: 'Color'}];
|
spyOn(controller, 'buildOrderFilter').and.callThrough();
|
||||||
controller.items = [{id: 1, name: 'My Item', tags: [
|
const expectedResult = [{field: 'showOrder, price', name: 'Color and price'}];
|
||||||
|
const items = [{id: 1, name: 'My Item', tags: [
|
||||||
{tagFk: 4, name: 'Length'},
|
{tagFk: 4, name: 'Length'},
|
||||||
{tagFk: 5, name: 'Color'}
|
{tagFk: 5, name: 'Color'}
|
||||||
]}];
|
]}];
|
||||||
|
controller.items = items;
|
||||||
|
|
||||||
expect(controller.orderFields.length).toEqual(5);
|
expect(controller.orderFields.length).toEqual(6);
|
||||||
expect(controller.orderFields).toEqual(jasmine.arrayContaining(expectedResult));
|
expect(controller.orderFields).toEqual(jasmine.arrayContaining(expectedResult));
|
||||||
expect(controller.orderFields).not.toEqual(jasmine.arrayContaining(unexpectedResult));
|
expect(controller.buildTagsFilter).toHaveBeenCalledWith(items);
|
||||||
|
expect(controller.buildOrderFilter).toHaveBeenCalledWith(items);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -222,6 +225,48 @@ describe('Order', () => {
|
||||||
expect(controller.$.model.addFilter).toHaveBeenCalledWith(null, expectedOrder);
|
expect(controller.$.model.addFilter).toHaveBeenCalledWith(null, expectedOrder);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe('buildTagsFilter()', () => {
|
||||||
|
it(`should create an array of non repeated tag values and then set the tagValues property`, () => {
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
|
id: 1, name: 'My Item 1', tags: [
|
||||||
|
{tagFk: 4, name: 'Length', value: 1},
|
||||||
|
{tagFk: 5, name: 'Color', value: 'red'}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2, name: 'My Item 2', tags: [
|
||||||
|
{tagFk: 4, name: 'Length', value: 1},
|
||||||
|
{tagFk: 5, name: 'Color', value: 'blue'}
|
||||||
|
]
|
||||||
|
}];
|
||||||
|
controller.buildTagsFilter(items);
|
||||||
|
|
||||||
|
expect(controller.tagValues.length).toEqual(3);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('buildOrderFilter()', () => {
|
||||||
|
it(`should create an array of non repeated tags plus default filters and then set the orderFields property`, () => {
|
||||||
|
const items = [
|
||||||
|
{
|
||||||
|
id: 1, name: 'My Item 1', tags: [
|
||||||
|
{tagFk: 4, name: 'Length'},
|
||||||
|
{tagFk: 5, name: 'Color'}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
id: 2, name: 'My Item 2', tags: [
|
||||||
|
{tagFk: 5, name: 'Color'},
|
||||||
|
{tagFk: 6, name: 'Relevancy'}
|
||||||
|
]
|
||||||
|
}];
|
||||||
|
controller.buildOrderFilter(items);
|
||||||
|
|
||||||
|
expect(controller.orderFields.length).toEqual(7);
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -16,6 +16,7 @@ Item id: Id de artículo
|
||||||
Order by: Ordenar por
|
Order by: Ordenar por
|
||||||
Order: Orden
|
Order: Orden
|
||||||
Price: Precio
|
Price: Precio
|
||||||
|
Color and price: Color y precio
|
||||||
Ascendant: Ascendente
|
Ascendant: Ascendente
|
||||||
Descendant: Descendente
|
Descendant: Descendente
|
||||||
Created from: Creado desde
|
Created from: Creado desde
|
||||||
|
|
Loading…
Reference in New Issue