Files
CT/src/View/ChatPages/boardStatusGridPage.tsx
T

254 lines
8.2 KiB
TypeScript
Raw Normal View History

2024-07-25 04:12:30 +02:00
import * as React from "bloatless-react";
2024-07-25 18:42:06 +02:00
import {
2026-04-01 08:29:39 +00:00
PropertyValueList,
collectPropertyValuesToState,
createPropertyValueIndexState,
createSortedPropertyValueState,
2024-07-25 18:42:06 +02:00
} from "../Components/propertyValueList";
2024-07-25 04:12:30 +02:00
import {
2026-04-01 08:29:39 +00:00
TaskCategoryBulkChangeViewModel,
TaskStatusBulkChangeViewModel,
2024-07-25 15:31:27 +02:00
} from "../../ViewModel/Utility/taskPropertyBulkChangeViewModel";
2024-07-25 04:12:30 +02:00
import BoardViewModel from "../../ViewModel/Pages/boardViewModel";
import { FilteredList } from "../Components/filteredList";
import TaskViewModel from "../../ViewModel/Pages/taskViewModel";
import { TaskViewModelToEntry } from "../Components/taskEntry";
2024-07-25 16:24:09 +02:00
import { allowDrop } from "../utility";
2024-07-25 04:12:30 +02:00
import { translations } from "../translations";
export function BoardStatusGridPage(boardViewModel: BoardViewModel) {
2026-04-01 08:29:39 +00:00
const statuses: React.ListState<string> = new React.ListState();
const sortedStatuses: React.State<string[]> =
createSortedPropertyValueState(statuses);
boardViewModel.filteredTaskViewModels.subscribe(() => {
2026-04-01 08:29:39 +00:00
collectPropertyValuesToState(
"status",
(taskViewModel: TaskViewModel) => taskViewModel.task,
boardViewModel.filteredTaskViewModels,
2026-04-01 08:29:39 +00:00
statuses,
);
});
2024-07-25 18:42:06 +02:00
2026-04-01 08:29:39 +00:00
const statusNameCellConverter: React.StateItemConverter<string> = (
statusName: string,
) => {
const index = createPropertyValueIndexState(sortedStatuses, statusName);
return StatusNameCell(statusName, index, boardViewModel);
};
2024-07-25 18:42:06 +02:00
2026-04-01 08:29:39 +00:00
return (
<div class="status-page-content">
2024-07-25 04:12:30 +02:00
<div
2026-04-01 08:29:39 +00:00
class="status-name-row"
children:append={[statuses, statusNameCellConverter]}
2024-07-25 04:12:30 +02:00
></div>
2026-04-01 08:29:39 +00:00
{PropertyValueList(
"category",
(taskViewModel: TaskViewModel) => taskViewModel.task,
boardViewModel.filteredTaskViewModels,
(
categories: React.ListState<string>,
sortedCategories: React.State<string[]>,
) => {
const categoryRowConverter: React.StateItemConverter<
string
> = (categoryName: string) => {
const index: React.State<number> =
createPropertyValueIndexState(
sortedCategories,
categoryName,
);
return CategoryRow(
categoryName,
index,
statuses,
sortedStatuses,
boardViewModel,
);
};
return (
<div
class="status-grid-wrapper"
children:append={[categories, categoryRowConverter]}
></div>
);
},
)}
</div>
);
2024-07-25 04:12:30 +02:00
}
2024-07-25 18:42:06 +02:00
function StatusNameCell(
2026-04-01 08:29:39 +00:00
statusName: string,
index: React.State<number>,
boardViewModel: BoardViewModel,
2024-07-25 18:42:06 +02:00
) {
2026-04-01 08:29:39 +00:00
const taskViewModelsWithMatchingStatus: React.ListState<TaskViewModel> =
new React.ListState();
boardViewModel.filteredTaskViewModels.handleAddition(
(taskViewModel: TaskViewModel) => {
const doesMatchStatus: boolean =
taskViewModel.task.status == statusName;
if (doesMatchStatus == false) return;
taskViewModelsWithMatchingStatus.add(taskViewModel);
boardViewModel.filteredTaskViewModels.handleRemoval(
taskViewModel,
() => {
taskViewModelsWithMatchingStatus.remove(taskViewModel);
},
);
},
);
2024-07-25 04:12:30 +02:00
2026-04-01 08:29:39 +00:00
const viewModel: TaskStatusBulkChangeViewModel =
new TaskStatusBulkChangeViewModel(
taskViewModelsWithMatchingStatus,
statusName,
);
const view = (
<div class="flex-row">
<div class="property-input-wrapper">
<input
placeholder={
translations.chatPage.task.renameStatusInputPlaceholder
2026-04-01 08:29:39 +00:00
}
bind:value={viewModel.inputValue}
on:enter={viewModel.set}
></input>
<button
class="primary"
on:click={viewModel.set}
toggle:disabled={viewModel.cannotSet}
>
<span class="icon">check</span>
</button>
</div>
</div>
2024-07-25 04:12:30 +02:00
);
2026-04-01 08:29:39 +00:00
index.subscribe((newIndex) => {
view.style.order = newIndex;
});
return view;
2024-07-25 04:12:30 +02:00
}
function CategoryRow(
2026-04-01 08:29:39 +00:00
categoryName: string,
index: React.State<number>,
allStatuses: React.ListState<string>,
sortedStatuses: React.State<string[]>,
boardViewModel: BoardViewModel,
2024-07-25 04:12:30 +02:00
) {
2026-04-01 08:29:39 +00:00
return FilteredList(
{ category: categoryName },
(taskViewModel: TaskViewModel) => taskViewModel.task,
boardViewModel.filteredTaskViewModels,
(taskViewModels: React.ListState<TaskViewModel>) => {
const statusNameConverter: React.StateItemConverter<string> = (
statusName: string,
) => {
const index = createPropertyValueIndexState(
sortedStatuses,
statusName,
);
return StatusColumn(
2026-04-01 08:29:39 +00:00
categoryName,
statusName,
index,
boardViewModel,
taskViewModels,
);
};
const viewModel: TaskCategoryBulkChangeViewModel =
new TaskCategoryBulkChangeViewModel(
taskViewModels,
categoryName,
);
const view = (
<div class="flex-row flex-no large-gap">
<div class="property-input-wrapper">
<input
placeholder={
translations.chatPage.task
.renameCategoryInputPlaceholder
}
bind:value={viewModel.inputValue}
on:enter={viewModel.set}
></input>
<button
class="primary"
on:click={viewModel.set}
toggle:disabled={viewModel.cannotSet}
>
<span class="icon">check</span>
</button>
</div>
<div
class="flex-row large-gap padding-right"
children:append={[allStatuses, statusNameConverter]}
></div>
</div>
);
2024-07-25 18:42:06 +02:00
2026-04-01 08:29:39 +00:00
index.subscribe((newIndex) => {
view.style.order = newIndex;
});
2024-07-25 18:42:06 +02:00
2026-04-01 08:29:39 +00:00
return view;
},
);
2024-07-25 04:12:30 +02:00
}
function StatusColumn(
2026-04-01 08:29:39 +00:00
categoryName: string,
statusName: string,
index: React.State<number>,
boardViewModel: BoardViewModel,
taskViewModelsWithMatchingCategory: React.ListState<TaskViewModel>,
2024-07-25 04:12:30 +02:00
) {
2026-04-01 08:29:39 +00:00
const taskViewModels: React.ListState<TaskViewModel> =
new React.ListState();
taskViewModelsWithMatchingCategory.handleAddition((taskViewModel) => {
const doesMatchStatus: boolean =
taskViewModel.status.value == statusName;
if (doesMatchStatus == false) return;
taskViewModels.add(taskViewModel);
taskViewModelsWithMatchingCategory.handleRemoval(taskViewModel, () => {
taskViewModels.remove(taskViewModel);
});
});
function drop() {
boardViewModel.handleDropWithinBoard(categoryName, statusName);
}
2024-07-25 04:12:30 +02:00
2026-04-01 08:29:39 +00:00
const view = (
<div
class="status-column gap"
on:dragover={allowDrop}
on:drop={drop}
children:append={[taskViewModels, TaskViewModelToEntry]}
></div>
);
2024-07-25 04:12:30 +02:00
2026-04-01 08:29:39 +00:00
index.subscribe((newIndex) => {
view.style.order = newIndex;
2024-07-25 04:12:30 +02:00
});
2026-04-01 08:29:39 +00:00
return view;
2024-07-25 04:12:30 +02:00
}