Browse Source

HUE-8926 [frontend] Use json source for app switcher URLs

Johan Ahlen 6 years ago
parent
commit
3f7a9668bf

File diff suppressed because it is too large
+ 32 - 0
desktop/core/src/desktop/js/ko/components/appSwitcher/apps.v2.json


+ 83 - 0
desktop/core/src/desktop/js/ko/components/appSwitcher/environment.js

@@ -0,0 +1,83 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. 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.
+
+const Environment = {
+  MOCK: 'MOCK',
+  LOCAL: 'LOCAL',
+  DEV: 'DEV',
+  INT: 'INT',
+  STAGE: 'STAGE',
+  PROD: 'PROD'
+};
+
+/**
+ * Returns environment type based on current url.
+ * @param ignoreLocalHost If set to true, localhost section of the url is ignored.
+ * E.g., PROD is returned for localhost.altus.cloudera.com
+ */
+const getEnvironment = () => {
+  const hostName = window.location.hostname;
+  if (!hostName.indexOf('localhost.') > -1) {
+    return Environment.LOCAL;
+  }
+  if (hostName.indexOf('-dev.cloudera.com') > -1) {
+    return Environment.DEV;
+  }
+  if (hostName.indexOf('-int.cloudera.com') > -1) {
+    return Environment.INT;
+  }
+  if (hostName.indexOf('-stage.cloudera.com') > -1) {
+    return Environment.STAGE;
+  }
+  if (hostName.indexOf('.cloudera.com') > -1) {
+    return Environment.PROD;
+  }
+  return Environment.MOCK;
+};
+
+export const getAltusBaseUrl = () => {
+  const environment = getEnvironment();
+  switch (environment) {
+    case Environment.MOCK:
+      return '';
+    case Environment.LOCAL:
+      return '';
+    case Environment.DEV:
+      return 'https://console.thunderhead-dev.cloudera.com';
+    case Environment.INT:
+      return 'https://console.thunderhead-int.cloudera.com';
+    case Environment.STAGE:
+      return 'https://console.thunderhead-stage.cloudera.com';
+    case Environment.PROD:
+      return 'https://console.altus.cloudera.com';
+  }
+};
+
+export const getMowBaseUrl = () => {
+  const environment = getEnvironment();
+  switch (environment) {
+    case Environment.MOCK:
+    case Environment.LOCAL:
+    case Environment.DEV:
+      return 'https://cloudera.dps.mow-dev.cloudera.com';
+    case Environment.INT:
+      return 'https://cloudera.cdp.mow-int.cloudera.com';
+    case Environment.STAGE:
+      return 'https://cloudera.cdp.mow-stage.cloudera.com';
+    case Environment.PROD:
+      return '';
+  }
+};

+ 91 - 0
desktop/core/src/desktop/js/ko/components/appSwitcher/ko.appSwitcher.js

