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

Handle lookup item & attachment creation in IdentifierLookupController #707

Merged
merged 46 commits into from
Nov 22, 2023

Conversation

mvasilak
Copy link
Contributor

@mvasilak mvasilak commented Jun 22, 2023

closes #683

Moves item & attachment creation from identifier lookup to a separate user controller, that is guarranted to fulfill ongoing lookups, if lookup window is closed.

With this change, perhaps we should label the button as Close, instead of Cancel. Furthermore, the items added for this identifier, perhaps should indicate that they might have pending downloads.

--

TODO:

  • Keep track of separate lookup window initializations, if selected library & collections are different.
  • Include downloaded attachments from translated identifiers, in items toolbar label Downloaded x/y.
  • Show progress of identifier lookup in items toolbar label as Saved x/y.
  • Add button in items toolbar, that will restore lookup window, when there are identifier lookups in the background.
  • Add Cancel all button in lookup window, that will cancel all downloads and trash items/attachments already fetched.
  • Rename current Cancel button in lookup window to Close, that dismisses window and continues lookup in the background.
  • Add a cancel button in each lookup item row, for individual cancellation. Cancelling an item, will also remove its attachments. Use an X or trash icon.
  • Add a cancel button in each attachment row, that cancels/removes this attachment.
  • Cleanup of finished lookup items from controller, when lookup window is closed, and all operations are finished/cancelled.
  • When new identifiers are added for lookup, with previous ones queued, show a list of all items.

@mvasilak mvasilak self-assigned this Jun 22, 2023
@mvasilak mvasilak force-pushed the fix-aborted-lookup-download branch from b22f4c5 to eaeb31a Compare June 27, 2023 11:31
@michalrentka
Copy link
Contributor

Code-wise it's fine, it moved existing functionality to background so that things can finish even if the UI is closed.

With this change, perhaps we should label the button as Close, instead of Cancel

@mvasilak I think that Cancel currently still cancels the translation? The web view is still inside the popup, so if the popup closes, translation is cancelled, right? I'd keep it as it is - you can cancel the translation if something goes wrong, but if items are translated successfully, you can close the popup so that you don't have to watch items download one by one.

Furthermore, the items added for this identifier, perhaps should indicate that they might have pending downloads.

@dstillman a little explanation and question: currently translation happens, item(s) are created for the main (parent) items, then files are downloaded and if individual downloads succeed then their attachment items are created. Which means if you're on slow internet you'll first see parent item(s) without attachments and only when those files are downloaded attachments start showing up.

As @mvasilak hinted, would it be better to create all items immediately and then start all downloads (and show their progress the same way as if downloading them from our server)? This approach would be more complicated just because you'd have to handle interruptions and retry downloads (if users just close the app, downloads are interrupted and will have to be restarted after the app starts again). Also if people don't really download that many big papers at once, you most likely won't even notice the difference, because smaller papers are downloaded quickly and they just show up after few seconds. So I'm not sure whether it's worth it.

@dstillman
Copy link
Member

Is the question about showing pending downloads in the lookup progress dialog or in the items list itself?

For the former, we know immediately from the translator whether there's an attachment, and we know the name to use. That's how we show the attachment line right away in the Zotero Connector save popup (and maybe the share extension?). So at least for that, we can show attachment progress without creating the attachment item first. Maybe we're already doing that?

If the question is about the items list, and we're talking about switching to a Close button once items are created but before downloads are done, could we hook into the lookup controller for the items list progress indicator, and also queue an 'open' action so that it opens the file once it exists? Seems very complicated, but I don't think we want to create an attachment item first, because that seems very likely to lead to attachment items with missing files, attachment items being synced before files are available, etc.

For a simpler option, could we just add an indicator/button somewhere that would reopen the lookup dialog to show progress? We do something similar for multi-item PDF metadata retrieval in the desktop app.

@michalrentka
Copy link
Contributor

Is the question about showing pending downloads in the lookup progress dialog or in the items list itself?

The former is already implemented, it was the latter. I agree it's probably unnecessarily overcomplicated and we can create attachments only after they download and just ignore them if they don't.

For a simpler option, could we just add an indicator/button somewhere that would reopen the lookup dialog to show progress? We do something similar for multi-item PDF metadata retrieval in the desktop app.

That's a good idea. We could have a progress bar on bottom, same as when we're downloading multiple files (screenshot below) with a button to re-open the lookup popup. That way you'd know you're currently downloading and can view state as well.

IMG_139D1C7CA62F-1

It could say "Lookup x/y" with progress bar below and "Open" to the right.

@dstillman
Copy link
Member

We could have a progress bar on bottom, same as when we're downloading multiple files (screenshot below) with a button to re-open the lookup popup. That way you'd know you're currently downloading and can view state as well.

👍

@dstillman
Copy link
Member

"Lookup" is an internal term for the feature. Can it not just say "Downloaded x/y"?

@michalrentka
Copy link
Contributor

"Lookup" is an internal term for the feature. Can it not just say "Downloaded x/y"?

Sure, I thought we might want to distinguish attachment downloads from lookup downloads. But I guess we can even combine them if both are in progress then.

@mvasilak mvasilak force-pushed the fix-aborted-lookup-download branch from eaeb31a to db49f50 Compare July 10, 2023 16:43
@michalrentka
Copy link
Contributor

@dstillman there's one more usability issue probably. When you add multiple identifiers, downloads are now in background, but translation happens sequentially. Translation could be moved to background too (by moving the underlying webview to parent controller). Do we want to do that? Or is it fine like this?

@dstillman
Copy link
Member

What would the usability issue be? That translation stops if you close the app?

