commit
37a978c640
@ -0,0 +1,71 @@
|
||||
<!-- Fond assombri -->
|
||||
<div
|
||||
class="fixed inset-0 bg-gray-900 bg-opacity-50 w-full h-full z-40 transition-opacity duration-300 ease-in-out"
|
||||
[ngClass]="{
|
||||
'opacity-0 pointer-events-none': !isOpen,
|
||||
'opacity-100': isOpen
|
||||
}"
|
||||
(click)="cancel()"
|
||||
id="confirm-modal-background"
|
||||
></div>
|
||||
|
||||
<!-- Contenu principal -->
|
||||
<div
|
||||
class="fixed inset-0 z-50 flex justify-center items-center w-full h-full"
|
||||
[ngClass]="{
|
||||
'opacity-0 scale-50 pointer-events-none': !isOpen,
|
||||
'opacity-100 scale-100': isOpen
|
||||
}"
|
||||
id="confirm-modal"
|
||||
>
|
||||
<div
|
||||
class="bg-white dark:bg-gray-700 rounded-lg shadow p-6 w-full max-w-md transition-transform duration-300 ease-in-out"
|
||||
>
|
||||
<!-- Modal header -->
|
||||
<div
|
||||
class="flex items-center justify-between border-b rounded-t dark:border-gray-600 mb-6 pb-2"
|
||||
>
|
||||
<h2 class="text-lg font-semibold text-gray-900 dark:text-white">
|
||||
Confirmation
|
||||
</h2>
|
||||
<button
|
||||
type="button"
|
||||
(click)="closeModal()"
|
||||
class="end-2.5 text-gray-400 bg-transparent hover:bg-gray-200 hover:text-gray-900 rounded-lg text-sm w-8 h-8 ms-auto inline-flex justify-center items-center dark:hover:bg-gray-600 dark:hover:text-white"
|
||||
>
|
||||
<svg
|
||||
class="w-3 h-3"
|
||||
aria-hidden="true"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
fill="none"
|
||||
viewBox="0 0 14 14"
|
||||
>
|
||||
<path
|
||||
stroke="currentColor"
|
||||
stroke-linecap="round"
|
||||
stroke-linejoin="round"
|
||||
stroke-width="2"
|
||||
d="m1 1 6 6m0 0 6 6M7 7l6-6M7 7l-6 6"
|
||||
/>
|
||||
</svg>
|
||||
<span class="sr-only">Fermer la modal</span>
|
||||
</button>
|
||||
</div>
|
||||
<p class="text-sm text-gray-700 dark:text-gray-300 mb-6">{{ message }}</p>
|
||||
|
||||
<div class="flex justify-end space-x-4">
|
||||
<button
|
||||
class="px-4 py-2 text-white bg-red-600 hover:bg-red-700 rounded"
|
||||
(click)="confirm()"
|
||||
>
|
||||
Supprimer
|
||||
</button>
|
||||
<button
|
||||
class="px-4 py-2 bg-gray-300 dark:bg-gray-600 text-gray-800 dark:text-white rounded hover:bg-gray-400 dark:hover:bg-gray-500"
|
||||
(click)="cancel()"
|
||||
>
|
||||
Annuler
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
@ -0,0 +1,23 @@
|
||||
import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ConfirmModalComponent } from './confirm-modal.component';
|
||||
|
||||
describe('ConfirmModalComponent', () => {
|
||||
let component: ConfirmModalComponent;
|
||||
let fixture: ComponentFixture<ConfirmModalComponent>;
|
||||
|
||||
beforeEach(async () => {
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ConfirmModalComponent]
|
||||
})
|
||||
.compileComponents();
|
||||
|
||||
fixture = TestBed.createComponent(ConfirmModalComponent);
|
||||
component = fixture.componentInstance;
|
||||
fixture.detectChanges();
|
||||
});
|
||||
|
||||
it('should create', () => {
|
||||
expect(component).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,75 @@
|
||||
import { CommonModule } from '@angular/common';
|
||||
import {
|
||||
Component,
|
||||
EventEmitter,
|
||||
Input,
|
||||
OnDestroy,
|
||||
OnInit,
|
||||
Output,
|
||||
} from '@angular/core';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { ModalService } from '../../services/modal/modal.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-confirm-modal',
|
||||
standalone: true,
|
||||
imports: [CommonModule],
|
||||
templateUrl: './confirm-modal.component.html',
|
||||
})
|
||||
export class ConfirmModalComponent implements OnInit, OnDestroy {
|
||||
@Input() modalId: string = 'confirm-modal';
|
||||
@Input() message: string = 'Es-tu sûr de vouloir supprimer ?';
|
||||
@Output() confirmed = new EventEmitter<void>();
|
||||
@Output() cancelled = new EventEmitter<void>();
|
||||
|
||||
isOpen = false;
|
||||
private subscription!: Subscription;
|
||||
|
||||
constructor(private modalService: ModalService) {}
|
||||
|
||||
ngOnInit() {
|
||||
this.subscription = this.modalService
|
||||
.getModalState(this.modalId)
|
||||
.subscribe((state) => {
|
||||
this.isOpen = state;
|
||||
if (state) {
|
||||
setTimeout(() => this.moveModalToBody(), 0);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
ngAfterViewInit() {
|
||||
// Appel initial pour déplacer le modal
|
||||
this.moveModalToBody();
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.subscription?.unsubscribe();
|
||||
}
|
||||
|
||||
confirm() {
|
||||
this.confirmed.emit();
|
||||
this.modalService.closeModal(this.modalId);
|
||||
}
|
||||
|
||||
cancel() {
|
||||
this.cancelled.emit();
|
||||
this.modalService.closeModal(this.modalId);
|
||||
}
|
||||
|
||||
closeModal() {
|
||||
this.isOpen = false;
|
||||
this.modalService.closeModal(this.modalId);
|
||||
}
|
||||
|
||||
private moveModalToBody(): void {
|
||||
const modal = document.getElementById('confirm-modal');
|
||||
if (modal && modal.parentElement !== document.body) {
|
||||
document.body.appendChild(modal);
|
||||
}
|
||||
const bg = document.getElementById('confirm-modal-background');
|
||||
if (bg && bg.parentElement !== document.body) {
|
||||
document.body.appendChild(bg);
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MapReloadService } from './map-reload.service';
|
||||
|
||||
describe('MapReloadService', () => {
|
||||
let service: MapReloadService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(MapReloadService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
});
|
@ -0,0 +1,14 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class MapReloadService {
|
||||
private reloadSubject = new Subject<void>();
|
||||
public reload$ = this.reloadSubject.asObservable();
|
||||
|
||||
requestReload(): void {
|
||||
this.reloadSubject.next();
|
||||
}
|
||||
}
|
Loading…
Reference in new issue