Updated Branches:
  refs/heads/trunk 17ab11391 -> 4ecaa001a

AMBARI-3805. "Add service" if nothing to add. (onechiporenko)


Project: http://git-wip-us.apache.org/repos/asf/incubator-ambari/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-ambari/commit/4ecaa001
Tree: http://git-wip-us.apache.org/repos/asf/incubator-ambari/tree/4ecaa001
Diff: http://git-wip-us.apache.org/repos/asf/incubator-ambari/diff/4ecaa001

Branch: refs/heads/trunk
Commit: 4ecaa001a7ba6b8eabc2389d53cadf7784e0d193
Parents: 17ab113
Author: Oleg Nechiporenko <cv_git...@yahoo.com>
Authored: Tue Nov 19 14:39:11 2013 +0200
Committer: Oleg Nechiporenko <cv_git...@yahoo.com>
Committed: Tue Nov 19 14:39:11 2013 +0200

----------------------------------------------------------------------
 ambari-web/app/controllers/main/service.js     | 45 ++++++++++++++++++-
 ambari-web/app/templates/main/host/summary.hbs | 34 +++++++--------
 ambari-web/app/templates/main/service.hbs      | 48 ++++++++++-----------
 ambari-web/app/utils/db.js                     | 11 +++++
 ambari-web/app/views/main/host/summary.js      | 12 +++++-
 ambari-web/app/views/main/service.js           | 10 ++++-
 6 files changed, 113 insertions(+), 47 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4ecaa001/ambari-web/app/controllers/main/service.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/controllers/main/service.js 
