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 {ArtifactModel, IFileDownload} from "app/models";
24 import {IWorkspaceViewModelScope} from "app/view-models/workspace/workspace-view-model";
25 import {ComponentGenericResponse} from "../../../../ng2/services/responses/component-generic-response";
26 import {ComponentServiceNg2} from "../../../../ng2/services/component-services/component.service";
28 export interface IToscaArtifactsScope extends IWorkspaceViewModelScope {
29 artifacts:Array<ArtifactModel>;
30 tableHeadersList:Array<any>;
32 downloadFile:IFileDownload;
38 download(artifact:ArtifactModel):void;
39 sort(sortBy:string):void;
40 showNoArtifactMessage():boolean;
43 export class ToscaArtifactsViewModel {
51 constructor(private $scope:IToscaArtifactsScope,
52 private $filter:ng.IFilterService,
53 private ComponentServiceNg2:ComponentServiceNg2) {
54 this.initToscaArtifacts();
57 private initToscaArtifacts = (): void => {
59 if(!this.$scope.component.toscaArtifacts) {
60 this.$scope.isLoading = true;
61 this.ComponentServiceNg2.getComponentToscaArtifacts(this.$scope.component).subscribe((response:ComponentGenericResponse) => {
62 this.$scope.component.toscaArtifacts = response.toscaArtifacts;
64 this.$scope.isLoading = false;
66 this.$scope.isLoading = false;
73 private initScope = ():void => {
74 this.$scope.isLoading = false;
75 this.$scope.sortBy = 'artifactDisplayName';
76 this.$scope.reverse = false;
77 this.$scope.setValidState(true);
78 this.$scope.artifactType = 'informational';
79 this.$scope.getTitle = ():string => {
80 return this.$filter("resourceName")(this.$scope.component.name) + ' Artifacts';
84 this.$scope.tableHeadersList = [
85 {title: 'Name', property: 'artifactDisplayName'},
86 {title: 'Type', property: 'artifactType'},
87 {title: 'Version', property: 'artifactVersion'}
90 this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.toscaArtifacts);
91 this.$scope.sort = (sortBy:string):void => {
92 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
93 this.$scope.sortBy = sortBy;
97 this.$scope.showNoArtifactMessage = ():boolean => {
98 if (this.$scope.artifacts.length === 0) {