From 008518dc35ded3bb6dc3e6352472b5816271f583 Mon Sep 17 00:00:00 2001 From: Lvbo163 Date: Thu, 11 Jan 2018 10:22:16 +0800 Subject: adjust folder change fold menu to menus Issue-ID: SDC-900 Change-Id: Ifce180badf4f468a3291b118bfd4f631483541ec Signed-off-by: Lvbo163 --- sdc-workflow-designer-ui/src/app/app.component.css | 2 +- sdc-workflow-designer-ui/src/app/app.module.ts | 40 +++++---- .../src/app/components/menu/menus.component.css | 23 ----- .../src/app/components/menu/menus.component.html | 31 ------- .../app/components/menu/menus.component.spec.ts | 36 -------- .../src/app/components/menu/menus.component.ts | 82 ----------------- .../microservice-detail.component.html | 49 ---------- .../microservice-detail.component.ts | 100 --------------------- .../microservice-list.component.css | 15 ---- .../microservice-list.component.html | 32 ------- .../microservice-list.component.ts | 81 ----------------- .../menu/microservice/microservice.component.html | 39 -------- .../menu/microservice/microservice.component.ts | 48 ---------- .../menu/workflows/workflows.component.html | 41 --------- .../menu/workflows/workflows.component.ts | 55 ------------ .../src/app/components/menus/menus.component.css | 23 +++++ .../src/app/components/menus/menus.component.html | 31 +++++++ .../app/components/menus/menus.component.spec.ts | 36 ++++++++ .../src/app/components/menus/menus.component.ts | 82 +++++++++++++++++ .../microservice-detail.component.html | 49 ++++++++++ .../microservice-detail.component.ts | 100 +++++++++++++++++++++ .../microservice-list.component.css | 15 ++++ .../microservice-list.component.html | 32 +++++++ .../microservice-list.component.ts | 81 +++++++++++++++++ .../menus/microservice/microservice.component.html | 39 ++++++++ .../menus/microservice/microservice.component.ts | 48 ++++++++++ .../menus/workflows/workflows.component.html | 41 +++++++++ .../menus/workflows/workflows.component.ts | 55 ++++++++++++ .../app/directive/resizable/resizable.directive.ts | 42 +++++++++ .../directive/resizeable/resizable.directive.ts | 42 --------- .../src/app/util/http.service.ts | 33 ++++--- .../src/app/util/rxjs-operators.ts | 1 + 32 files changed, 719 insertions(+), 705 deletions(-) delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/menus.component.css delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/menus.component.html delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/menus.component.spec.ts delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/menus.component.ts delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.html delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.ts delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.css delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.html delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.ts delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.html delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.ts delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html delete mode 100644 sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.ts create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/menus.component.css create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/menus.component.html create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/menus.component.spec.ts create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/menus.component.ts create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.html create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.ts create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.css create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.html create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.ts create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.html create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.ts create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.html create mode 100644 sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.ts create mode 100644 sdc-workflow-designer-ui/src/app/directive/resizable/resizable.directive.ts delete mode 100644 sdc-workflow-designer-ui/src/app/directive/resizeable/resizable.directive.ts (limited to 'sdc-workflow-designer-ui/src/app') diff --git a/sdc-workflow-designer-ui/src/app/app.component.css b/sdc-workflow-designer-ui/src/app/app.component.css index 95166937..5ad27fed 100644 --- a/sdc-workflow-designer-ui/src/app/app.component.css +++ b/sdc-workflow-designer-ui/src/app/app.component.css @@ -9,7 +9,7 @@ * Contributors: * ZTE - initial API and implementation and/or initial documentation */ - .loading-div{ +.loading-div{ position: absolute; top: 0; width: 100%; diff --git a/sdc-workflow-designer-ui/src/app/app.module.ts b/sdc-workflow-designer-ui/src/app/app.module.ts index 3d5aa778..9785a69e 100644 --- a/sdc-workflow-designer-ui/src/app/app.module.ts +++ b/sdc-workflow-designer-ui/src/app/app.module.ts @@ -33,10 +33,10 @@ import { BroadcastService } from "./services/broadcast.service"; import { PropertiesComponent } from "./components/property/properties.component"; import { StartEventParametersComponent } from "./components/property/start-event-parameters/start-event-parameters.component"; import { ParameterComponent } from "./components/parameter/parameter.component"; -import { MenusComponent } from "./components/menu/menus.component"; -import { MicroserviceDetailComponent } from "./components/menu/microservice/microservice-detail/microservice-detail.component"; -import { MicroserviceComponent } from "./components/menu/microservice/microservice.component"; -import { MicroserviceListComponent } from "./components/menu/microservice/microservice-list/microservice-list.component"; +import { MenusComponent } from "./components/menus/menus.component"; +import { MicroserviceDetailComponent } from "./components/menus/microservice/microservice-detail/microservice-detail.component"; +import { MicroserviceComponent } from "./components/menus/microservice/microservice.component"; +import { MicroserviceListComponent } from "./components/menus/microservice/microservice-list/microservice-list.component"; import { ModalModule } from "ngx-bootstrap/modal"; import { WorkflowConfigService } from "./services/workflow-config.service"; import { RestTaskComponent } from "./components/property/rest-task/rest-task.component"; @@ -45,11 +45,11 @@ import { SwaggerTreeConverterService } from "./services/swagger-tree-converter.s import { IntermediateCatchEventComponent } from "./components/property/intermediate-catch-event/intermediate-catch-event.component"; import { SequenceFlowComponent } from "./components/sequence-flow/sequence-flow.component"; import { ScriptTaskComponent } from "./components/property/script-task/script-task.component"; -import { WorkflowsComponent } from "./components/menu/workflows/workflows.component"; +import { WorkflowsComponent } from "./components/menus/workflows/workflows.component"; import { ModelService } from './services/model.service'; import { ContainerComponent } from './components/container/container.component'; import { RestService } from './services/rest.service'; -import { ResizableDirective } from './directive/resizeable/resizable.directive'; +import { ResizableDirective } from './directive/resizable/resizable.directive'; import { StartEventComponent } from './components/property/start-event/start-event.component'; import { NodeParametersComponent } from './components/node-parameters/node-parameters.component'; import { ParameterTreeComponent } from './components/node-parameters/parameter-tree/parameter-tree.component'; @@ -78,6 +78,18 @@ import { ParameterTreeComponent } from './components/node-parameters/parameter-t ToolbarComponent, WorkflowsComponent, ], + providers: [ + BroadcastService, + DataAccessService, + HttpService, + JsPlumbService, + ModelService, + RestService, + SwaggerTreeConverterService, + WorkflowConfigService, + + WorkflowService + ], imports: [ AccordionModule.forRoot(), BrowserAnimationsModule, @@ -97,17 +109,9 @@ import { ParameterTreeComponent } from './components/node-parameters/parameter-t allowParentSelection: false }) ], - providers: [ - BroadcastService, - DataAccessService, - HttpService, - JsPlumbService, - RestService, - SwaggerTreeConverterService, - WorkflowConfigService, - ModelService, - WorkflowService + bootstrap: [ + AppComponent, ], - bootstrap: [AppComponent] }) -export class AppModule { } +export class AppModule { +} diff --git a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.css b/sdc-workflow-designer-ui/src/app/components/menu/menus.component.css deleted file mode 100644 index 6ba4133b..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.css +++ /dev/null @@ -1,23 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - -.btn-right{ - float: right; -} - -.btn-left{ - float: left; -} - -button i{ - padding-right: 3px; -} diff --git a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.html b/sdc-workflow-designer-ui/src/app/components/menu/menus.component.html deleted file mode 100644 index 7e043829..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.html +++ /dev/null @@ -1,31 +0,0 @@ - - -
- -
-
- - - - -
- - diff --git a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.spec.ts b/sdc-workflow-designer-ui/src/app/components/menu/menus.component.spec.ts deleted file mode 100644 index b80edce7..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.spec.ts +++ /dev/null @@ -1,36 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ -import { async, ComponentFixture, TestBed } from '@angular/core/testing'; - -import { MenuComponent } from './menu.component'; - -describe('MenuComponent', () => { - let component: MenuComponent; - let fixture: ComponentFixture; - - beforeEach(async(() => { - TestBed.configureTestingModule({ - declarations: [MenuComponent] - }) - .compileComponents(); - })); - - beforeEach(() => { - fixture = TestBed.createComponent(MenuComponent); - component = fixture.componentInstance; - fixture.detectChanges(); - }); - - it('should be created', () => { - expect(component).toBeTruthy(); - }); -}); diff --git a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.ts b/sdc-workflow-designer-ui/src/app/components/menu/menus.component.ts deleted file mode 100644 index e5f68ad1..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/menus.component.ts +++ /dev/null @@ -1,82 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ -import { Component, OnInit, ViewChild } from '@angular/core'; - -import { WorkflowService } from '../../services/workflow.service'; -import { MicroserviceComponent } from "./microservice/microservice.component"; -import { WorkflowsComponent } from "./workflows/workflows.component"; -import { BroadcastService } from "../../services/broadcast.service"; -import { PlanModel } from "../../model/workflow/plan-model"; - -@Component({ - selector: 'menus', - templateUrl: './menus.component.html', - styleUrls: ['./menus.component.css'] -}) -export class MenusComponent { - @ViewChild(MicroserviceComponent) public microserviceComponent: MicroserviceComponent; - @ViewChild(WorkflowsComponent) public workflowsComponent: WorkflowsComponent; - public currentWorkflowId : number; - public workflows = []; - - constructor(private broadcastService: BroadcastService, private workflowService: WorkflowService) { - this.broadcastService.workflows.subscribe(wfs => { - this.workflows.splice(0, this.workflows.length); - if(wfs) { - wfs.forEach((value, key, map) => { - this.workflows.push({label: value.planName, command: () => { - this.workflowSelected(key, value.plan); - }}); - }); - } - }); - } - - public save(): void { - this.workflowService.save(); - } - - public showMicroserviceModal(): void { - this.microserviceComponent.show(); - } - - public test() { - } - - public showWorkflows() { - this.workflowsComponent.show(); - } - - public workflowSelected(planId: number, planModel: PlanModel) { - - this.broadcastService.broadcast(this.broadcastService.planModel, planModel); - this.broadcastService.broadcast(this.broadcastService.planId, planId); - } - - public getCurrentPlanName() { - let planName = this.workflowService.getPlanName(this.currentWorkflowId); - return planName ? planName : 'Workflows' - } - - public download() { - const filename = this.getCurrentPlanName() + '.json'; - const content = JSON.stringify(this.workflowService.planModel); - var eleLink = document.createElement('a'); - eleLink.download = filename; - eleLink.style.display = 'none'; - var blob = new Blob([content]); - eleLink.href = URL.createObjectURL(blob); - document.body.appendChild(eleLink); - eleLink.click(); - document.body.removeChild(eleLink); - } -} diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.html b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.html deleted file mode 100644 index d13895dd..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.html +++ /dev/null @@ -1,49 +0,0 @@ - -
- -
- -
-
-
- -
- -
-
-
- -
- - -
-
-
- -
- -
-
- -
-
- -
- -
- -
-
diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.ts b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.ts deleted file mode 100644 index bffaef42..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-detail/microservice-detail.component.ts +++ /dev/null @@ -1,100 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - -import { Component, Input, OnChanges, ViewChild } from '@angular/core'; -import { ModalDirective } from 'ngx-bootstrap/modal'; - -import { Microservice } from '../../../../model/workflow/microservice'; -import { WorkflowConfigService } from '../../../../services/workflow-config.service'; -import { Swagger } from "../../../../model/swagger"; -import { RestConfig } from '../../../../model/rest-config'; - -/** - * toolbar component contains some basic operations(save) and all of the supported workflow nodes. - * The supported nodes can be dragged to container component. which will add a new node to the workflow. - */ -@Component({ - selector: 'b4t-microservice-detail', - templateUrl: 'microservice-detail.component.html', -}) -export class MicroserviceDetailComponent implements OnChanges { - @Input() microservice: RestConfig; - - public detail: string; - public dynamic = false; - - constructor(private configService: WorkflowConfigService) { - } - - public ngOnChanges() { - if(this.microservice == null) { - this.microservice = new RestConfig('', '', null, ''); - } - this.checkDynamic(); - this.parseSwagger2String(); - } - - private checkDynamic() { - if(this.microservice.url) { - this.dynamic = true; - } else { - this.dynamic = false; - } - } - - private parseSwagger2String() { - if (this.microservice.swagger) { - this.detail = JSON.stringify(this.microservice.swagger); - } else { - this.detail = ''; - } - } - - public onDetailChanged(detail: string) { - try { - if(detail) { - const swagger = new Swagger(JSON.parse(detail)); - this.detail = detail; - console.log(swagger); - this.microservice.swagger = swagger; - } else { - this.detail = ''; - this.microservice.swagger = null; - } - } catch (e) { - // if detail is not a json object, then not change the swagger - } - } - - public toggleDynamic(dynamic: boolean) { - this.dynamic = dynamic; - this.onDetailChanged(null); - - if(!dynamic) { - this.microservice.url = null; - } - } - - private loadDynamicInfo() { - this.configService.loadDynamicInfo(this.microservice.url) - .subscribe(response => { - try { - - this.microservice.swagger = response; - this.parseSwagger2String(); - } catch (e) { - console.log('detail transfer error'); - console.error(e); - } - }); - } -} diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.css b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.css deleted file mode 100644 index f403890e..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.css +++ /dev/null @@ -1,15 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - - .swagger-list{ - overflow: auto; - } \ No newline at end of file diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.html b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.html deleted file mode 100644 index ce4730f7..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.html +++ /dev/null @@ -1,32 +0,0 @@ - -
-
-
- Config List - -
- -
    -
  • -
    {{microservice.name}}
    -
    - -
    -
  • -
-
-
- diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.ts b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.ts deleted file mode 100644 index b44d423f..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice-list/microservice-list.component.ts +++ /dev/null @@ -1,81 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - -import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; -import { ModalDirective } from 'ngx-bootstrap/modal'; - -import { Microservice } from '../../../../model/workflow/microservice'; -import { RestConfig } from '../../../../model/rest-config'; - -/** - * toolbar component contains some basic operations(save) and all of the supported workflow nodes. - * The supported nodes can be dragged to container component. which will add a new node to the workflow. - */ -@Component({ - selector: 'b4t-microservice-list', - templateUrl: 'microservice-list.component.html', -}) -export class MicroserviceListComponent { - @Input() microservices: RestConfig[]; - @Output() microserviceSelected = new EventEmitter(); - - public onMicroserviceSelected(microservice: RestConfig) { - this.microserviceSelected.emit(microservice); - } - - public addMicroservice() { - const microservice = new RestConfig(this.getConfigId(), 'new microservice', '', null); - this.microservices.push(microservice); - - this.onMicroserviceSelected(microservice); - } - - public deleteMicroservice(index: number, microservice: Microservice) { - this.deleteMicroService(microservice.name, microservice.version); - - // set the next microservice selected - let selectedMicroservice; - if (this.microservices.length > 0) { - if (this.microservices[index]) { - selectedMicroservice = this.microservices[index]; - } else { - selectedMicroservice = this.microservices[index - 1]; - } - } - this.onMicroserviceSelected(selectedMicroservice); - } - - private deleteMicroService(name: string, version: string) { - const index = this.microservices.findIndex(service => (service.name === name && service.version === version)); - if(index !== -1) { - return this.microservices.splice(index, 1)[0]; - } - - return undefined; - } - - private getConfigId(): string { - const idSet = new Set(); - this.microservices.forEach(config => { - idSet.add(config.id); - }); - - for(let index = 0; index < idSet.size; index++) { - const id = `config${index}`; - if(!idSet.has(id)) { - return id; - } - } - - return `config0`; - } -} diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.html b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.html deleted file mode 100644 index e8483c22..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.html +++ /dev/null @@ -1,39 +0,0 @@ - - diff --git a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.ts b/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.ts deleted file mode 100644 index eeedac47..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/microservice/microservice.component.ts +++ /dev/null @@ -1,48 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - -import { AfterViewInit, Component, ViewChild } from '@angular/core'; -import { ModalDirective } from 'ngx-bootstrap/modal'; - -import { MicroserviceListComponent } from './microservice-list/microservice-list.component'; -import { Microservice } from "../../../model/workflow/microservice"; -import { WorkflowConfigService } from "../../../services/workflow-config.service"; -import { RestService } from '../../../services/rest.service'; -import { RestConfig } from '../../../model/rest-config'; - -/** - * microservice component - * open a model to set microservice info - */ -@Component({ - selector: 'b4t-microservice', - templateUrl: 'microservice.component.html', -}) -export class MicroserviceComponent { - @ViewChild('microserviceModal') public microserviceModal: ModalDirective; - - public microservices: RestConfig[]; - public currentMicroservice: Microservice; - - constructor(private restService: RestService) { - } - - public microserviceSelected(microservice: any) { - this.currentMicroservice = microservice; - } - - public show() { - this.microservices = this.restService.getRestConfigs(); - this.microserviceModal.show(); - } - -} diff --git a/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html b/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html deleted file mode 100644 index 0f6c7ff2..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.html +++ /dev/null @@ -1,41 +0,0 @@ - - diff --git a/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.ts b/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.ts deleted file mode 100644 index bf884983..00000000 --- a/sdc-workflow-designer-ui/src/app/components/menu/workflows/workflows.component.ts +++ /dev/null @@ -1,55 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - -import { AfterViewInit, Component, ViewChild } from '@angular/core'; -import { ModalDirective } from 'ngx-bootstrap/modal'; - -import { WorkflowService } from "../../../services/workflow.service"; -import { PlanModel } from "../../../model/workflow/plan-model"; - -/** - * workflows component - * open a model to set workflow info - */ -@Component({ - selector: 'b4t-workflows', - templateUrl: 'workflows.component.html', -}) -export class WorkflowsComponent { - @ViewChild('workflowsModal') public workflowsModal: ModalDirective; - - public workflows :Map; - - constructor(private workflowService: WorkflowService) { - } - - public show() { - this.workflows = this.workflowService.getWorkflows(); - // this.workflowService.getWorkflows().forEach((value, key, map) => { - // this.workflows.push({ - // "planName": value.planName, - // "planId": key - // }); - // });; - - this.workflowsModal.show(); - } - - public deleteWorkflow(planId: number) { - this.workflowService.deleteWorkflow(planId); - } - - public addWorkflow() { - this.workflowService.addWorkflow(); - } - -} diff --git a/sdc-workflow-designer-ui/src/app/components/menus/menus.component.css b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.css new file mode 100644 index 00000000..6ba4133b --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.css @@ -0,0 +1,23 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + +.btn-right{ + float: right; +} + +.btn-left{ + float: left; +} + +button i{ + padding-right: 3px; +} diff --git a/sdc-workflow-designer-ui/src/app/components/menus/menus.component.html b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.html new file mode 100644 index 00000000..7e043829 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.html @@ -0,0 +1,31 @@ + + +
+ +
+
+ + + + +
+ + diff --git a/sdc-workflow-designer-ui/src/app/components/menus/menus.component.spec.ts b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.spec.ts new file mode 100644 index 00000000..b80edce7 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.spec.ts @@ -0,0 +1,36 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ +import { async, ComponentFixture, TestBed } from '@angular/core/testing'; + +import { MenuComponent } from './menu.component'; + +describe('MenuComponent', () => { + let component: MenuComponent; + let fixture: ComponentFixture; + + beforeEach(async(() => { + TestBed.configureTestingModule({ + declarations: [MenuComponent] + }) + .compileComponents(); + })); + + beforeEach(() => { + fixture = TestBed.createComponent(MenuComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should be created', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/sdc-workflow-designer-ui/src/app/components/menus/menus.component.ts b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.ts new file mode 100644 index 00000000..e5f68ad1 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/menus.component.ts @@ -0,0 +1,82 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ +import { Component, OnInit, ViewChild } from '@angular/core'; + +import { WorkflowService } from '../../services/workflow.service'; +import { MicroserviceComponent } from "./microservice/microservice.component"; +import { WorkflowsComponent } from "./workflows/workflows.component"; +import { BroadcastService } from "../../services/broadcast.service"; +import { PlanModel } from "../../model/workflow/plan-model"; + +@Component({ + selector: 'menus', + templateUrl: './menus.component.html', + styleUrls: ['./menus.component.css'] +}) +export class MenusComponent { + @ViewChild(MicroserviceComponent) public microserviceComponent: MicroserviceComponent; + @ViewChild(WorkflowsComponent) public workflowsComponent: WorkflowsComponent; + public currentWorkflowId : number; + public workflows = []; + + constructor(private broadcastService: BroadcastService, private workflowService: WorkflowService) { + this.broadcastService.workflows.subscribe(wfs => { + this.workflows.splice(0, this.workflows.length); + if(wfs) { + wfs.forEach((value, key, map) => { + this.workflows.push({label: value.planName, command: () => { + this.workflowSelected(key, value.plan); + }}); + }); + } + }); + } + + public save(): void { + this.workflowService.save(); + } + + public showMicroserviceModal(): void { + this.microserviceComponent.show(); + } + + public test() { + } + + public showWorkflows() { + this.workflowsComponent.show(); + } + + public workflowSelected(planId: number, planModel: PlanModel) { + + this.broadcastService.broadcast(this.broadcastService.planModel, planModel); + this.broadcastService.broadcast(this.broadcastService.planId, planId); + } + + public getCurrentPlanName() { + let planName = this.workflowService.getPlanName(this.currentWorkflowId); + return planName ? planName : 'Workflows' + } + + public download() { + const filename = this.getCurrentPlanName() + '.json'; + const content = JSON.stringify(this.workflowService.planModel); + var eleLink = document.createElement('a'); + eleLink.download = filename; + eleLink.style.display = 'none'; + var blob = new Blob([content]); + eleLink.href = URL.createObjectURL(blob); + document.body.appendChild(eleLink); + eleLink.click(); + document.body.removeChild(eleLink); + } +} diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.html b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.html new file mode 100644 index 00000000..d13895dd --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.html @@ -0,0 +1,49 @@ + +
+ +
+ +
+
+
+ +
+ +
+
+
+ +
+ + +
+
+
+ +
+ +
+
+ +
+
+ +
+ +
+ +
+
diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.ts b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.ts new file mode 100644 index 00000000..bffaef42 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-detail/microservice-detail.component.ts @@ -0,0 +1,100 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + +import { Component, Input, OnChanges, ViewChild } from '@angular/core'; +import { ModalDirective } from 'ngx-bootstrap/modal'; + +import { Microservice } from '../../../../model/workflow/microservice'; +import { WorkflowConfigService } from '../../../../services/workflow-config.service'; +import { Swagger } from "../../../../model/swagger"; +import { RestConfig } from '../../../../model/rest-config'; + +/** + * toolbar component contains some basic operations(save) and all of the supported workflow nodes. + * The supported nodes can be dragged to container component. which will add a new node to the workflow. + */ +@Component({ + selector: 'b4t-microservice-detail', + templateUrl: 'microservice-detail.component.html', +}) +export class MicroserviceDetailComponent implements OnChanges { + @Input() microservice: RestConfig; + + public detail: string; + public dynamic = false; + + constructor(private configService: WorkflowConfigService) { + } + + public ngOnChanges() { + if(this.microservice == null) { + this.microservice = new RestConfig('', '', null, ''); + } + this.checkDynamic(); + this.parseSwagger2String(); + } + + private checkDynamic() { + if(this.microservice.url) { + this.dynamic = true; + } else { + this.dynamic = false; + } + } + + private parseSwagger2String() { + if (this.microservice.swagger) { + this.detail = JSON.stringify(this.microservice.swagger); + } else { + this.detail = ''; + } + } + + public onDetailChanged(detail: string) { + try { + if(detail) { + const swagger = new Swagger(JSON.parse(detail)); + this.detail = detail; + console.log(swagger); + this.microservice.swagger = swagger; + } else { + this.detail = ''; + this.microservice.swagger = null; + } + } catch (e) { + // if detail is not a json object, then not change the swagger + } + } + + public toggleDynamic(dynamic: boolean) { + this.dynamic = dynamic; + this.onDetailChanged(null); + + if(!dynamic) { + this.microservice.url = null; + } + } + + private loadDynamicInfo() { + this.configService.loadDynamicInfo(this.microservice.url) + .subscribe(response => { + try { + + this.microservice.swagger = response; + this.parseSwagger2String(); + } catch (e) { + console.log('detail transfer error'); + console.error(e); + } + }); + } +} diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.css b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.css new file mode 100644 index 00000000..f403890e --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.css @@ -0,0 +1,15 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + + .swagger-list{ + overflow: auto; + } \ No newline at end of file diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.html b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.html new file mode 100644 index 00000000..ce4730f7 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.html @@ -0,0 +1,32 @@ + +
+
+
+ Config List + +
+ +
    +
  • +
    {{microservice.name}}
    +
    + +
    +
  • +
+
+
+ diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.ts b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.ts new file mode 100644 index 00000000..b44d423f --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice-list/microservice-list.component.ts @@ -0,0 +1,81 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + +import { Component, EventEmitter, Input, Output, ViewChild } from '@angular/core'; +import { ModalDirective } from 'ngx-bootstrap/modal'; + +import { Microservice } from '../../../../model/workflow/microservice'; +import { RestConfig } from '../../../../model/rest-config'; + +/** + * toolbar component contains some basic operations(save) and all of the supported workflow nodes. + * The supported nodes can be dragged to container component. which will add a new node to the workflow. + */ +@Component({ + selector: 'b4t-microservice-list', + templateUrl: 'microservice-list.component.html', +}) +export class MicroserviceListComponent { + @Input() microservices: RestConfig[]; + @Output() microserviceSelected = new EventEmitter(); + + public onMicroserviceSelected(microservice: RestConfig) { + this.microserviceSelected.emit(microservice); + } + + public addMicroservice() { + const microservice = new RestConfig(this.getConfigId(), 'new microservice', '', null); + this.microservices.push(microservice); + + this.onMicroserviceSelected(microservice); + } + + public deleteMicroservice(index: number, microservice: Microservice) { + this.deleteMicroService(microservice.name, microservice.version); + + // set the next microservice selected + let selectedMicroservice; + if (this.microservices.length > 0) { + if (this.microservices[index]) { + selectedMicroservice = this.microservices[index]; + } else { + selectedMicroservice = this.microservices[index - 1]; + } + } + this.onMicroserviceSelected(selectedMicroservice); + } + + private deleteMicroService(name: string, version: string) { + const index = this.microservices.findIndex(service => (service.name === name && service.version === version)); + if(index !== -1) { + return this.microservices.splice(index, 1)[0]; + } + + return undefined; + } + + private getConfigId(): string { + const idSet = new Set(); + this.microservices.forEach(config => { + idSet.add(config.id); + }); + + for(let index = 0; index < idSet.size; index++) { + const id = `config${index}`; + if(!idSet.has(id)) { + return id; + } + } + + return `config0`; + } +} diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.html b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.html new file mode 100644 index 00000000..e8483c22 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.html @@ -0,0 +1,39 @@ + + diff --git a/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.ts b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.ts new file mode 100644 index 00000000..eeedac47 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/microservice/microservice.component.ts @@ -0,0 +1,48 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + +import { AfterViewInit, Component, ViewChild } from '@angular/core'; +import { ModalDirective } from 'ngx-bootstrap/modal'; + +import { MicroserviceListComponent } from './microservice-list/microservice-list.component'; +import { Microservice } from "../../../model/workflow/microservice"; +import { WorkflowConfigService } from "../../../services/workflow-config.service"; +import { RestService } from '../../../services/rest.service'; +import { RestConfig } from '../../../model/rest-config'; + +/** + * microservice component + * open a model to set microservice info + */ +@Component({ + selector: 'b4t-microservice', + templateUrl: 'microservice.component.html', +}) +export class MicroserviceComponent { + @ViewChild('microserviceModal') public microserviceModal: ModalDirective; + + public microservices: RestConfig[]; + public currentMicroservice: Microservice; + + constructor(private restService: RestService) { + } + + public microserviceSelected(microservice: any) { + this.currentMicroservice = microservice; + } + + public show() { + this.microservices = this.restService.getRestConfigs(); + this.microserviceModal.show(); + } + +} diff --git a/sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.html b/sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.html new file mode 100644 index 00000000..0f6c7ff2 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.html @@ -0,0 +1,41 @@ + + diff --git a/sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.ts b/sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.ts new file mode 100644 index 00000000..bf884983 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/components/menus/workflows/workflows.component.ts @@ -0,0 +1,55 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + +import { AfterViewInit, Component, ViewChild } from '@angular/core'; +import { ModalDirective } from 'ngx-bootstrap/modal'; + +import { WorkflowService } from "../../../services/workflow.service"; +import { PlanModel } from "../../../model/workflow/plan-model"; + +/** + * workflows component + * open a model to set workflow info + */ +@Component({ + selector: 'b4t-workflows', + templateUrl: 'workflows.component.html', +}) +export class WorkflowsComponent { + @ViewChild('workflowsModal') public workflowsModal: ModalDirective; + + public workflows :Map; + + constructor(private workflowService: WorkflowService) { + } + + public show() { + this.workflows = this.workflowService.getWorkflows(); + // this.workflowService.getWorkflows().forEach((value, key, map) => { + // this.workflows.push({ + // "planName": value.planName, + // "planId": key + // }); + // });; + + this.workflowsModal.show(); + } + + public deleteWorkflow(planId: number) { + this.workflowService.deleteWorkflow(planId); + } + + public addWorkflow() { + this.workflowService.addWorkflow(); + } + +} diff --git a/sdc-workflow-designer-ui/src/app/directive/resizable/resizable.directive.ts b/sdc-workflow-designer-ui/src/app/directive/resizable/resizable.directive.ts new file mode 100644 index 00000000..b285b595 --- /dev/null +++ b/sdc-workflow-designer-ui/src/app/directive/resizable/resizable.directive.ts @@ -0,0 +1,42 @@ +/** + * Copyright (c) 2017 ZTE Corporation. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * and the Apache License 2.0 which both accompany this distribution, + * and are available at http://www.eclipse.org/legal/epl-v10.html + * and http://www.apache.org/licenses/LICENSE-2.0 + * + * Contributors: + * ZTE - initial API and implementation and/or initial documentation + */ + +import { AfterViewInit, Directive, ElementRef } from '@angular/core'; +import * as $ from 'jquery'; + +import { JsPlumbService } from '../../services/jsplumb.service'; +import { ModelService } from '../../services/model.service'; + +@Directive({ selector: '[b4tResizable]' }) +export class ResizableDirective implements AfterViewInit { + + constructor(private el: ElementRef, + private jsPlumbService: JsPlumbService, + private planModelService: ModelService) { + } + + public ngAfterViewInit() { + console.log('init resizble.'); + + $(this.el.nativeElement).resizable({ + handles: 'all', + resize: (event, ui) => { + const element = ui.helper[0]; + this.planModelService.updatePosition(element.id, + element.offsetLeft, element.offsetTop, element.offsetWidth, element.offsetHeight - 12); + this.jsPlumbService.resizeParent(element, element.parentNode); + const node = this.planModelService.getNodeMap().get(element.id); + this.jsPlumbService.jsplumbInstanceMap.get(node.parentId).revalidate(element.id); + }, + }); + } +} diff --git a/sdc-workflow-designer-ui/src/app/directive/resizeable/resizable.directive.ts b/sdc-workflow-designer-ui/src/app/directive/resizeable/resizable.directive.ts deleted file mode 100644 index f591fe6f..00000000 --- a/sdc-workflow-designer-ui/src/app/directive/resizeable/resizable.directive.ts +++ /dev/null @@ -1,42 +0,0 @@ -/** - * Copyright (c) 2017 ZTE Corporation. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * and the Apache License 2.0 which both accompany this distribution, - * and are available at http://www.eclipse.org/legal/epl-v10.html - * and http://www.apache.org/licenses/LICENSE-2.0 - * - * Contributors: - * ZTE - initial API and implementation and/or initial documentation - */ - -import { AfterViewInit, Directive, ElementRef } from '@angular/core'; -import * as $ from 'jquery'; - -import { JsPlumbService } from '../../services/jsplumb.service'; -import { ModelService } from '../../services/model.service'; - -@Directive({ selector: '[b4tResizable]' }) -export class ResizableDirective implements AfterViewInit { - - constructor(private el: ElementRef, - private jsPlumbService: JsPlumbService, - private planModelService: ModelService) { - } - - public ngAfterViewInit() { - console.log('init resizble.'); - - $(this.el.nativeElement).resizable({ - handles: 'all', - resize: (event, ui) => { - const element = ui.helper[0]; - this.planModelService.updatePosition(element.id, - element.offsetLeft, element.offsetTop, element.offsetWidth, element.offsetHeight - 12); - this.jsPlumbService.resizeParent(element, element.parentNode); - const node = this.planModelService.getNodeMap().get(element.id); - this.jsPlumbService.jsplumbInstanceMap.get(node.parentId).revalidate(element.id); - }, - }); - } -} diff --git a/sdc-workflow-designer-ui/src/app/util/http.service.ts b/sdc-workflow-designer-ui/src/app/util/http.service.ts index 32669555..f754d38e 100644 --- a/sdc-workflow-designer-ui/src/app/util/http.service.ts +++ b/sdc-workflow-designer-ui/src/app/util/http.service.ts @@ -16,13 +16,13 @@ import './rxjs-operators'; @Injectable() export class HttpService { - constructor(private http: Http) {} + constructor(private http: Http) { } - public get(uri: string): Observable { - return this.getHttp('get', uri); + public get(uri: string, options?: RequestOptionsArgs): Observable { + return this.getHttp('get', uri, options); } - public post(uri: string, data: any): Observable { + public post(uri: string, data: any, options?: RequestOptionsArgs): Observable { return this.getHttp('post', uri, data); } @@ -37,22 +37,31 @@ export class HttpService { public getHttp(type: string, uri: string, data?: any, options?: RequestOptionsArgs): Observable { if (data) { return this.http[type](uri, data, options) - .map(response => - response.json() - ) + .map(response => { + if (response.text() === '') { + return {}; + } + + return response.json(); + }) .catch(this.handleError); } else { return this.http[type](uri, options) - .map(response => - response.json() - ) + .map(response => response.json()) .catch(this.handleError); } } private handleError(error: any) { - const errMsg = (error.message) ? error.message : - error.status ? `${error.status}-${error.statusText}` : 'Server error'; + let errMsg = ''; + try { + errMsg = error.json().message; + if (!errMsg) { + errMsg = error.json().msg; + } + } catch (e) { + errMsg = error.status ? `${error.status}-${error.statusText}` : 'Server error'; + } return Observable.throw(errMsg); } } diff --git a/sdc-workflow-designer-ui/src/app/util/rxjs-operators.ts b/sdc-workflow-designer-ui/src/app/util/rxjs-operators.ts index 00fa50b8..1a8f11c0 100644 --- a/sdc-workflow-designer-ui/src/app/util/rxjs-operators.ts +++ b/sdc-workflow-designer-ui/src/app/util/rxjs-operators.ts @@ -9,6 +9,7 @@ * Contributors: * ZTE - initial API and implementation and/or initial documentation */ +import 'rxjs/add/observable/forkJoin'; import 'rxjs/add/observable/throw'; import 'rxjs/add/operator/catch'; import 'rxjs/add/operator/debounceTime'; -- cgit 1.2.3-korg