Implémentation de la suppresion d'une note

develop
Yanaël GRETTE 4 years ago
parent 1771dc67c2
commit 9bb818d684
  1. 2
      src/app/notes/details-note/details-note.component.html
  2. 38
      src/app/notes/details-note/details-note.component.ts
  3. 4
      src/app/notes/details-note/dialog-suppression-note.html
  4. 5
      src/app/notes/notes.module.ts

@ -10,5 +10,5 @@
<p>Créé le {{ note.dateCreation | date : 'dd/MM/yyyy à hh:mm'}}</p> <p>Créé le {{ note.dateCreation | date : 'dd/MM/yyyy à hh:mm'}}</p>
<p>Dernère mise à jour le {{ note.dateMiseAjour | date : 'dd/MM/yyyy à hh:mm'}}</p> <p>Dernère mise à jour le {{ note.dateMiseAjour | date : 'dd/MM/yyyy à hh:mm'}}</p>
<button mat-raised-button [routerLink]="['/notes', note.id, 'edit']">Modifier la note </button> <button mat-raised-button [routerLink]="['/notes', note.id, 'edit']">Modifier la note </button>
<button mat-raised-button color="warn">Supprimer la note</button> <button mat-raised-button color="warn" (click)="supprimerNote()">Supprimer la note</button>
</ng-container> </ng-container>

@ -1,5 +1,6 @@
import { Component, OnInit } from "@angular/core"; import { Component, Inject, OnInit } from "@angular/core";
import { ActivatedRoute } from "@angular/router"; import { MatDialog, MatDialogRef, MAT_DIALOG_DATA } from "@angular/material/dialog";
import { ActivatedRoute, Router } from "@angular/router";
import { DetailsNoteDTO, NotesService } from "@shared/api-swagger"; import { DetailsNoteDTO, NotesService } from "@shared/api-swagger";
import { Subscription } from "rxjs"; import { Subscription } from "rxjs";
@ -14,7 +15,7 @@ export class DetailsNoteComponent implements OnInit{
noteSubscription: Subscription; noteSubscription: Subscription;
constructor(private noteService: NotesService, private activatedRoute: ActivatedRoute) {} constructor(private dialog: MatDialog, private noteService: NotesService, private activatedRoute: ActivatedRoute) {}
ngOnInit() { ngOnInit() {
const id: any = this.activatedRoute.snapshot.paramMap.get("id"); const id: any = this.activatedRoute.snapshot.paramMap.get("id");
@ -25,4 +26,35 @@ export class DetailsNoteComponent implements OnInit{
) )
} }
} }
supprimerNote() {
this.dialog.open(DialogSuppressionNoteComponent, { data: this.note})
}
}
@Component({
selector: "dialog-supprimer-note",
templateUrl: "./dialog-suppression-note.html"
})
export class DialogSuppressionNoteComponent {
noteSubcription: Subscription;
constructor(private dialogRef: MatDialogRef<DialogSuppressionNoteComponent>,@Inject(MAT_DIALOG_DATA) public data: DetailsNoteDTO, private noteService: NotesService, private router: Router) {}
fermer() {
this.dialogRef.close();
}
supprimer() {
this.noteSubcription = this.noteService.deleteNote(this.data.id).subscribe(
() => {
this.router.navigate(["/notes"]);
this.dialogRef.close();
},
err => console.log(err)
);
}
} }

@ -0,0 +1,4 @@
<p> <b>Souhaitez-vous réellement supprimer la note {{data.titre}} ? Une fois supprimée, aucune note ne peut être récupérée !</b></p>
<button mat-raised-button color="warn" (click)="supprimer()">Supprimer</button>
<button mat-raised-button (click)="fermer()">Annuler</button>

@ -9,7 +9,7 @@ import { NotesComponent } from "./notes.component";
import { FormsModule, ReactiveFormsModule } from "@angular/forms"; import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { DialogChoixCollaborateurNoteComponent, NouvelleNoteComponent } from "./nouvelle-note/nouvelle-note.component"; import { DialogChoixCollaborateurNoteComponent, NouvelleNoteComponent } from "./nouvelle-note/nouvelle-note.component";
import { MatTablesModule } from "@shared/mat-tables/mat-tables.module"; import { MatTablesModule } from "@shared/mat-tables/mat-tables.module";
import { DetailsNoteComponent } from "./details-note/details-note.component"; import { DetailsNoteComponent, DialogSuppressionNoteComponent } from "./details-note/details-note.component";
import { ModifierNoteComponent } from "./modifier-note/modifier-note.component"; import { ModifierNoteComponent } from "./modifier-note/modifier-note.component";
@ -17,7 +17,8 @@ import { ModifierNoteComponent } from "./modifier-note/modifier-note.component";
declarations: [ declarations: [
NotesComponent, NouvelleNoteComponent, NotesComponent, NouvelleNoteComponent,
DialogChoixCollaborateurNoteComponent, DialogChoixCollaborateurNoteComponent,
DetailsNoteComponent, ModifierNoteComponent DetailsNoteComponent, ModifierNoteComponent,
DialogSuppressionNoteComponent
], ],
imports: [ imports: [
CommonModule, CommonModule,

Loading…
Cancel
Save