Explorar el Código

AMBARI-7635. Slider View: configured with bad props, JS error (Max Shepel via onechiporenko)

Oleg Nechiporenko hace 10 años
padre
commit
ac70302451

+ 27 - 0
contrib/views/slider/src/main/resources/ui/app/controllers/application_controller.js

@@ -0,0 +1,27 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+App.ApplicationController = Ember.Controller.extend({
+
+  /**
+   * Determines if Slider View instance has any configuration errors
+   * @type {boolean}
+   */
+  hasConfigErrors: false
+
+});

+ 3 - 0
contrib/views/slider/src/main/resources/ui/app/mappers/slider_apps_mapper.js

@@ -53,6 +53,7 @@ App.SliderAppsMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
       sender: this,
       success: 'parse'
     }).fail(function(jqXHR, textStatus){
+        App.__container__.lookup('controller:application').set('hasConfigErrors', true);
         if (!self.get('isWarningPopupShown')) {
           var message = textStatus === "timeout" ? "timeout" : jqXHR.responseText;
           self.set('isWarningPopupShown', true);
@@ -231,6 +232,8 @@ App.SliderAppsMapper = App.Mapper.createWithMixins(App.RunPeriodically, {
       self = this,
       appsToDelete = App.SliderApp.store.all('sliderApp').get('content').mapProperty('id');
 
+    App.__container__.lookup('controller:application').set('hasConfigErrors', false);
+
     if (this.get('isWarningPopupShown')) {
       this.closeWarningPopup();
       this.set('isWarningPopupShown', false);

+ 1 - 1
contrib/views/slider/src/main/resources/ui/app/templates/application.hbs

@@ -35,7 +35,7 @@
 <div class="slider-header">
   {{#view view.SliderTitleView}}
       <h3 class="pull-left" id="slider-title"><span class="slider-app-title">{{App.label}}</span></h3>
-    {{#if view.isIndexPage}}
+    {{#if view.showCreateAppButton}}
       <div class="box-header pull-right">
         <div class="create-app">
           <a href="#" class="btn btn-primary" {{action createApp}}>

+ 5 - 2
contrib/views/slider/src/main/resources/ui/app/views/application_view.js

@@ -37,10 +37,13 @@ App.ApplicationView = Ember.View.extend({
       })
     }.property('content'),
 
-    isIndexPage: function () {
+    showCreateAppButton: function () {
+      if (this.get('controller.hasConfigErrors')) {
+        return false;
+      }
       var currentPath = this.get('controller.currentPath');
       return currentPath && (currentPath == 'slider_apps.index' || currentPath.indexOf('slider_apps.createAppWizard') != -1);
-    }.property('controller.currentPath'),
+    }.property('controller.currentPath', 'controller.hasConfigErrors'),
 
     /**
      * Set <code>popover</code> template