Skip to content

Commit

Permalink
Added app settings service
Browse files Browse the repository at this point in the history
  • Loading branch information
jirkapok committed Aug 8, 2024
1 parent dfc6f56 commit 3767f25
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 1 deletion.
35 changes: 35 additions & 0 deletions projects/planner/src/app/shared/ApplicationSettings.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import { TestBed } from '@angular/core/testing';
import { ApplicationSettingsService } from './ApplicationSettings';
import { UnitConversion } from './UnitConversion';

describe('ApplicationSettingsService', () => {
let sut: ApplicationSettingsService;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [],
imports: [],
providers: [
ApplicationSettingsService, UnitConversion
]
}).compileComponents();

sut = TestBed.inject(ApplicationSettingsService);
});

it('Applies gas density', () => {
sut.maxGasDensity = 5.3;
expect(sut.maxGasDensity).toBeCloseTo(5.3, 3);
});

describe('Imperial units', () => {
beforeEach(() => {
const units = TestBed.inject(UnitConversion);
units.imperialUnits = true;
});

it('Applies gas density in lbs/cuft', () => {
expect(sut.maxGasDensity).toBeCloseTo(0.35583938, 8);
});
});
});
30 changes: 30 additions & 0 deletions projects/planner/src/app/shared/ApplicationSettings.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import { Injectable } from '@angular/core';
import { UnitConversion } from './UnitConversion';
import { GasDensity } from 'scuba-physics';

// TODO AppSettings:
// * add to normalization service
// * Add to application serialization settings
// * Don't add to url

export class AppSettings {
public maxGasDensity = GasDensity.recommendedMaximum;
public priamryTankReserve = 30;
public stageTankReserve = 30;
}

@Injectable()
export class ApplicationSettingsService {
public appSettings = new AppSettings();

constructor(private units: UnitConversion) {
}

public get maxGasDensity(): number {
return this.units.fromGramPerLiter(this.appSettings.maxGasDensity);
}

public set maxGasDensity(value: number) {
this.appSettings.maxGasDensity = this.units.toGramPerLiter(value);
}
}
6 changes: 5 additions & 1 deletion projects/planner/src/app/shared/UnitConversion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,10 @@ export class UnitConversion {
return this.current.fromGramPerLiter(density);
}

public toGramPerLiter(density: number): number {
return this.current.toGramPerLiter(density);
}

public fromKilogram(weight: number): number {
return this.current.fromKilogram(weight);
}
Expand Down Expand Up @@ -173,7 +177,7 @@ export interface RangeConstants {
duration: [number, number];
durationLabel: string;
altitude: [number, number];
altitudeLevels: [number, number, number, number]
altitudeLevels: [number, number, number, number];
altitudeLabel: string;
altitudePressure: [number, number];
speed: [number, number];
Expand Down

0 comments on commit 3767f25

Please sign in to comment.