2 * ============LICENSE_START=======================================================
4 * ================================================================================
5 * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6 * ================================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END=========================================================
22 import {ModalsHandler} from "app/utils";
23 import {SharingService} from "app/services";
24 import {IAppConfigurtaion, ArtifactModel, IFileDownload} from "app/models";
25 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
26 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
27 import {ArtifactGroupModel} from "../../../../models/artifacts";
28 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
30 export interface IInformationArtifactsScope extends IWorkspaceViewModelScope {
31 artifacts:Array<ArtifactModel>;
32 tableHeadersList:Array<any>;
34 isResourceInstance:boolean;
35 downloadFile:IFileDownload;
41 addOrUpdate(artifact:ArtifactModel):void;
42 delete(artifact:ArtifactModel):void;
43 download(artifact:ArtifactModel):void;
44 clickArtifactName(artifact:any):void;
45 openEditEnvParametersModal(artifactResource:ArtifactModel):void;
46 sort(sortBy:string):void;
47 showNoArtifactMessage():boolean;
50 export class InformationArtifactsViewModel {
61 constructor(private $scope:IInformationArtifactsScope,
62 private $filter:ng.IFilterService,
64 private sdcConfig:IAppConfigurtaion,
65 private ModalsHandler:ModalsHandler,
66 private ComponentServiceNg2: ComponentServiceNg2) {
67 this.initInformationalArtifacts();
70 private initInformationalArtifacts = ():void => {
71 if(!this.$scope.component.artifacts) {
72 this.$scope.isLoading = true;
73 this.ComponentServiceNg2.getComponentInformationalArtifacts(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
74 this.$scope.component.artifacts = response.artifacts;
76 this.$scope.isLoading = false;
83 private initScope = ():void => {
85 this.$scope.isLoading = false;
86 this.$scope.sortBy = 'artifactDisplayName';
87 this.$scope.reverse = false;
88 this.$scope.setValidState(true);
89 this.$scope.artifactType = 'informational';
90 this.$scope.getTitle = ():string => {
91 return this.$filter("resourceName")(this.$scope.component.name) + ' Artifacts';
95 this.$scope.tableHeadersList = [
96 {title: 'Name', property: 'artifactDisplayName'},
97 {title: 'Type', property: 'artifactType'},
98 {title: 'Version', property: 'artifactVersion'},
99 {title: 'UUID', property: 'artifactUUID'}
102 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
103 this.$scope.sort = (sortBy:string):void => {
104 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
105 this.$scope.sortBy = sortBy;
109 this.$scope.addOrUpdate = (artifact:ArtifactModel):void => {
110 artifact.artifactGroupType = 'INFORMATIONAL';
111 this.ModalsHandler.openArtifactModal(artifact, this.$scope.component).then(() => {
112 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
116 this.$scope.showNoArtifactMessage = ():boolean => {
117 let artifacts:any = [];
118 artifacts = _.filter(this.$scope.artifacts, (artifact:ArtifactModel)=> {
119 return artifact.esId;
122 if (artifacts.length === 0) {
128 this.$scope.delete = (artifact:ArtifactModel):void => {
130 let onOk = ():void => {
131 this.$scope.isLoading = true;
132 let onSuccess = ():void => {
133 this.$scope.isLoading = false;
134 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
137 let onFailed = (error:any):void => {
138 console.log('Delete artifact returned error:', error);
139 this.$scope.isLoading = false;
142 this.$scope.component.deleteArtifact(artifact.uniqueId, artifact.artifactLabel).then(onSuccess, onFailed);
145 let title:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TITLE");
146 let message:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TEXT", "{'name': '" + artifact.artifactDisplayName + "'}");
147 this.ModalsHandler.openConfirmationModal(title, message, false).then(onOk);
150 this.$scope.clickArtifactName = (artifact:any) => {
151 if (!artifact.esId) {
152 this.$scope.addOrUpdate(artifact);