Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder books #2338 #2810

Merged
merged 6 commits into from
Feb 16, 2024
Merged

Reorder books #2338 #2810

merged 6 commits into from
Feb 16, 2024

Conversation

m7modSy
Copy link
Contributor

@m7modSy m7modSy commented Dec 15, 2023

Implemented the ability to sort books in four different ways:

  1. Oldest to Newest: Sorts books based on their creation date.
  2. Newest to Oldest: Sorts books in reverse order of creation date.
  3. Alphabetical Order: Sorts books alphabetically.
  4. Manual Sorting: Users can now manually reorder books. Changes are saved persistently, even after leaving the website.

Manual Sorting Features:

  • Swap: Users can swap the positions of two directly adjacent books.
  • Specify Location: Users can specify the desired location for a book.
  • Drag-and-Drop: Initially considered, but not implemented to ensure efficiency, especially for users on mobile devices.

Note: This pull request addresses issue #2338.

@m7modSy m7modSy mentioned this pull request Dec 15, 2023
@smilerz
Copy link
Collaborator

smilerz commented Dec 15, 2023

  • ordering should be handled within the API instead of on the front end
  • manually ordering should be added to the Book model and be persistent

@vabene1111
Copy link
Collaborator

Hi, thanks for your PR. As smilerz said there is some room for improvement, espcecially since this adds a lot of code to the frontend.

We usually do ordering in tandoor by adding an order field to the model (see for example MealType).

For automatic ordering this is not needed as you could just add a query param to the API, for manual ordering that field could be edited by the user (not very user friendly but thats also the case for properties) but automatic ordering and manual ordering could conflict so that needs to be taken into account.

Copy link
Collaborator

@vabene1111 vabene1111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

see comments above, please also make sur to share a draft of what you want to do before writing code so that we can save you time by giving feedback directly (see https://docs.tandoor.dev/contribute/)

@m7modSy
Copy link
Contributor Author

m7modSy commented Dec 17, 2023

Hallo,
Thank you guys @smilerz @vabene1111 for your Feedback on my PR :)

For automatic ordering i think its pretty straight forward. i added 2 options for ordering through the api client

  1. order_field: Specify the field to order by
  2. Specify 'asc' for ascending order or 'desc' for descending order.

manual ordering:
I am very confused here:
I have seen how you handle the field order. My thoughts are that I make an update request with every swap, but is that really efficient or even possible?

@smilerz
Copy link
Collaborator

smilerz commented Dec 18, 2023

manual ordering: I am very confused here: I have seen how you handle the field order. My thoughts are that I make an update request with every swap, but is that really efficient or even possible?

ascending and descending should be part of the API/Serializer, not the model.
The behavior on the API is handled through a combination of Model, API and Serializer. (model.py, api.py and serializer.py)

Take a look at SupermarketCategory for an example on how this has been handled.

@m7modSy
Copy link
Contributor Author

m7modSy commented Jan 8, 2024

Hi @smilerz and @vabene1111,
you can take a look now at the code :)
you can now change the manual order by dragging and dropping, exactly like the SupermarketCategory

@m7modSy m7modSy requested a review from vabene1111 January 27, 2024 17:13
Copy link
Collaborator

@vabene1111 vabene1111 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok finally got around to reviewing this, just 2 minor changes and we are good to go

@@ -651,15 +651,23 @@ def destroy(self, *args, **kwargs):
content = {'error': True, 'msg': e.args[0]}
return Response(content, status=status.HTTP_403_FORBIDDEN)


import json
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please have imports on the top of the file

cookbook/migrations/0206_recipebook_order.py Outdated Show resolved Hide resolved
@vabene1111 vabene1111 merged commit 631af65 into TandoorRecipes:develop Feb 16, 2024
2 of 3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants