Permalink
Browse files

finished jQuery substitutions; correct RSS feed

  • Loading branch information...
1 parent ab5fc6d commit df7226f1674533e728417cbe162848ceb01f7312 @cwise cwise committed Feb 23, 2011
@@ -12,7 +12,6 @@ def index
query
end
-
def query
exceptions = LoggedException.sorted
unless params[:id].blank?
@@ -28,16 +27,25 @@ def query
exceptions = exceptions.by_exception_class(params[:exception_names_filter])
end
unless params[:controller_actions_filter].blank?
- c_a_params = params[:controller_actions_filter].split('/').collect(&:downcase)
- exceptions = exceptions.by_controller(c_a_params.first)
- exceptions = exceptions.by_action(c_a_params.last)
+ c_a_params = params[:controller_actions_filter].split('/')
+ controller_filter = c_a_params.first.underscore
+ action_filter = c_a_params.last.downcase
+ exceptions = exceptions.by_controller(controller_filter)
+ exceptions = exceptions.by_action(action_filter)
end
@exceptions = exceptions.paginate(:per_page => 30, :page => params[:page])
respond_to do |format|
format.html { redirect_to :action => 'index' unless action_name == 'index' }
format.js
- format.xml
+ end
+ end
+
+ def feed
+ @exceptions = LoggedException.all
+
+ respond_to do |format|
+ format.rss { render :layout => false }
end
end
@@ -57,7 +65,7 @@ def destroy
def destroy_all
LoggedException.delete_all(:id => params[:ids]) unless params[:ids].blank?
- query
+ query
end
private
@@ -4,9 +4,11 @@
<title><%= content_for?(:title) ? yield(:title) : "Exception Logger" %></title>
<meta charset="UTF-8" />
<%= javascript_include_tag 'https://ajax.googleapis.com/ajax/libs/jquery/1.4.3/jquery.min.js' %>
- <%= javascript_include_tag 'exception_logger.jquery.js' %>
+ <%= javascript_include_tag 'exception_logger.js' %>
<%= stylesheet_link_tag 'exception_logger' %>
<%= csrf_meta_tag %>
+
+ <%= auto_discovery_link_tag(:rss, {:action => "feed"}, {:title => "RSS Feed"}) %>
</head>
<body>
<div id="container">
@@ -22,7 +22,7 @@
<span class="message"><%= h exception.message %></span>
</td>
<td class="time"><%= pretty_exception_date(exception) %></td>
- <td><%= link_to 'Delete', { :action => 'destroy', :id => exception },:method => :delete, :class => "util delete_link" %></td>
+ <td><%= link_to 'Delete', { :action => 'destroy', :id => exception }, :method => :delete, :class => "util delete_link" %></td>
</tr>
<% end %>
</tbody>
@@ -1,8 +1,3 @@
-<%
- feed_params = [:id, :query, :date_ranges_filter, :exception_names_filter, :controller_actions_filter].inject({:format => 'rss'}) do |p, key|
- params[key].blank? ? p : p.update(key => params[key])
- end
-%>
<ul id="feed" class="filters">
- <li><%= link_to "RSS Feed", feed_params %></li>
+ <li><%= link_to "RSS Feed", feed_logged_exceptions_url(:format => :rss) %></li>
</ul>
@@ -0,0 +1,2 @@
+$('#exceptions').html('<%= escape_javascript render :partial => "exceptions" %>');
+$('#showpage').hide();
@@ -1,2 +0,0 @@
-page[:exceptions].replace :partial => "exceptions"
-page[:showpage].hide
@@ -2,7 +2,7 @@ xml.instruct! :xml, :version=>"1.0", :encoding=>"UTF-8"
xml.rss "version" => "2.0" do
xml.channel do
- xml.title "Recent Exceptions#{%( (filtered)) if filtered?} | #{LoggedExceptionsController.application_name}"
+ xml.title "#{LoggedExceptionsController.application_name}"
xml.link url_for(:only_path => false, :skip_relative_url_root => false)
xml.language "en-us"
xml.ttl "60"
@@ -7,21 +7,21 @@
<h4><%=t(".exception")%></h4>
<ul id="exception_names" class="filters">
<% @exception_names.each do |name| %>
- <li><%= link_to name, {:action => 'index', :exception_names_filter => "#{name}"}, :onclick => "ExceptionLogger.setFilter('exception_names','#{escape_javascript name}'); return false;" %></li>
+ <li><%= link_to name, {:action => 'query', :exception_names_filter => "#{name}"}, :class => 'filter_link' %></li>
<% end %>
</ul>
<h4><%=t(".controller_action")%></h4>
<ul id="controller_actions" class="filters">
<% @controller_actions.each do |action| %>
- <li><%= link_to action, {:action => 'index', :controller_actions_filter => "#{action}"}, :onclick => "ExceptionLogger.setFilter('controller_actions','#{escape_javascript action}'); return false;" %></li>
+ <li><%= link_to action, {:action => 'query', :controller_actions_filter => "#{action}"}, :class => 'filter_link' %></li>
<% end %>
</ul>
<h4><%=t(".dates")%></h4>
<ul id="date_ranges" class="filters">
- <li><%= link_to t(".today"), {:action => 'index', :data_ranges_filter => "1"}, :onclick => "ExceptionLogger.setFilter('date_ranges', 1); return false;", :title => "1" %></li>
- <li><%= link_to t(".last_few_days"), {:action => 'index', :data_ranges_filter => "3"}, :onclick => "ExceptionLogger.setFilter('date_ranges', 3); return false;", :title => "3" %></li>
- <li><%= link_to t(".last_7_days"), {:action => 'index', :data_ranges_filter => "7"}, :onclick => "ExceptionLogger.setFilter('date_ranges', 7); return false;", :title => "7" %></li>
- <li><%= link_to t(".last_30_days"), {:action => 'index', :data_ranges_filter => "30"}, :onclick => "ExceptionLogger.setFilter('date_ranges', 30); return false;", :title => "30" %></li>
+ <li><%= link_to t(".today"), {:action => 'query', :date_ranges_filter => "1"}, :title => "1", :class => 'filter_link' %></li>
+ <li><%= link_to t(".last_few_days"), {:action => 'query', :date_ranges_filter => "3"}, :title => "3", :class => 'filter_link' %></li>
+ <li><%= link_to t(".last_7_days"), {:action => 'query', :date_ranges_filter => "7"}, :title => "7", :class => 'filter_link' %></li>
+ <li><%= link_to t(".last_30_days"), {:action => 'query', :date_ranges_filter => "30"}, :title => "30", :class => 'filter_link' %></li>
</ul>
<div id="search">
<%= form_tag "logged_exceptions/query",:remote => true, :id => 'query-form' %>
@@ -0,0 +1,2 @@
+$('#exceptions').html('<%= escape_javascript render :partial => "exceptions" %>');
+$('#showpage').hide();
@@ -1,3 +0,0 @@
-page[:exceptions].replace :partial => "exceptions"
-page[:showpage].hide
-page[:feed].replace :partial => 'feed'
View
@@ -5,7 +5,7 @@
collection do
post :query
post :destroy_all
+ get :feed
end
end
-
end
@@ -1,31 +0,0 @@
-$(function () {
- $('.show_link').live('click', function(event) {
- $.get($(this).attr("href"));
- return false;
- });
-
- $('.close_link').live('click', function(event) {
- $("#showpage").hide();
- return false;
- });
-
- $('.delete_link').live('click', function(event) {
- $.ajax({
- url: $(this).attr("href"),
- type: 'DELETE'
- });
- return false;
- });
-
- $('.delete_visible_link').live('click', function(event) {
-// $('tr.exception').each(function(tr) { $(tr).attr("id").replace(/^\w+_/, ''); });
- var ids="ids=8,2, 10, 30, 31, 29, 28"
- $.ajax({
- url: $(this).attr("href"),
- type: 'POST',
- data: ids
- });
- return false;
- });
-});
-
@@ -1,81 +1,42 @@
-ExceptionLogger = {
- filters: ['exception_names', 'controller_actions', 'date_ranges'],
- setPage: function(num) {
- $('page').value = num;
- //$('query-form').onsubmit();
- new Ajax.Request('/logged_exceptions/query', {asynchronous:true, evalScripts:true, parameters:Form.serialize('query-form')});
- return false;
- },
-
- setFilter: function(context, name) {
- var filterName = context + '_filter'
- $(filterName).value = ($F(filterName) == name) ? '' : name;
- this.deselect(context, filterName);
- $('page').value = '1';
- //$('query-form').onsubmit();
- new Ajax.Request('/logged_exceptions/query', {asynchronous:true, evalScripts:true, parameters:Form.serialize('query-form')});
- return false;
- },
-
- deselect: function(context, filterName) {
- $$('#' + context + ' a').each(function(a) {
- var value = $(filterName) ? $F(filterName) : null;
- a.className = (value && (a.getAttribute('title') == value || a.innerHTML == value)) ? 'selected' : '';
- });
- },
-
- deleteAllRequest: function() {
- new Ajax.Request('/logged_exceptions/destroy_all', {asynchronous:true, evalScripts:true, parameters:ExceptionLogger.deleteAll()});
- return false;
- },
-
- deleteAll: function() {
- return Form.serialize('query-form') + '&' + $$('tr.exception').collect(function(tr) { return tr.getAttribute('id').gsub(/^\w+_/, ''); }).toQueryString('ids');
- },
-
- // If the user visits /logged_exceptions#e123, show exception with id 123
- showFromHash: function() {
- if (m = location.hash.match(/^#e(\d+)$/))
- new Ajax.Request('/logged_exceptions/show/'+m[1], {asynchronous:true, evalScripts:true});
- },
-
- unsetHash: function() {
- location.hash = '#'; // if set to '', page reloads
- },
-
- hideDetails: function() {
- $('showpage').hide();
- this.unsetHash();
- }
-
-}
-
-Event.observe(window, 'load', function() {
- ExceptionLogger.filters.each(function(context) {
- $(context + '_filter').value = '';
- });
-
- Event.observe(document, 'keypress', function(event) {
- if (event.keyCode == Event.KEY_ESC)
- ExceptionLogger.hideDetails();
- });
-
- ExceptionLogger.showFromHash();
+$(function () {
+ $('.show_link').live('click', function(event) {
+ $.get($(this).attr("href"));
+ return false;
+ });
+
+ $('.close_link').live('click', function(event) {
+ $("#showpage").hide();
+ return false;
+ });
+
+ $('.delete_link').live('click', function(event) {
+ $.ajax({
+ url: $(this).attr("href"),
+ type: 'DELETE'
+ });
+ return false;
+ });
+
+ $('.delete_visible_link').live('click', function(event) {
+ var arr=$('tr.exception').map(function() { var id = $(this).attr("id"); return parseInt(id.replace(/^\w+_/, '')); }).get();
+ $.ajax({
+ url: $(this).attr("href"),
+ type: 'POST',
+ data: $.param({ids: arr}),
+ dataType: 'script'
+ });
+ return false;
+ });
+
+ $('.filter_link').live('click', function(event) {
+ $('.filter_link').removeClass('selected');
+ $(this).addClass('selected');
+ $.ajax({
+ url: $(this).attr("href"),
+ type: 'POST',
+ dataType: 'script'
+ });
+ return false;
+ });
});
-Object.extend(Array.prototype, {
- toQueryString: function(name) {
- return this.collect(function(item) { return name + "[]=" + encodeURIComponent(item); }).join('&');
- }
-});
-
-Ajax.Responders.register({
- onCreate: function() {
- ExceptionLogger.unsetHash();
- if($('activity') && Ajax.activeRequestCount > 0) $('activity').visualEffect('appear', {duration:0.25});
- },
-
- onComplete: function() {
- if($('activity') && Ajax.activeRequestCount == 0) $('activity').visualEffect('fade', {duration:0.25});
- }
-});

0 comments on commit df7226f

Please sign in to comment.