Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

streamlining page footers for less queries per page load

git-svn-id: http://eldorado.googlecode.com/svn/trunk@518 9c008b19-a030-0410-9975-d76d301b4276
  • Loading branch information...
commit fe0912b6b1c5fbf5ef8171bf63aec2ac23b86a6b 1 parent d961ce0
trevorturk authored
Showing with 105 additions and 94 deletions.
  1. +11 −15 app/controllers/application.rb
  2. +2 −0  app/controllers/forums_controller.rb
  3. +4 −4 app/controllers/themes_controller.rb
  4. +1 −0  app/controllers/users_controller.rb
  5. +4 −7 app/helpers/application_helper.rb
  6. +1 −1  app/models/avatar.rb
  7. +1 −1  app/models/ban.rb
  8. +1 −1  app/models/category.rb
  9. +1 −1  app/models/event.rb
  10. +1 −1  app/models/forum.rb
  11. +1 −1  app/models/header.rb
  12. +1 −1  app/models/post.rb
  13. +1 −1  app/models/rank.rb
  14. +3 −3 app/models/{option.rb → setting.rb}
  15. +1 −1  app/models/subscription.rb
  16. +1 −1  app/models/theme.rb
  17. +1 −1  app/models/topic.rb
  18. +1 −1  app/models/upload.rb
  19. +1 −1  app/models/user.rb
  20. +13 −0 app/views/forums/index.rhtml
  21. +6 −6 app/views/layouts/application.rhtml
  22. +0 −6 app/views/shared/nav2.rhtml
  23. +1 −2  app/views/shared/stats.rhtml
  24. +9 −0 db/migrate/064_change_options_to_settings.rb
  25. +10 −10 db/schema.rb
  26. +1 −1  lib/tasks/import.rake
  27. +1 −1  test/fixtures/avatars.yml
  28. +1 −1  test/fixtures/bans.yml
  29. +1 −1  test/fixtures/categories.yml
  30. +1 −1  test/fixtures/events.yml
  31. +1 −1  test/fixtures/forums.yml
  32. +1 −1  test/fixtures/headers.yml
  33. +1 −1  test/fixtures/posts.yml
  34. +1 −1  test/fixtures/ranks.yml
  35. +2 −2 test/fixtures/{options.yml → settings.yml}
  36. +1 −1  test/fixtures/subscriptions.yml
  37. +1 −1  test/fixtures/themes.yml
  38. +1 −1  test/fixtures/topics.yml
  39. +1 −1  test/fixtures/uploads.yml
  40. +1 −1  test/fixtures/users.yml
  41. +1 −1  test/unit/avatar_test.rb
  42. +1 −1  test/unit/ban_test.rb
  43. +1 −1  test/unit/category_test.rb
  44. +1 −1  test/unit/event_test.rb
  45. +1 −1  test/unit/forum_test.rb
  46. +1 −1  test/unit/header_test.rb
  47. +3 −3 test/unit/{option_test.rb → setting_test.rb}
  48. +1 −1  test/unit/subscription_test.rb
  49. +1 −1  test/unit/theme_test.rb
  50. +1 −1  test/unit/upload_test.rb
26 app/controllers/application.rb
View
@@ -1,7 +1,7 @@
class ApplicationController < ActionController::Base
around_filter :set_timezone
- before_filter :auth_token_login, :check_bans, :update_online_at, :get_options, :get_stats, :get_reminders
+ before_filter :auth_token_login, :check_bans, :update_online_at, :get_settings, :get_reminders
helper_method :current_user, :logged_in?, :is_online?, :admin?, :can_edit?, :require_login, :require_admin, :redirect_home
rescue_from ActiveRecord::RecordNotFound, :with => :record_not_found
@@ -55,24 +55,20 @@ def get_reminders
@reminders = Event.find(:all, :order => 'date asc', :conditions => ["reminder = ?", true])
@reminders = [] unless logged_in?
end
-
- def get_stats
- @newest_user = User.find(:first, :order => "created_at desc")
- @user_count = User.count
- @posts_count = Forum.sum('posts_count')
- end
-
+
def record_not_found
flash[:notice] = "Sorry, the page you requested was not found."
redirect_to root_path
end
- def get_options
- @options = Option.find(:first)
- if @options.blank? # set default options
- return if (Category.count != 0) || (Forum.count != 0) || (Option.count != 0) || (Post.count != 0) || (Topic.count != 0) || (User.count != 0)
- @option = Option.new(:title => 'El Dorado.org', :tagline => 'All an elaborate, unapproachable, unprofitable, retributive joke', :announcement => '', :footer => '<p style="text-align:right;margin:0;">Powered by El Dorado | <a href="http://almosteffortless.com">&aelig;</a></p>')
- @option.save!
+ def get_settings
+ @users_count = User.count
+ @newest_user = User.find(:first, :order => "created_at desc")
+ @settings = Setting.find(:first)
+ if @settings.blank? # set default settings
+ return if (Category.count != 0) || (Forum.count != 0) || (Setting.count != 0) || (Post.count != 0) || (Topic.count != 0) || (User.count != 0)
+ @setting = Setting.new(:title => 'El Dorado.org', :tagline => 'All an elaborate, unapproachable, unprofitable, retributive joke', :announcement => '', :footer => '<p style="text-align:right;margin:0;">Powered by El Dorado | <a href="http://almosteffortless.com">&aelig;</a></p>')
+ @setting.save!
@category = Category.new(:name => 'Test Category')
@category.save!
@forum = @category.forums.build(:name => 'Test Forum', :description => "This is just a test forum")
@@ -87,7 +83,7 @@ def get_options
@post.topic_id = 1
@post.save!
flash[:notice] = "Setup complete. You can now log in as 'Administrator' with the password '#{pass}'"
- @options = Option.find(:first)
+ @settings = Setting.find(:first)
@category = nil; @forum = nil; @user = nil; @topic = nil; @post = nil # reset for page_title
end
end
2  app/controllers/forums_controller.rb
View
@@ -5,6 +5,8 @@ class ForumsController < ApplicationController
def index
@categories = Category.find(:all, :include => [:forums], :order => 'categories.position, forums.position')
+ @posts_count = Forum.sum('posts_count')
+ @topics_count = Forum.sum('topics_count')
end
def show
8 app/controllers/themes_controller.rb
View
@@ -5,7 +5,7 @@ class ThemesController < ApplicationController
def index
@themes = Theme.paginate(:page => params[:page], :per_page => Topic::PER_PAGE)
- @current_theme = Theme.find(@options.theme_id) unless @options.theme_id.nil?
+ @current_theme = Theme.find(@settings.theme_id) unless @settings.theme_id.nil?
end
def new
@@ -23,19 +23,19 @@ def create
def destroy
@theme = Theme.find(params[:id])
redirect_to themes_path and return false unless can_edit?(@theme)
- @options.update_attributes(:theme_id => nil) if @options.theme_id == @theme.id
+ @settings.update_attributes(:theme_id => nil) if @settings.theme_id == @theme.id
@theme.destroy
redirect_to themes_path
end
def select
@theme = Theme.find(params[:id])
- @options.update_attributes(:theme_id => @theme.id)
+ @settings.update_attributes(:theme_id => @theme.id)
redirect_to themes_path
end
def deselect
- @options.update_attributes(:theme_id => nil)
+ @settings.update_attributes(:theme_id => nil)
redirect_to themes_path
end
1  app/controllers/users_controller.rb
View
@@ -4,6 +4,7 @@ class UsersController < ApplicationController
def index
@users = User.paginate(:page => params[:page], :order => 'profile_updated_at desc')
+
end
def show
11 app/helpers/application_helper.rb
View
@@ -18,16 +18,13 @@ def random_header_css
end
def theme_css
- if @options.theme_id.nil?
- return '<style type="text/css">@import "/stylesheets/application.css";</style>'
- else
- @theme = Theme.find(@options.theme_id)
- return '<style type="text/css">@import "' + @theme.public_filename + '";</style>'
- end
+ return '<style type="text/css">@import "/stylesheets/application.css";</style>' if @settings.theme_id.blank?
+ @theme = Theme.find(@settings.theme_id)
+ return '<style type="text/css">@import "' + @theme.public_filename + '";</style>'
end
def page_title
- page_title = h(@options.title)
+ page_title = h(@settings.title)
page_title << ': ' + @category.to_s unless @category.nil? or @category.name.nil?
page_title << ': ' + @event.to_s unless @event.nil? or @event.title.nil?
page_title << ': ' + @forum.to_s unless @forum.nil? or @forum.name.nil?
2  app/models/avatar.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: avatars
#
2  app/models/ban.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: bans
#
2  app/models/category.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: categories
#
2  app/models/event.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: events
#
2  app/models/forum.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: forums
#
2  app/models/header.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: headers
#
2  app/models/post.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: posts
#
2  app/models/rank.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: ranks
#
6 app/models/option.rb → app/models/setting.rb
View
@@ -1,7 +1,7 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
-# Table name: options
+# Table name: settings
#
# id :integer(11) not null, primary key
# title :string(255)
@@ -12,7 +12,7 @@
# favicon :string(255)
#
-class Option < ActiveRecord::Base
+class Setting < ActiveRecord::Base
def to_s
title.to_s
2  app/models/subscription.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: subscriptions
#
2  app/models/theme.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: themes
#
2  app/models/topic.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: topics
#
2  app/models/upload.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: uploads
#
2  app/models/user.rb
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: users
#
13 app/views/forums/index.rhtml
View
@@ -2,6 +2,19 @@
<%= render 'topics/new' %>
</div>
+<div class="info-left">
+ <span class="title">Forum</span>
+ <span class="detail">&nbsp;|&nbsp;
+ <%= pluralize(number_with_delimiter(@posts_count) || 0, 'Post') %> in
+ <%= pluralize(number_with_delimiter(@topics_count) || 0, 'Topic') %>
+ </span>
+</div>
+<div class="info-right">
+ <span class="title">&nbsp;</span>
+ <span class="detail"><%= link_to('View All Topics &raquo;', topics_path) %></span>
+</div>
+<div style="clear:both;"> </div>
+
<% for category in @categories %>
<table cellspacing="0" class="forums-index">
<thead>
12 app/views/layouts/application.rhtml
View
@@ -10,8 +10,8 @@
<title><%= page_title %></title>
<!-- Powered by El Dorado (http://almosteffortless.com) -->
- <% unless @options.favicon.blank? %>
- <link rel="shortcut icon" href="<%= @options.favicon %>" />
+ <% unless @settings.favicon.blank? %>
+ <link rel="shortcut icon" href="<%= @settings.favicon %>" />
<% end %>
<%= random_header_css %>
@@ -31,8 +31,8 @@
<% end %>
<div class="header">
- <h1><%= link_to h(@options.title), root_path %></h1>
- <div class="tagline"><%=h @options.tagline %></div>
+ <h1><%= link_to h(@settings.title), root_path %></h1>
+ <div class="tagline"><%=h @settings.tagline %></div>
</div>
<%= render 'shared/tabs' %>
@@ -46,7 +46,7 @@
<%= content_tag 'div', h(flash[:notice]), :id => 'notice' if flash[:notice] %>
<%= content_tag 'div', h(flash[:error]), :id => 'error' if flash[:error] %>
- <div class="announcement"><%= @options.announcement %></div>
+ <div class="announcement"><%= @settings.announcement %></div>
<%= yield %>
@@ -55,7 +55,7 @@
</div>
- <div class="footer"><%= @options.footer %></div>
+ <div class="footer"><%= @settings.footer %></div>
</div>
6 app/views/shared/nav2.rhtml
View
@@ -53,12 +53,6 @@
</div>
<% end %>
-<% if current_controller == 'forums' and current_action == 'index' %>
- <div class="info-right" style="margin-top:5px;">
- <%= link_to('View All Topics &raquo;', topics_path) %>
- </div>
-<% end %>
-
<% if current_controller == 'forums' and current_action == 'show' %>
<div class="info-left">
<%= link_to 'Home', root_path %> &raquo;
3  app/views/shared/stats.rhtml
View
@@ -6,8 +6,7 @@
<% end %>
</p>
<p class="nav-right">
- <%= pluralize(number_with_delimiter(@posts_count) || 0, 'Post') %> by
- <%= pluralize(number_with_delimiter(@user_count), 'User') %> |
+ <%= pluralize(number_with_delimiter(@users_count), 'User') %> |
Newest User: <%= link_to h(@newest_user.login), @newest_user %>
</p>
</div>
9 db/migrate/064_change_options_to_settings.rb
View
@@ -0,0 +1,9 @@
+class ChangeOptionsToSettings < ActiveRecord::Migration
+ def self.up
+ rename_table :options, :settings
+ end
+
+ def self.down
+ rename_table :settings, :options
+ end
+end
20 db/schema.rb
View
@@ -2,7 +2,7 @@
# migrations feature of ActiveRecord to incrementally modify your database, and
# then regenerate this schema definition.
-ActiveRecord::Schema.define(:version => 63) do
+ActiveRecord::Schema.define(:version => 64) do
create_table "avatars", :force => true do |t|
t.integer "parent_id"
@@ -82,15 +82,6 @@
t.datetime "created_at"
end
- create_table "options", :force => true do |t|
- t.string "title"
- t.string "tagline"
- t.text "announcement"
- t.text "footer"
- t.integer "theme_id"
- t.string "favicon"
- end
-
create_table "posts", :force => true do |t|
t.integer "user_id"
t.integer "topic_id"
@@ -117,6 +108,15 @@
add_index "sessions", ["session_id"], :name => "index_sessions_on_session_id"
add_index "sessions", ["updated_at"], :name => "index_sessions_on_updated_at"
+ create_table "settings", :force => true do |t|
+ t.string "title"
+ t.string "tagline"
+ t.text "announcement"
+ t.text "footer"
+ t.integer "theme_id"
+ t.string "favicon"
+ end
+
create_table "subscriptions", :force => true do |t|
t.integer "user_id"
t.integer "topic_id"
2  lib/tasks/import.rake
View
@@ -38,7 +38,7 @@ namespace :import do
ActiveRecord::Base.establish_connection(eldorado['import'])
@items = ActiveRecord::Base.connection.execute("SELECT conf_name, conf_value FROM #{prefix}config LIMIT 4")
ActiveRecord::Base.establish_connection(eldorado[RAILS_ENV])
- @item = Option.new
+ @item = Setting.new
@index = 0
for i in @items
@index += 1
2  test/fixtures/avatars.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: avatars
#
2  test/fixtures/bans.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: bans
#
2  test/fixtures/categories.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: categories
#
2  test/fixtures/events.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: events
#
2  test/fixtures/forums.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: forums
#
2  test/fixtures/headers.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: headers
#
2  test/fixtures/posts.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: posts
#
2  test/fixtures/ranks.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: ranks
#
4 test/fixtures/options.yml → test/fixtures/settings.yml
View
@@ -1,7 +1,7 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
-# Table name: options
+# Table name: settings
#
# id :integer(11) not null, primary key
# title :string(255)
2  test/fixtures/subscriptions.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: subscriptions
#
2  test/fixtures/themes.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: themes
#
2  test/fixtures/topics.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: topics
#
2  test/fixtures/uploads.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: uploads
#
2  test/fixtures/users.yml
View
@@ -1,5 +1,5 @@
# == Schema Information
-# Schema version: 63
+# Schema version: 64
#
# Table name: users
#
2  test/unit/avatar_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class AvatarTest < Test::Unit::TestCase
- fixtures :avatars
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/ban_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class BanTest < Test::Unit::TestCase
- fixtures :bans
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/category_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class CategoryTest < Test::Unit::TestCase
- fixtures :categories
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/event_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class EventTest < Test::Unit::TestCase
- fixtures :events
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/forum_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class ForumTest < Test::Unit::TestCase
- fixtures :forums
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/header_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class HeaderTest < Test::Unit::TestCase
- fixtures :headers
+ fixtures :all
# Replace this with your real tests.
def test_truth
6 test/unit/option_test.rb → test/unit/setting_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
-class OptionTest < Test::Unit::TestCase
- fixtures :options
+class SettingTest < Test::Unit::TestCase
+ fixtures :all
# Replace this with your real tests.
def test_truth
@@ -9,7 +9,7 @@ def test_truth
end
def test_to_s
- o = Option.find(1)
+ o = Setting.find(1)
assert_equal o.to_s, 'El Dorado.org'
end
2  test/unit/subscription_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class SubscriptionTest < Test::Unit::TestCase
- fixtures :subscriptions
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/theme_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class ThemeTest < Test::Unit::TestCase
- fixtures :themes
+ fixtures :all
# Replace this with your real tests.
def test_truth
2  test/unit/upload_test.rb
View
@@ -1,7 +1,7 @@
require File.dirname(__FILE__) + '/../test_helper'
class UploadTest < Test::Unit::TestCase
- fixtures :uploads
+ fixtures :all
# Replace this with your real tests.
def test_truth
Please sign in to comment.
Something went wrong with that request. Please try again.