1 import { Component, Inject, OnInit, ViewChild } from "@angular/core";
2 import { WorkspaceService } from "../workspace.service";
3 import { ArtifactModel } from "../../../../models";
4 import { Select, Store } from "@ngxs/store";
5 import { WorkspaceState } from "../../../store/states/workspace.state";
6 import { ArtifactGroupType } from "../../../../utils";
7 import { GetArtifactsByTypeAction } from "../../../store/actions/artifacts.action";
8 import { Observable } from "rxjs/index";
9 import { ArtifactsState } from "../../../store/states/artifacts.state";
10 import { map } from "rxjs/operators";
11 import { ArtifactType, ComponentState, ComponentType } from "app/utils/constants"
12 import { TopologyTemplateService } from "app/ng2/services/component-services/topology-template.service";
15 selector: 'tosca-artifact-page',
17 templateUrl: './tosca-artifact-page.component.html',
18 styleUrls: ['./tosca-artifact-page.component.less', '../../../../../assets/styles/table-style.less']
20 export class ToscaArtifactPageComponent implements OnInit {
22 @Select(WorkspaceState.isViewOnly) isViewOnly$: boolean;
23 @ViewChild('toscaArtifactsTable') table: any;
24 public toscaArtifacts$: Observable<ArtifactModel[]>;
25 public componentId: string;
26 public componentType:string;
27 public isLoading: boolean = false;
30 private workspaceService: WorkspaceService,
32 @Inject("Notification") private Notification: any,
33 private componentService: TopologyTemplateService) {
38 this.componentId = this.workspaceService.metadata.uniqueId;
39 this.componentType = this.workspaceService.metadata.componentType;
41 this.store.dispatch(new GetArtifactsByTypeAction({componentType:this.componentType, componentId:this.componentId, artifactType:ArtifactGroupType.TOSCA}));
42 this.toscaArtifacts$ = this.store.select(ArtifactsState.getArtifactsByType).pipe(map(filterFn => filterFn(ArtifactGroupType.TOSCA)));
46 if(event.type === 'click'){
47 this.table.rowDetail.toggleExpandRow(event.row);
51 getExtension(artifactType: string) {
52 switch (artifactType) {
53 case (ArtifactType.TOSCA.TOSCA_CSAR):
55 case (ArtifactType.TOSCA.TOSCA_TEMPLATE):
61 return ComponentType.SERVICE === this.componentType;
65 return this.workspaceService.metadata.lifecycleState === ComponentState.NOT_CERTIFIED_CHECKOUT;
68 onFileUpload(file, artifactType) {
69 if (file && file.name) {
70 this.isLoading = true;
71 switch (artifactType) {
72 case (ArtifactType.TOSCA.TOSCA_CSAR):
73 this.componentService.putServiceToscaModel(this.componentId, this.componentType, file).subscribe((response)=> {
74 this.Notification.success({
75 message: "Service " + response.name + " has been updated",
78 this.isLoading = false;
80 this.isLoading = false;
83 case (ArtifactType.TOSCA.TOSCA_TEMPLATE):
84 this.componentService.putServiceToscaTemplate(this.componentId, this.componentType, file).subscribe((response)=> {
85 this.Notification.success({
86 message: "Service " + response.name + " has been updated",
89 this.isLoading = false;
91 this.isLoading = false;