Merge branch 'devel' into dev/jsclientdocs
Conflicts: src/octoprint/static/js/app/viewmodels/printerstate.js
This commit is contained in:
commit
72bc30eae5
7 changed files with 126 additions and 17 deletions
|
|
@ -19,17 +19,38 @@ Issue a job command
|
|||
Starts the print of the currently selected file. For selecting a file, see :ref:`Issue a file command <sec-api-fileops-filecommand>`.
|
||||
If a print job is already active, a :http:statuscode:`409` will be returned.
|
||||
|
||||
cancel
|
||||
Cancels the current print job. If no print job is active (either paused or printing), a :http:statuscode:`409`
|
||||
will be returned.
|
||||
|
||||
restart
|
||||
Restart the print of the currently selected file from the beginning. There must be an active print job for this to work
|
||||
and the print job must currently be paused. If either is not the case, a :http:statuscode:`409` will be returned.
|
||||
|
||||
pause
|
||||
Pauses/unpauses the current print job. If no print job is active (either paused or printing), a :http:statuscode:`409`
|
||||
will be returned.
|
||||
Equivalent to issuing a ``cancel`` command while paused, directly followed by a ``start`` command.
|
||||
|
||||
cancel
|
||||
Cancels the current print job. If no print job is active (either paused or printing), a :http:statuscode:`409`
|
||||
will be returned.
|
||||
pause
|
||||
Pauses/resumes/toggles the current print job. Accepts one optional additional parameter ``action``
|
||||
specifying which action to take. Valid values for this parameter are:
|
||||
|
||||
pause
|
||||
Pauses the current job if it's printing, does nothing if it's already paused.
|
||||
resume
|
||||
Resumes the current job if it's paused, does nothing if it's printing.
|
||||
toggle
|
||||
Toggles the pause state of the job, pausing it if it's printing and resuming it if it's currently paused.
|
||||
|
||||
In order to stay backwards compatible to earlier iterations of this API, the default
|
||||
action to take if no ``action`` parameter is supplied is to toggle the print job status.
|
||||
|
||||
If no print job is active (either paused or printing), a :http:statuscode:`409` will be returned.
|
||||
|
||||
.. note::
|
||||
|
||||
While the approach to implement pause/resume/toggle behaviour through sub commands via the ``action``
|
||||
parameter instead of having dedicated ``pause``, ``resume`` and ``toggle`` commands seems clumsy, this path
|
||||
was chosen to have the API stay backwards compatible to prior versions which only offered the toggle
|
||||
behaviour under the ``pause`` command.
|
||||
|
||||
Upon success, a status code of :http:statuscode:`204` and an empty body is returned.
|
||||
|
||||
|
|
@ -50,6 +71,23 @@ Issue a job command
|
|||
|
||||
HTTP/1.1 204 No Content
|
||||
|
||||
**Example Cancel Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
POST /api/job HTTP/1.1
|
||||
Host: example.com
|
||||
Content-Type: application/json
|
||||
X-Api-Key: abcdef...
|
||||
|
||||
{
|
||||
"command": "cancel"
|
||||
}
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 204 No Content
|
||||
|
||||
**Example Restart Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
|
@ -77,14 +115,15 @@ Issue a job command
|
|||
X-Api-Key: abcdef...
|
||||
|
||||
{
|
||||
"command": "pause"
|
||||
"command": "pause",
|
||||
"action": "pause"
|
||||
}
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 204 No Content
|
||||
|
||||
**Example Cancel Request**
|
||||
**Example Resume Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
|
|
@ -94,7 +133,26 @@ Issue a job command
|
|||
X-Api-Key: abcdef...
|
||||
|
||||
{
|
||||
"command": "cancel"
|
||||
"command": "pause",
|
||||
"action": "resume"
|
||||
}
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
HTTP/1.1 204 No Content
|
||||
|
||||
**Example Pause Toggle Request**
|
||||
|
||||
.. sourcecode:: http
|
||||
|
||||
POST /api/job HTTP/1.1
|
||||
Host: example.com
|
||||
Content-Type: application/json
|
||||
X-Api-Key: abcdef...
|
||||
|
||||
{
|
||||
"command": "pause",
|
||||
"action": "toggle"
|
||||
}
|
||||
|
||||
.. sourcecode:: http
|
||||
|
|
|
|||
|
|
@ -249,11 +249,26 @@ class PrinterInterface(object):
|
|||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def pause_print(self):
|
||||
"""
|
||||
Pauses the current print job if it is currently running, does nothing otherwise.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def resume_print(self):
|
||||
"""
|
||||
Resumes the current print job if it is currently paused, does nothing otherwise.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
|
||||
def toggle_pause_print(self):
|
||||
"""
|
||||
Pauses the current print job if it is currently running or resumes it if it is currently paused.
|
||||
"""
|
||||
raise NotImplementedError()
|
||||
if self.is_printing():
|
||||
self.pause_print()
|
||||
elif self.is_paused():
|
||||
self.resume_print()
|
||||
|
||||
def cancel_print(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -406,14 +406,29 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback):
|
|||
self._setCurrentZ(None)
|
||||
self._comm.startPrint(pos=pos)
|
||||
|
||||
def toggle_pause_print(self):
|
||||
def pause_print(self):
|
||||
"""
|
||||
Pause the current printjob.
|
||||
Pause the current printjob.
|
||||
"""
|
||||
if self._comm is None:
|
||||
return
|
||||
|
||||
self._comm.setPause(not self._comm.isPaused())
|
||||
if self._comm.isPaused():
|
||||
return
|
||||
|
||||
self._comm.setPause(True)
|
||||
|
||||
def resume_print(self):
|
||||
"""
|
||||
Resume the current printjob.
|
||||
"""
|
||||
if self._comm is None:
|
||||
return
|
||||
|
||||
if not self._comm.isPaused():
|
||||
return
|
||||
|
||||
self._comm.setPause(False)
|
||||
|
||||
def cancel_print(self):
|
||||
"""
|
||||
|
|
|
|||
|
|
@ -43,7 +43,15 @@ def controlJob():
|
|||
elif command == "pause":
|
||||
if not activePrintjob:
|
||||
return make_response("Printer is neither printing nor paused, 'pause' command cannot be performed", 409)
|
||||
printer.toggle_pause_print()
|
||||
action = data.get("action", "toggle")
|
||||
if action == "toggle":
|
||||
printer.toggle_pause_print()
|
||||
elif action == "pause":
|
||||
printer.pause_print()
|
||||
elif action == "resume":
|
||||
printer.resume_print()
|
||||
else:
|
||||
return make_response("Unknown action '{}', allowed values for action parameter are 'pause', 'resume' and 'toggle'".format(action), 400)
|
||||
elif command == "cancel":
|
||||
if not activePrintjob:
|
||||
return make_response("Printer is neither printing nor paused, 'cancel' command cannot be performed", 409)
|
||||
|
|
@ -58,4 +66,4 @@ def jobState():
|
|||
"job": currentData["job"],
|
||||
"progress": currentData["progress"],
|
||||
"state": currentData["state"]["text"]
|
||||
})
|
||||
})
|
||||
|
|
|
|||
|
|
@ -225,6 +225,11 @@ class ReverseProxied(object):
|
|||
|
||||
# determine scheme
|
||||
scheme = environ.get(self._header_scheme, "")
|
||||
if scheme and "," in scheme:
|
||||
# Scheme might be something like "https,https" if doubly-reverse-proxied
|
||||
# without stripping original scheme header first, make sure to only use
|
||||
# the first entry in such a case. See #1391.
|
||||
scheme, _ = map(lambda x: x.strip(), scheme.split(",", 1))
|
||||
if not scheme:
|
||||
scheme = self._fallback_scheme
|
||||
|
||||
|
|
|
|||
|
|
@ -220,7 +220,15 @@ $(function() {
|
|||
}
|
||||
};
|
||||
|
||||
self.pause = function() {
|
||||
self.onlyPause = function() {
|
||||
OctoPrint.job.pause();
|
||||
};
|
||||
|
||||
self.onlyResume = function() {
|
||||
OctoPrint.job.resume();
|
||||
};
|
||||
|
||||
self.pause = function(action) {
|
||||
OctoPrint.job.togglePause();
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -15,6 +15,6 @@
|
|||
|
||||
<div class="row-fluid print-control" style="display: none;" data-bind="visible: loginState.isUser">
|
||||
<button class="btn btn-primary span4" data-bind="click: print, enable: enablePrint, css: {'btn-danger': isPaused()}, attr: {title: titlePrintButton}" id="job_print"><i class="icon-white" data-bind="css: {'icon-print': !isPaused(), 'icon-undo': isPaused()}"></i> <span data-bind="text: (isPaused() ? '{{ _('Restart') }}' : '{{ _('Print') }}')">{{ _('Print') }}</span></button>
|
||||
<button class="btn span4" id="job_pause" data-bind="click: pause, enable: enablePause, css: {active: isPaused()}, attr: {title: titlePauseButton}"><i data-bind="css: {'icon-pause': !isPaused(), 'icon-play': isPaused()}"></i> <span data-bind="visible: !isPaused()">{{ _('Pause') }}</span><span data-bind="visible: isPaused()">{{ _('Resume') }}</span></button>
|
||||
<button class="btn span4" id="job_pause" data-bind="click: function() { isPaused() ? onlyResume() : onlyPause(); }, enable: enablePause, css: {active: isPaused()}, attr: {title: titlePauseButton}"><i data-bind="css: {'icon-pause': !isPaused(), 'icon-play': isPaused()}"></i> <span data-bind="visible: !isPaused()">{{ _('Pause') }}</span><span data-bind="visible: isPaused()">{{ _('Resume') }}</span></button>
|
||||
<button class="btn span4" id="job_cancel" data-bind="click: cancel, enable: enableCancel" title="{{ _('Cancels the print job') }}"><i class="icon-stop"></i> {{ _('Cancel') }}</button>
|
||||
</div>
|
||||
|
|
|
|||
Loading…
Reference in a new issue