Skip to content

Commit

Permalink
adding image placeholders.
Browse files Browse the repository at this point in the history
fix #353
  • Loading branch information
AnalogJ committed Dec 13, 2023
1 parent 7c6b180 commit 5d966d8
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div (click)="onCardClick()" class="card-body" [class.border-left-danger]="status == 'failed'">

<div class="h-100 d-flex align-items-center">
<img [src]="'assets/sources/'+(sourceInfo?.metadata.brand_logo ? sourceInfo?.metadata?.brand_logo : sourceInfo?.metadata?.source_type+'.png')" [alt]="sourceInfo?.metadata?.display" class="img-fluid">
<img imageFallback [src]="'assets/sources/'+(sourceInfo?.metadata.brand_logo ? sourceInfo?.metadata?.brand_logo : sourceInfo?.metadata?.source_type+'.png')" [alt]="sourceInfo?.metadata?.display" class="img-fluid">
<div *ngIf="status == 'failed'" class="card-img-overlay">
<span class="badge badge-danger">failed</span>
</div>
Expand Down
9 changes: 6 additions & 3 deletions frontend/src/app/directives/directives.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,19 @@ import { NgModule } from '@angular/core';

// Directives
import {ExternalLinkDirective} from './external-link.directive';
import { ImageFallbackDirective } from './image-fallback.directive';

@NgModule({
declarations: [
ExternalLinkDirective,
ImageFallbackDirective,
],
imports: [

],
exports: [
ExternalLinkDirective,
]
exports: [
ExternalLinkDirective,
ImageFallbackDirective,
]
})
export class DirectivesModule {}
8 changes: 8 additions & 0 deletions frontend/src/app/directives/image-fallback.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { ImageFallbackDirective } from './image-fallback.directive';

describe('ImageFallbackDirective', () => {
it('should create an instance', () => {
const directive = new ImageFallbackDirective();
expect(directive).toBeTruthy();
});
});
16 changes: 16 additions & 0 deletions frontend/src/app/directives/image-fallback.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import {Directive, ElementRef, HostListener, Input} from '@angular/core';

@Directive({
selector: 'img[imageFallback]'
})
export class ImageFallbackDirective {

@Input() imageFallback?: string;
constructor(private elementRef: ElementRef) {}

@HostListener('error')
loadFallbackOnError() {
this.elementRef.nativeElement.src = this.imageFallback || 'assets/images/no-image.svg';
}

}
Binary file added frontend/src/assets/banner/banner-trimmed.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions frontend/src/assets/images/no-image.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 5d966d8

Please sign in to comment.