@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
203 lines (196 loc) • 7.14 kB
JavaScript
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
export default class ManagementContactsIndexController extends Controller {
contactActions;
tableContext;
intl;
/** query params */
queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'internal_id', 'created_by', 'updated_by', 'status', 'title', 'email', 'phone'];
page = 1;
limit;
sort = '-created_at';
public_id;
internal_id;
title;
email;
phone;
status;
table;
/** action buttons */
get actionButtons() {
return [
{
icon: 'refresh',
onClick: this.contactActions.refresh,
helpText: this.intl.t('common.refresh'),
},
{
text: this.intl.t('common.new'),
type: 'primary',
icon: 'plus',
onClick: this.contactActions.transition.create,
},
{
text: this.intl.t('common.import'),
type: 'magic',
icon: 'upload',
onClick: this.contactActions.import,
},
{
text: this.intl.t('common.export'),
icon: 'long-arrow-up',
iconClass: 'rotate-icon-45',
wrapperClass: 'hidden md:flex',
onClick: this.contactActions.export,
},
];
}
/** bulk actions */
get bulkActions() {
const selected = this.tableContext.getSelectedRows();
return [
{
label: this.intl.t('common.delete-selected-count', { count: selected.length }),
class: 'text-red-500',
fn: this.contactActions.bulkDelete,
},
];
}
/** columns */
get columns() {
return [
{
sticky: true,
label: this.intl.t('column.name'),
valuePath: 'name',
cellComponent: 'table/cell/media-name',
action: this.contactActions.transition.view,
permission: 'fleet-ops view contact',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.id'),
valuePath: 'public_id',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.internal-id'),
valuePath: 'internal_id',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.title'),
valuePath: 'title',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
hidden: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.email'),
valuePath: 'email',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.phone'),
valuePath: 'phone',
cellComponent: 'click-to-copy',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.address'),
valuePath: 'address',
cellComponent: 'table/cell/anchor',
action: this.contactActions.viewPlace,
resizable: true,
sortable: true,
filterable: true,
filterParam: 'address',
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.created'),
valuePath: 'createdAt',
sortParam: 'created_at',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: this.intl.t('column.updated'),
valuePath: 'updatedAt',
sortParam: 'updated_at',
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('common.resource-actions', { resource: this.intl.t('resource.contact') }),
cellClassNames: 'overflow-visible',
wrapperClass: 'flex items-center justify-end mx-2',
sticky: 'right',
width: 60,
actions: [
{
label: this.intl.t('common.view-resource', { resource: this.intl.t('resource.contact') }),
icon: 'eye',
fn: this.contactActions.transition.view,
permission: 'fleet-ops view contact',
},
{
label: this.intl.t('common.edit-resource', { resource: this.intl.t('resource.contact') }),
icon: 'pencil',
fn: this.contactActions.transition.edit,
permission: 'fleet-ops update contact',
},
{
separator: true,
},
...this.contactActions.accountRowActionItems(),
{
separator: true,
},
{
label: this.intl.t('common.delete-resource', { resource: this.intl.t('resource.contact') }),
icon: 'trash',
fn: this.contactActions.delete,
permission: 'fleet-ops delete contact',
},
],
sortable: false,
filterable: false,
resizable: false,
searchable: false,
},
];
}
}