Catalog alignment
[sdc.git] / catalog-ui / src / app / ng2 / pages / workspace / information-artifact / information-artifact-page.component.ts
1 import {Component, OnInit, ViewChild} from "@angular/core";
2 import {WorkspaceService} from "../workspace.service";
3 import {SdcUiCommon, SdcUiComponents, SdcUiServices} from "onap-ui-angular";
4 import {TopologyTemplateService} from "../../../services/component-services/topology-template.service";
5 import * as _ from "lodash";
6 import {ArtifactGroupType, ArtifactType} from "../../../../utils/constants";
7 import {ArtifactsService} from "../../../components/forms/artifacts-form/artifacts.service";
8 import {DeleteArtifactAction, GetArtifactsByTypeAction} from "../../../store/actions/artifacts.action";
9 import {Select, Store} from "@ngxs/store";
10 import {Observable} from "rxjs/index";
11 import {ArtifactsState} from "../../../store/states/artifacts.state";
12 import {map} from "rxjs/operators";
13 import {WorkspaceState} from "../../../store/states/workspace.state";
14 import {ArtifactModel} from "../../../../models/artifacts";
15
16 @Component({
17     selector: 'information-artifact-page',
18     templateUrl: './information-artifact-page.component.html',
19     styleUrls: ['./information-artifact-page.component.less', '../../../../../assets/styles/table-style.less']
20 })
21 export class InformationArtifactPageComponent implements OnInit {
22
23     public componentId: string;
24     public componentType: string;
25     public informationArtifacts$: Observable<ArtifactModel[]>;
26     public informationArtifactsAsButtons$: Observable<ArtifactModel[]>;
27     @Select(WorkspaceState.isViewOnly) isViewOnly$: boolean;
28     @ViewChild('informationArtifactsTable') table: any;
29
30     constructor(private workspaceService: WorkspaceService,
31                 private artifactsService: ArtifactsService,
32                 private store: Store) {
33     }
34
35     ngOnInit(): void {
36         this.componentId = this.workspaceService.metadata.uniqueId;
37         this.componentType = this.workspaceService.metadata.componentType;
38
39         this.store.dispatch(new GetArtifactsByTypeAction({
40             componentType: this.componentType,
41             componentId: this.componentId,
42             artifactType: ArtifactGroupType.INFORMATION
43         }));
44
45         let artifacts = this.store.select(ArtifactsState.getArtifactsByType).pipe(map(filterFn => filterFn(ArtifactType.INFORMATION)));
46         this.informationArtifacts$ = artifacts.pipe(map(artifacts => _.filter(artifacts, (artifact) => {
47             return artifact.esId;
48         })));
49
50         this.informationArtifactsAsButtons$ = artifacts.pipe(map(artifacts => _.filter(artifacts, (artifact) => {
51             return !artifact.esId;
52         })));
53     }
54
55     onActivate(event) {
56         if (event.type === 'click') {
57             this.table.rowDetail.toggleExpandRow(event.row);
58         }
59     }
60
61     public addOrUpdateArtifact = (artifact: ArtifactModel, isViewOnly?: boolean) => {
62         this.artifactsService.openArtifactModal(this.componentId, this.componentType, artifact, ArtifactGroupType.INFORMATION, isViewOnly);
63     }
64
65     public deleteArtifact = (artifactToDelete) => {
66       this.artifactsService.deleteArtifact(this.componentType, this.componentId, artifactToDelete)
67     }
68
69 }