diff --git a/client/helpers/crudModelHelper.js b/client/helpers/crudModelHelper.js
index a9e29e882..8bd33a955 100644
--- a/client/helpers/crudModelHelper.js
+++ b/client/helpers/crudModelHelper.js
@@ -18,5 +18,7 @@ module.exports.crudModel = {
accept();
});
},
- refresh: () => {}
+ refresh: () => {},
+ addFilter: () => {},
+ applyFilter: () => {}
};
diff --git a/client/order/src/catalog/index.html b/client/order/src/catalog/index.html
index 5485c41a8..ec21fb2ea 100644
--- a/client/order/src/catalog/index.html
+++ b/client/order/src/catalog/index.html
@@ -1,9 +1,9 @@
-
+ data="items" on-data-change="$ctrl.onDataChange()" >
@@ -11,17 +11,28 @@
@@ -78,14 +89,14 @@
-
+
No results
-
diff --git a/client/order/src/catalog/index.js b/client/order/src/catalog/index.js
index a6b6e302b..0b38a4d9e 100644
--- a/client/order/src/catalog/index.js
+++ b/client/order/src/catalog/index.js
@@ -2,48 +2,104 @@ import ngModule from '../module';
import './style.scss';
class Controller {
- constructor($scope, $state, $translate) {
+ constructor($scope, $state) {
this.$scope = $scope;
this.$state = $state;
- this.orderList = [
- {
- order: 'relevancy DESC, name',
- name: $translate.instant('Default order')
- },
- {
- order: 'name',
- name: $translate.instant('Ascendant name')
- },
- {
- order: 'name DESC',
- name: $translate.instant('Descendant name')
- },
- {
- order: 'price',
- name: $translate.instant('Ascendant price')
- },
- {
- order: 'price DESC',
- name: $translate.instant('Descendant price')
- }
+
+ // Static autocomplete data
+ this.wayList = [
+ {way: 'ASC', name: 'Ascendant'},
+ {way: 'DESC', name: 'Descendant'},
];
- this.orderBy = this.orderList[0].order;
- this.filter = {
- order: this.orderBy
+ this.defaultFieldList = [
+ {field: 'relevancy DESC, name', name: 'Name'},
+ {field: 'price', name: 'Price'}
+ ];
+ this.fieldList = [];
+ this.fieldList = this.fieldList.concat(this.defaultFieldList);
+ this._way = this.wayList[0].way;
+ this._field = this.fieldList[0].field;
+ }
+
+ /**
+ * Fills order autocomplete with tags
+ * obtained from last filtered
+ */
+ onDataChange() {
+ const items = this.$scope.model.data;
+
+ if (!items) return;
+
+ this.fieldList = [];
+ this.fieldList = this.fieldList.concat(this.defaultFieldList);
+
+ items.forEach(item => {
+ item.tags.forEach(itemTag => {
+ const alreadyAdded = this.fieldList.find(order => {
+ return order.field == itemTag.tagFk;
+ });
+
+ if (!alreadyAdded)
+ this.fieldList.push({
+ name: itemTag.name,
+ field: itemTag.tagFk,
+ isTag: true
+ });
+ });
+ });
+ }
+
+ /**
+ * Get order way ASC/DESC
+ */
+ get way() {
+ return this._way;
+ }
+
+ set way(value) {
+ this._way = value;
+
+ if (value)
+ this.applyOrder();
+ }
+
+ /**
+ * Get order fields
+ */
+ get field() {
+ return this._field;
+ }
+
+ set field(value) {
+ this._field = value;
+
+ if (value)
+ this.applyOrder();
+ }
+
+ /**
+ * Returns order param
+ *
+ * @return {Object} - Order param
+ */
+ getOrderBy() {
+ let field = this.$scope.field;
+ let args = {
+ field: this.field,
+ way: this.way
};
+
+ if (field.selection && field.selection.isTag)
+ args.isTag = true;
+
+ return args;
}
- get orderBy() {
- return this._orderBy;
- }
-
- set orderBy(value) {
- this._orderBy = value;
- }
-
- setOrder(order) {
- this.$scope.model.filter.order = order;
- this.$scope.model.refresh();
+ /**
+ * Apply order to model
+ */
+ applyOrder() {
+ this.$scope.model.addFilter(null, {orderBy: this.getOrderBy()});
}
preview(event, item) {
@@ -56,18 +112,17 @@ class Controller {
}
$onChanges() {
- if (this.order && this.order.isConfirmed) {
+ if (this.order && this.order.isConfirmed)
this.$state.go('order.card.line');
- }
}
}
-Controller.$inject = ['$scope', '$state', '$translate'];
+Controller.$inject = ['$scope', '$state'];
ngModule.component('vnOrderCatalog', {
template: require('./index.html'),
controller: Controller,
bindings: {
- order: '<'
- }
+ order: '<',
+ },
});
diff --git a/client/order/src/catalog/index.spec.js b/client/order/src/catalog/index.spec.js
index 7606bafe3..13f3e041b 100644
--- a/client/order/src/catalog/index.spec.js
+++ b/client/order/src/catalog/index.spec.js
@@ -15,16 +15,49 @@ describe('Order', () => {
$componentController = _$componentController_;
$scope = $rootScope.$new();
$scope.model = crudModel;
+ $scope.field = {};
controller = $componentController('vnOrderCatalog', {$scope: $scope});
}));
- describe('setOrder()', () => {
- it(`should apply filter order and call model refresh() method`, () => {
- spyOn(controller.$scope.model, 'refresh');
- controller.setOrder('relevancy DESC');
+ 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'}
+ ]}];
- expect(controller.$scope.model.filter.order).toEqual('relevancy DESC');
- expect(controller.$scope.model.refresh).toHaveBeenCalledWith();
+ controller.onDataChange();
+
+ expect(controller.fieldList).toEqual(expectedList);
+ });
+ });
+
+ describe('getOrderBy()', () => {
+ it(`should return an object with order params`, () => {
+ controller.field = 'relevancy DESC, name';
+ controller.way = 'DESC';
+ let expectedResult = {field: 'relevancy DESC, name', way: 'DESC'};
+ let result = controller.getOrderBy();
+
+ expect(result).toEqual(expectedResult);
+ });
+ });
+
+ describe('applyOrder()', () => {
+ it(`should apply order param to model calling getOrderBy()`, () => {
+ controller.field = 'relevancy DESC, name';
+ controller.way = 'ASC';
+ let expectedOrder = {orderBy: controller.getOrderBy()};
+ spyOn(controller, 'getOrderBy').and.callThrough();
+ spyOn(controller.$scope.model, 'addFilter');
+ controller.applyOrder();
+
+ expect(controller.getOrderBy).toHaveBeenCalledWith();
+ expect(controller.$scope.model.addFilter).toHaveBeenCalledWith(null, expectedOrder);
});
});
});
diff --git a/client/order/src/filter/index.html b/client/order/src/filter/index.html
index f94a23564..ddf2e6ffc 100644
--- a/client/order/src/filter/index.html
+++ b/client/order/src/filter/index.html
@@ -21,7 +21,6 @@
-