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 * as _ from "lodash";
23 import {ModalsHandler} from "app/utils";
24 import {SharingService} from "app/services";
25 import {IAppConfigurtaion, ArtifactModel, IFileDownload} from "app/models";
26 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
27 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
28 import {ArtifactGroupModel} from "../../../../models/artifacts";
29 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
31 export interface IInformationArtifactsScope extends IWorkspaceViewModelScope {
32 artifacts:Array<ArtifactModel>;
33 tableHeadersList:Array<any>;
35 isResourceInstance:boolean;
36 downloadFile:IFileDownload;
42 addOrUpdate(artifact:ArtifactModel):void;
43 delete(artifact:ArtifactModel):void;
44 download(artifact:ArtifactModel):void;
45 clickArtifactName(artifact:any):void;
46 openEditEnvParametersModal(artifactResource:ArtifactModel):void;
47 sort(sortBy:string):void;
48 showNoArtifactMessage():boolean;
51 export class InformationArtifactsViewModel {
62 constructor(private $scope:IInformationArtifactsScope,
63 private $filter:ng.IFilterService,
65 private sdcConfig:IAppConfigurtaion,
66 private ModalsHandler:ModalsHandler,
67 private ComponentServiceNg2: ComponentServiceNg2) {
68 this.initInformationalArtifacts();
71 private initInformationalArtifacts = ():void => {
72 if(!this.$scope.component.artifacts) {
73 this.$scope.isLoading = true;
74 this.ComponentServiceNg2.getComponentInformationalArtifacts(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
75 this.$scope.component.artifacts = response.artifacts;
77 this.$scope.isLoading = false;
84 private initScope = ():void => {
86 this.$scope.isLoading = false;
87 this.$scope.sortBy = 'artifactDisplayName';
88 this.$scope.reverse = false;
89 this.$scope.setValidState(true);
90 this.$scope.artifactType = 'informational';
91 this.$scope.getTitle = ():string => {
92 return this.$filter("resourceName")(this.$scope.component.name) + ' Artifacts';
96 this.$scope.tableHeadersList = [
97 {title: 'Name', property: 'artifactDisplayName'},
98 {title: 'Type', property: 'artifactType'},
99 {title: 'Version', property: 'artifactVersion'},
100 {title: 'UUID', property: 'artifactUUID'}
103 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
104 this.$scope.sort = (sortBy:string):void => {
105 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
106 this.$scope.sortBy = sortBy;
110 this.$scope.addOrUpdate = (artifact:ArtifactModel):void => {
111 artifact.artifactGroupType = 'INFORMATIONAL';
112 this.ModalsHandler.openArtifactModal(artifact, this.$scope.component).then(() => {
113 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
117 this.$scope.showNoArtifactMessage = ():boolean => {
118 let artifacts:any = [];
119 artifacts = _.filter(this.$scope.artifacts, (artifact:ArtifactModel)=> {
120 return artifact.esId;
123 if (artifacts.length === 0) {
129 this.$scope.delete = (artifact:ArtifactModel):void => {
131 let onOk = ():void => {
132 this.$scope.isLoading = true;
133 let onSuccess = ():void => {
134 this.$scope.isLoading = false;
135 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
138 let onFailed = (error:any):void => {
139 console.log('Delete artifact returned error:', error);
140 this.$scope.isLoading = false;
143 this.$scope.component.deleteArtifact(artifact.uniqueId, artifact.artifactLabel).then(onSuccess, onFailed);
146 let title:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TITLE");
147 let message:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TEXT", "{'name': '" + artifact.artifactDisplayName + "'}");
148 this.ModalsHandler.openConfirmationModal(title, message, false).then(onOk);
151 this.$scope.clickArtifactName = (artifact:any) => {
152 if (!artifact.esId) {
153 this.$scope.addOrUpdate(artifact);