From 79d0b4379368fa188e9e08b8f4da9fb784732fe1 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 4 May 2011 09:08:17 +0200 Subject: [PATCH 1/4] [FIT #19136] Upon saving a private report, the "Save As" button is still labeled with just "Save". This is a cache-invalidation problem (the report was previously 'new', so we had cached this widget's html, even though it depends on the save-status of the widget, too). Solved by adding the new_record? state to the cache_key for controls, and actually have controls inherit from Widget::Controls --- lib/widget/controls.rb | 4 ++++ lib/widget/controls/apply.rb | 2 +- lib/widget/controls/clear.rb | 2 +- lib/widget/controls/delete.rb | 2 +- lib/widget/controls/query_name.rb | 2 +- lib/widget/controls/save.rb | 2 +- lib/widget/controls/save_as.rb | 3 ++- lib/widget/{controls => }/help.rb | 0 8 files changed, 11 insertions(+), 6 deletions(-) rename lib/widget/{controls => }/help.rb (100%) diff --git a/lib/widget/controls.rb b/lib/widget/controls.rb index b8d8b9c516..12e83d2c05 100644 --- a/lib/widget/controls.rb +++ b/lib/widget/controls.rb @@ -1,3 +1,7 @@ class Widget::Controls < Widget::Base extend ProactiveAutoloader + + def cache_key + "#{super}#{@query.new_record? ? 1 : 0}" + end end diff --git a/lib/widget/controls/apply.rb b/lib/widget/controls/apply.rb index d8bcecbde0..d52c31e406 100644 --- a/lib/widget/controls/apply.rb +++ b/lib/widget/controls/apply.rb @@ -1,5 +1,5 @@ -class Widget::Controls::Apply < Widget::Base +class Widget::Controls::Apply < Widget::Controls def render write link_to content_tag(:span, content_tag(:em, l(:button_apply))), {}, :href => "#", :id => "query-icon-apply-button", diff --git a/lib/widget/controls/clear.rb b/lib/widget/controls/clear.rb index c6dbadec4c..89a022133d 100644 --- a/lib/widget/controls/clear.rb +++ b/lib/widget/controls/clear.rb @@ -1,5 +1,5 @@ -class Widget::Controls::Clear < Widget::Base +class Widget::Controls::Clear < Widget::Controls def render html = link_to(content_tag(:span, content_tag(:em, l(:"button_clear"), :class => "button-icon icon-clear")), '#', :id => 'query-link-clear', :class => 'button secondary') diff --git a/lib/widget/controls/delete.rb b/lib/widget/controls/delete.rb index b26f3fc3e5..a738d9890c 100644 --- a/lib/widget/controls/delete.rb +++ b/lib/widget/controls/delete.rb @@ -1,4 +1,4 @@ -class Widget::Controls::Delete < Widget::Base +class Widget::Controls::Delete < Widget::Controls def render return "" if @query.new_record? or !@options[:can_delete] button = link_to content_tag(:span, content_tag(:em, l(:button_delete), :class => "button-icon icon-delete")), "#", diff --git a/lib/widget/controls/query_name.rb b/lib/widget/controls/query_name.rb index 873eb98032..ba5fd36aba 100644 --- a/lib/widget/controls/query_name.rb +++ b/lib/widget/controls/query_name.rb @@ -1,4 +1,4 @@ -class Widget::Controls::QueryName < Widget::Base +class Widget::Controls::QueryName < Widget::Controls dont_cache! # The name might change, but the query stays the same... def render diff --git a/lib/widget/controls/save.rb b/lib/widget/controls/save.rb index 3f54451805..f030bc8a3a 100644 --- a/lib/widget/controls/save.rb +++ b/lib/widget/controls/save.rb @@ -1,4 +1,4 @@ -class Widget::Controls::Save < Widget::Base +class Widget::Controls::Save < Widget::Controls def render return "" if @query.new_record? or !@options[:can_save] write link_to content_tag(:span, content_tag(:em, l(:button_save)), :class => "button-icon icon-save"), {}, diff --git a/lib/widget/controls/save_as.rb b/lib/widget/controls/save_as.rb index de629bbc64..61e87e1846 100644 --- a/lib/widget/controls/save_as.rb +++ b/lib/widget/controls/save_as.rb @@ -1,4 +1,5 @@ -class Widget::Controls::SaveAs < Widget::Base +class Widget::Controls::SaveAs < Widget::Controls + def render if @query.new_record? link_name = l(:button_save) diff --git a/lib/widget/controls/help.rb b/lib/widget/help.rb similarity index 100% rename from lib/widget/controls/help.rb rename to lib/widget/help.rb From 1f1d5dc22acf3c213161f2da09a59e8b6a80912a Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 4 May 2011 09:25:12 +0200 Subject: [PATCH 2/4] The Help widget is not control, even though it might be rendered next to one --- lib/widget/base.rb | 2 +- lib/widget/help.rb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/widget/base.rb b/lib/widget/base.rb index cf0a0c7a31..1a84f3ce85 100644 --- a/lib/widget/base.rb +++ b/lib/widget/base.rb @@ -111,7 +111,7 @@ class Widget::Base < Widget options[:fallback_html] ||= '' output = "".html_safe if text = options[:help_text] || help_text - output += render_widget Widget::Controls::Help, text do + output += render_widget Widget::Help, text do options end else diff --git a/lib/widget/help.rb b/lib/widget/help.rb index 021092a2ae..011ed89752 100644 --- a/lib/widget/help.rb +++ b/lib/widget/help.rb @@ -1,8 +1,8 @@ ## -# Usgae: render_widget Widget::Controls::Help, :text +# Usage: render_widget Widget::Help, :text # # Where :text is a i18n key. -class Widget::Controls::Help < Widget::Base +class Widget::Help < Widget::Base dont_cache! def render From 29ef6e820b5242f80f99d8c65657b2921b639f94 Mon Sep 17 00:00:00 2001 From: Tim Felgentreff Date: Wed, 4 May 2011 10:20:37 +0200 Subject: [PATCH 3/4] Stop the progressbar when an error occurs trying to fetch a report. --- assets/javascripts/reporting/controls.js | 2 ++ assets/javascripts/reporting/progressbar.js | 10 +++++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/assets/javascripts/reporting/controls.js b/assets/javascripts/reporting/controls.js index 829b54d98d..a7d0e80f4f 100644 --- a/assets/javascripts/reporting/controls.js +++ b/assets/javascripts/reporting/controls.js @@ -121,8 +121,10 @@ Reporting.Controls = { default_failure_callback: function (response) { if (response.status >= 400 && response.status < 500) { Reporting.flash(response.responseText); + Reporting.Progress.abort(); } else { Reporting.flash("There was an error getting the results. The administrator has been informed."); + Reporting.Progress.abort(); } } }; diff --git a/assets/javascripts/reporting/progressbar.js b/assets/javascripts/reporting/progressbar.js index 24f3f184bf..bd6cbb0411 100644 --- a/assets/javascripts/reporting/progressbar.js +++ b/assets/javascripts/reporting/progressbar.js @@ -3,14 +3,18 @@ Reporting.Progress = { + abort: function () { + window.progressbar.stop(); + }, + replace_with_bar: function (element) { var parent = element.up(); var size = parseInt(element.getAttribute('data-query-size'), 10) || 500; element.remove(); - var bar = Reporting.Progress.add_bar_to_parent(parent); + window.progressbar = Reporting.Progress.add_bar_to_parent(parent); // Speed determined through laborous experimentation! - bar.options.interval = (size * (Math.log(size))) / 100000; - bar.start(); + window.progressbar.options.interval = (size * (Math.log(size))) / 100000; + window.progressbar.start(); }, add_bar_to_parent: function (parent) { From f149d39cd723a0cca4916cbbcd8bd9770949baee Mon Sep 17 00:00:00 2001 From: Markus Kahl Date: Wed, 4 May 2011 10:56:50 +0200 Subject: [PATCH 4/4] fix too large tmp file names --- lib/widget/base.rb | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/lib/widget/base.rb b/lib/widget/base.rb index 1a84f3ce85..2467719e7d 100644 --- a/lib/widget/base.rb +++ b/lib/widget/base.rb @@ -1,3 +1,5 @@ +require 'digest/sha1' + class Widget::Base < Widget attr_reader :engine, :output @@ -57,10 +59,12 @@ class Widget::Base < Widget end def cache_key - @cache_key ||= if subject.respond_to? :cache_key - "#{self.class.name.demodulize}/#{subject.cache_key}/#{@options.sort_by(&:to_s)}" - else - subject + @cache_key ||= Digest::SHA1::hexdigest begin + if subject.respond_to? :cache_key + "#{self.class.name.demodulize}/#{subject.cache_key}/#{@options.sort_by(&:to_s)}" + else + subject.inspect + end end end @@ -74,7 +78,6 @@ class Widget::Base < Widget !self.class.dont_cache? end - ## # Render this widget or serve it from cache def render_with_cache(options = {}, &block)