Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed

- Use translated itemtype name for reservation item select groups
- Filter the '0' empty-selection sentinel in Table and LDAP select questions
- Fix Table question column type edge cases

Expand Down
12 changes: 6 additions & 6 deletions public/js/modules/ReservationQuestionWidget.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,22 +93,22 @@ export class ReservationQuestionWidget {
$select.on('select2:clear select2:unselecting', () => this.#onItemCleared());
}

/** Groups flat {id, text, itemtype} results into Select2 optgroups per itemtype. */
/** Groups flat {id, text, itemtype, itemtype_label} results into Select2 optgroups per itemtype. */
#groupResultsByItemtype(data) {
const groups = new Map();

for (const item of data) {
const group_label = item.itemtype || '';
if (!groups.has(group_label)) {
groups.set(group_label, []);
const key = item.itemtype || '';
if (!groups.has(key)) {
groups.set(key, { text: item.itemtype_label || key, children: [] });
}
groups.get(group_label).push({
groups.get(key).children.push({
id: item.id,
text: item.text,
});
}

return Array.from(groups, ([text, children]) => ({ text, children }));
return Array.from(groups.values());
}

#onItemSelected() {
Expand Down
6 changes: 4 additions & 2 deletions src/Controller/ReservableItemsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public function __invoke(Request $request): Response

/**
* @param class-string<CommonDBTM> $itemtype
* @return array<int, array{id: int, text: string, itemtype: string}>
* @return array<int, array{id: int, text: string, itemtype: string, itemtype_label: string}>
*/
private function getReservableItemsForType(string $itemtype, string $search): array
{
Expand Down Expand Up @@ -114,10 +114,12 @@ private function getReservableItemsForType(string $itemtype, string $search): ar
}

$id = $row['id'] ?? null;
$itemtype_label = $itemtype::getTypeName(1);
$results[] = [
'id' => is_numeric($id) ? (int) $id : 0,
'text' => sprintf('%s (%s)', $item->getName(), $itemtype::getTypeName(1)),
'text' => sprintf('%s (%s)', $item->getName(), $itemtype_label),
'itemtype' => $itemtype,
'itemtype_label' => $itemtype_label,
];
}

Expand Down