- add themes.css
- add DatasetService.ts and InternalIdHandler
This commit is contained in:
parent
427b7b9c91
commit
92d0e94582
11 changed files with 327 additions and 39 deletions
|
@ -14,8 +14,9 @@ import { MessageService } from './message.service';
|
|||
import { GeomonPlatform } from '../../shared/models/platform';
|
||||
import { Dataset, GeomonTimeseries } from '../../shared/models/dataset';
|
||||
|
||||
import { deserialize } from 'class-transformer';
|
||||
import { map } from 'rxjs/operators';
|
||||
|
||||
import { InternalIdHandler } from '../../common/components/services/internal-id-handler.service';
|
||||
// @Injectable({
|
||||
// providedIn: 'root'
|
||||
// })
|
||||
|
@ -27,7 +28,8 @@ export class DatasetApiService {
|
|||
constructor(
|
||||
private httpClient: HttpClient,
|
||||
protected httpService: HttpService,
|
||||
private messageService: MessageService) {
|
||||
private messageService: MessageService,
|
||||
protected internalDatasetId: InternalIdHandler,) {
|
||||
}
|
||||
|
||||
public getPhenomena(apiUrl: string, params?: any, options?: any) {
|
||||
|
@ -73,13 +75,24 @@ export class DatasetApiService {
|
|||
|
||||
public getDataset(id: string, apiUrl: string, params?: any, options?: HttpRequestOptions): Observable<GeomonTimeseries> {
|
||||
const url = this.createRequestUrl(apiUrl, 'datasets', id);
|
||||
return this.requestApi<GeomonTimeseries>(url, params, options);
|
||||
//.pipe(
|
||||
// map((res) => this.prepareDataset(res, apiUrl))
|
||||
// );
|
||||
return this.requestApi<GeomonTimeseries>(url, params, options)
|
||||
.pipe(
|
||||
map((res) => this.prepareDataset(res, apiUrl))
|
||||
);
|
||||
}
|
||||
|
||||
//#region Helper method
|
||||
|
||||
private prepareDataset(datasetObj:GeomonTimeseries, apiUrl: string) {
|
||||
let dataset = deserialize<GeomonTimeseries>(GeomonTimeseries, JSON.stringify(datasetObj));
|
||||
dataset.url = apiUrl;
|
||||
this.internalDatasetId.generateInternalId(dataset);
|
||||
// if (dataset.seriesParameters) {
|
||||
// dataset.parameters = dataset.seriesParameters;
|
||||
// delete dataset.seriesParameters;
|
||||
// }
|
||||
return dataset;
|
||||
}
|
||||
|
||||
protected createGeomonPlatform(feature: Station): GeomonPlatform {
|
||||
const datasetIds = [];
|
||||
|
|
70
src/app/services/dataset.service.ts
Normal file
70
src/app/services/dataset.service.ts
Normal file
|
@ -0,0 +1,70 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { EventEmitter } from '@angular/core';
|
||||
|
||||
@Injectable()
|
||||
export class DatasetService<T> {
|
||||
|
||||
public datasetIds: string[] = [];
|
||||
public datasetService: Map<string, T> = new Map();
|
||||
|
||||
public datasetIdsChanged: EventEmitter<string[]> = new EventEmitter();
|
||||
|
||||
/**
|
||||
* Adds the dataset to the selection
|
||||
*
|
||||
* @param internalId
|
||||
* @param [options]
|
||||
* @returns Successfull added the dataset.
|
||||
*/
|
||||
public addDataset(internalId: string, options?: T): boolean {
|
||||
if (this.datasetIds.indexOf(internalId) < 0) {
|
||||
this.datasetIds.push(internalId);
|
||||
// if (options) {
|
||||
// this.datasetOptions.set(internalId, options);
|
||||
// } else {
|
||||
// this.datasetOptions.set(internalId, this.createStyles(internalId));
|
||||
// }
|
||||
// this.saveState();
|
||||
}
|
||||
// else if (options instanceof Array) {
|
||||
// const temp = (this.datasetOptions.get(internalId) as DatasetOptions[]);
|
||||
// options.forEach((e) => temp.push(e));
|
||||
// // this.saveState();
|
||||
// }
|
||||
this.datasetService.set(internalId, options);
|
||||
|
||||
this.datasetIdsChanged.emit(this.datasetIds);
|
||||
return true;
|
||||
}
|
||||
|
||||
public removeAllDatasets() {
|
||||
this.datasetIds.length = 0;
|
||||
this.datasetService.clear();
|
||||
this.datasetIdsChanged.emit(this.datasetIds);
|
||||
// this.saveState();
|
||||
}
|
||||
|
||||
public removeDataset(internalId: string) {
|
||||
const datasetIdx = this.datasetIds.indexOf(internalId);
|
||||
if (datasetIdx > -1) {
|
||||
this.datasetIds.splice(datasetIdx, 1);
|
||||
this.datasetService.delete(internalId);
|
||||
}
|
||||
this.datasetIdsChanged.emit(this.datasetIds);
|
||||
// this.saveState();
|
||||
}
|
||||
|
||||
public hasDatasets(): boolean {
|
||||
return this.datasetIds.length > 0;
|
||||
}
|
||||
|
||||
public hasDataset(id: string): boolean {
|
||||
// return this.datasetIds.indexOf(id) >= 0;
|
||||
return this.datasetService.has(id);
|
||||
}
|
||||
|
||||
public updateDatasetOptions(options: T, internalId: string) {
|
||||
this.datasetService.set(internalId, options);
|
||||
// this.saveState();
|
||||
}
|
||||
}
|
Loading…
Add table
editor.link_modal.header
Reference in a new issue