Skip to content
This repository has been archived by the owner on Jan 8, 2019. It is now read-only.

Commit

Permalink
- refactored the menu generation and paging code
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisoelkers committed Dec 19, 2010
1 parent d65f077 commit 853253a
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
26 changes: 19 additions & 7 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
module ApplicationHelper
def menu_item where
if where[:controller] == root_path
destination = root_path
else
destination = (root_path = "/" ? where[:controller] : root_path + "/" + where[:controller])
def menu_item title, where
li_class = ""
link = link_to_unless_current(title, where) do
li_class = " class=\"topmenu-active\""
title
end

"<li class=\"#{"topmenu-active" if is_current_menu_item?(where[:controller])}\">#{link_to(where[:title], destination)}</li>"
"<li#{li_class}>#{link}</li>"
#"<li class=\"#{"topmenu-active" if is_current_menu_item?(where[:controller])}\">#{link_to(where[:title], destination)}</li>"
end

def tab_link tab
Expand Down Expand Up @@ -141,4 +141,16 @@ def is_current_menu_item? item
def is_current_tab? tab
true if params[:action] == tab.downcase
end

def current_page
params[:page].blank? ? 1 : params[:page].to_i
end

def next_page
current_page + 1
end

def previous_page
current_page <= 2 ? 1 : current_page - 1
end
end
12 changes: 6 additions & 6 deletions app/views/layouts/application.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@
</div>
<%= link_to image_tag("graylog.png", :id => "toplogo"), (permitted_to?(:index, :messages) ? messages_path : streams_path)%>
<ul id="topmenu">
<% permitted_to? :index, :messages do %><%=raw menu_item({ :title => "Messages", :controller => "messages" }) %><% end %>
<% permitted_to? :index, :streams do %><%=raw menu_item({ :title => "Streams", :controller => "streams" }) %><% end %>
<% permitted_to? :index, :hosts do %><%=raw menu_item({ :title => "Hosts", :controller => "hosts" }) %><% end %>
<% permitted_to? :index, :blacklists do %><%=raw menu_item({ :title => "Blacklists", :controller => "blacklists" }) %><% end %>
<% permitted_to? :index, :settings do %><%=raw menu_item({ :title => "Settings", :controller => "settings" }) %><% end %>
<% permitted_to? :index, :users do %><%=raw menu_item({ :title => "Users", :controller => "users" }) %><% end %>
<% permitted_to? :index, :messages do %><%=raw menu_item("Messages", messages_path) %><% end %>
<% permitted_to? :index, :streams do %><%=raw menu_item("Streams", streams_path) %><% end %>
<% permitted_to? :index, :hosts do %><%=raw menu_item("Hosts", hosts_path) %><% end %>
<% permitted_to? :index, :blacklists do %><%=raw menu_item("Blacklists", {:controller => :blacklists}) %><% end %>
<% permitted_to? :index, :settings do %><%=raw menu_item("Settings", {:controller => :settings}) %><% end %>
<% permitted_to? :index, :users do %><%=raw menu_item("Users", {:controller => :users}) %><% end %>
</ul>

<% message_count_interval = Setting.get_message_count_interval(current_user) %>
Expand Down
10 changes: 2 additions & 8 deletions app/views/messages/_table.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -33,20 +33,14 @@
</tbody>
</table>

<%
params[:page].blank? ? current_page = 1 : current_page = params[:page].to_i;
next_page = current_page+1;
current_page <= 1 ? previous_page = 1 : previous_page = current_page-1;
%>
<% unless defined? @inline_version %>
<div id="messages-bottom">
<% unless current_page <= 1 %>
<a href="<%=h build_controller_action_uri 'page' %><%= previous_page %>" class="previous-page">previous page</a>
<%= link_to "previous page", {:page => previous_page}, {:class => "previous-page"} %>
<% end %>
<% if total_messages > (Message::LIMIT*current_page) %>
<a href="<%=h build_controller_action_uri 'page' %><%= next_page %>" class="next-page">next page</a>
<%= link_to "next page", {:page => next_page}, {:class => "next-page"} %>
<% end %>
</div>

Expand Down
2 changes: 1 addition & 1 deletion app/views/streams/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@
</div>

<a href="#" id="streams-show-statistics">&raquo; Show statistics</a>

<%= link_to raw("&raquo; back"), :back %>
<div id="blocks-statistics" style="display: none;">
<div class="loading"></div>
</div>
Expand Down

0 comments on commit 853253a

Please sign in to comment.