Skip to content

Commit

Permalink
Merge pull request #440 from sinfo/389-change-download-cvs-error-for-…
Browse files Browse the repository at this point in the history
…companies

Error changed so companies know what happened
  • Loading branch information
andreromao authored Apr 14, 2024
2 parents 5cd78f7 + fae81ed commit 3ef29f8
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 16 deletions.
2 changes: 1 addition & 1 deletion src/app/session/session.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { SessionService } from './session.service'
import { Session } from './session.model'
import { SpeakerService } from '../speakers/speaker.service'
import { Speaker } from '../speakers/speaker.model'
import { EventService } from './../events/event.service'
import { EventService } from '../events/event.service'
import {
trigger,
style,
Expand Down
2 changes: 1 addition & 1 deletion src/app/sponsor/sponsor.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { SessionService } from '../session/session.service';
import { Session } from '../session/session.model'
import { Company } from '../company/company.model';
import { CompanyService } from '../company/company.service';
import { EventService } from './../events/event.service'
import { EventService } from '../events/event.service'
import { Event } from '../events/event.model';
import { Sponsor } from '../landing-page/sponsors/sponsor.model';

Expand Down
2 changes: 1 addition & 1 deletion src/app/static/static.component.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnInit } from '@angular/core'
import { Title } from '@angular/platform-browser'

import { EventService } from './../events/event.service'
import { EventService } from '../events/event.service'

@Component({
selector: 'app-code-of-conduct',
Expand Down
2 changes: 1 addition & 1 deletion src/app/user/cv/cv.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HttpEventType, HttpResponse } from '@angular/common/http'
import { EventService } from '../../events/event.service'
import { UserService } from '../user.service'
import { User } from '../user.model'
import { environment } from './../../../environments/environment'
import { environment } from '../../../environments/environment'
import { AuthService } from '../../auth/auth.service'
import { File as CV } from './file'
import { MatDialog } from '@angular/material/dialog'
Expand Down
5 changes: 3 additions & 2 deletions src/app/user/downloads/downloads.component.css
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
.btn {
margin: 0;
margin: 0 auto;
margin-bottom: 10px;
letter-spacing: 3px;
min-width: 250px;
padding: 15px;
font-size: 12px;;
font-size: 12px;
}

.btn-info {
background-color: #428bca;
border-color: #357ebd;
Expand Down
13 changes: 7 additions & 6 deletions src/app/user/downloads/downloads.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,18 @@ <h6 class="lead">

<div class="row">
<div class="col-sm-12">
<a href="{{ cvsDownloadUrl }}" target="_blank" class="btn btn-info">
<button (click)="downloadCVs()" class="btn btn-info">
<span class="glyphicon glyphicon-cloud-download"></span>
Download CVs
</a>
</button>
</div>
<div *ngIf="me && me.role === 'company'" class="col-sm-12">
<a href="{{ linksCVsDownloadUrl }}" target="_blank" class="btn btn-info">
<span class="glyphicon glyphicon-link"></span>
Download Links' CVs
</a>
<button (click)="downloadLinksCVs()" class="btn btn-info">
<span class="glyphicon glyphicon-link"></span>
Download Links' CVs
</button>
</div>

</div>

</div>
Expand Down
70 changes: 67 additions & 3 deletions src/app/user/downloads/downloads.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ import { environment } from '../../../environments/environment'
import { AuthService } from '../../auth/auth.service'
import { EventService } from '../../events/event.service'

import { catchError } from 'rxjs/operators';
import { Observable } from 'rxjs';


import { HttpClient, HttpHeaders, HttpParams} from '@angular/common/http';

@Component({
selector: 'app-downloads',
templateUrl: './downloads.component.html',
Expand All @@ -26,9 +32,11 @@ export class DownloadsComponent implements OnInit {
private companyService: CompanyService,
private authService: AuthService,
private eventService: EventService,
private titleService: Title
private titleService: Title,
private http: HttpClient
) { }


ngOnInit () {
this.userService.getMe()
.subscribe(me => {
Expand All @@ -45,11 +53,10 @@ export class DownloadsComponent implements OnInit {
const company = me.company.find(c => {
return c.edition === event.id
})

this.companyService.getCompany(company.company)
.subscribe(_company => {
this.company = _company
})
});

this.linksCVsDownloadUrl = `${environment.cannonUrl}/company/${company.company}` +
`/files/download?editionId=${event.id}&links=true` +
Expand All @@ -62,4 +69,61 @@ export class DownloadsComponent implements OnInit {
})
})
}

downloadCVs() {
if (this.cvsDownloadUrl) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
}),
observe: 'response' as 'response'
};

this.http.get(this.cvsDownloadUrl, httpOptions)
.pipe(
catchError(err => {
console.error('Failed to download CVs:', err);
alert('Unable to dowload CVs at this time. When available the team will contact you.');
throw err; // Re-throw the error if needed for further handling
})
)
.subscribe({
next: response => {
// Success, open the download URL
window.open(this.cvsDownloadUrl, '_blank');
}
});
} else {
alert('CV download URL is not available.');
}
}

downloadLinksCVs() {
if (this.linksCVsDownloadUrl) {
const httpOptions = {
headers: new HttpHeaders({
'Content-Type': 'application/json'
}),
observe: 'response' as 'response'
};

this.http.get(this.linksCVsDownloadUrl, httpOptions)
.pipe(
catchError(err => {
console.error('Failed to download linked CVs:', err);
alert('Unable to dowload links CVs at this time. When available the team will contact you.');
throw err; // Re-throw the error if needed for further handling
})
)
.subscribe({
next: response => {
// Success, open the download URL
window.open(this.linksCVsDownloadUrl, '_blank');
}
});
} else {
alert('Links CV download URL is not available.');
}
}

}
2 changes: 1 addition & 1 deletion src/app/user/my-profile/my-profile.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Title } from '@angular/platform-browser'

import { UserService } from '../user.service'
import { User } from '../user.model'
import { environment } from './../../../environments/environment'
import { environment } from '../../../environments/environment'
import { CompanyService } from '../../company/company.service'
import { Company } from '../../company/company.model'
import { AuthService } from '../../auth/auth.service'
Expand Down

0 comments on commit 3ef29f8

Please sign in to comment.