@fleetbase/dev-engine
Version:
Fleetbase Developers extension provides a module for managing developer resources such as API keys, webhooks, sockets, events and logs.
117 lines (103 loc) • 3.35 kB
JavaScript
import BaseController from '../base-controller';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action, computed } from '@ember/object';
import fromStore from '@fleetbase/ember-core/decorators/legacy-from-store';
export default class SocketsIndexController extends BaseController {
modalsManager;
intl;
notifications;
currentUser;
store;
hostRouter;
abilities;
/**
* All columns applicable for orders
*
* @var {Array}
*/
columns = [
{
label: '',
width: '12%',
sortable: false,
cellComponent: 'table/cell/link-to',
linkText: this.intl.t('developers.sockets.index.link-text'),
linkClass: 'btn btn-default btn-xs flex flex-row-reverse',
linkIcon: 'arrow-right',
linkIconClass: 'ml-2',
route: 'sockets.view',
cellClassNames: 'no-underline',
},
{
label: this.intl.t('developers.sockets.index.channel'),
valuePath: 'name',
width: '88%',
cellComponent: 'click-to-copy',
},
];
/**
* All api credentials.
*
* @memberof SocketsIndexController
*/
apiCredentials;
/**
* Get all available known socket channels
*
* @readonly
* @memberof SocketsIndexController
*/
get channels() {
const channels = [];
const apiCredentials = this.apiCredentials ?? [];
for (let index = 0; index < apiCredentials.length; index++) {
const apiCredential = apiCredentials.objectAt(index);
if (!apiCredential?.id) {
continue;
}
channels.push({
name: `api.${apiCredential.id}`,
source: apiCredentials,
});
}
channels.pushObject({
name: `company.${this.currentUser.companyId}`,
});
return channels;
}
/**
* Link user to full event log view
*
* @void
*/
onRowClick(row) {
return this.hostRouter.transitionTo('console.developers.sockets.view', row);
}
/**
* Prompt dialog to allow user to listen on a custom socket channel
*
* @void
*/
listenOnCustomChannel() {
this.modalsManager.show('modals/listen-custom-channel', {
title: this.intl.t('developers.sockets.index.listen-channel-title'),
acceptButtonText: this.intl.t('developers.sockets.index.listen-channel-button-text'),
acceptButtonIcon: 'headphones',
declineButtonIcon: 'times',
declineButtonIconPrefix: 'fas',
channelId: null,
confirm: (modal) => {
modal.startLoading();
const channelId = modal.getOption('channelId');
return this.hostRouter.transitionTo('console.developers.sockets.view', { name: channelId });
},
});
}
/**
* Reload data.
*/
reload() {
return this.hostRouter.refresh();
}
}