Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions isic/core/templates/core/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -81,21 +81,20 @@
</script>

<script type="text/javascript">
function downloadAsZip(params) {
async function downloadAsZip(params) {
params = params || Object.fromEntries((new URL(document.location)).searchParams);
console.log(params);

axios.post('/api/v2/zip-download/url/', params, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
}).then((resp) => {
try {
const resp = await axios.post('/api/v2/zip-download/url/', params, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
});
window.location.href = resp.data;
}).catch(function(error) {
} catch (error) {
alert('Something went wrong, try again.');
console.error(error);
});
throw error;
}
}
</script>

Expand Down
85 changes: 44 additions & 41 deletions isic/core/templates/core/collection_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@
function collectionDetail() {
return {
errorMessage: '',
shareCollectionWithUsers() {
async shareCollectionWithUsers() {
let _this = this; // eek

if ($('#user-selection').val().length === 0) {
Expand All @@ -205,52 +205,51 @@
}

if (confirm('Are you sure you want to grant additional access to this collection?')) {
axios.post('{% url "api:collection_share_to_users" collection.pk %}', {
user_ids: $('#user-selection').val().map(function(n) { return parseInt(n) }),
notify: document.getElementById('notify-users').checked
}, {
try {
const resp = await axios.post('{% url "api:collection_share_to_users" collection.pk %}', {
user_ids: $('#user-selection').val().map(function(n) { return parseInt(n) }),
notify: document.getElementById('notify-users').checked
}, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
});
window.location.reload();
} catch (error) {
_this.errorMessage = error.response.data[0];
alert('Something went wrong, try again.');
throw error;
}
}
},
async setPinned(pinned) {
try {
const resp = await axios.post('/api/v2/collections/{{ collection.pk }}/set-pinned/', { pinned }, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
}).then((resp) => {
window.location.reload();
}).catch(function(error) {
_this.errorMessage = error.response.data[0];
});
}
},
setPinned(pinned) {
axios.post('/api/v2/collections/{{ collection.pk }}/set-pinned/', { pinned }, {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
}).then(() => {
window.location.reload();
}).catch(function(error) {
if (error.response && error.response.data && error.response.data.error) {
alert(error.response.data.error);
} else {
alert('Something went wrong.');
}
});
} catch (error) {
alert('Something went wrong, try again.');
throw error;
}
},
deleteCollection() {
async deleteCollection() {
if (confirm('Are you sure you want to delete this collection? This action cannot be undone.')) {
axios.delete('/api/v2/collections/{{ collection.pk }}/', {
headers: {
'X-CSRFToken': '{{ csrf_token }}'
}
}).then((resp) => {
try {
const resp = await axios.delete('/api/v2/collections/{{ collection.pk }}/', {
headers: {
'X-CSRFToken': '{{ csrf_token }}'
}
});
window.location.href = '{% url "core/collection-list" %}';
}).catch(function(error) {
if (error.response && error.response.data && error.response.data.error) {
alert(error.response.data.error);
} else {
alert('Something went wrong.');
}
});
} catch (error) {
alert('Something went wrong, try again.');
throw error;
}
}
},
};
Expand All @@ -261,14 +260,18 @@
attributions: [],
fetched: false,
loading: false,
fetchMetaInformation() {
async fetchMetaInformation() {
const _this = this;
this.loading = true;
axios.get('{% url "api:collection_attribution_information" collection.pk %}').then((resp) => {
try {
const resp = await axios.get('{% url "api:collection_attribution_information" collection.pk %}');
_this.attributions = resp.data;
_this.loading = false;
_this.fetched = true;
});
} catch (error) {
alert('Something went wrong, try again.');
throw error;
}
}
}
}
Expand Down
28 changes: 16 additions & 12 deletions isic/core/templates/core/partials/edit_collection_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -29,20 +29,24 @@
removeImage(imageId) {
this._persist();
},
deleteImages() {
async deleteImages() {
let _this = this; // eek
if (confirm(`Are you sure you want to remove ${this.images.size} images from this collection?`)) {
axios.post(`/api/v2/collections/${this.collectionId}/remove-from-list/`, {'isic_ids': this._imagesToArray()},
{ headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
}).then((resp) => {
this.resetImages(`/collections/${this.collectionId}/`);
}).catch(function(error) {
console.error(error);
alert('Something went wrong.');
});
try {
const resp = await axios.post(`/api/v2/collections/${this.collectionId}/remove-from-list/`,
{'isic_ids': this._imagesToArray()},
{
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
}
);
this.resetImages(`/collections/${this.collectionId}/`);
} catch (error) {
alert('Something went wrong, try again.');
throw error;
}
}
},
resetImages(url) {
Expand Down
26 changes: 16 additions & 10 deletions isic/core/templates/core/partials/image_browser_js.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,25 @@
this.addSearchResultsToCollection();
});
},
addSearchResultsToCollection() {
async addSearchResultsToCollection() {
let _this = this;
if (confirm('Are you sure you want to add {{ total_images|intcomma }} images to this collection?')) {
axios.post(`/api/v2/collections/${this.selectedCollection}/populate-from-search/`, '{{ search_body|escapejs }}', {
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
}).then((resp) => {
try {
const resp = await axios.post(
`/api/v2/collections/${this.selectedCollection}/populate-from-search/`,
'{{ search_body|escapejs }}',
{
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
}
},
);
window.location.href = `/collections/${this.selectedCollection}/`;
}).catch(function(error) {
_this.errorMessage = error.response.data[0];
});
} catch (error) {
alert('Something went wrong, try again.');
throw error;
}
} else {
this.selectedCollection = '';
}
Expand Down
28 changes: 13 additions & 15 deletions isic/ingest/templates/ingest/metadata_apply.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,23 @@
</div>

<script type="text/javascript">
function deleteMetadataFile(pk, e) {
async function deleteMetadataFile(pk, e) {
e.preventDefault();

if (confirm('Are you sure you want to delete this file?')) {
fetch(`/api/v2/metadata-files/${pk}/`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
}).then((resp) => {
if (!resp.ok) {
throw new Error('Something went wrong.');
}

try {
const resp = await fetch(`/api/v2/metadata-files/${pk}/`, {
method: 'DELETE',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
});
window.location.reload();
}).catch((error) => {
alert('There was a problem deleting the file.');
});
} catch (error) {
alert('Something went wrong, try again.');
throw error;
}
}
}
</script>
Expand Down
29 changes: 14 additions & 15 deletions isic/ingest/templates/ingest/metadata_file_detail.html
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,28 @@ <h3>{{ metadata_file.blob_name }}</h3>
return {
applying: false,
applied: false,
apply() {
async apply() {
this.applying = true;

fetch(`/api/v2/metadata-files/{{ metadata_file.id }}/update_metadata/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({})
}).then((resp) => {
try {
const resp = await fetch(`/api/v2/metadata-files/{{ metadata_file.id }}/update_metadata/`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'X-CSRFToken': '{{ csrf_token }}'
},
body: JSON.stringify({})
});
if (!resp.ok) {
throw new Error('Something went wrong.');
}

this.applied = true;
this.applying = false;
window.location.href = '{% url "ingest/cohort-detail" cohort.id %}';
}).catch((err) => {
} catch (error) {
this.applying = false;
console.error(err);
alert('Something went wrong.');
});
alert('Something went wrong, try again.');
throw error;
}
}
}
}
Expand Down
Loading