Skip to content

Commit

Permalink
water-fountains#481 remove operator from Database
Browse files Browse the repository at this point in the history
moreover:
- remove lat/lng and radius from FountainSelector
- only keep `i` and `l` on QueryParams
  • Loading branch information
robstoll committed Dec 10, 2021
1 parent cc55f7a commit ab41ae8
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 82 deletions.
99 changes: 38 additions & 61 deletions src/app/data.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -535,38 +535,22 @@ export class DataService {
selectFountainByFeature(fountain: Fountain): void {
try {
let fountainSelector: FountainSelector;
let what: string | null = null;
const fProps = fountain.properties;
if (fProps['id_wikidata'] !== null && fProps['id_wikidata'] !== 'null') {
fountainSelector = {
queryType: 'byId',
database: 'wikidata',
idval: fProps['id_wikidata'],
};
what = 'wdId-f ' + fProps['id_wikidata'];
} else if (fProps['id_operator'] !== null && fProps['id_operator'] !== 'null') {
fountainSelector = {
queryType: 'byId',
// TODO @ralf.hauser, there was the remark in FountainSelector, that it should either be wikidata or osm
database: 'operator',
idval: fProps['id_operator'],
};
what = 'wdId-op ' + fProps['id_operator'];
} else if (fProps['id_osm'] !== null && fProps['id_osm'] !== 'null') {
fountainSelector = {
queryType: 'byId',
database: 'osm',
idval: fProps['id_osm'],
};
what = 'osmId ' + fProps['id_osm'];
} else {
illegalState('neither id_wikidata nor id_osm on properties defined', fProps);
}
if (!environment.production) {
this.cityService.city.subscribeOnce(city => {
console.log('selectFountainByFeature: ' + what + ' ' + city + ', ' + new Date().toISOString());
});
}
this.selectFountainBySelector(fountainSelector);
} catch (err: unknown) {
console.trace(err);
Expand Down Expand Up @@ -776,7 +760,7 @@ export class DataService {
const cached = this.findCachedFountain(fountainSelector);
// If not forced reload and data cached is complete, then don't call API but use cached fountain instead
if (!forceReload && cached && this.isCachedDataComplete(cached, fountainSelector.idval)) {
this.getCachedFountainDetails(cached, fountainSelector, forceReload);
this.getCachedFountainDetails(cached, fountainSelector);
console.log(
'data.service.ts selectFountainBySelector: got fountain_detail from cache - ' +
fountainSelector.idval +
Expand All @@ -790,7 +774,7 @@ export class DataService {
console.log(
'data.services.ts selectFountainBySelector: selJSON is _currentFountainSelector ' +
selJSON +
'. " updateDatabase ' +
'. " forceReload ' +
forceReload +
' ' +
new Date().toISOString()
Expand All @@ -802,7 +786,7 @@ export class DataService {
selJSON +
'. "' +
err +
'" updateDatabase ' +
'" forceReload ' +
forceReload +
' ' +
new Date().toISOString()
Expand Down Expand Up @@ -883,7 +867,7 @@ export class DataService {
}
}

private getFountainDetailsFromServer(fountainSelector: FountainSelector, updateDatabase: boolean) {
private getFountainDetailsFromServer(fountainSelector: FountainSelector, forceReload: boolean) {
// create parameter string
let params = '';
for (const key in fountainSelector) {
Expand Down Expand Up @@ -935,9 +919,9 @@ export class DataService {
this._currentFountainSelector = undefined;
this.layoutService.switchToDetail(fountain, fountainSelector);

if (updateDatabase) {
if (forceReload) {
console.log(
'data.service.ts selectFountainBySelector: updateDatabase "' +
'data.service.ts selectFountainBySelector: forceReload "' +
nam +
'" ' +
fProps['id_wikidata'].value +
Expand Down Expand Up @@ -1004,14 +988,9 @@ export class DataService {
}

// Get fountain data from local cache.
private getCachedFountainDetails(
fountainData: Fountain,
selectorData: FountainSelector,
checkUpdateDatabase: boolean
): void {
private getCachedFountainDetails(fountainData: Fountain, selectorData: FountainSelector): void {
const fountain = fountainData;
const selector = selectorData;
const updateDatabase = checkUpdateDatabase;
try {
if (fountain !== null) {
const fProps = fountain.properties;
Expand All @@ -1037,54 +1016,52 @@ export class DataService {
this._currentFountainSelector = undefined;
this.layoutService.switchToDetail(fountain, selector);

if (updateDatabase) {
console.log(
'data.service.ts selectFountainBySelector: updateDatabase "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
if (this._fountainPropertiesMeta) {
const fountain_simple = essenceOf(fountain, this._fountainPropertiesMeta);
console.log(
'data.service.ts selectFountainBySelector: essenceOf done "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
if (this.fountainsAll) this._fountainsAll = replaceFountain(this.fountainsAll, fountain_simple);
console.log(
'data.service.ts selectFountainBySelector: replaceFountain done "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
}
this.sortByProximity();
console.log(
'data.service.ts selectFountainBySelector: updateDatabase "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
if (this._fountainPropertiesMeta) {
const fountain_simple = essenceOf(fountain, this._fountainPropertiesMeta);
console.log(
'data.service.ts selectFountainBySelector: sortByProximity done "' +
'data.service.ts selectFountainBySelector: essenceOf done "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
this.filterFountains(this._filter);
if (this.fountainsAll) this._fountainsAll = replaceFountain(this.fountainsAll, fountain_simple);
console.log(
'data.service.ts selectFountainBySelector: filterFountains done "' +
'data.service.ts selectFountainBySelector: replaceFountain done "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
}
this.sortByProximity();
console.log(
'data.service.ts selectFountainBySelector: sortByProximity done "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
this.filterFountains(this._filter);
console.log(
'data.service.ts selectFountainBySelector: filterFountains done "' +
nam +
'" ' +
fProps['id_wikidata'].value +
' ' +
new Date().toISOString()
);
}
} catch (err: unknown) {
console.trace(err);
Expand Down
13 changes: 1 addition & 12 deletions src/app/services/routing.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,8 @@ import { catchError, filter, first } from 'rxjs/operators';
import { MapConfig } from '../map/map.config';

export interface QueryParams {
lang?: string;
l?: string; // short version of lang param for #159
mode?: string;
queryType?: string;
database?: string;
idval?: string;
l?: string;
i?: string; // url for identifiers, for #159
lat?: number;
lng?: number;
onlyOlderThan?: number;
onlyNotable?: boolean;
onlySpringwater?: string;
filterText?: string;
}

@Injectable({
Expand Down
10 changes: 1 addition & 9 deletions src/app/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -277,18 +277,10 @@ export interface FountainProperty {
source_name?: string;
issues?: DataIssue[];
}
// TODO @ralf.hauser, there was the comment here that it should either be wikidata or osm, but operator is defined in route-validator.service.ts
export type Database = SourceType | 'operator'; // name of database for which the id is provided

export function isDatabase(s: string): s is Database {
return s === 'wikidata' || s === 'osm' || s === 'operator';
}
export type Database = SourceType;

export interface FountainSelector {
queryType: 'byId';
lat?: number;
lng?: number;
radius?: number;
database?: Database;
idval?: string;
}

0 comments on commit ab41ae8

Please sign in to comment.