Loading openflexure_microscope/api/static/main_v1.js +20 −4 Original line number Diff line number Diff line Loading @@ -44,15 +44,26 @@ window.onload = function() { getCaptures() } function deleteCapture(capture_id) { function deleteCaptureCallback(response, status) { console.log(status); getCaptures(); } var r = confirm("Warning! This will delete all copies of this capture from the Raspberry Pi. Click OK to proceed."); if (r == true) { safeRequest("DELETE", baseURI+"/capture/"+capture_id+"/", null, deleteCaptureCallback, false) } } function getCaptures() { function updateCapturesCallback(response, status) { console.log(status); updateCaptures(response); updateCaptureList(response); } safeRequest("GET", baseURI+"/capture", null, updateCapturesCallback, false) } function updateCaptures(response) { function updateCaptureList(response) { // Clear captures list var capturesNode = document.getElementById("captures"); while (capturesNode.firstChild) { Loading @@ -69,8 +80,13 @@ function updateCaptures(response) { <div class="clearfix"> <div class="left-col"><img src="${element_uri}/download?thumbnail=true"></div> <div class="right-col"> <b>${element.filename}</b><br> <a href="${element_uri}/download" target="_blank">View</a> <a href="${element_uri}/download?as_attachment=true">Download</a> Delete <a href="${element_uri}/" target="_blank">JSON</a> <b>${element.filename}</b> <br> <button type="button" onclick="window.open('${element_uri}/download', '_blank');">View</button> <button type="button" onclick="window.open('${element_uri}/download?as_attachment=true');">Download</button> <br> <button type="button" onclick="window.open('${element_uri}/', '_blank');">JSON</button> <button type="button" onclick="deleteCapture('${element.id}');">Delete</button> <br> </div> </div> Loading openflexure_microscope/api/static/style_v1.css +1 −1 Original line number Diff line number Diff line Loading @@ -77,5 +77,5 @@ body { } .capture img { width: 60px; width: 80px; } No newline at end of file openflexure_microscope/api/v1.py +16 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ def uri(suffix, base=None): # Create flask app app = Flask(__name__) app.url_map.strict_slashes = False # Make errors more API friendly Loading Loading @@ -291,9 +292,9 @@ class CaptureListAPI(MicroscopeView): include_unavailable = get_bool(request.args.get('include_unavailable')) if include_unavailable: captures = [image.metadata for image in self.microscope.camera.images if image.metadata['available']] else: captures = [image.metadata for image in self.microscope.camera.images] else: captures = [image.metadata for image in self.microscope.camera.images if image.metadata['available']] return jsonify(captures) Loading Loading @@ -462,10 +463,17 @@ class CaptureAPI(MicroscopeView): def delete(self, capture_id): """ Delete a capture (not yet implemented) Delete all capture data from the Pi, even if `keep_on_disk=true;`. .. :quickref: Capture; Delete capture .. :quickref: Capture; Delete capture. """ capture_obj = self.microscope.camera.image_from_id(capture_id) if not capture_obj: return abort(404) # 404 Not Found capture_obj.delete() return jsonify({"return": capture_id}) def put(self, capture_id): Loading Loading @@ -505,7 +513,7 @@ class CaptureDownloadAPI(MicroscopeView): print(capture_id) capture_obj = self.microscope.camera.image_from_id(capture_id) if not capture_obj: if not capture_obj or not capture_obj.metadata['available']: return abort(404) # 404 Not Found as_attachment = get_bool(request.args.get('as_attachment')) Loading openflexure_microscope/camera/capture.py +6 −0 Original line number Diff line number Diff line Loading @@ -251,6 +251,12 @@ class StreamObject(object): else: return False def delete(self): """Entirely delete all capture data.""" logging.info("Deleting {}".format(self.id)) self.delete_stream() self.delete_file() def shunt(self): """Demote the StreamObject from being stored in memory.""" if not self.file_exists: # If file doesn't already exist Loading Loading
openflexure_microscope/api/static/main_v1.js +20 −4 Original line number Diff line number Diff line Loading @@ -44,15 +44,26 @@ window.onload = function() { getCaptures() } function deleteCapture(capture_id) { function deleteCaptureCallback(response, status) { console.log(status); getCaptures(); } var r = confirm("Warning! This will delete all copies of this capture from the Raspberry Pi. Click OK to proceed."); if (r == true) { safeRequest("DELETE", baseURI+"/capture/"+capture_id+"/", null, deleteCaptureCallback, false) } } function getCaptures() { function updateCapturesCallback(response, status) { console.log(status); updateCaptures(response); updateCaptureList(response); } safeRequest("GET", baseURI+"/capture", null, updateCapturesCallback, false) } function updateCaptures(response) { function updateCaptureList(response) { // Clear captures list var capturesNode = document.getElementById("captures"); while (capturesNode.firstChild) { Loading @@ -69,8 +80,13 @@ function updateCaptures(response) { <div class="clearfix"> <div class="left-col"><img src="${element_uri}/download?thumbnail=true"></div> <div class="right-col"> <b>${element.filename}</b><br> <a href="${element_uri}/download" target="_blank">View</a> <a href="${element_uri}/download?as_attachment=true">Download</a> Delete <a href="${element_uri}/" target="_blank">JSON</a> <b>${element.filename}</b> <br> <button type="button" onclick="window.open('${element_uri}/download', '_blank');">View</button> <button type="button" onclick="window.open('${element_uri}/download?as_attachment=true');">Download</button> <br> <button type="button" onclick="window.open('${element_uri}/', '_blank');">JSON</button> <button type="button" onclick="deleteCapture('${element.id}');">Delete</button> <br> </div> </div> Loading
openflexure_microscope/api/static/style_v1.css +1 −1 Original line number Diff line number Diff line Loading @@ -77,5 +77,5 @@ body { } .capture img { width: 60px; width: 80px; } No newline at end of file
openflexure_microscope/api/v1.py +16 −8 Original line number Diff line number Diff line Loading @@ -44,6 +44,7 @@ def uri(suffix, base=None): # Create flask app app = Flask(__name__) app.url_map.strict_slashes = False # Make errors more API friendly Loading Loading @@ -291,9 +292,9 @@ class CaptureListAPI(MicroscopeView): include_unavailable = get_bool(request.args.get('include_unavailable')) if include_unavailable: captures = [image.metadata for image in self.microscope.camera.images if image.metadata['available']] else: captures = [image.metadata for image in self.microscope.camera.images] else: captures = [image.metadata for image in self.microscope.camera.images if image.metadata['available']] return jsonify(captures) Loading Loading @@ -462,10 +463,17 @@ class CaptureAPI(MicroscopeView): def delete(self, capture_id): """ Delete a capture (not yet implemented) Delete all capture data from the Pi, even if `keep_on_disk=true;`. .. :quickref: Capture; Delete capture .. :quickref: Capture; Delete capture. """ capture_obj = self.microscope.camera.image_from_id(capture_id) if not capture_obj: return abort(404) # 404 Not Found capture_obj.delete() return jsonify({"return": capture_id}) def put(self, capture_id): Loading Loading @@ -505,7 +513,7 @@ class CaptureDownloadAPI(MicroscopeView): print(capture_id) capture_obj = self.microscope.camera.image_from_id(capture_id) if not capture_obj: if not capture_obj or not capture_obj.metadata['available']: return abort(404) # 404 Not Found as_attachment = get_bool(request.args.get('as_attachment')) Loading
openflexure_microscope/camera/capture.py +6 −0 Original line number Diff line number Diff line Loading @@ -251,6 +251,12 @@ class StreamObject(object): else: return False def delete(self): """Entirely delete all capture data.""" logging.info("Deleting {}".format(self.id)) self.delete_stream() self.delete_file() def shunt(self): """Demote the StreamObject from being stored in memory.""" if not self.file_exists: # If file doesn't already exist Loading