From f5854fd32c19c44d32a3e6739b30271d4dccd393 Mon Sep 17 00:00:00 2001 From: Avi Ziv Date: Mon, 31 Jul 2017 15:50:46 +0300 Subject: [SDC] code rebase for sdc resync to LF Change-Id: If6d87c9e324f508a8a6b80b10a03d1843901472e Signed-off-by: Michael Lando --- catalog-ui/src/app/models.ts | 1 + catalog-ui/src/app/models/modal.ts | 4 +- catalog-ui/src/app/models/server-error-response.ts | 84 +++++ catalog-ui/src/app/ng2/app.module.ts | 19 +- .../ui-element-integer-input.component.ts | 2 +- .../inputs-table/inputs-table.component.html | 2 +- .../inputs-table/inputs-table.component.ts | 2 +- .../ng2/components/loader/loader.component.html | 3 +- .../ng2/components/loader/loader.component.less | 16 + .../app/ng2/components/loader/loader.component.ts | 66 ++-- .../error-message/error-message.component.html | 5 + .../modal/error-message/error-message.component.ts | 38 +++ .../app/ng2/components/modal/modal.component.html | 8 +- .../app/ng2/components/modal/modal.component.less | 15 +- .../app/ng2/components/modal/modal.component.ts | 6 +- .../src/app/ng2/components/modal/modal.module.ts | 9 +- .../properties-table.component.html | 2 +- .../properties-assignment.module.ts | 3 +- .../properties-assignment.page.component.html | 2 +- .../properties-assignment.page.component.less | 15 +- .../properties-assignment.page.component.ts | 24 +- .../properties-assignment/properties.utils.ts | 4 +- .../component-instance.service.ts | 4 +- .../component-services/component.service.ts | 8 +- .../services/component-services/service.service.ts | 4 +- .../src/app/ng2/services/data-type.service.ts | 2 + .../app/ng2/services/http.interceptor.service.ts | 162 --------- catalog-ui/src/app/ng2/services/http.service.ts | 29 +- catalog-ui/src/app/ng2/services/modal.service.ts | 27 +- .../src/app/services/event-listener-service.ts | 2 +- catalog-ui/src/app/utils/constants.ts | 6 + .../onboard-vendor/onboard-vendor-view-model.ts | 10 +- .../onboard-vendor/onboard-vendor-view.html | 2 +- .../workspace/tabs/activity-log/activity-log.ts | 1 - .../tabs/attributes/attributes-view-model.ts | 1 - .../tabs/composition/composition-view-model.ts | 7 +- .../tabs/artifacts/artifacts-view-model.ts | 3 +- .../deployment-artifacts-view-model.ts | 1 - .../tabs/deployment/deployment-view-model.ts | 1 - .../tabs/distribution/distribution-view-model.ts | 1 - .../workspace/tabs/general/general-view-model.ts | 1 - .../information-artifacts-view-model.ts | 1 - .../resource-input/resource-inputs-view-model.ts | 1 - .../service-input/service-inputs-view-model.ts | 1 - .../management-workflow-view-model.ts | 225 ++++++------- .../management-workflow-view.html | 5 +- .../network-call-flow-view-model.ts | 10 +- .../network-call-flow/network-call-flow-view.html | 3 +- .../tabs/properties/properties-view-model.ts | 1 - .../req-and-capabilities-view-model.ts | 1 - .../tosca-artifacts/tosca-artifacts-view-model.ts | 1 - .../view-models/workspace/workspace-view-model.ts | 8 +- catalog-ui/src/assets/styles/app.less | 2 +- catalog-ui/src/assets/styles/sdc-ui.css | 361 --------------------- catalog-ui/src/index.html | 2 +- catalog-ui/src/third-party/PunchOutRegistry.js | 27 +- .../CytoscapeEdgeEditation.js | 3 +- 57 files changed, 468 insertions(+), 786 deletions(-) create mode 100644 catalog-ui/src/app/models/server-error-response.ts create mode 100644 catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.html create mode 100644 catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.ts delete mode 100644 catalog-ui/src/app/ng2/services/http.interceptor.service.ts delete mode 100644 catalog-ui/src/assets/styles/sdc-ui.css (limited to 'catalog-ui/src') diff --git a/catalog-ui/src/app/models.ts b/catalog-ui/src/app/models.ts index f3eb5d5fa6..ec70ebe8b1 100644 --- a/catalog-ui/src/app/models.ts +++ b/catalog-ui/src/app/models.ts @@ -95,6 +95,7 @@ export * from './models/member'; export * from './models/modules/base-module'; export * from './models/properties'; export * from './models/requirement'; +export * from './models/server-error-response'; export * from './models/tab'; export * from './models/tooltip-data'; export * from './models/user'; diff --git a/catalog-ui/src/app/models/modal.ts b/catalog-ui/src/app/models/modal.ts index 51aa5e19a7..b7bdf251fe 100644 --- a/catalog-ui/src/app/models/modal.ts +++ b/catalog-ui/src/app/models/modal.ts @@ -5,12 +5,14 @@ export class ModalModel { title: string; content: any; buttons: Array; + type: string; 'standard|error|alert' - constructor(size?: string, title?: string, content?: any, buttons?: Array) { + constructor(size?: string, title?: string, content?: any, buttons?: Array, type?:string) { this.size = size; this.title = title; this.content = content; this.buttons = buttons; + this.type = type || 'standard'; } } diff --git a/catalog-ui/src/app/models/server-error-response.ts b/catalog-ui/src/app/models/server-error-response.ts new file mode 100644 index 0000000000..61d09af48b --- /dev/null +++ b/catalog-ui/src/app/models/server-error-response.ts @@ -0,0 +1,84 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +/** + * Created by ngordon on 7/27/2017. + */ + +import { Response } from '@angular/http'; +import { SEVERITY, ServerErrors } from "../utils/constants"; + +export class ServerErrorResponse { + + title: string; + message: string; + messageId: string; + status: number; + severity: SEVERITY; + + constructor(response?: Response) { + + if (response) { + let rejectionObj: any = {}; + if (response.text().length) { + let rejection = response.json(); + rejectionObj = rejection.serviceException || rejection.requestError && (rejection.requestError.serviceException || rejection.requestError.policyException); + rejectionObj.text = this.getFormattedMessage(rejectionObj.text || ServerErrors.MESSAGE_ERROR, rejectionObj.variables); + } + + this.title = ServerErrors.ERROR_TITLE; + this.message = rejectionObj.text || response.statusText || ServerErrors.DEFAULT_ERROR; + this.messageId = rejectionObj.messageId; + this.status = response.status; + this.severity = SEVERITY.ERROR; + } + } + + + private getFormattedMessage = (text: string, variables: Array): string => { //OLD CODE + // Remove the "Error: " text at the begining + if (text.trim().indexOf("Error:") === 0) { + text = text.replace("Error:", "").trim(); + } + + //mshitrit DE199895 bug fix + let count: number = 0; + variables.forEach(function (item) { + variables[count] = item ? item.replace('<', '<').replace('>', '>') : ''; + count++; + }); + + // Format the message in case has array to
  • + text = text.replace(/\[%(\d+)\]/g, function (_, m) { + let tmp = []; + let list = variables[--m].split(";"); + list.forEach(function (item) { + tmp.push("
  • " + item + "
  • "); + }); + return "
      " + tmp.join("") + "
    "; + }); + + // Format the message %1 %2 + text = text.format(variables); + + return text; + + }; +} \ No newline at end of file diff --git a/catalog-ui/src/app/ng2/app.module.ts b/catalog-ui/src/app/ng2/app.module.ts index 57adb8fd66..88c2d876c4 100644 --- a/catalog-ui/src/app/ng2/app.module.ts +++ b/catalog-ui/src/app/ng2/app.module.ts @@ -32,14 +32,13 @@ import { } from "./utils/ng1-upgraded-provider"; import {ConfigService} from "./services/config.service"; import {HttpModule} from '@angular/http'; +import {HttpService} from './services/http.service'; import {AuthenticationService} from './services/authentication.service'; import {Cookie2Service} from "./services/cookie.service"; import {ComponentServiceNg2} from "./services/component-services/component.service"; import {ServiceServiceNg2} from "./services/component-services/service.service"; import {ComponentInstanceServiceNg2} from "./services/component-instance-services/component-instance.service"; -import { InterceptorService } from 'ng2-interceptors'; import { XHRBackend, RequestOptions } from '@angular/http'; -import {HttpInterceptor} from "./services/http.interceptor.service"; import { SearchBarComponent } from './shared/search-bar/search-bar.component'; import { SearchWithAutoCompleteComponent } from './shared/search-with-autocomplete/search-with-autocomplete.component'; @@ -49,16 +48,6 @@ export function configServiceFactory(config:ConfigService) { return () => config.loadValidationConfiguration(); } -export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: RequestOptions){ - let service = new InterceptorService(xhrBackend, requestOptions); - service.addInterceptor(new HttpInterceptor()); - return service; -} - - -// export function httpServiceFactory(backend: XHRBackend, options: RequestOptions) { -// return new HttpService(backend, options); -// } @NgModule({ declarations: [ @@ -87,6 +76,7 @@ export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: Reque ConfigService, ComponentServiceNg2, ServiceServiceNg2, + HttpService, ComponentInstanceServiceNg2, { provide: APP_INITIALIZER, @@ -94,11 +84,6 @@ export function interceptorFactory(xhrBackend: XHRBackend, requestOptions: Reque deps: [ConfigService], multi: true }, - { - provide: InterceptorService, - useFactory: interceptorFactory, - deps: [XHRBackend, RequestOptions] - } ], bootstrap: [AppComponent] }) diff --git a/catalog-ui/src/app/ng2/components/dynamic-element/elements-ui/integer-input/ui-element-integer-input.component.ts b/catalog-ui/src/app/ng2/components/dynamic-element/elements-ui/integer-input/ui-element-integer-input.component.ts index 8b27ab7e3a..3339b605ca 100644 --- a/catalog-ui/src/app/ng2/components/dynamic-element/elements-ui/integer-input/ui-element-integer-input.component.ts +++ b/catalog-ui/src/app/ng2/components/dynamic-element/elements-ui/integer-input/ui-element-integer-input.component.ts @@ -35,7 +35,7 @@ export class UiElementIntegerInputComponent extends UiElementBase implements UiE onSave() { if (!this.control.invalid){ - this.baseEmitter.emit(JSON.parse(this.value)); + this.baseEmitter.emit(this.value ? JSON.parse(this.value) : this.value); } } } diff --git a/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.html b/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.html index 38de3ce649..2b58d0f086 100644 --- a/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.html +++ b/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.html @@ -1,5 +1,5 @@
    - +
    Property Name
    From Instance
    diff --git a/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.ts b/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.ts index 30cdb89d8e..736655f3f7 100644 --- a/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.ts +++ b/catalog-ui/src/app/ng2/components/inputs-table/inputs-table.component.ts @@ -57,7 +57,7 @@ export class InputsTableComponent { openDeleteModal = (input:InputFEModel) => { this.selectedInputToDelete = input; - this.modalService.openActionModal("Delete Input", "Are you sure you want to delete this input?", "Delete", this.onDeleteInput, "Close"); + this.modalService.createActionModal("Delete Input", "Are you sure you want to delete this input?", "Delete", this.onDeleteInput, "Close").instance.open(); } } diff --git a/catalog-ui/src/app/ng2/components/loader/loader.component.html b/catalog-ui/src/app/ng2/components/loader/loader.component.html index 0e13cee674..a62aa114d9 100644 --- a/catalog-ui/src/app/ng2/components/loader/loader.component.html +++ b/catalog-ui/src/app/ng2/components/loader/loader.component.html @@ -1,4 +1,5 @@ -
    +
    diff --git a/catalog-ui/src/app/ng2/components/loader/loader.component.less b/catalog-ui/src/app/ng2/components/loader/loader.component.less index 054b6021a1..ddb9915176 100644 --- a/catalog-ui/src/app/ng2/components/loader/loader.component.less +++ b/catalog-ui/src/app/ng2/components/loader/loader.component.less @@ -16,6 +16,22 @@ z-index: 10002; } +.loader-relative { + display: block; + position:absolute; + width: 100%; + height:100%; +} + +.loader-fixed { + display: block; + position:fixed; + top:0; + left:0; + width: 100%; + height:100%; +} + @keyframes fadein { from { opacity: 0; } to { opacity: 0.8; } diff --git a/catalog-ui/src/app/ng2/components/loader/loader.component.ts b/catalog-ui/src/app/ng2/components/loader/loader.component.ts index 92278d3ff5..f66aa551e2 100644 --- a/catalog-ui/src/app/ng2/components/loader/loader.component.ts +++ b/catalog-ui/src/app/ng2/components/loader/loader.component.ts @@ -21,7 +21,7 @@ /** * Created by rc2122 on 6/6/2017. */ -import {Component, Input, ElementRef, Renderer, SimpleChanges} from "@angular/core"; +import { Component, Input, ViewContainerRef, SimpleChanges} from "@angular/core"; @Component({ selector: 'loader', templateUrl: './loader.component.html', @@ -29,13 +29,20 @@ import {Component, Input, ElementRef, Renderer, SimpleChanges} from "@angular/co }) export class LoaderComponent { - @Input() display:boolean; - @Input() size:string;// small || medium || large - @Input() relative: boolean; - @Input() elementSelector: string; // optional. If is relative is set to true, option to pass in element that loader should be relative to. Otherwise, will be relative to parent element. + @Input() display: boolean; + @Input() size: string;// small || medium || large + @Input() relative: boolean; // If is relative is set to true, loader will appear over parent element. Otherwise, will be fixed over the entire page. + @Input() loaderDelay: number; //optional - number of ms to delay loader display. + private isVisible: boolean = false; + private offset : { + top: string; + left: string; + width: string; + height: string; + }; - constructor (private el: ElementRef, private renderer: Renderer){ + constructor(private viewContainerRef: ViewContainerRef) { } ngOnInit() { @@ -49,46 +56,31 @@ export class LoaderComponent { ngOnChanges(changes: SimpleChanges) { if(changes.display){ - if (this.display) { - this.changeLoaderDisplay(false); //display is set to true, so loader will appear unless we explicitly tell it not to. - window.setTimeout((): void => { - this.display && this.changeLoaderDisplay(true); //only show loader if we still need to display it. - }, 500); - } else { - window.setTimeout(():void => { - this.changeLoaderDisplay(false); - }, 0); - } + this.changeLoaderDisplay(this.display); } } - changeLoaderDisplay = (display: boolean): void => { + private changeLoaderDisplay = (display: boolean): void => { if (display) { - this.calculateLoaderPosition(); - this.renderer.setElementStyle(this.el.nativeElement, 'display', 'block'); + window.setTimeout((): void => { + this.display && this.showLoader(); //only show loader if this.display has not changed in the meanwhile. + }, this.loaderDelay || 0); } else { - this.renderer.setElementStyle(this.el.nativeElement, 'display', 'none'); + this.isVisible = false; } } - calculateLoaderPosition = () => { - if (this.relative === true) { // Can change the parent position to relative without causing style issues. - let parent = (this.elementSelector) ? angular.element(this.elementSelector).get(0) : this.el.nativeElement.parentElement; - this.renderer.setElementStyle(parent, 'position', 'relative'); - this.setLoaderPosition(0, 0); //will be relative to parent and appear over specified element - //TODO: DONT force parent to have position relative; set inner div's style instead of outer element - // let parentPos: ClientRect = this.el.nativeElement.parentElement.getBoundingClientRect(); - // this.setLoaderPosition(parentPos.top, parentPos.left, parentPos.width, parentPos.height); - } else { - this.setLoaderPosition(0, 0); //will appear over whole page + private showLoader = () => { + if (this.relative === true) { + let parentElement = this.viewContainerRef.element.nativeElement.parentElement; + this.offset = { + left: (parentElement.offsetLeft) ? parentElement.offsetLeft + "px" : undefined, + top: (parentElement.offsetTop) ? parentElement.offsetTop + "px" : undefined, + width: (parentElement.offsetWidth) ? parentElement.offsetWidth + "px" : undefined, + height: (parentElement.offsetHeight) ? parentElement.offsetHeight + "px" : undefined + }; } + this.isVisible = true; } - setLoaderPosition = (top:number, left:number, width?:number, height?:number): void => { - this.renderer.setElementStyle(this.el.nativeElement, 'position', 'absolute'); - this.renderer.setElementStyle(this.el.nativeElement, 'top', top? top.toString() : "0"); - this.renderer.setElementStyle(this.el.nativeElement, 'left', left? left.toString() : "0"); - this.renderer.setElementStyle(this.el.nativeElement, 'width', width? width.toString() : "100%"); - this.renderer.setElementStyle(this.el.nativeElement, 'height', height? height.toString() : "100%"); - }; } diff --git a/catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.html b/catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.html new file mode 100644 index 0000000000..433bd4fd6f --- /dev/null +++ b/catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.html @@ -0,0 +1,5 @@ +
    +
    Error code: {{input.messageId}}
    +
    Status code: {{input.status}}
    +
    {{input.message}}
    +
    \ No newline at end of file diff --git a/catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.ts b/catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.ts new file mode 100644 index 0000000000..c0d6673412 --- /dev/null +++ b/catalog-ui/src/app/ng2/components/modal/error-message/error-message.component.ts @@ -0,0 +1,38 @@ +/*- + * ============LICENSE_START======================================================= + * SDC + * ================================================================================ + * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved. + * ================================================================================ + * Licensed 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. + * ============LICENSE_END========================================================= + */ + +/** + * Created by ngordon on 7/30/2017. + */ +import { Component, Input } from '@angular/core'; +import { ServerErrorResponse } from 'app/models'; + +@Component({ + selector: 'error-message', + templateUrl: './error-message.component.html' +}) + +export class ErrorMessageComponent { + @Input() input: ServerErrorResponse; + + constructor() { + } + +} diff --git a/catalog-ui/src/app/ng2/components/modal/modal.component.html b/catalog-ui/src/app/ng2/components/modal/modal.component.html index cc411bc751..d843867cdb 100644 --- a/catalog-ui/src/app/ng2/components/modal/modal.component.html +++ b/catalog-ui/src/app/ng2/components/modal/modal.component.html @@ -1,10 +1,14 @@
    -
    + -
    {{input.content}}
    +
    +
    {{input.content}}
    +
    +
    +