From e911180535be5c2f2e2194e3a26bbac81e870dff Mon Sep 17 00:00:00 2001 From: AtomicNicos Date: Sun, 26 Apr 2020 21:41:26 +0200 Subject: [PATCH] i18n services/map --- src/app/community/community.component.html | 7 +-- src/app/maps/maps.component.css | 27 ++++++++++ src/app/maps/maps.component.html | 27 ++++++---- src/app/maps/maps.component.ts | 19 ++++--- src/app/services/firebase-data.service.ts | 16 ++++++ src/app/services/geocode.service.ts | 63 +++++++++++----------- src/assets/i18n/de.json | 4 +- src/assets/i18n/en.json | 4 +- src/assets/i18n/fr.json | 4 +- src/assets/i18n/it.json | 4 +- 10 files changed, 119 insertions(+), 56 deletions(-) diff --git a/src/app/community/community.component.html b/src/app/community/community.component.html index 3bf70cd..4bb3ed2 100644 --- a/src/app/community/community.component.html +++ b/src/app/community/community.component.html @@ -14,8 +14,9 @@ alt="user" width="50" class="rounded-circle">
-
{{ user }}
{{time | date:"yyyy-MM-dd"}} +
{{ user }}
+ + {{time | date:"yyyy-MM-dd"}}

{{ message }}

@@ -105,4 +106,4 @@ - \ No newline at end of file + diff --git a/src/app/maps/maps.component.css b/src/app/maps/maps.component.css index a8de609..258a085 100644 --- a/src/app/maps/maps.component.css +++ b/src/app/maps/maps.component.css @@ -10,3 +10,30 @@ agm-map { width: 100%; background-color: lightblue; } + +.description { + width: 100%; + background-color: lightgreen +} + +.content-header { + background-color: gray; + padding: 20px 0px 10px 0px; + align-items: middle; + font-size: 18pt; +} + +.content-grid { + display: grid; + grid-template-columns: repeat(3, 1fr); +} + +.content-grid > * { + padding: 5px; + background-color: whitesmoke; + border-radius: 5px; +} + +.content-grid > * > p { + word-wrap: break-word; +} diff --git a/src/app/maps/maps.component.html b/src/app/maps/maps.component.html index 8bbfc62..50c5c80 100644 --- a/src/app/maps/maps.component.html +++ b/src/app/maps/maps.component.html @@ -21,19 +21,28 @@ {{ place.address }}
{{ place.postalCode }}
{{ place.city }}
- MAP.WEBSITE - -
- {{ 'MAP.WHO' | translate }} :
- {{ place.type }}
-

- + MAP.WEBSITE
+ {{ place.tel }}
+ {{ 'MAP.WHO' | translate }} : {{ place.type }}
-
-

{{d.name}}
{{d.address}}
{{d.postal_code}} {{ d.city }}
{{ d.tel }}
{{ d.website }}

+
+

{{t.key}}

+

MAP.UNCATEGORIZED

+
+
+

+ {{d.name}}
+ {{d.address}}
+ {{d.postalCode}} {{ d.city }}
+ {{ d.tel }}
+ MAP.WEBSITE
+ {{ 'MAP.DESCRIPTION' | translate }} : {{ d.description }}
+

