Replace top-level actions View with builtin LabThings
This commit is contained in:
parent
427d5b0093
commit
421a2e3960
3 changed files with 7 additions and 36 deletions
|
|
@ -140,8 +140,6 @@ labthing.add_view(views.MjpegStream, "/streams/mjpeg")
|
||||||
labthing.add_view(views.SnapshotStream, "/streams/snapshot")
|
labthing.add_view(views.SnapshotStream, "/streams/snapshot")
|
||||||
|
|
||||||
# Attach microscope action resources
|
# Attach microscope action resources
|
||||||
labthing.add_view(views.actions.ActionsView, "/actions")
|
|
||||||
labthing.add_root_link(views.actions.ActionsView, "actions")
|
|
||||||
for name, action in views.enabled_root_actions().items():
|
for name, action in views.enabled_root_actions().items():
|
||||||
view_class = action["view_class"]
|
view_class = action["view_class"]
|
||||||
rule = action["rule"]
|
rule = action["rule"]
|
||||||
|
|
|
||||||
|
|
@ -100,8 +100,8 @@ export default {
|
||||||
configurationUri: function() {
|
configurationUri: function() {
|
||||||
return `${this.$store.getters.baseUri}/api/v2/instrument/configuration`;
|
return `${this.$store.getters.baseUri}/api/v2/instrument/configuration`;
|
||||||
},
|
},
|
||||||
actionsUri: function() {
|
rootUri: function() {
|
||||||
return `${this.$store.getters.baseUri}/api/v2/actions`;
|
return `${this.$store.getters.baseUri}/api/v2`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
@ -135,22 +135,22 @@ export default {
|
||||||
},
|
},
|
||||||
updateSystemActions: function() {
|
updateSystemActions: function() {
|
||||||
axios
|
axios
|
||||||
.get(this.actionsUri)
|
.get(this.rootUri)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
if ("reboot" in response.data) {
|
if ("RebootAPI" in response.data.actions) {
|
||||||
this.$set(
|
this.$set(
|
||||||
this.systemActionLinks,
|
this.systemActionLinks,
|
||||||
"reboot",
|
"reboot",
|
||||||
response.data.reboot.links.self.href
|
`${this.$store.getters.baseUri}/api/v2/actions/system/reboot/`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
delete this.systemActionLinks.reboot;
|
delete this.systemActionLinks.reboot;
|
||||||
}
|
}
|
||||||
if ("shutdown" in response.data) {
|
if ("ShutdownAPI" in response.data.actions) {
|
||||||
this.$set(
|
this.$set(
|
||||||
this.systemActionLinks,
|
this.systemActionLinks,
|
||||||
"shutdown",
|
"shutdown",
|
||||||
response.data.shutdown.links.self.href
|
`${this.$store.getters.baseUri}/api/v2/actions/system/shutdown/`
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
delete this.systemActionLinks.shutdown;
|
delete this.systemActionLinks.shutdown;
|
||||||
|
|
|
||||||
|
|
@ -54,30 +54,3 @@ _actions = {
|
||||||
|
|
||||||
def enabled_root_actions():
|
def enabled_root_actions():
|
||||||
return {k: v for k, v in _actions.items() if v["conditions"]}
|
return {k: v for k, v in _actions.items() if v["conditions"]}
|
||||||
|
|
||||||
|
|
||||||
class ActionsView(View):
|
|
||||||
def get(self):
|
|
||||||
"""
|
|
||||||
List of enabled default API actions.
|
|
||||||
|
|
||||||
This list does not include any actions added by LabThings extensions, only
|
|
||||||
those part of the default OpenFlexure Microscope API.
|
|
||||||
"""
|
|
||||||
actions = {}
|
|
||||||
for name, action in enabled_root_actions().items():
|
|
||||||
d = {
|
|
||||||
"links": {
|
|
||||||
"self": {
|
|
||||||
"href": url_for(action["view_class"].endpoint, _external=True),
|
|
||||||
"mimetype": "application/json",
|
|
||||||
**description_from_view(action["view_class"]),
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"rule": action["rule"],
|
|
||||||
"view_class": str(action["view_class"]),
|
|
||||||
}
|
|
||||||
|
|
||||||
actions[name] = d
|
|
||||||
|
|
||||||
return actions
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue