2 import {ModalsHandler} from "app/utils";
3 import {SharingService} from "app/services";
4 import {IAppConfigurtaion, ArtifactModel, IFileDownload} from "app/models";
5 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
6 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
7 import {ArtifactGroupModel} from "../../../../models/artifacts";
8 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
10 export interface IInformationArtifactsScope extends IWorkspaceViewModelScope {
11 artifacts:Array<ArtifactModel>;
12 tableHeadersList:Array<any>;
14 isResourceInstance:boolean;
15 downloadFile:IFileDownload;
21 addOrUpdate(artifact:ArtifactModel):void;
22 delete(artifact:ArtifactModel):void;
23 download(artifact:ArtifactModel):void;
24 clickArtifactName(artifact:any):void;
25 openEditEnvParametersModal(artifactResource:ArtifactModel):void;
26 sort(sortBy:string):void;
27 showNoArtifactMessage():boolean;
30 export class InformationArtifactsViewModel {
41 constructor(private $scope:IInformationArtifactsScope,
42 private $filter:ng.IFilterService,
44 private sdcConfig:IAppConfigurtaion,
45 private ModalsHandler:ModalsHandler,
46 private ComponentServiceNg2: ComponentServiceNg2) {
47 this.initInformationalArtifacts();
48 this.$scope.updateSelectedMenuItem();
51 private initInformationalArtifacts = ():void => {
52 if(!this.$scope.component.artifacts) {
53 this.$scope.isLoading = true;
54 this.ComponentServiceNg2.getComponentInformationalArtifacts(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
55 this.$scope.component.artifacts = response.artifacts;
57 this.$scope.isLoading = false;
64 private initScope = ():void => {
66 this.$scope.isLoading = false;
67 this.$scope.sortBy = 'artifactDisplayName';
68 this.$scope.reverse = false;
69 this.$scope.setValidState(true);
70 this.$scope.artifactType = 'informational';
71 this.$scope.getTitle = ():string => {
72 return this.$filter("resourceName")(this.$scope.component.name) + ' Artifacts';
76 this.$scope.tableHeadersList = [
77 {title: 'Name', property: 'artifactDisplayName'},
78 {title: 'Type', property: 'artifactType'},
79 {title: 'Version', property: 'artifactVersion'},
80 {title: 'UUID', property: 'artifactUUID'}
83 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
84 this.$scope.sort = (sortBy:string):void => {
85 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
86 this.$scope.sortBy = sortBy;
90 this.$scope.addOrUpdate = (artifact:ArtifactModel):void => {
91 artifact.artifactGroupType = 'INFORMATIONAL';
92 this.ModalsHandler.openArtifactModal(artifact, this.$scope.component).then(() => {
93 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
97 this.$scope.showNoArtifactMessage = ():boolean => {
98 let artifacts:any = [];
99 artifacts = _.filter(this.$scope.artifacts, (artifact:ArtifactModel)=> {
100 return artifact.esId;
103 if (artifacts.length === 0) {
109 this.$scope.delete = (artifact:ArtifactModel):void => {
111 let onOk = ():void => {
112 this.$scope.isLoading = true;
113 let onSuccess = ():void => {
114 this.$scope.isLoading = false;
115 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
118 let onFailed = (error:any):void => {
119 console.log('Delete artifact returned error:', error);
120 this.$scope.isLoading = false;
123 this.$scope.component.deleteArtifact(artifact.uniqueId, artifact.artifactLabel).then(onSuccess, onFailed);
126 let title:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TITLE");
127 let message:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TEXT", "{'name': '" + artifact.artifactDisplayName + "'}");
128 this.ModalsHandler.openConfirmationModal(title, message, false).then(onOk);
131 this.$scope.clickArtifactName = (artifact:any) => {
132 if (!artifact.esId) {
133 this.$scope.addOrUpdate(artifact);