b/ambari-web/app/controllers/main/service.js
index b5674b6..da60de0 100644
--- a/ambari-web/app/controllers/main/service.js
+++ b/ambari-web/app/controllers/main/service.js
@@ -34,6 +34,39 @@ App.MainServiceController = Em.ArrayController.extend({
     return App.Cluster.find().objectAt(0);
   }.property('App.router.clusterController.isLoaded'),
 
+  isAllServicesInstalled: function() {
+    var availableServices = App.db.getServices();
+    if (!availableServices) {
+      this.loadAvailableServices();
+      availableServices = App.db.getServices();
+    }
+    return this.get('content').length == availableServices.length;
+  }.property('content.@each', 'content.length'),
+
+  loadAvailableServices: function() {
+    App.ajax.send({
+      name: 'wizard.service_components',
+      sender: this,
+      data: {
+        stackUrl: App.get('stack2VersionURL'),
+        stackVersion: App.get('currentStackVersionNumber')
+      },
+      success: 'loadAvailableServicesSuccessCallback'
+    });
+  },
+
+  loadAvailableServicesSuccessCallback: function(jsonData) {
+    var data = [];
+    var displayOrderConfig = require('data/services');
+    for (var i = 0; i < displayOrderConfig.length; i++) {
+      var entry = jsonData.items.findProperty("StackServices.service_name", 
displayOrderConfig[i].serviceName);
+      if (entry) {
+        data.push(entry.StackServices.service_name);
+      }
+    }
+    App.db.setServices(data);
+  },
+
   isStartAllDisabled: function(){
     if(this.get('isStartStopAllClicked') == true) {
       return true;
@@ -51,7 +84,7 @@ App.MainServiceController = Em.ArrayController.extend({
       if(!['HCATALOG', 'PIG', 'SQOOP'].contains(item.get('serviceName'))){
         flag = false;
       }
-    })
+    });
     return flag;
   }.property('isStartStopAllClicked', 'content.@each.healthStatus'),
   isStartStopAllClicked: function(){
@@ -115,5 +148,13 @@ App.MainServiceController = Em.ArrayController.extend({
   },
   allServicesCallErrorCallback: function() {
     console.log("ERROR");
+  },
+
+  gotoAddService: function() {
+    if (this.get('isAllServicesInstalled')) {
+      return;
+    }
+    App.router.transitionTo('main.serviceAdd');
   }
-})
+
+});
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4ecaa001/ambari-web/app/templates/main/host/summary.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/host/summary.hbs 
b/ambari-web/app/templates/main/host/summary.hbs
index 31bb5f3..63416fb 100644
--- a/ambari-web/app/templates/main/host/summary.hbs
+++ b/ambari-web/app/templates/main/host/summary.hbs
@@ -165,25 +165,21 @@
             </div>
             <div class="span5 row">
               {{#if App.isAdmin}}
-                {{#if view.isAddComponent}}
-                  {{#if view.addableComponents.length}}
-                    <div class="btn-group pull-right">
-                      <button id="add_component" class="btn btn-info 
dropdown-toggle" data-toggle="dropdown">
-                        {{t hosts.host.summary.addComponent}}
-                        <span class="caret pull-right"></span>
-                      </button>
-                      <ul class="dropdown-menu">
-                        {{#each component in view.addableComponents}}
-                          <li>
-                            <a href="javascript:void(null)" 
data-toggle="modal" {{action addComponent component target="controller"}}>
-                              {{component.displayName}}
-                            </a>
-                          </li>
-                        {{/each}}
-                      </ul>
-                    </div>
-                  {{/if}}
-                {{/if}}
+                <div class="btn-group pull-right">
+                  <button id="add_component" data-toggle="dropdown" {{bindAttr 
class="view.addComponentDisabled:disabled :btn :btn-info :dropdown-toggle"}}>
+                    {{t hosts.host.summary.addComponent}}
+                    <span class="caret pull-right"></span>
+                  </button>
+                  <ul class="dropdown-menu">
+                    {{#each component in view.addableComponents}}
+                      <li>
+                        <a href="javascript:void(null)" data-toggle="modal" 
{{action addComponent component target="controller"}}>
+                          {{component.displayName}}
+                        </a>
+                      </li>
+                    {{/each}}
+                  </ul>
+                </div>
               {{/if}}
             </div>
           </div>

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4ecaa001/ambari-web/app/templates/main/service.hbs
----------------------------------------------------------------------
diff --git a/ambari-web/app/templates/main/service.hbs 
b/ambari-web/app/templates/main/service.hbs
index 08d9b04..cdb8668 100644
--- a/ambari-web/app/templates/main/service.hbs
+++ b/ambari-web/app/templates/main/service.hbs
@@ -20,30 +20,30 @@
   <div class="services-menu well span2 service-menu-width" style="padding: 8px 
0">
     {{view App.MainServiceMenuView}}
     {{#if App.isAdmin}}
-    {{#if App.supports.addServices}}
-    <div class="add-service-button">
-      <a class="btn" {{action addService href="true"}}>
-        <i class="icon-plus"></i>
-        {{t services.service.add}}
-      </a>
-    </div>
-    {{/if}}
-    {{#if App.supports.startStopAllServices}}
-      <div class="start-stop-all-service-button">
-        <a href="javascript:void(null)" {{bindAttr class=":btn 
controller.isStartAllDisabled:disabled:btn-success" }}
-           data-toggle="modal" {{action "startAllService" 
target="controller"}}>
-          <i class="icon-play"></i>
-          {{t services.service.startAll}}
-        </a>
-      </div>
-      <div class="start-stop-all-service-button">
-        <a href="javascript:void(null)" {{bindAttr class=":btn 
controller.isStopAllDisabled:disabled:btn-danger" }}
-           data-toggle="modal" {{action "stopAllService" target="controller"}}>
-          <i class="icon-stop icon-white"></i>
-          {{t services.service.stopAll}}
-        </a>
-      </div>
-    {{/if}}
+      {{#if App.supports.addServices}}
+        <div class="add-service-button">
+          <a {{bindAttr class=":btn 
controller.isAllServicesInstalled:disabled"}} {{action gotoAddService 
target="controller"}}>
+            <i class="icon-plus"></i>
+            {{t services.service.add}}
+          </a>
+        </div>
+      {{/if}}
+      {{#if App.supports.startStopAllServices}}
+        <div class="start-stop-all-service-button">
+          <a href="javascript:void(null)" {{bindAttr class=":btn 
controller.isStartAllDisabled:disabled:btn-success" }}
+             data-toggle="modal" {{action "startAllService" 
target="controller"}}>
+            <i class="icon-play"></i>
+            {{t services.service.startAll}}
+          </a>
+        </div>
+        <div class="start-stop-all-service-button">
+          <a href="javascript:void(null)" {{bindAttr class=":btn 
controller.isStopAllDisabled:disabled:btn-danger" }}
+             data-toggle="modal" {{action "stopAllService" 
target="controller"}}>
+            <i class="icon-stop icon-white"></i>
+            {{t services.service.stopAll}}
+          </a>
+        </div>
+      {{/if}}
     {{/if}}
   </div>
   <div class="span10 summary-width">

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4ecaa001/ambari-web/app/utils/db.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/utils/db.js b/ambari-web/app/utils/db.js
index c34d4de..20a0458 100644
--- a/ambari-web/app/utils/db.js
+++ b/ambari-web/app/utils/db.js
@@ -296,6 +296,12 @@ App.db.setStacks = function (stacks) {
   localStorage.setObject('ambari', App.db.data);
 };
 
+App.db.setServices = function (services) {
+  App.db.data = localStorage.getObject('ambari');
+  App.db.data.app.services = services;
+  localStorage.setObject('ambari', App.db.data);
+};
+
 App.db.setConfigs = function (configs) {
   App.db.data = localStorage.getObject('ambari');
   App.db.data.app.configs = configs;
@@ -701,6 +707,11 @@ App.db.getStacks = function () {
   return App.db.data.app.stacksVersions;
 };
 
+App.db.getServices = function () {
+  App.db.data = localStorage.getObject('ambari');
+  return App.db.data.app.services;
+};
+
 App.db.getHighAvailabilityWizardHdfsUser = function () {
   App.db.data = localStorage.getObject('ambari');
   return App.db.data.HighAvailabilityWizard.hdfsUser;

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4ecaa001/ambari-web/app/views/main/host/summary.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/host/summary.js 
b/ambari-web/app/views/main/host/summary.js
index a0c1ac4..47a56fa 100644
--- a/ambari-web/app/views/main/host/summary.js
+++ b/ambari-web/app/views/main/host/summary.js
@@ -122,7 +122,13 @@ App.MainHostSummaryView = Em.View.extend({
   },
   didInsertElement: function () {
     this.loadDecommissionNodesList();
+    this.addToolTip();
   },
+  addToolTip: function() {
+    if (this.get('addComponentDisabled')) {
+      $('#add_component').tooltip({title: Em.I18n.t('services.nothingToAdd')});
+    }
+  }.observes('addComponentDisabled'),
   sortedComponents: function () {
     var slaveComponents = [];
     var masterComponents = [];
@@ -166,7 +172,11 @@ App.MainHostSummaryView = Em.View.extend({
   isAddComponent: function () {
     return this.get('content.healthClass') !== 'health-status-DEAD-YELLOW';
   }.property('content.healthClass'),
-  
+
+  addComponentDisabled: function() {
+    return (!this.get('isAddComponent')) || 
(this.get('addableComponents.length') == 0);
+  }.property('isAddComponent', 'addableComponents.length'),
+
   installableClientComponents: function() {
     var installableClients = [];
     if (!App.supports.deleteHost) {

http://git-wip-us.apache.org/repos/asf/incubator-ambari/blob/4ecaa001/ambari-web/app/views/main/service.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/service.js 
b/ambari-web/app/views/main/service.js
index 9ed9d61..a06d091 100644
--- a/ambari-web/app/views/main/service.js
+++ b/ambari-web/app/views/main/service.js
@@ -19,5 +19,13 @@
 var App = require('app');
 
 App.MainServiceView = Em.View.extend({
-  templateName:require('templates/main/service')
+  templateName:require('templates/main/service'),
+  didInsertElement: function() {
+    this.addToolTip();
+  },
+  addToolTip: function() {
+    if (this.get('controller.isAllServicesInstalled')) {
+      $('.add-service-button a').tooltip({title: 
Em.I18n.t('services.nothingToAdd')});
+    }
+  }.observes('controller.isAllServicesInstalled')
 });
\ No newline at end of file

Reply via email to