Implemented API delete method
This commit is contained in:
parent
e3724ffefc
commit
ede218ccc3
4 changed files with 43 additions and 13 deletions
|
|
@ -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) {
|
||||
|
|
@ -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>
|
||||
|
|
|
|||
|
|
@ -77,5 +77,5 @@ body {
|
|||
}
|
||||
|
||||
.capture img {
|
||||
width: 60px;
|
||||
width: 80px;
|
||||
}
|
||||
|
|
@ -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
|
||||
|
||||
|
|
@ -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)
|
||||
|
||||
|
|
@ -462,16 +463,23 @@ class CaptureAPI(MicroscopeView):
|
|||
|
||||
def delete(self, capture_id):
|
||||
"""
|
||||
Delete a capture (not yet implemented)
|
||||
|
||||
.. :quickref: Capture; Delete capture
|
||||
Delete all capture data from the Pi, even if `keep_on_disk=true;`.
|
||||
|
||||
.. :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):
|
||||
"""
|
||||
Modify the metadata of a capture (not yet implemented)
|
||||
|
||||
|
||||
.. :quickref: Capture; Update capture metadata
|
||||
"""
|
||||
return jsonify({"return": capture_id})
|
||||
|
|
@ -485,7 +493,7 @@ class CaptureDownloadAPI(MicroscopeView):
|
|||
def get(self, capture_id):
|
||||
"""
|
||||
Return image data for a capture.
|
||||
|
||||
|
||||
.. :quickref: Capture; Download capture file
|
||||
|
||||
**Example request**:
|
||||
|
|
@ -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…
Add table
Add a link
Reference in a new issue