🐛 Fix add & register modal openning
continuous-integration/drone/push Build is passing Details

master
Alexis Feron 4 days ago
parent a4f9ae6e0d
commit 3c6bf958c1

@ -1,12 +1,3 @@
<!-- Modal toggle -->
<button
(click)="openPinModal()"
class="block py-2 text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300"
type="button"
>
<p *ngIf="!isHomePage">Ajouter un pin</p>
</button>
<!-- Fond assombri --> <!-- Fond assombri -->
<div <div
class="fixed inset-0 bg-gray-900 bg-opacity-50 w-full h-full transition-opacity duration-300 ease-in-out z-40" class="fixed inset-0 bg-gray-900 bg-opacity-50 w-full h-full transition-opacity duration-300 ease-in-out z-40"

@ -1,10 +1,5 @@
import { CommonModule } from '@angular/common'; import { CommonModule } from '@angular/common';
import { import { Component, Input, OnInit, ViewChild } from '@angular/core';
Component,
Input,
OnInit,
ViewChild,
} from '@angular/core';
import { import {
FormBuilder, FormBuilder,
FormControl, FormControl,
@ -55,8 +50,14 @@ export class AddPinPopupComponent implements OnInit {
private imageService: ImageService private imageService: ImageService
) { ) {
this.form = this.fb.group({ this.form = this.fb.group({
title: new FormControl('', [Validators.required, Validators.minLength(3)]), title: new FormControl('', [
description: new FormControl('', [Validators.required, Validators.minLength(3)]), Validators.required,
Validators.minLength(3),
]),
description: new FormControl('', [
Validators.required,
Validators.minLength(3),
]),
location: new FormControl('', [Validators.required]), location: new FormControl('', [Validators.required]),
complete_address: new FormControl('', [Validators.required]), complete_address: new FormControl('', [Validators.required]),
coordinates: new FormControl<number[]>([]), coordinates: new FormControl<number[]>([]),
@ -109,7 +110,7 @@ export class AddPinPopupComponent implements OnInit {
debounceTime(200), // Attendre 200ms après la dernière frappe debounceTime(200), // Attendre 200ms après la dernière frappe
distinctUntilChanged(), // Ignorer si la nouvelle valeur est la même que la précédente distinctUntilChanged(), // Ignorer si la nouvelle valeur est la même que la précédente
switchMap((query) => { switchMap((query) => {
if(query === null) { if (query === null) {
return of([]); return of([]);
} }
const trimmedQuery = query.trim(); const trimmedQuery = query.trim();
@ -154,11 +155,17 @@ export class AddPinPopupComponent implements OnInit {
try { try {
const data = await this.exifService.getLocation(files[0]); const data = await this.exifService.getLocation(files[0]);
if (data.latitude !== undefined && data.longitude !== undefined) { if (data.latitude !== undefined && data.longitude !== undefined) {
this.autocompleteService.getAddressFromCoordinates(data.latitude, data.longitude).subscribe((address) => { this.autocompleteService
.getAddressFromCoordinates(data.latitude, data.longitude)
.subscribe((address) => {
if (address) { if (address) {
this.form.get('location')?.setValue(address.display_name); this.form.get('location')?.setValue(address.display_name);
this.form.get('complete_address')?.setValue(address.display_name); this.form
this.form.get('coordinates')?.setValue([data.latitude, data.longitude]); .get('complete_address')
?.setValue(address.display_name);
this.form
.get('coordinates')
?.setValue([data.latitude, data.longitude]);
} }
}); });
} }
@ -178,14 +185,15 @@ export class AddPinPopupComponent implements OnInit {
async submitForm(): Promise<void> { async submitForm(): Promise<void> {
// Marquer tous les champs comme touched pour afficher les erreurs // Marquer tous les champs comme touched pour afficher les erreurs
Object.keys(this.form.controls).forEach(key => { Object.keys(this.form.controls).forEach((key) => {
const control = this.form.get(key); const control = this.form.get(key);
control?.markAsTouched(); control?.markAsTouched();
}); });
if (this.form.valid) { if (this.form.valid) {
const uploadObservables = await Promise.all(this.files.map(async (file) => { const uploadObservables = await Promise.all(
if(file.size === 0) { this.files.map(async (file) => {
if (file.size === 0) {
this.uploadError = file.name + ' : ' + 'Image vide'; this.uploadError = file.name + ' : ' + 'Image vide';
return of(null); return of(null);
} }
@ -193,19 +201,22 @@ export class AddPinPopupComponent implements OnInit {
const pictureExifDate = await this.exifService.getDateTime(file); const pictureExifDate = await this.exifService.getDateTime(file);
return this.imageService.postImage(file, pictureExifDate).pipe( return this.imageService.postImage(file, pictureExifDate).pipe(
catchError(error => { catchError((error) => {
this.uploadError = file.name + ' : ' + error.error.detail || 'Erreur lors de l\'upload de l\'image'; this.uploadError =
file.name + ' : ' + error.error.detail ||
"Erreur lors de l'upload de l'image";
if (this.dragDropComponent) { if (this.dragDropComponent) {
this.dragDropComponent.errorMessage = this.uploadError; this.dragDropComponent.errorMessage = this.uploadError;
} }
return of(null); return of(null);
}) })
) );
})); })
);
forkJoin(uploadObservables).subscribe((responses) => { forkJoin(uploadObservables).subscribe((responses) => {
// Vérifier si toutes les réponses sont valides // Vérifier si toutes les réponses sont valides
if (responses.some(response => response === null)) { if (responses.some((response) => response === null)) {
return; // Ne pas continuer si une erreur s'est produite return; // Ne pas continuer si une erreur s'est produite
} }
@ -217,7 +228,9 @@ export class AddPinPopupComponent implements OnInit {
files: this.files, files: this.files,
date: this.form.get('date')?.value || null, date: this.form.get('date')?.value || null,
location: coordinates || [0, 0], // Utiliser les coordonnées pour location location: coordinates || [0, 0], // Utiliser les coordonnées pour location
complete_address: this.form.get('complete_address')?.value || this.form.get('location')?.value, complete_address:
this.form.get('complete_address')?.value ||
this.form.get('location')?.value,
}; };
// Supprimer le champ coordinates qui n'est pas dans le modèle Pin // Supprimer le champ coordinates qui n'est pas dans le modèle Pin
@ -236,17 +249,15 @@ export class AddPinPopupComponent implements OnInit {
} }
} }
openPinModal() {
this.modalService.openModal(this.modalId);
}
closePinModal() { closePinModal() {
this.modalService.closeModal(this.modalId); this.modalService.closeModal(this.modalId);
this.form.reset(); this.form.reset();
this.files = []; this.files = [];
this.uploadError = ''; this.uploadError = '';
if (this.dragDropComponent) { if (this.dragDropComponent) {
this.dragDropComponent.updateFileNamesFromFileList(new DataTransfer().files); this.dragDropComponent.updateFileNamesFromFileList(
new DataTransfer().files
);
this.dragDropComponent.errorMessage = ''; this.dragDropComponent.errorMessage = '';
} }
} }

@ -1,5 +1,6 @@
<nav class="bg-white border-gray-200 dark:bg-gray-900"> <nav class="bg-white border-gray-200 dark:bg-gray-900">
<app-login-page></app-login-page> <app-login-page></app-login-page>
<app-register-page></app-register-page>
<div <div
class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4" class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-4"
> >
@ -79,7 +80,13 @@
class="block text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300" class="block text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300"
> >
<span> <span>
<app-register-page></app-register-page> <button
(click)="openRegisterModal()"
class="block py-2 text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300"
type="button"
>
Inscription
</button>
</span> </span>
</a> </a>
</li> </li>

@ -16,4 +16,8 @@ export class HomeNavbarComponent {
openLoginModal() { openLoginModal() {
this.modalService.openModal('login-modal'); this.modalService.openModal('login-modal');
} }
openRegisterModal() {
this.modalService.openModal('register-modal');
}
} }

@ -12,11 +12,11 @@ import * as L from 'leaflet';
import 'leaflet.markercluster'; import 'leaflet.markercluster';
import { Pin } from '../../model/Pin'; import { Pin } from '../../model/Pin';
import { AutocompleteService } from '../../services/auto-complete/auto-complete.service'; import { AutocompleteService } from '../../services/auto-complete/auto-complete.service';
import { IntroService } from '../../services/intro/intro.service';
import { MapReloadService } from '../../services/map-reload/map-reload.service'; import { MapReloadService } from '../../services/map-reload/map-reload.service';
import { ModalService } from '../../services/modal/modal.service'; import { ModalService } from '../../services/modal/modal.service';
import { PinService } from '../../services/pin/pin.service'; import { PinService } from '../../services/pin/pin.service';
import { PinMarkerComponent } from '../pin-marker/pin-marker.component'; import { PinMarkerComponent } from '../pin-marker/pin-marker.component';
import { IntroService } from '../../services/intro/intro.service';
@Component({ @Component({
selector: 'app-leaflet-map', selector: 'app-leaflet-map',
@ -60,7 +60,7 @@ export class LeafletMapComponent implements OnInit {
}); });
this.route.params.subscribe((params) => { this.route.params.subscribe((params) => {
if(params['tutorial'] === "true") { if (params['tutorial'] === 'true') {
this.introService.startIntro(); this.introService.startIntro();
} }
}); });
@ -222,6 +222,7 @@ export class LeafletMapComponent implements OnInit {
// Pour chaque pin, récupérer ses partages // Pour chaque pin, récupérer ses partages
pins.forEach((pin) => { pins.forEach((pin) => {
if (!pin.is_poi) {
this.pinsService.getPinShares(pin.id).subscribe((response: any) => { this.pinsService.getPinShares(pin.id).subscribe((response: any) => {
if (response && response.shares) { if (response && response.shares) {
response.shares.forEach((share: any) => { response.shares.forEach((share: any) => {
@ -230,6 +231,7 @@ export class LeafletMapComponent implements OnInit {
this.availablePersons = Array.from(personsSet).sort(); this.availablePersons = Array.from(personsSet).sort();
} }
}); });
}
}); });
} }
@ -269,7 +271,8 @@ export class LeafletMapComponent implements OnInit {
const filteredPins = this.allPins.filter((pin) => { const filteredPins = this.allPins.filter((pin) => {
const pinCountry = this.pinCountries[pin.id]; const pinCountry = this.pinCountries[pin.id];
const matchesCountry = this.selectedCountry === '__all__' const matchesCountry =
this.selectedCountry === '__all__'
? true ? true
: pinCountry === this.selectedCountry; : pinCountry === this.selectedCountry;
const matchesPerson = const matchesPerson =
@ -336,14 +339,19 @@ export class LeafletMapComponent implements OnInit {
.unsubscribe(); .unsubscribe();
this.markerClusterGroup.addLayer(marker); this.markerClusterGroup.addLayer(marker);
if(this.selectedCountry === '__all__' && this.selectedPerson === '__all__') { if (
this.selectedCountry === '__all__' &&
this.selectedPerson === '__all__'
) {
this.map.fitBounds( this.map.fitBounds(
L.latLngBounds(filteredPins.map(pin => pin.location as [number, number])), L.latLngBounds(
filteredPins.map((pin) => pin.location as [number, number])
),
{ {
padding: [50, 50], padding: [50, 50],
maxZoom: 10, maxZoom: 10,
animate: true, animate: true,
duration: 1.5 duration: 1.5,
} }
); );
} }
@ -353,12 +361,14 @@ export class LeafletMapComponent implements OnInit {
// Ajuster la vue si un pays est sélectionné // Ajuster la vue si un pays est sélectionné
if (this.selectedCountry !== '__all__' && filteredPins.length > 0) { if (this.selectedCountry !== '__all__' && filteredPins.length > 0) {
const bounds = L.latLngBounds(filteredPins.map(pin => pin.location as [number, number])); const bounds = L.latLngBounds(
filteredPins.map((pin) => pin.location as [number, number])
);
this.map.fitBounds(bounds, { this.map.fitBounds(bounds, {
padding: [50, 50], // Ajoute un peu d'espace autour des marqueurs padding: [50, 50], // Ajoute un peu d'espace autour des marqueurs
maxZoom: 10, // Limite le zoom maximum pour garder une vue d'ensemble maxZoom: 10, // Limite le zoom maximum pour garder une vue d'ensemble
animate: true, // Active l'animation animate: true, // Active l'animation
duration: 1.5 // Durée de l'animation en secondes duration: 1.5, // Durée de l'animation en secondes
}); });
} }
} }

@ -1,4 +1,5 @@
<nav class="bg-white border-gray-200 dark:bg-gray-900"> <nav class="bg-white border-gray-200 dark:bg-gray-900">
<app-add-pin-popup></app-add-pin-popup>
<div <div
class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-3" class="max-w-screen-xl flex flex-wrap items-center justify-between mx-auto p-3"
> >
@ -173,7 +174,13 @@
> >
</li> </li>
<li id="add"> <li id="add">
<app-add-pin-popup></app-add-pin-popup> <button
(click)="openPinModal()"
class="block py-2 text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300"
type="button"
>
<p>Ajouter un pin</p>
</button>
</li> </li>
<li id="friend"> <li id="friend">
<app-friend-page></app-friend-page> <app-friend-page></app-friend-page>

@ -20,11 +20,12 @@ import {
switchMap, switchMap,
} from 'rxjs'; } from 'rxjs';
import { Pin } from '../../model/Pin'; import { Pin } from '../../model/Pin';
import { AuthService } from '../../services/auth/auth.service';
import { ModalService } from '../../services/modal/modal.service';
import { NavbarService } from '../../services/navbar/navbar.service';
import { PinService } from '../../services/pin/pin.service'; import { PinService } from '../../services/pin/pin.service';
import { AddPinPopupComponent } from '../add-pin-popup/add-pin-popup.component'; import { AddPinPopupComponent } from '../add-pin-popup/add-pin-popup.component';
import { FriendPageComponent } from '../friend-page/friend-page.component'; import { FriendPageComponent } from '../friend-page/friend-page.component';
import { AuthService } from '../../services/auth/auth.service';
import { NavbarService } from '../../services/navbar/navbar.service';
@Component({ @Component({
selector: 'app-navbar', selector: 'app-navbar',
@ -54,18 +55,19 @@ export class NavbarComponent implements OnInit {
private pinService: PinService, private pinService: PinService,
private fb: FormBuilder, private fb: FormBuilder,
private authService: AuthService, private authService: AuthService,
private navbarService: NavbarService private navbarService: NavbarService,
private modalService: ModalService
) { ) {
this.searchForm = this.fb.group({ this.searchForm = this.fb.group({
searchControl: new FormControl(''), searchControl: new FormControl(''),
}); });
this.navbarService.isSearchOpen$.subscribe(isOpen => { this.navbarService.isSearchOpen$.subscribe((isOpen) => {
this.isSearchOpen = isOpen; this.isSearchOpen = isOpen;
this.isNavbarOpen = false; this.isNavbarOpen = false;
}); });
this.navbarService.isNavbarOpen$.subscribe(isOpen => { this.navbarService.isNavbarOpen$.subscribe((isOpen) => {
this.isNavbarOpen = isOpen; this.isNavbarOpen = isOpen;
this.isSearchOpen = false; this.isSearchOpen = false;
}); });
@ -79,15 +81,21 @@ export class NavbarComponent implements OnInit {
this.navbarService.toggleNavbar(); this.navbarService.toggleNavbar();
} }
openPinModal() {
this.modalService.openModal('add-modal');
}
ngOnInit(): void { ngOnInit(): void {
this.pins = this.pinService.getPins().subscribe((pins: Pin[]) => { this.pins = this.pinService.getPins().subscribe((pins: Pin[]) => {
this.pins = pins; this.pins = pins;
}); });
this.showTimeline = this.router.url !== '/timeline' && this.router.url !== '/'; this.showTimeline =
this.router.url !== '/timeline' && this.router.url !== '/';
this.router.events.subscribe((event) => { this.router.events.subscribe((event) => {
if (event instanceof NavigationEnd) { if (event instanceof NavigationEnd) {
this.showTimeline = event.url !== '/timeline' && this.router.url !== '/'; this.showTimeline =
event.url !== '/timeline' && this.router.url !== '/';
} }
}); });
@ -114,7 +122,6 @@ export class NavbarComponent implements OnInit {
.subscribe((filteredPins) => { .subscribe((filteredPins) => {
this.pinsFiltered = filteredPins; this.pinsFiltered = filteredPins;
}); });
} }
filterPins(searchTerm: string): Pin[] { filterPins(searchTerm: string): Pin[] {

@ -1,12 +1,3 @@
<!-- Modal toggle -->
<button
(click)="openRegisterModal()"
class="block py-2 text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300"
type="button"
>
Inscription
</button>
<!-- Main modal --> <!-- Main modal -->
<div <div
class="fixed inset-0 z-40 bg-gray-900 bg-opacity-50 w-full h-full transition-opacity duration-300 ease-in-out" class="fixed inset-0 z-40 bg-gray-900 bg-opacity-50 w-full h-full transition-opacity duration-300 ease-in-out"

@ -10,8 +10,8 @@ import {
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { Subscription } from 'rxjs'; import { Subscription } from 'rxjs';
import { User } from '../../model/User'; import { User } from '../../model/User';
import { ModalService } from '../../services/modal/modal.service';
import { AuthService } from '../../services/auth/auth.service'; import { AuthService } from '../../services/auth/auth.service';
import { ModalService } from '../../services/modal/modal.service';
@Component({ @Component({
selector: 'app-register-page', selector: 'app-register-page',
@ -77,14 +77,12 @@ export class RegisterPageComponent {
this.user.login = this.userForm.value.login; this.user.login = this.userForm.value.login;
this.user.password = this.userForm.value.password; this.user.password = this.userForm.value.password;
this.authService this.authService.register(this.user.login, this.user.password).subscribe({
.register(this.user.login, this.user.password)
.subscribe({
next: () => { next: () => {
this.closeRegisterModal(); this.closeRegisterModal();
setTimeout(() => { setTimeout(() => {
this.router.navigate(['/map', {tutorial: true}]); this.router.navigate(['/map', { tutorial: true }]);
}, 1); }, 1);
}, },
error: (response) => { error: (response) => {
@ -94,10 +92,6 @@ export class RegisterPageComponent {
}); });
} }
openRegisterModal() {
this.modalService.openModal(this.modalId);
}
closeRegisterModal() { closeRegisterModal() {
this.modalService.closeModal(this.modalId); this.modalService.closeModal(this.modalId);
} }

Loading…
Cancel
Save