diff --git a/app/assets/javascripts/projects/show.js b/app/assets/javascripts/projects/show.js index 8be597218..ef963b50f 100644 --- a/app/assets/javascripts/projects/show.js +++ b/app/assets/javascripts/projects/show.js @@ -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(); })(); diff --git a/app/controllers/experiments_controller.rb b/app/controllers/experiments_controller.rb index 6a1880205..8f98df299 100644 --- a/app/controllers/experiments_controller.rb +++ b/app/controllers/experiments_controller.rb @@ -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 diff --git a/app/helpers/projects_helper.rb b/app/helpers/projects_helper.rb index 9f51bfadb..5edf289da 100644 --- a/app/helpers/projects_helper.rb +++ b/app/helpers/projects_helper.rb @@ -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 diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 7569d26f3..06581cdb3 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -23,9 +23,7 @@ -