Skip to content

Commit

Permalink
Allow backend to recalculate sortorder re #10604
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobtylerwalls committed Apr 16, 2024
1 parent 3c36dae commit 18d8988
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
8 changes: 4 additions & 4 deletions arches/app/src/components/ControlledListManager/ListTree.vue
Original file line number Diff line number Diff line change
Expand Up @@ -175,16 +175,16 @@ const addChild = async (parent_id: string) => {
const setParent = async (parentNode: typeof TreeNode) => {
let errorText;
const setListRecursive = (child: ControlledListItem) => {
const setListAndSortOrderRecursive = (child: ControlledListItem) => {
child.controlled_list_id = parentNode.key;
child.children.forEach(grandchild => setListRecursive(grandchild));
child.sortorder = -1; // tells backend to renumber
child.children.forEach(grandchild => setListAndSortOrderRecursive(grandchild));
};
const item = itemToAdjustParent.value.data;
if (parentNode.data.name) {
item.controlled_list_id = parentNode.key;
item.children.forEach(setListRecursive);
setListAndSortOrderRecursive(item);
} else {
item.parent_id = parentNode.key;
}
Expand Down
6 changes: 6 additions & 0 deletions arches/app/views/controlled_lists.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,12 +150,14 @@ def prefetch_terms(request):


def handle_items(item_dicts):
max_sortorder = 0
items_to_save = []
labels_to_save = []

def handle_item(item_dict):
nonlocal items_to_save
nonlocal labels_to_save
nonlocal max_sortorder

# Deletion/insertion of list items not yet implemented.
labels = item_dict.pop("labels")
Expand All @@ -167,6 +169,10 @@ def handle_item(item_dict):
item_to_save._state.adding = False # allows checking uniqueness
items_to_save.append(item_to_save)

if item_to_save.sortorder < 0:
item_to_save.sortorder = max_sortorder + 1
max_sortorder = max(max_sortorder, item_to_save.sortorder)

if len({item.controlled_list_id for item in items_to_save}) > 1:
raise MixedListsException

Expand Down

0 comments on commit 18d8988

Please sign in to comment.