Skip to content

Commit

Permalink
Port Env Catalogs to 1.6
Browse files Browse the repository at this point in the history
  • Loading branch information
westlywright committed Apr 24, 2017
1 parent 27e5f65 commit bd9108a
Show file tree
Hide file tree
Showing 12 changed files with 376 additions and 99 deletions.
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,19 @@ testem.log
.DS_Store
.tern-port
.tern-project
.vscode
.vscodeignore
/typings
.env
.floo
.flooignore


*.swp
*~
\#.*
.python-version
\#*
.\#*

*.org
33 changes: 27 additions & 6 deletions app/catalog-tab/index/controller.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
import Ember from 'ember';
import { isAlternate } from 'ui/utils/platform';
import C from 'ui/utils/constants';
import { getCatalogSubtree } from 'ui/utils/parse-catalog-setting';

export default Ember.Controller.extend({
application: Ember.inject.controller(),
catalog: Ember.inject.service(),
settings: Ember.inject.service(),
application: Ember.inject.controller(),
catalog: Ember.inject.service(),
settings: Ember.inject.service(),
projects: Ember.inject.service(),
projectId: Ember.computed.alias(`tab-session.${C.TABSESSION.PROJECT}`),

catalogController: Ember.inject.controller('catalog-tab'),
category: Ember.computed.alias('catalogController.category'),
categories: Ember.computed.alias('model.categories'),
catalogId: Ember.computed.alias('catalogController.catalogId'),
category: Ember.computed.alias('catalogController.category'),
categories: Ember.computed.alias('model.categories'),
catalogId: Ember.computed.alias('catalogController.catalogId'),
modalService: Ember.inject.service('modal'),

parentRoute: 'catalog-tab',
launchRoute: 'catalog-tab.launch',
Expand All @@ -19,6 +24,15 @@ export default Ember.Controller.extend({
updating: 'no',

actions: {
addEnvCatalog() {
this.get('modalService').toggleModal('modal-edit-env-catalogs', {
project: this.get('projects.current'),
catalogs: this.get('model.catalogs.content'),
});
},
clearSearch() {
this.set('search', '');
},
launch(id, onlyAlternate) {
if ( onlyAlternate && !isAlternate(event) ) {
return false;
Expand All @@ -39,8 +53,15 @@ export default Ember.Controller.extend({
},

init() {
this._super(...arguments);
this.get('catalog.componentRequestingRefresh');
},

childRequestiongRefresh: Ember.observer('catalog.componentRequestingRefresh', function() {
if (this.get('catalog.componentRequestingRefresh')) {
this.send('update');
}
}),
arrangedContent: Ember.computed('model.catalog', 'search', function() {
var search = this.get('search').toUpperCase();
var result = [];
Expand Down
3 changes: 3 additions & 0 deletions app/catalog-tab/index/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
{{/if}}
{{/if}}
</button>
<button type="button" class="btn bg-primary btn-sm" {{ action "addEnvCatalog" }}>
{{t 'catalogPage.index.manage'}} <i class="icon icon-edit"></i>
</button>
</div>

<div class="btn-group pull-right r-ml10">
Expand Down
8 changes: 7 additions & 1 deletion app/catalog-tab/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import Ember from 'ember';
import C from 'ui/utils/constants';

export default Ember.Route.extend({
access: Ember.inject.service(),
Expand Down Expand Up @@ -31,7 +32,11 @@ export default Ember.Route.extend({
return this.get('projects').updateOrchestrationState().then(() => {
return Ember.RSVP.hash({
stacks: this.get('store').find('stack'),
catalogs: this.get('catalog').fetchCatalogs(),
catalogs: this.get('catalog').fetchCatalogs({
headers: {
[C.HEADER.PROJECT_ID]: this.get('projects.current.id')
},
}),
}).then((hash) => {
this.set('catalogs', hash.catalogs);
this.set('stacks', this.get('store').all('stack'));
Expand All @@ -47,6 +52,7 @@ export default Ember.Route.extend({
let exists = stacks.findBy('externalIdInfo.templateId', tpl.get('id'));
tpl.set('exists', !!exists);
});
res.catalogs = this.get('catalogs');

return res;
});
Expand Down
130 changes: 130 additions & 0 deletions app/components/env-catalog/component.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
import Ember from 'ember';
import C from 'ui/utils/constants';

export default Ember.Component.extend({
catalog: Ember.inject.service(),
project: null,
catalogs: null,
ary: null,
global: null,

kindChoices: [
{translationKey: 'catalogSettings.more.kind.native', value: 'native'},
{translationKey: 'catalogSettings.more.kind.helm', value: 'helm'},
],

init() {
this._super(...arguments);
this.setProperties({
ary: this.get('catalogs').filterBy('environmentId', this.get('project.id')),
global: this.get('catalogs').filterBy('environmentId', 'global') // this should change to falsey check when josh updates the catalog to remove 'global' from the id
});
},
actions: {
add() {
this.get('ary').pushObject(Ember.Object.create({
name: '',
branch: C.CATALOG.DEFAULT_BRANCH,
url: '',
kind: 'native',
toAdd: true
}));

Ember.run.next(() => {
if ( this.isDestroyed || this.isDestroying ) {
return;
}

this.$('INPUT.name').last()[0].focus();
});
},
remove(obj) {
Ember.set(obj, 'toRemove', true);
},
save(cb) {
if (this.validate()) {
this.set('errors', []);
var newCatalogs = this.get('ary').filterBy('toAdd', true);
var catalogsToRemove = this.get('ary').filterBy('toRemove', true);
var all = [];

newCatalogs.forEach((cat) => {
all.push(this.addCatalogs(cat));
});

catalogsToRemove.forEach((cat) => {
all.push(this.removeCatalogs(cat));
});

Ember.RSVP.all(all).then(() => {
this.set('catalog.componentRequestingRefresh', true);
this.set('saving', false);
cb(true);
Ember.run.later(() => {
this.sendAction('cancel');
}, 500);
}).catch((err) => {
this.set('errors',err);
cb(false);
this.set('saving', false);
});
} else {
cb(false);
this.set('saving', false);
}
}
},
validate: function() {
var errors = [];
var globals = ['all', 'community', 'library']; // these should be removed when these terms are removed from the envid field
var newCatalogs = this.get('ary').filterBy('toAdd', true);

if (newCatalogs.length) {
newCatalogs.forEach((cat) => {
if ( (cat.name||'').trim().length === 0 )
{
errors.push('A name is required');
}
if ( (cat.url||'').trim().length === 0 )
{
errors.push('A url is required');
}
if (globals.indexOf(cat.name.toLowerCase()) >= 0) {
errors.push('Catalog name can not match a gloabl catalog name');
}
});
}

if ( errors.length )
{
this.set('errors',errors.uniq());
return false;
}
else
{
this.set('errors', null);
}

return true;
},
addCatalogs(catalogs) {
return this.get('store').request({
url: `${this.get('app.catalogEndpoint')}/catalogs`,
method: 'POST',
headers: {
[C.HEADER.PROJECT_ID]: this.get('project.id')
},
body: JSON.stringify(catalogs)
});
},
removeCatalogs(catalogs) {
return this.get('store').request({
url: `${this.get('app.catalogEndpoint')}/catalogs/${catalogs.name}`,
method: 'DELETE',
headers: {
[C.HEADER.PROJECT_ID]: this.get('project.id')
},
body: JSON.stringify(catalogs)
});
},
});
100 changes: 100 additions & 0 deletions app/components/env-catalog/template.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
<div>
<h2>{{t 'envCatalog.header'}}</h2>
<h5 class="help-block">{{format-html-message 'envCatalog.subtext'}}</h5>
<hr/>
</div>
<div>
{{#if global.length}}
<h3>{{t 'envCatalog.global'}}</h3>
<h5>{{t 'envCatalog.globalNote'}}</h5>
<table class="table fixed no-lines no-top-padding">
<tr class="text-muted hidden-xs hidden-sm text-left">
<th>{{t 'catalogSettings.more.name.label'}}</th>
<th width="30">&nbsp;</th>
<th>{{t 'catalogSettings.more.url.label'}}</th>
<th width="30">&nbsp;</th>
<th>{{t 'catalogSettings.more.kind.label'}}</th>
<th width="30">&nbsp;</th>
<th>{{t 'catalogSettings.more.branch.label'}}</th>
<th width="30">&nbsp;</th>
</tr>
{{#each global as |row|}}
{{#unless row.toRemove}}
<tr>
<td class="valign-top pt-5 pb-5" data-title="{{t 'catalogSettings.more.name.label'}}:">
{{row.name}}
</td>
<td>&nbsp;</td>
<td class="valign-top pt-5 pb-5" data-title="{{t 'catalogSettings.more.url.label'}}:">
{{row.url}}
</td>
<td>&nbsp;</td>
<td class="valign-top pt-5 pb-5" data-title="{{t 'catalogSettings.more.kind.label'}}:">
{{row.kind}}
</td>
<td>&nbsp;</td>
<td class="valign-top pt-5 pb-5" data-title="{{t 'catalogSettings.more.branch.label'}}:">
{{row.branch}}
</td>
</tr>
{{/unless}}
{{/each}}
</table>
{{/if}}
<hr/>
</div>
<div>
<button class="btn btn-sm btn-primary r-mb10" {{action "add"}}>
<i class="icon icon-plus text-small"/>
<span>{{t 'envCatalog.addActionLabel'}}</span>
</button>

{{#if ary.length}}
<table class="table fixed no-lines no-top-padding">
<tr class="text-muted hidden-xs hidden-sm text-left">
<th width="200">{{t 'catalogSettings.more.name.label'}}</th>
<th width="30">&nbsp;</th>
<th>{{t 'catalogSettings.more.url.label'}}</th>
<th width="30">&nbsp;</th>
<th width="100">{{t 'catalogSettings.more.kind.label'}}</th>
<th width="30">&nbsp;</th>
<th width="200">{{t 'catalogSettings.more.branch.label'}}</th>
<th width="30">&nbsp;</th>
</tr>
{{#each ary as |row|}}
{{#unless row.toRemove}}
<tr>
<td data-title="{{t 'catalogSettings.more.name.label'}}:">
{{input class="form-control input-sm name" type="text" value=row.name placeholder=(t 'catalogSettings.more.name.placeholder')}}
</td>
<td>&nbsp;</td>
<td data-title="{{t 'catalogSettings.more.url.label'}}:">
{{input class="form-control input-sm" type="text" value=row.url placeholder=(t 'catalogSettings.more.url.placeholder')}}
</td>
<td>&nbsp;</td>
<td data-title="{{t 'catalogSettings.more.kind.label'}}:">
{{new-select
classNames="form-control"
content=kindChoices
optionLabelPath="translationKey"
optionValuePath="value"
localizedLabel=true
value=row.kind
}}
</td>
<td>&nbsp;</td>
<td data-title="{{t 'catalogSettings.more.branch.label'}}:">
{{input class="form-control input-sm" type="text" value=row.branch placeholder=(t 'catalogSettings.more.branch.placeholder')}}
</td>

<td class="valign-top text-right">
<button class="btn bg-primary btn-sm" {{action "remove" row}}><i class="icon icon-minus"/><span class="sr-only">{{t 'generic.remove'}}</span></button>
</td>
</tr>
{{/unless}}
{{/each}}
</table>
{{/if}}
</div>
{{top-errors errors=errors}}
{{save-cancel classNames="pt-20" cancel=(action cancel) editing=true save="save"}}
Loading

0 comments on commit bd9108a

Please sign in to comment.