Files
CT/src/ViewModel/Utility/taskPropertyBulkChangeViewModel.ts
T

75 lines
2.1 KiB
TypeScript
Raw Normal View History

2024-07-25 02:49:23 +02:00
import * as React from "bloatless-react";
2024-07-25 15:31:27 +02:00
import TaskViewModel from "../Pages/taskViewModel";
2024-07-25 02:49:23 +02:00
export default class TaskPropertyBulkChangeViewModel {
2026-04-01 08:29:39 +00:00
taskViewModels: React.ListState<TaskViewModel>;
2024-07-25 02:49:23 +02:00
2026-04-01 08:29:39 +00:00
// state
inputValue: React.State<string> = new React.State("");
2024-07-25 02:49:23 +02:00
2026-04-01 08:29:39 +00:00
// guards
cannotSet: React.State<boolean>;
2024-07-25 02:49:23 +02:00
2026-04-01 08:29:39 +00:00
// methods
set = (): void => {
if (this.cannotSet.value == true) return;
this.taskViewModels.value.forEach((taskViewModel: TaskViewModel) => {
this.setValue(this.inputValue.value, taskViewModel);
});
};
2024-07-25 02:49:23 +02:00
setValue: (newValue: string, taskViewModel: TaskViewModel) => void = () => {};
2024-07-25 02:49:23 +02:00
2026-04-01 08:29:39 +00:00
// init
constructor(
taskViewModels: React.ListState<TaskViewModel>,
valueSetter: (newValue: string, taskViewModel: TaskViewModel) => void,
initialValue: string,
) {
this.taskViewModels = taskViewModels;
this.inputValue.value = initialValue;
2024-07-25 02:49:23 +02:00
2026-04-01 08:29:39 +00:00
this.setValue = valueSetter;
2024-07-25 02:49:23 +02:00
2026-04-01 08:29:39 +00:00
this.cannotSet = React.createProxyState(
[this.inputValue],
() =>
this.inputValue.value == "" ||
this.inputValue.value == initialValue,
);
}
2024-07-25 02:49:23 +02:00
}
export class TaskCategoryBulkChangeViewModel extends TaskPropertyBulkChangeViewModel {
2026-04-01 08:29:39 +00:00
constructor(
taskViewModels: React.ListState<TaskViewModel>,
initialValue: string,
) {
super(
taskViewModels,
(newCategory: string, taskViewModel: TaskViewModel) => {
taskViewModel.category.value = newCategory;
taskViewModel.save();
},
initialValue,
);
}
2024-07-25 02:49:23 +02:00
}
2024-07-25 04:12:30 +02:00
export class TaskStatusBulkChangeViewModel extends TaskPropertyBulkChangeViewModel {
2026-04-01 08:29:39 +00:00
constructor(
taskViewModels: React.ListState<TaskViewModel>,
initialValue: string,
) {
super(
taskViewModels,
(newStatus: string, taskViewModel: TaskViewModel) => {
taskViewModel.status.value = newStatus;
taskViewModel.save();
},
initialValue,
);
}
2024-07-25 04:12:30 +02:00
}