This commit is contained in:
parent
b7db5f969b
commit
d11a51b3f1
|
@ -75,9 +75,9 @@ export default class ArrayModel extends ModelProxy {
|
|||
});
|
||||
}
|
||||
|
||||
data.sort((a, b) => this.sortFunc(a, b, orderComp));
|
||||
data = data.sort((a, b) => this.sortFunc(a, b, orderComp));
|
||||
} else if (typeof order === 'function')
|
||||
data.sort(order);
|
||||
data = data.sort(order);
|
||||
|
||||
this.skip = skip;
|
||||
|
||||
|
|
|
@ -14,4 +14,8 @@ vn-check {
|
|||
md-checkbox.md-checked .md-icon {
|
||||
background-color: $color-main;
|
||||
}
|
||||
|
||||
md-checkbox {
|
||||
margin-bottom: 0
|
||||
}
|
||||
}
|
||||
|
|
|
@ -111,6 +111,7 @@ module.exports = Self => {
|
|||
FROM tmp.ticketCalculateItem tci
|
||||
JOIN vn.item i ON i.id = tci.itemFk
|
||||
JOIN vn.itemType it ON it.id = i.typeFk
|
||||
JOIN vn.ink ON ink.id = i.inkFk
|
||||
JOIN vn.worker w on w.id = it.workerFk`);
|
||||
|
||||
// Apply order by tag
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
initial-data="$ctrl.field"
|
||||
field="$ctrl.field"
|
||||
translate-fields="['name']"
|
||||
order="name"
|
||||
show-field="name"
|
||||
value-field="field"
|
||||
label="Order by">
|
||||
|
|
|
@ -12,7 +12,9 @@ class Controller {
|
|||
{way: 'DESC', name: 'Descendant'},
|
||||
];
|
||||
this.defaultFieldList = [
|
||||
{field: 'relevancy DESC, name', name: 'Name'},
|
||||
{field: 'relevancy DESC, name', name: 'Default'},
|
||||
{field: 'showOrder, price', name: 'Color'},
|
||||
{field: 'name', name: 'Name'},
|
||||
{field: 'price', name: 'Price'}
|
||||
];
|
||||
this.fieldList = [];
|
||||
|
@ -27,20 +29,18 @@ class Controller {
|
|||
*/
|
||||
onDataChange() {
|
||||
const items = this.$scope.model.data;
|
||||
|
||||
const newFilterList = [];
|
||||
if (!items) return;
|
||||
|
||||
this.fieldList = [];
|
||||
this.fieldList = this.fieldList.concat(this.defaultFieldList);
|
||||
|
||||
items.forEach(item => {
|
||||
// Add new tag filters
|
||||
item.tags.forEach(itemTag => {
|
||||
const alreadyAdded = this.fieldList.find(order => {
|
||||
return order.field == itemTag.tagFk;
|
||||
const alreadyAdded = newFilterList.findIndex(filter => {
|
||||
return filter.field == itemTag.tagFk;
|
||||
});
|
||||
|
||||
if (!alreadyAdded) {
|
||||
this.fieldList.push({
|
||||
if (alreadyAdded == -1) {
|
||||
newFilterList.push({
|
||||
name: itemTag.name,
|
||||
field: itemTag.tagFk,
|
||||
isTag: true
|
||||
|
@ -48,6 +48,20 @@ class Controller {
|
|||
}
|
||||
});
|
||||
});
|
||||
|
||||
// Add default filters - Replaces tags with same name
|
||||
this.defaultFieldList.forEach(defaultField => {
|
||||
const index = newFilterList.findIndex(newfield => {
|
||||
return newfield.name == defaultField.name;
|
||||
});
|
||||
|
||||
if (index > -1)
|
||||
newFilterList[index] = defaultField;
|
||||
else
|
||||
newFilterList.push(defaultField);
|
||||
});
|
||||
|
||||
this.fieldList = newFilterList;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -17,18 +17,17 @@ describe('Order', () => {
|
|||
|
||||
describe('onDataChange()', () => {
|
||||
it(`should return an object with order params`, () => {
|
||||
let expectedList = [
|
||||
{field: 'relevancy DESC, name', name: 'Name'},
|
||||
{field: 'price', name: 'Price'},
|
||||
{field: 4, name: 'Length', isTag: true}
|
||||
];
|
||||
$scope.model.data = [{id: 1, name: 'My Item', tags: [
|
||||
{tagFk: 4, name: 'Length'}
|
||||
{tagFk: 4, name: 'Length'},
|
||||
{tagFk: 5, name: 'Color'}
|
||||
]}];
|
||||
|
||||
let expectedResult = [{field: 'showOrder, price', name: 'Color'}];
|
||||
let unexpectedResult = [{tagFk: 5, name: 'Color'}];
|
||||
controller.onDataChange();
|
||||
|
||||
expect(controller.fieldList).toEqual(expectedList);
|
||||
expect(controller.fieldList.length).toEqual(5);
|
||||
expect(controller.fieldList).toEqual(jasmine.arrayContaining(expectedResult));
|
||||
expect(controller.fieldList).not.toEqual(jasmine.arrayContaining(unexpectedResult));
|
||||
});
|
||||
});
|
||||
|
||||
|
|
Loading…
Reference in New Issue