From 4069333ce12e244acfb6a63bff8ac0fb99a85b47 Mon Sep 17 00:00:00 2001 From: Vincent Fiduccia Date: Fri, 18 Aug 2017 14:29:43 -0700 Subject: [PATCH] Stuff --- .../clusters/cluster/host-new/route.js | 6 +--- .../clusters/index/controller.js | 6 +--- app/components/cluster-welcome/component.js | 14 ++------ app/components/cluster-welcome/template.hbs | 18 ++++++---- .../modal-edit-cluster/component.js | 34 +++++++++++++++++-- app/models/cluster.js | 11 ++++++ 6 files changed, 58 insertions(+), 31 deletions(-) diff --git a/app/authenticated/clusters/cluster/host-new/route.js b/app/authenticated/clusters/cluster/host-new/route.js index 81adfbf3f..03487ebe1 100644 --- a/app/authenticated/clusters/cluster/host-new/route.js +++ b/app/authenticated/clusters/cluster/host-new/route.js @@ -26,11 +26,7 @@ export default Ember.Route.extend({ }, goBack() { - if ( this.get('backTo') === 'waiting' ) { - this.transitionTo('authenticated.project.waiting'); - } else { - this.transitionTo('hosts'); - } + this.send('goToPrevious','authenticated.clusters'); } }, diff --git a/app/authenticated/clusters/index/controller.js b/app/authenticated/clusters/index/controller.js index 104ca764b..e6cc37ea0 100644 --- a/app/authenticated/clusters/index/controller.js +++ b/app/authenticated/clusters/index/controller.js @@ -9,11 +9,7 @@ export default Ember.Controller.extend({ actions: { newCluster() { - let cluster = this.get('userStore').createRecord({ - type: 'cluster', - }); - - this.get('modalService').toggleModal('modal-edit-cluster', cluster); + this.get('modalService').toggleModal('modal-edit-cluster'); }, }, diff --git a/app/components/cluster-welcome/component.js b/app/components/cluster-welcome/component.js index 76b917290..da8401402 100644 --- a/app/components/cluster-welcome/component.js +++ b/app/components/cluster-welcome/component.js @@ -4,15 +4,7 @@ export default Ember.Component.extend({ projects: Ember.inject.service(), settings: Ember.inject.service(), - clusters: null, - - canCreate: true, - canImport: true, - canReuse: Ember.computed.gt('clusters.length', 0), - - init() { - this._super(), - - this.set('clusters', this.get('store').all('cluster')); - }, + cluster: Ember.computed.alias('projects.currentCluster'), + canCreate: Ember.computed.notEmpty('cluster.registrationToken.hostCommand'), + canImport: Ember.computed.notEmpty('cluster.registrationToken.clusterCommand'), }); diff --git a/app/components/cluster-welcome/template.hbs b/app/components/cluster-welcome/template.hbs index fbf80df22..64dd3eb4b 100644 --- a/app/components/cluster-welcome/template.hbs +++ b/app/components/cluster-welcome/template.hbs @@ -5,14 +5,16 @@
-

Add Host

+

Add Hosts

Define and manage hosts inside {{settings.appName}}.

Supports on-premise, bare-metal, and cloud infrastructure.

- + {{#if canCreate}} + + {{/if}}
@@ -25,9 +27,11 @@

Individual hosts are managed by cluster provider outside of {{settings.appName}}.

Supports hosted services like Google Container Engine.

- + {{#if canImport}} + + {{/if}}
diff --git a/app/components/modal-edit-cluster/component.js b/app/components/modal-edit-cluster/component.js index bdf7b9a28..3408e94fa 100644 --- a/app/components/modal-edit-cluster/component.js +++ b/app/components/modal-edit-cluster/component.js @@ -11,9 +11,37 @@ export default Ember.Component.extend(ModalBase, NewOrEdit, { willInsertElement: function() { this._super(...arguments); var orig = this.get('originalModel'); - var clone = orig.clone(); - this.set('model', clone); - this.set('editing', !!this.get('model.id')); + if ( orig ) { + var clone = orig.clone(); + this.setProperties({ + editing: true, + model: clone, + createProject: null, + }); + } else { + this.setProperties({ + editing: false, + model: this.get('userStore').createRecord({ + type: 'cluster', + }), + createProject: this.get('userStore').createRecord({ + type: 'project', + name: 'Default', + }), + }); + } + }, + + didInsertElement() { + this.$('INPUT')[0].focus(); + }, + + didSave() { + let project = this.get('createProject'); + if ( project ) { + project.set('clusterId', this.get('model.id')); + return project.save(); + } }, doneSaving: function() { diff --git a/app/models/cluster.js b/app/models/cluster.js index 928785b14..cde2bf919 100644 --- a/app/models/cluster.js +++ b/app/models/cluster.js @@ -4,6 +4,7 @@ import PolledResource from 'ui/mixins/cattle-polled-resource'; var Cluster = Resource.extend(PolledResource, { modalService: Ember.inject.service('modal'), + userStore: Ember.inject.service('user-store'), type: 'cluster', @@ -13,6 +14,16 @@ var Cluster = Resource.extend(PolledResource, { } }, + _allProjects: null, + init() { + this._super(...arguments); + this.set('_allProjects', this.get('userStore').all('project')); + }, + + projects: function() { + return this.get('_allProjects').filterBy('clusterId', this.get('id')); + }.property('_allProjects.@each.clusterId'), + availableActions: function() { // let a = this.get('actionLinks'); let l = this.get('links');