Skip to content

Commit

Permalink
Img preview (#1118)
Browse files Browse the repository at this point in the history
* fix(secureImage): handle missing image to show unavailable image and avoid message service to raise

* lint + cleanup

* fix(secureImage): handle missing image to show unavailable image and avoid message service to raise

* lint

* chore(build): remove reverse storedqueries from default build (prod and dev)

* chore(build): remove reverse storedqueries from default build (prod and dev)

* fix(demo): fix layer error

* refactor(layer-legend): legend was flashing during loading

Co-authored-by: Pierre-Étienne Lord <[email protected]>
Co-authored-by: Philippe Lafreniere <[email protected]>
  • Loading branch information
3 people authored and cbourget committed Mar 21, 2023
1 parent f705f4d commit 49a5d65
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 42 deletions.
5 changes: 5 additions & 0 deletions angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@
"demo/src/config",
"demo/src/contexts",
"demo/src/locale",
{
"glob": "**/*",
"input": "./dist/common/assets/",
"output": "./assets/igo2/common/"
},
{
"glob": "**/*",
"input": "./dist/core/assets/",
Expand Down
3 changes: 3 additions & 0 deletions demo/src/app/common/entity-table/entity-table.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ export class AppEntityTableComponent implements OnInit, OnDestroy {
const ids = [2, 1, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13];

const entities = ids.map(id => {
if (id === 3) {
return { id , name: `Name ${id}`, description: `<b>Description ${id}</b>`, url: 'https://igouverte.org', image: 'https://www.igouverte.org/assets/img/NONEXISTINGIMAGE.png'};
}
return { id , name: `Name ${id}`, description: `<b>Description ${id}</b>`, url: 'https://igouverte.org', image: 'https://www.igouverte.org/assets/img/Igo_logoavec.png'};
});
this.store.load(entities);
Expand Down
31 changes: 3 additions & 28 deletions demo/src/app/geo/legend/legend.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,12 @@ export class AppLegendComponent {

this.layerService
.createAsyncLayer({
title: 'Commission scolaire anglophone',
sourceOptions: {
type: 'wms',
url: 'https://geoegl.msp.gouv.qc.ca/apis/ws/igo_gouvouvert.fcgi',
optionsFromCapabilities: true,
url: 'https://geoegl.msp.gouv.qc.ca/apis/wss/all.fcgi',
params: {
LAYERS: 'MELS_CS_ANGLO_S',
LAYERS: 'WMS_MEQ_CS_ANGLO',
VERSION: '1.3.0'
}
}
Expand Down Expand Up @@ -193,31 +193,6 @@ export class AppLegendComponent {
})
.subscribe(l => this.map.addLayer(l));

this.layerService
.createAsyncLayer({
title: '2 styles nurc:Arc_Sample_Parent',
visible: true,
legendOptions: {
// collapsed: false,
display: true,
// url: 'https://v.seloger.com/s/width/1144/visuels/0/m/l/4/0ml42xbt1n3itaboek3qec5dtskdgw6nlscu7j69k.jpg',
stylesAvailable: [
{ name: 'rain', title: 'Pluie' },
{ name: 'raster', title: 'Défaut' }
] //
},
sourceOptions: {
type: 'wms',
url: 'https://demo.geo-solutions.it/geoserver/ows',
optionsFromCapabilities: true,
params: {
LAYERS: 'nurc:Arc_Sample', // , test:Linea_costa
VERSION: '1.3.0'
}
}
})
.subscribe(l => this.map.addLayer(l));

this.layerService
.createAsyncLayer({
title: 'Avertissements routier',
Expand Down
1 change: 1 addition & 0 deletions demo/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ export const environment: Environment = {
]
},
searchSources: {
storedqueriesreverse: { enabled: false},
nominatim: {
enabled: false
},
Expand Down
1 change: 1 addition & 0 deletions demo/src/environments/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,7 @@ export const environment: Environment = {
]
},
searchSources: {
storedqueriesreverse: { enabled: false},
storedqueries: {
available: true,
title: 'Feuillets SNRC',
Expand Down
4 changes: 2 additions & 2 deletions gulpfile.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ gulp.task('core:copyAssets', done => {

gulp.task('common:copyAssets', done => {
gulp
.src('./packages/common/src/assets', {
.src('./packages/common/src/assets/**/*', {
base: './packages/common/src/assets/',
allowEmpty: true
})
Expand All @@ -64,7 +64,7 @@ gulp.task('common:copyAssets', done => {

gulp.task('auth:copyAssets', done => {
gulp
.src('./packages/auth/src/assets', {
.src('./packages/auth/src/assets/**/*', {
base: './packages/auth/src/assets/',
allowEmpty: true
})
Expand Down
Binary file added packages/common/src/assets/images/na.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
<ng-template #isAnUrlDefault>
<td mat-cell class="mat-cell-text" [ngClass]="getCellClass(record, column)">
<a href="{{getValue(record, column)}}" target='_blank' rel="noopener noreferrer" (click)="$event.stopPropagation()">
<img *ngIf="isImg(getValue(record, column));else notImg" src="{{(getValue(record, column) | secureImage) | async}}" width="50" heigth="auto">
<img igoImageError *ngIf="isImg(getValue(record, column));else notImg" src="{{(getValue(record, column) | secureImage) | async}}" width="50" heigth="auto">
<ng-template #notImg><span>{{
'igo.common.entity-table.targetHtmlUrl' | translate }}
</span></ng-template>
Expand All @@ -57,7 +57,7 @@
<ng-template #isAnUrlHTML>
<td mat-cell class="mat-cell-text" [ngClass]="getCellClass(record, column)">
<a href="{{getValue(record, column)}}" target='_blank' rel="noopener noreferrer" (click)="$event.stopPropagation()">
<img *ngIf="isImg(getValue(record, column));else notImg" src="{{(getValue(record, column) | secureImage) | async}}" width="50" heigth="auto">
<img igoImageError *ngIf="isImg(getValue(record, column));else notImg" src="{{(getValue(record, column) | secureImage) | async}}" width="50" heigth="auto">
<ng-template #notImg><span>{{ 'igo.geo.targetHtmlUrl' |
translate }} </span></ng-template>
</a>
Expand Down Expand Up @@ -111,7 +111,7 @@
<ng-template #isAnUrlUnsanitizedHTML>
<td mat-cell class="mat-cell-text" [ngClass]="getCellClass(record, column)">
<a href="{{getValue(record, column)}}" target='_blank' rel="noopener noreferrer" (click)="$event.stopPropagation()">
<img *ngIf="isImg(getValue(record, column));else notImg" src="{{(getValue(record, column) | secureImage) | async}}" width="50" heigth="auto">
<img igoImageError *ngIf="isImg(getValue(record, column));else notImg" src="{{(getValue(record, column) | secureImage) | async}}" width="50" heigth="auto">
<ng-template #notImg><span>{{ 'igo.geo.targetHtmlUrl' | translate }} </span></ng-template>
</a>
</td>
Expand Down
28 changes: 28 additions & 0 deletions packages/common/src/lib/image/image-error.directive.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import {
Directive,
HostListener,
Input,
ElementRef
} from '@angular/core';

@Directive({
selector: '[igoImageError]'
})
export class ImageErrorDirective {

@Input() errorImageUrl: string = '/assets/igo2/common/images/na.png';
@Input() hideError: boolean = false;

constructor(private el: ElementRef) {}

@HostListener("error", ['$event'])
public onError(event: any): void {
if (this.hideError) {
this.el.nativeElement.style.display = "none";
} else {
event.target.src = this.errorImageUrl;
}

}

}
5 changes: 3 additions & 2 deletions packages/common/src/lib/image/image.module.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
import { ImageErrorDirective } from './image-error.directive';
import { SecureImagePipe } from './secure-image.pipe';

@NgModule({
imports: [],
declarations: [SecureImagePipe],
exports: [SecureImagePipe]
declarations: [SecureImagePipe, ImageErrorDirective],
exports: [SecureImagePipe, ImageErrorDirective]
})
export class IgoImageModule {
static forRoot(): ModuleWithProviders<IgoImageModule> {
Expand Down
1 change: 1 addition & 0 deletions packages/common/src/lib/image/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
export * from './image-error.directive';
export * from './secure-image.pipe';
10 changes: 8 additions & 2 deletions packages/common/src/lib/image/secure-image.pipe.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { HttpClient, HttpHeaders } from '@angular/common/http';

import { Cacheable } from 'ts-cacheable';
import { Observable } from 'rxjs';
import { switchMap } from 'rxjs/operators';
import { catchError, switchMap } from 'rxjs/operators';
import { ConfigService } from '@igo2/core';

@Pipe({
Expand All @@ -20,7 +20,8 @@ export class SecureImagePipe implements PipeTransform {
transform(url: string): Observable<string> {
const headers = new HttpHeaders({
'Content-Type': 'text/plain',
activityInterceptor: 'false'
activityInterceptor: 'false',
interceptError: 'false'
});

const regexDepot = new RegExp(this.configService?.getConfig('depot.url') + '.*?(?="|$)');
Expand All @@ -34,6 +35,11 @@ export class SecureImagePipe implements PipeTransform {
responseType: 'blob'
})
.pipe(
catchError((err) => {
err.error.caught = true;
err.error.toDisplay = false;
throw err;
}),
switchMap((blob) => {
return new Observable((observer) => {
const reader = new FileReader();
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/lib/message/shared/message.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ interface ActiveMessageTranslation {
export class MessageService {
public messages$ = new BehaviorSubject<Message[]>([]);
private options: MessageOptions;
private activeMessageTranslations: ActiveMessageTranslation[];
private activeMessageTranslations: ActiveMessageTranslation[] = [];

constructor(
@Inject(Injector) private injector: Injector,
Expand Down
9 changes: 8 additions & 1 deletion packages/core/src/lib/request/error.interceptor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,16 @@ export class ErrorInterceptor implements HttpInterceptor {
) {}

intercept(
req: HttpRequest<any>,
originalReq: HttpRequest<any>,
next: HttpHandler
): Observable<HttpEvent<any>> {
const interceptError = originalReq.headers.get('interceptError');
const req = originalReq.clone({
headers: originalReq.headers.delete('interceptError')
});
if (interceptError === 'false') {
return next.handle(req);
}
const errorContainer = { httpError: undefined };
return next.handle(req).pipe(
catchError(error => this.handleError(error, errorContainer)),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@

<td *ngIf="feature.properties.target === undefined && !isObject(property.value) && isUrl(property.value) && isImg(property.value)">
<a href="{{property.value}}" target='_blank' (click)="openSecureUrl(property.value)" rel="noopener noreferrer">
<img src="{{(property.value | secureImage) | async}}" width="225" height="auto">
<img igoImageError src="{{(property.value | secureImage) | async}}" width="225" height="auto">
</a>
</td>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ <h4 matLine>{{computeItemTitle(item) | async}} </h4>
</div>
<div *ngIf="!(item.collapsed)">
<div *ngIf="item.url">
<img #renderedLegend id="{{item.title}}" (load)="onLoadImage(item.title)"
src="{{[item.imgGraphValue]}}"
<img igoImageError *ngIf="item.imgGraphValue" hideError="true" #renderedLegend id="{{item.title}}" (load)="onLoadImage(item.title)"
[src]="item.imgGraphValue"
alt="{{'igo.geo.layer.legend.loadingLegendText' | translate}}">
<small *ngIf="imagesHeight[item.title]<16">
{{'igo.geo.layer.legend.noLegendScale' | translate}}
Expand Down

0 comments on commit 49a5d65

Please sign in to comment.