1 import {Injectable} from '@angular/core';
2 import {Response, RequestOptions, Headers} from '@angular/http';
3 import { Observable } from 'rxjs/Observable';
4 import {sdc2Config} from "../../../../main";
5 import {PropertyBEModel} from "app/models";
6 import {CommonUtils} from "app/utils";
7 import {Component, ComponentInstance, InputModel} from "app/models";
8 import {InterceptorService} from "ng2-interceptors/index";
11 export class ComponentInstanceServiceNg2 {
15 constructor(private http: InterceptorService) {
16 this.baseUrl = sdc2Config.api.root + sdc2Config.api.component_api_root;
19 getComponentInstanceProperties(component: Component, componentInstanceId: string): Observable<Array<PropertyBEModel>> {
21 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstanceId + '/properties')
22 .map((res: Response) => {
23 return CommonUtils.initBeProperties(res.json());
27 getComponentInstanceInputs(component: Component, componentInstance: ComponentInstance): Observable<Array<PropertyBEModel>> {
28 return this.http.get(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/componentInstances/' + componentInstance.uniqueId + '/' + componentInstance.componentUid + '/inputs')
29 .map((res: Response) => {
30 return CommonUtils.initInputs(res.json());
34 updateInstanceProperty(component: Component, componentInstanceId: string, property: PropertyBEModel): Observable<PropertyBEModel> {
36 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/property', property)
37 .map((res: Response) => {
38 return new PropertyBEModel(res.json());
42 updateInstanceInput(component: Component, componentInstanceId: string, input: PropertyBEModel): Observable<PropertyBEModel> {
44 return this.http.post(this.baseUrl + component.getTypeUrl() + component.uniqueId + '/resourceInstance/' + componentInstanceId + '/input', input)
45 .map((res: Response) => {
46 return new PropertyBEModel(res.json());