ui/app/models/app.js

52 lines
1.8 KiB
JavaScript

import Resource from 'ember-api-store/models/resource';
import { hasMany } from 'ember-api-store/utils/denormalize';
import { computed, get } from '@ember/object';
import { parseHelmExternalId } from 'ui/utils/parse-externalid';
import StateCounts from 'ui/mixins/state-counts';
import { inject as service } from '@ember/service';
const App = Resource.extend(StateCounts, {
catalog: service(),
router: service(),
pods: hasMany('installNamespace', 'pod', 'namespaceId'),
init() {
this._super(...arguments);
this.defineStateCounts('pods', 'podStates', 'podCountSort');
},
externalIdInfo: computed('externalId', function() {
return parseHelmExternalId(get(this, 'externalId'));
}),
catalogTemplate: computed('externalIdInfo.templateId', function() {
return this.get('catalog').getTemplateFromCache(this.get('externalIdInfo.templateId'));
}),
actions: {
edit() {
let templateId = get(this, 'externalIdInfo.templateId');
let catalogId = get(this, 'externalIdInfo.catalog');
get(this, 'router').transitionTo('catalog-tab.launch', templateId, {queryParams: {
catalog: catalogId,
namespaceId: get(this, 'model.installNamespace'),
appId: get(this, 'id'),
}});
}
},
availableActions: computed('actionLinks.{rollback,upgrade}', function () {
let l = get(this,'links');
var choices = [
{ label: 'action.edit', icon: 'icon icon-edit', action: 'edit', enabled: !!l.update },
{ label: 'action.remove', icon: 'icon icon-trash', action: 'promptDelete', enabled: !!l.remove, altAction: 'delete', bulkable: true},
{ divider: true },
{ label: 'action.viewInApi', icon: 'icon icon-external-link', action: 'goToApi', enabled: true},
];
return choices;
}),
});
export default App;