Skip to content

Commit

Permalink
Implemented surface interval with buttons
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Dec 11, 2023
1 parent 6e3b9d2 commit 9fcd33f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,15 @@
</div>
<div *ngIf="true" class="mb-4 col col-12 col-md-6 col-lg-12 col-xl-6">
<label for="duration" class="form-label" mdbLabel>Surface interval [min]:</label>
<input id="surfaceInterval" formControlName="mask" class="form-control" (input)="valuesChanged()"
<input id="surfaceInterval" formControlName="surfaceInterval" class="form-control" (input)="valuesChanged()"
type="text" required [class.is-invalid]="surfaceIntervalInvalid"
[maskito]="maskitoTimeOptions" placeholder="HH:MM"/>
[maskito]="maskitoTimeOptions" [placeholder]="placeHolder" [readonly]="surfaceReadOnly" />
<div class="invalid-feedback position-absolute">Needs to text in form hh:mm
</div>
<button type="button" class="btn btn-secondary mt-2 me-2 col col-auto" (click)="applyFirst()"
[class.invisible]="isFirstDive" id="btnApplyFirst">First dive</button>
<button type="button" class="btn btn-secondary mt-2 col col-auto" (click)="applyOneHour()"
[class.invisible]="isFirstDive" id="btnApplyOneHour">1 Hour</button>
</div>
</div>
</form>
Expand Down
46 changes: 35 additions & 11 deletions projects/planner/src/app/depths-simple/depths-simple.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,14 @@ import { DiveResults } from '../shared/diveresults';
import { Streamed } from '../shared/streamed';
import { RangeConstants, UnitConversion } from '../shared/UnitConversion';
import { ValidatorGroups } from '../shared/ValidatorGroups';
import { Precision } from 'scuba-physics';
import { Precision, Time } from 'scuba-physics';
import { DiveSchedules } from '../shared/dive.schedules';
import { ReloadDispatcher } from '../shared/reloadDispatcher';
import { maskitoTimeOptionsGenerator } from '@maskito/kit';

interface SimpleDepthsForm {
planDuration: FormControl<number>;
surfaceInterval: FormControl<number>;
mask: FormControl<Date>;
surfaceInterval: FormControl<Date>;
}

@Component({
Expand Down Expand Up @@ -69,19 +68,32 @@ export class DepthsSimpleComponent extends Streamed implements OnInit {
return false;
}

private get surfaceInterval(): number {
return this.schedules.selected.surfaceInterval;
public get surfaceReadOnly(): boolean {
return this.schedules.selected.surfaceInterval === Number.POSITIVE_INFINITY;
}

private set surfaceInterval(newValue: number) {
this.schedules.selected.surfaceInterval = newValue;
public get isFirstDive(): boolean {
return this.schedules.selected.isFirst;
}

public get placeHolder(): string {
return this.surfaceReadOnly ? 'First dive' : 'HH:MM';
}

private get surfaceInterval(): Date {
const currentSeconds = this.schedules.selected.surfaceInterval;
return new Date(1970, 1,1, 0, 0, currentSeconds, 0);
}

private set surfaceInterval(newValue: Date | undefined) {
const newSeconds = newValue ? newValue.getSeconds() : Number.POSITIVE_INFINITY;
this.setSurfaceIntervalSeconds(newSeconds);
}

public ngOnInit(): void {
this.simpleForm = this.fb.group({
planDuration: [Precision.round(this.depths.planDuration, 1), this.validators.duration],
surfaceInterval: [this.surfaceInterval, this.validators.duration],
mask: [new Date(), []]
surfaceInterval: [this.surfaceInterval]
});

// Reload is not relevant here
Expand All @@ -102,9 +114,16 @@ export class DepthsSimpleComponent extends Streamed implements OnInit {
}

const newValue = this.simpleForm.value;
this.surfaceInterval = Number(newValue.surfaceInterval);
this.surfaceInterval = newValue.surfaceInterval;
this.depths.planDuration = Number(newValue.planDuration);
console.log(newValue.mask);
}

public applyFirst(): void {
this.setSurfaceIntervalSeconds(Number.POSITIVE_INFINITY);
}

public applyOneHour(): void {
this.setSurfaceIntervalSeconds(Time.oneMinute * 60);
}

private reload(): void {
Expand All @@ -114,4 +133,9 @@ export class DepthsSimpleComponent extends Streamed implements OnInit {
surfaceInterval: this.surfaceInterval
});
}

private setSurfaceIntervalSeconds(newValue: number) {
this.schedules.selected.surfaceInterval = newValue;
this.reload();
}
}
6 changes: 5 additions & 1 deletion projects/planner/src/app/shared/dive.schedules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ export class DiveSchedule {
return this._id;
}

public get isFirst(): boolean {
return this.id === 1;
}

public get surfaceInterval(): number {
return this._surfaceInterval;
}
Expand Down Expand Up @@ -59,7 +63,7 @@ export class DiveSchedule {
* For first dive it is always POSITIVE_INFINITY.
*/
public set surfaceInterval(newValue: number) {
if(this.id === 1 || newValue < 0) {
if(this.isFirst || newValue < 0) {
return;
}

Expand Down
1 change: 0 additions & 1 deletion projects/planner/src/app/shared/preferencesStore.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { Injectable } from '@angular/core';
import { PlannerService } from './planner.service';
import { Preferences } from './preferences';
import { AppPreferences, DiveDto } from './serialization.model';
import { DiveSchedule } from './dive.schedules';
Expand Down

0 comments on commit 9fcd33f

Please sign in to comment.