ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From atk...@apache.org
Subject [2/2] ambari git commit: AMBARI-9529 Ambari view - View iframe pointing to invalid link when ambari url contains query parameters. (atkach)
Date Wed, 11 Feb 2015 19:34:19 GMT
AMBARI-9529 Ambari view - View iframe pointing to invalid link when ambari url contains query
parameters. (atkach)


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

Branch: refs/heads/trunk
Commit: 032bbd760fb4dae566734779f1b6999958a0ffcc
Parents: 143f381
Author: Andrii Tkach <atkach@hortonworks.com>
Authored: Wed Feb 11 21:32:56 2015 +0200
Committer: Andrii Tkach <atkach@hortonworks.com>
Committed: Wed Feb 11 21:34:11 2015 +0200

----------------------------------------------------------------------
 ambari-web/app/assets/test/tests.js        |  1 +
 ambari-web/app/routes/views.js             | 33 +++++++++++++++-
 ambari-web/app/views/main/views/details.js |  2 +-
 ambari-web/test/routes/views_test.js       | 50 +++++++++++++++++++++++++
 4 files changed, 83 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/032bbd76/ambari-web/app/assets/test/tests.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/assets/test/tests.js b/ambari-web/app/assets/test/tests.js
index 454fd8d..cd0dc1d 100644
--- a/ambari-web/app/assets/test/tests.js
+++ b/ambari-web/app/assets/test/tests.js
@@ -255,6 +255,7 @@ var files = ['test/init_model_test',
   'test/models/user_test',
   'test/models/host_stack_version_test',
   'test/models/upgrade_entity_test',
+  'test/routes/views_test',
   //contains test with fake timers that affect Date
   'test/utils/lazy_loading_test'
 

http://git-wip-us.apache.org/repos/asf/ambari/blob/032bbd76/ambari-web/app/routes/views.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/routes/views.js b/ambari-web/app/routes/views.js
index b0e2f15..68ba817 100644
--- a/ambari-web/app/routes/views.js
+++ b/ambari-web/app/routes/views.js
@@ -35,10 +35,39 @@ module.exports = Em.Route.extend({
     route: '/:viewName/:version/:instanceName',
     connectOutlets: function (router, params) {
       // find and set content for `mainViewsDetails` and associated controller
+
+      var href = ['/views', params.viewName, params.version, params.instanceName].join('/');
+      var viewPath = this.parseViewPath(params.instanceName);
+      if (viewPath) {
+        href = ['/views', params.viewName, params.version, params.instanceName.slice(0, params.instanceName.lastIndexOf('?'))].join('/');
+      }
+
       router.get('mainViewsController').dataLoading().done(function() {
-        router.get('mainController').connectOutlet('mainViewsDetails', App.router.get('mainViewsController.ambariViews')
-          .findProperty('href', ['/views', params.viewName, params.version, params.instanceName].join('/')));
+        var content = App.router.get('mainViewsController.ambariViews').findProperty('href',
href);
+        if (content) content.set('viewPath', viewPath);
+        router.get('mainController').connectOutlet('mainViewsDetails', content);
       });
+    },
+    /**
+     * parse internal view path
+     * "viewPath" - used as a key of additional path
+     * Example:
+     *   origin URL: viewName?viewPath=%2Fuser%2Fadmin%2Faddress&foo=bar&count=1
+     * should be translated to
+     *   view path: /user/admin/address?foo=bar&count=1
+     *
+     * @param {string} instanceName
+     * @returns {string}
+     */
+    parseViewPath: function (instanceName) {
+      var path = '';
+      if (instanceName.contains('?')) {
+        path = instanceName.slice(instanceName.indexOf('?'));
+        if (path.contains('viewPath')) {
+          path = decodeURIComponent(path.slice((path.lastIndexOf('?viewPath=') + 10))).replace('&',
'?');
+        }
+      }
+      return path;
     }
   })
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/032bbd76/ambari-web/app/views/main/views/details.js
----------------------------------------------------------------------
diff --git a/ambari-web/app/views/main/views/details.js b/ambari-web/app/views/main/views/details.js
index 453724c..e90cb20 100644
--- a/ambari-web/app/views/main/views/details.js
+++ b/ambari-web/app/views/main/views/details.js
@@ -87,7 +87,7 @@ App.MainViewsDetailsView = Em.View.extend({
 
   src: function() {
     // can't use window.location.origin because IE doesn't support it
-    return window.location.protocol + '//' + window.location.host + this.get('controller.content.href');
+    return window.location.protocol + '//' + window.location.host + this.get('controller.content.href')
+ this.get('controller.content.viewPath');
   }.property('controller.content')
 
 });

http://git-wip-us.apache.org/repos/asf/ambari/blob/032bbd76/ambari-web/test/routes/views_test.js
----------------------------------------------------------------------
diff --git a/ambari-web/test/routes/views_test.js b/ambari-web/test/routes/views_test.js
new file mode 100644
index 0000000..b5c5cf7
--- /dev/null
+++ b/ambari-web/test/routes/views_test.js
@@ -0,0 +1,50 @@
+/**
+ * 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.
+ */
+
+var routeClass = require('routes/views');
+
+describe('routes/views', function() {
+
+  var route = routeClass.create().get('viewDetails').create();
+
+  describe("#parseViewPath", function() {
+    var testCases = [
+      {
+        url: 'viewName',
+        result: ''
+      },
+      {
+        url: 'viewName?foo=bar&count=1',
+        result: '?foo=bar&count=1'
+      },
+      {
+        url: 'viewName?viewPath=%2Fuser%2Fadmin%2Faddress',
+        result: '/user/admin/address'
+      },
+      {
+        url: 'viewName?viewPath=%2Fuser%2Fadmin%2Faddress&foo=bar&count=1',
+        result: '/user/admin/address?foo=bar&count=1'
+      }
+    ].forEach(function(test){
+        it("url = " + test.url, function() {
+          expect(route.parseViewPath(test.url)).to.equal(test.result);
+        });
+      });
+  });
+
+});


Mime
View raw message