From b42ccbf59a1f8c4a6c88fc3165653c28b471da7a Mon Sep 17 00:00:00 2001 From: Ann Shumilova Date: Wed, 19 Apr 2017 12:19:47 +0300 Subject: [PATCH] Add caption, empty message and additional info to namespace registry Signed-off-by: Ann Shumilova --- .../workspace-details.controller.ts | 54 ++++++++++++++++- .../workspace-details/workspace-details.html | 24 +++++--- .../workspace-details/workspace-details.styl | 12 ++++ .../che-namespace-registry.factory.ts | 60 ++++++++++++++++++- 4 files changed, 140 insertions(+), 10 deletions(-) diff --git a/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts b/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts index a3e42f436ee..00e51ad60c4 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts +++ b/dashboard/src/app/workspaces/workspace-details/workspace-details.controller.ts @@ -51,6 +51,7 @@ export class WorkspaceDetailsController { namespaceId: string = ''; namespaceLabel: string; namespaceLabels: Array; + namespaceInfo: String; onNamespaceChanged: Function; workspaceId: string = ''; workspaceName: string = ''; @@ -188,12 +189,14 @@ export class WorkspaceDetailsController { this.namespaceId = namespace ? namespace.id : (this.getNamespaces().length ? this.getNamespaces()[0].id : undefined); this.namespaceLabel = namespace ? namespace.label : (this.getNamespaces().length ? this.getNamespaces()[0].label : undefined); this.namespaceLabels = this.getNamespaces().length ? this.lodash.pluck(this.getNamespaces(), 'label') : []; + this.fetchNamespaceInfo(); this.onNamespaceChanged = (label: string) => { let namespace = this.getNamespaces().find((namespace: any) => { return namespace.label === label; }); this.namespaceId = namespace ? namespace.id : this.namespaceId; + this.fetchNamespaceInfo(); } }); } @@ -268,7 +271,7 @@ export class WorkspaceDetailsController { */ getWorkspaceStatus(): string { if (this.isCreationFlow) { - return 'CREATING'; + return 'New'; } let unknownStatus = 'unknown'; @@ -312,6 +315,17 @@ export class WorkspaceDetailsController { } } + fetchNamespaceInfo() { + if (!this.cheNamespaceRegistry.getAdditionalInfo()) { + this.namespaceInfo = null; + return; + } + + this.cheNamespaceRegistry.getAdditionalInfo()(this.namespaceId).then((info: string) => { + this.namespaceInfo = info; + }); + } + /** * Callback when Team button is clicked in Edit mode. * Redirects to billing details or team details. @@ -657,7 +671,7 @@ export class WorkspaceDetailsController { return tabs.some((tabIndex: number) => { return this.checkFormsNotValid(tabIndex); - }); + }) || this.isDisableWorkspaceCreation(); } /** @@ -687,5 +701,41 @@ export class WorkspaceDetailsController { } } + /** + * Returns namespaces empty message if set. + * + * @returns {string} + */ + getNamespaceEmptyMessage(): string { + return this.cheNamespaceRegistry.getEmptyMessage(); + } + + /** + * Returns namespaces caption. + * + * @returns {string} + */ + getNamespaceCaption(): string { + return this.cheNamespaceRegistry.getCaption(); + } + + /** + * Returns namespaces additional information. + * + * @returns {()=>Function} + */ + getNamespaceAdditionalInfo(): Function { + return this.cheNamespaceRegistry.getAdditionalInfo; + } + + /** + * Returns whether workspace creation should be disabled based on namespaces. + * + * @returns {boolean|string} + */ + isDisableWorkspaceCreation(): boolean { + let namespaces = this.cheNamespaceRegistry.getNamespaces(); + return (this.isCreationFlow && (!namespaces || namespaces.length === 0) && this.cheNamespaceRegistry.getEmptyMessage()); + } } diff --git a/dashboard/src/app/workspaces/workspace-details/workspace-details.html b/dashboard/src/app/workspaces/workspace-details/workspace-details.html index af9990b1778..bb35b404ab9 100644 --- a/dashboard/src/app/workspaces/workspace-details/workspace-details.html +++ b/dashboard/src/app/workspaces/workspace-details/workspace-details.html @@ -62,13 +62,23 @@ - - - + +
+ + + {{workspaceDetailsController.namespaceInfo}} + +
+
+ + {{workspaceDetailsController.getNamespaceEmptyMessage()}} +
+ ; private namespaces : INamespace[]; + private emptyMessage: string; + private caption: string; + private getAdditionalInfoFunction: Function; /** * Default constructor that is using resource @@ -33,6 +35,8 @@ export class CheNamespaceRegistry { constructor($q: ng.IQService) { this.$q = $q; this.namespaces = []; + + this.caption = 'Namespace'; } /** @@ -76,4 +80,58 @@ export class CheNamespaceRegistry { getNamespaces() : INamespace[] { return this.namespaces; } + + /** + * Set empty message (message is displayed, when no namespaces). + * + * @param message empty message + */ + setEmptyMessage(message: string): void { + this.emptyMessage = message; + } + + /** + * Returns empty message to display, when no namespaces. + * + * @returns {string} + */ + getEmptyMessage(): string { + return this.emptyMessage ? this.emptyMessage : null; + } + + /** + * Set display caption of the namespaces. + * + * @param caption namespaces caption + */ + setCaption(caption: string): void { + this.caption = caption; + } + + /** + * Returns the caption of the namespaces. + * + * @returns {string} namepsaces caption + */ + getCaption(): string { + return this.caption; + } + + /** + * Sets the function for retrieving available RAM for the namespaces. + * + * @param getAdditionalInfo additional information function + */ + setGetAdditionalInfo(getAdditionalInfo: Function): void { + this.getAdditionalInfoFunction = getAdditionalInfo; + } + + /** + * Returns function, that returns promise. + * + * @returns {Function} + */ + getAdditionalInfo(): Function { + return this.getAdditionalInfoFunction; + } }