@lipagas/fleetops-engine
Version:
Fleet & Transport Management Extension for Fleetbase
132 lines (114 loc) • 3.27 kB
JavaScript
import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
import { underscore } from '@ember/string';
import { task } from 'ember-concurrency';
import contextComponentCallback from '@lipagas/ember-core/utils/context-component-callback';
import applyContextComponentArguments from '@lipagas/ember-core/utils/apply-context-component-arguments';
export default class FleetFormPanelComponent extends Component {
/**
* @service store
*/
store;
/**
* @service notifications
*/
notifications;
/**
* @service hostRouter
*/
hostRouter;
/**
* @service intl
*/
intl;
/**
* @service contextPanel
*/
contextPanel;
/**
* Overlay context.
* @type {any}
* @memberof FleetFormPanelComponent
*/
context;
/**
* All possible order status options
*
* @var {String}
* @memberof FleetFormPanelComponent
*/
statusOptions = ['active', 'disabled', 'decommissioned'];
/**
* Constructs the component and applies initial state.
*/
constructor() {
super(...arguments);
this.fleet = this.args.fleet;
applyContextComponentArguments(this);
}
/**
* Sets the overlay context.
*
* @action
* @param {OverlayContextObject} overlayContext
* @memberof FleetFormPanelComponent
*/
setOverlayContext(overlayContext) {
this.context = overlayContext;
contextComponentCallback(this, 'onLoad', ...arguments);
}
/**
* Task to save fleet.
*
* @return {void}
* @memberof FleetFormPanelComponent
*/
*save() {
contextComponentCallback(this, 'onBeforeSave', this.fleet);
try {
this.fleet = yield this.fleet.save();
} catch (error) {
this.notifications.serverError(error);
return;
}
this.notifications.success(this.intl.t('fleet-ops.component.fleet-form-panel.success-message', { fleetName: this.fleet.name }));
contextComponentCallback(this, 'onAfterSave', this.fleet);
}
/**
* View the details of the fleet.
*
* @action
* @memberof FleetFormPanelComponent
*/
onViewDetails() {
const isActionOverrided = contextComponentCallback(this, 'onViewDetails', this.fleet);
if (!isActionOverrided) {
this.contextPanel.focus(this.fleet, 'viewing');
}
}
/**
* Handles cancel button press.
*
* @action
* @returns {any}
* @memberof FleetFormPanelComponent
*/
onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.fleet);
}
/**
* Update relation on a model.
*
* @param {String} relation
* @param {Model|null} value
* @memberof FleetFormPanelComponent
*/
updateRelationship(relation, value) {
this.fleet.set(relation, value);
if (!value) {
this.fleet.set(underscore(relation) + '_uuid', null);
}
}
}