diff --git a/app/models/catalog.js b/app/models/catalog.js index 27f748162..2cf8f961b 100644 --- a/app/models/catalog.js +++ b/app/models/catalog.js @@ -12,6 +12,12 @@ export default Resource.extend({ return ucFirst(get(this, 'kind')); }), + combinedState: computed('id', function() { + if ( !get(this, 'id') ) { + return 'disabled'; + } + }), + canClone: computed('actions.clone', function() { const name = get(this, 'name'); const catalogNames = get(C, 'CATALOG'); @@ -23,15 +29,27 @@ export default Resource.extend({ availableActions: computed('actionLinks.{refresh}', function() { let a = get(this, 'actionLinks') || {}; - return [{ - enabled: !!a.refresh, - label: 'catalogPage.index.refreshBtn', - icon: 'icon icon-refresh', - action: 'refresh' - }]; + return [ + { + action: 'enable', + icon: 'icon icon-plus-circle', + enabled: !this.id, + label: 'generic.enable', + }, + { + enabled: !!a.refresh, + label: 'catalogPage.index.refreshBtn', + icon: 'icon icon-refresh', + action: 'refresh' + } + ]; }), actions: { + enable() { + this.save(); + }, + edit() { get(this, 'modalService').toggleModal('modal-edit-catalog', { model: this, diff --git a/lib/global-admin/addon/catalog/controller.js b/lib/global-admin/addon/catalog/controller.js index 834d3313a..e12d4f81a 100644 --- a/lib/global-admin/addon/catalog/controller.js +++ b/lib/global-admin/addon/catalog/controller.js @@ -15,130 +15,6 @@ export default Controller.extend({ togglingLibrary: false, actions: { - disableLibrary() { - if ( get(this, 'togglingLibrary') ) { - return; - } - - set(this, 'togglingLibrary', true); - get(this, 'library').delete().catch((err) => { - get(this, 'growl').fromError('Error removing Library', err); - }).finally(() => { - set(this, 'togglingLibrary', false); - this.send('refresh'); - }); - }, - enableLibrary() { - if ( get(this, 'togglingLibrary') ) { - return; - } - - set(this, 'togglingLibrary', true); - get(this, 'globalStore').createRecord({ - type: 'catalog', - name: C.CATALOG.LIBRARY_KEY, - url: C.CATALOG.LIBRARY_VALUE, - branch: C.CATALOG.DEFAULT_BRANCH, - kind: 'helm', - }).save().catch((err) => { - get(this, 'growl').fromError('Error saving Library', err); - }) - .finally(() => { - set(this, 'togglingLibrary', false); - this.send('refresh'); - }); - }, - - disableHelmIncubator() { - if ( get(this, 'togglingHelmIncubator') ) { - return; - } - - set(this, 'togglingHelmIncubator', true); - get(this, 'helmIncubator').delete().catch((err) => { - get(this, 'growl').fromError('Error removing Incubator', err); - }).finally(() => { - set(this, 'togglingHelmIncubator', false); - this.send('refresh'); - }); - }, - enableHelmIncubator() { - if ( get(this, 'togglingHelmIncubator') ) { - return; - } - - set(this, 'togglingHelmIncubator', true); - get(this, 'globalStore').createRecord({ - type: 'catalog', - name: C.CATALOG.HELM_INCUBATOR_KEY, - url: C.CATALOG.HELM_INCUBATOR_VALUE, - branch: C.CATALOG.DEFAULT_BRANCH, - kind: 'helm', - }).save().catch((err) => { - get(this, 'growl').fromError('Error saving Incubator', err); - }) - .finally(() => { - set(this, 'togglingHelmIncubator', false); - this.send('refresh'); - }); - }, - - disableHelmStable() { - if ( get(this, 'togglingHelmStable') ) { - return; - } - - set(this, 'togglingHelmStable', true); - get(this, 'helmStable').delete().catch((err) => { - get(this, 'growl').fromError('Error removing Stable', err); - }).finally(() => { - set(this, 'togglingHelmStable', false); - this.send('refresh'); - }); - }, - enableHelmStable() { - if ( get(this, 'togglingHelmStable') ) { - return; - } - - set(this, 'togglingHelmStable', true); - get(this, 'globalStore').createRecord({ - type: 'catalog', - name: C.CATALOG.HELM_STABLE_KEY, - url: C.CATALOG.HELM_STABLE_VALUE, - branch: C.CATALOG.DEFAULT_BRANCH, - kind: 'helm', - }).save().catch((err) => { - get(this, 'growl').fromError('Error saving Stable', err); - }) - .finally(() => { - set(this, 'togglingHelmStable', false); - this.send('refresh'); - }); - }, - - enableCommunity() { - get(this, 'globalStore').createRecord({ - type: 'catalog', - name: C.CATALOG.COMMUNITY_KEY, - url: C.CATALOG.COMMUNITY_VALUE, - branch: C.CATALOG.COMMUNITY_BRANCH, - }).save().catch((err) => { - get(this, 'growl').fromError('Error saving Community', err); - }) - .finally(() => { - this.send('refresh', this) - }); - }, - - disableCommunity() { - get(this, 'stdCommunity').delete().catch((err) => { - get(this, 'growl').fromError('Error removing Community', err); - }).finally(() => { - this.send('refresh', this) - }); - }, - add() { const record = get(this, 'globalStore').createRecord({ type: 'catalog', @@ -152,62 +28,4 @@ export default Controller.extend({ }); }, }, - - library: computed('model.@each.{name,url,branch}', function() { - return this.findMatch( - C.CATALOG.LIBRARY_KEY, - C.CATALOG.LIBRARY_VALUE - ); - }), - - helmStable: computed('model.@each.{name,url,branch}', function() { - return this.findMatch( - C.CATALOG.HELM_STABLE_KEY, - C.CATALOG.HELM_STABLE_VALUE, - ); - }), - - helmIncubator: computed('model.@each.{name,url,branch}', function() { - return this.findMatch( - C.CATALOG.HELM_INCUBATOR_KEY, - C.CATALOG.HELM_INCUBATOR_VALUE, - ); - }), - - custom: computed('library', 'helmStable', 'helmIncubator', function() { - const hide = [ - get(this, 'library'), - get(this, 'helmStable'), - get(this, 'helmIncubator'), - ]; - - return get(this, 'model').filter((x) => !hide.includes(x)); - }), - - customLibrary: computed('custom.@each.{name}', function() { - return get(this, 'custom').findBy('name', 'library') - }), - - customHelmStable: computed('custom.@each.{name}', function() { - return get(this, 'custom').findBy('name', 'helm') - }), - - customHelmIncubator: computed('custom.@each.{name}', function() { - return get(this, 'custom').findBy('name', 'helm-incubator') - }), - - findMatch(name, url, branch) { - const entry = get(this, 'model').findBy('name', name); - - if ( !entry ) { - return null; - } - - if ( get(entry, 'url') === url && - (!branch || get(entry, 'branch') === branch) - ) { - return entry; - } - }, - }); diff --git a/lib/global-admin/addon/catalog/template.hbs b/lib/global-admin/addon/catalog/template.hbs index 70e0856a5..a3754ec7f 100644 --- a/lib/global-admin/addon/catalog/template.hbs +++ b/lib/global-admin/addon/catalog/template.hbs @@ -8,92 +8,6 @@

{{t 'catalogSettings.header'}}

-
-
-

{{t 'catalogSettings.library.label'}}

-
- {{#if library}} -
- - -
- {{else}} -
- - -
- {{/if}} - {{#if customLibrary}} - {{#banner-message color='bg-warning'}} - {{t 'catalogSettings.errors.nameInExists' key='library' }} - {{/banner-message}} - {{/if}} -
-

- {{t 'catalogSettings.library.detail' appName=settings.appName}} -

- {{#if library.showTransitioningMessage}} -

{{uc-first library.transitioningMessage}}

- {{/if}} -
- -
-

{{t 'catalogSettings.helm.stable.label'}}

-
- {{#if helmStable}} -
- - -
- {{else}} -
- - -
- {{/if}} - {{#if customHelmStable}} - {{#banner-message color='bg-warning'}} - {{t 'catalogSettings.errors.nameInExists' key='helm' }} - {{/banner-message}} - {{/if}} -
-

- {{t 'catalogSettings.helm.stable.detail'}} -

- {{#if helmStable.showTransitioningMessage}} -

{{uc-first helmStable.transitioningMessage}}

- {{/if}} -
- -
-

{{t 'catalogSettings.helm.incubator.label'}}

-
- {{#if helmIncubator}} -
- - -
- {{else}} -
- - -
- {{/if}} - {{#if customHelmIncubator}} - {{#banner-message color='bg-warning'}} - {{t 'catalogSettings.errors.nameInExists' key='helm-incubator' }} - {{/banner-message}} - {{/if}} -
-

- {{t 'catalogSettings.helm.incubator.detail'}} -

- {{#if helmIncubator.showTransitioningMessage}} -

{{uc-first helmIncubator.transitioningMessage}}

- {{/if}} -
-
- {{custom-catalog - catalogs=custom -}} \ No newline at end of file + catalogs=model +}} diff --git a/lib/shared/addon/components/custom-catalog/component.js b/lib/shared/addon/components/custom-catalog/component.js index 08a25344c..f4e3cc5ef 100644 --- a/lib/shared/addon/components/custom-catalog/component.js +++ b/lib/shared/addon/components/custom-catalog/component.js @@ -40,6 +40,7 @@ const headers = [ ]; export default Component.extend({ + globalStore: service(), settings: service(), layout, headers, @@ -50,9 +51,51 @@ export default Component.extend({ paging: true, rightActions: true, - filtered: computed('catalogs.@each.{name,url}', function() { - return get(this, 'catalogs').filter((catalog) => { - return !(get(catalog, 'name') === C.CATALOG.SYSTEM_LIBRARY_KEY && get(catalog, 'url') === C.CATALOG.SYSTEM_LIBRARY_VALUE); - }); + library: computed('catalogs.@each.{name}', function() { + return get(this, 'catalogs').findBy('name', C.CATALOG.LIBRARY_KEY); + }), + + helmStable: computed('catalogs.@each.{name}', function() { + return get(this, 'catalogs').findBy('name', C.CATALOG.HELM_STABLE_KEY) + }), + + helmIncubator: computed('catalogs.@each.{name}', function() { + return get(this, 'catalogs').findBy('name', C.CATALOG.HELM_INCUBATOR_KEY) + }), + + rows: computed('catalogs.@each.{id,name,url}', function() { + const out = get(this, 'catalogs').slice(); + + if ( !this.library ) { + out.push(get(this, 'globalStore').createRecord({ + type: 'catalog', + name: C.CATALOG.LIBRARY_KEY, + url: C.CATALOG.LIBRARY_VALUE, + branch: C.CATALOG.DEFAULT_BRANCH, + kind: 'helm', + })); + } + + if ( !this.helmStable ) { + out.push(get(this, 'globalStore').createRecord({ + type: 'catalog', + name: C.CATALOG.HELM_STABLE_KEY, + url: C.CATALOG.HELM_STABLE_VALUE, + branch: C.CATALOG.DEFAULT_BRANCH, + kind: 'helm', + })); + } + + if ( !this.helmIncubator ) { + out.push(get(this, 'globalStore').createRecord({ + type: 'catalog', + name: C.CATALOG.HELM_INCUBATOR_KEY, + url: C.CATALOG.HELM_INCUBATOR_VALUE, + branch: C.CATALOG.DEFAULT_BRANCH, + kind: 'helm', + })); + } + + return out; }) }); diff --git a/lib/shared/addon/components/custom-catalog/template.hbs b/lib/shared/addon/components/custom-catalog/template.hbs index 8cb4fd34a..6fb4b989a 100644 --- a/lib/shared/addon/components/custom-catalog/template.hbs +++ b/lib/shared/addon/components/custom-catalog/template.hbs @@ -1,22 +1,5 @@ -
-

{{t 'catalogSettings.more.header'}}

-
-

{{t 'catalogSettings.more.helpText.header' htmlSafe=true}}

- -
-
- {{#sortable-table - body=filtered + body=rows descending=descending headers=headers paging=paging @@ -47,7 +30,7 @@ {{row.name}} - {{row.url}} + {{row.url}} {{row.branch}} @@ -64,4 +47,4 @@ {{else if (eq kind "norows")}} {{t 'catalogSettings.more.noData'}} {{/if}} -{{/sortable-table}} \ No newline at end of file +{{/sortable-table}}