scrapy / scrapyd

A service daemon to run Scrapy spiders
https://scrapyd.readthedocs.io/en/stable/
BSD 3-Clause "New" or "Revised" License
2.96k stars 570 forks source link

Change Cancel button to call cancel.json via JavaScript, to avoid page navigation #436

Open ilias-ant opened 2 years ago

ilias-ant commented 2 years ago

Problem

When someone uses the Cancel button(s) available in the /jobs page:

image

the action redirects you to the /cancel.json page (which is the respective web service response), detailing something like the following:

{"node_name": "foobar", "status": "ok", "prevstate": "pending"}

If someone wants to perform multiple Cancel actions, it has to navigate between the /jobs page and the individual redirected /cancel.json pages, which makes it a bit tiresome.

Context

scrapyd v1.3.0

Proposal

The Cancel action through the /jobs UI should not redirect, but rather display the response in the same view (/jobs). Perhaps this cannot be done purely with HTML, and a bit of Javascript may be needed.

jpmckinney commented 3 months ago

Yes, we can maybe make the request to cancel.json and then display the results.

There was a start at a new UI in #304 from before I became maintainer.

There was also some relevant code in #254

Edit: Another idea is to maybe add a hidden input to the form, which, if received, causes the webservice to return a 302 to redirect to the homepage. While that's maybe simpler, the JavaScript solution is preferred, to avoid polluting the API with this sort of frontend logic.