Files
CT/src/Model/Global/settingsModel.ts
T

46 lines
1.0 KiB
TypeScript
Raw Normal View History

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;
2024-07-22 02:23:21 +02:00
// data
2024-07-20 00:22:53 +02:00
username: string;
2024-07-22 01:13:20 +02:00
firstDayOfWeek: string;
2024-07-20 00:22:53 +02:00
// 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
}
2024-07-22 01:13:20 +02:00
setFirstDayOfWeek(newValue: string): void {
2024-07-20 00:22:53 +02:00
this.firstDayOfWeek = newValue;
const path = storageKeys.firstDayOfWeek;
2024-07-22 01:13:20 +02:00
this.storageModel.write(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);
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-22 01:13:20 +02:00
const content = this.storageModel.read(path);
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
}
}