@myorders/storefront-engine
Version:
Headless Commerce & Marketplace Extension for Myorders
279 lines (257 loc) • 7.21 kB
JavaScript
import { inject as service } from '@ember/service';
import { isBlank } from '@ember/utils';
import BaseController from '@myorders/storefront-engine/controllers/base-controller';
import { tracked } from '@glimmer/tracking';
import { timeout } from 'ember-concurrency';
import { task } from 'ember-concurrency-decorators';
import { action } from '@ember/object';
export default class CustomersIndexController extends BaseController {
/**
* Inject the `notifications` service
*
* @var {Service}
*/
notifications;
/**
* Inject the `modals-manager` service
*
* @var {Service}
*/
modalsManager;
/**
* Inject the `crud` service
*
* @var {Service}
*/
crud;
/**
* Inject the `fetch` service
*
* @var {Service}
*/
fetch;
/**
* Inject the `filters` service
*
* @var {Service}
*/
filters;
/**
* Inject the `intl` service
*
* @var {Service}
*/
intl;
/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'internal_id', 'phone', 'email', 'address', 'created_by', 'updated_by', 'status'];
/**
* The current page of data being viewed
*
* @var {Integer}
*/
page = 1;
/**
* The maximum number of items to show per page
*
* @var {Integer}
*/
limit;
/**
* The param to sort the data on, the param with prepended `-` is descending
*
* @var {String}
*/
sort;
/**
* The filterable param `public_id`
*
* @var {String}
*/
public_id;
/**
* The filterable param `internal_id`
*
* @var {String}
*/
internal_id;
/**
* The filterable param `email`
*
* @var {String}
*/
email;
/**
* The filterable param `phone`
*
* @var {String}
*/
phone;
/**
* The filterable param `status`
*
* @var {Array}
*/
status;
/**
* All columns applicable for orders
*
* @var {Array}
*/
columns = [
{
label: this.intl.t('storefront.common.name'),
valuePath: 'name',
width: '15%',
cellComponent: 'table/cell/media-name',
action: this.viewCustomer,
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.common.id'),
valuePath: 'public_id',
cellComponent: 'click-to-copy',
width: '15%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.customers.index.internal-id'),
valuePath: 'internal_id',
cellComponent: 'click-to-copy',
width: '15%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.common.email'),
valuePath: 'email',
cellComponent: 'table/cell/base',
width: '15%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.common.phone'),
valuePath: 'phone',
cellComponent: 'table/cell/base',
width: '15%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.common.address'),
valuePath: 'address',
cellComponent: 'table/cell/anchor',
// action: this.viewVendorPlace,
width: '30%',
resizable: true,
sortable: true,
filterable: true,
filterParam: 'address',
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.common.country'),
valuePath: 'country',
cellComponent: 'table/cell/base',
cellClassNames: 'uppercase',
width: '10%',
resizable: true,
sortable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.customers.index.create-at'),
valuePath: 'createdAt',
sortParam: 'created_at',
width: '15%',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: this.intl.t('storefront.customers.index.update-at'),
valuePath: 'updatedAt',
sortParam: 'updated_at',
width: '15%',
resizable: true,
sortable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: '',
cellComponent: 'table/cell/dropdown',
ddButtonText: false,
ddButtonIcon: 'ellipsis-h',
ddButtonIconPrefix: 'fas',
ddMenuLabel: this.intl.t('storefront.customers.index.vendor-action'),
cellClassNames: 'overflow-visible',
wrapperClass: 'flex items-center justify-end mx-2',
width: '10%',
actions: [
{
label: this.intl.t('storefront.customers.index.view-customer-details'),
fn: this.viewCustomer,
},
{
label: this.intl.t('storefront.customers.index.edit-customer'),
// fn: this.editVendor,
},
{
separator: true,
},
{
label: this.intl.t('storefront.customers.index.delete-customer'),
// fn: this.deleteVendor,
},
],
sortable: false,
filterable: false,
resizable: false,
searchable: false,
},
];
viewCustomer(customer) {
return this.transitionToRoute('customers.index.view', customer);
}
/**
* The search task.
*
* @void
*/
*search({ target: { value } }) {
// if no query don't search
if (isBlank(value)) {
this.query = null;
return;
}
// timeout for typing
yield timeout(250);
// reset page for results
if (this.page > 1) {
this.page = 1;
}
// update the query param
this.query = value;
}
}