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 import { Component, HostBinding, Input } from '@angular/core';
22 import { Select, Store } from '@ngxs/store';
23 import { Component as TopologyTemplate, ComponentInstance, FullComponentInstance, GroupInstance, PolicyInstance, Resource, Service } from 'app/models';
24 import { ArtifactsTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/artifacts-tab/artifacts-tab.component';
25 import { GroupMembersTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/group-members-tab/group-members-tab.component';
26 import { GroupOrPolicyPropertiesTab } from 'app/ng2/pages/composition/panel/panel-tabs/group-or-policy-properties-tab/group-or-policy-properties-tab.component';
27 import { InfoTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/info-tab/info-tab.component';
28 import { PolicyTargetsTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/policy-targets-tab/policy-targets-tab.component';
29 import { PropertiesTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/properties-tab/properties-tab.component';
30 import { ReqAndCapabilitiesTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/req-capabilities-tab/req-capabilities-tab.component';
31 import { ComponentType, ResourceType } from 'app/utils';
32 import * as _ from 'lodash';
33 import { Subscription } from 'rxjs';
34 import { Observable } from 'rxjs/Observable';
35 import { ArtifactGroupType, COMPONENT_FIELDS } from '../../../../utils/constants';
36 import { WorkspaceState } from '../../../store/states/workspace.state';
37 import { OnSidebarOpenOrCloseAction } from '../common/store/graph.actions';
38 import { CompositionStateModel, GraphState } from '../common/store/graph.state';
39 import { ServiceConsumptionTabComponent } from './panel-tabs/service-consumption-tab/service-consumption-tab.component';
40 import { ServiceDependenciesTabComponent } from './panel-tabs/service-dependencies-tab/service-dependencies-tab.component';
41 import {SubstitutionFilterTabComponent} from "./panel-tabs/substitution-filter-tab/substitution-filter-tab.component";
42 import {InterfaceOperationsComponent} from "../interface-operatons/interface-operations.component";
46 titleIcon: 'info-circle',
47 component: InfoTabComponent,
50 tooltipText: 'Information',
51 testId: 'detail-tab-information'
54 titleIcon: 'settings-o',
55 component: GroupOrPolicyPropertiesTab,
56 input: {type: 'policy'},
58 tooltipText: 'Properties',
59 testId: 'detail-tab-policy-properties'
62 titleIcon: 'inputs-o',
63 component: PolicyTargetsTabComponent,
66 tooltipText: 'Targets',
67 testId: 'detail-tab-policy-targets'
70 titleIcon: 'inputs-o',
71 component: GroupMembersTabComponent,
74 tooltipText: 'Members',
75 testId: 'detail-tab-group-members'
78 titleIcon: 'settings-o',
79 component: GroupOrPolicyPropertiesTab,
80 input: {type: 'group'},
82 tooltipText: 'Properties',
83 testId: 'detail-tab-group-properties'
85 deploymentArtifacts: {
86 titleIcon: 'deployment-artifacts-o',
87 component: ArtifactsTabComponent,
88 input: {type: ArtifactGroupType.DEPLOYMENT},
90 tooltipText: 'Deployment Artifacts',
91 testId: 'detail-tab-deployment-artifacts'
95 component: ArtifactsTabComponent,
96 input: {type: ArtifactGroupType.SERVICE_API},
98 tooltipText: 'API Artifacts',
99 testId: 'detail-tab-api-artifacts'
102 titleIcon: 'info-square-o',
103 component: ArtifactsTabComponent,
104 input: {type: ArtifactGroupType.INFORMATION},
106 tooltipText: 'Information Artifacts',
107 testId: 'detail-tab-information-artifacts'
110 titleIcon: 'settings-o',
111 component: PropertiesTabComponent,
112 input: {title: 'Properties and Attributes'},
114 tooltipText: 'Properties',
115 testId: 'detail-tab-properties-attributes'
117 reqAndCapabilities: {
118 titleIcon: 'req-capabilities-o',
119 component: ReqAndCapabilitiesTabComponent,
122 tooltipText: 'Requirements and Capabilities',
123 testId: 'detail-tab-requirements-capabilities'
126 titleIcon: 'inputs-o',
127 component: PropertiesTabComponent,
128 input: {title: 'Inputs'},
130 tooltipText: 'Inputs',
131 testId: 'detail-tab-inputs'
134 titleIcon: 'settings-o',
135 component: PropertiesTabComponent,
138 tooltipText: 'Settings',
139 testId: 'detail-tab-settings'
143 component: ServiceConsumptionTabComponent,
144 input: {title: 'OPERATION CONSUMPTION'},
146 tooltipText: 'Service Consumption',
147 testId: 'detail-tab-operation-consumption'
150 titleIcon: 'archive',
151 component: ServiceDependenciesTabComponent,
152 input: {title: 'DIRECTIVES AND NODE FILTER'},
154 tooltipText: 'Service Dependencies',
155 testId: 'detail-tab-directives-node-filter'
157 substitutionFilter: {
158 titleIcon: 'composition-o',
159 component: SubstitutionFilterTabComponent,
160 input: {title: 'SUBSTITUTION FILTER'},
162 tooltipText: 'Substitution Filter',
163 testId: 'detail-tab-substitution-filter'
165 interfaceOperations: {
166 titleIcon: 'composition-o',
167 component: InterfaceOperationsComponent,
168 input: {title: 'Interface Operations'},
170 tooltipText: 'Interface Operations',
171 testId: 'detail-tab-interface-operations'
176 selector: 'ng2-composition-panel',
177 templateUrl: './composition-panel.component.html',
178 styleUrls: ['./composition-panel.component.less', './panel-tabs/panel-tabs.less'],
180 export class CompositionPanelComponent {
182 @Input() topologyTemplate: TopologyTemplate;
183 @HostBinding('class') classes = 'component-details-panel';
184 @Select(GraphState) compositionState$: Observable<CompositionStateModel>;
185 @Select(GraphState.withSidebar) withSidebar$: boolean;
186 @Select(WorkspaceState.isViewOnly) isViewOnly$: boolean;
188 subscription: Subscription;
190 private selectedComponent;
192 constructor(public store: Store) {
196 this.subscription = this.store.select(GraphState.getSelectedComponent).subscribe((component) => {
197 this.selectedComponent = component;
198 this.initTabs(component);
199 this.activatePreviousActiveTab();
204 onRightClick(selectedComponent: any) {
205 console.info("onRightClick", selectedComponent)
210 if (this.subscription) {
211 this.subscription.unsubscribe();
215 public setActive = (tabToSelect) => {
216 this.tabs.map((tab) => tab.isActive = (tab.titleIcon === tabToSelect.titleIcon) ? true : false);
219 public activatePreviousActiveTab = () => { // sets the info tab to active if no other tab selected
221 this.setActive(this.tabs.find((tab) => tab.isActive) || tabs.infoTab);
225 private initTabs = (component) => {
229 this.tabs.push(tabs.infoTab);
231 if (component instanceof PolicyInstance) {
232 this.tabs.push(tabs.policyTargets);
233 this.tabs.push(tabs.policyProperties);
237 if (component instanceof GroupInstance) {
238 this.tabs.push(tabs.groupMembers);
239 this.tabs.push(tabs.groupProperties);
243 // Deployment artifacts
244 if (!this.isPNF() && !this.isConfiguration() && !this.selectedComponentIsServiceProxyInstance() && !this.selectedComponentIsServiceSubstitutionInstance()) {
245 this.tabs.push(tabs.deploymentArtifacts);
248 // Properties or Inputs
249 if (component.isResource() || this.selectedComponentIsServiceProxyInstance() || this.selectedComponentIsServiceSubstitutionInstance()) {
250 this.tabs.push(tabs.properties);
252 this.tabs.push(tabs.inputs);
255 if (!this.isConfiguration() && !this.selectedComponentIsServiceProxyInstance() && !this.selectedComponentIsServiceSubstitutionInstance()) {
256 this.tabs.push(tabs.infoArtifacts);
259 if (!(component.isService()) || this.selectedComponentIsServiceProxyInstance() || this.selectedComponentIsServiceSubstitutionInstance()) {
260 this.tabs.push(tabs.reqAndCapabilities);
263 if (component.isService() && !this.selectedComponentIsServiceProxyInstance() && !this.selectedComponentIsServiceSubstitutionInstance()) {
264 this.tabs.push(tabs.apiArtifacts);
267 if (this.showSubstitutionFilterTab(component)) {
268 this.tabs.push(tabs.substitutionFilter);
271 if (component.isService() && (this.selectedComponentIsServiceProxyInstance() || this.selectedComponentIsServiceSubstitutionInstance())) {
272 this.tabs.push(tabs.consumption);
273 this.tabs.push(tabs.dependencies);
274 this.tabs.push(tabs.interfaceOperations);
275 } else if (component.isResource() && this.isComponentInstanceSelected()) {
276 this.tabs.push(tabs.dependencies);
277 this.tabs.push(tabs.interfaceOperations);
282 private showSubstitutionFilterTab(component): boolean {
283 if ((component.isService() || this.isVF()) && !this.isComponentInstanceSelected()) {
284 if (component.isService()) {
285 return (<Service>component).isSubstituteCandidate();
293 private toggleSidebarDisplay = () => {
294 // this.withSidebar = !this.withSidebar;
295 this.store.dispatch(new OnSidebarOpenOrCloseAction());
298 private isPNF = (): boolean => {
299 return this.topologyTemplate.isResource() && (this.topologyTemplate as Resource).resourceType === ResourceType.PNF;
302 private isVF = (): boolean => {
303 return this.topologyTemplate.isResource() && (this.topologyTemplate as Resource).resourceType === ResourceType.VF;
306 private isConfiguration = (): boolean => {
307 return this.topologyTemplate.isResource() && (this.topologyTemplate as Resource).resourceType === ResourceType.CONFIGURATION;
310 private isComponentInstanceSelected = (): boolean => {
311 return this.selectedComponent instanceof FullComponentInstance;
314 private selectedComponentIsServiceProxyInstance = (): boolean => {
315 return this.isComponentInstanceSelected() && this.selectedComponent.isServiceProxy();
318 private selectedComponentIsServiceSubstitutionInstance = (): boolean => {
319 return this.isComponentInstanceSelected() && this.selectedComponent.isServiceSubstitution();