1 import { Component, OnInit, ViewChild } from '@angular/core';
2 import { Select, Store } from '@ngxs/store';
3 import { ArtifactModel } from 'app/models';
4 import * as _ from 'lodash';
5 import { SdcUiCommon, SdcUiComponents, SdcUiServices } from 'onap-ui-angular';
6 import { Observable } from 'rxjs/index';
7 import { map } from 'rxjs/operators';
8 import { GabConfig } from '../../../../models/gab-config';
9 import { PathsAndNamesDefinition } from '../../../../models/paths-and-names';
10 import { GenericArtifactBrowserComponent } from '../../../../ng2/components/logic/generic-artifact-browser/generic-artifact-browser.component';
11 import { ArtifactGroupType, ArtifactType } from '../../../../utils/constants';
12 import { ArtifactsService } from '../../../components/forms/artifacts-form/artifacts.service';
13 import { PopoverContentComponent } from '../../../components/ui/popover/popover-content.component';
14 import { CacheService } from '../../../services/cache.service';
15 import { TranslateService } from '../../../shared/translator/translate.service';
16 import { GetArtifactsByTypeAction } from '../../../store/actions/artifacts.action';
17 import { ArtifactsState } from '../../../store/states/artifacts.state';
18 import { WorkspaceState, WorkspaceStateModel } from '../../../store/states/workspace.state';
19 import { WorkspaceService } from '../workspace.service';
20 import { ModalService } from 'app/ng2/services/modal.service';
22 export interface IPoint {
28 selector: 'deployment-artifact-page',
29 templateUrl: './deployment-artifacts-page.component.html',
30 styleUrls: ['./deployment-artifacts-page.component.less', '../../../../../assets/styles/table-style.less']
32 export class DeploymentArtifactsPageComponent implements OnInit {
34 public componentId: string;
35 public componentType: string;
36 public deploymentArtifacts$: Observable<ArtifactModel[]>;
37 public isComponentInstanceSelected: boolean;
39 @Select(WorkspaceState) workspaceState$: Observable<WorkspaceStateModel>;
40 @ViewChild('informationArtifactsTable') table: any;
41 @ViewChild('popoverForm') popoverContentComponent: PopoverContentComponent;
43 constructor(private workspaceService: WorkspaceService,
44 private artifactsService: ArtifactsService,
46 private popoverService: SdcUiServices.PopoverService,
47 private cacheService: CacheService,
48 private modalService: SdcUiServices.ModalService,
49 private translateService: TranslateService) {
52 private getEnvArtifact = (heatArtifact: ArtifactModel, artifacts: ArtifactModel[]): ArtifactModel => {
53 return _.find(artifacts, (item: ArtifactModel) => {
54 return item.generatedFromId === heatArtifact.uniqueId;
58 // we need to sort the artifact in a way that the env artifact is always under the artifact he is connected to- this is cause of the way the ngx databale work
59 private sortArtifacts = ((artifacts) => {
60 const sortedArtifacts = [];
61 _.forEach(artifacts, (artifact: ArtifactModel): void => {
62 const envArtifact = this.getEnvArtifact(artifact, artifacts);
63 if (!artifact.generatedFromId) {
64 sortedArtifacts.push(artifact);
67 sortedArtifacts.push(envArtifact);
70 return sortedArtifacts;
74 this.componentId = this.workspaceService.metadata.uniqueId;
75 this.componentType = this.workspaceService.metadata.componentType;
77 this.store.dispatch(new GetArtifactsByTypeAction({
78 componentType: this.componentType,
79 componentId: this.componentId,
80 artifactType: ArtifactGroupType.DEPLOYMENT
82 this.deploymentArtifacts$ = this.store.select(ArtifactsState.getArtifactsByType).pipe(map((filterFn) => filterFn(ArtifactType.DEPLOYMENT))).pipe(map(artifacts => {
83 return this.sortArtifacts(artifacts);
88 if (event.type === 'click') {
89 this.table.rowDetail.toggleExpandRow(event.row);
93 public addOrUpdateArtifact = (artifact: ArtifactModel, isViewOnly: boolean) => {
94 this.artifactsService.openArtifactModal(this.componentId, this.componentType, artifact, ArtifactGroupType.DEPLOYMENT, isViewOnly);
97 public deleteArtifact = (artifactToDelete) => {
98 this.artifactsService.deleteArtifact(this.componentType, this.componentId, artifactToDelete);
101 private openPopOver = (title: string, content: string, positionOnPage: IPoint, location: string) => {
102 this.popoverService.createPopOver(title, content, positionOnPage, location);
105 public updateEnvParams = (artifact: ArtifactModel, isViewOnly: boolean) => {
106 this.artifactsService.openUpdateEnvParams(this.componentType, this.componentId, artifact );
109 private openGenericArtifactBrowserModal = (artifact: ArtifactModel): void => {
110 const titleStr = 'Generic Artifact Browser';
111 const modalConfig = {
114 type: SdcUiCommon.ModalType.custom,
116 id: 'closeGABButton',
120 }] as SdcUiCommon.IModalButtonComponent[]
123 const uiConfiguration: any = this.cacheService.get('UIConfiguration');
124 let noConfig: boolean = false;
125 let pathsandnamesArr: PathsAndNamesDefinition[] = [];
127 if (typeof uiConfiguration.gab === 'undefined') {
130 const gabConfig: GabConfig = uiConfiguration.gab
131 .find((config) => config.artifactType === artifact.artifactType);
132 if (typeof gabConfig === 'undefined') {
135 pathsandnamesArr = gabConfig.pathsAndNamesDefinitions;
141 const msg = this.translateService.translate('DEPLOYMENT_ARTIFACT_GAB_NO_CONFIG');
142 this.modalService.openAlertModal(titleStr, msg);
145 const modalInputs = {
146 pathsandnames: pathsandnamesArr,
147 artifactid: artifact.esId,
148 resourceid: this.componentId
151 this.modalService.openCustomModal(modalConfig, GenericArtifactBrowserComponent, modalInputs);