diff --git a/src/app/interfaces/map-point.ts b/src/app/interfaces/map-point.ts new file mode 100644 index 0000000000000000000000000000000000000000..d78031161b14bb057131949e3430650fd51d3050 --- /dev/null +++ b/src/app/interfaces/map-point.ts @@ -0,0 +1,14 @@ +export interface MapPoint { + name: string; + address: string; + postalCode: string; + city: string; + canton: string; + description: string; + tel: string; + email: string; + type: string; + website: string; + longitude: string; + latitude: string; +} diff --git a/src/app/json-typings.d.ts b/src/app/json-typings.d.ts index 1056388336d1945aa985d08d74f8e208c697f22b..f3f59664185ae35b78f4014d89a7a4e8f77e9390 100644 --- a/src/app/json-typings.d.ts +++ b/src/app/json-typings.d.ts @@ -1,4 +1,4 @@ declare module "*.json" { - const value: any; - export default value; - } \ No newline at end of file + const value: any; + export default value; +} diff --git a/src/app/maps/maps.component.css b/src/app/maps/maps.component.css index ebda8792c6875bae5594f6cadbed63d9c8b01fee..a8de609d1cd490bff1c90586923834439216be86 100644 --- a/src/app/maps/maps.component.css +++ b/src/app/maps/maps.component.css @@ -5,3 +5,8 @@ agm-map { height: 50vh; } + +.target { + width: 100%; + background-color: lightblue; +} diff --git a/src/app/maps/maps.component.html b/src/app/maps/maps.component.html index 8cb3520768dff6a59712c802d35170b85f2e38bf..8bbfc62c6b5044a809d83de0f9a93393017c4fb5 100644 --- a/src/app/maps/maps.component.html +++ b/src/app/maps/maps.component.html @@ -14,12 +14,20 @@ [disableDefaultUI]="false" [zoomControl]="false"> + [latitude]="place.latitude" + [longitude]="place.longitude"> - {{ place.name }}
- {{ place.address }}
- {{ place.website }} + {{ place.name }}
+ {{ place.address }}
+ {{ place.postalCode }}
+ {{ place.city }}
+ MAP.WEBSITE + +
+ {{ 'MAP.WHO' | translate }} :
+ {{ place.type }}
+

