2021-06-04 10:37:47 +03:00
|
|
|
import Component from '@glimmer/component';
|
|
|
|
import {action} from '@ember/object';
|
|
|
|
import {inject as service} from '@ember/service';
|
|
|
|
import {tracked} from '@glimmer/tracking';
|
|
|
|
|
2022-01-31 21:26:12 +03:00
|
|
|
const TYPES = [{
|
|
|
|
name: 'Active',
|
|
|
|
value: 'active'
|
|
|
|
},{
|
|
|
|
name: 'Archived',
|
|
|
|
value: 'archived'
|
|
|
|
}];
|
|
|
|
|
2021-06-04 10:37:47 +03:00
|
|
|
export default class extends Component {
|
|
|
|
@service membersUtils;
|
|
|
|
@service ghostPaths;
|
|
|
|
@service ajax;
|
|
|
|
@service store;
|
|
|
|
@service config;
|
|
|
|
|
|
|
|
@tracked showProductModal = false;
|
|
|
|
@tracked productModel = null;
|
2022-01-31 21:26:12 +03:00
|
|
|
@tracked type = 'active';
|
2021-06-04 10:37:47 +03:00
|
|
|
|
|
|
|
get products() {
|
2022-01-31 21:26:12 +03:00
|
|
|
return this.args.products.filter((product) => {
|
|
|
|
if (this.type === 'active') {
|
|
|
|
return !!product.active;
|
|
|
|
} else if (this.type === 'archived') {
|
|
|
|
return !product.active;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get availableTypes() {
|
|
|
|
return TYPES;
|
|
|
|
}
|
|
|
|
|
|
|
|
get selectedType() {
|
|
|
|
return this.type ? TYPES.find((d) => {
|
|
|
|
return this.type === d.value;
|
|
|
|
}) : TYPES[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
get isEmptyList() {
|
|
|
|
return this.products.length === 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
onTypeChange(type) {
|
|
|
|
this.type = type.value;
|
2021-06-04 10:37:47 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async openEditProduct(product) {
|
|
|
|
this.productModel = product;
|
|
|
|
this.showProductModal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
async openNewProduct() {
|
|
|
|
this.productModel = this.store.createRecord('product');
|
|
|
|
this.showProductModal = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
closeProductModal() {
|
|
|
|
this.showProductModal = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
@action
|
|
|
|
confirmProductSave() {
|
|
|
|
this.args.confirmProductSave();
|
|
|
|
}
|
|
|
|
}
|