@@ -9,6 +9,12 @@ import { environment } from '../../../environments/environment'
9
9
import { AuthService } from '../../auth/auth.service'
10
10
import { EventService } from '../../events/event.service'
11
11
12
+ import { catchError } from 'rxjs/operators' ;
13
+ import { Observable } from 'rxjs' ;
14
+
15
+
16
+ import { HttpClient , HttpHeaders , HttpParams } from '@angular/common/http' ;
17
+
12
18
@Component ( {
13
19
selector : 'app-downloads' ,
14
20
templateUrl : './downloads.component.html' ,
@@ -26,9 +32,11 @@ export class DownloadsComponent implements OnInit {
26
32
private companyService : CompanyService ,
27
33
private authService : AuthService ,
28
34
private eventService : EventService ,
29
- private titleService : Title
35
+ private titleService : Title ,
36
+ private http : HttpClient
30
37
) { }
31
38
39
+
32
40
ngOnInit ( ) {
33
41
this . userService . getMe ( )
34
42
. subscribe ( me => {
@@ -45,11 +53,10 @@ export class DownloadsComponent implements OnInit {
45
53
const company = me . company . find ( c => {
46
54
return c . edition === event . id
47
55
} )
48
-
49
56
this . companyService . getCompany ( company . company )
50
57
. subscribe ( _company => {
51
58
this . company = _company
52
- } )
59
+ } ) ;
53
60
54
61
this . linksCVsDownloadUrl = `${ environment . cannonUrl } /company/${ company . company } ` +
55
62
`/files/download?editionId=${ event . id } &links=true` +
@@ -62,4 +69,61 @@ export class DownloadsComponent implements OnInit {
62
69
} )
63
70
} )
64
71
}
72
+
73
+ downloadCVs ( ) {
74
+ if ( this . cvsDownloadUrl ) {
75
+ const httpOptions = {
76
+ headers : new HttpHeaders ( {
77
+ 'Content-Type' : 'application/json'
78
+ } ) ,
79
+ observe : 'response' as 'response'
80
+ } ;
81
+
82
+ this . http . get ( this . cvsDownloadUrl , httpOptions )
83
+ . pipe (
84
+ catchError ( err => {
85
+ console . error ( 'Failed to download CVs:' , err ) ;
86
+ alert ( 'Unable to dowload CVs at this time. When available the team will contact you.' ) ;
87
+ throw err ; // Re-throw the error if needed for further handling
88
+ } )
89
+ )
90
+ . subscribe ( {
91
+ next : response => {
92
+ // Success, open the download URL
93
+ window . open ( this . cvsDownloadUrl , '_blank' ) ;
94
+ }
95
+ } ) ;
96
+ } else {
97
+ alert ( 'CV download URL is not available.' ) ;
98
+ }
99
+ }
100
+
101
+ downloadLinksCVs ( ) {
102
+ if ( this . linksCVsDownloadUrl ) {
103
+ const httpOptions = {
104
+ headers : new HttpHeaders ( {
105
+ 'Content-Type' : 'application/json'
106
+ } ) ,
107
+ observe : 'response' as 'response'
108
+ } ;
109
+
110
+ this . http . get ( this . linksCVsDownloadUrl , httpOptions )
111
+ . pipe (
112
+ catchError ( err => {
113
+ console . error ( 'Failed to download linked CVs:' , err ) ;
114
+ alert ( 'Unable to dowload links CVs at this time. When available the team will contact you.' ) ;
115
+ throw err ; // Re-throw the error if needed for further handling
116
+ } )
117
+ )
118
+ . subscribe ( {
119
+ next : response => {
120
+ // Success, open the download URL
121
+ window . open ( this . linksCVsDownloadUrl , '_blank' ) ;
122
+ }
123
+ } ) ;
124
+ } else {
125
+ alert ( 'Links CV download URL is not available.' ) ;
126
+ }
127
+ }
128
+
65
129
}
0 commit comments