5ffae646895b25a43ad6b754c0e747c0fa7e812e
[sdc.git] /
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
21 'use strict';
22 import {Distribution, DistributionComponent, ExportExcel} from "app/models";
23
24 interface IDistributionStatusModalViewModelScope {
25     distribution:Distribution;
26     status:string;
27     getStatusCount(distributionComponent:Array<DistributionComponent>):any;
28     getUrlName(url:string):string;
29     modalDitributionStatus:ng.ui.bootstrap.IModalServiceInstance;
30     footerButtons:Array<any>;
31     //exportExcelData:ExportExcel;
32     close():void;
33     initDataForExportExcel():ExportExcel;
34 }
35
36 export class DistributionStatusModalViewModel {
37
38     static '$inject' = ['$scope', '$uibModalInstance', 'data', '$filter'];
39
40     constructor(private $scope:IDistributionStatusModalViewModelScope,
41                 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
42                 private data:any,
43                 private $filter:ng.IFilterService) {
44         this.initScope();
45     }
46
47     private generateMetaDataForExportExcel = ():Array<string>=> {
48         let metaData = [];
49         metaData[0] = 'Name:' + this.data.component.name + '| UUID:' + this.data.component.uuid + '|  Invariant UUID:' + this.data.component.invariantUUID;
50         metaData[1] = 'Distribution ID:' + this.$scope.distribution.distributionID +
51             '| USER ID:' + this.$scope.distribution.userId +
52             '| Time[UTC]:' + this.$filter('date')(this.$scope.distribution.timestamp, 'MM/dd/yyyy h:mma', 'UTC') +
53             '| Status:' + this.$scope.distribution.deployementStatus;
54         return metaData;
55     };
56
57     private generateDataObjectForExportExcel = ():any=> {
58         let correctFormatDataObj = [];
59         _.each(this.$scope.distribution.distributionComponents, (dComponent:DistributionComponent) => {
60             if (dComponent.status == this.$scope.status) {
61                 correctFormatDataObj.push({
62                     'omfComponentID': dComponent.omfComponentID,
63                     'artiFactName': this.$scope.getUrlName(dComponent.url),
64                     'url': dComponent.url,
65                     'timestamp': this.$filter('date')(dComponent.timestamp, 'MM/dd/yyyy h:mma', 'UTC'),
66                     'status': dComponent.status
67                 });
68             }
69         });
70         return correctFormatDataObj;
71     };
72
73     private initScope = ():void => {
74         this.$scope.distribution = this.data.distribution;
75         this.$scope.status = this.data.status;
76         this.$scope.modalDitributionStatus = this.$uibModalInstance;
77
78
79         this.$scope.getUrlName = (url:string):string => {
80             let urlName:string = _.last(url.split('/'));
81             return urlName;
82         };
83
84         this.$scope.initDataForExportExcel = ():ExportExcel => {
85             let exportExcelData = new ExportExcel();
86             exportExcelData.fileName = this.$scope.status;
87             exportExcelData.groupByField = "omfComponentID";
88             exportExcelData.tableHeaders = ["Component ID", "Artifact Name", "URL", "Time(UTC)", "Status"];
89             exportExcelData.metaData = this.generateMetaDataForExportExcel();
90             exportExcelData.dataObj = this.generateDataObjectForExportExcel();
91             return exportExcelData;
92         };
93
94         this.$scope.close = ():void => {
95             this.$uibModalInstance.close();
96         };
97
98         this.$scope.footerButtons = [
99             {'name': 'Close', 'css': 'blue', 'callback': this.$scope.close}
100         ];
101
102     };
103 }