2024-07-20 00:22:53 +02:00
|
|
|
// this file is responsible for all settings.
|
|
|
|
|
|
|
|
|
|
import StorageModel, { storageKeys } from "./storageModel";
|
|
|
|
|
|
|
|
|
|
export default class SettingsModel {
|
|
|
|
|
storageModel: StorageModel;
|
|
|
|
|
|
|
|
|
|
username: string;
|
|
|
|
|
firstDayOfWeek: number;
|
|
|
|
|
|
|
|
|
|
// set
|
|
|
|
|
setName(newValue: string): void {
|
|
|
|
|
this.username = newValue;
|
|
|
|
|
const path = storageKeys.username;
|
2024-07-21 21:41:19 +02:00
|
|
|
this.storageModel.write(path, newValue);
|
2024-07-20 00:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
setFirstDayOfWeek(newValue: number): void {
|
|
|
|
|
this.firstDayOfWeek = newValue;
|
|
|
|
|
const path = storageKeys.firstDayOfWeek;
|
2024-07-21 21:41:19 +02:00
|
|
|
this.storageModel.writeStringifiable(path, newValue);
|
2024-07-20 00:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-21 21:41:19 +02:00
|
|
|
// load
|
|
|
|
|
loadUsernam(): void {
|
2024-07-20 00:22:53 +02:00
|
|
|
const path = storageKeys.username;
|
2024-07-21 21:41:19 +02:00
|
|
|
const content = this.storageModel.read(path);
|
2024-07-20 02:00:00 +02:00
|
|
|
this.username = content ?? "";
|
2024-07-20 00:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-21 21:41:19 +02:00
|
|
|
loadFirstDayofWeek(): void {
|
2024-07-20 00:22:53 +02:00
|
|
|
const path = storageKeys.firstDayOfWeek;
|
2024-07-21 21:41:19 +02:00
|
|
|
const content = this.storageModel.readStringifiable(path);
|
2024-07-20 02:00:00 +02:00
|
|
|
this.firstDayOfWeek = content ?? 0;
|
2024-07-20 00:22:53 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// init
|
|
|
|
|
constructor(storageModel: StorageModel) {
|
|
|
|
|
this.storageModel = storageModel;
|
|
|
|
|
|
2024-07-21 21:41:19 +02:00
|
|
|
this.loadUsernam();
|
|
|
|
|
this.loadFirstDayofWeek();
|
2024-07-20 00:22:53 +02:00
|
|
|
}
|
|
|
|
|
}
|