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 {Distribution, DistributionComponent, ExportExcel} from "app/models";
24 interface IDistributionStatusModalViewModelScope {
25 distribution:Distribution;
27 getStatusCount(distributionComponent:Array<DistributionComponent>):any;
28 getUrlName(url:string):string;
29 modalDitributionStatus:ng.ui.bootstrap.IModalServiceInstance;
30 footerButtons:Array<any>;
31 //exportExcelData:ExportExcel;
33 initDataForExportExcel():ExportExcel;
36 export class DistributionStatusModalViewModel {
38 static '$inject' = ['$scope', '$uibModalInstance', 'data', '$filter'];
40 constructor(private $scope:IDistributionStatusModalViewModelScope,
41 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
43 private $filter:ng.IFilterService) {
47 private generateMetaDataForExportExcel = ():Array<string>=> {
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;
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
70 return correctFormatDataObj;
73 private initScope = ():void => {
74 this.$scope.distribution = this.data.distribution;
75 this.$scope.status = this.data.status;
76 this.$scope.modalDitributionStatus = this.$uibModalInstance;
79 this.$scope.getUrlName = (url:string):string => {
80 let urlName:string = _.last(url.split('/'));
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;
94 this.$scope.close = ():void => {
95 this.$uibModalInstance.close();
98 this.$scope.footerButtons = [
99 {'name': 'Close', 'css': 'blue', 'callback': this.$scope.close}