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 * as _ from "lodash";
25 import {LeftPaletteComponent, LeftPaletteMetadataTypes} from "app/models/components/displayComponent";
26 import {Component} from "app/models/components/component";
27 import {EventListenerService} from "../../event-listener-service";
28 import {ComponentFactory} from "../../../utils/component-factory";
29 import {IAppConfigurtaion} from "app/models/app-config";
30 import {ResourceType, ComponentType, EVENTS} from "../../../utils/constants";
31 import {ComponentMetadata} from "app/models/component-metadata";
32 import {GroupMetadata, GroupTpes} from "app/models/group-metadata";
33 import {PolicyMetadata, PolicyTpes} from "app/models/policy-metadata";
34 import {Resource} from "app/models/components/resource";
36 export class LeftPaletteLoaderService {
43 'EventListenerService'
47 constructor(protected restangular:restangular.IElement,
48 protected sdcConfig:IAppConfigurtaion,
49 protected $q:ng.IQService,
50 protected ComponentFactory:ComponentFactory,
51 protected EventListenerService:EventListenerService) {
53 this.restangular.setBaseUrl(sdcConfig.api.root + sdcConfig.api.component_api_root);
57 leftPanelComponents:Array<LeftPaletteComponent>;
59 public loadLeftPanel = (component:Component):void => {
60 this.leftPanelComponents = [];
61 this.updateLeftPaletteForTopologyTemplate(component);
64 private updateLeftPalette = (componentInternalType:string):void => {
67 this.restangular.one("resources").one('/latestversion/notabstract/metadata').get({'internalComponentType': componentInternalType}).then((leftPaletteComponentMetadata:Array<ComponentMetadata>) => {
68 _.forEach(leftPaletteComponentMetadata, (componentMetadata:ComponentMetadata) => {
69 this.leftPanelComponents.push(new LeftPaletteComponent(LeftPaletteMetadataTypes.Component, componentMetadata));
73 this.restangular.one('/groupTypes').get({'internalComponentType': componentInternalType}).then((leftPaletteGroupTypes:GroupTpes) => {
74 _.forEach(leftPaletteGroupTypes, (groupMetadata: GroupMetadata) => {
75 this.leftPanelComponents.push(new LeftPaletteComponent(LeftPaletteMetadataTypes.Group, groupMetadata));
77 this.EventListenerService.notifyObservers(EVENTS.LEFT_PALETTE_UPDATE_EVENT);
81 this.restangular.one('/policyTypes').get({'internalComponentType': componentInternalType}).then((leftPalettePolicyTypes:PolicyTpes) => {
82 _.forEach(leftPalettePolicyTypes, (policyMetadata: PolicyMetadata) => {
83 this.leftPanelComponents.push(new LeftPaletteComponent(LeftPaletteMetadataTypes.Policy, policyMetadata));
85 this.EventListenerService.notifyObservers(EVENTS.LEFT_PALETTE_UPDATE_EVENT);
92 public getLeftPanelComponentsForDisplay = (component:Component):Array<LeftPaletteComponent> => {
93 return this.leftPanelComponents;
97 * Update left palete items according to current topology templates we are in.
99 public updateLeftPaletteForTopologyTemplate = (component:Component):void => {
100 switch (component.componentType) {
101 case ComponentType.SERVICE:
102 this.updateLeftPalette(ComponentType.SERVICE);
104 case ComponentType.RESOURCE:
105 this.updateLeftPalette((<Resource>component).resourceType);
108 console.log('ERROR: Component type '+ component.componentType + ' is not exists');