Little test with AI + Add the equipment (#8)

Tests using local LLM AI to add comments in the C# files
For the flights tunnel, show the total to day/hours
For the jump, add the equipment (now just with the wingsuit)

Reviewed-on: #8
Co-authored-by: sandre <perso@sebastienandre.com>
Co-committed-by: sandre <perso@sebastienandre.com>
This commit was merged in pull request #8.
This commit is contained in:
2026-05-16 09:24:13 +00:00
committed by sandre
parent 0ebdbca549
commit ceed44f997
70 changed files with 12142 additions and 10444 deletions
+9995 -9995
View File
File diff suppressed because it is too large Load Diff
@@ -0,0 +1,91 @@
<form (ngSubmit)="updateGear()">
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_Name" | translate }}</mat-label>
<input
type="text"
matInput
name="name"
[(ngModel)]="gear.name"
name="name"
type="text"
/>
</mat-form-field>
</p>
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_Manufacturer" | translate }}</mat-label>
<input
type="text"
matInput
name="manufacturer"
[(ngModel)]="gear.manufacturer"
name="manufacturer"
/>
</mat-form-field>
</p>
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_MinSize" | translate }}Min size</mat-label>
<input
type="text"
matInput
name="minSize"
[(ngModel)]="gear.minSize"
name="minSize"
/>
</mat-form-field>
</p>
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_MaxSize" | translate }}</mat-label>
<input
type="text"
matInput
name="maxSize"
[(ngModel)]="gear.maxSize"
name="maxSize"
/>
</mat-form-field>
</p>
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_AAD" | translate }}</mat-label>
<input
type="text"
matInput
name="aad"
[(ngModel)]="gear.aad"
name="aad"
/>
</mat-form-field>
</p>
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_MainCanopy" | translate }}</mat-label>
<input
type="text"
matInput
name="mainCanopy"
[(ngModel)]="gear.mainCanopy"
name="mainCanopy"
/>
</mat-form-field>
</p>
<p>
<mat-form-field>
<mat-label>{{ "GearInfos_ReserveCanopy" | translate }}</mat-label>
<input
type="text"
matInput
name="reserveCanopy"
[(ngModel)]="gear.reserveCanopy"
name="reserveCanopy"
/>
</mat-form-field>
</p>
<br />
@if (editMode) {
<button mat-raised-button color="accent">Update</button>
}
</form>
@@ -0,0 +1,62 @@
import { Component, Inject, OnInit } from "@angular/core";
import { MAT_DIALOG_DATA } from "@angular/material/dialog";
import { TranslateModule } from "@ngx-translate/core";
import { MatCheckboxModule } from "@angular/material/checkbox";
import { MatFormFieldModule } from "@angular/material/form-field";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { MatInputModule } from "@angular/material/input";
import { MatButtonModule } from "@angular/material/button";
import { AddAction } from "../../models/add-action.enum";
import { GearResp } from "../../models/gear";
import { GearService } from "../../services/gear.service";
import { ServiceComm } from "../../services/service-comm.service";
@Component({
selector: "app-gear-infos",
templateUrl: "./gear-infos.component.html",
styleUrls: ["./gear-infos.component.css"],
imports: [
TranslateModule,
FormsModule,
MatCheckboxModule,
MatFormFieldModule,
ReactiveFormsModule,
MatInputModule,
MatButtonModule,
],
})
export class GearInfosComponent implements OnInit {
public editMode: boolean;
public gear: GearResp;
constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
private serviceGear: GearService,
private serviceComm: ServiceComm,
) {
this.gear = new GearResp(data.gear);
this.editMode = data.editMode;
}
ngOnInit(): void {}
public updateGear() {
this.serviceGear
.updateGear(
this.gear.id,
this.gear.name,
this.gear.manufacturer,
this.gear.minSize,
this.gear.maxSize,
this.gear.aad,
this.gear.mainCanopy,
this.gear.reserveCanopy,
)
.subscribe(() => {
this.serviceComm.refreshData(AddAction.Gear);
});
}
}
@@ -7,6 +7,7 @@
[(ngModel)]="jump.isSpecial"
name="isSpecial"
labelPosition="before"
[disabled]="!editMode"
>Special jump</mat-checkbox
>
</p>
@@ -15,6 +16,7 @@
[(ngModel)]="jump.withCutaway"
name="withCutaway"
labelPosition="before"
[disabled]="!editMode"
>Cutaway</mat-checkbox
>
</p>
@@ -26,11 +28,22 @@
[(ngModel)]="jump.notes"
name="comments"
type="text"
[disabled]="!editMode"
></textarea>
</mat-form-field>
<br />
@if (editMode) {
<button mat-raised-button color="accent">Update</button>
}
<p>
<mat-form-field>
<mat-label>{{ "NewJump_Equipment" | translate }}</mat-label>
<mat-select [(value)]="jump.equipment" [disabled]="!editMode">
@for (equipment of listOfEquipment; track equipment) {
<mat-option [value]="equipment.value">{{
equipment.viewValue
}}</mat-option>
}
</mat-select>
</mat-form-field>
@if (editMode) {
<button mat-raised-button color="accent">Update</button>
}
</p>
</form>
@@ -7,6 +7,7 @@ import { MatFormFieldModule } from "@angular/material/form-field";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { MatInputModule } from "@angular/material/input";
import { MatButtonModule } from "@angular/material/button";
import { MatSelectModule } from "@angular/material/select";
import { AddAction } from "../../models/add-action.enum";
import { JumpResp } from "../../models/jump";
@@ -14,6 +15,11 @@ import { JumpResp } from "../../models/jump";
import { JumpService } from "../../services/jump.service";
import { ServiceComm } from "../../services/service-comm.service";
interface Equipment {
value: string;
viewValue: string;
}
@Component({
selector: "app-jump-infos",
templateUrl: "./jump-infos.component.html",
@@ -26,11 +32,21 @@ import { ServiceComm } from "../../services/service-comm.service";
ReactiveFormsModule,
MatInputModule,
MatButtonModule,
MatSelectModule,
],
})
export class JumpInfosComponent implements OnInit {
public editMode: boolean;
public jump: JumpResp;
public selectedEquipment: string;
public listOfEquipment: Array<Equipment> = [
{ value: "", viewValue: "<None>" },
{ value: "Freak 6", viewValue: "Freak 6" },
{ value: "ATC 4", viewValue: "ATC 4" },
{ value: "ATC 2", viewValue: "ATC 2" },
{ value: "Havok", viewValue: "Havok" },
{ value: "Hawk", viewValue: "Hawk" },
];
constructor(
@Inject(MAT_DIALOG_DATA) public data: any,
@@ -38,6 +54,7 @@ export class JumpInfosComponent implements OnInit {
private serviceComm: ServiceComm,
) {
this.jump = new JumpResp(data.jump);
this.selectedEquipment = this.jump.equipment;
this.editMode = data.editMode;
}
@@ -50,6 +67,7 @@ export class JumpInfosComponent implements OnInit {
this.jump.isSpecial,
this.jump.withCutaway,
this.jump.notes,
this.jump.equipment,
)
.subscribe(() => {
this.serviceComm.refreshData(AddAction.Jump);
@@ -71,6 +71,26 @@
{{ element.reserveCanopy }}
</td>
</ng-container>
<ng-container matColumnDef="actions">
<th
mat-header-cell
*matHeaderCellDef
style="min-width: 80px; text-wrap: nowrap"
></th>
<td
mat-cell
*matCellDef="let element"
style="text-align: left; text-wrap: nowrap"
>
<mat-icon
aria-hidden="false"
aria-label="Update this gear"
style="cursor: pointer; margin-left: 10px"
(click)="openDialog(element, true)"
svgIcon="edit"
></mat-icon>
</td>
</ng-container>
<tr
mat-header-row
*matHeaderRowDef="displayedColumns; sticky: true"
@@ -6,12 +6,14 @@ import { TranslateModule, TranslateService } from "@ngx-translate/core";
import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
import { MatButtonModule } from "@angular/material/button";
import { MatIconModule } from "@angular/material/icon";
import { GearService } from "../../services/gear.service";
import { ServiceComm } from "../../services/service-comm.service";
import { GearResp } from "../../models/gear";
import { AddAction } from "../../models/add-action.enum";
import { NewGearComponent } from "../new-gear/new-gear.component";
import { GearInfosComponent } from "../gear-infos/gear-infos.component";
@Component({
selector: "app-list-of-gears",
@@ -23,6 +25,7 @@ import { NewGearComponent } from "../new-gear/new-gear.component";
MatProgressSpinnerModule,
MatTableModule,
MatButtonModule,
MatIconModule,
],
})
export class ListOfGearsComponent implements OnInit {
@@ -33,6 +36,7 @@ export class ListOfGearsComponent implements OnInit {
"aad",
"mainCanopy",
"reserveCanopy",
"actions",
];
public dataSourceTable: MatTableDataSource<GearResp>;
public resultsLength = 0;
@@ -80,6 +84,14 @@ export class ListOfGearsComponent implements OnInit {
});
}
openDialog(item: GearResp, editMode: boolean) {
this.dialog.open(GearInfosComponent, {
data: { gear: item, editMode: editMode },
maxHeight: "400px",
minWidth: "350px",
});
}
private updateTitle() {
this.translateService.get("ListGears_Title").subscribe((data) => {
this.serviceComm.updatedComponentTitle(data);
@@ -105,7 +105,7 @@ export class ListOfJumpsComponent implements OnInit {
openDialog(item: Jump, editMode: boolean) {
this.dialog.open(JumpInfosComponent, {
data: { jump: item, editMode: editMode },
maxHeight: "400px",
maxHeight: "450px",
minWidth: "350px",
});
}
@@ -33,7 +33,7 @@
<mat-nav-list>
@for (stat of stats; track stat) {
<mat-list-item matListItemLine>
<label>{{ stat.id }} : {{ stat.values }}</label>
<label>{{ stat.label }} : {{ stat.hoursAndMinutes.hours }}h {{ stat.hoursAndMinutes.minutes }}m</label>
</mat-list-item>
}
</mat-nav-list>
@@ -59,7 +59,13 @@ export class ListOfTunnelFlightsComponent implements OnInit {
"flightDate",
"actions",
];
public stats: Array<{ id: String | Number; values: String | Number }> = [];
public stats: Array<{
label: String;
hoursAndMinutes: {
hours: number;
minutes: number;
};
}> = [];
constructor(
private serviceComm: ServiceComm,
@@ -92,6 +98,14 @@ export class ListOfTunnelFlightsComponent implements OnInit {
this.getDataForTable();
}
public delete(item: TunnelFlight) {
let data: Array<TunnelFlight> = this.dataSourceTable.data;
data = data.filter((d) => d.id !== item.id);
this.dataSourceTable.data = data;
this.serviceTunnelFlight.deleteTunnelFlight(item);
}
private chartConfig() {
this.barChartType = "bar";
this.barChartOptions = {
@@ -190,15 +204,25 @@ export class ListOfTunnelFlightsComponent implements OnInit {
),
),
map((arr) => ({
id: arr[0],
label: arr[0],
values: arr
.slice(1)
.reduce((a, b) => Number(a) + Number(b), 0),
hoursAndMinutes: {},
})),
)
.subscribe((p) => {
console.log(p);
this.stats.push(p);
let newStat: {
label: String;
hoursAndMinutes: {
hours: number;
minutes: number;
};
} = {
label: p.label.toString(),
hoursAndMinutes: this.toHoursAndMinutes(+p.values),
};
this.stats.push(newStat);
});
}
@@ -285,11 +309,13 @@ export class ListOfTunnelFlightsComponent implements OnInit {
return beginDate;
}
public delete(item: TunnelFlight) {
let data: Array<TunnelFlight> = this.dataSourceTable.data;
data = data.filter((d) => d.id !== item.id);
private toHoursAndMinutes(totalMinutes: number): {
hours: number;
minutes: number;
} {
const hours = Math.floor(totalMinutes / 60);
const minutes = totalMinutes % 60;
this.dataSourceTable.data = data;
this.serviceTunnelFlight.deleteTunnelFlight(item);
return { hours, minutes };
}
}
@@ -30,7 +30,7 @@
</mat-option>
</mat-select>
</mat-card-title>
<mat-card-subtitle style="font-size: 12px">
<mat-card-subtitle style="font-size: 12px; text-align: center;">
{{ "App_Footer" | translate }}{{ version }} - &#64;Séb
</mat-card-subtitle>
</mat-card-header>
@@ -152,6 +152,16 @@
</button>
}
</mat-form-field>
<mat-form-field>
<mat-label>{{ "NewJump_Equipment" | translate }}</mat-label>
<mat-select [(value)]="selectedEquipment">
@for (equipment of listOfEquipment; track equipment) {
<mat-option [value]="equipment.value">{{
equipment.viewValue
}}</mat-option>
}
</mat-select>
</mat-form-field>
<mat-checkbox [(ngModel)]="withCutaway" name="withCutaway">{{
"NewJump_Cutaway" | translate
}}</mat-checkbox>
@@ -18,6 +18,7 @@ import { MatProgressSpinnerModule } from "@angular/material/progress-spinner";
import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { MatInputModule } from "@angular/material/input";
import { MatButtonModule } from "@angular/material/button";
import { MatSelectModule } from "@angular/material/select";
import { JumpTypeResp } from "../../models/jumpType";
import { AircraftResp } from "../../models/aircraft";
@@ -48,6 +49,11 @@ class PickDateAdapter extends NativeDateAdapter {
}
}
interface Equipment {
value: string;
viewValue: string;
}
@Component({
selector: "app-new-jump",
templateUrl: "./new-jump.component.html",
@@ -72,6 +78,7 @@ class PickDateAdapter extends NativeDateAdapter {
ReactiveFormsModule,
MatInputModule,
MatButtonModule,
MatSelectModule,
],
})
export class NewJumpComponent implements OnInit {
@@ -96,6 +103,15 @@ export class NewJumpComponent implements OnInit {
private pendingAddRequest: boolean;
private listOfDropZone: Array<DropZoneResp>;
public maxDate: Date;
public selectedEquipment: string = "";
public listOfEquipment: Array<Equipment> = [
{ value: "", viewValue: "<None>" },
{ value: "Freak 6", viewValue: "Freak 6" },
{ value: "ATC 4", viewValue: "ATC 4" },
{ value: "ATC 2", viewValue: "ATC 2" },
{ value: "Havok", viewValue: "Havok" },
{ value: "Hawk", viewValue: "Hawk" },
];
constructor(
private serviceComm: ServiceComm,
@@ -142,10 +158,12 @@ export class NewJumpComponent implements OnInit {
this.countOfJumps,
this.comments,
this.isSpecial === undefined ? false : this.isSpecial,
this.selectedEquipment,
)
.subscribe(() => {
this.statsService.resetStats();
this.comments = undefined;
this.selectedEquipment = "";
this.withCutaway = false;
this.isSpecial = false;
@@ -233,6 +251,7 @@ export class NewJumpComponent implements OnInit {
this.listOfFilteredDropZone = this.listOfDropZone;
this.comments = undefined;
this.selectedEquipment = "";
this.withCutaway = false;
this.isSpecial = false;
@@ -99,6 +99,7 @@ export class SummaryComponent implements OnInit {
}
public refreshStats() {
this.serviceApi.resetStats();
this.serviceApi.deleteAllCache();
this.tabGroup.selectedIndex = 0;
}
+10 -1
View File
@@ -120,6 +120,7 @@
"NewJump_Count": "Count of jumps",
"NewJump_Comments": "Comments",
"NewJump_Submit": "Submit",
"NewJump_Equipment": "Equipment",
"NewTunnelFlight_ChooseTunnel": "Choose the tunnel",
"NewTunnelFlight_Minutes": "Minutes of the flight",
@@ -143,5 +144,13 @@
"UserProfile_Mail": "E-mail",
"UserProfile_Lastname": "Lastname",
"UserProfile_Firstname": "Firstname",
"UserProfile_Login": "Login"
"UserProfile_Login": "Login",
"GearInfos_Name": "Name",
"GearInfos_Manufacturer": "Manufacturer",
"GearInfos_MinSize": "Min size",
"GearInfos_MaxSize": "Max size",
"GearInfos_AAD": "AAD system",
"GearInfos_MainCanopy": "Main canopy",
"GearInfos_ReserveCanopy": "Reserve canopy"
}
+10 -1
View File
@@ -120,6 +120,7 @@
"NewJump_Count": "Nombre de sauts",
"NewJump_Comments": "Commentaires",
"NewJump_Submit": "Ajouter",
"NewJump_Equipment": "Équipment",
"NewTunnelFlight_ChooseTunnel": "Choisir le tunnel",
"NewTunnelFlight_Minutes": "Temps de vol(minutes)",
@@ -143,5 +144,13 @@
"UserProfile_Mail": "E-mail",
"UserProfile_Lastname": "Nom",
"UserProfile_Firstname": "Prénom",
"UserProfile_Login": "Identifiant"
"UserProfile_Login": "Identifiant",
"GearInfos_Name": "Nom",
"GearInfos_Manufacturer": "Fabriquant",
"GearInfos_MinSize": "Taille min",
"GearInfos_MaxSize": "Taile max",
"GearInfos_AAD": "Système de sécurité",
"GearInfos_MainCanopy": "Voile principale",
"GearInfos_ReserveCanopy": "Voile de secours"
}
+22 -22
View File
@@ -1,29 +1,29 @@
export class GearReq {
constructor(data: any) {
Object.assign(this, data);
}
constructor(data: any) {
Object.assign(this, data);
}
public id: number;
public name: string;
public manufacturer: string;
public minSize: number;
public maxSize: number;
public aad: string;
public mainCanopy: string;
public reserveCanopy: string;
public id: number;
public name: string;
public manufacturer: string;
public minSize: number;
public maxSize: number;
public aad: string;
public mainCanopy: string;
public reserveCanopy: string;
}
export class GearResp {
constructor(data: any) {
Object.assign(this, data);
}
constructor(data: any) {
Object.assign(this, data);
}
public id: number;
public name: string;
public manufacturer: string;
public minSize: number;
public maxSize: number;
public aad: string;
public mainCanopy: string;
public reserveCanopy: string;
public id: number;
public name: string;
public manufacturer: string;
public minSize: number;
public maxSize: number;
public aad: string;
public mainCanopy: string;
public reserveCanopy: string;
}
+56 -53
View File
@@ -1,66 +1,69 @@
import { GearResp } from './gear';
import { DropZoneResp } from './dropzone';
import { AircraftResp } from './aircraft';
import { JumpTypeResp } from './jumpType';
import { GearResp } from "./gear";
import { DropZoneResp } from "./dropzone";
import { AircraftResp } from "./aircraft";
import { JumpTypeResp } from "./jumpType";
export class JumpReq {
constructor(data: any) {
Object.assign(this, data);
}
constructor(data: any) {
Object.assign(this, data);
}
public id: number;
public jumpTypeId: number;
public aircraftId: number;
public dropZoneId: number;
public gearId: number;
public exitAltitude: number;
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: string;
public isSpecial: boolean;
public id: number;
public jumpTypeId: number;
public aircraftId: number;
public dropZoneId: number;
public gearId: number;
public exitAltitude: number;
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: string;
public isSpecial: boolean;
public equipment: string;
}
export class JumpResp {
constructor(data: any) {
Object.assign(this, data);
this.jumpDate = new Date(data.jumpDate);
}
constructor(data: any) {
Object.assign(this, data);
this.jumpDate = new Date(data.jumpDate);
}
public id: number;
public jumpType: JumpTypeResp;
public aircraft: AircraftResp;
public dropZone: DropZoneResp;
public gear: GearResp;
public id: number;
public jumpType: JumpTypeResp;
public aircraft: AircraftResp;
public dropZone: DropZoneResp;
public gear: GearResp;
public jumpTypeId: number;
public aircraftId: number;
public dropZoneId: number;
public gearId: number;
public jumpTypeId: number;
public aircraftId: number;
public dropZoneId: number;
public gearId: number;
public exitAltitude: number;
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: Date;
public isSpecial: boolean;
public exitAltitude: number;
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: Date;
public isSpecial: boolean;
public equipment: string;
}
export class Jump {
constructor(data: any) {
Object.assign(this, data);
this.jumpDate = new Date(data.jumpDate);
}
constructor(data: any) {
Object.assign(this, data);
this.jumpDate = new Date(data.jumpDate);
}
public id: number;
public jumpType: JumpTypeResp;
public aircraft: AircraftResp;
public dropZone: DropZoneResp;
public gear: GearResp;
public exitAltitude: number;
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: Date;
public isSpecial: boolean;
}
public id: number;
public jumpType: JumpTypeResp;
public aircraft: AircraftResp;
public dropZone: DropZoneResp;
public gear: GearResp;
public exitAltitude: number;
public deployAltitude: number;
public withCutaway: boolean;
public notes: string;
public jumpDate: Date;
public isSpecial: boolean;
public equipment: string;
}
@@ -10,46 +10,85 @@ import { CacheApiKey } from "../models/cache-api-key.enum";
@Injectable()
export class GearService extends BaseService {
constructor(private http: HttpClient) {
super();
}
constructor(private http: HttpClient) {
super();
}
public getListOfGears(): Observable<Array<GearResp>> {
let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, { headers: this.headers });
return this.serviceCacheApi.get<Array<GearResp>>(CacheApiKey.Gear, callToApi);
}
public getListOfGears(): Observable<Array<GearResp>> {
let callToApi = this.http.get<Array<GearResp>>(`${this.apiUrl}/Gear`, {
headers: this.headers,
});
return this.serviceCacheApi.get<Array<GearResp>>(
CacheApiKey.Gear,
callToApi,
);
}
public addGear(name: string,
manufacturer: string,
minSize: number,
maxSize: number,
aad: string,
mainCanopy: string,
reserveCanopy: string)
{
const bodyNewGear: GearReq = {
id: 0,
name: name,
manufacturer: manufacturer,
minSize: minSize,
maxSize: maxSize,
aad: aad,
mainCanopy: mainCanopy,
reserveCanopy: reserveCanopy
};
public addGear(
name: string,
manufacturer: string,
minSize: number,
maxSize: number,
aad: string,
mainCanopy: string,
reserveCanopy: string,
) {
const bodyNewGear: GearReq = {
id: 0,
name: name,
manufacturer: manufacturer,
minSize: minSize,
maxSize: maxSize,
aad: aad,
mainCanopy: mainCanopy,
reserveCanopy: reserveCanopy,
};
this.serviceCacheApi.delete(CacheApiKey.Gear);
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, { headers: this.headers});
}
this.serviceCacheApi.delete(CacheApiKey.Gear);
return this.http.post(`${this.apiUrl}/Gear`, bodyNewGear, {
headers: this.headers,
});
}
public getById(id: number) : Observable<GearResp> {
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear)
.pipe(map(data => {
return data.find(f => f.id === id);
}));
}
public getById(id: number): Observable<GearResp> {
return this.serviceCacheApi
.getByKey<Array<GearResp>>(CacheApiKey.Gear)
.pipe(
map((data) => {
return data.find((f) => f.id === id);
}),
);
}
public getFromCache(): Observable<Array<GearResp>> {
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear);
}
public getFromCache(): Observable<Array<GearResp>> {
return this.serviceCacheApi.getByKey<Array<GearResp>>(CacheApiKey.Gear);
}
public updateGear(
id: number,
name: string,
manufacturer: string,
minSize: number,
maxSize: number,
aad: string,
mainCanopy: string,
reserveCanopy: string,
) {
const gearData = {
id: id,
name: name,
manufacturer: manufacturer,
minSize: minSize,
maxSize: maxSize,
aad: aad,
mainCanopy: mainCanopy,
reserveCanopy: reserveCanopy,
};
const bodyUpdatedGear = new GearReq(gearData);
this.serviceCacheApi.delete(CacheApiKey.Gear);
return this.http.put(`${this.apiUrl}/Gear/${id}`, bodyUpdatedGear, {
headers: this.headers,
});
}
}
+184 -138
View File
@@ -1,6 +1,6 @@
import { Injectable } from "@angular/core";
import { HttpClient } from "@angular/common/http";
import { DatePipe } from '@angular/common';
import { DatePipe } from "@angular/common";
import { forkJoin, Observable } from "rxjs";
import { map } from "rxjs/operators";
@@ -20,158 +20,204 @@ import { GearService } from "./gear.service";
@Injectable()
export class JumpService extends BaseService {
private callsToAdd: Array<Observable<any>>;
private callsToAdd: Array<Observable<any>>;
constructor(private http: HttpClient,
private dateService: DateService,
private datePipe: DatePipe,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService) {
super();
}
constructor(
private http: HttpClient,
private dateService: DateService,
private datePipe: DatePipe,
private dropzoneService: DropzoneService,
private aircraftService: AircraftService,
private jumpTypeService: JumpTypeService,
private gearService: GearService,
) {
super();
}
public getListOfJumps(): Observable<Array<Jump>> {
return this.http.get<Array<JumpResp>>(`${this.apiUrl}/Jump`, { headers: this.headers })
.pipe(map((response) => {
return this.mapWithDataInCache(response);
}));
}
public getListOfJumps(): Observable<Array<Jump>> {
return this.http
.get<
Array<JumpResp>
>(`${this.apiUrl}/Jump`, { headers: this.headers })
.pipe(
map((response) => {
return this.mapWithDataInCache(response);
}),
);
}
public getJumps(beginIndex: number, endIndex: number): Observable<JumpList> {
return this.http.get<JumpListResp>(`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`, { headers: this.headers })
.pipe(map(response => {
let result: JumpList = {
public getJumps(
beginIndex: number,
endIndex: number,
): Observable<JumpList> {
return this.http
.get<JumpListResp>(
`${this.apiUrl}/Jump/${beginIndex}/${endIndex}`,
{ headers: this.headers },
)
.pipe(
map((response) => {
let result: JumpList = {
rows: this.mapWithDataInCache(response.rows),
count: response.count
};
count: response.count,
};
return new JumpList(result);
}));
}
public addListOfJump(selectedJumpType: number,
selectedAircraft: number,
selectedDz: number,
selectedRig: number,
withCutaway: boolean,
beginDate: Date,
endDate: Date,
defaultExitAltitude: number,
defaultDeployAltitude: number,
countOfJumps: number,
notes: string,
isSpecial: boolean): Observable<any[]> {
this.callsToAdd = new Array<Observable<any>>();
const diffInDays = this.dateService.diffBetweenDates(beginDate, endDate) + 1;
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
for (let i = 1; beginDate.getTime() < endDate.getTime(); i++) {
this.addJumps(selectedJumpType,
selectedAircraft,
selectedDz,
selectedRig,
withCutaway,
beginDate,
defaultExitAltitude,
defaultDeployAltitude,
countOfJumpsPerDay,
notes,
isSpecial);
beginDate = this.dateService.addDays(beginDate, 1);
return new JumpList(result);
}),
);
}
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
public addListOfJump(
selectedJumpType: number,
selectedAircraft: number,
selectedDz: number,
selectedGear: number,
withCutaway: boolean,
beginDate: Date,
endDate: Date,
defaultExitAltitude: number,
defaultDeployAltitude: number,
countOfJumps: number,
notes: string,
isSpecial: boolean,
equipment: string,
): Observable<any[]> {
this.callsToAdd = new Array<Observable<any>>();
const diffInDays =
this.dateService.diffBetweenDates(beginDate, endDate) + 1;
const countOfJumpsPerDay = Math.trunc(countOfJumps / diffInDays);
this.addJumps(selectedJumpType,
selectedAircraft,
selectedDz,
selectedRig,
withCutaway,
beginDate,
defaultExitAltitude,
defaultDeployAltitude,
restfJumps,
notes,
isSpecial);
for (let i = 1; beginDate.getTime() < endDate.getTime(); i++) {
this.addJumps(
selectedJumpType,
selectedAircraft,
selectedDz,
selectedGear,
withCutaway,
beginDate,
defaultExitAltitude,
defaultDeployAltitude,
countOfJumpsPerDay,
notes,
isSpecial,
equipment,
);
return forkJoin(this.callsToAdd);
}
beginDate = this.dateService.addDays(beginDate, 1);
}
public deleteJump(item: Jump) {
this.http.delete(`${this.apiUrl}/Jump/${item.id}`, { headers: this.headers }).subscribe();
}
const restfJumps = countOfJumps - countOfJumpsPerDay * (diffInDays - 1);
public updateJump(id: number,
isSpecial: boolean,
withCutaway: boolean,
notes: string) {
const jumpData = {
id: id,
isSpecial: isSpecial,
withCutaway: withCutaway,
notes: notes
};
const bodyUpdatedJump = new JumpReq(jumpData);
this.addJumps(
selectedJumpType,
selectedAircraft,
selectedDz,
selectedGear,
withCutaway,
beginDate,
defaultExitAltitude,
defaultDeployAltitude,
restfJumps,
notes,
isSpecial,
equipment,
);
return this.http.put(`${this.apiUrl}/Jump/${id}`,
bodyUpdatedJump,
{ headers: this.headers, });
}
private addJumps(selectedJumpType: number,
selectedAircraft: number,
selectedDz: number,
selectedRig: number,
withCutaway: boolean,
jumpDate: Date,
defaultExitAltitude: number,
defaultDeployAltitude: number,
countOfJumps: number,
notes: string,
isSpecial: boolean) {
for (let i = 0; i < countOfJumps; i++) {
const bodyNewjump: JumpReq = {
jumpTypeId: selectedJumpType,
aircraftId: selectedAircraft,
dropZoneId: selectedDz,
withCutaway: withCutaway,
exitAltitude: defaultExitAltitude,
deployAltitude: defaultDeployAltitude,
gearId: selectedRig,
notes: notes,
id: 0,
jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd"),
isSpecial: isSpecial
};
let call = this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, { headers: this.headers });
this.callsToAdd.push(call);
return forkJoin(this.callsToAdd);
}
}
private mapWithDataInCache(apiResp: Array<JumpResp>): Array<Jump> {
let allDropzones: Array<DropZoneResp>;
this.dropzoneService.getFromCache().subscribe(data => { allDropzones = data; });
let allAircrafts: Array<AircraftResp>;
this.aircraftService.getFromCache().subscribe(data => { allAircrafts = data; });
let allJumpType: Array<JumpTypeResp>;
this.jumpTypeService.getFromCache().subscribe(data => { allJumpType = data; });
let allGears: Array<GearResp>;
this.gearService.getFromCache().subscribe(data => { allGears = data; });
public deleteJump(item: Jump) {
this.http
.delete(`${this.apiUrl}/Jump/${item.id}`, { headers: this.headers })
.subscribe();
}
return apiResp.map((data) => {
let tmp = new Jump(data);
public updateJump(
id: number,
isSpecial: boolean,
withCutaway: boolean,
notes: string,
equipment: string,
) {
const jumpData = {
id: id,
isSpecial: isSpecial,
withCutaway: withCutaway,
notes: notes,
equipment: equipment,
};
const bodyUpdatedJump = new JumpReq(jumpData);
tmp.dropZone = allDropzones.find(d => d.id == data.dropZoneId);
tmp.aircraft = allAircrafts.find(d => d.id == data.aircraftId);
tmp.jumpType = allJumpType.find(d => d.id == data.jumpTypeId);
tmp.gear = allGears.find(d => d.id == data.gearId);
return this.http.put(`${this.apiUrl}/Jump/${id}`, bodyUpdatedJump, {
headers: this.headers,
});
}
return tmp;
});
}
private addJumps(
selectedJumpType: number,
selectedAircraft: number,
selectedDz: number,
selectedGear: number,
withCutaway: boolean,
jumpDate: Date,
defaultExitAltitude: number,
defaultDeployAltitude: number,
countOfJumps: number,
notes: string,
isSpecial: boolean,
equipment: string,
) {
for (let i = 0; i < countOfJumps; i++) {
const bodyNewjump: JumpReq = {
jumpTypeId: selectedJumpType,
aircraftId: selectedAircraft,
dropZoneId: selectedDz,
withCutaway: withCutaway,
exitAltitude: defaultExitAltitude,
deployAltitude: defaultDeployAltitude,
gearId: selectedGear,
notes: notes,
id: 0,
jumpDate: this.datePipe.transform(jumpDate, "yyyy-MM-dd"),
isSpecial: isSpecial,
equipment: equipment,
};
let call = this.http.post(`${this.apiUrl}/Jump`, bodyNewjump, {
headers: this.headers,
});
this.callsToAdd.push(call);
}
}
private mapWithDataInCache(apiResp: Array<JumpResp>): Array<Jump> {
let allDropzones: Array<DropZoneResp>;
this.dropzoneService.getFromCache().subscribe((data) => {
allDropzones = data;
});
let allAircrafts: Array<AircraftResp>;
this.aircraftService.getFromCache().subscribe((data) => {
allAircrafts = data;
});
let allJumpType: Array<JumpTypeResp>;
this.jumpTypeService.getFromCache().subscribe((data) => {
allJumpType = data;
});
let allGears: Array<GearResp>;
this.gearService.getFromCache().subscribe((data) => {
allGears = data;
});
return apiResp.map((data) => {
let tmp = new Jump(data);
tmp.dropZone = allDropzones.find((d) => d.id == data.dropZoneId);
tmp.aircraft = allAircrafts.find((d) => d.id == data.aircraftId);
tmp.jumpType = allJumpType.find((d) => d.id == data.jumpTypeId);
tmp.gear = allGears.find((d) => d.id == data.gearId);
return tmp;
});
}
}