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

Add bulk delete, bulk archive/unarchive, and bulk metadata edit buttons in books table page #3113

Open
wants to merge 19 commits into
base: master
Choose a base branch
from

Conversation

jmarmstrong1207
Copy link

@jmarmstrong1207 jmarmstrong1207 commented Aug 2, 2024

This PR adds the following:

  • Bulk deleting
  • Bulk archive/unarchive
  • Bulk metadata editing. This is related to Edit Metadata in Bulk #1558
  • Fixed change_archived_books() so that when state=false and an unarchived book is passed, it won't archive it.
  • Fixed edit_book_read_status() so that when state=false and an unread book is passed, it won't mark it as read
  • Added ability to select multiple books at once via shift-click. Works similar to File Explorer shift clicking to select multiple files.

Screenshots below show the workflow for deleting for end-users, but is the same as for archive/unarching in bulk. Read comments below for more screenshots:

Select books

image

Delete books

image

Book list after deletion

image

@jmarmstrong1207 jmarmstrong1207 changed the title Add bulk delete button in books table page Add bulk delete button and archive/unarchive button in books table page Aug 2, 2024
@OzzieIsaacs
Copy link
Collaborator

I prefer to have the buttons for mass delete/unarchive in the top of the table, similar to the ones in the user edit table (.../admin/usertable):
image

@jmarmstrong1207
Copy link
Author

jmarmstrong1207 commented Aug 2, 2024

Looks like this now. It looks off; is this style good? I'm also thinking of adding bulk read status buttons too in this PR
image

@jmarmstrong1207 jmarmstrong1207 marked this pull request as draft August 2, 2024 17:20
@jmarmstrong1207
Copy link
Author

Okay, got it to work. Had to use $(document).on('click', '#id', function....) instead of $('#id').click() for the buttons because adding the buttons within the table header makes them dynamically-added elements.

Also added the bulk read/unread buttons. I have tested it to work, but of course testing yourself would be best
image

@jmarmstrong1207
Copy link
Author

jmarmstrong1207 commented Aug 2, 2024

Alright, final feature for this PR. I added bulk metadata editing. No more additional features will be added from now on as I've done what I intended to do!
image

@jmarmstrong1207 jmarmstrong1207 changed the title Add bulk delete button and archive/unarchive button in books table page Add bulk delete button, archive/unarchive, and metadata editing button in books table page Aug 2, 2024
@jmarmstrong1207 jmarmstrong1207 marked this pull request as ready for review August 2, 2024 23:08
@jmarmstrong1207 jmarmstrong1207 changed the title Add bulk delete button, archive/unarchive, and metadata editing button in books table page Add bulk delete, bulk archive/unarchive, and bulk metadata edit buttons in books table page Aug 3, 2024
@jmarmstrong1207
Copy link
Author

Let me know if I am missing anything. Fleshed out basically everything I can think of myself

@@ -350,6 +350,74 @@ def table_get_custom_enum(c_id):
@edit_required
def edit_list_book(param):
Copy link
Author

Choose a reason for hiding this comment

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

I moved the function to edit_book_param() in order to modularize it. This is so it can be used with the '/editselectedbooks/' calls. This essentially makes the change atomic from the client's perspective. Otherwise when bulk editing metadata, each metadata for each book needs an individual rest API call.

@@ -54,10 +54,10 @@ def remove_synced_book(book_id, all=False, session=None):
def change_archived_books(book_id, state=None, message=None):
archived_book = ub.session.query(ub.ArchivedBook).filter(and_(ub.ArchivedBook.user_id == int(current_user.id),
ub.ArchivedBook.book_id == book_id)).first()
if not archived_book:
if not archived_book and state == True:
Copy link
Author

@jmarmstrong1207 jmarmstrong1207 Aug 3, 2024

Choose a reason for hiding this comment

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

Makes it so only requests to archive (ie state = true) actually creates an archivedbook listing.

Edit: Made line 57 if not archived_book and (state == True or state == None) so state=None makes the function a toggler. Otherwise, not adding or state == None will make it not create an archivedbook listing when someone tries to use the /togglearchived endpoint on a brand new, never-archived book

archived_book = ub.ArchivedBook(user_id=current_user.id, book_id=book_id)

archived_book.is_archived = state if state else not archived_book.is_archived
archived_book.is_archived = state if state != None else not archived_book.is_archived
Copy link
Author

@jmarmstrong1207 jmarmstrong1207 Aug 3, 2024

Choose a reason for hiding this comment

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

Without this, bulk unarchiving on already-unarchived books will actually archive them instead. Without this, this function is just a toggler if state is false.

Same exact thing with edit_book_read_status is fixed in the commit below

@jmarmstrong1207
Copy link
Author

Added ability to shift click to select multiple books at once. Works like in file explorer when shift clicking for multi-selection. Was a stupid easy change, just setting a property to True in the table creation

@jmarmstrong1207
Copy link
Author

@OzzieIsaacs This PR is ready to review now, whenever you're ready

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.

2 participants