Implemented root API v2 routes
This commit is contained in:
parent
5aa783c269
commit
6581612312
27 changed files with 1205 additions and 148 deletions
|
|
@ -152,7 +152,7 @@ class ConfigAPI(MicroscopeView):
|
|||
:>header Content-Type: application/json
|
||||
:status 200: state available
|
||||
"""
|
||||
return jsonify(self.microscope.read_config(json_safe=True))
|
||||
return jsonify(self.microscope.read_settings(json_safe=True))
|
||||
|
||||
def post(self):
|
||||
"""
|
||||
|
|
@ -223,10 +223,10 @@ class ConfigAPI(MicroscopeView):
|
|||
logging.debug("Updating settings from POST request:")
|
||||
logging.debug(payload.json)
|
||||
|
||||
self.microscope.apply_config(payload.json)
|
||||
self.microscope.save_config()
|
||||
self.microscope.apply_settings(payload.json)
|
||||
self.microscope.save_settings()
|
||||
|
||||
return jsonify(self.microscope.read_config(json_safe=True))
|
||||
return jsonify(self.microscope.read_settings(json_safe=True))
|
||||
|
||||
|
||||
def construct_blueprint(microscope_obj):
|
||||
|
|
|
|||
|
|
@ -130,16 +130,19 @@ class ListAPI(MicroscopeView):
|
|||
output.file, use_video_port=use_video_port, resize=resize, bayer=bayer
|
||||
)
|
||||
|
||||
metadata.update(
|
||||
{
|
||||
"microscope_settings": self.microscope.read_config(),
|
||||
# Inject system metadata
|
||||
system_metadata = {
|
||||
"microscope_settings": self.microscope.read_settings(),
|
||||
"microscope_state": self.microscope.state,
|
||||
"microscope_id": self.microscope.id,
|
||||
"microscope_name": self.microscope.name,
|
||||
}
|
||||
)
|
||||
output.system_metadata.update(system_metadata)
|
||||
|
||||
# Insert custom metadata
|
||||
output.put_metadata(metadata)
|
||||
|
||||
# Insert custom tags
|
||||
output.put_tags(tags)
|
||||
|
||||
return jsonify(output.state)
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ class ZoomAPI(MicroscopeView):
|
|||
:<header Content-Type: application/json
|
||||
:status 200: preview started/stopped
|
||||
"""
|
||||
zoom_value = self.microscope.camera.state["zoom_value"]
|
||||
zoom_value = self.microscope.camera.status["zoom_value"]
|
||||
|
||||
return jsonify({"zoom_value": zoom_value})
|
||||
|
||||
|
|
@ -47,7 +47,7 @@ class ZoomAPI(MicroscopeView):
|
|||
|
||||
self.microscope.camera.set_zoom(zoom_value)
|
||||
|
||||
return jsonify(self.microscope.camera.state)
|
||||
return jsonify(self.microscope.camera.status)
|
||||
|
||||
|
||||
class OverlayAPI(MicroscopeView):
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ from openflexure_microscope.api.views import MicroscopeViewPlugin
|
|||
from flask import Blueprint, jsonify
|
||||
from openflexure_microscope.api.views import MicroscopeView
|
||||
|
||||
import copy
|
||||
import logging
|
||||
import warnings
|
||||
|
||||
|
|
@ -21,7 +22,7 @@ class PluginFormAPI(MicroscopeView):
|
|||
A complete list of enabled plugins can be found in the microscope state.
|
||||
|
||||
"""
|
||||
out = self.microscope.plugin.forms
|
||||
out = self.microscope.plugins.forms
|
||||
return jsonify(out)
|
||||
|
||||
|
||||
|
|
@ -38,7 +39,10 @@ def construct_blueprint(microscope_obj):
|
|||
all_routes = []
|
||||
|
||||
# For each plugin attached to the microscope object
|
||||
for plugin_name, plugin_obj in microscope_obj.plugin.plugins:
|
||||
for plugin_representation in microscope_obj.plugins.active:
|
||||
|
||||
plugin_obj = plugin_representation["plugin"]
|
||||
plugin_name = plugin_representation["name"]
|
||||
|
||||
# If plugin contains valid endpoints
|
||||
if hasattr(plugin_obj, "api_views") and isinstance(plugin_obj.api_views, dict):
|
||||
|
|
@ -94,7 +98,7 @@ def construct_blueprint(microscope_obj):
|
|||
if hasattr(plugin_obj, "api_form") and isinstance(
|
||||
plugin_obj.api_form, dict
|
||||
):
|
||||
api_form_info = plugin_obj.api_form
|
||||
api_form_info = copy.deepcopy(plugin_obj.api_form)
|
||||
api_form_info["id"] = plugin_name
|
||||
if "forms" in api_form_info and isinstance(
|
||||
api_form_info["forms"], list
|
||||
|
|
@ -110,8 +114,8 @@ def construct_blueprint(microscope_obj):
|
|||
)
|
||||
|
||||
# Store the complete form in Microscope().plugin.form
|
||||
microscope_obj.plugin.forms.append(api_form_info)
|
||||
print(microscope_obj.plugin.forms)
|
||||
microscope_obj.plugins.forms.append(api_form_info)
|
||||
print(microscope_obj.plugins.forms)
|
||||
|
||||
else:
|
||||
warnings.warn(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue