2018-07-24 07:35:23 +00:00
|
|
|
import ngModule from '../module';
|
2018-09-14 07:10:30 +00:00
|
|
|
import './style.scss';
|
2018-07-24 07:35:23 +00:00
|
|
|
|
|
|
|
class Controller {
|
2018-10-31 13:56:54 +00:00
|
|
|
constructor($scope, $state) {
|
2018-07-24 07:35:23 +00:00
|
|
|
this.$scope = $scope;
|
2018-09-18 07:37:54 +00:00
|
|
|
this.$state = $state;
|
2019-08-07 05:27:00 +00:00
|
|
|
this.$stateParams = $state.params;
|
2018-10-31 13:56:54 +00:00
|
|
|
|
|
|
|
// Static autocomplete data
|
2019-10-28 16:31:33 +00:00
|
|
|
this.orderWays = [
|
2018-10-31 13:56:54 +00:00
|
|
|
{way: 'ASC', name: 'Ascendant'},
|
|
|
|
{way: 'DESC', name: 'Descendant'},
|
2018-09-14 07:10:30 +00:00
|
|
|
];
|
2019-10-28 16:31:33 +00:00
|
|
|
this.defaultOrderFields = [
|
|
|
|
{field: 'relevancy DESC, name', name: 'Relevancy'},
|
2019-02-19 14:13:27 +00:00
|
|
|
{field: 'showOrder, price', name: 'Color'},
|
|
|
|
{field: 'name', name: 'Name'},
|
2018-10-31 13:56:54 +00:00
|
|
|
{field: 'price', name: 'Price'}
|
|
|
|
];
|
2019-10-28 16:31:33 +00:00
|
|
|
this.orderFields = [].concat(this.defaultOrderFields);
|
|
|
|
this._orderWay = this.orderWays[0].way;
|
|
|
|
this._orderField = this.orderFields[0].field;
|
2018-07-24 07:35:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 13:56:54 +00:00
|
|
|
/**
|
|
|
|
* Fills order autocomplete with tags
|
|
|
|
* obtained from last filtered
|
|
|
|
*/
|
|
|
|
onDataChange() {
|
|
|
|
const items = this.$scope.model.data;
|
2019-02-19 14:13:27 +00:00
|
|
|
const newFilterList = [];
|
2018-10-31 13:56:54 +00:00
|
|
|
if (!items) return;
|
|
|
|
|
|
|
|
items.forEach(item => {
|
2019-02-19 14:13:27 +00:00
|
|
|
// Add new tag filters
|
2018-10-31 13:56:54 +00:00
|
|
|
item.tags.forEach(itemTag => {
|
2019-02-19 14:13:27 +00:00
|
|
|
const alreadyAdded = newFilterList.findIndex(filter => {
|
|
|
|
return filter.field == itemTag.tagFk;
|
2018-10-31 13:56:54 +00:00
|
|
|
});
|
|
|
|
|
2019-02-19 14:13:27 +00:00
|
|
|
if (alreadyAdded == -1) {
|
|
|
|
newFilterList.push({
|
2018-10-31 13:56:54 +00:00
|
|
|
name: itemTag.name,
|
|
|
|
field: itemTag.tagFk,
|
|
|
|
isTag: true
|
|
|
|
});
|
2019-01-23 10:08:27 +00:00
|
|
|
}
|
2018-10-31 13:56:54 +00:00
|
|
|
});
|
|
|
|
});
|
2019-02-19 14:13:27 +00:00
|
|
|
|
|
|
|
// Add default filters - Replaces tags with same name
|
2019-10-28 16:31:33 +00:00
|
|
|
this.defaultOrderFields.forEach(orderField => {
|
2019-02-19 14:13:27 +00:00
|
|
|
const index = newFilterList.findIndex(newfield => {
|
2019-10-28 16:31:33 +00:00
|
|
|
return newfield.name == orderField.name;
|
2019-02-19 14:13:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
if (index > -1)
|
2019-10-28 16:31:33 +00:00
|
|
|
newFilterList[index] = orderField;
|
2019-02-19 14:13:27 +00:00
|
|
|
else
|
2019-10-28 16:31:33 +00:00
|
|
|
newFilterList.push(orderField);
|
2019-02-19 14:13:27 +00:00
|
|
|
});
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
this.orderFields = newFilterList;
|
2018-07-24 07:35:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 13:56:54 +00:00
|
|
|
/**
|
|
|
|
* Get order way ASC/DESC
|
|
|
|
*/
|
2019-10-28 16:31:33 +00:00
|
|
|
get orderWay() {
|
|
|
|
return this._orderWay;
|
2018-07-24 07:35:23 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
set orderWay(value) {
|
|
|
|
this._orderWay = value;
|
2019-04-24 07:21:24 +00:00
|
|
|
if (value) this.applyOrder();
|
2018-10-31 13:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get order fields
|
|
|
|
*/
|
2019-10-28 16:31:33 +00:00
|
|
|
get orderField() {
|
|
|
|
return this._orderField;
|
2018-10-31 13:56:54 +00:00
|
|
|
}
|
|
|
|
|
2019-10-28 16:31:33 +00:00
|
|
|
set orderField(value) {
|
|
|
|
this._orderField = value;
|
2019-04-24 07:21:24 +00:00
|
|
|
if (value) this.applyOrder();
|
2018-10-31 13:56:54 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns order param
|
|
|
|
*
|
|
|
|
* @return {Object} - Order param
|
|
|
|
*/
|
|
|
|
getOrderBy() {
|
2019-10-28 16:31:33 +00:00
|
|
|
return {
|
|
|
|
field: this.orderField,
|
|
|
|
way: this.orderWay,
|
|
|
|
isTag: !!(this.orderSelection && this.orderSelection.isTag)
|
2018-10-31 13:56:54 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Apply order to model
|
|
|
|
*/
|
|
|
|
applyOrder() {
|
|
|
|
this.$scope.model.addFilter(null, {orderBy: this.getOrderBy()});
|
2018-07-24 07:35:23 +00:00
|
|
|
}
|
2018-08-20 07:01:38 +00:00
|
|
|
|
2018-08-21 11:38:16 +00:00
|
|
|
preview(event, item) {
|
|
|
|
event.preventDefault();
|
2018-08-20 07:01:38 +00:00
|
|
|
this.$scope.pricesPopover.show(event, item);
|
|
|
|
}
|
|
|
|
|
|
|
|
onDescriptorLoad() {
|
|
|
|
this.$scope.popover.relocate();
|
|
|
|
}
|
2018-09-18 07:37:54 +00:00
|
|
|
|
|
|
|
$onChanges() {
|
2018-10-31 13:56:54 +00:00
|
|
|
if (this.order && this.order.isConfirmed)
|
2018-09-18 07:37:54 +00:00
|
|
|
this.$state.go('order.card.line');
|
|
|
|
}
|
2018-07-24 07:35:23 +00:00
|
|
|
}
|
|
|
|
|
2018-10-31 13:56:54 +00:00
|
|
|
Controller.$inject = ['$scope', '$state'];
|
2018-07-24 07:35:23 +00:00
|
|
|
|
2018-08-21 11:38:16 +00:00
|
|
|
ngModule.component('vnOrderCatalog', {
|
2018-07-24 07:35:23 +00:00
|
|
|
template: require('./index.html'),
|
|
|
|
controller: Controller,
|
|
|
|
bindings: {
|
2018-10-31 13:56:54 +00:00
|
|
|
order: '<',
|
2019-01-30 22:47:06 +00:00
|
|
|
}
|
2018-07-24 07:35:23 +00:00
|
|
|
});
|