From cf8fd6ef9ef66eb0834d23a810096497612d9915 Mon Sep 17 00:00:00 2001 From: Carlos Morais Date: Fri, 17 Feb 2012 21:15:07 -0200 Subject: [PATCH] [Mezuro] Auto-loading every 20 seconds --- plugins/mezuro/lib/mezuro_plugin.rb | 4 ---- plugins/mezuro/public/javascripts/dynamic.js | 51 --------------------------------------------------- plugins/mezuro/public/javascripts/project_content.js | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ plugins/mezuro/public/javascripts/source_tree_toggle.js | 6 ------ plugins/mezuro/views/content_viewer/_source_tree.rhtml | 6 +++--- plugins/mezuro/views/content_viewer/show_project.rhtml | 11 ++++------- 6 files changed, 64 insertions(+), 71 deletions(-) delete mode 100644 plugins/mezuro/public/javascripts/dynamic.js create mode 100644 plugins/mezuro/public/javascripts/project_content.js delete mode 100644 plugins/mezuro/public/javascripts/source_tree_toggle.js diff --git a/plugins/mezuro/lib/mezuro_plugin.rb b/plugins/mezuro/lib/mezuro_plugin.rb index 655ea87..cee7d0b 100644 --- a/plugins/mezuro/lib/mezuro_plugin.rb +++ b/plugins/mezuro/lib/mezuro_plugin.rb @@ -16,8 +16,4 @@ class MezuroPlugin < Noosfero::Plugin true end - def js_files - ['javascripts/dynamic.js', 'javascripts/source_tree_toggle.js'] - end - end diff --git a/plugins/mezuro/public/javascripts/dynamic.js b/plugins/mezuro/public/javascripts/dynamic.js deleted file mode 100644 index 10fbba6..0000000 --- a/plugins/mezuro/public/javascripts/dynamic.js +++ /dev/null @@ -1,51 +0,0 @@ -function dynamic($) { - $.get(endpoint('project_state'), {}, select_project_partial); -} - -function endpoint(action){ - var profile = jQuery('#project-content').attr('data-profile'); - var project = jQuery('#project-content').attr('data-content'); - return '/profile/' + profile + '/plugins/mezuro/' + action + '/' + project; -} - -function select_project_partial(state){ - var action, callback = show_project_content; - if (state == 'ERROR') - action = 'project_error'; - else if (state == 'READY') - action = 'project_result'; - else { -// wait(10); - action = 'project_state'; - callback = select_project_partial; - } - jQuery.get(endpoint(action), {}, callback); -} - -//function wait(seconds){ -// var remaining = seconds; -// while(remaining > 0){ -// setTimeout(function() { -// jQuery('#project-content').html("Processing. Trying again in " + remaining + " seconds"); -// }, 1000); -// remaining--; -// } -// jQuery('#project-content').html("Trying now..."); -//} - -function show_project_content(content){ - jQuery('#project-content').html(content); - jQuery('.module-result-link').click(show_module_result); - return false; -} - -function show_module_result(){ - var module_name = jQuery(this).attr('data-module-name'); - jQuery('#module-result').html("Loading results for " + module_name + "..."); - jQuery.get(endpoint('module_result'), { module_name: module_name }, show_result_table); - return false; -} - -function show_result_table(content){ - jQuery('#module-result').html(content); -} diff --git a/plugins/mezuro/public/javascripts/project_content.js b/plugins/mezuro/public/javascripts/project_content.js new file mode 100644 index 0000000..331747e --- /dev/null +++ b/plugins/mezuro/public/javascripts/project_content.js @@ -0,0 +1,57 @@ +jQuery(showProjectContent); + +function showProjectContent() { + callAction('project_state', {}, showProjectContentFor); +} + +function showProjectContentFor(state){ + if (state == 'ERROR') + callAction('project_error', {}, setProjectContent); + else if (state == 'READY') + callAction('project_result', {}, setProjectContent); + else if (state.endsWith("ING")) + showProjectContentAfter(20); +} + +function showProjectContentAfter(seconds){ + if (seconds > 0){ + setProjectContent("Not ready. Trying again in " + seconds + " seconds"); + setTimeout(function() { showProjectContentAfter(seconds - 1);}, 1000); + } else { + setProjectContent("Trying now..."); + showProjectContent(); + } +} + +function setProjectContent(content){ + jQuery('#project-content').html(content); + jQuery('.module-result-link').click(showModuleResult); +} + +function showModuleResult(){ + var module_name = jQuery(this).attr('data-module-name'); + setModuleResult("Loading results for " + module_name + "..."); + callAction('module_result', {module_name: module_name}, setModuleResult); + return false; +} + +function setModuleResult(content){ + jQuery('#module-result').html(content); +} + +function callAction(action, params, callback){ + var profile = projectContentData('profile'); + var content = projectContentData('content'); + var endpoint = '/profile/' + profile + '/plugins/mezuro/' + action + '/' + content; + jQuery.get(endpoint, params, callback); +} + +function projectContentData(data){ + return jQuery('#project-content').attr('data-' + data); +} + +function sourceNodeToggle(id){ + var suffixes = ['_hidden', '_plus', '_minus']; + for (var i in suffixes) + jQuery('#' + id + suffixes[i]).toggle(); +} \ No newline at end of file diff --git a/plugins/mezuro/public/javascripts/source_tree_toggle.js b/plugins/mezuro/public/javascripts/source_tree_toggle.js deleted file mode 100644 index 035562a..0000000 --- a/plugins/mezuro/public/javascripts/source_tree_toggle.js +++ /dev/null @@ -1,6 +0,0 @@ -function source_tree_toggle(id){ - var suffixes = ['_hidden', '_plus', '_minus']; - for (var i in suffixes){ - jQuery('#' + id + suffixes[i]).toggle(); - } -} diff --git a/plugins/mezuro/views/content_viewer/_source_tree.rhtml b/plugins/mezuro/views/content_viewer/_source_tree.rhtml index 9f20d73..28bae10 100644 --- a/plugins/mezuro/views/content_viewer/_source_tree.rhtml +++ b/plugins/mezuro/views/content_viewer/_source_tree.rhtml @@ -5,9 +5,9 @@ + - + id="<%= module_name %>_plus" onclick="sourceNodeToggle('<%= module_name %>')"/> + diff --git a/plugins/mezuro/views/content_viewer/show_project.rhtml b/plugins/mezuro/views/content_viewer/show_project.rhtml index bcbf726..bf20e63 100644 --- a/plugins/mezuro/views/content_viewer/show_project.rhtml +++ b/plugins/mezuro/views/content_viewer/show_project.rhtml @@ -1,5 +1,6 @@ -<% @project = @page.project %> + +<% @project = @page.project %> @@ -29,10 +30,6 @@
-
+

<%= _('Processing ') + @project.name + '...' %>

-
- - +
\ No newline at end of file -- libgit2 0.21.2
<%= _('Name') %>