Skip to content

Commit

Permalink
109442: Fix authorisation on comcol logo
Browse files Browse the repository at this point in the history
  • Loading branch information
Atmire-Kristof committed Dec 11, 2023
1 parent 72e5cb6 commit 3203a8d
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 13 deletions.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
<div *ngIf="logo && (src$ | async)" class="dso-logo mb-3">
<img [src]="src$ | async" class="img-fluid" [attr.alt]="alternateText ? alternateText : null" (error)="errorHandler($event)"/>
<div *ngIf="logo" class="dso-logo mb-3">
<img [src]="logo?._links?.content?.href" class="img-fluid" [class.d-none]="loading" [attr.alt]="alternateText ? alternateText : null" (error)="errorHandler($event)"/>
</div>
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { Component, Input, OnChanges } from '@angular/core';
import { Component, Input } from '@angular/core';

import { Bitstream } from '../../../core/shared/bitstream.model';
import { AuthService } from '../../../core/auth/auth.service';
import { AuthorizationDataService } from '../../../core/data/feature-authorization/authorization-data.service';
import { FileService } from '../../../core/shared/file.service';
import { BehaviorSubject, of as observableOf } from 'rxjs';
import { of as observableOf } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { FeatureID } from '../../../core/data/feature-authorization/feature-id';
import { hasValue } from '../../empty.util';
Expand All @@ -14,12 +14,15 @@ import { hasValue } from '../../empty.util';
styleUrls: ['./comcol-page-logo.component.scss'],
templateUrl: './comcol-page-logo.component.html',
})
export class ComcolPageLogoComponent implements OnChanges {
export class ComcolPageLogoComponent {
@Input() logo: Bitstream;

@Input() alternateText: string;

src$: BehaviorSubject<string> = new BehaviorSubject<string>(undefined);
/**
* Flag used to hide the image element while resolving an error into placeholder or authorised image
*/
loading = false;

/**
* The default 'holder.js' image
Expand All @@ -33,8 +36,15 @@ export class ComcolPageLogoComponent implements OnChanges {
) {
}

ngOnChanges() {
/**
* Handle an error on the image
* Attempt to get an authorised version of the image
* When that fails, or no logo is present, show the placeholder
*/
errorHandler(event) {
console.log(event);
if (this.logo?._links?.content?.href) {
this.loading = true;
this.auth.isAuthenticated().pipe(
switchMap((isLoggedIn) => {
if (isLoggedIn) {
Expand All @@ -52,16 +62,15 @@ export class ComcolPageLogoComponent implements OnChanges {
}),
).subscribe((src) => {
if (hasValue(src)) {
this.src$.next(src);
event.target.src = src;
} else {
this.src$.next(this.holderSource);
event.target.src = this.holderSource;
}
this.loading = false;
});
} else {
event.currentTarget.src = this.holderSource;
}
}

errorHandler(event) {
event.currentTarget.src = this.holderSource;
}

}

0 comments on commit 3203a8d

Please sign in to comment.