Skip to content
Snippets Groups Projects
Commit 9ca9bfab authored by FORESTIER Fabien's avatar FORESTIER Fabien
Browse files

Optimization of http calls on the Download and API tabs + small css fix

parent 68832883
No related branches found
No related tags found
1 merge request!73Development
Pipeline #5069 passed
...@@ -45,15 +45,11 @@ export class DatasetAPIComponent implements OnInit, OnDestroy { ...@@ -45,15 +45,11 @@ export class DatasetAPIComponent implements OnInit, OnDestroy {
this.cguModalIsOpened = (this._cookieService.get(environment.cguAcceptedCookieName) !== 'true') && this.cguModalIsOpened = (this._cookieService.get(environment.cguAcceptedCookieName) !== 'true') &&
!this._userService.userIsSignedIn; !this._userService.userIsSignedIn;
this.initialize();
this._resourcesService.getResources().subscribe( this._resourcesService.getResources().subscribe(
(results) => { (results) => {
this.resources = results; this.resources = results;
this.initialize(); this.initialize();
this.sub = this._datasetDetailService.dataset$.subscribe(() => {
this.initialize();
});
}, },
(err) => { (err) => {
this._notificationService.notify(new Notification({ this._notificationService.notify(new Notification({
...@@ -63,6 +59,9 @@ export class DatasetAPIComponent implements OnInit, OnDestroy { ...@@ -63,6 +59,9 @@ export class DatasetAPIComponent implements OnInit, OnDestroy {
}, },
); );
this.sub = this._datasetDetailService.dataset$.subscribe(() => {
this.initialize();
});
} }
ngOnDestroy() { ngOnDestroy() {
......
...@@ -8,12 +8,12 @@ ...@@ -8,12 +8,12 @@
<span>{{downloadable.key}}</span> <span>{{downloadable.key}}</span>
</div> </div>
<div class="resource-downloadable-files" *ngFor="let resource of downloadable.value"> <div class="resource-downloadable-files" *ngFor="let resource of downloadable.value">
<ng-container *ngFor="let format of resource.formats; let i=index"> <div class="resource-download-item-wrapper" *ngFor="let format of resource.formats; let i=index">
<app-resource-download-item [metadata]="metadata" <app-resource-download-item [metadata]="metadata"
[format]="format" [resource]="resource" [projections]="projections" [format]="format" [resource]="resource" [projections]="projections"
[isQueryable]="true"> [isQueryable]="true">
</app-resource-download-item> </app-resource-download-item>
</ng-container> </div>
</div> </div>
</div> </div>
</div> </div>
......
...@@ -48,11 +48,11 @@ ...@@ -48,11 +48,11 @@
.resource-download { .resource-download {
margin-bottom: 1.5rem; margin-bottom: 1.5rem;
border-bottom: 2px solid $grey-background-color;
background-color: white; background-color: white;
padding: 2.5rem; padding: 2.5rem;
box-shadow: 0 6px 12px 0 rgba(129, 128, 128, 0.1); box-shadow: 0 6px 12px 0 rgba(129, 128, 128, 0.1);
border-radius: 8px; border-radius: 8px;
border-bottom: 2px solid $grey-background-color;
} }
.resource-description { .resource-description {
...@@ -136,6 +136,15 @@ ...@@ -136,6 +136,15 @@
} }
} }
.resource-download-item-wrapper,
.resource-static-files {
border-bottom: 1px solid #f2f2f2;
}
.resource-downloadable-files:last-of-type .resource-download-item-wrapper:last-of-type,
.resource-static-files:last-of-type {
border-bottom: none;
}
::ng-deep .downloads-container { ::ng-deep .downloads-container {
.modal { .modal {
overflow-y: auto; overflow-y: auto;
......
...@@ -53,29 +53,26 @@ export class DatasetDownloadsComponent implements OnInit { ...@@ -53,29 +53,26 @@ export class DatasetDownloadsComponent implements OnInit {
this.isSample = this._datasetDetailService.dataset.editorialMetadata.isSample; this.isSample = this._datasetDetailService.dataset.editorialMetadata.isSample;
this.initialize();
// Why retrieveDatasetData():
// to retrieve the first data for the dataset (if exists). It will be used in the
// Data, Downloads and API tabs.
forkJoin([ forkJoin([
this._resourcesService.getProjections(), this._resourcesService.getProjections(),
this._resourcesService.getResources(), this._resourcesService.getResources(),
this._datasetDetailService.retrieveDatasetData(), ]).subscribe(
]).subscribe((response) => { (response) => {
this.projections = response[0]; this.projections = response[0];
this.resources = response[1]; this.resources = response[1];
this.initialize();
this.sub = this._datasetDetailService.dataset$.subscribe(() => {
this.initialize(); this.initialize();
}); },
// tslint:disable-next-line: align (err) => {
}, (err) => { this._notificationService.notify(new Notification({
this._notificationService.notify(new Notification({ type: 'error',
type: 'error', message: `${notificationMessages.resources.initializationError}`,
message: `${notificationMessages.resources.initializationError}`, }));
})); },
);
this.sub = this._datasetDetailService.dataset$.subscribe(() => {
this.initialize();
}); });
} }
......
<div class="resource-download"> <div class="resource-download-item">
<div class="first-line"> <div class="first-line">
<div class="resource-left"> <div class="resource-left">
......
@import '../../../../../../scss/variables.scss'; @import '../../../../../../scss/variables.scss';
@import '../.././../../../../../node_modules/bulma/sass/utilities/_all.sass'; @import '../.././../../../../../node_modules/bulma/sass/utilities/_all.sass';
.resource-download { .resource-download-item {
background-color: white; background-color: white;
align-items: center; align-items: center;
border-bottom: 1px solid #f2f2f2;
margin-top: 1rem; margin-top: 1rem;
padding-bottom: 1rem; padding-bottom: 1rem;
} }
......
import { HttpClient } from '@angular/common/http'; import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import lodashClonedeep from 'lodash.clonedeep'; import lodashClonedeep from 'lodash.clonedeep';
import { of } from 'rxjs';
import { map } from 'rxjs/operators'; import { map } from 'rxjs/operators';
import { APP_CONFIG } from '../../core/services/app-config.service'; import { APP_CONFIG } from '../../core/services/app-config.service';
import { IMetadataLink, linkFormats, Metadata } from '../../shared/models'; import { IMetadataLink, linkFormats, Metadata } from '../../shared/models';
...@@ -11,24 +12,36 @@ export class ResourcesService { ...@@ -11,24 +12,36 @@ export class ResourcesService {
linkFormats = linkFormats; linkFormats = linkFormats;
resources: Resource[]; resources: Resource[];
projections: Projection[];
constructor( constructor(
private _httpClient: HttpClient, private _httpClient: HttpClient,
) { } ) { }
getResources() { getResources() {
if (this.resources && this.resources.length > 0) {
return of(this.resources);
}
return this._httpClient.get<IResource[]>(`${APP_CONFIG.backendUrls.resources}/resources`).pipe( return this._httpClient.get<IResource[]>(`${APP_CONFIG.backendUrls.resources}/resources`).pipe(
map((resourcesBack) => { map((resourcesBack) => {
this.resources = resourcesBack.map(r => new Resource(r)); this.resources = resourcesBack.map(r => new Resource(r));
return this.resources; return this.resources;
})); }),
);
} }
getProjections() { getProjections() {
if (this.projections && this.projections.length > 0) {
return of(this.projections);
}
return this._httpClient.get<IProjection[]>(`${APP_CONFIG.backendUrls.resources}/projections`).pipe( return this._httpClient.get<IProjection[]>(`${APP_CONFIG.backendUrls.resources}/projections`).pipe(
map((resourcesBack) => { map((projections) => {
return resourcesBack.map(r => new Projection(r)); this.projections = projections.map(r => new Projection(r));
})); return this.projections;
}),
);
} }
getQueryableResources(link: IMetadataLink[]) { getQueryableResources(link: IMetadataLink[]) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment