Skip to content

Commit d205435

Browse files
committed
Export download
1 parent da1a97e commit d205435

File tree

4 files changed

+36
-7
lines changed

4 files changed

+36
-7
lines changed

backend/webserver/api/datasets.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,7 @@ def get(self, dataset_id):
373373

374374
time_delta = datetime.datetime.utcnow() - export.created_at
375375
dict_export.append({
376+
'id': export.id,
376377
'ago': query_util.td_format(time_delta),
377378
'tags': export.tags
378379
})

backend/webserver/api/exports.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from flask import send_file
12
from flask_restplus import Namespace, Resource, reqparse
23
from flask_login import login_required, current_user
34

@@ -66,5 +67,5 @@ def get(self, export_id):
6667
if not current_user.can_download(dataset):
6768
return {"message": "You do not have permission to download the dataset's annotations"}, 403
6869

69-
return {}
70+
return send_file(export.path, attachment_filename=f"{dataset.name}-{'-'.join(export.tags)}.json", as_attachment=True)
7071

client/src/models/exports.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
import axios from "axios";
2+
3+
const baseURL = "/api/export";
4+
5+
export default {
6+
download(id, dataset) {
7+
axios({
8+
url: `${baseURL}/${id}/download`,
9+
method: "GET",
10+
responseType: "blob"
11+
}).then(response => {
12+
const url = window.URL.createObjectURL(new Blob([response.data]));
13+
const link = document.createElement("a");
14+
link.href = url;
15+
link.setAttribute("download", `${dataset}-${id}.json`);
16+
document.body.appendChild(link);
17+
link.click();
18+
});
19+
}
20+
};

client/src/views/Dataset.vue

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,15 @@
6666
<h6 class="border-bottom border-gray pb-2"><b>Exports</b></h6>
6767

6868
<div class="media text-muted pt-3" v-for="exp in datasetExports">
69-
<div class="media-body pb-3 mb-0 small lh-125 border-bottom border-gray">
70-
<div class="d-flex justify-content-between align-items-center w-100">
71-
<div class="text-gray-dark">
72-
<strong>Exported {{ exp.ago.length > 0 ? exp.ago : 0 + " seconds" }} ago</strong>
73-
</div>
74-
</div>
69+
<div class="media-body lh-125 border-bottom border-gray">
70+
Exported {{ exp.ago.length > 0 ? exp.ago : 0 + " seconds" }} ago
71+
<button
72+
class="btn btn-sm btn-success"
73+
style="float: right; margin: 2px; padding: 2px"
74+
@click="downloadExport(exp.id)"
75+
>
76+
Download
77+
</button>
7578
</div>
7679
</div>
7780
</div>
@@ -340,6 +343,7 @@
340343
<script>
341344
import toastrs from "@/mixins/toastrs";
342345
import Dataset from "@/models/datasets";
346+
import Export from "@/models/exports";
343347
import ImageCard from "@/components/cards/ImageCard";
344348
import Pagination from "@/components/Pagination";
345349
import PanelString from "@/components/PanelInputString";
@@ -463,6 +467,9 @@ export default {
463467
this.users = response.data
464468
});
465469
},
470+
downloadExport(id) {
471+
Export.download(id, this.dataset.name);
472+
},
466473
getExports() {
467474
Dataset.getExports(this.dataset.id)
468475
.then(response => {

0 commit comments

Comments
 (0)