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";
35 import IHttpPromiseCallbackArg = angular.IHttpPromiseCallbackArg;
37 export class LeftPaletteLoaderService {
45 'EventListenerService'
49 constructor(protected restangular:restangular.IElement,
50 protected $http:ng.IHttpService,
51 protected sdcConfig:IAppConfigurtaion,
52 protected $q:ng.IQService,
53 protected ComponentFactory:ComponentFactory,
54 protected EventListenerService:EventListenerService) {
56 this.restangular.setBaseUrl(sdcConfig.api.root + sdcConfig.api.component_api_root);
60 leftPanelComponents:Array<LeftPaletteComponent>;
62 public loadLeftPanel = (component:Component):void => {
63 this.leftPanelComponents = [];
64 this.updateLeftPaletteForTopologyTemplate(component);
67 private updateLeftPalette = (componentInternalType:string):void => {
70 const leftPaletteUrl = this.sdcConfig.api.uicache_root + this.sdcConfig.api.GET_uicache_left_palette;
71 this.$http.get(leftPaletteUrl, {params: {'internalComponentType': componentInternalType}}).then((res) => res.data).then((leftPaletteComponentMetadata:Array<ComponentMetadata>) => {
72 // this.restangular.one("resources").one('/latestversion/notabstract/metadata').get({'internalComponentType': componentInternalType}).then((leftPaletteComponentMetadata:Array<ComponentMetadata>) => {
73 _.forEach(leftPaletteComponentMetadata, (componentMetadata:ComponentMetadata) => {
74 this.leftPanelComponents.push(new LeftPaletteComponent(LeftPaletteMetadataTypes.Component, componentMetadata));
78 this.restangular.one('/groupTypes').get({'internalComponentType': componentInternalType}).then((leftPaletteGroupTypes:GroupTpes) => {
79 _.forEach(leftPaletteGroupTypes, (groupMetadata: GroupMetadata) => {
80 this.leftPanelComponents.push(new LeftPaletteComponent(LeftPaletteMetadataTypes.Group, groupMetadata));
82 this.EventListenerService.notifyObservers(EVENTS.LEFT_PALETTE_UPDATE_EVENT);
86 this.restangular.one('/policyTypes').get({'internalComponentType': componentInternalType}).then((leftPalettePolicyTypes:PolicyTpes) => {
87 _.forEach(leftPalettePolicyTypes, (policyMetadata: PolicyMetadata) => {
88 this.leftPanelComponents.push(new LeftPaletteComponent(LeftPaletteMetadataTypes.Policy, policyMetadata));
90 this.EventListenerService.notifyObservers(EVENTS.LEFT_PALETTE_UPDATE_EVENT);
97 public getLeftPanelComponentsForDisplay = (component:Component):Array<LeftPaletteComponent> => {
98 return this.leftPanelComponents;
102 * Update left palete items according to current topology templates we are in.
104 public updateLeftPaletteForTopologyTemplate = (component:Component):void => {
105 switch (component.componentType) {
106 case ComponentType.SERVICE:
107 this.updateLeftPalette(ComponentType.SERVICE);
109 case ComponentType.RESOURCE:
110 this.updateLeftPalette((<Resource>component).resourceType);
113 console.log('ERROR: Component type '+ component.componentType + ' is not exists');