@@ -18,47 +18,69 @@ let downloadSummary = function (ApiService) {
18
18
scope . disableGenerate = true ;
19
19
scope . disableDownload = true ;
20
20
21
+ scope . downloadStatus = {
22
+ workloadSummaries : {
23
+ isEmpty : true ,
24
+ isLessThanOneHourOld : true ,
25
+ disableDownload : true ,
26
+ disableGenerate : false ,
27
+ fileStatus : ""
28
+ } ,
29
+ workloadSnapshots : {
30
+ isEmpty : true ,
31
+ isLessThanOneHourOld : true
32
+ }
33
+ } ;
34
+
21
35
ApiService . get ( `/api/workloadSummaryReport/years/${ year } /download/status` ) . then ( metadata => {
22
- if ( metadata ) {
23
- const isEmptyFile = metadata . contentLength === 0 ;
24
- const isLessThanOneHourAgo = scope . IsDateLessThanOneHourAgo ( metadata . lastModified ) ;
36
+ Object . keys ( metadata ) . forEach ( file => {
37
+ const isEmpty = metadata [ file ] . contentLength === 0 ;
38
+ const isLessThanOneHourOld = scope . IsDateLessThanOneHourAgo ( metadata [ file ] . lastModified ) ;
39
+
40
+ scope . downloadStatus [ file ] . isEmpty = isEmpty ;
41
+ scope . downloadStatus [ file ] . isLessThanOneHourOld = isLessThanOneHourOld ;
25
42
26
- if ( isEmptyFile && isLessThanOneHourAgo ) {
27
- scope . disableDownload = true ;
28
- scope . disableGenerate = true ;
29
- scope . fileStatus = "In progress, check back later." ;
30
- } else if ( isEmptyFile && ! isLessThanOneHourAgo ) {
31
- scope . disableDownload = true ;
32
- scope . disableGenerate = false ;
33
- scope . fileStatus = "File creation failed, please try again." ;
43
+ if ( isEmpty && isLessThanOneHourOld ) {
44
+ scope . downloadStatus [ file ] . disableDownload = true ;
45
+ scope . downloadStatus [ file ] . disableGenerate = true ;
46
+ scope . downloadStatus [ file ] . fileStatus = "In progress, check back later." ;
47
+ } else if ( isEmpty && ! isLessThanOneHourOld ) {
48
+ scope . downloadStatus [ file ] . disableDownload = true ;
49
+ scope . downloadStatus [ file ] . disableGenerate = false ;
50
+ scope . downloadStatus [ file ] . fileStatus = "File creation failed, please try again." ;
34
51
} else {
35
- scope . disableDownload = false ;
36
- scope . disableGenerate = false ;
37
- scope . fileStatus = "Created: " + new Date ( metadata . lastModified ) . toLocaleString ( ) ;
52
+ scope . downloadStatus [ file ] . disableDownload = false ;
53
+ scope . downloadStatus [ file ] . disableGenerate = false ;
54
+ scope . downloadStatus [ file ] . fileStatus = "Created: " + new Date ( metadata [ file ] . lastModified ) . toLocaleString ( ) ;
38
55
}
39
- } else {
40
- scope . disableDownload = true ;
41
- scope . disableGenerate = false ;
42
- }
56
+ } ) ;
57
+
43
58
scope . isLoading = false ;
44
59
} ) ;
45
60
46
61
scope . generate = ( ) => {
47
- scope . disableGenerate = true ;
48
- scope . fileStatus = "In progress, check back later." ;
62
+ scope . downloadStatus . workloadSummaries . disableGenerate = true ;
63
+ scope . downloadStatus . workloadSummaries . fileStatus = "In progress, check back later." ;
49
64
50
- ApiService . get ( `/api/workloadSummaryReport/${ workgroupId } /years/${ year } /generateMultiple` ) ;
65
+ ApiService . post ( `/api/workloadSummaryReport/${ workgroupId } /years/${ year } /generateMultiple` , null ) ;
51
66
} ;
52
67
53
- scope . download = ( ) => {
54
- ApiService . postWithResponseType ( `/api/workloadSummaryReport/${ scope . workgroup . id } /years/${ year } /downloadMultiple` , "" , "" , 'arraybuffer' ) . then (
68
+ scope . download = ( file ) => {
69
+ let reportName ;
70
+ if ( file === "workloadSummaries" ) {
71
+ reportName = `Summary Report` ;
72
+ } else if ( file === "workloadSnapshots" ) {
73
+ reportName = `Snapshots` ;
74
+ }
75
+
76
+ ApiService . postWithResponseType ( `/api/workloadSummaryReport/years/${ year } /downloadMultiple/${ file } ` , "" , "" , 'arraybuffer' ) . then (
55
77
response => {
56
78
var url = window . URL . createObjectURL (
57
79
new Blob ( [ response . data ] , { type : 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' } )
58
80
) ;
59
81
var a = window . document . createElement ( 'a' ) ; // eslint-disable-line
60
82
a . href = url ;
61
- a . download = `${ year } Workload Summary Report .xlsx` ;
83
+ a . download = `${ year } Workload ${ reportName } .xlsx` ;
62
84
window . document . body . appendChild ( a ) ; // eslint-disable-line
63
85
a . click ( ) ;
64
86
a . remove ( ) ; //afterwards we remove the element again
0 commit comments