Ajout de la possibilité de supprimer un saut

Ajout de la possibilité de ne pas reset le
formulaire après ajout de sauts
This commit is contained in:
Sébastien André
2021-04-20 10:38:05 +02:00
parent 27928f1696
commit 49c2a87423
5 changed files with 64 additions and 44 deletions

View File

@@ -50,6 +50,14 @@
<td mat-cell *matCellDef="let element">{{element.gear.name}}</td> <td mat-cell *matCellDef="let element">{{element.gear.name}}</td>
</ng-container> </ng-container>
<ng-container matColumnDef="actions">
<th mat-header-cell *matHeaderCellDef></th>
<td mat-cell *matCellDef="let element" style="text-align: left;">
<mat-icon aria-hidden="false" aria-label="Delete this jump" style="cursor: pointer;"
(click)='delete(element)'>delete</mat-icon>
</td>
</ng-container>
<tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr> <tr mat-header-row *matHeaderRowDef="displayedColumns; sticky: true"></tr>
<tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr> <tr mat-row *matRowDef="let row; columns: displayedColumns;"></tr>
</table> </table>

View File

@@ -22,7 +22,8 @@ export class ListOfJumpsComponent implements OnInit {
'jumpDate', 'jumpDate',
'jumpType', 'jumpType',
'aircraft', 'aircraft',
'dropZone' 'dropZone',
'actions'
]; ];
public dataSourceTable; public dataSourceTable;
public resultsLength = 0; public resultsLength = 0;
@@ -51,11 +52,15 @@ export class ListOfJumpsComponent implements OnInit {
openDialog(item: JumpResp) { openDialog(item: JumpResp) {
this.dialog.open(JumpInfosComponent, { this.dialog.open(JumpInfosComponent, {
data: item //, data: item
// position: {
// top: '0px',
// left: '0px'
// }
}); });
} }
delete(item: JumpResp) {
let data : Array<JumpResp> = this.dataSourceTable.data;
data = data.filter(d => d.id !== item.id);
this.dataSourceTable.data = data;
this.serviceApi.DeleteJump(item);
}
} }

View File

@@ -2,6 +2,7 @@
<div class="content"> <div class="content">
<div> <div>
<button mat-raised-button color="accent" [routerLink]="['/jumps']" [routerLinkActive]="['active']" skipLocationChange>View the jumps</button> <button mat-raised-button color="accent" [routerLink]="['/jumps']" [routerLinkActive]="['active']" skipLocationChange>View the jumps</button>
<p><mat-checkbox [(ngModel)]="resetForm" labelPosition="before">Reset form after adding : </mat-checkbox></p>
</div> </div>
<form class="formNewJumps" (ngSubmit)="onFormSubmit()" *ngIf="notLoadingToDisplay() else loading"> <form class="formNewJumps" (ngSubmit)="onFormSubmit()" *ngIf="notLoadingToDisplay() else loading">
<mat-form-field> <mat-form-field>

View File

@@ -17,24 +17,25 @@ import { GearService } from "../../services/gear.service";
styleUrls: ["./new-jump.component.css"] styleUrls: ["./new-jump.component.css"]
}) })
export class NewJumpComponent implements OnInit { export class NewJumpComponent implements OnInit {
beginDate: Date; public beginDate: Date;
endDate: Date; public endDate: Date;
exitAltitude: number; public exitAltitude: number;
deployAltitude: number; public deployAltitude: number;
countOfJumps: number; public countOfJumps: number;
selectedDz: DropZoneResp; public selectedDz: DropZoneResp;
selectedGear: GearResp; public selectedGear: GearResp;
selectedAircraft: AircraftResp; public selectedAircraft: AircraftResp;
selectedJumpType: JumpTypeResp; public selectedJumpType: JumpTypeResp;
withCutaway: boolean; public withCutaway: boolean;
listOfJumpType: Array<JumpTypeResp>; public listOfJumpType: Array<JumpTypeResp>;
listOfAircraft: Array<AircraftResp>; public listOfAircraft: Array<AircraftResp>;
private listOfDropZone: Array<DropZoneResp>; public listOfFilteredDropZone: Array<DropZoneResp>;
listOfFilteredDropZone: Array<DropZoneResp>; public listOfGear: Array<GearResp>;
listOfGear: Array<GearResp>; public comments: string;
public resetForm: boolean;
private countDatasLoaded: number; private countDatasLoaded: number;
private pendingAddRequest: boolean; private pendingAddRequest: boolean;
comments: string; private listOfDropZone: Array<DropZoneResp>;
constructor(private serviceComm: ServiceComm, constructor(private serviceComm: ServiceComm,
private serviceJump: JumpService, private serviceJump: JumpService,
@@ -69,28 +70,28 @@ export class NewJumpComponent implements OnInit {
this.comments); this.comments);
setTimeout(() => { setTimeout(() => {
this.initForm(); if (this.resetForm === true) {
this.initForm();
}
this.pendingAddRequest = false; this.pendingAddRequest = false;
}, 1000); }, 1000);
} }
public isValidatedForm(): boolean { public isValidatedForm(): boolean {
return ( return (this.selectedDz !== undefined &&
this.selectedDz !== undefined && this.selectedDz.id !== undefined &&
this.selectedDz.id !== undefined && this.selectedGear !== undefined &&
this.selectedGear !== undefined && this.selectedGear.id !== undefined &&
this.selectedGear.id !== undefined && this.selectedAircraft !== undefined &&
this.selectedAircraft !== undefined && this.selectedAircraft.id !== undefined &&
this.selectedAircraft.id !== undefined && this.selectedJumpType !== undefined &&
this.selectedJumpType !== undefined && this.selectedJumpType.id !== undefined &&
this.selectedJumpType.id !== undefined && this.exitAltitude !== undefined &&
this.exitAltitude !== undefined && typeof this.exitAltitude === "number" &&
typeof this.exitAltitude === "number" && this.deployAltitude !== undefined &&
this.deployAltitude !== undefined && typeof this.deployAltitude === "number" &&
typeof this.deployAltitude === "number" && this.countOfJumps !== undefined &&
this.countOfJumps !== undefined && typeof this.countOfJumps === "number");
typeof this.countOfJumps === "number"
);
} }
private getListOfJumpTypes() { private getListOfJumpTypes() {

View File

@@ -74,6 +74,12 @@ export class JumpService extends BaseService {
notes); notes);
} }
public DeleteJump(item: JumpResp) {
this.http.delete(`${this.apiUrl}/Jump/${item.id}`,
{ headers: this.headers, })
.subscribe((data) => console.log(data));
}
private AddJumps(selectedJumpType: number, private AddJumps(selectedJumpType: number,
selectedAircraft: number, selectedAircraft: number,
selectedDz: number, selectedDz: number,
@@ -99,11 +105,10 @@ export class JumpService extends BaseService {
jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd") jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd")
}; };
this.http this.http.post(`${this.apiUrl}/Jump`,
.post(`${this.apiUrl}/Jump`, bodyNewjump, { bodyNewjump,
headers: this.headers, { headers: this.headers, })
}) .subscribe((data) => console.log(data));
.subscribe((data) => console.log(data));
} }
} }
} }