Commit cf8fd6ef9ef66eb0834d23a810096497612d9915
1 parent
15de0856
Exists in
master
and in
28 other branches
[Mezuro] Auto-loading every 20 seconds
Showing
6 changed files
with
64 additions
and
71 deletions
Show diff stats
plugins/mezuro/lib/mezuro_plugin.rb
plugins/mezuro/public/javascripts/dynamic.js
| ... | ... | @@ -1,51 +0,0 @@ |
| 1 | -function dynamic($) { | |
| 2 | - $.get(endpoint('project_state'), {}, select_project_partial); | |
| 3 | -} | |
| 4 | - | |
| 5 | -function endpoint(action){ | |
| 6 | - var profile = jQuery('#project-content').attr('data-profile'); | |
| 7 | - var project = jQuery('#project-content').attr('data-content'); | |
| 8 | - return '/profile/' + profile + '/plugins/mezuro/' + action + '/' + project; | |
| 9 | -} | |
| 10 | - | |
| 11 | -function select_project_partial(state){ | |
| 12 | - var action, callback = show_project_content; | |
| 13 | - if (state == 'ERROR') | |
| 14 | - action = 'project_error'; | |
| 15 | - else if (state == 'READY') | |
| 16 | - action = 'project_result'; | |
| 17 | - else { | |
| 18 | -// wait(10); | |
| 19 | - action = 'project_state'; | |
| 20 | - callback = select_project_partial; | |
| 21 | - } | |
| 22 | - jQuery.get(endpoint(action), {}, callback); | |
| 23 | -} | |
| 24 | - | |
| 25 | -//function wait(seconds){ | |
| 26 | -// var remaining = seconds; | |
| 27 | -// while(remaining > 0){ | |
| 28 | -// setTimeout(function() { | |
| 29 | -// jQuery('#project-content').html("Processing. Trying again in " + remaining + " seconds"); | |
| 30 | -// }, 1000); | |
| 31 | -// remaining--; | |
| 32 | -// } | |
| 33 | -// jQuery('#project-content').html("Trying now..."); | |
| 34 | -//} | |
| 35 | - | |
| 36 | -function show_project_content(content){ | |
| 37 | - jQuery('#project-content').html(content); | |
| 38 | - jQuery('.module-result-link').click(show_module_result); | |
| 39 | - return false; | |
| 40 | -} | |
| 41 | - | |
| 42 | -function show_module_result(){ | |
| 43 | - var module_name = jQuery(this).attr('data-module-name'); | |
| 44 | - jQuery('#module-result').html("Loading results for " + module_name + "..."); | |
| 45 | - jQuery.get(endpoint('module_result'), { module_name: module_name }, show_result_table); | |
| 46 | - return false; | |
| 47 | -} | |
| 48 | - | |
| 49 | -function show_result_table(content){ | |
| 50 | - jQuery('#module-result').html(content); | |
| 51 | -} |
| ... | ... | @@ -0,0 +1,57 @@ |
| 1 | +jQuery(showProjectContent); | |
| 2 | + | |
| 3 | +function showProjectContent() { | |
| 4 | + callAction('project_state', {}, showProjectContentFor); | |
| 5 | +} | |
| 6 | + | |
| 7 | +function showProjectContentFor(state){ | |
| 8 | + if (state == 'ERROR') | |
| 9 | + callAction('project_error', {}, setProjectContent); | |
| 10 | + else if (state == 'READY') | |
| 11 | + callAction('project_result', {}, setProjectContent); | |
| 12 | + else if (state.endsWith("ING")) | |
| 13 | + showProjectContentAfter(20); | |
| 14 | +} | |
| 15 | + | |
| 16 | +function showProjectContentAfter(seconds){ | |
| 17 | + if (seconds > 0){ | |
| 18 | + setProjectContent("Not ready. Trying again in " + seconds + " seconds"); | |
| 19 | + setTimeout(function() { showProjectContentAfter(seconds - 1);}, 1000); | |
| 20 | + } else { | |
| 21 | + setProjectContent("Trying now..."); | |
| 22 | + showProjectContent(); | |
| 23 | + } | |
| 24 | +} | |
| 25 | + | |
| 26 | +function setProjectContent(content){ | |
| 27 | + jQuery('#project-content').html(content); | |
| 28 | + jQuery('.module-result-link').click(showModuleResult); | |
| 29 | +} | |
| 30 | + | |
| 31 | +function showModuleResult(){ | |
| 32 | + var module_name = jQuery(this).attr('data-module-name'); | |
| 33 | + setModuleResult("Loading results for " + module_name + "..."); | |
| 34 | + callAction('module_result', {module_name: module_name}, setModuleResult); | |
| 35 | + return false; | |
| 36 | +} | |
| 37 | + | |
| 38 | +function setModuleResult(content){ | |
| 39 | + jQuery('#module-result').html(content); | |
| 40 | +} | |
| 41 | + | |
| 42 | +function callAction(action, params, callback){ | |
| 43 | + var profile = projectContentData('profile'); | |
| 44 | + var content = projectContentData('content'); | |
| 45 | + var endpoint = '/profile/' + profile + '/plugins/mezuro/' + action + '/' + content; | |
| 46 | + jQuery.get(endpoint, params, callback); | |
| 47 | +} | |
| 48 | + | |
| 49 | +function projectContentData(data){ | |
| 50 | + return jQuery('#project-content').attr('data-' + data); | |
| 51 | +} | |
| 52 | + | |
| 53 | +function sourceNodeToggle(id){ | |
| 54 | + var suffixes = ['_hidden', '_plus', '_minus']; | |
| 55 | + for (var i in suffixes) | |
| 56 | + jQuery('#' + id + suffixes[i]).toggle(); | |
| 57 | +} | |
| 0 | 58 | \ No newline at end of file | ... | ... |
plugins/mezuro/public/javascripts/source_tree_toggle.js
plugins/mezuro/views/content_viewer/_source_tree.rhtml
| ... | ... | @@ -5,9 +5,9 @@ |
| 5 | 5 | <tr> |
| 6 | 6 | <td width="10%"> |
| 7 | 7 | <img alt="+" src="/plugins/mezuro/images/plus.png" class="link" |
| 8 | - id="<%= module_name %>_plus" onclick="source_tree_toggle('<%= module_name %>')"/> | |
| 9 | - <img alt="-" src="/plugins/mezuro/images/minus.png" class="link" | |
| 10 | - id="<%= module_name %>_minus" onclick="source_tree_toggle('<%= module_name %>')" style="display: none"/> | |
| 8 | + id="<%= module_name %>_plus" onclick="sourceNodeToggle('<%= module_name %>')"/> | |
| 9 | + <img alt="-" src="/plugins/mezuro/images/minus.png" class="link" style="display: none" | |
| 10 | + id="<%= module_name %>_minus" onclick="sourceNodeToggle('<%= module_name %>')"/> | |
| 11 | 11 | </td> |
| 12 | 12 | <td> |
| 13 | 13 | <a href="#" class="module-result-link" data-module-name="<%= module_name %>"> | ... | ... |
plugins/mezuro/views/content_viewer/show_project.rhtml
| 1 | -<% @project = @page.project %> | |
| 1 | +<script src="/plugins/mezuro/javascripts/project_content.js" type="text/javascript"></script> | |
| 2 | 2 | |
| 3 | +<% @project = @page.project %> | |
| 3 | 4 | <table> |
| 4 | 5 | <tr> |
| 5 | 6 | <td><%= _('Name') %></td> |
| ... | ... | @@ -29,10 +30,6 @@ |
| 29 | 30 | |
| 30 | 31 | <br /> |
| 31 | 32 | |
| 32 | -<div id="project-content" data-profile="<%= @page.profile.identifier %>" data-content='<%= @page.id %>'> | |
| 33 | +<div id="project-content" data-profile="<%= @page.profile.identifier %>" data-content="<%= @page.id %>"> | |
| 33 | 34 | <h3><%= _('Processing ') + @project.name + '...' %></h3> |
| 34 | -</div> | |
| 35 | - | |
| 36 | -<script type="text/javascript"> | |
| 37 | - jQuery(dynamic); | |
| 38 | -</script> | |
| 35 | +</div> | |
| 39 | 36 | \ No newline at end of file | ... | ... |