@fleetbase/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
161 lines (152 loc) • 5.37 kB
JavaScript
import Controller from '@ember/controller';
import { inject as service } from '@ember/service';
import { tracked } from '@glimmer/tracking';
import { task } from 'ember-concurrency';
import fleetOpsOptions from '../../../utils/fleet-ops-options';
export default class ConnectivityTelematicsIndexController extends Controller {
telematicActions;
fetch;
intl;
notifications;
providers = [];
/** query params */
queryParams = ['name', 'provider', 'status', 'page', 'limit', 'sort', 'query', 'public_id', 'created_at', 'updated_at'];
page = 1;
limit;
sort = '-created_at';
public_id;
name;
provider;
status;
constructor() {
super(...arguments);
this.loadProviders.perform();
}
/** action buttons */
actionButtons = [
{
icon: 'refresh',
onClick: this.telematicActions.refresh,
helpText: this.intl.t('common.refresh'),
},
{
text: this.intl.t('common.new'),
type: 'primary',
icon: 'plus',
onClick: this.telematicActions.transition.create,
},
{
text: this.intl.t('common.import'),
type: 'magic',
icon: 'upload',
onClick: this.telematicActions.import,
},
{
text: this.intl.t('common.export'),
icon: 'long-arrow-up',
iconClass: 'rotate-icon-45',
wrapperClass: 'hidden md:flex',
onClick: this.telematicActions.export,
},
];
/** bulk action buttons */
bulkActions = [
{
label: 'Delete selected...',
class: 'text-red-500',
fn: this.telematicActions.bulkDelete,
},
];
/** columns */
columns = [
{
sticky: true,
label: 'Provider',
valuePath: 'name',
cellComponent: 'cell/telematic-provider',
action: this.telematicActions.transition.view,
permission: 'fleet-ops view telematic',
width: 460,
resizable: true,
sortable: true,
filterable: true,
filterParam: 'name',
filterComponent: 'filter/string',
},
{
label: this.intl.t('column.status'),
valuePath: 'status',
cellComponent: 'cell/telematic-status',
cellClassNames: 'fleetops-provider-connections-cell-middle',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/multi-option',
filterOptions: fleetOpsOptions('telematicStatuses'),
},
{
label: this.intl.t('column.created-at'),
valuePath: 'createdAt',
sortParam: 'created_at',
cellClassNames: 'fleetops-provider-connections-cell-middle',
resizable: true,
sortable: true,
filterable: true,
filterComponent: 'filter/date',
},
{
label: this.intl.t('column.updated-at'),
valuePath: 'updatedAt',
sortParam: 'updated_at',
cellClassNames: 'fleetops-provider-connections-cell-middle',
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.telematic') }),
cellClassNames: 'fleetops-provider-connections-cell-middle 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.telematic') }),
fn: this.telematicActions.transition.view,
permission: 'fleet-ops view telematic',
},
{
label: this.intl.t('common.edit-resource', { resource: this.intl.t('resource.telematic') }),
fn: this.telematicActions.transition.edit,
permission: 'fleet-ops update telematic',
},
{
separator: true,
},
{
label: this.intl.t('common.delete-resource', { resource: this.intl.t('resource.telematic') }),
fn: this.telematicActions.delete,
permission: 'fleet-ops delete telematic',
},
],
sortable: false,
filterable: false,
resizable: false,
searchable: false,
},
];
*loadProviders() {
try {
this.providers = yield this.fetch.get('telematics/providers');
} catch (error) {
this.notifications.serverError(error);
}
}
}