+
+
diff --git a/src/app/maps/maps.component.ts b/src/app/maps/maps.component.ts index 133662f..feb31c3 100644 --- a/src/app/maps/maps.component.ts +++ b/src/app/maps/maps.component.ts @@ -7,7 +7,6 @@ import { TranslateService } from '@ngx-translate/core'; import { FirebaseDataService } from '../services/firebase-data.service'; import { MapPoint } from '../interfaces/map-point'; - @Component({ selector: 'app-maps', templateUrl: './maps.component.html', @@ -20,8 +19,10 @@ export class MapsComponent implements OnInit { cantonCenter: Location = { lat: 46.9479222, lng: 7.4446085 }; translate: TranslateService; + typeMap: {}; + cantonSelected = ''; - cantons = this.firebase.getCantons(); + cantons = this.firebaseDB.getCantons(); cantonData: MapPoint[] = []; regex: RegExp = /\(([^()]*)\)/g; @@ -30,7 +31,7 @@ export class MapsComponent implements OnInit { private geocodeService: GeocodeService, private ref: ChangeDetectorRef, public lang: LangService, - private firebase: FirebaseDataService) { + private firebaseDB: FirebaseDataService) { this.translate = lang.getTranslateService(); this.mapsAPI.load().then(() => { }); } @@ -42,9 +43,9 @@ export class MapsComponent implements OnInit { this.cantonCenter = location; } else { const point: MapPoint = this.cantonData.filter((e) => e.address == address && e.city == city && e.postalCode == cp)[0]; - // Update db point.latitude = '' + location.lat; point.longitude = '' + location.lng; + this.firebaseDB.updatePoint(point); } this.ref.detectChanges(); } @@ -60,7 +61,6 @@ export class MapsComponent implements OnInit { (e: MapPoint) => e.address !== '' && e.postalCode !== '' && e.city !== '' && e.latitude === '' && e.longitude === '' ).forEach((e: MapPoint) => { this.getLocation(e.address, e.postalCode, e.city, false); - console.log(e); }); } else { this.centersFound = false; @@ -71,8 +71,13 @@ export class MapsComponent implements OnInit { this.cantonSelected = this.cantons[value]; if (this.cantonSelected.match(this.regex) !== null) { const abbr = this.cantonSelected.match(this.regex)[0].substring(1, 3); - this.cantonData = await this.firebase.getCantonData(abbr); - console.log(this.cantonSelected, this.cantonData); + this.cantonData = await this.firebaseDB.getCantonData(abbr); + this.typeMap = {}; + for (const t of this.cantonData) { + (!(t.type in this.typeMap)) ? this.typeMap[t.type] = [] : null; + this.typeMap[t.type].push(t); + } + console.log(this.typeMap); } this.getPosition(); } diff --git a/src/app/services/firebase-data.service.ts b/src/app/services/firebase-data.service.ts index 34ef318..51cae1a 100644 --- a/src/app/services/firebase-data.service.ts +++ b/src/app/services/firebase-data.service.ts @@ -28,4 +28,20 @@ export class FirebaseDataService { return results; } + + async updatePoint(point: MapPoint) { + const ref = this.firebaseDB.database.ref('data/safe-spaces'); + ref.orderByChild('name') + .equalTo(point.name) + .orderByChild('address') + .equalTo(point.address) + .orderByChild('postalCode') + .equalTo(point.postalCode) + .once('value', (snapshot: firebase.database.DataSnapshot) => { + snapshot.forEach((s) => { + s.ref.update({ latitude: parseFloat(point.latitude), longitude: parseFloat(point.longitude) }); + }); + } + ); + } } diff --git a/src/app/services/geocode.service.ts b/src/app/services/geocode.service.ts index 83ee1fb..2aa6de6 100644 --- a/src/app/services/geocode.service.ts +++ b/src/app/services/geocode.service.ts @@ -9,44 +9,41 @@ declare var google: any; @Injectable() export class GeocodeService { private geocoder: any; - + constructor(private mapLoader: MapsAPILoader) {} - + private initGeocoder() { - console.log('Init geocoder!'); this.geocoder = new google.maps.Geocoder(); } - + private waitForMapsToLoad(): Observable { - if(!this.geocoder) { + if (!this.geocoder) { return from(this.mapLoader.load()) - .pipe( - tap(() => this.initGeocoder()), - map(() => true) + .pipe( + tap(() => this.initGeocoder()), + map(() => true) ); - } - return of(true); } - - geocodeAddress(location: string): Observable { - console.log('Start geocoding!'); - return this.waitForMapsToLoad().pipe( - switchMap(() => { - return new Observable(observer => { - this.geocoder.geocode({'address': location}, (results, status) => { - if (status == google.maps.GeocoderStatus.OK) { - console.log('Geocoding complete!'); - observer.next({ - lat: results[0].geometry.location.lat(), - lng: results[0].geometry.location.lng() - }); - } else { - console.log('Error - ', results, ' & Status - ', status); - observer.next({lat: 0, lng: 0}); - } - }); - }) - }) - )} - - } \ No newline at end of file + return of(true); + } + + geocodeAddress(location: string): Observable { + return this.waitForMapsToLoad().pipe( + switchMap(() => { + return new Observable(observer => { + this.geocoder.geocode({ address: location }, (results, status) => { + if (status == google.maps.GeocoderStatus.OK) { + observer.next({ + lat: results[0].geometry.location.lat(), + lng: results[0].geometry.location.lng() + }); + } else { + console.log('Error - ', results, ' & Status - ', status); + observer.next({lat: 0, lng: 0}); + } + }); + }); + }) + ); + } +} diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index c929801..1ac1d96 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -54,7 +54,9 @@ "CANTONOF": "Kanton", "SORRY": "Es tut uns leid, aber diese Seite ist eine Demo. Die Daten f\u00fcr diesen Kanton k\u00f6nnen nicht geladen werden", "WEBSITE": "Webseite", - "WHO": "Für wen" + "WHO": "Für wen", + "DESCRIPTION": "Beschreibung", + "UNCATEGORIZED": "Unkategorisiert" }, "FILES": { "TEST": "test.png" diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index 2bcb270..d0c4fb7 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -54,7 +54,9 @@ "CANTONOF": "Canton of", "SORRY": "Sorry, this site is a demo. The data for your canton could not be loaded.", "WEBSITE": "Website", - "WHO": "Who for" + "WHO": "Who for", + "DESCRIPTION": "Description", + "UNCATEGORIZED": "Uncategorized" }, "FILES": { "TEST": "test.png" diff --git a/src/assets/i18n/fr.json b/src/assets/i18n/fr.json index a09cde9..f44dcfa 100644 --- a/src/assets/i18n/fr.json +++ b/src/assets/i18n/fr.json @@ -54,7 +54,9 @@ "CANTONOF": "Canton de", "SORRY": "Nous sommes d\u00e9sol\u00e9s, ce site est une d\u00e9mo. Nous n'avons pas encore pu charger les donn\u00e9es de votre canton.", "WEBSITE": "Site Web", - "WHO": "Pour qui" + "WHO": "Pour qui", + "DESCRIPTION": "Description", + "UNCATEGORIZED": "Non class\u00e9" }, "FILES": { "TEST": "test.png" diff --git a/src/assets/i18n/it.json b/src/assets/i18n/it.json index 2f84c88..98a0cf0 100644 --- a/src/assets/i18n/it.json +++ b/src/assets/i18n/it.json @@ -54,7 +54,9 @@ "CANTONOF": "Cantone di", "SORRY": "Siamo spiacenti, questo sito \u00e9 una demo. Non siamo stati in grado di caricare i dati del tuo cantone", "WEBSITE": "Sito Internet", - "WHO": "Per chi" + "WHO": "Per chi", + "DESCRIPTION": "Descrizione", + "UNCATEGORIZED": "Senza categoria" }, "FILES": { "TEST": "test.png" -- GitLab