diff --git a/src/app/geosource/components/dataset-detail/dataset-data-details/dataset-data-detail-properties/dataset-data-detail-properties.component.scss b/src/app/geosource/components/dataset-detail/dataset-data-details/dataset-data-detail-properties/dataset-data-detail-properties.component.scss index 4e5d6ac175d75b27d6b39c51dc6beff65bdb48f7..b997f176cacbf0a745a7f3a568e856900a0afc52 100644 --- a/src/app/geosource/components/dataset-detail/dataset-data-details/dataset-data-detail-properties/dataset-data-detail-properties.component.scss +++ b/src/app/geosource/components/dataset-detail/dataset-data-details/dataset-data-detail-properties/dataset-data-detail-properties.component.scss @@ -2,7 +2,7 @@ .property-value { font-weight: 600; - word-break: break-all; + word-break: break-word; } .property-child { diff --git a/src/app/geosource/components/dataset-detail/dataset-detail.component.ts b/src/app/geosource/components/dataset-detail/dataset-detail.component.ts index 98759a892b8a2bade49c81e45e844edc7b4b4721..9f5810005382747299445564d7f66fc2aa819ef2 100644 --- a/src/app/geosource/components/dataset-detail/dataset-detail.component.ts +++ b/src/app/geosource/components/dataset-detail/dataset-detail.component.ts @@ -23,7 +23,6 @@ export class DatasetDetailComponent implements OnInit, OnDestroy { pageHeaderInfo: IPageHeaderInfo = { title: '', }; - metadata: Metadata; readonly typesMetadata = typesMetadata; position: any; scrollSubscription: Subscription; @@ -50,24 +49,11 @@ export class DatasetDetailComponent implements OnInit, OnDestroy { this._scroller.scrollToPosition(this.position); }); + this.initDatasetInfo(); + this._route.params.subscribe((params) => { this.isLoading = true; - this._datasetDetailService.initializeDataset(params.id).subscribe( - (res) => { - this.initDatasetInfo(); - }, - (err) => { - this._notificationService.notify(new Notification({ - message: err.message, - type: 'error', - })); - if (err.redirect) { - this._router.navigate(['/', AppRoutes.page404.uri]); - } else { - this.initDatasetInfo(); - } - }, - ); + this.initDatasetInfo(); }); } @@ -75,6 +61,10 @@ export class DatasetDetailComponent implements OnInit, OnDestroy { this.scrollSubscription.unsubscribe(); } + get metadata(): Metadata { + return this._datasetDetailService.datasetMetadata; + } + // Number of data found by elasticsearch get datasetDataNumber() { return this._datasetDetailService.datasetDataNumber; @@ -124,10 +114,6 @@ export class DatasetDetailComponent implements OnInit, OnDestroy { } initDatasetInfo() { - // Emit event to indicate to child component that the dataset has changed - this._datasetDetailService.datasetChanged(); - this.metadata = this._datasetDetailService.datasetMetadata; - this.pageHeaderInfo = { title: this.metadata.title, metadataSubtitle: this.metadata.subtitle, @@ -135,6 +121,19 @@ export class DatasetDetailComponent implements OnInit, OnDestroy { }; this.isLoading = false; + + if (this.hasTable || this.hasMap) { + this._router.navigate([ + `/${AppRoutes.datasets.uri}/${this._datasetDetailService.dataset.slug}/${AppRoutes.data.uri}`, + ]); + } else { + this._router.navigate([ + `/${AppRoutes.datasets.uri}/${this._datasetDetailService.dataset.slug}/${AppRoutes.info.uri}`, + ]); + } + + // Emit event to indicate to child component that the dataset has changed + this._datasetDetailService.datasetChanged(); } setPosition() { diff --git a/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.scss b/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.scss index 83d3e5a02989b02a4938c33b18d6872fda8ebe68..665da900d1f5c480216e063804836b27f56c6bd8 100644 --- a/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.scss +++ b/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.scss @@ -126,7 +126,7 @@ } .documents-number { - border-bottom: 1px solid #ccd6ea; + border-bottom: 2px solid #ccd6ea; position: relative; align-self: center; padding-bottom: 0.2rem; @@ -138,9 +138,9 @@ } .result-number-bar { - border-bottom: 1px solid $blue-color; + border-bottom: 2px solid $blue-color; position: absolute; - top: 1px; + top: 2px; height: 100%; left: 0; } diff --git a/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.ts b/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.ts index baf1c883e3179160ba8726131253704bf3c1af77..0c517006db81359cf5f0f80b6546e1296e7abffd 100644 --- a/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.ts +++ b/src/app/geosource/components/dataset-detail/dataset-table-map/dataset-table-map.component.ts @@ -2,8 +2,6 @@ import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core'; import { DatasetDetailService } from '../../../services'; import { DatasetMapComponent } from '../dataset-map/dataset-map.component'; import { FormControl } from '@angular/forms'; -import { Router, ActivatedRoute } from '@angular/router'; -import { AppRoutes } from '../../../../routes'; import { Data } from '../../../models'; import { Subscription } from 'rxjs'; @@ -23,7 +21,6 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy { tableIsEnabled = true; displayDataDetails = false; // Wether the data details should be displayed or not - properties: string[]; selectedProperties: string[] = []; // Array of columns to be displayed selectedData: Data | mapboxgl.MapboxGeoJSONFeature = null; // Contains the properties of the selected feature dataDetailsShouldBeAnimated = false; // Used to prevent animation on first load of the component @@ -35,23 +32,16 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy { constructor( private _datasetDetailService: DatasetDetailService, - private _router: Router, - private _route: ActivatedRoute, ) { } ngOnInit() { + this.initComponent(); + this.subscriptions.push( // If the dataset has at least a table or a map then initialize the component // else redirect to the info tab this._datasetDetailService.dataset$.subscribe(() => { - if (this.hasTable || this.hasMap) { - this.properties = this._datasetDetailService.dataset.fields.list; - this.selectedProperties = Array.from(this.properties); - // Intialize the search value with the value from the service in order to keep it when navigating in tabs - this.searchInput.setValue(this._datasetDetailService.searchString); - } else { - this._router.navigate([`./${AppRoutes.info.uri}`], { relativeTo: this._route.parent }); - } + this.initComponent(); }), ); } @@ -62,6 +52,12 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy { }); } + initComponent() { + this.selectedProperties = Array.from(this.properties); + // Intialize the search value with the value from the service in order to keep it when navigating in tabs + this.searchInput.setValue(this._datasetDetailService.searchString); + } + get isSample(): boolean { return this._datasetDetailService.dataset.editorialMetadata.isSample; } @@ -88,6 +84,10 @@ export class DatasetTableMapComponent implements OnInit, OnDestroy { return this._datasetDetailService.datasetDataNumber; } + get properties() { + return this._datasetDetailService.dataset.fields.list; + } + get researchMaxResult() { return this._datasetDetailService.researchMaxResult; } diff --git a/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.scss b/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.scss index 9ddff69d6468812c281fc2971e6dcfef3feca825..91eb22269963a2d373ce376ca75e36414ec221f3 100644 --- a/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.scss +++ b/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.scss @@ -25,6 +25,14 @@ span { color: $tomato-color; } + + svg path { + fill: $tomato-color !important; + } + + .warning-complexity { + color: $tomato-color !important; + } } .column-header { diff --git a/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.ts b/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.ts index 5a5f3664a8429dbcdbf6aea0bc8f9139dc44d15f..464d4c453f9fe0f5e974c6d63640b0e5433a89a5 100644 --- a/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.ts +++ b/src/app/geosource/components/dataset-detail/dataset-table/dataset-table.component.ts @@ -32,7 +32,6 @@ export class DatasetTableComponent implements OnInit, OnDestroy { private subscriptions: Subscription[] = []; AppRoutes = AppRoutes; - data: Data[] = []; // Infinite scroll throttle = 300; @@ -46,14 +45,8 @@ export class DatasetTableComponent implements OnInit, OnDestroy { ) { } ngOnInit() { - - this.initializeComponent(); - + this.getSearchResults(); this.subscriptions.push( - // Subscribe to dataset changes - this._datasetDetailService.dataset$.subscribe(() => { - this.initializeComponent(); - }), // Subscribe to input changes this._datasetDetailService.datasetDataSearchChanged$.subscribe(() => { this.getSearchResults(); @@ -67,10 +60,6 @@ export class DatasetTableComponent implements OnInit, OnDestroy { }); } - initializeComponent() { - this.data = this._datasetDetailService.datasetData; - } - getStyle() { const gridColumns = this.selectedProperties.length !== 1 ? `repeat(${this.selectedProperties.length - 1}, max-content) 1fr` : '1fr'; @@ -92,9 +81,7 @@ export class DatasetTableComponent implements OnInit, OnDestroy { // cause an internal error in elaticsearch and the request will fail if (this._datasetDetailService.scrollOptionsSum <= this.maximumNumberOfData) { // Update the array of data with the newly retrieved data (size shoul have increased by 'size' value) - this._datasetDetailService.retrieveMoreDatasetData().subscribe((data) => { - this.data = data; - }); + this._datasetDetailService.retrieveMoreDatasetData().subscribe(); } else { this.message = `${geosource.datasetData.maxDataDisplayedMessage}${this.maximumNumberOfData}.`; } @@ -107,22 +94,22 @@ export class DatasetTableComponent implements OnInit, OnDestroy { // Set the new sort value in the service this._datasetDetailService.sortBy(key); // Retrieve date sorted with the new value - this._datasetDetailService.retrieveDatasetData().subscribe((data) => { - this.data = data; - }); + this._datasetDetailService.retrieveDatasetData().subscribe(); } getSearchResults() { // Get the new data - this._datasetDetailService.retrieveDatasetData().subscribe((data) => { - this.data = data; - }); + this._datasetDetailService.retrieveDatasetData().subscribe(); } emitSelectedData(data: Data) { this.dataSelected.emit(data); } + get data(): Data[] { + return this._datasetDetailService.datasetData; + } + get sortValue() { return this._datasetDetailService.sortValue; } diff --git a/src/app/geosource/geosource-routing.module.ts b/src/app/geosource/geosource-routing.module.ts index fc4615d030fb541759b7d857a0f0b5e59f320efe..eedd2d4d8a539570b9b7b4c8d4f995a7cf5b19ba 100644 --- a/src/app/geosource/geosource-routing.module.ts +++ b/src/app/geosource/geosource-routing.module.ts @@ -6,6 +6,7 @@ import { DatasetTableMapComponent } from './components'; import { AppRoutes } from '../routes'; +import { DatasetDetailResolver } from './resolvers'; export const routes: Routes = [ { @@ -34,12 +35,10 @@ export const routes: Routes = [ { path: `${AppRoutes.datasets.uri}/:id`, component: DatasetDetailComponent, + resolve: { + dataset: DatasetDetailResolver, + }, children: [ - { - path: '', - redirectTo: AppRoutes.data.uri, - pathMatch: 'full', - }, { path: AppRoutes.info.uri, component: DatasetInfoComponent, diff --git a/src/app/geosource/geosource.module.ts b/src/app/geosource/geosource.module.ts index 2ddd0a23012453b0ffeea935b407953ee7c29e7a..569603110d88c38de6cfd9d607bb74060b77da42 100644 --- a/src/app/geosource/geosource.module.ts +++ b/src/app/geosource/geosource.module.ts @@ -8,6 +8,7 @@ import { SharedModule } from '../shared/shared.module'; import { MapModule } from '../map/map.module'; import { InlineSVGModule } from 'ng-inline-svg'; import { InfiniteScrollModule } from 'ngx-infinite-scroll'; +import { GeosourceResolvers } from './resolvers'; @NgModule({ imports: [ @@ -33,7 +34,7 @@ export class GeosourceModule { static forRoot(): ModuleWithProviders { return { ngModule: GeosourceModule, - providers: [DatasetResearchService], + providers: [DatasetResearchService, GeosourceResolvers], }; } } diff --git a/src/app/geosource/models/dataset.model.ts b/src/app/geosource/models/dataset.model.ts index 33e6491dfe14fcf0158a7ed78d2589fd649c11dc..59ad5d1d917920d3cb32e4a487b52c530b35f75b 100644 --- a/src/app/geosource/models/dataset.model.ts +++ b/src/app/geosource/models/dataset.model.ts @@ -21,7 +21,7 @@ export interface IDatasetFields { export class Dataset { uuid: string; - slug?: string; + slug: string; highlights?: Highlights; metadata: Metadata; totalData: number; @@ -40,6 +40,17 @@ export class Dataset { this.data = data.data ? data.data : []; this.totalData = data.totalData ? data.totalData : 0; this.editorialMetadata = new EditorialMetadata(data.editorialMetadata); + } else { + this.uuid = null; + this.slug = null; + this.metadata = new Metadata(); + this.fields = { + list: [], + types: {}, + }; + this.data = []; + this.totalData = 0; + this.editorialMetadata = new EditorialMetadata(); } } diff --git a/src/app/geosource/models/editorial-metadata.model.ts b/src/app/geosource/models/editorial-metadata.model.ts index 82f0b8a0e5520552cd078fd85d859416d21a8007..0412f5784cfa04853c909e08b95ef80bb9dd3914 100644 --- a/src/app/geosource/models/editorial-metadata.model.ts +++ b/src/app/geosource/models/editorial-metadata.model.ts @@ -19,7 +19,7 @@ export class EditorialMetadata { isSearchable: boolean; isSample: boolean; - constructor(metadata: IEditorialMetadata) { + constructor(metadata?: IEditorialMetadata) { if (metadata) { this.isAreal = metadata.isAreal; this.isLinear = metadata.isLinear; diff --git a/src/app/geosource/resolvers/dataset-detail.resolver.ts b/src/app/geosource/resolvers/dataset-detail.resolver.ts new file mode 100644 index 0000000000000000000000000000000000000000..2ff09dc6e842cb04ed662de64f071bcb4b4434b3 --- /dev/null +++ b/src/app/geosource/resolvers/dataset-detail.resolver.ts @@ -0,0 +1,17 @@ +import { Resolve, ActivatedRouteSnapshot } from '@angular/router'; +import { Injectable } from '@angular/core'; +import { catchError, map } from 'rxjs/operators'; +import { of } from 'rxjs'; +import { DatasetDetailService } from '../services'; +import { Dataset, Metadata, IMetadata } from '../models'; + +@Injectable() +export class DatasetDetailResolver implements Resolve<Dataset> { + constructor(private datasetDetailService: DatasetDetailService) { } + + resolve(route: ActivatedRouteSnapshot) { + return this.datasetDetailService.initializeDataset(route.params.id).pipe( + catchError(() => of(null)), + ); + } +} diff --git a/src/app/geosource/resolvers/index.ts b/src/app/geosource/resolvers/index.ts new file mode 100644 index 0000000000000000000000000000000000000000..af5791ad0a5fd7bdd91eebf12c18b09cac1d0792 --- /dev/null +++ b/src/app/geosource/resolvers/index.ts @@ -0,0 +1,10 @@ +import { DatasetDetailResolver } from './dataset-detail.resolver'; + +export { + DatasetDetailResolver, +}; + +// tslint:disable-next-line:variable-name +export const GeosourceResolvers = [ + DatasetDetailResolver, +]; diff --git a/src/app/geosource/services/dataset-detail.service.ts b/src/app/geosource/services/dataset-detail.service.ts index 8019f9af9f2d8da75c98de74d4203ef38e745de8..ff7e3817eed0560df1b4832cebd4447e1621d9e6 100644 --- a/src/app/geosource/services/dataset-detail.service.ts +++ b/src/app/geosource/services/dataset-detail.service.ts @@ -43,7 +43,7 @@ export class DatasetDetailService { private _matomoService: MatomoService, ) { } - initializeDataset(slug: string) { + initializeDataset(slug: string): Observable<Dataset> { this._dataset.data = []; this._dataset.nbViews = null; this._elasticSearchOptions = new ElasticsearchOptions(this._initialScrollOptions); @@ -62,9 +62,13 @@ export class DatasetDetailService { 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.editorialMetadata = e.hits.hits[0]._source['editorial-metadata']; - this._dataset.fields = e.hits.hits[0]._source['fields']; + this._dataset.fields = e.hits.hits[0]._source['fields'] ? e.hits.hits[0]._source['fields'] : { + list: [], + types: {}, + }; metadata.dataset_id = e.hits.hits[0]._id; const bbox = e.hits.hits[0]._source['metadata-fr']['bbox']; if (bbox !== undefined && bbox['coordinates'] !== undefined) { @@ -126,10 +130,6 @@ export class DatasetDetailService { return of(dataset); } }), - flatMap(() => { - // Retrieve a part of the dataset's data (see size in scrollQueryOptions) - return this.retrieveDatasetData(); - }), flatMap(() => { // Get the dataset's children return this._elasticsearchService.getDatasetChildren(this._dataset.uuid).pipe( @@ -150,6 +150,9 @@ export class DatasetDetailService { }), ); }), + map(() => { + return this.dataset; + }), finalize(() => { this.asyncRequestDone(); }), diff --git a/src/app/map/components/map.component.scss b/src/app/map/components/map.component.scss index 1aade434ae8a693501831ebee2a016feca4b8ee2..bb6430ec36aa88e8f4facb4ad8ec82045325ca53 100644 --- a/src/app/map/components/map.component.scss +++ b/src/app/map/components/map.component.scss @@ -49,6 +49,10 @@ } } +::ng-deep .button[disabled] { + border: none; +} + .copy-map, .geolocation-container { position: absolute; diff --git a/src/app/map/services/map.service.ts b/src/app/map/services/map.service.ts index 720182e674c2a14da00f9549d2d5b1e8f7db5681..d365704844c01c4ee60776689094c26891c34fd8 100644 --- a/src/app/map/services/map.service.ts +++ b/src/app/map/services/map.service.ts @@ -253,6 +253,15 @@ export class MapService { this.featureHighlightedColor, 'transparent', ], + 'circle-stroke-width': ['case', + ['boolean', ['feature-state', 'hover'], false], + 1, + ['boolean', ['feature-state', 'highlight'], false], + 1, + 0, + ], + 'circle-stroke-color': 'white', + 'circle-stroke-opacity': 0.5, // 'circle-radius': 0.5, }, });