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 {Distribution, DistributionComponent, ExportExcel} from "app/models";
25 interface IDistributionStatusModalViewModelScope {
26 distribution:Distribution;
28 getStatusCount(distributionComponent:Array<DistributionComponent>):any;
29 getUrlName(url:string):string;
30 modalDitributionStatus:ng.ui.bootstrap.IModalServiceInstance;
31 footerButtons:Array<any>;
32 //exportExcelData:ExportExcel;
34 initDataForExportExcel():ExportExcel;
37 export class DistributionStatusModalViewModel {
39 static '$inject' = ['$scope', '$uibModalInstance', 'data', '$filter'];
41 constructor(private $scope:IDistributionStatusModalViewModelScope,
42 private $uibModalInstance:ng.ui.bootstrap.IModalServiceInstance,
44 private $filter:ng.IFilterService) {
48 private generateMetaDataForExportExcel = ():Array<string>=> {
50 metaData[0] = 'Name:' + this.data.component.name + '| UUID:' + this.data.component.uuid + '| Invariant UUID:' + this.data.component.invariantUUID;
51 metaData[1] = 'Distribution ID:' + this.$scope.distribution.distributionID +
52 '| USER ID:' + this.$scope.distribution.userId +
53 '| Time[UTC]:' + this.$filter('date')(this.$scope.distribution.timestamp, 'MM/dd/yyyy h:mma', 'UTC') +
54 '| Status:' + this.$scope.distribution.deployementStatus;
58 private generateDataObjectForExportExcel = ():any=> {
59 let correctFormatDataObj = [];
60 _.each(this.$scope.distribution.distributionComponents, (dComponent:DistributionComponent) => {
61 if (dComponent.status == this.$scope.status) {
62 correctFormatDataObj.push({
63 'omfComponentID': dComponent.omfComponentID,
64 'artiFactName': this.$scope.getUrlName(dComponent.url),
65 'url': dComponent.url,
66 'timestamp': this.$filter('date')(dComponent.timestamp, 'MM/dd/yyyy h:mma', 'UTC'),
67 'status': dComponent.status
71 return correctFormatDataObj;
74 private initScope = ():void => {
75 this.$scope.distribution = this.data.distribution;
76 this.$scope.status = this.data.status;
77 this.$scope.modalDitributionStatus = this.$uibModalInstance;
80 this.$scope.getUrlName = (url:string):string => {
81 let urlName:string = _.last(url.split('/'));
85 this.$scope.initDataForExportExcel = ():ExportExcel => {
86 let exportExcelData = new ExportExcel();
87 exportExcelData.fileName = this.$scope.status;
88 exportExcelData.groupByField = "omfComponentID";
89 exportExcelData.tableHeaders = ["Component ID", "Artifact Name", "URL", "Time(UTC)", "Status"];
90 exportExcelData.metaData = this.generateMetaDataForExportExcel();
91 exportExcelData.dataObj = this.generateDataObjectForExportExcel();
92 return exportExcelData;
95 this.$scope.close = ():void => {
96 this.$uibModalInstance.close();
99 this.$scope.footerButtons = [
100 {'name': 'Close', 'css': 'blue', 'callback': this.$scope.close}