mirror of https://github.com/rancher/ui.git
90 lines
2.2 KiB
JavaScript
90 lines
2.2 KiB
JavaScript
import { isArray } from '@ember/array';
|
|
import { inject as service } from '@ember/service';
|
|
import Component from '@ember/component';
|
|
import layout from './template';
|
|
|
|
export default Component.extend({
|
|
layout,
|
|
allWorkloads: service(),
|
|
|
|
selected: null, // Selected workload ID
|
|
selectClass: 'form-control',
|
|
withPods: false,
|
|
exclude: null, // ID or array of IDs to exclude from list
|
|
|
|
// For use as a catalog question
|
|
field: null, // Read default from a schema resourceField
|
|
value: null, // namespace/workloadName string output
|
|
|
|
// For other abuses
|
|
obj: null,
|
|
|
|
init() {
|
|
this._super(...arguments);
|
|
|
|
if ( this.get('obj') ) {
|
|
this.set('selected', this.get('obj.id'));
|
|
}
|
|
|
|
let def = this.get('field.default');
|
|
if ( def && !this.get('selected') ) {
|
|
var exact, justWorkload;
|
|
|
|
this.get('allWorkloads.list').forEach((entry) => {
|
|
if ( def === entry.value )
|
|
{
|
|
exact = entry.id;
|
|
}
|
|
else if ( def === entry.name )
|
|
{
|
|
justWorkload = entry.id;
|
|
}
|
|
});
|
|
|
|
this.set('selected', exact || justWorkload || null);
|
|
}
|
|
},
|
|
|
|
grouped: function() {
|
|
let list = this.get('allWorkloads.list');
|
|
|
|
let exclude = this.get('exclude');
|
|
if ( exclude ) {
|
|
if ( !isArray(exclude) ) {
|
|
exclude = [exclude];
|
|
}
|
|
|
|
list = list.filter(x => !exclude.includes(x.id));
|
|
}
|
|
|
|
let out = this.get('allWorkloads').group(list);
|
|
let selected = this.get('allWorkloads').byId(this.get('selected'));
|
|
if ( selected && !list.findBy('id', selected.get('id')) ) {
|
|
out['(Selected)'] = [{
|
|
id: selected.get('id'),
|
|
name: selected.get('displayName'),
|
|
kind: selected.get('type'),
|
|
obj: selected,
|
|
}];
|
|
}
|
|
|
|
return out;
|
|
}.property('allWorkloads.list.[]'),
|
|
|
|
selectedChanged: function() {
|
|
let id = this.get('selected');
|
|
let str = null;
|
|
let workload = null;
|
|
|
|
if ( id ) {
|
|
workload = this.get('allWorkloads').byId(id);
|
|
if ( workload ) {
|
|
str = workload.get('namespace.name') + '/' + workload.get('name');
|
|
}
|
|
}
|
|
|
|
this.set('value', str);
|
|
this.set('obj', workload);
|
|
}.observes('selected'),
|
|
});
|