@michalrentka
Copy link
Contributor

What would the usability issue be? That translation stops if you close the app?

Currently yes. The popup says "Cancel" while translations are in progress, so when you close the popup currently running translations are stopped. Started downloads finish in background.

@dstillman
Copy link
Member

That seems fine.

@michalrentka
Copy link
Contributor

That seems fine.

For me personally those translations took longer than file downloads, so I can't really close the window and see background downloads as we initially intended. This will only be visible for bigger file downloads. I guess that's not a problem. But if you add a lot of identifiers you'll have to wait for all of them to translate which can take some time. But it's still faster than adding them 1 by 1 through share extension.

@dstillman
Copy link
Member

Ah, I see. So the question is if we want to change it to process them in the background with a Close button instead of (or in addition to) Cancel? And we added something to reopen the progress dialog, right? Does that button stick around after completion so you can view results?

@michalrentka
Copy link
Contributor

Ah, I see. So the question is if we want to change it to process them in the background with a Close button instead of (or in addition to) Cancel? And we added something to reopen the progress dialog, right? Does that button stick around after completion so you can view results?

I guess we could add cancel to individual translations instead of general cancel and we'd keep Close for the whole window. The button to reopen dialog is not there yet, I'm just writing comment about that too.

@mvasilak
Copy link
Contributor Author

The re-opening is still in development (PR is still WIP), but that is the goal. We can modify the items toolbar to say both
downloaded x/y and translated z/w.

@dstillman
Copy link
Member

I guess we could add cancel to individual translations instead of general cancel and we'd keep Close for the whole window.

Why? Because some network request might be hanging? Maybe we want that, but seems weird not to also give the option to cancel the whole process if we have any cancel options.

translated z/w

"Saved z/w"

@michalrentka
Copy link
Contributor

@mvasilak got it.

Some other issues:

@michalrentka
Copy link
Contributor

I guess we could add cancel to individual translations instead of general cancel and we'd keep Close for the whole window.

Why? Because some network request might be hanging? Maybe we want that, but seems weird not to also give the option to cancel the whole process if we have any cancel options.

I thought cancel would make sense when the translation finishes and you see the resulted item is not what you wanted. But we can add cancel (all) and individual cancels or just cancel option.

@mvasilak
Copy link
Contributor Author

mvasilak commented Jul 11, 2023

@michalrentka I'd noticed that as well. Probably needs an initial event w/ 0 progress, similar to what AttachmentDownloader does. I will investigate it.

@dstillman
Copy link
Member

I thought cancel would make sense when the translation finishes and you see the resulted item is not what you wanted.

The latter could be useful, but it should probably be an (x) delete button. And I guess that'd be fine for cancelling while in progress too.

@mvasilak
Copy link
Contributor Author

New specs, from the discussion, please verify:

  • Downloaded attachments from translated identifiers, are included in items toolbar label Downloaded x/y.
  • New label Saved x/y will be added also in items toolbar, to show translation progress in the background.
  • Button in items toolbar, will allow to re-open queue of translated identifiers.
  • Lookup window will have Cancel all button, that will cancel all downloads and remove items/attachments already fetched. Probably it's good to show a confirmation alert.
  • Lookup window will also have Close button, that just continues the process in the background.
  • Each lookup item row will have a cancel button, for individual cancellation. Cancelling an item, will also remove its attachments. If item already downloaded, in a sense it becomes a delete/remove button, but could be the same, e.g. an X or trash icon.
  • Each attachment row will also have a cancel button, just to cancel/remove this attachment.

A few things not commented already:

  • Looking up new identifiers, could open the lookup input window, but when lookup is started, add them in the list with existing lookup items, if any.
  • Lookup items should be removed at some point from the list. I guess when all their attachments have finished (successfully or otherwise), and if the lookup list window is not visible at the time.

@mvasilak mvasilak force-pushed the fix-aborted-lookup-download branch from db49f50 to 452678f Compare July 11, 2023 09:36
@mvasilak
Copy link
Contributor Author

mvasilak commented Jul 11, 2023

@michalrentka regarding the sole download not appearing, it also happens for normal downloads of attachments, due to this guard

guard total > 1 else { return nil }

What is the reasoning behind this?
Should this edge case be maintained? If so I'll make this an option for the constructor.
Or could we make this check for total > 0 for all cases?

@michalrentka
Copy link
Contributor

@michalrentka regarding the sole download not appearing, it also happens for normal downloads of attachments, due to this guard

guard total > 1 else { return nil }

What is the reasoning behind this? Should this edge case be maintained? If so I'll make this an option for the constructor. Or could we remove this check for all cases?

Yeah it made sense when it was used just for downloads. When you tap a single attachment which needs to download, you already see the download progress in the icon, so I ignored it. I guess just remove the guard.

@mvasilak mvasilak force-pushed the fix-aborted-lookup-download branch 2 times, most recently from b4e0be0 to 153856b Compare July 13, 2023 13:28
Add Cancel All button to lookup window that cancels pending
items/attachments and trashes already stored items/attachments
Fix bug in RemoteAttachmentDownloader
Make access to batch data & current lookup data synchronous
Improve ItemsToolbarController progress view
update when switching collections
Simplify observation of IdentifierLookupController by LookupActionHandler
Ignore adding identifiers that have ongoing lookup
Cleanup web views when all current lookups finish
Dismiss lookup controller after canceling all lookups
@michalrentka michalrentka merged commit 2f4687a into zotero:master Nov 22, 2023
1 check passed
@mvasilak mvasilak deleted the fix-aborted-lookup-download branch November 28, 2023 09:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

Identifier lookup download aborted when popup is closed
3 participants