forked from rancher/ui
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
27e5f65
commit bd9108a
Showing
12 changed files
with
376 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
}); | ||
}, | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"> </th> | ||
<th>{{t 'catalogSettings.more.url.label'}}</th> | ||
<th width="30"> </th> | ||
<th>{{t 'catalogSettings.more.kind.label'}}</th> | ||
<th width="30"> </th> | ||
<th>{{t 'catalogSettings.more.branch.label'}}</th> | ||
<th width="30"> </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> </td> | ||
<td class="valign-top pt-5 pb-5" data-title="{{t 'catalogSettings.more.url.label'}}:"> | ||
{{row.url}} | ||
</td> | ||
<td> </td> | ||
<td class="valign-top pt-5 pb-5" data-title="{{t 'catalogSettings.more.kind.label'}}:"> | ||
{{row.kind}} | ||
</td> | ||
<td> </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"> </th> | ||
<th>{{t 'catalogSettings.more.url.label'}}</th> | ||
<th width="30"> </th> | ||
<th width="100">{{t 'catalogSettings.more.kind.label'}}</th> | ||
<th width="30"> </th> | ||
<th width="200">{{t 'catalogSettings.more.branch.label'}}</th> | ||
<th width="30"> </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> </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> </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> </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"}} |
Oops, something went wrong.