浏览代码

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

Oleg Nechiporenko 11 年之前
父节点
当前提交
4ecaa001a7

+ 43 - 2
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');
   }
-})
+
+});

+ 15 - 19
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>

+ 24 - 24
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">

+ 11 - 0
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;

+ 11 - 1
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) {

+ 9 - 1
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')
 });