From d11a51b3f134c28acc37c92409502a877d1a4699 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 19 Feb 2019 15:13:27 +0100 Subject: [PATCH] added color filter #1041 --- .../components/array-model/array-model.js | 4 +-- front/core/components/check/style.scss | 4 +++ .../order/back/methods/order/catalogFilter.js | 1 + modules/order/front/catalog/index.html | 1 + modules/order/front/catalog/index.js | 32 +++++++++++++------ modules/order/front/catalog/index.spec.js | 15 ++++----- 6 files changed, 38 insertions(+), 19 deletions(-) diff --git a/front/core/components/array-model/array-model.js b/front/core/components/array-model/array-model.js index e1bbb7eea..3697abc3b 100644 --- a/front/core/components/array-model/array-model.js +++ b/front/core/components/array-model/array-model.js @@ -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; diff --git a/front/core/components/check/style.scss b/front/core/components/check/style.scss index 696e1dc0c..0804a5750 100644 --- a/front/core/components/check/style.scss +++ b/front/core/components/check/style.scss @@ -14,4 +14,8 @@ vn-check { md-checkbox.md-checked .md-icon { background-color: $color-main; } + + md-checkbox { + margin-bottom: 0 + } } diff --git a/modules/order/back/methods/order/catalogFilter.js b/modules/order/back/methods/order/catalogFilter.js index 7c609ec8d..9fa74647c 100644 --- a/modules/order/back/methods/order/catalogFilter.js +++ b/modules/order/back/methods/order/catalogFilter.js @@ -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 diff --git a/modules/order/front/catalog/index.html b/modules/order/front/catalog/index.html index 8fda4bd70..adf7e46cd 100644 --- a/modules/order/front/catalog/index.html +++ b/modules/order/front/catalog/index.html @@ -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"> diff --git a/modules/order/front/catalog/index.js b/modules/order/front/catalog/index.js index ec28df420..bc9bd20d5 100644 --- a/modules/order/front/catalog/index.js +++ b/modules/order/front/catalog/index.js @@ -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; } /** diff --git a/modules/order/front/catalog/index.spec.js b/modules/order/front/catalog/index.spec.js index 3f3c49c64..98494b3ca 100644 --- a/modules/order/front/catalog/index.spec.js +++ b/modules/order/front/catalog/index.spec.js @@ -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)); }); });