diff --git a/projects/planner/src/app/app-settings/app-settings.component.spec.ts b/projects/planner/src/app/app-settings/app-settings.component.spec.ts index a3695791..2c61a984 100644 --- a/projects/planner/src/app/app-settings/app-settings.component.spec.ts +++ b/projects/planner/src/app/app-settings/app-settings.component.spec.ts @@ -85,8 +85,6 @@ describe('App settings component', () => { // TODO AppSettings: // * After changing units, also the range values need to be reloaded // * Add save and load last form state. Do we want this? Or together with reset to default? -// * Apply to algorithm -// * add to normalization service // TODO missing test cases: diff --git a/projects/planner/src/app/app-settings/app-settings.component.ts b/projects/planner/src/app/app-settings/app-settings.component.ts index 52ec19f6..160fa7cc 100644 --- a/projects/planner/src/app/app-settings/app-settings.component.ts +++ b/projects/planner/src/app/app-settings/app-settings.component.ts @@ -50,16 +50,12 @@ export class AppSettingsComponent implements OnInit { return this.inputs.controlInValid(densityControl); } - public get densityRounding(): number { - return this.units.imperialUnits ? 3 : 1; - } - public get densityStep(): number { - return Math.pow(0.1, this.densityRounding); + return Math.pow(0.1, this.ranges.densityRounding); } private get maxDensity(): number { - return Precision.round(this.appSettings.maxGasDensity, this.densityRounding); + return Precision.round(this.appSettings.maxGasDensity, this.ranges.densityRounding); } public ngOnInit(): void { diff --git a/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts b/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts index 2afcbf34..77b26c4d 100644 --- a/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts +++ b/projects/planner/src/app/shared/PlanUrlSerialization.spec.ts @@ -49,7 +49,7 @@ describe('Url Serialization', () => { const appSettings = new ApplicationSettingsService(units); const planner = new PlannerService(schedules, dispatcher, viewSwitch, appSettings, irrelevantFactory, units); const preferences = new Preferences(viewSwitch, units, schedules, appSettings, new ViewStates()); - const normalization = new SettingsNormalizationService(units, schedules); + const normalization = new SettingsNormalizationService(units, appSettings, schedules); const urlSerialization = new PlanUrlSerialization(viewSwitch, units, normalization, schedules, appSettings, preferences); const firstDive = schedules.dives[0]; diff --git a/projects/planner/src/app/shared/UnitConversion.ts b/projects/planner/src/app/shared/UnitConversion.ts index 3ef86089..5f1245ba 100644 --- a/projects/planner/src/app/shared/UnitConversion.ts +++ b/projects/planner/src/app/shared/UnitConversion.ts @@ -172,6 +172,7 @@ export interface RangeConstants { depthLabel: string; maxDensity: [number, number]; maxDensityLabel: string; + densityRounding: number; narcoticDepth: [number, number]; narcoticDepthLabel: string; lastStopDepth: [number, number]; @@ -205,6 +206,7 @@ class MetricRanges implements RangeConstants { public readonly durationLabel: string = toLabel(this.duration, 'min'); public readonly maxDensity: [number, number] = [1, 10]; public readonly maxDensityLabel: string = toLabel(this.maxDensity, this.units.densityShortcut); + public readonly densityRounding: number = 1; public readonly narcoticDepth: [number, number] = [1, 100]; public readonly narcoticDepthLabel: string = toLabel(this.narcoticDepth, this.units.lengthShortcut); public readonly nitroxOxygen: [number, number] = [21, 100]; @@ -243,6 +245,7 @@ class ImperialRanges implements RangeConstants { public readonly durationLabel: string = toLabel(this.duration, 'min'); public readonly maxDensity: [number, number] = [0.0624, 0.624]; public readonly maxDensityLabel: string = toLabel(this.maxDensity, this.units.densityShortcut); + public readonly densityRounding: number = 4; public readonly narcoticDepth: [number, number] = [1, 300]; public readonly narcoticDepthLabel: string = toLabel(this.narcoticDepth, this.units.lengthShortcut); public readonly nitroxOxygen: [number, number] = [21, 100]; diff --git a/projects/planner/src/app/shared/settings-normalization.service.spec.ts b/projects/planner/src/app/shared/settings-normalization.service.spec.ts index fe1e781c..9e3d2ac8 100644 --- a/projects/planner/src/app/shared/settings-normalization.service.spec.ts +++ b/projects/planner/src/app/shared/settings-normalization.service.spec.ts @@ -10,6 +10,7 @@ import { DiverOptions } from './models'; import { DiveSchedules } from './dive.schedules'; import { ViewStates } from './viewStates'; import { ReloadDispatcher } from './reloadDispatcher'; +import { ApplicationSettingsService } from './ApplicationSettings'; describe('SettingsNormalizationService', () => { let service: SettingsNormalizationService; @@ -30,7 +31,8 @@ describe('SettingsNormalizationService', () => { providers: [ RouterTestingModule, UnitConversion, SettingsNormalizationService, ReloadDispatcher, - ViewStates, DiveSchedules + ViewStates, DiveSchedules, + ApplicationSettingsService ], imports: [RouterTestingModule.withRoutes([])] }); diff --git a/projects/planner/src/app/shared/settings-normalization.service.ts b/projects/planner/src/app/shared/settings-normalization.service.ts index 51d309a6..6a625c21 100644 --- a/projects/planner/src/app/shared/settings-normalization.service.ts +++ b/projects/planner/src/app/shared/settings-normalization.service.ts @@ -3,14 +3,15 @@ import { Precision } from 'scuba-physics'; import { OptionsService } from './options.service'; import { TanksService } from './tanks.service'; import { RangeConstants, UnitConversion } from './UnitConversion'; -import { ViewStates } from './viewStates'; import { DepthsService } from './depths.service'; import { DiveSchedule, DiveSchedules } from './dive.schedules'; +import { ApplicationSettingsService } from './ApplicationSettings'; @Injectable() export class SettingsNormalizationService { constructor( private units: UnitConversion, + private appSettings: ApplicationSettingsService, private schedules: DiveSchedules ) { } @@ -28,6 +29,16 @@ export class SettingsNormalizationService { this.normalizeSegments(dive.depths); } + private applyToAppSettings(): void { + const settings = this.appSettings.settings; + const densityRounding = this.units.ranges.densityRounding; + + settings.maxGasDensity = this.fitUnit( + v => this.units.fromGramPerLiter(v), + v => this.units.toGramPerLiter(v), + settings.maxGasDensity, this.units.ranges.maxDensity, densityRounding); + } + private applyToOptions(options: OptionsService): void { const oDiver = options.diverOptions; const rmvRounding = this.units.ranges.rmvRounding;