From dc5517f3b6f41da6f2330dc0a8d30af6c7761987 Mon Sep 17 00:00:00 2001 From: Ann Shumilova Date: Wed, 14 Dec 2016 13:31:12 +0200 Subject: [PATCH] CHE-3257: display version number in CHE dashboard from API request Signed-off-by: Ann Shumilova --- dashboard/pom.xml | 4 -- .../workspace-recipe-import.directive.spec.ts | 2 + dashboard/src/assets/branding/product.json | 3 +- .../src/components/api/che-service.factory.ts | 52 +++++++++++++++++-- .../components/api/test/che-http-backend.ts | 1 + .../branding/che-branding.factory.ts | 24 ++++++--- .../validator/custom-validator.spec.ts | 2 + dashboard/src/index.html | 2 +- 8 files changed, 70 insertions(+), 20 deletions(-) diff --git a/dashboard/pom.xml b/dashboard/pom.xml index 86326190744..a14e2f41964 100644 --- a/dashboard/pom.xml +++ b/dashboard/pom.xml @@ -79,10 +79,6 @@ ]]> ]]> - - - - diff --git a/dashboard/src/app/workspaces/workspace-details/select-stack/recipe-import/workspace-recipe-import.directive.spec.ts b/dashboard/src/app/workspaces/workspace-details/select-stack/recipe-import/workspace-recipe-import.directive.spec.ts index f828eb06dac..3cd02e4712d 100644 --- a/dashboard/src/app/workspaces/workspace-details/select-stack/recipe-import/workspace-recipe-import.directive.spec.ts +++ b/dashboard/src/app/workspaces/workspace-details/select-stack/recipe-import/workspace-recipe-import.directive.spec.ts @@ -36,7 +36,9 @@ describe('WorkspaceRecipeImport', () => { $compile = _$compile_; httpBackend = cheHttpBackend.getHttpBackend(); + // avoid tracking requests from branding controller httpBackend.whenGET(/.*/).respond(200, ''); + httpBackend.when('OPTIONS', '/api/').respond({}); $rootScope.model = { recipeUrl: '', diff --git a/dashboard/src/assets/branding/product.json b/dashboard/src/assets/branding/product.json index c2a66c7393a..3ef39ef9837 100644 --- a/dashboard/src/assets/branding/product.json +++ b/dashboard/src/assets/branding/product.json @@ -9,6 +9,5 @@ "helpPath": "https://www.eclipse.org/che/", "helpTitle": "Community", "supportEmail": "wish@codenvy.com", - "oauthDocs": "Configure OAuth in the che.properties file.", - "version": "project_version" + "oauthDocs": "Configure OAuth in the che.properties file." } diff --git a/dashboard/src/components/api/che-service.factory.ts b/dashboard/src/components/api/che-service.factory.ts index 50fee51140f..5651d1c7490 100644 --- a/dashboard/src/components/api/che-service.factory.ts +++ b/dashboard/src/components/api/che-service.factory.ts @@ -16,24 +16,43 @@ * @author Ann Shumilova */ export class CheService { + /** + * Service for performing HTTP requests. + */ + private $http: ng.IHttpService; + + private servicesPromise: ng.IPromise; + /** + * The list of available services. + */ + private services: Array; + /** + * Information about services. + */ + private servicesInfo: any; /** * Default constructor that is using resource * @ngInject for Dependency injection */ - constructor ($http) { + constructor ($http: ng.IHttpService) { this.$http = $http; } - fetchServices() { + /** + * Fetches all available services. + * + * @returns {ng.IPromise} + */ + fetchServices(): ng.IPromise { if (this.servicesPromise) { return this.servicesPromise; } let promise = this.$http.get('/api/'); - this.servicesPromise = promise.then((response) => { + this.servicesPromise = promise.then((response: any) => { this.services = []; - response.data.rootResources.forEach((service) => { + response.data.rootResources.forEach((service: any) => { let path = service.path.charAt(0) === '/' ? service.path.substr(1) : service.path; this.services.push(path); }); @@ -44,13 +63,36 @@ export class CheService { /** * Checks whether service is available. + * @param name service name * @returns {Boolean|*} */ - isServiceAvailable(name) { + isServiceAvailable(name: string): boolean { if (!this.services) { return false; } return this.services.indexOf(name) > -1; } + + /** + * Fetches the services info. + * + * @returns {IHttpPromise} + */ + fetchServicesInfo(): ng.IPromise { + let promise = this.$http({'method': 'OPTIONS', 'url': '/api/'}); + let infoPromise = promise.then((response: any) => { + this.servicesInfo = response.data; + }); + return infoPromise; + } + + /** + * Returns services information. + * + * @returns {any} servies information + */ + getServicesInfo(): any { + return this.servicesInfo; + } } diff --git a/dashboard/src/components/api/test/che-http-backend.ts b/dashboard/src/components/api/test/che-http-backend.ts index c6f614d18f4..99b61f36a4c 100644 --- a/dashboard/src/components/api/test/che-http-backend.ts +++ b/dashboard/src/components/api/test/che-http-backend.ts @@ -52,6 +52,7 @@ export class CheHttpBackend { this.addWorkspaceAgent(key, tmpWorkspace.runtime); this.httpBackend.when('GET', '/api/workspace/' + key).respond(tmpWorkspace); } + this.httpBackend.when('OPTIONS', '/api/').respond({}); this.httpBackend.when('GET', '/api/workspace').respond(workspaceReturn); diff --git a/dashboard/src/components/branding/che-branding.factory.ts b/dashboard/src/components/branding/che-branding.factory.ts index ca8268bc255..43ad07fd6f3 100644 --- a/dashboard/src/components/branding/che-branding.factory.ts +++ b/dashboard/src/components/branding/che-branding.factory.ts @@ -9,23 +9,37 @@ * Codenvy, S.A. - initial API and implementation */ 'use strict'; +import {CheService} from '../api/che-service.factory'; /** * This class is handling the branding data in Che * @author Florent Benoit */ export class CheBranding { + $q: ng.IQService; + $rootScope: che.IRootScopeService; + $http: ng.IHttpService; + cheService: CheService; /** * Default constructor that is using resource * @ngInject for Dependency injection */ - constructor($http, $rootScope, $q) { + constructor($http: ng.IHttpService, $rootScope: che.IRootScopeService, $q: ng.IQService, cheService: CheService) { this.$http = $http; this.$rootScope = $rootScope; this.deferred = $q.defer(); this.promise = this.deferred.promise; + this.cheService = cheService; this.updateData(); + this.getVersion(); + } + + getVersion() { + this.cheService.fetchServicesInfo().then(() => { + let info = this.cheService.getServicesInfo(); + this.$rootScope.productVersion = (info && info.implementationVersion) ? info.implementationVersion : ''; + }); } updateData() { @@ -48,8 +62,7 @@ export class CheBranding { helpPath : brandingData.helpPath, helpTitle : brandingData.helpTitle, supportEmail: brandingData.supportEmail, - oauthDocs: brandingData.oauthDocs, - version: brandingData.version + oauthDocs: brandingData.oauthDocs }; this.productName = this.$rootScope.branding.title; @@ -62,7 +75,6 @@ export class CheBranding { this.helpTitle = this.$rootScope.branding.helpTitle; this.supportEmail = this.$rootScope.branding.supportEmail; this.oauthDocs = this.$rootScope.branding.oauthDocs; - this.version = this.$rootScope.branding.version; this.deferred.resolve(this.$rootScope.branding); }); @@ -99,9 +111,5 @@ export class CheBranding { getProductSupportEmail() { return this.supportEmail; } - - getProductVersion() { - return this.version; - } } diff --git a/dashboard/src/components/validator/custom-validator.spec.ts b/dashboard/src/components/validator/custom-validator.spec.ts index a89d8260d0a..5e9729da02e 100644 --- a/dashboard/src/components/validator/custom-validator.spec.ts +++ b/dashboard/src/components/validator/custom-validator.spec.ts @@ -30,7 +30,9 @@ describe('custom-validator', () => { $compile = _$compile_; httpBackend = cheHttpBackend.getHttpBackend(); + // avoid tracking requests from branding controller httpBackend.whenGET(/.*/).respond(200, ''); + httpBackend.when('OPTIONS', '/api/').respond({}); $scope.validateFn = (value) => { return value % 2 === 0; diff --git a/dashboard/src/index.html b/dashboard/src/index.html index 03d981d8530..85984cb52cc 100644 --- a/dashboard/src/index.html +++ b/dashboard/src/index.html @@ -56,7 +56,7 @@ che-support-help-title="{{branding.helpTitle}}" che-support-email="{{branding.supportEmail}}" che-logo="{{branding.logoURL}}" - che-version="{{branding.version}}" + che-version="{{productVersion}}" che-product-name="Eclipse Che" ng-show="waitingLoaded && !showIDE">