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

Fix bug in dataset-table-map component

parent d68963ab
Branches
Tags
1 merge request!48Version 2.3.0
Pipeline #1709 passed
import { Component, OnInit, ViewChild } from '@angular/core'; import { Component, OnInit, ViewChild, OnDestroy } from '@angular/core';
import { DatasetDetailService } from '../../../services'; import { DatasetDetailService } from '../../../services';
import { DatasetMapComponent } from '../dataset-map/dataset-map.component'; import { DatasetMapComponent } from '../dataset-map/dataset-map.component';
import { FormControl } from '@angular/forms'; import { FormControl } from '@angular/forms';
import { Router, ActivatedRoute } from '@angular/router'; import { Router, ActivatedRoute } from '@angular/router';
import { AppRoutes } from '../../../../routes'; import { AppRoutes } from '../../../../routes';
import { Data } from '../../../models'; import { Data } from '../../../models';
import { Subscription } from 'rxjs';
@Component({ @Component({
selector: 'app-dataset-table-map', selector: 'app-dataset-table-map',
templateUrl: './dataset-table-map.component.html', templateUrl: './dataset-table-map.component.html',
styleUrls: ['./dataset-table-map.component.scss'], styleUrls: ['./dataset-table-map.component.scss'],
}) })
export class DatasetTableMapComponent implements OnInit { export class DatasetTableMapComponent implements OnInit, OnDestroy {
@ViewChild(DatasetMapComponent) datasetMapComponent: DatasetMapComponent; @ViewChild(DatasetMapComponent) datasetMapComponent: DatasetMapComponent;
...@@ -27,6 +28,8 @@ export class DatasetTableMapComponent implements OnInit { ...@@ -27,6 +28,8 @@ export class DatasetTableMapComponent implements OnInit {
selectedData: Data | mapboxgl.MapboxGeoJSONFeature = null; // Contains the properties of the selected feature selectedData: Data | mapboxgl.MapboxGeoJSONFeature = null; // Contains the properties of the selected feature
dataDetailsShouldBeAnimated = false; // Used to prevent animation on first load of the component dataDetailsShouldBeAnimated = false; // Used to prevent animation on first load of the component
subscriptions: Subscription[] = [];
// search // search
searchInput = new FormControl(''); searchInput = new FormControl('');
...@@ -37,16 +40,26 @@ export class DatasetTableMapComponent implements OnInit { ...@@ -37,16 +40,26 @@ export class DatasetTableMapComponent implements OnInit {
) { } ) { }
ngOnInit() { ngOnInit() {
// If the dataset has at least a table or a map then initialize the component this.subscriptions.push(
// else redirect to the info tab // If the dataset has at least a table or a map then initialize the component
if (this.hasTable || this.hasMap) { // else redirect to the info tab
this.properties = this._datasetDetailService.dataset.fields.list; this._datasetDetailService.dataset$.subscribe(() => {
this.selectedProperties = Array.from(this.properties); if (this.hasTable || this.hasMap) {
// Intialize the search value with the value from the service in order to keep it when navigating in tabs this.properties = this._datasetDetailService.dataset.fields.list;
this.searchInput.setValue(this._datasetDetailService.searchString); this.selectedProperties = Array.from(this.properties);
} else { // Intialize the search value with the value from the service in order to keep it when navigating in tabs
this._router.navigate([`./${AppRoutes.info.uri}`], { relativeTo: this._route.parent }); this.searchInput.setValue(this._datasetDetailService.searchString);
} } else {
this._router.navigate([`./${AppRoutes.info.uri}`], { relativeTo: this._route.parent });
}
}),
);
}
ngOnDestroy() {
this.subscriptions.forEach((sub) => {
sub.unsubscribe();
});
} }
get isSample(): boolean { get isSample(): boolean {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment