Initial OpenECOMP SDC commit
[sdc.git] / catalog-ui / app / scripts / view-models / workspace / tabs / tosca-artifacts / tosca-artifacts-view-model.ts
1 /*-
2  * ============LICENSE_START=======================================================
3  * SDC
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
10  *
11  *      http://www.apache.org/licenses/LICENSE-2.0
12  *
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=========================================================
19  */
20 /// <reference path="../../../../references"/>
21 module Sdc.ViewModels {
22     'use strict';
23     import ArtifactModel = Sdc.Models.ArtifactModel;
24
25     export interface IToscaArtifactsScope extends IWorkspaceViewModelScope {
26         artifacts: Array<Models.ArtifactModel>;
27         tableHeadersList: Array<any>;
28         artifactType: string;
29         downloadFile:Models.IFileDownload;
30         isLoading:boolean;
31         sortBy:string;
32         reverse:boolean;
33
34         getTitle(): string;
35         download(artifact:Models.ArtifactModel): void;
36         sort(sortBy:string): void;
37         showNoArtifactMessage():boolean;
38     }
39
40     export class ToscaArtifactsViewModel {
41
42         static '$inject' = [
43             '$scope',
44             '$filter'
45         ];
46
47         constructor(private $scope:IToscaArtifactsScope,
48                     private $filter:ng.IFilterService) {
49             this.initScope();
50             this.$scope.updateSelectedMenuItem();
51         }
52
53         private initScope = ():void => {
54             let self = this;
55             this.$scope.isLoading = false;
56             this.$scope.sortBy = 'artifactDisplayName';
57             this.$scope.reverse = false;
58             this.$scope.setValidState(true);
59             this.$scope.artifactType = 'normal';
60             this.$scope.getTitle = ():string => {
61                 return this.$filter("resourceName")(this.$scope.component.name) + ' Artifacts';
62
63             };
64
65             this.$scope.tableHeadersList = [
66                 {title: 'Name', property: 'artifactDisplayName'},
67                 {title: 'Type', property: 'artifactType'}
68             ];
69
70             this.$scope.artifacts = <ArtifactModel[]>_.values(this.$scope.component.toscaArtifacts);
71             this.$scope.sort = (sortBy:string):void => {
72                 this.$scope.reverse = (this.$scope.sortBy === sortBy) ? !this.$scope.reverse : false;
73                 this.$scope.sortBy = sortBy;
74             };
75
76
77
78             this.$scope.showNoArtifactMessage = ():boolean => {
79                 if (this.$scope.artifacts.length === 0) {
80                     return true;
81                 }
82                 return false;
83             };
84
85         }
86     }
87 }