app/helpers/event_groups_helper.rb in whoops-0.3.5 vs app/helpers/event_groups_helper.rb in whoops-0.4.0

- old
+ new

@@ -1,31 +1,38 @@ module EventGroupsHelper def event_group_scoped_link(event_group, scope) new_filter = {:whoops_filter => event_group_filter.to_query_document.merge(scope => event_group.send(scope))} link_to(event_group.send(scope), whoops_event_groups_path(new_filter)) end - - # meant for consumption by options_from_collection_for_select - def filter_options - all_event_groups = Whoops::EventGroup.all - return @filter_options if @filter_options - @filter_options = Hash.new{|h, k| h[k] = []} - - @filter_options["service"] = Whoops::EventGroup.services.to_a - @filter_options["environment"] = Whoops::EventGroup.all.distinct("environment") - @filter_options["event_type"] = Whoops::EventGroup.all.distinct("event_type") + def filter_field_allowed_values + return @filter_field_allowed_values if @filter_field_allowed_values + @filter_field_allowed_values = Hash.new{|h, k| h[k] = [["all"]]} - # add the field name as an empty option - @filter_options.keys.each do |field_name| - @filter_options[field_name].compact! - @filter_options[field_name].sort!{|a, b| a.first <=> b.first}.uniq! if @filter_options[field_name] - end + # group services by root, eg "sv1.web" and "sv1.resque" are in the + # same sub array + previous_service_root = "" + Whoops::EventGroup.services.to_a.sort.each { |service| + service_root = (/(.*?)\./ =~ service && $~[1]) || service + if service_root == previous_service_root + @filter_field_allowed_values["service"].last << service + else + @filter_field_allowed_values["service"] << ["#{service_root}.*", service] + previous_service_root = service_root + end + } - @filter_options + @filter_field_allowed_values["environment"] << Whoops::EventGroup.all.distinct("environment") + @filter_field_allowed_values["event_type"] << Whoops::EventGroup.all.distinct("event_type") + @filter_field_allowed_values end - def filter_checked?(field_name, option) - filtered_field = session[:event_group_filter].send(field_name) - filtered_field && filtered_field.include?(option) + def allowed_value_checked?(field_name, allowed_value, filter) + filtered_field = filter.send(field_name) + (allowed_value == "all" && filtered_field_allows_all?(filtered_field)) || + filtered_field.try(:include?, allowed_value) + end + + def filtered_field_allows_all?(filtered_field) + filtered_field.blank? end end