@fleetbase/pallet-engine
Version:
Inventory & Warehouse Management Extension for Fleetbase
289 lines (262 loc) • 6.76 kB
JavaScript
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { action } from '@ember/object';
import { isBlank } from '@ember/utils';
import { timeout } from 'ember-concurrency';
import { task } from 'ember-concurrency-decorators';
export default class PurchaseOrdersIndexController extends Controller {
/**
* Inject the `notifications` service
*
* @var {Service}
*/
notifications;
/**
* Inject the `modals-manager` service
*
* @var {Service}
*/
modalsManager;
/**
* Inject the `crud` service
*
* @var {Service}
*/
crud;
/**
* Inject the `store` service
*
* @var {Service}
*/
store;
/**
* Inject the `hostRouter` service
*
* @var {Service}
*/
hostRouter;
/**
* Inject the `contextPanel` service
*
* @var {Service}
*/
contextPanel;
/**
* Inject the `filters` service
*
* @var {Service}
*/
filters;
/**
* Inject the `loader` service
*
* @var {Service}
*/
loader;
/**
* Queryable parameters for this controller's model
*
* @var {Array}
*/
queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'created_by', 'updated_by', 'status', 'delivery_date_at'];
/**
* 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 = '-created_at';
/**
* The filterable param `public_id`
*
* @var {String}
*/
public_id;
/**
* The filterable param `status`
*
* @var {Array}
*/
status;
/**
* All columns applicable for orders
*
* @var {Array}
*/
columns = [
{
label: 'ID',
valuePath: 'public_id',
width: '130px',
cellComponent: 'table/cell/anchor',
action: this.viewPurchaseOrder,
resizable: true,
sortable: true,
filterable: true,
hidden: false,
filterComponent: 'filter/string',
},
{
label: 'Status',
valuePath: 'status',
cellComponent: 'table/cell/status',
width: '100px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/multi-option',
filterOptions: this.statusOption,
},
{
label: 'Created At',
valuePath: 'createdAt',
sortParam: 'createdAt',
width: '120px',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: 'Updated At',
valuePath: 'updatedAt',
sortParam: 'updated_at',
width: '120px',
resizable: true,
sortable: true,
hidden: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: '',
cellComponent: 'table/cell/dropdown',
ddButtonText: false,
ddButtonIcon: 'ellipsis-h',
ddButtonIconPrefix: 'fas',
ddMenuLabel: 'Sales Order Actions',
cellClassNames: 'overflow-visible',
wrapperClass: 'flex items-center justify-end mx-2',
width: '10%',
actions: [
{
label: 'View Details',
fn: this.viewPurchaseOrder,
},
{
label: 'Edit Sales Order',
fn: this.editPurchaseOrder,
},
{
separator: true,
},
{
label: 'Delete Sales Order',
fn: this.deletePurchaseOrder,
},
],
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;
}
/**
* Toggles dialog to export a Sales Order
*
* @void
*/
exportFuelReports() {
this.crud.export('purchase-order');
}
/**
* View the selected Sales Order
*
* @param {PurchaseOrderModel} fuelReport
* @param {Object} options
* @void
*/
viewPurchaseOrder(purchaseOrder) {
this.transitionToRoute('purchase-orders.index.details', purchaseOrder);
}
/**
* Create a new Sales Order
*
* @void
*/
createPurchaseOrder() {
this.transitionToRoute('purchase-orders.index.new');
}
/**
* Edit a Sales Order
*
* @param {PurchaseOrderModel} purchaseOrder
* @void
*/
editPurchaseOrder(purchaseOrder) {
this.transitionToRoute('purchase-orders.index.edit', purchaseOrder);
}
/**
* Prompt to delete a Sales Order
*
* @param {PurchaseOrderModel} purchaseOrder
* @param {Object} options
* @void
*/
deletePurchaseOrder(purchaseOrder, options = {}) {
this.crud.delete(purchaseOrder, {
onConfirm: () => {
this.hostRouter.refresh();
},
...options,
});
}
/**
* Bulk deletes selected Sales Order's via confirm prompt
*
* @param {Array} selected an array of selected models
* @void
*/
bulkDeletePurchaseOrder() {
const selected = this.table.selectedRows;
this.crud.bulkDelete(selected, {
modelNamePath: 'public_id',
acceptButtonText: 'Delete Sales Order',
onSuccess: () => {
return this.hostRouter.refresh();
},
});
}
}