Commit a40009d0 authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Add support for dataset uuid in routes for dataset detail page

parent e44cff46
Pipeline #1780 passed with stages
in 6 minutes and 35 seconds
......@@ -15,7 +15,7 @@
<div class="dataset-list">
<div class="reused-dataset" *ngFor="let dataset of datasetsUsed">
<img [src]="dataset.image.url" alt="Dataset image"
<img [src]="dataset.image.url || './assets/img/vignette-data.png'" alt="Dataset image"
onerror="this.onerror=null;this.src='./assets/img/vignette-data.png';this.alt='Default image'">
<div class="dataset-title">
<a class="link-without-decoration"
......
......@@ -48,8 +48,6 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
this._scroller.scrollToPosition(this.position);
});
this.initDatasetInfo();
this._route.params.subscribe((params) => {
this.isLoading = true;
this.initDatasetInfo();
......@@ -123,7 +121,7 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
// If a tab (info, data...) is not specified in the url then redirect to the data tab if the dataset
// as a table or a map or to the info tab in the failing case
if (this._route.snapshot.url.join('/') === `${AppRoutes.datasets.uri}/${this._route.snapshot.params.id}`) {
if (!this._route.snapshot.firstChild) {
if (this.hasTable || this.hasMap) {
this._router.navigate([
`/${AppRoutes.datasets.uri}/${this._datasetDetailService.dataset.slug}/${AppRoutes.data.uri}`,
......@@ -133,6 +131,12 @@ export class DatasetDetailComponent implements OnInit, OnDestroy {
`/${AppRoutes.datasets.uri}/${this._datasetDetailService.dataset.slug}/${AppRoutes.info.uri}`,
]);
}
} else {
// Making that the url contains the slug and not the uuid of the dataset
this._router.navigate([
// tslint:disable-next-line: max-line-length
`/${AppRoutes.datasets.uri}/${this._datasetDetailService.dataset.slug}/${this._route.snapshot.firstChild.url[0]}`,
]);
}
// Emit event to indicate to child component that the dataset has changed
......
......@@ -24,7 +24,7 @@
</span>
<div class="related-dataset">
<div class="related-dataset-item">
<img [src]="parent.imageUrl" alt="dataset parent thumbnail image"
<img [src]="parent.imageUrl || './assets/img/vignette-collection.png'" alt="dataset parent thumbnail image"
onerror="this.onerror=null;this.src='./assets/img/vignette-collection.png';this.alt='Default image'">
<a class="link-without-decoration"
[routerLink]="['/', AppRoutes.datasets.uri, parent.slug]">{{parent.title}}</a>
......@@ -38,7 +38,7 @@
</span>
<div class="related-dataset">
<div class="related-dataset-item" *ngFor="let child of children">
<img [src]="child.imageUrl" alt="dataset children thumbnail image"
<img [src]="child.imageUrl || './assets/img/vignette-data.png'" alt="dataset children thumbnail image"
onerror="this.onerror=null;this.src='./assets/img/vignette-data.png';this.alt='Default image'">
<a class="link-without-decoration"
[routerLink]="['/', AppRoutes.datasets.uri, child.slug]">{{child.title}}</a>
......
......@@ -10,6 +10,8 @@ export interface IElasticsearchHit {
'metadata-fr': IMetadata;
'data-fr': IData;
} | IESCMSResponse;
'uuid': string;
'slug': string;
'inner_hits': {
'data': {
'hits': {
......
......@@ -10,8 +10,18 @@ export class DatasetDetailResolver implements Resolve<Dataset> {
constructor(private datasetDetailService: DatasetDetailService) { }
resolve(route: ActivatedRouteSnapshot) {
return this.datasetDetailService.initializeDataset(route.params.id).pipe(
catchError(() => of(null)),
);
let toBeReturned;
if (
!(route.params.id === this.datasetDetailService.dataset.slug) &&
!(route.params.id === this.datasetDetailService.dataset.uuid)
) {
toBeReturned = this.datasetDetailService.initializeDataset(route.params.id).pipe(
catchError(() => of(null)),
);
} else {
toBeReturned = of(null);
}
return toBeReturned;
}
}
......@@ -44,26 +44,26 @@ export class DatasetDetailService {
private _matomoService: MatomoService,
) { }
initializeDataset(slug: string): Observable<Dataset> {
initializeDataset(slugOrUuid: string): Observable<Dataset> {
this._dataset.data = [];
this._dataset.nbViews = null;
this._elasticSearchOptions = new ElasticsearchOptions(this._initialScrollOptions);
this.newAsyncRequest();
this._matomoService.getPageMetadataPageMetrics(slug).pipe(
this._matomoService.getPageMetadataPageMetrics(slugOrUuid).pipe(
catchError(() => of(null)),
).subscribe((nbViews) => {
this._dataset.nbViews = nbViews;
});
// Get the metadata
return this._elasticsearchService.getDatasetMetadata(slug).pipe(
return this._elasticsearchService.getDatasetMetadata(slugOrUuid).pipe(
map((e) => {
if (e.hits.hits.length > 0) {
const metadata = new Metadata(e.hits.hits[0]._source['metadata-fr']);
this._dataset.uuid = metadata.geonet.uuid;
this.dataset.slug = slug;
this._dataset.slug = e.hits.hits[0]._source['slug'];
this._dataset.editorialMetadata = e.hits.hits[0]._source['editorial-metadata'];
this._dataset.fields = e.hits.hits[0]._source['fields'] ? e.hits.hits[0]._source['fields'] : {
......
......@@ -48,16 +48,27 @@ export class ElasticsearchService {
);
}
getDatasetMetadata(slug: string): Observable<IElasticsearchResponse> {
getDatasetMetadata(slugOrUuid: string): Observable<IElasticsearchResponse> {
return this._http.request<IElasticsearchResponse>('POST', this.elasticSearchUrl, {
withCredentials: true,
body: {
from: 0,
size: 1,
_source: ['metadata-fr', 'editorial-metadata', 'uuid', 'fields'],
_source: ['metadata-fr', 'editorial-metadata', 'uuid', 'fields', 'slug'],
query: {
term: {
'slug.keyword': slug,
bool: {
should: [
{
term: {
'slug.keyword': slugOrUuid,
},
},
{
term: {
'metadata-fr.geonet:info.uuid.keyword': slugOrUuid,
},
},
],
},
},
},
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment