diff --git a/projects/planner/src/app/depths-simple/depths-simple.component.html b/projects/planner/src/app/depths-simple/depths-simple.component.html index 72179a3f..0df05686 100644 --- a/projects/planner/src/app/depths-simple/depths-simple.component.html +++ b/projects/planner/src/app/depths-simple/depths-simple.component.html @@ -25,11 +25,15 @@
- + [maskito]="maskitoTimeOptions" [placeholder]="placeHolder" [readonly]="surfaceReadOnly" />
Needs to text in form hh:mm
+ +
diff --git a/projects/planner/src/app/depths-simple/depths-simple.component.ts b/projects/planner/src/app/depths-simple/depths-simple.component.ts index 43f0d747..b1f54c28 100644 --- a/projects/planner/src/app/depths-simple/depths-simple.component.ts +++ b/projects/planner/src/app/depths-simple/depths-simple.component.ts @@ -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; - surfaceInterval: FormControl; - mask: FormControl; + surfaceInterval: FormControl; } @Component({ @@ -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 @@ -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 { @@ -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(); + } } diff --git a/projects/planner/src/app/shared/dive.schedules.ts b/projects/planner/src/app/shared/dive.schedules.ts index 270b5382..cf598b5f 100644 --- a/projects/planner/src/app/shared/dive.schedules.ts +++ b/projects/planner/src/app/shared/dive.schedules.ts @@ -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; } @@ -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; } diff --git a/projects/planner/src/app/shared/preferencesStore.ts b/projects/planner/src/app/shared/preferencesStore.ts index d5d6fd50..e7788cd9 100644 --- a/projects/planner/src/app/shared/preferencesStore.ts +++ b/projects/planner/src/app/shared/preferencesStore.ts @@ -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';