mirror of
https://github.com/scinote-eln/scinote-web.git
synced 2024-12-28 19:24:10 +08:00
set ajax loading of experiments images [fixes SCI-349]
This commit is contained in:
parent
b86e67a0d6
commit
d38f29d207
7 changed files with 46 additions and 46 deletions
|
@ -1,48 +1,59 @@
|
|||
(function(){
|
||||
var count = 0;
|
||||
|
||||
function initProjectExperiment(){
|
||||
var url = $("[data-lupdated-url]").data("lupdated-url");
|
||||
var updated = "[data-id=" + $("[data-lupdated-id]").data('lupdated-id') +"]";
|
||||
var el = $(updated).find("img");
|
||||
var timestamp = el.data("timestamp");
|
||||
var img_url = $(updated).find(".workflowimg-container").data('updated-img');
|
||||
|
||||
animateSpinner($(updated).find(".workflowimg-container"), true);
|
||||
checkUpdatedImg(el, img_url, url, timestamp, updated);
|
||||
animateSpinner($(updated).find(".workflowimg-container"), false);
|
||||
function init(){
|
||||
$("[data-id]").each(function(){
|
||||
var that = $(this);
|
||||
that.find(".workflowimg-container").hide();
|
||||
initProjectExperiment(that);
|
||||
});
|
||||
}
|
||||
|
||||
function initProjectExperiment(element){
|
||||
var container = element.find(".workflowimg-container");
|
||||
var url = container.data("check-img");
|
||||
var timestamp = container.data("timestamp");
|
||||
var img_url = container.data('updated-img');
|
||||
|
||||
function checkUpdatedImg(el, img_url, url, timestamp, updated){
|
||||
if (count !== 100){
|
||||
animateSpinner(container, true);
|
||||
checkUpdatedImg(img_url, url, timestamp, container);
|
||||
}
|
||||
|
||||
// checks if the experiment image is updated
|
||||
function checkUpdatedImg(img_url, url, timestamp, container){
|
||||
if (count < 30 && timestamp){
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
data: { "timestamp": timestamp },
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
getNewWorkforwImg(el, img_url, updated);
|
||||
animateSpinner($(updated).find(".workflowimg-container"), false);
|
||||
getNewWorkforwImg(container, img_url);
|
||||
container.show();
|
||||
animateSpinner(container, false);
|
||||
},
|
||||
error: function (ev) {
|
||||
if (ev.status == 404) {
|
||||
setTimeout(checkUpdatedImg(el, img_url, url, timestamp, updated), 200);
|
||||
}
|
||||
count++;
|
||||
setTimeout(checkUpdatedImg(img_url, url, timestamp, container), 500);
|
||||
} else {
|
||||
animateSpinner(container, false);
|
||||
}
|
||||
count++;
|
||||
}
|
||||
});
|
||||
} else {
|
||||
animateSpinner(container, false);
|
||||
}
|
||||
}
|
||||
|
||||
function getNewWorkforwImg(el, url, updated){
|
||||
// fetch the new experiment image
|
||||
function getNewWorkforwImg(el, url){
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: "GET",
|
||||
dataType: "json",
|
||||
success: function (data) {
|
||||
el.html(data.workflowimg);
|
||||
animateSpinner($(updated).find(".workflowimg-container"), false);
|
||||
el.append(data.workflowimg);
|
||||
},
|
||||
error: function (ev) {
|
||||
// TODO
|
||||
|
@ -50,5 +61,5 @@
|
|||
});
|
||||
}
|
||||
// init
|
||||
initProjectExperiment();
|
||||
init();
|
||||
})();
|
||||
|
|
|
@ -220,7 +220,7 @@ class ExperimentsController < ApplicationController
|
|||
def updated_img
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
if @experiment.workflowimg_updated_at.to_i !=
|
||||
if @experiment.workflowimg_updated_at.to_i >=
|
||||
params[:timestamp].to_time.to_i
|
||||
render json: {}, status: 200
|
||||
else
|
||||
|
@ -230,19 +230,13 @@ class ExperimentsController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def get_workflow_img
|
||||
def fetch_workflow_img
|
||||
respond_to do |format|
|
||||
format.json do
|
||||
render json: {
|
||||
workflowimg: (link_to image_tag(experiment
|
||||
.workflowimg
|
||||
.expiring_url(30),
|
||||
class: 'img-responsive center-block',
|
||||
data: {
|
||||
timestamp: experiment
|
||||
.workflowimg_updated_at
|
||||
}),
|
||||
canvas_experiment_path(experiment)).to_s
|
||||
workflowimg: render_to_string(
|
||||
partial: 'projects/show/workflow_img.html.erb'
|
||||
)
|
||||
}
|
||||
end
|
||||
end
|
||||
|
|
|
@ -11,11 +11,4 @@ module ProjectsHelper
|
|||
end
|
||||
conns.to_s[1..-2]
|
||||
end
|
||||
|
||||
def last_experiment_updated(project)
|
||||
project
|
||||
.active_experiments(updated_at: :desc)
|
||||
.pluck(:id)
|
||||
.first.to_s
|
||||
end
|
||||
end
|
||||
|
|
|
@ -23,9 +23,7 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row"
|
||||
data-lupdated-id="<%= last_experiment_updated(@project) %>"
|
||||
data-lupdated-url="<%= updated_img_experiment_url(last_experiment_updated(@project))%>">
|
||||
<div class="row">
|
||||
<% @project.active_experiments.each_with_index do |experiment, index| %>
|
||||
<%= render partial: 'projects/show/experiment',
|
||||
locals: { experiment: experiment } %>
|
||||
|
|
|
@ -23,11 +23,12 @@
|
|||
<div class="panel-body">
|
||||
<% if experiment.workflowimg? %>
|
||||
<div class="workflowimg-container"
|
||||
data-updated-img="<%= get_workflow_img_experiment_url(experiment) %>"
|
||||
data-check-img="<%= updated_img_experiment_url(experiment) %>"
|
||||
data-updated-img="<%= fetch_workflow_img_experiment_url(experiment) %>"
|
||||
data-timestamp="<%= experiment.updated_at %>"
|
||||
>
|
||||
<%= link_to image_tag(experiment.workflowimg.expiring_url(30),
|
||||
<%#= link_to image_tag(experiment.workflowimg.expiring_url(30),
|
||||
class: 'img-responsive center-block',
|
||||
data: { timestamp: experiment.workflowimg_updated_at }),
|
||||
canvas_experiment_path(experiment) %>
|
||||
</div>
|
||||
<% end %>
|
||||
|
|
3
app/views/projects/show/_workflow_img.html.erb
Normal file
3
app/views/projects/show/_workflow_img.html.erb
Normal file
|
@ -0,0 +1,3 @@
|
|||
<%= link_to image_tag( @experiment.workflowimg.expiring_url(30),
|
||||
class: 'img-responsive center-block'),
|
||||
canvas_experiment_path(@experiment) %>
|
|
@ -129,7 +129,7 @@ Rails.application.routes.draw do
|
|||
post 'move' # move experiment
|
||||
get 'samples' # Samples for single project
|
||||
get 'updated_img' # Checks if the workflow image is updated
|
||||
get 'get_workflow_img' # Get udated workflow img
|
||||
get 'fetch_workflow_img' # Get udated workflow img
|
||||
# Renders sample datatable for single project (ajax action)
|
||||
post 'samples_index'
|
||||
post :delete_samples,
|
||||
|
|
Loading…
Reference in a new issue