From 32515517bf288697e3c5adaaeabf8899ab2d5fb0 Mon Sep 17 00:00:00 2001 From: Vitaliy Gulyy Date: Mon, 30 Sep 2019 16:57:33 +0300 Subject: [PATCH] refactor: remove unused code (#14480) Signed-off-by: Vitaliy Gulyy --- dashboard/src/app/index.module.ts | 18 ++- dashboard/src/assets/branding/product.json | 1 - .../branding/che-branding.factory.ts | 11 -- dashboard/src/components/components-config.ts | 2 - .../ide-fetcher/che-ide-fetcher-config.ts | 23 --- .../ide-fetcher/che-ide-fetcher.service.ts | 132 ------------------ 6 files changed, 12 insertions(+), 175 deletions(-) delete mode 100644 dashboard/src/components/ide-fetcher/che-ide-fetcher-config.ts delete mode 100644 dashboard/src/components/ide-fetcher/che-ide-fetcher.service.ts diff --git a/dashboard/src/app/index.module.ts b/dashboard/src/app/index.module.ts index 74eb26da7d0..58a899a9c62 100755 --- a/dashboard/src/app/index.module.ts +++ b/dashboard/src/app/index.module.ts @@ -31,8 +31,6 @@ import {DemoComponentsController} from './demo-components/demo-components.contro import {CheBranding} from '../components/branding/che-branding.factory'; import {ChePreferences} from '../components/api/che-preferences.factory'; import {RoutingRedirect} from '../components/routing/routing-redirect.factory'; -import IdeIFrameSvc from './ide/ide-iframe/ide-iframe.service'; -import {CheIdeFetcher} from '../components/ide-fetcher/che-ide-fetcher.service'; import {RouteHistory} from '../components/routing/route-history.service'; import {CheUIElementsInjectorService} from '../components/service/injector/che-ui-elements-injector.service'; import {OrganizationsConfig} from './organizations/organizations-config'; @@ -260,8 +258,18 @@ initModule.config(['$routeProvider', ($routeProvider: che.route.IRouteProvider) /** * Setup route redirect module */ -initModule.run(['$rootScope', '$location', '$routeParams', 'routingRedirect', '$timeout', '$mdSidenav', 'cheIdeFetcher', 'routeHistory', 'cheUIElementsInjectorService', 'workspaceDetailsService', - ($rootScope: che.IRootScopeService, $location: ng.ILocationService, $routeParams: ng.route.IRouteParamsService, routingRedirect: RoutingRedirect, $timeout: ng.ITimeoutService, $mdSidenav: ng.material.ISidenavService, cheIdeFetcher: CheIdeFetcher, routeHistory: RouteHistory, cheUIElementsInjectorService: CheUIElementsInjectorService) => { +initModule.run(['$rootScope', '$location', '$routeParams', 'routingRedirect', '$timeout', '$mdSidenav', 'routeHistory', 'cheUIElementsInjectorService', 'workspaceDetailsService', + ( + $rootScope: che.IRootScopeService, + $location: ng.ILocationService, + $routeParams: ng.route.IRouteParamsService, + routingRedirect: RoutingRedirect, + $timeout: ng.ITimeoutService, + $mdSidenav: ng.material.ISidenavService, + routeHistory: RouteHistory, + cheUIElementsInjectorService: CheUIElementsInjectorService + ) => { + $rootScope.hideLoader = false; $rootScope.waitingLoaded = false; $rootScope.showIDE = false; @@ -269,7 +277,6 @@ initModule.run(['$rootScope', '$location', '$routeParams', 'routingRedirect', '$ // here only to create instances of these components /* tslint:disable */ - cheIdeFetcher; routeHistory; /* tslint:enable */ @@ -324,7 +331,6 @@ initModule.run(['$rootScope', '$location', '$routeParams', 'routingRedirect', '$ ]); initModule.config(['$mdThemingProvider', 'jsonColors', ($mdThemingProvider: ng.material.IThemingProvider, jsonColors: any) => { - const cheColors = angular.fromJson(jsonColors); const getColor = (key: string) => { let color = cheColors[key]; diff --git a/dashboard/src/assets/branding/product.json b/dashboard/src/assets/branding/product.json index e25667bc795..8bddddc035e 100644 --- a/dashboard/src/assets/branding/product.json +++ b/dashboard/src/assets/branding/product.json @@ -5,7 +5,6 @@ "logoTextFile": "che-logo-text.svg", "favicon": "favicon.ico", "loader": "loader.svg", - "ideResources": "/_app/", "websocketContext": "/api/websocket", "helpPath": "https://www.eclipse.org/che/", "helpTitle": "Community", diff --git a/dashboard/src/components/branding/che-branding.factory.ts b/dashboard/src/components/branding/che-branding.factory.ts index a0ddbebfb94..38e552f0b46 100644 --- a/dashboard/src/components/branding/che-branding.factory.ts +++ b/dashboard/src/components/branding/che-branding.factory.ts @@ -19,7 +19,6 @@ interface IBranding { logoTextFile?: string; favicon?: string; loader?: string; - ideResources?: string; websocketContext?: string; helpPath?: string; helpTitle?: string; @@ -56,7 +55,6 @@ const DEFAULT_PRODUCT_FAVICON = 'favicon.ico'; const DEFAULT_LOADER = 'loader.svg'; const DEFAULT_PRODUCT_LOGO = 'che-logo.svg'; const DEFAULT_PRODUCT_LOGO_TEXT = 'che-logo-text.svg'; -const DEFAULT_IDE_RESOURCES_PATH = '/_app/'; const DEFAULT_OAUTH_DOCS = 'Configure OAuth in the che.properties file.'; const DEFAULT_CLI_NAME = 'che.env'; const DEFAULT_CLI_CONFIG_NAME = 'CHE'; @@ -125,7 +123,6 @@ export class CheBranding { logoText: this.getProductLogoText(), favicon: this.getProductFavicon(), loaderURL: this.getLoaderUrl(), - ideResourcesPath: this.getIdeResourcesPath(), websocketContext: this.getWebsocketContext(), helpPath: this.getProductHelpPath(), helpTitle: this.getProductHelpTitle(), @@ -207,14 +204,6 @@ export class CheBranding { return this.brandingData.loader ? ASSET_PREFIX + this.brandingData.loader : ASSET_PREFIX + DEFAULT_LOADER; } - /** - * Gets ide resources path. - * @returns {string} - */ - getIdeResourcesPath(): string { - return this.brandingData.ideResources ? this.brandingData.ideResources : DEFAULT_IDE_RESOURCES_PATH; - } - /** * Gets ide resources path. * @returns {string} diff --git a/dashboard/src/components/components-config.ts b/dashboard/src/components/components-config.ts index 7911b573fa3..e42795b6735 100644 --- a/dashboard/src/components/components-config.ts +++ b/dashboard/src/components/components-config.ts @@ -17,7 +17,6 @@ import {AttributeConfig} from './attribute/attribute-config'; import {FilterConfig} from './filter/filter-config'; import {CheBrandingConfig} from './branding/che-branding-config'; import {GitHubService} from './github/github-service'; -import {CheIdeFetcherConfig} from './ide-fetcher/che-ide-fetcher-config'; import {CheNotificationConfig} from './notification/che-notification-config'; import {RoutingConfig} from './routing/routing-config'; import {ValidatorConfig} from './validator/validator-config'; @@ -38,7 +37,6 @@ export class ComponentsConfig { new FilterConfig(register); new CheBrandingConfig(register); new GitHubService(register); - new CheIdeFetcherConfig(register); new CheNotificationConfig(register); new RoutingConfig(register); new ValidatorConfig(register); diff --git a/dashboard/src/components/ide-fetcher/che-ide-fetcher-config.ts b/dashboard/src/components/ide-fetcher/che-ide-fetcher-config.ts deleted file mode 100644 index f9cef8ad9b5..00000000000 --- a/dashboard/src/components/ide-fetcher/che-ide-fetcher-config.ts +++ /dev/null @@ -1,23 +0,0 @@ -/* - * Copyright (c) 2015-2018 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -'use strict'; - -import {CheIdeFetcher} from './che-ide-fetcher.service'; - -export class CheIdeFetcherConfig { - - constructor(register: che.IRegisterService) { - - register.factory('cheIdeFetcher', CheIdeFetcher); - - } -} diff --git a/dashboard/src/components/ide-fetcher/che-ide-fetcher.service.ts b/dashboard/src/components/ide-fetcher/che-ide-fetcher.service.ts deleted file mode 100644 index 8321ff238e6..00000000000 --- a/dashboard/src/components/ide-fetcher/che-ide-fetcher.service.ts +++ /dev/null @@ -1,132 +0,0 @@ -/* - * Copyright (c) 2015-2018 Red Hat, Inc. - * This program and the accompanying materials are made - * available under the terms of the Eclipse Public License 2.0 - * which is available at https://www.eclipse.org/legal/epl-2.0/ - * - * SPDX-License-Identifier: EPL-2.0 - * - * Contributors: - * Red Hat, Inc. - initial API and implementation - */ -'use strict'; -import {CheBranding} from '../branding/che-branding.factory'; - -const IDE_FETCHER_CALLBACK_ID = 'cheIdeFetcherCallback'; - -/** - * Provides a way to download IDE .js and then cache it before trying to load the IDE - * @author Florent Benoit - * @author Oleksii Orel - */ -export class CheIdeFetcher { - - static $inject = ['$log', '$http', '$window', 'cheBranding']; - - private $log: ng.ILogService; - private $http: ng.IHttpService; - private $window: ng.IWindowService; - private cheBranding: CheBranding; - private userAgent: string; - - /** - * Default constructor that is using resource injection - */ - constructor($log: ng.ILogService, $http: ng.IHttpService, $window: ng.IWindowService, cheBranding: CheBranding) { - this.$log = $log; - this.$http = $http; - this.$window = $window; - this.cheBranding = cheBranding; - - this.userAgent = this.getUserAgent(); - - const callback = () => { - this.findMappingFile(); - this.cheBranding.unregisterCallback(IDE_FETCHER_CALLBACK_ID); - }; - this.cheBranding.registerCallback(IDE_FETCHER_CALLBACK_ID, callback.bind(this)); - } - - /** - * Gets user agent. - * @returns {string} - */ - getUserAgent(): string { - const userAgent = this.$window.navigator.userAgent.toLowerCase(); - const docMode = (this.$window.document).documentMode; - - if (userAgent.indexOf('webkit') !== -1) { - return 'safari'; - } else if (userAgent.indexOf('msie') !== -1) { - if (docMode >= 10 && docMode < 11) { - return 'ie10'; - } else if (docMode >= 9 && docMode < 11) { - return 'ie9'; - } else if (docMode >= 8 && docMode < 11) { - return 'ie8'; - } - } else if (userAgent.indexOf('gecko') !== -1) { - return 'gecko1_8'; - } - - return 'unknown'; - } - - /** - * Finds mapping file. - */ - findMappingFile(): void { - // get the content of the compilation mapping file - const randVal = Math.floor((Math.random() * 1000000) + 1); - const resourcesPath = this.cheBranding.getIdeResourcesPath(); - if (!resourcesPath) { - this.$log.log('Unable to get IDE resources path'); - return; - } - - const fileMappingUrl = `${resourcesPath}compilation-mappings.txt?uid=${randVal}`; - - this.$http.get(fileMappingUrl).then((response: {data: any}) => { - if (!response || !response.data) { - return; - } - let urlToLoad = this.getIdeUrlMappingFile(response.data); - // load the url - if (angular.isDefined(urlToLoad)) { - this.$log.log('Preloading IDE javascript', urlToLoad); - this.$http.get(urlToLoad, { cache: true}); - } else { - this.$log.error('Unable to find the IDE javascript file to cache'); - } - }, (error: any) => { - this.$log.log('unable to find compilation mapping file', error); - }); - } - - /** - * Gets URL of mapping file. - * @param data {string} - * @returns {string} - */ - getIdeUrlMappingFile(data: string): string { - let mappingFileUrl: string; - let javascriptFileName: string; - const mappings = data.split(new RegExp('^\\n', 'gm')); - const isPasses = mappings.some((mapping: string) => { - const subMappings = mapping.split('\n'); - const userAgent = subMappings.find((subMapping: string) => { - return subMapping.startsWith('user.agent '); - }).split(' ')[1]; - javascriptFileName = subMappings.find((subMapping: string) => { - return subMapping.endsWith('.cache.js'); - }); - return javascriptFileName && userAgent && this.userAgent === userAgent; - }); - if (isPasses && javascriptFileName) { - mappingFileUrl = this.cheBranding.getIdeResourcesPath() + javascriptFileName; - } - - return mappingFileUrl; - } - -}