Skip to content

Commit

Permalink
Initial UI block when saving to all
Browse files Browse the repository at this point in the history
  • Loading branch information
knabar committed Mar 13, 2024
1 parent 99aebd2 commit 882def8
Show file tree
Hide file tree
Showing 3 changed files with 79 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,7 @@ OME.refreshThumbnails = function(options) {
spw_selector = "#image-" + options.imageId + ", #wellImages li[data-imageId='" + options.imageId + "']";
}

var promise = Promise.resolve();
// Try SPW data or Search data by directly updating thumb src...
var $thumbs = $(spw_selector + ", " + search_selector);
if ($thumbs.length > 0){
Expand All @@ -392,7 +393,7 @@ OME.refreshThumbnails = function(options) {
// filter out empty wells etc.
return img_id.length > 0;
}).get();
OME.load_thumbnails(
promise = OME.load_thumbnails(
options.thumbnail_url,
iids, options.thumbnailsBatch,
options.defaultThumbnail
Expand All @@ -407,59 +408,68 @@ OME.refreshThumbnails = function(options) {
data = {'imageId': options.imageId};
}
var e = {'type': type};
update_thumbnails_panel(e, data);
promise = update_thumbnails_panel(e, data);
}

// Update viewport via global variable
if (!options.ignorePreview && OME.preview_viewport && OME.preview_viewport.loadedImg.id) {
OME.preview_viewport.load(OME.preview_viewport.loadedImg.id);
}

return promise;
};

OME.load_thumbnails = function(thumbnails_url, input, batch, dthumb) {
OME.load_thumbnails = function (thumbnails_url, input, batch, dthumb) {
// load thumbnails in a batches
if (input.length > 0 && batch > 0) {
var iids = input.slice(0 , batch)
var iids = input.slice(0, batch)
if (iids.length > 0) {
$.ajax({
type: "GET",
url: thumbnails_url,
data: $.param( { id: iids }, true),
dataType: 'json',
success: function(data){
var invalid_thumbs = [];
$.each(data, function(key, value) {
if (value !== null) {
// SPW Plate and WellImages
$("img#image-"+key).attr("src", value);
$("#wellImages li[data-imageId='" + key + "'] img").attr("src", value);
$("#well_birds_eye img[data-imageid='" + key + "']").attr("src", value);
// Search results
$("#image_icon-" + key + " img").attr("src", value);
var promise = new Promise(function (resolve) {
$.ajax({
type: "GET",
url: thumbnails_url,
data: $.param({id: iids}, true),
dataType: 'json',
success: function (data) {
var invalid_thumbs = [];
$.each(data, function (key, value) {
if (value !== null) {
// SPW Plate and WellImages
$("img#image-" + key).attr("src", value);
$("#wellImages li[data-imageId='" + key + "'] img").attr("src", value);
$("#well_birds_eye img[data-imageid='" + key + "']").attr("src", value);
// Search results
$("#image_icon-" + key + " img").attr("src", value);
} else {
invalid_thumbs.push(key);
}
});
// If we got invalid thumbnails as a set and ALL failed, try re-loading 1 at a time
if (invalid_thumbs.length === iids.length && batch > 1) {
OME.load_thumbnails(thumbnails_url, invalid_thumbs, 1, dthumb).then(resolve);
} else {
invalid_thumbs.push(key);
// If only some thumbs failed (or single thumb failed), show placeholder
if ((invalid_thumbs.length < iids.length) || (batch === 1 && invalid_thumbs.length === 1)) {
// If batch > 1 then we try loading again, otherwise we failed...
invalid_thumbs.forEach(function (key) {
$("img#image-" + key).attr("src", dthumb);
$("#wellImages li[data-imageId='" + key + "'] img").attr("src", dthumb);
$("#image_icon-" + key + " img").attr("src", dthumb);
});
}
resolve();
}
});
// If we got invalid thumbnails as a set and ALL failed, try re-loading 1 at a time
if (invalid_thumbs.length === iids.length && batch > 1) {
OME.load_thumbnails(thumbnails_url, invalid_thumbs, 1, dthumb);
}
// If only some thumbs failed (or single thumb failed), show placeholder
if ((invalid_thumbs.length < iids.length) || (batch === 1 && invalid_thumbs.length === 1)) {
// If batch > 1 then we try loading again, otherwise we failed...
invalid_thumbs.forEach(function(key){
$("img#image-"+key).attr("src", dthumb);
$("#wellImages li[data-imageId='" + key + "'] img").attr("src", dthumb);
$("#image_icon-" + key + " img").attr("src", dthumb);
});
}
}
},
error: resolve,
});
});
input = input.slice(batch, input.length);
OME.load_thumbnails(thumbnails_url, input, batch, dthumb);
return Promise.all([promise, OME.load_thumbnails(thumbnails_url, input, batch, dthumb)]);
}
}
}
return Promise.resolve();
};

OME.load_thumbnail = function(iid, thumbnails_url, callback) {
// load thumbnails in a batches
$.ajax({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,16 @@
.line {
fill: none;
}

.ome-modal-progress button {
display: none;
}
.ome-modal-progress .ui-dialog-content {
justify-content: center;
align-items: center;
font-size: larger;
display: flex;
}
</style>


Expand Down Expand Up @@ -322,6 +332,18 @@
.attr('title', "Apply and Save settings to all images in " + pid)
.prop('disabled', false).removeClass("button-disabled")
.on('click', function(){
var progress = $('<div><img class="loader" alt="Loading" src="{% static "webgateway/img/spinner.gif" %}"/>&nbsp;Saving to all...</div>')
.appendTo(document.body)
.dialog({
modal: true,
autoOpen: true,
closeOnEscape: false,
draggable: false,
resizable: false,
classes: {
'ui-dialog': 'ome-modal-progress',
}
});
var $span = $('span', this),
spanTxt = $span.text();
$span.text("Saving...");
Expand All @@ -348,6 +370,8 @@
'thumbnail_url': "{% url 'get_thumbnails_json' %}",
'defaultThumbnail': "{% static 'webgateway/img/image128.png' %}",
'thumbnailsBatch': 1
}).finally(function () {
progress.dialog('destroy').remove();
});
updateMyRdef(OME.preview_viewport.getQuery());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,14 @@
$("#content_details").html("");
parentId = undefined;
clearThumbnailsPanel();
return;
return Promise.resolve();
}
var dtype = selected[0].type;
if (selected.length > 1 && dtype !== "image") {
$("#content_details").html("");
parentId = undefined;
clearThumbnailsPanel();
return;
return Promise.resolve();
}

// parent node could be dataset, orphaned, share or tag
Expand All @@ -182,12 +182,12 @@
} else if (dtype === "plate" || dtype === "acquisition") {
parentId = undefined;
load_spw(event, data);
return;
return Promise.resolve();
// All other types have blank centre panel
} else {
parentId = undefined;
clearThumbnailsPanel();
return;
return Promise.resolve();
}

if (!parentNode) {
Expand All @@ -206,7 +206,7 @@

highlightSelectedThumbs(selected);

return;
return Promise.resolve();
}
// update single thumbnail, see OME.refreshThumbnails
if (event.type === "refreshThumb") {
Expand All @@ -217,7 +217,7 @@
$("li#image_icon-"+data.imageId+ " img").attr("src", thumb);
}
);
return;
return Promise.resolve();
}

parentId = newParentId;
Expand Down Expand Up @@ -312,7 +312,7 @@
if (parentNode.type === "share") {
thumbnailsBatch = 1;
}
OME.load_thumbnails(
var promise = OME.load_thumbnails(
thumbUrl, iids, thumbnailsBatch,
"{% static 'webgateway/img/image128.png' %}"
);
Expand All @@ -331,7 +331,7 @@
// scroll to selected thumbnail (if any)
focusThumbnail();

return;
return promise;
}

// Update thumbnails when we switch between plugins
Expand Down

0 comments on commit 882def8

Please sign in to comment.