import Ember from 'ember'; import Sortable from 'ui/mixins/sortable'; import C from 'ui/utils/constants'; import { tagsToArray, normalizedChoices } from 'ui/models/stack'; export default Ember.Controller.extend(Sortable, { stacksController: Ember.inject.controller('stacks'), projects: Ember.inject.service(), prefs: Ember.inject.service(), intl: Ember.inject.service(), stacks: Ember.computed.alias('stacksController.stacks'), infraTemplates: Ember.computed.alias('stacksController.infraTemplates'), which: Ember.computed.alias('stacksController.which'), tags: Ember.computed.alias('stacksController.tags'), showAddtlInfo: false, selectedService: null, tagsArray: null, tagChoices: function() { let out = normalizedChoices(this.get('model')); tagsToArray(this.get('tags')).forEach((tag) => { out.addObject(tag); }); return out.sort((a,b) => { return a.toLowerCase().localeCompare(b.toLowerCase()); }); }.property('model.@each.group'), actions: { showAddtlInfo(service) { this.set('selectedService', service); this.set('showAddtlInfo', true); }, dismiss() { this.set('showAddtlInfo', false); this.set('selectedService', null); }, sortResults(name) { this.get('prefs').set(C.PREFS.SORT_STACKS_BY, name); this.send('setSort', name); }, updateTags(select) { let options = Array.prototype.slice.call(select.target.options, 0); let selected = options.filterBy('selected',true).map(opt => opt.value); if ( selected.length === 0 ) { this.set('tags',''); } else { this.set('tags', selected.join(',')); } }, }, setup: function() { // Need this to setup the observer for filteredStacks this.get('which'); var sort = this.get(`prefs.${C.PREFS.SORT_STACKS_BY}`); if (sort && sort !== this.get('sortBy')) { this.set('sortBy', sort); } this.set('tagsArray', tagsToArray(this.get('tags'))); Ember.run.schedule('afterRender', this, () => { var opts = { maxHeight: 200, buttonClass: 'btn btn-sm btn-default', templates: { li: '