+
diff --git a/src/app/maps/maps.component.ts b/src/app/maps/maps.component.ts index 217759c066835fd4f45fb225919494083f1e4b99..133662f1ec98d951af017ea85761a6aeb39b1eb2 100644 --- a/src/app/maps/maps.component.ts +++ b/src/app/maps/maps.component.ts @@ -4,6 +4,9 @@ import { GeocodeService } from '../services/geocode.service'; import { Location } from '../services/location-representation'; import { LangService } from '../services/lang.service'; import { TranslateService } from '@ngx-translate/core'; +import { FirebaseDataService } from '../services/firebase-data.service'; +import { MapPoint } from '../interfaces/map-point'; + @Component({ selector: 'app-maps', @@ -11,62 +14,65 @@ import { TranslateService } from '@ngx-translate/core'; styleUrls: ['./maps.component.css'] }) export class MapsComponent implements OnInit { - address = 'London'; location: Location; centersFound = false; geocoder: any; - cantonCenter: Location = {lng: 7.4446085, lat: 46.9479222}; + cantonCenter: Location = { lat: 46.9479222, lng: 7.4446085 }; translate: TranslateService; cantonSelected = ''; - cantons = ['Argovie (AG)', 'Appenzell Rhodes-Intérieures (AI)', 'Appenzell Rhodes-Extérieures (AR)', 'Berne (BE)', 'Bâle-Campagne (BL)', 'Bâle-Ville (BS)', 'Fribourg (FR)', 'Genève (GE)', 'Glaris (GL)', 'Grisons (GR)', 'Jura (JU)', 'Lucerne (LU)', 'Neuchâtel (NE)', 'Nidwald (NW)', 'Obwald (OW)', 'Saint-Gall (SG)', 'Schaffhouse (SH)', 'Soleure (SO)', 'Schwytz (SZ)', 'Thurgovie (TG)', 'Tessin (TI)', 'Uri (UR)', 'Vaud (VD)', 'Valais (VS)', 'Zoug (ZG)', 'Zurich (ZH)'] - cantons_total_data = {"VD": [{"name": "Bureau d'information Femmes - BIF", "address": "Eglantine 6", "city": "Lausanne", "postal_code": 1006, "tel": "021 320 04 04", "website": "www.bif-vd.ch", "description": "Lieu d'écoute, accueil sans rendez-vous, gratuit et confidentialité garantie"}, {"name": "Les centres LAVI", "address": "Rue du Grand-Pont 2bis", "city": "Lausanne", "postal_code": 1003, "tel": "021 631 03 00", "website": "http://www.profa.ch/services-2/centre-lavi/#1525268514379-f98f76dd-1965", "description": "Centre d'aide aux victimes d'agressions violentes"}, {"name": "Les centres LAVI", "address": "Rue de la Plaine 2", "city": "Yverdon-les-Bains", "postal_code": 1400, "tel": "021 631 03 08", "website": "http://www.profa.ch/services-2/centre-lavi/#1525268514379-f98f76dd-1965", "description": "Centre d'aide aux victimes d'agressions violentes"}, {"name": "Les centres LAVI", "address": "Rue du Molage 36", "city": "Aigle", "postal_code": 1860, "tel": "021 631 03 04", "website": "http://www.profa.ch/services-2/centre-lavi/#1525268514379-f98f76dd-1965", "description": "Centre d'aide aux victimes d'agressions violentes"}, {"name": "Regional Social Center (CSR)", "address": "Place Chauderon 4", "city": "Lausanne", "postal_code": 1002, "tel": "021 316 52 21", "website": "https://www.vaudfamille.ch/N1320/lausanne-csr-centre-social-regional.html", "description": "Le CSR traite les problématiques suivantes: Allocation du Revenu d'Insertion; Mesures de réinsertion sociale; Appui social pour les personnes rencontrant toute forme de difficultés; Soutien et aide en cas de difficultés familiales, sociales, financiéres et de logement"}, {"name": "ProJuventute", "address": "Place Chauderon 24", "city": "Lausanne", "postal_code": 1003, "tel": "021 622 08 17", "website": "https://pj.projuventute.ch/index.php?id=3916&L=1", "description": "Fond de soutien aux famille - aide individuelle"}, {"name": "Centre d'accueil MalleyPrairie", "address": "Chemin de la Prairie 34", "city": "Lausanne", "postal_code": 1007, "tel": "021 620 76 76", "website": "https://malleyprairie.ch/", "description": "Pour les femmes et les hommes victimes de violences conjugales ou familiales"}, {"name": "Association avocats ressources en matiére de violence domistique", "address": "Rue de Bourg 47-49", "city": "Lausanne", "postal_code": 1002, "tel": "021 317 50 81", "website": "https://arvd.ch/", "description": "Réunir les avocats sensibilisés \u00e0 la problématique afin d'offrir un conseil et un soutien jurdique aux personnes concernées par la violence domestique"}, {"name": "Unité de médicine des violences (UMV) CHUV", "address": "Rue du Bugnon 44", "city": "Lausanne", "postal_code": 1011, "tel": "021 314 00 60", "website": "https://www.curml.ch/node/16", "description": "Consultation médico-légale pour adultes victimes de violences"}, {"name": "Unité de médicine des violences (UMV) l'Hopital d'Yverdon-les-Bains", "address": "Rue d'Entremonts 11", "city": "Yverdon-les-Bains", "postal_code": 1400, "tel": "024 424 42 20", "website": "https://www.curml.ch/node/16", "description": "Consultation médico-légale pour adultes victimes de violences"}, {"name": "Unité de médicine des violences (UMV) l'Hopital Riviera-Chablais", "address": "Route du Vieux-Séquola 20", "city": "Rennaz", "postal_code": 1847, "tel": "058 773 64 77", "website": "https://www.curml.ch/node/16", "description": "Consultation médico-légale pour adultes victimes de violences"}, {"name": "Unité de médicine des violence (UMV) Nyon", "address": "Avenue Reverdil 8", "city": "Nyon", "postal_code": 1260, "tel": "021 314 08 51", "website": "https://www.curml.ch/node/16", "description": "Consultation médico-légale pour adultes victimes de violences"}]} - - cantonData = []; - regex = /\(([^()]*)\)/g; + cantons = this.firebase.getCantons(); - locationData = []; + cantonData: MapPoint[] = []; + regex: RegExp = /\(([^()]*)\)/g; constructor(public mapsAPI: MapsAPILoader, private geocodeService: GeocodeService, private ref: ChangeDetectorRef, - public lang: LangService) { + public lang: LangService, + private firebase: FirebaseDataService) { this.translate = lang.getTranslateService(); - this.mapsAPI = mapsAPI; this.mapsAPI.load().then(() => { }); } getLocation(address: string, cp: string, city: string, isCanton: boolean) { this.geocodeService.geocodeAddress(address + ' ' + cp + ' ' + city) .subscribe((location: Location) => { - if (isCanton) - this.cantonCenter = location; - else - this.cantonData.filter((e) => e.address == address && e.city == city && e.code_postal == cp)[0].location = location; - this.ref.detectChanges(); + if (isCanton) { + 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.ref.detectChanges(); + } + ); } getPosition() { - this.locationData = []; - this.getLocation('Canton of ' + this.cantonSelected, '', '', true); + this.getLocation('Canton of ' + this.cantonSelected, '', '', true); - if (this.cantonData !== undefined) { - this.centersFound = true; - this.cantonData.forEach((e) => { - this.getLocation(e.address, e.code_postal, e.city, false); - console.log(e); - }); - } else - this.centersFound = false; + if (this.cantonData !== undefined) { + this.centersFound = true; + this.cantonData.filter( + (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; + } } - onSelect(value) { + async onSelect(value: string) { 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 = this.cantons_total_data[abbr]; + this.cantonData = await this.firebase.getCantonData(abbr); + console.log(this.cantonSelected, this.cantonData); } this.getPosition(); } diff --git a/src/app/services/firebase-auth.service.ts b/src/app/services/firebase-auth.service.ts index 00ec1dbd240d601dcca0f0ffa92d7941e4a768cb..c33bfdb85fe311fca91d1c8110619f3d98347b71 100644 --- a/src/app/services/firebase-auth.service.ts +++ b/src/app/services/firebase-auth.service.ts @@ -1,6 +1,5 @@ import { Injectable } from '@angular/core'; - -import * as firebase from 'firebase'; +import { AngularFireAuth } from '@angular/fire/auth'; @Injectable({ providedIn: 'root' @@ -9,7 +8,7 @@ export class FirebaseAuthService { createNewUser(email: string, password: string) { return new Promise( (resolve, reject) => { - firebase.auth().createUserWithEmailAndPassword(email, password).then( + this.firebaseAuth.createUserWithEmailAndPassword(email, password).then( () => { resolve(); }, @@ -24,7 +23,7 @@ export class FirebaseAuthService { signInUser(email: string, password: string) { return new Promise( (resolve, reject) => { - firebase.auth().signInWithEmailAndPassword(email, password).then( + this.firebaseAuth.signInWithEmailAndPassword(email, password).then( () => { resolve(); }, @@ -37,8 +36,12 @@ export class FirebaseAuthService { } signOutUser() { - firebase.auth().signOut(); + this.firebaseAuth.signOut(); + } + + getUser(): Promise { + return this.firebaseAuth.currentUser; } - constructor() { } + constructor(private firebaseAuth: AngularFireAuth) { } } diff --git a/src/app/services/firebase-data.service.spec.ts b/src/app/services/firebase-data.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..afdfe8fcbbbd4109e62fa0b5de4431dc38613229 --- /dev/null +++ b/src/app/services/firebase-data.service.spec.ts @@ -0,0 +1,16 @@ +import { TestBed } from '@angular/core/testing'; + +import { FirebaseDataService } from './firebase-data.service'; + +describe('FirebaseDataService', () => { + let service: FirebaseDataService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(FirebaseDataService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/firebase-data.service.ts b/src/app/services/firebase-data.service.ts new file mode 100644 index 0000000000000000000000000000000000000000..34ef318c055aee6f0a850efb49add37d7cde3313 --- /dev/null +++ b/src/app/services/firebase-data.service.ts @@ -0,0 +1,31 @@ +import { Injectable } from '@angular/core'; +import { AngularFireDatabase } from '@angular/fire/database'; +import { MapPoint } from '../interfaces/map-point'; +import * as sampleData from '../../assets/maps/cantons.json'; + +@Injectable({ + providedIn: 'root' +}) +export class FirebaseDataService { + constructor(protected firebaseDB: AngularFireDatabase) { } + regex: RegExp = /\(([^()]*)\)/g; + + getCantons(): string[] { + return (sampleData as any).default; + } + + async getCantonData(canton: string): Promise { + let results: MapPoint[] = []; + await new Promise((resolve, reject) => + this.firebaseDB.list('/data/safe-spaces/').valueChanges().subscribe((v: MapPoint[]) => + (v.length > 0) ? resolve(v) : reject({ error: 'No results '}) + ) + ).then((v: MapPoint[]) => + results = v.filter((mp: MapPoint) => mp.canton === canton) + ).catch((reason) => + console.log(reason) + ); + + return results; + } +} diff --git a/src/app/services/lang.service.ts b/src/app/services/lang.service.ts index 5d6f9683d07128a0c150892fcb13faedbca31a74..2c4819773c39185950402758f2b84f95b20c8430 100644 --- a/src/app/services/lang.service.ts +++ b/src/app/services/lang.service.ts @@ -1,7 +1,6 @@ import { Injectable } from '@angular/core'; import { TranslateService } from '@ngx-translate/core'; -import { Subject, BehaviorSubject, Observable } from 'rxjs'; @Injectable({ providedIn: 'root' diff --git a/src/app/services/location-representation.ts b/src/app/services/location-representation.ts index f6a16ce60cccc4041b3f6a1c1cc9feb24baa3f96..c82fe31c4d36eb731077c7e9ac76c994d5839b59 100644 --- a/src/app/services/location-representation.ts +++ b/src/app/services/location-representation.ts @@ -1,4 +1,4 @@ export interface Location { - lat: number; + lat: number; lng: number; - } \ No newline at end of file + } diff --git a/src/assets/i18n/de.json b/src/assets/i18n/de.json index 4fb465fa658abb5af2abe28145be590468b4b3dd..c9298017c0851a24169280d9267650ad1c464c4e 100644 --- a/src/assets/i18n/de.json +++ b/src/assets/i18n/de.json @@ -52,7 +52,9 @@ }, "MAP": { "CANTONOF": "Kanton", - "SORRY": "Es tut uns leid, aber diese Seite ist eine Demo. Die Daten f\u00fcr diesen Kanton k\u00f6nnen nicht geladen werden" + "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" }, "FILES": { "TEST": "test.png" diff --git a/src/assets/i18n/en.json b/src/assets/i18n/en.json index c0aab1ac9ef3ebd91d4ef157eba08012a6105f26..2bcb270cf9dec069660ae40e82fbab1553f7810f 100644 --- a/src/assets/i18n/en.json +++ b/src/assets/i18n/en.json @@ -52,7 +52,9 @@ }, "MAP": { "CANTONOF": "Canton of", - "SORRY": "Sorry, this site is a demo. The data for your canton could not be loaded." + "SORRY": "Sorry, this site is a demo. The data for your canton could not be loaded.", + "WEBSITE": "Website", + "WHO": "Who for" }, "FILES": { "TEST": "test.png" diff --git a/src/assets/i18n/fr.json b/src/assets/i18n/fr.json index d71bbeb6114192fe145650b49a949bfec3e45161..a09cde9440c7c2109499afe35def24edd78613de 100644 --- a/src/assets/i18n/fr.json +++ b/src/assets/i18n/fr.json @@ -52,7 +52,9 @@ }, "MAP": { "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." + "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" }, "FILES": { "TEST": "test.png" diff --git a/src/assets/i18n/it.json b/src/assets/i18n/it.json index 914194ffe79d819cfdd9f50d5288537f72e427ec..2f84c883b14f57dbd9183d7c415ac7be96eb7ded 100644 --- a/src/assets/i18n/it.json +++ b/src/assets/i18n/it.json @@ -52,7 +52,9 @@ }, "MAP": { "CANTONOF": "Cantone di", - "SORRY": "Siamo spiacenti, questo sito \u00e9 una demo. Non siamo stati in grado di caricare i dati del tuo cantone" + "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" }, "FILES": { "TEST": "test.png"