UNPKG

@lipagas/storefront-engine

Version:

Headless Commerce & Marketplace Extension for Fleetbase

341 lines (326 loc) 10.1 kB
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} */ @service notifications; /** * Inject the `intl` service * * @var {Service} */ @service intl; /** * Inject the `modals-manager` service * * @var {Service} */ @service modalsManager; /** * Inject the `crud` service * * @var {Service} */ @service crud; /** * Inject the `fetch` service * * @var {Service} */ @service fetch; /** * Inject the `filters` service * * @var {Service} */ @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', ]; @tracked page = 1; @tracked limit; @tracked query; @tracked sort = '-created_at'; @tracked public_id; @tracked internal_id; @tracked tracking; @tracked facilitator; @tracked customer; @tracked driver; @tracked payload; @tracked pickup; @tracked dropoff; @tracked updated_by; @tracked created_by; @tracked status; @tracked 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 */ @task({ restartable: true }) *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; } @action viewOrder(order) { return this.transitionToRoute('orders.index.view', order); } }