From 21c751e4a0dbfde682fd75fb093eca64e11afa0e Mon Sep 17 00:00:00 2001 From: Alexis Feron Date: Tue, 7 Jan 2025 15:21:29 +0100 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=9A=A7=20Add=20the=20modal?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../add-pin-popup.component.html | 144 ++++++++++++++++++ .../add-pin-popup.component.spec.ts | 23 +++ .../add-pin-popup/add-pin-popup.component.ts | 9 ++ .../leaflet-map/leaflet-map.component.html | 2 +- .../components/navbar/navbar.component.html | 6 +- src/app/components/navbar/navbar.component.ts | 3 +- 6 files changed, 180 insertions(+), 7 deletions(-) create mode 100644 src/app/components/add-pin-popup/add-pin-popup.component.html create mode 100644 src/app/components/add-pin-popup/add-pin-popup.component.spec.ts create mode 100644 src/app/components/add-pin-popup/add-pin-popup.component.ts diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.html b/src/app/components/add-pin-popup/add-pin-popup.component.html new file mode 100644 index 0000000..082920c --- /dev/null +++ b/src/app/components/add-pin-popup/add-pin-popup.component.html @@ -0,0 +1,144 @@ + + + + + diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.spec.ts b/src/app/components/add-pin-popup/add-pin-popup.component.spec.ts new file mode 100644 index 0000000..51da39f --- /dev/null +++ b/src/app/components/add-pin-popup/add-pin-popup.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { AddPinPopupComponent } from './add-pin-popup.component'; + +describe('AddPinPopupComponent', () => { + let component: AddPinPopupComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [AddPinPopupComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(AddPinPopupComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.ts b/src/app/components/add-pin-popup/add-pin-popup.component.ts new file mode 100644 index 0000000..042a7a7 --- /dev/null +++ b/src/app/components/add-pin-popup/add-pin-popup.component.ts @@ -0,0 +1,9 @@ +import { MatGoogleMapsAutocompleteModule } from '@angular-material-extensions/google-maps-autocomplete'; +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-add-pin-popup', + imports: [MatGoogleMapsAutocompleteModule], + templateUrl: './add-pin-popup.component.html', +}) +export class AddPinPopupComponent {} diff --git a/src/app/components/leaflet-map/leaflet-map.component.html b/src/app/components/leaflet-map/leaflet-map.component.html index b7e9bc7..2d422b6 100644 --- a/src/app/components/leaflet-map/leaflet-map.component.html +++ b/src/app/components/leaflet-map/leaflet-map.component.html @@ -1,3 +1,3 @@
-
+
diff --git a/src/app/components/navbar/navbar.component.html b/src/app/components/navbar/navbar.component.html index 55ae8d9..df8c94e 100644 --- a/src/app/components/navbar/navbar.component.html +++ b/src/app/components/navbar/navbar.component.html @@ -137,11 +137,7 @@ >
  • - Add a pin +
  • Date: Tue, 7 Jan 2025 23:18:51 +0100 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=A7=20Autocomplete=20localisation?= =?UTF-8?q?=20partially=20works?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/app.config.ts | 7 ++- .../add-pin-popup.component.html | 24 ++++++-- .../add-pin-popup/add-pin-popup.component.ts | 56 ++++++++++++++++++- .../services/auto-complete.service.spec.ts | 16 ++++++ src/app/services/auto-complete.service.ts | 23 ++++++++ 5 files changed, 117 insertions(+), 9 deletions(-) create mode 100644 src/app/services/auto-complete.service.spec.ts create mode 100644 src/app/services/auto-complete.service.ts diff --git a/src/app/app.config.ts b/src/app/app.config.ts index a1e7d6f..8766d64 100644 --- a/src/app/app.config.ts +++ b/src/app/app.config.ts @@ -1,8 +1,13 @@ +import { provideHttpClient } from '@angular/common/http'; import { ApplicationConfig, provideZoneChangeDetection } from '@angular/core'; import { provideRouter } from '@angular/router'; import { routes } from './app.routes'; export const appConfig: ApplicationConfig = { - providers: [provideZoneChangeDetection({ eventCoalescing: true }), provideRouter(routes)] + providers: [ + provideZoneChangeDetection({ eventCoalescing: true }), + provideRouter(routes), + provideHttpClient(), + ], }; diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.html b/src/app/components/add-pin-popup/add-pin-popup.component.html index 082920c..6b615bc 100644 --- a/src/app/components/add-pin-popup/add-pin-popup.component.html +++ b/src/app/components/add-pin-popup/add-pin-popup.component.html @@ -50,7 +50,7 @@
    -
    +
    +
    +
      +
    • + {{ suggestion.display_name }} +
    • +
    +
    +
    +
  • + + diff --git a/src/app/components/drag-drop/drag-drop.component.spec.ts b/src/app/components/drag-drop/drag-drop.component.spec.ts new file mode 100644 index 0000000..17747dc --- /dev/null +++ b/src/app/components/drag-drop/drag-drop.component.spec.ts @@ -0,0 +1,23 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; + +import { DragDropComponent } from './drag-drop.component'; + +describe('DragDropComponent', () => { + let component: DragDropComponent; + let fixture: ComponentFixture; + + beforeEach(async () => { + await TestBed.configureTestingModule({ + imports: [DragDropComponent] + }) + .compileComponents(); + + fixture = TestBed.createComponent(DragDropComponent); + component = fixture.componentInstance; + fixture.detectChanges(); + }); + + it('should create', () => { + expect(component).toBeTruthy(); + }); +}); diff --git a/src/app/components/drag-drop/drag-drop.component.ts b/src/app/components/drag-drop/drag-drop.component.ts new file mode 100644 index 0000000..72718bb --- /dev/null +++ b/src/app/components/drag-drop/drag-drop.component.ts @@ -0,0 +1,45 @@ +import { CommonModule } from '@angular/common'; +import { Component } from '@angular/core'; + +@Component({ + selector: 'app-drag-drop', + imports: [CommonModule], + templateUrl: './drag-drop.component.html', +}) +export class DragDropComponent { + fileNames: string[] = []; + + onFilesSelected(event: Event): void { + const input = event.target as HTMLInputElement; + if (input.files) { + this.updateFileNames(input.files); + } + } + + onDrop(event: DragEvent): void { + event.preventDefault(); + event.stopPropagation(); + if (event.dataTransfer && event.dataTransfer.files) { + this.updateFileNames(event.dataTransfer.files); + } + } + + onDragOver(event: DragEvent): void { + event.preventDefault(); + } + + onDragLeave(event: DragEvent): void { + event.preventDefault(); + } + + private updateFileNames(files: FileList): void { + for (let i = 0; i < files.length; i++) { + this.fileNames.push(files[i].name); + } + } + + removeFile(fileName: string): void { + const index = this.fileNames.indexOf(fileName); + this.fileNames.splice(index, 1); + } +} From 5ac50a1d2372ab4f9b1ea8b6750f7fdab12f4189 Mon Sep 17 00:00:00 2001 From: Alexis Feron Date: Mon, 13 Jan 2025 18:19:20 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=E2=9C=A8=20Adding=20a=20pin=20to=20the=20d?= =?UTF-8?q?atabase=20works=20&=20navbar=20improvement?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../add-pin-popup.component.html | 12 +++-- .../add-pin-popup/add-pin-popup.component.ts | 46 +++++++++++++------ .../drag-drop/drag-drop.component.html | 1 + .../drag-drop/drag-drop.component.ts | 5 +- .../components/navbar/navbar.component.html | 22 ++++++++- src/app/components/navbar/navbar.component.ts | 1 + src/app/services/add-pin.service.spec.ts | 16 +++++++ src/app/services/add-pin.service.ts | 27 +++++++++++ 8 files changed, 111 insertions(+), 19 deletions(-) create mode 100644 src/app/services/add-pin.service.spec.ts create mode 100644 src/app/services/add-pin.service.ts diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.html b/src/app/components/add-pin-popup/add-pin-popup.component.html index 654f293..86e8634 100644 --- a/src/app/components/add-pin-popup/add-pin-popup.component.html +++ b/src/app/components/add-pin-popup/add-pin-popup.component.html @@ -5,7 +5,7 @@ class="block py-2 text-gray-900 dark:text-white hover:text-gray-700 dark:hover:text-gray-300" type="button" > - Add a pin +

    Add a pin

    @@ -13,7 +13,7 @@ id="authentication-modal" tabindex="-1" aria-hidden="true" - class="hidden absolute top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full" + class="hidden overflow-auto absolute top-0 right-0 left-0 z-50 justify-center items-center w-full md:inset-0 h-[calc(100%-1rem)] max-h-full" >
    @@ -61,6 +61,7 @@ type="title" name="title" id="title" + formControlName="title" class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-600 dark:border-gray-500 dark:placeholder-gray-400 dark:text-white" placeholder="Mont Saint-Michel" required @@ -97,7 +98,9 @@
    - +
    Inscription -
  • - +
  • +
  • { + let service: AddPinService; + + beforeEach(() => { + TestBed.configureTestingModule({}); + service = TestBed.inject(AddPinService); + }); + + it('should be created', () => { + expect(service).toBeTruthy(); + }); +}); diff --git a/src/app/services/add-pin.service.ts b/src/app/services/add-pin.service.ts new file mode 100644 index 0000000..6c56afa --- /dev/null +++ b/src/app/services/add-pin.service.ts @@ -0,0 +1,27 @@ +import { HttpClient, HttpHeaders } from '@angular/common/http'; +import { Injectable } from '@angular/core'; +import { environment } from '../../environments/environment'; + +@Injectable({ + providedIn: 'root', +}) +export class AddPinService { + private apiURL = environment.apiURL; + private token = localStorage.getItem('token') || ''; + + constructor(private http: HttpClient) {} + + addPin(pin: { title: string; description: string }) { + const url = `${this.apiURL}/pin/add`; + const headers = new HttpHeaders({ + Authorization: 'Bearer ' + this.token, + }); + return this.http + .post( + url, + { title: pin.title, description: pin.description }, + { headers } + ) + .subscribe(); + } +} From 578023ae5bec69be208e613137165ffdc580fa82 Mon Sep 17 00:00:00 2001 From: Alexis Feron Date: Fri, 17 Jan 2025 14:40:51 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=E2=9C=A8=20Save=20all=20pins=20data=20to?= =?UTF-8?q?=20db?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../add-pin-popup/add-pin-popup.component.ts | 6 +++++- src/app/services/add-pin.service.ts | 18 ++++++++++++++---- 2 files changed, 19 insertions(+), 5 deletions(-) diff --git a/src/app/components/add-pin-popup/add-pin-popup.component.ts b/src/app/components/add-pin-popup/add-pin-popup.component.ts index fb56d28..58c2a2f 100644 --- a/src/app/components/add-pin-popup/add-pin-popup.component.ts +++ b/src/app/components/add-pin-popup/add-pin-popup.component.ts @@ -28,7 +28,7 @@ export class AddPinPopupComponent implements OnInit { suggestions: any[] = []; inputFocused: boolean = false; @Input() isHomePage: boolean = false; - files: File[] = []; + files: any[] = []; constructor( private fb: FormBuilder, @@ -90,6 +90,10 @@ export class AddPinPopupComponent implements OnInit { submitForm(): void { if (this.form.valid) { + this.files = this.files.map((file) => { + return file.name; //TODO: Mettre le hash du fichier + }); + const pinData = { ...this.form.value, files: this.files, // Ajoutez les fichiers au payload diff --git a/src/app/services/add-pin.service.ts b/src/app/services/add-pin.service.ts index 6c56afa..1581452 100644 --- a/src/app/services/add-pin.service.ts +++ b/src/app/services/add-pin.service.ts @@ -7,19 +7,29 @@ import { environment } from '../../environments/environment'; }) export class AddPinService { private apiURL = environment.apiURL; - private token = localStorage.getItem('token') || ''; - + private token = localStorage.getItem('token'); constructor(private http: HttpClient) {} - addPin(pin: { title: string; description: string }) { + addPin(pin: { + title: string; + description: string; + location: string; + files: any[]; + }) { const url = `${this.apiURL}/pin/add`; const headers = new HttpHeaders({ + 'Content-Type': 'application/json', Authorization: 'Bearer ' + this.token, }); return this.http .post( url, - { title: pin.title, description: pin.description }, + { + title: pin.title, + description: pin.description, + location: pin.location, + files: pin.files, + }, { headers } ) .subscribe();