UNPKG

@ducna01120/fleetops-engine

Version:

Fleet & Transport Management Extension for Fleetbase

149 lines (131 loc) 3.73 kB
import Component from '@glimmer/component'; import { tracked } from '@glimmer/tracking'; import { action } from '@ember/object'; import { inject as service } from '@ember/service'; import { isArray } from '@ember/array'; import IssuePanelDetailComponent from './issue-panel/details'; import contextComponentCallback from '@fleetbase/ember-core/utils/context-component-callback'; import applyContextComponentArguments from '@fleetbase/ember-core/utils/apply-context-component-arguments'; import findActiveTab from '../utils/find-active-tab'; export default class IssuePanelComponent extends Component { /** * Service for fetching data. * * @type {Service} */ @service fetch; /** * Service for managing modals. * * @type {Service} */ @service modalsManager; /** * Universe service for managing global data and settings. * * @type {Service} */ @service universe; /** * Ember data store service. * * @type {Service} */ @service store; /** * Service for managing routing within the host app. * * @type {Service} */ @service hostRouter; /** * Service for managing the context panel. * * @type {Service} */ @service contextPanel; /** * The current active tab. * * @type {Object} * @tracked */ @tracked tab; /** * The Issue being displayed or edited. * * @type {IssueModel} * @tracked */ @tracked issue; /** * Returns the array of tabs available for the panel. * * @type {Array} */ get tabs() { const registeredTabs = this.universe.getMenuItemsFromRegistry('fleet-ops:component:issue-panel'); // this.universe._createMenuItem('Tracking', null, { icon: 'satellite-dish', component: IssuePanelTrackingComponent }), const defaultTabs = [this.universe._createMenuItem('Details', null, { icon: 'circle-info', component: IssuePanelDetailComponent })]; if (isArray(registeredTabs)) { return [...defaultTabs, ...registeredTabs]; } return defaultTabs; } /** * Initializes the Issue panel component. */ constructor() { super(...arguments); this.issue = this.args.issue; this.tab = findActiveTab(this.tabs, this.args.tab); applyContextComponentArguments(this); } /** * Sets the overlay context. * * @action * @param {OverlayContextObject} overlayContext */ @action setOverlayContext(overlayContext) { this.context = overlayContext; contextComponentCallback(this, 'onLoad', ...arguments); } /** * Handles changing the active tab. * * @method * @param {String} tab - The new tab to switch to. * @action */ @action onTabChanged(tab) { this.tab = findActiveTab(this.tabs, tab); contextComponentCallback(this, 'onTabChanged', tab); } /** * Handles edit action for the Issue. * * @method * @action */ @action onEdit() { const isActionOverrided = contextComponentCallback(this, 'onEdit', this.issue); if (!isActionOverrided) { this.contextPanel.focus(this.issue, 'editing', { onAfterSave: () => { this.contextPanel.clear(); }, }); } } /** * Handles the cancel action. * * @method * @action * @returns {Boolean} Indicates whether the cancel action was overridden. */ @action onPressCancel() { return contextComponentCallback(this, 'onPressCancel', this.issue); } }