ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From srima...@apache.org
Subject ambari git commit: AMBARI-9528. TEZ Ambari view - Make bookmarking functional for TEZ view (Sreenath Somarajapuram via srimanth)
Date Fri, 06 Feb 2015 23:18:38 GMT
Repository: ambari
Updated Branches:
  refs/heads/trunk bdee006b5 -> 87b85a527


AMBARI-9528. TEZ Ambari view - Make bookmarking functional for TEZ view (Sreenath Somarajapuram
via srimanth)


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

Branch: refs/heads/trunk
Commit: 87b85a5277044373eb2170a0f419477f376a7d2e
Parents: bdee006
Author: Srimanth Gunturi <sgunturi@hortonworks.com>
Authored: Fri Feb 6 15:17:21 2015 -0800
Committer: Srimanth Gunturi <sgunturi@hortonworks.com>
Committed: Fri Feb 6 15:17:38 2015 -0800

----------------------------------------------------------------------
 .../resources/ui/scripts/init-ambari-view.js    | 134 +++++++++++++++++--
 1 file changed, 120 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/ambari/blob/87b85a52/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
----------------------------------------------------------------------
diff --git a/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js b/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
index 8c4856f..b43183e 100644
--- a/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
+++ b/contrib/views/tez/src/main/resources/ui/scripts/init-ambari-view.js
@@ -16,6 +16,70 @@
  * limitations under the License.
  */
 
+App.deferReadiness();
+
+var TEZ_PARAM = "tezPath";
+
+function createParam(path) {
+  return '%@=%@'.fmt(TEZ_PARAM, encodeURIComponent(path));
+}
+
+function getSetParam(queryString, path) {
+  if(queryString) {
+    var params = queryString.split('&'),
+        param;
+
+    for(var i = 0, count = params.length; i < count; i++) {
+      param = params[i];
+
+      if(param.substr(0, TEZ_PARAM.length) == TEZ_PARAM) {
+        if(path != undefined) {
+          if(path == '') {
+            params.splice(i, 1);
+          }
+          else {
+            params[i] = createParam(path);
+          }
+          return params.join('&');
+        }
+        else {
+          return decodeURIComponent(param.split('=')[1]);
+        }
+      }
+    }
+  }
+  // If param was empty and path is available, set.
+  return (path != undefined && path != '') ? createParam(path) : '';
+}
+
+// Redirect if required
+function redirectionCheck() {
+  var href = window.location.href;
+
+  // If opened outside ambari, redirect
+  if(window.parent == window) {
+    var hrefParts = href.split('/#/'),
+        ambariLink = hrefParts[0].replace('/views/', '/#/main/views/');
+
+    href = '%@?%@'.fmt(ambariLink, getSetParam('', hrefParts[1] || ''));
+  }
+  // If opened inside ambari with a path different from current path redirect iframe
+  else {
+    var parentHref = window.parent.location.href.split('?'),
+        tezPath = getSetParam(parentHref[1]),
+        currentPath = href.split('/#/')[1];
+
+    if(tezPath && tezPath != currentPath) {
+      href = '%@#/%@'.fmt(parentHref[0].replace('/#/main/views/', '/views/'), tezPath);
+    }
+  }
+
+  if(href != window.location.href) {
+    window.location = href;
+    return true;
+  }
+}
+
 App.Helpers.ambari = (function () {
   /**
    * Stores parameters from Ambari.
@@ -100,21 +164,63 @@ App.Helpers.ambari = (function () {
 
 })();
 
-App.deferReadiness();
-App.Helpers.ambari.getInstanceParameters().then(function () {
-  $.extend(true, App.Configs, {
-    envDefaults: {
-      isStandalone: false,
-      timelineBaseUrl: App.Helpers.ambari.getParam(App.Helpers.ambari.TIMELINE_URL),
-      RMWebUrl: App.Helpers.ambari.getParam(App.Helpers.ambari.RM_URL)
+function allowFullScreen() {
+  if(window.parent) {
+    var arrFrames = parent.document.getElementsByTagName("IFRAME"),
+        iframe;
+    for (var i = 0; i < arrFrames.length; i++) {
+      if (arrFrames[i].contentWindow === window) {
+        iframe = arrFrames[i];
+        break;
+      }
+    }
+
+    if(iframe) {
+      iframe.setAttribute('AllowFullScreen', true);
     }
+  }
+}
+
+function loadParams() {
+  App.Helpers.ambari.getInstanceParameters().then(function () {
+    $.extend(true, App.Configs, {
+      envDefaults: {
+        isStandalone: false,
+        timelineBaseUrl: App.Helpers.ambari.getParam(App.Helpers.ambari.TIMELINE_URL),
+        RMWebUrl: App.Helpers.ambari.getParam(App.Helpers.ambari.RM_URL)
+      }
+    });
+
+    App.advanceReadiness();
   });
+}
 
-  App.advanceReadiness();
-});
+function onPathChange() {
+  var path = window.location.hash.substr(2).trim(),
+      urlParts = window.parent.location.href.split('?'),
+      queryParam = getSetParam(urlParts[1], path);
+  window.parent.history.replaceState(
+    null,
+    null,
+    queryParam ? '%@?%@'.fmt(urlParts[0], queryParam) : urlParts[0]
+  );
+}
 
-Ember.$.ajaxSetup({
-  beforeSend: function (jqXHR, settings) {
-    settings.url = location.pathname + 'proxy?url=' + encodeURIComponent(settings.url);
-  }
-});
+if(!redirectionCheck()) {
+  App.ApplicationRoute.reopen({
+    actions: {
+      didTransition: function (arguments) {
+        setTimeout(onPathChange, 100);
+      }
+    }
+  });
+
+  allowFullScreen();
+  loadParams();
+
+  Ember.$.ajaxSetup({
+    beforeSend: function (jqXHR, settings) {
+      settings.url = location.pathname + 'proxy?url=' + encodeURIComponent(settings.url);
+    }
+  });
+}


Mime
View raw message