2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
21 * Created by obarda on 3/13/2016.
24 import {LeftPaletteComponent} from "../../../models/components/displayComponent";
25 import {Component} from "../../../models/components/component";
26 import {EventListenerService} from "../../event-listener-service";
27 import {ComponentFactory} from "../../../utils/component-factory";
28 import {IAppConfigurtaion} from "../../../models/app-config";
29 import {ResourceType, ComponentType, EVENTS} from "../../../utils/constants";
30 import {ComponentMetadata} from "../../../models/component-metadata";
31 import {Resource} from "app/models/components/resource";
33 export class LeftPaletteDataObject {
34 displayLeftPanelComponents:Array<LeftPaletteComponent>;
35 onFinishLoadingEvent:string;
37 constructor(onFinishEventListener:string) {
39 this.displayLeftPanelComponents = new Array<LeftPaletteComponent>();
40 this.onFinishLoadingEvent = onFinishEventListener;
44 export class LeftPaletteLoaderService {
51 'EventListenerService'
55 constructor(protected restangular:restangular.IElement,
56 protected sdcConfig:IAppConfigurtaion,
57 protected $q:ng.IQService,
58 protected ComponentFactory:ComponentFactory,
59 protected EventListenerService:EventListenerService) {
61 this.restangular.setBaseUrl(sdcConfig.api.root + sdcConfig.api.component_api_root);
65 private serviceLeftPaletteData:LeftPaletteDataObject;
66 private resourceLeftPaletteData:LeftPaletteDataObject;
67 private resourcePNFLeftPaletteData:LeftPaletteDataObject;
68 private vlData:LeftPaletteDataObject;
70 public loadLeftPanel = (component:Component):void => {
71 this.serviceLeftPaletteData = new LeftPaletteDataObject(EVENTS.SERVICE_LEFT_PALETTE_UPDATE_EVENT);
72 this.resourceLeftPaletteData = new LeftPaletteDataObject(EVENTS.RESOURCE_LEFT_PALETTE_UPDATE_EVENT);
73 this.resourcePNFLeftPaletteData = new LeftPaletteDataObject(EVENTS.RESOURCE_PNF_LEFT_PALETTE_UPDATE_EVENT);
74 this.updateComponentLeftPalette(component);
77 private getResourceLeftPaletteDataByResourceType = (resourceType:string):LeftPaletteDataObject => {
78 if(resourceType == ResourceType.PNF) {
79 return this.resourcePNFLeftPaletteData;
81 return this.resourceLeftPaletteData;
84 private onFinishLoading = (componentType:string, leftPaletteData:LeftPaletteDataObject):void => {
85 this.EventListenerService.notifyObservers(leftPaletteData.onFinishLoadingEvent);
88 private updateLeftPalette = (componentType, componentInternalType:string, leftPaletteData:LeftPaletteDataObject):void => {
90 this.restangular.one("resources").one('/latestversion/notabstract/metadata').get({'internalComponentType': componentInternalType}).then((leftPaletteComponentMetadata:Array<ComponentMetadata>) => {
91 _.forEach(leftPaletteComponentMetadata, (componentMetadata:ComponentMetadata) => {
92 leftPaletteData.displayLeftPanelComponents.push(new LeftPaletteComponent(componentMetadata));
94 this.onFinishLoading(componentType, leftPaletteData);
98 public getLeftPanelComponentsForDisplay = (component:Component):Array<LeftPaletteComponent> => {
99 switch (component.componentType) {
100 case ComponentType.SERVICE:
101 return this.serviceLeftPaletteData.displayLeftPanelComponents;
103 return this.getResourceLeftPaletteDataByResourceType((<Resource>component).resourceType).displayLeftPanelComponents;
107 public updateComponentLeftPalette = (component:Component):void => {
108 switch (component.componentType) {
109 case ComponentType.SERVICE:
110 this.updateLeftPalette(ComponentType.SERVICE, ComponentType.SERVICE, this.serviceLeftPaletteData);
112 case ComponentType.RESOURCE:
113 this.updateLeftPalette(ComponentType.RESOURCE, (<Resource>component).resourceType, this.getResourceLeftPaletteDataByResourceType((<Resource>component).resourceType));
116 console.log('ERROR: Component type '+ component.componentType + ' is not exists');