@lipagas/storefront-engine
Version:
Headless Commerce & Marketplace Extension for Fleetbase
341 lines (326 loc) • 10.1 kB
JavaScript
import { action } from '@ember/object';
import { inject as service } from '@ember/service';
import { isBlank } from '@ember/utils';
import BaseController from '@lipagas/storefront-engine/controllers/base-controller';
import { tracked } from '@glimmer/tracking';
import { timeout } from 'ember-concurrency';
import { task } from 'ember-concurrency-decorators';
export default class OrdersIndexController extends BaseController {
/**
* Inject the `notifications` service
*
* @var {Service}
*/
notifications;
/**
* Inject the `intl` service
*
* @var {Service}
*/
intl;
/**
* 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;
/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
queryParams = [
'page',
'limit',
'sort',
'query',
'public_id',
'internal_id',
'payload',
'tracking_number',
'facilitator',
'customer',
'driver',
'pickup',
'dropoff',
'created_by',
'updated_by',
'status',
];
page = 1;
limit;
query;
sort = '-created_at';
public_id;
internal_id;
tracking;
facilitator;
customer;
driver;
payload;
pickup;
dropoff;
updated_by;
created_by;
status;
columns = [
{
label: this.intl.t('storefront.common.id'),
valuePath: 'public_id',
width: '150px',
cellComponent: 'table/cell/anchor',
onClick: this.viewOrder,
resizable: true,
sortable: true,
filterable: true,
},
{
label: this.intl.t('storefront.orders.index.internal-id'),
valuePath: 'internal_id',
width: '125px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.orders.index.customer'),
valuePath: 'customer.name',
cellComponent: 'table/cell/base',
width: '125px',
resizable: true,
sortable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/model',
filterComponentPlaceholder: this.intl.t('storefront.orders.index.select-order-customer'),
filterParam: 'customer',
model: 'customer',
},
{
label: this.intl.t('storefront.common.pickup'),
valuePath: 'pickupName',
cellComponent: 'table/cell/base',
width: '160px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/model',
filterComponentPlaceholder: this.intl.t('storefront.orders.index.select-order-pickup-location'),
filterParam: 'pickup',
model: 'place',
},
{
label: this.intl.t('storefront.common.dropoff'),
valuePath: 'dropoffName',
cellComponent: 'table/cell/base',
width: '160px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/model',
filterComponentPlaceholder: this.intl.t('storefront.orders.index.select-order-dropoff-location'),
filterParam: 'dropoff',
model: 'place',
},
{
label: this.intl.t('storefront.orders.index.scheduled-at'),
valuePath: 'scheduledAt',
sortParam: 'scheduled_at',
filterParam: 'scheduled_at',
width: '150px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: '# Items',
cellComponent: 'table/cell/base',
valuePath: 'item_count',
resizable: true,
hidden: true,
width: '50px',
},
{
label: this.intl.t('storefront.orders.index.transaction-total'),
cellComponent: 'table/cell/base',
valuePath: 'transaction_amount',
width: '50px',
resizable: true,
hidden: true,
sortable: true,
},
{
label: this.intl.t('storefront.orders.index.tracking-number'),
cellComponent: 'table/cell/base',
valuePath: 'tracking_number.tracking_number',
width: '170px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('storefront.orders.index.driver-assigned'),
cellComponent: 'table/cell/driver-name',
valuePath: 'driver_assigned',
modelPath: 'driver_assigned',
width: '170px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/model',
filterComponentPlaceholder: this.intl.t('storefront.orders.index.select-driver-for-order'),
filterParam: 'driver',
model: 'driver',
query: {
// no model, serializer, adapter for relations
without: ['fleets', 'vendor', 'vehicle', 'currentJob'],
},
},
{
label: this.intl.t('storefront.common.type'),
cellComponent: 'cell/humanize',
valuePath: 'type',
width: '100px',
resizable: true,
hidden: true,
sortable: true,
},
{
label: this.intl.t('storefront.common.status'),
valuePath: 'status',
cellComponent: 'table/cell/status',
width: '120px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/multi-option',
// filterOptions: this.statusOptions,
},
{
label: this.intl.t('storefront.orders.index.created-at'),
valuePath: 'createdAt',
sortParam: 'created_at',
filterParam: 'created_at',
width: '140px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: this.intl.t('storefront.orders.index.updated-at'),
valuePath: 'updatedAt',
sortParam: 'updated_at',
filterParam: 'updated_at',
width: '125px',
resizable: true,
sortable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: this.intl.t('storefront.orders.index.created-by'),
valuePath: 'created_by_name',
width: '125px',
resizable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/model',
filterComponentPlaceholder: 'Select user',
filterParam: 'created_by',
model: 'user',
},
{
label: this.intl.t('storefront.orders.index.updated-by'),
valuePath: 'updated_by_name',
width: '125px',
resizable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/model',
filterComponentPlaceholder: this.intl.t('storefront.orders.index.select-user'),
filterParam: 'updated_by',
model: 'user',
},
{
label: '',
cellComponent: 'table/cell/dropdown',
ddButtonText: false,
ddButtonIcon: 'ellipsis-h',
ddButtonIconPrefix: 'fas',
ddMenuLabel: 'Order Actions',
cellClassNames: 'overflow-visible',
wrapperClass: 'flex items-center justify-end mx-2',
width: '12%',
actions: [
{
label: this.intl.t('storefront.orders.index.view-order'),
icon: 'eye',
fn: this.viewOrder,
},
{
label: this.intl.t('storefront.orders.index.cancel-order'),
icon: 'ban',
fn: this.cancelOrder,
},
{
separator: true,
},
{
label: this.intl.t('storefront.orders.index.delete-order'),
icon: 'trash',
fn: this.deleteOrder,
},
],
sortable: false,
filterable: false,
resizable: false,
searchable: false,
},
];
/**
* 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;
}
viewOrder(order) {
return this.transitionToRoute('orders.index.view', order);
}
}