diff options
-rw-r--r-- | lib/mauve/history.rb | 10 | ||||
-rw-r--r-- | lib/mauve/web_interface.rb | 12 | ||||
-rw-r--r-- | views/_events_calendar_day.haml | 2 | ||||
-rw-r--r-- | views/_history.haml | 2 | ||||
-rw-r--r-- | views/events_list.haml | 4 |
5 files changed, 21 insertions, 9 deletions
diff --git a/lib/mauve/history.rb b/lib/mauve/history.rb index 674099f..fa5078d 100644 --- a/lib/mauve/history.rb +++ b/lib/mauve/history.rb @@ -116,6 +116,16 @@ module Mauve public + def cached_alerts + return @cached_alerts if defined? @cached_alerts + @cached_alerts = [] + end + + def reload + @cached_alerts = [] + super + end + # @return Log4r::Logger def logger Log4r::Logger.new self.class.to_s diff --git a/lib/mauve/web_interface.rb b/lib/mauve/web_interface.rb index 5bb339a..896b9cb 100644 --- a/lib/mauve/web_interface.rb +++ b/lib/mauve/web_interface.rb @@ -476,12 +476,13 @@ EOF query = {:alert => {}, :history => {}} query[:alert][:id] = params[:id] - query[:history][:type] = ["update", "notification"] + query[:history][:type] = ["update", "notification"] + query[:history][:order] = [:created_at.asc] @alert = Alert.get!(params['id']) @title += " Events: Alert #{@alert.alert_id} from #{@alert.source}" @alert_counts = alert_counts(false) - @events = AlertHistory.all(formulate_events_query(query)).history + @events = AlertHistory.all(formulate_events_query(query)) haml :events_list end @@ -527,14 +528,14 @@ EOF query = {:history => {}} query[:history][:created_at.gte] = Time.local(today.year, today.month, today.day, 0, 0, 0) query[:history][:created_at.lt] = Time.local(tomorrow.year, tomorrow.month, tomorrow.day, 0, 0, 0) + query[:history][:order] = [:created_at.asc] events = AlertHistory.all(formulate_events_query(query)) - event_week = ((today - start)/7).floor event_day = (today.wday == 0 ? 6 : (today.wday - 1)) @events_by_week[event_week] ||= Array.new(7) { Array.new } - @events_by_week[event_week][event_day] = (events.count == 0 ? [] : events.history) + @events_by_week[event_week][event_day] = events today = tomorrow end @@ -581,8 +582,9 @@ EOF query = {:history => {}} query[:history][:created_at.gte] = @start query[:history][:created_at.lt] = finish + query[:history][:order] = [:created_at.asc] - @events = AlertHistory.all(formulate_events_query(query)).history + @events = AlertHistory.all(formulate_events_query(query)) @alert_counts = alert_counts(false) haml :events_list diff --git a/views/_events_calendar_day.haml b/views/_events_calendar_day.haml index 712559c..5aee31c 100644 --- a/views/_events_calendar_day.haml +++ b/views/_events_calendar_day.haml @@ -2,7 +2,7 @@ %p.event_date %a{:href => "/events/list/#{@today.strftime("%F")}?#{request.query_string}"} = @today.strftime((@today.day == 1) ? "%d %b" : "%d") - =partial("history", :collection => events_calendar_day.last(10).alerts.to_a.reverse) + =partial("history", :collection => events_calendar_day.first(10).collect{|e| e.history.cached_alerts << e.alert ; e }.collect{|e| e.history}.uniq.sort{|a,b| a.created_at <=> b.created_at}) %p - n_events = events_calendar_day.count - if n_events > 10 diff --git a/views/_history.haml b/views/_history.haml index 400c1c3..a399113 100644 --- a/views/_history.haml +++ b/views/_history.haml @@ -3,7 +3,7 @@ = history.created_at.strftime("%a %d %b %Y") %p = history.created_at.strftime("%R") - - history.alerts.each do |alert| + - (history.cached_alerts.empty? ? history.alerts : history.cached_alerts).each do |alert| %a{ :href => self.class.url_for(alert) } = alert.id %strong diff --git a/views/events_list.haml b/views/events_list.haml index ff56310..ed08d3a 100644 --- a/views/events_list.haml +++ b/views/events_list.haml @@ -11,8 +11,8 @@ %a{:href => "/events/calendar/#{@start.strftime("%Y-%m")}?"+request.query_string} Calendar view = partial('events_form') -- if @events.length > 0 - = partial('history', :collection => @events) +- if @events.count > 0 + = partial('history', :collection => @events.collect{|e| e.history.cached_alerts << e.alert ; e }.collect{|e| e.history}.uniq.sort{|a,b| a.created_at <=> b.created_at}) - else %p %strong |