aboutsummaryrefslogtreecommitdiffstats
path: root/catalog-ui/src/app/ng2/pages/composition/panel/composition-panel.component.ts
blob: 3422cc142d68b9175428aa97d7cd4efb5fd1226b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
/*-
 * ============LICENSE_START=======================================================
 * SDC
 * ================================================================================
 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
 * ================================================================================
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ============LICENSE_END=========================================================
 */

import { Component, HostBinding, Input } from '@angular/core';
import { Select, Store } from '@ngxs/store';
import { Component as TopologyTemplate, ComponentInstance, FullComponentInstance, GroupInstance, PolicyInstance, Resource, Service } from 'app/models';
import { ArtifactsTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/artifacts-tab/artifacts-tab.component';
import { GroupMembersTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/group-members-tab/group-members-tab.component';
import { GroupOrPolicyPropertiesTab } from 'app/ng2/pages/composition/panel/panel-tabs/group-or-policy-properties-tab/group-or-policy-properties-tab.component';
import { InfoTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/info-tab/info-tab.component';
import { PolicyTargetsTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/policy-targets-tab/policy-targets-tab.component';
import { PropertiesTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/properties-tab/properties-tab.component';
import { ReqAndCapabilitiesTabComponent } from 'app/ng2/pages/composition/panel/panel-tabs/req-capabilities-tab/req-capabilities-tab.component';
import { ComponentType, ResourceType } from 'app/utils';
import * as _ from 'lodash';
import { Subscription } from 'rxjs';
import { Observable } from 'rxjs/Observable';
import { ArtifactGroupType, COMPONENT_FIELDS } from '../../../../utils/constants';
import { WorkspaceState } from '../../../store/states/workspace.state';
import { OnSidebarOpenOrCloseAction } from '../common/store/graph.actions';
import { CompositionStateModel, GraphState } from '../common/store/graph.state';
import { ServiceConsumptionTabComponent } from './panel-tabs/service-consumption-tab/service-consumption-tab.component';
import { ServiceDependenciesTabComponent } from './panel-tabs/service-dependencies-tab/service-dependencies-tab.component';
import {SubstitutionFilterTabComponent} from "./panel-tabs/substitution-filter-tab/substitution-filter-tab.component";
import {InterfaceOperationsComponent} from "../interface-operatons/interface-operations.component";

const tabs = {
    infoTab: {
        titleIcon: 'info-circle',
        component: InfoTabComponent,
        input: {},
        isActive: true,
        tooltipText: 'Information',
        testId: 'detail-tab-information'
    },
    policyProperties: {
        titleIcon: 'settings-o',
        component: GroupOrPolicyPropertiesTab,
        input: {type: 'policy'},
        isActive: false,
        tooltipText: 'Properties',
        testId: 'detail-tab-policy-properties'
    },
    policyTargets: {
        titleIcon: 'inputs-o',
        component: PolicyTargetsTabComponent,
        input: {},
        isActive: false,
        tooltipText: 'Targets',
        testId: 'detail-tab-policy-targets'
    },
    groupMembers: {
        titleIcon: 'inputs-o',
        component: GroupMembersTabComponent,
        input: {},
        isActive: false,
        tooltipText: 'Members',
        testId: 'detail-tab-group-members'
    },
    groupProperties: {
        titleIcon: 'settings-o',
        component: GroupOrPolicyPropertiesTab,
        input: {type: 'group'},
        isActive: false,
        tooltipText: 'Properties',
        testId: 'detail-tab-group-properties'
    },
    deploymentArtifacts: {
        titleIcon: 'deployment-artifacts-o',
        component: ArtifactsTabComponent,
        input: {type: ArtifactGroupType.DEPLOYMENT},
        isActive: false,
        tooltipText: 'Deployment Artifacts',
        testId: 'detail-tab-deployment-artifacts'
    },
    apiArtifacts: {
        titleIcon: 'api-o',
        component: ArtifactsTabComponent,
        input: {type: ArtifactGroupType.SERVICE_API},
        isActive: false,
        tooltipText: 'API Artifacts',
        testId: 'detail-tab-api-artifacts'
    },
    infoArtifacts: {
        titleIcon: 'info-square-o',
        component: ArtifactsTabComponent,
        input: {type: ArtifactGroupType.INFORMATION},
        isActive: false,
        tooltipText: 'Information Artifacts',
        testId: 'detail-tab-information-artifacts'
    },
    properties: {
        titleIcon: 'settings-o',
        component: PropertiesTabComponent,
        input: {title: 'Properties and Attributes'},
        isActive: false,
        tooltipText: 'Properties',
        testId: 'detail-tab-properties-attributes'
    },
    reqAndCapabilities: {
        titleIcon: 'req-capabilities-o',
        component: ReqAndCapabilitiesTabComponent,
        input: {},
        isActive: false,
        tooltipText: 'Requirements and Capabilities',
        testId: 'detail-tab-requirements-capabilities'
    },
    inputs: {
        titleIcon: 'inputs-o',
        component: PropertiesTabComponent,
        input: {title: 'Inputs'},
        isActive: false,
        tooltipText: 'Inputs',
        testId: 'detail-tab-inputs'
    },
    settings: {
        titleIcon: 'settings-o',
        component: PropertiesTabComponent,
        input: {},
        isActive: false,
        tooltipText: 'Settings',
        testId: 'detail-tab-settings'
    },
    consumption: {
        titleIcon: 'api-o',
        component: ServiceConsumptionTabComponent,
        input: {title: 'OPERATION CONSUMPTION'},
        isActive: false,
        tooltipText: 'Service Consumption',
        testId: 'detail-tab-operation-consumption'
    },
    dependencies: {
        titleIcon: 'archive',
        component: ServiceDependenciesTabComponent,
        input: {title: 'DIRECTIVES AND NODE FILTER'},
        isActive: false,
        tooltipText: 'Service Dependencies',
        testId: 'detail-tab-directives-node-filter'
    },
    substitutionFilter: {
        titleIcon: 'composition-o',
        component: SubstitutionFilterTabComponent,
        input: {title: 'SUBSTITUTION FILTER'},
        isActive: false,
        tooltipText: 'Substitution Filter',
        testId: 'detail-tab-substitution-filter'
    },
    interfaceOperations: {
        titleIcon: 'composition-o',
        component: InterfaceOperationsComponent,
        input: {title: 'Interface Operations'},
        isActive: false,
        tooltipText: 'Interface Operations',
        testId: 'detail-tab-interface-operations'
    }
};

@Component({
    selector: 'ng2-composition-panel',
    templateUrl: './composition-panel.component.html',
    styleUrls: ['./composition-panel.component.less', './panel-tabs/panel-tabs.less'],
})
export class CompositionPanelComponent {

    @Input() topologyTemplate: TopologyTemplate;
    @HostBinding('class') classes = 'component-details-panel';
    @Select(GraphState) compositionState$: Observable<CompositionStateModel>;
    @Select(GraphState.withSidebar) withSidebar$: boolean;
    @Select(WorkspaceState.isViewOnly) isViewOnly$: boolean;
    tabs: any[];
    subscription: Subscription;

    private selectedComponent;

    constructor(public store: Store) {
    }

    ngOnInit() {
        this.subscription = this.store.select(GraphState.getSelectedComponent).subscribe((component) => {
            this.selectedComponent = component;
            this.initTabs(component);
            this.activatePreviousActiveTab();
        });
    }


    onRightClick(selectedComponent: any) {
        console.info("onRightClick", selectedComponent)
        return false;
    }

    ngOnDestroy() {
        if (this.subscription) {
            this.subscription.unsubscribe();
        }
    }

    public setActive = (tabToSelect) => {
        this.tabs.map((tab) => tab.isActive = (tab.titleIcon === tabToSelect.titleIcon) ? true : false);
    }

    public activatePreviousActiveTab = () => { // sets the info tab to active if no other tab selected

        this.setActive(this.tabs.find((tab) => tab.isActive) || tabs.infoTab);

    }

    private initTabs = (component) => {
        this.tabs = [];

        // Information
        this.tabs.push(tabs.infoTab);

        if (component instanceof PolicyInstance) {
            this.tabs.push(tabs.policyTargets);
            this.tabs.push(tabs.policyProperties);
            return;
        }

        if (component instanceof GroupInstance) {
            this.tabs.push(tabs.groupMembers);
            this.tabs.push(tabs.groupProperties);
            return;
        }

        // Deployment artifacts
        if (!this.isPNF() && !this.isConfiguration() && !this.selectedComponentIsServiceProxyInstance() && !this.selectedComponentIsServiceSubstitutionInstance()) {
            this.tabs.push(tabs.deploymentArtifacts);
        }

        // Properties or Inputs
        if (component.isResource() || this.selectedComponentIsServiceProxyInstance() || this.selectedComponentIsServiceSubstitutionInstance()) {
            this.tabs.push(tabs.properties);
        } else {
            this.tabs.push(tabs.inputs);
        }

        if (!this.isConfiguration() && !this.selectedComponentIsServiceProxyInstance() && !this.selectedComponentIsServiceSubstitutionInstance()) {
            this.tabs.push(tabs.infoArtifacts);
        }

        if (!(component.isService()) || this.selectedComponentIsServiceProxyInstance() || this.selectedComponentIsServiceSubstitutionInstance()) {
            this.tabs.push(tabs.reqAndCapabilities);
        }

        if (component.isService() && !this.selectedComponentIsServiceProxyInstance() && !this.selectedComponentIsServiceSubstitutionInstance()) {
            this.tabs.push(tabs.apiArtifacts);
        }

        if (this.showSubstitutionFilterTab(component)) {
            this.tabs.push(tabs.substitutionFilter);
        }

        if (component.isService() && (this.selectedComponentIsServiceProxyInstance() || this.selectedComponentIsServiceSubstitutionInstance())) {
            this.tabs.push(tabs.consumption);
            this.tabs.push(tabs.dependencies);
            this.tabs.push(tabs.interfaceOperations);
        } else if (component.isResource() && this.isComponentInstanceSelected()) {
            this.tabs.push(tabs.dependencies);
            this.tabs.push(tabs.interfaceOperations);
        }

    }

    private showSubstitutionFilterTab(component): boolean {
        if ((component.isService() || this.isVF()) && !this.isComponentInstanceSelected()) {
            if (component.isService()) {
                return (<Service>component).isSubstituteCandidate();
            }
            return true;
        }

        return false;
    }

    private toggleSidebarDisplay = () => {
        // this.withSidebar = !this.withSidebar;
        this.store.dispatch(new OnSidebarOpenOrCloseAction());
    }

    private isPNF = (): boolean => {
        return this.topologyTemplate.isResource() && (this.topologyTemplate as Resource).resourceType === ResourceType.PNF;
    }

    private isVF = (): boolean => {
        return this.topologyTemplate.isResource() && (this.topologyTemplate as Resource).resourceType === ResourceType.VF;
    }

    private isConfiguration = (): boolean => {
        return this.topologyTemplate.isResource() && (this.topologyTemplate as Resource).resourceType === ResourceType.CONFIGURATION;
    }

    private isComponentInstanceSelected = (): boolean => {
        return this.selectedComponent instanceof FullComponentInstance;
    }

    private selectedComponentIsServiceProxyInstance = (): boolean => {
        return this.isComponentInstanceSelected() && this.selectedComponent.isServiceProxy();
    }
    
    private selectedComponentIsServiceSubstitutionInstance = (): boolean => {
        return this.isComponentInstanceSelected() && this.selectedComponent.isServiceSubstitution();
    }
}