@@ -0,0 +1,91 @@
+// Licensed to Cloudera, Inc. under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  Cloudera, Inc. 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.
+
+import $ from 'jquery';
+import ko from 'knockout';
+
+import apps from 'ko/components/appSwitcher/apps.v2';
+import componentUtils from 'ko/components/componentUtils';
+import { getAltusBaseUrl, getMowBaseUrl } from 'ko/components/appSwitcher/environment';
+
+const TEMPLATE = `
+  <div class="hue-sidebar-header">
+    <a class="hue-app-switcher-trigger" data-bind="toggle: open"><svg class="show"><use xlink:href="#hi-app-picker"></use></svg></a>
+  </div>
+
+  <div class="hue-app-switcher" data-bind="css: { 'open': open }">
+    <h3>Cloudera Data Platform</h3>
+    <ul data-bind="foreach: links">
+      <li><a data-bind="attr: { href: url }"><i data-bind="html: svg"></i><span data-bind="text: label"></span></a></li>
+    </ul>
+  </div>
+`;
+
+const AppSwitcher = function AppSwitcher(params, element) {
+  this.links = [];
+
+  const getUrl = (baseUrl, path) => {
+    if (baseUrl === 'mow') {
+      return getMowBaseUrl() + path;
+    } else if (baseUrl === 'altus') {
+      return getAltusBaseUrl() + path;
+    }
+    console.warn('Could not find baseUrl for "' + baseUrl + '", using relative link instead.');
+    return path;
+  };
+
+  apps.forEach(app => {
+    this.links.push({
+      label: app.displayName,
+      svg: app.logo,
+      url: getUrl(app.baseUrl, app.path)
+    });
+  });
+
+  this.open = ko.observable(false);
+
+  const closeOnClickOutside = event => {
+    if (!this.open()) {
+      return;
+    }
+    if (
+      $.contains(document, event.target) &&
+      !$.contains($('.hue-app-switcher')[0], event.target)
+    ) {
+      this.open(false);
+    }
+  };
+
+  this.open.subscribe(newVal => {
+    if (newVal) {
+      window.setTimeout(() => {
+        $(document).on('click', closeOnClickOutside);
+      }, 0);
+    } else {
+      $(document).off('click', closeOnClickOutside);
+    }
+  });
+};
+
+componentUtils.registerComponent(
+  'hue-app-switcher',
+  {
+    createViewModel: function(params, componentInfo) {
+      return new AppSwitcher(params, componentInfo.element);
+    }
+  },
+  TEMPLATE
+);

File diff suppressed because it is too large
+ 0 - 63
desktop/core/src/desktop/js/ko/components/ko.appSwitcher.js


+ 1 - 1
desktop/core/src/desktop/js/ko/ko.all.js

@@ -127,6 +127,7 @@ import 'ko/bindings/ko.typeahead';
 import 'ko/bindings/ko.verticalSlide';
 import 'ko/bindings/ko.verticalSlide';
 import 'ko/bindings/ko.visibleOnHover';
 import 'ko/bindings/ko.visibleOnHover';
 
 
+import 'ko/components/appSwitcher/ko.appSwitcher';
 import 'ko/components/assist/ko.assistDashboardPanel';
 import 'ko/components/assist/ko.assistDashboardPanel';
 import 'ko/components/assist/ko.assistDbPanel';
 import 'ko/components/assist/ko.assistDbPanel';
 import 'ko/components/assist/ko.assistDocumentsPanel';
 import 'ko/components/assist/ko.assistDocumentsPanel';
@@ -141,7 +142,6 @@ import 'ko/components/assist/ko.assistStoragePanel';
 import 'ko/components/assist/ko.rightAssistPanel';
 import 'ko/components/assist/ko.rightAssistPanel';
 import 'ko/components/contextPopover/ko.contextPopover';
 import 'ko/components/contextPopover/ko.contextPopover';
 import 'ko/components/simpleAceEditor/ko.simpleAceEditor';
 import 'ko/components/simpleAceEditor/ko.simpleAceEditor';
-import 'ko/components/ko.appSwitcher';
 import 'ko/components/ko.catalogEntriesList';
 import 'ko/components/ko.catalogEntriesList';
 import 'ko/components/ko.contextSelector';
 import 'ko/components/ko.contextSelector';
 import 'ko/components/ko.createDirectoryModal';
 import 'ko/components/ko.createDirectoryModal';

File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue-embedded.css


File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue.css


File diff suppressed because it is too large
+ 0 - 0
desktop/core/src/desktop/static/desktop/css/hue3-extra.css


+ 1 - 1
desktop/core/src/desktop/static/desktop/less/components/hue-app-switcher.less

@@ -51,7 +51,7 @@
 
 
   ul {
   ul {
     list-style: none;
     list-style: none;
-    padding: 24px;
+    padding: 24px 0 24px 24px;
     margin: 0;
     margin: 0;
 
 
     li a {
     li a {

Some files were not shown because too many files changed in this diff