Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CHE-3257: display version number in CHE dashboard from API request #3379

Merged
merged 1 commit into from
Dec 14, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions dashboard/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,6 @@
<replacetoken><![CDATA[<base href="/">]]></replacetoken>
<replacevalue><![CDATA[<base href="/dashboard/">]]></replacevalue>
</replace>
<replaceregexp file="${basedir}/dist/assets/branding/product.json" flags="m">
<regexp pattern="project_version" />
<substitution expression="${project.version}" />
</replaceregexp>
</target>
</configuration>
</execution>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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: '',
Expand Down
3 changes: 1 addition & 2 deletions dashboard/src/assets/branding/product.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,5 @@
"helpPath": "https://www.eclipse.org/che/",
"helpTitle": "Community",
"supportEmail": "[email protected]",
"oauthDocs": "Configure OAuth in the che.properties file.",
"version": "project_version"
"oauthDocs": "Configure OAuth in the che.properties file."
}
52 changes: 47 additions & 5 deletions dashboard/src/components/api/che-service.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string>;
/**
* 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);
});
Expand All @@ -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<T>}
*/
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;
}
}
1 change: 1 addition & 0 deletions dashboard/src/components/api/test/che-http-backend.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
24 changes: 16 additions & 8 deletions dashboard/src/components/branding/che-branding.factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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);
});

Expand Down Expand Up @@ -99,9 +111,5 @@ export class CheBranding {
getProductSupportEmail() {
return this.supportEmail;
}

getProductVersion() {
return this.version;
}
}

2 changes: 2 additions & 0 deletions dashboard/src/components/validator/custom-validator.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -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"></che-footer>
</div>
<!-- Addons are not automatically injected -->
Expand Down