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=========================================================
20 /// <reference path="../../../../references"/>
21 module Sdc.ViewModels {
23 import ArtifactModel = Sdc.Models.ArtifactModel;
25 export interface IInformationArtifactsScope extends IWorkspaceViewModelScope {
26 artifacts: Array<Models.ArtifactModel>;
27 tableHeadersList: Array<any>;
29 isResourceInstance:boolean;
30 downloadFile:Models.IFileDownload;
36 addOrUpdate(artifact:Models.ArtifactModel): void;
37 delete(artifact:Models.ArtifactModel): void;
38 download(artifact:Models.ArtifactModel): void;
39 clickArtifactName(artifact:any):void;
40 openEditEnvParametersModal(artifactResource:Models.ArtifactModel):void;
41 sort(sortBy:string): void;
42 showNoArtifactMessage():boolean;
45 export class InformationArtifactsViewModel {
52 'Sdc.Services.SharingService',
58 constructor(private $scope:IInformationArtifactsScope,
59 private $filter:ng.IFilterService,
60 private $modal:ng.ui.bootstrap.IModalService,
61 private $templateCache:ng.ITemplateCacheService,
62 private sharingService:Sdc.Services.SharingService,
64 private sdcConfig:Models.IAppConfigurtaion,
65 private ModalsHandler:Utils.ModalsHandler) {
67 this.$scope.updateSelectedMenuItem();
71 private getMappedObjects():any {
73 normal: this.$scope.component.artifacts
77 private initScope = ():void => {
79 this.$scope.isLoading = false;
80 this.$scope.sortBy = 'artifactDisplayName';
81 this.$scope.reverse = false;
82 this.$scope.setValidState(true);
83 this.$scope.artifactType = 'normal';
84 this.$scope.getTitle = ():string => {
85 return this.$filter("resourceName")(this.$scope.component.name) + ' Artifacts';
89 this.$scope.tableHeadersList = [
90 {title: 'Name', property: 'artifactDisplayName'},
91 {title: 'Type', property: 'artifactType'}
94 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
95 this.$scope.sort = (sortBy:string):void => {
96 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
97 this.$scope.sortBy = sortBy;
101 this.$scope.addOrUpdate = (artifact:Models.ArtifactModel):void => {
102 artifact.artifactGroupType = 'INFORMATIONAL';
103 this.ModalsHandler.openWizardArtifactModal(artifact, this.$scope.component).then(() => {
104 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
108 this.$scope.showNoArtifactMessage = ():boolean => {
109 let artifacts:any = [];
110 artifacts = _.filter(this.$scope.artifacts, (artifact:Models.ArtifactModel)=> {
111 return artifact.esId;
114 if (artifacts.length === 0) {
120 this.$scope.delete = (artifact:Models.ArtifactModel):void => {
122 let onOk = ():void => {
123 this.$scope.isLoading = true;
124 let onSuccess = ():void => {
125 this.$scope.isLoading = false;
126 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.artifacts);
129 let onFailed = (error:any):void => {
130 console.log('Delete artifact returned error:', error);
131 this.$scope.isLoading = false;
134 this.$scope.component.deleteArtifact(artifact.uniqueId, artifact.artifactLabel).then(onSuccess, onFailed);
137 let title:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TITLE");
138 let message:string = this.$filter('translate')("ARTIFACT_VIEW_DELETE_MODAL_TEXT", "{'name': '" + artifact.artifactDisplayName + "'}");
139 this.ModalsHandler.openConfirmationModal(title, message, false).then(onOk);
142 this.$scope.clickArtifactName = (artifact:any) => {
143 if (!artifact.esId) {
144 this.$scope.addOrUpdate(artifact);