Skip to content

Commit e359f94

Browse files
committed
Added the ability to edit configuration options. More are coming later.
Added contributors to the readme file.
1 parent c7b7024 commit e359f94

18 files changed

+405
-278
lines changed

README.markdown

+5-1
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,8 @@ Also you should set `STANDALONE = false` inside _config/environment.rb_.
118118

119119
If you wish to use a different authentication system other than Restful Authentication then remove the user model (*app/models/user.rb*) and replace it with your own whilst not forgetting to `include Rboard::UserExtension`, the AuthenticatedSystem module (*lib/authenticated_system.rb*) and the AuthenticatedTestHelper module (*lib/authenticated_test_helper.rb*)
120120

121-
121+
## Contributors
122+
123+
Thomas Sinclair
124+
Bodaniel Jeanes
125+
Tore Darell

TODO.html

+280-269
Large diffs are not rendered by default.

TODO.rtf

+6-4
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf430
1+
{\rtf1\ansi\ansicpg1252\cocoartf949\cocoasubrtf460
22
{\fonttbl\f0\fnil\fcharset0 LucidaGrande;}
33
{\colortbl;\red255\green255\blue255;\red255\green3\blue0;\red255\green0\blue0;}
44
\margl1440\margr1440\margb1800\margt1800\vieww10500\viewh9600\viewkind0
@@ -177,9 +177,11 @@ Visual representation of unread topics (including previously read topics with ne
177177
\uc0\u9702 Show all new(/newly replied to) posts and mark all forums read links\
178178
\pard\tx220\tx720\pardeftab720\li720\fi-720\sl380\ql\qnatural\pardirnatural
179179
\cf0 \expnd0\expndtw0\kerning0
180-
\'95 Ability to mark forums as active (shown/hidden)\
181-
\'95 Ability to mark forums as open (allows new posts)\
182-
\'95 Customise how many sub forums are shown on the index page\
180+
\'95 Ability to mark forums as active (shown/hidden) (mark[oz])\
181+
\'95 Ability to mark forums as open (allows new posts) (mark[oz])\
182+
\'95 \cf2 \expnd0\expndtw0\kerning0
183+
Customise how many sub forums are shown on the index page (mark[oz])\cf0 \expnd0\expndtw0\kerning0
184+
\
183185
\pard\tx560\tx1120\tx1680\tx2240\tx2800\tx3360\tx3920\tx4480\tx5040\tx5600\tx6160\tx6720\pardeftab720\sl380\sa220\ql\qnatural\pardirnatural
184186

185187
\b \cf0 \expnd0\expndtw0\kerning0

app/controllers/admin/application_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def can_not_manage
2424
end
2525

2626
def find_sections
27-
@sections = ["categories", "forums", "users", "groups", "ranks", "themes"].select do |name|
27+
@sections = ["categories", "forums", "users", "groups", "ranks", "themes", "configurations"].select do |name|
2828
current_user.can?("manage_#{name}")
2929
end
3030
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
class Admin::ConfigurationsController < Admin::ApplicationController
2+
before_filter :find_configuration, :only => [:edit, :update]
3+
4+
def index
5+
@configurations = Configuration.all
6+
end
7+
8+
9+
def update_all
10+
configurations = Configuration.find_all_by_key(params[:configurations].keys)
11+
12+
configurations.each do |configuration|
13+
configuration.update_attributes(params[:configurations][configuration.id])
14+
end
15+
flash[:notice] = t(:configuration_settings_updated)
16+
redirect_to admin_configurations_path
17+
end
18+
19+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
module Admin::ConfigurationsHelper
2+
end

app/models/configuration.rb

+10
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
class Configuration < ActiveRecord::Base
2+
default_scope :order => :title
3+
4+
def self.[](key)
5+
Configuration.find_by_key!(key).value
6+
rescue ActiveRecord::RecordNotFound
7+
raise NotFound, t(:Configuration_not_found, :key => key)
8+
end
9+
10+
11+
class NotFound < Exception; end
212
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<%= link_to t(:Administration_Section), admin_root_path %> -> <%= t(:Configuration_Settings) %>
2+
<h2><%= t(:Configuration_Settings) %></h2>
3+
<%= link_to t(:New, :thing => "Group"), new_admin_group_path %>
4+
<% form_for :configurations, :url => update_all_admin_configurations_path, :html => { :method => :put } do %>
5+
<table cellspacing='0' cellpadding='2' class='list-table' width='100%' rules='groups'>
6+
<thead>
7+
<tr>
8+
<td>Title</td>
9+
<td>Value</td>
10+
<td>Submit</td>
11+
</tr>
12+
</thead>
13+
<tbody>
14+
<% for configuration in @configurations %>
15+
<tr>
16+
<td class='lalign'><strong><%= configuration.title %></strong><br>
17+
<%= configuration.description %>
18+
</td>
19+
<% fields_for "configurations[]", configuration do |c| %>
20+
<td>
21+
<%= c.text_field :value %>
22+
</td>
23+
<% end %>
24+
<td><%= submit_tag "Update" %></td>
25+
</tr>
26+
<% end %>
27+
</tbody>
28+
</table>
29+
<% end %>

app/views/forums/_forum.html.erb

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<h1><%= link_to(h(forum.title), forum_path(forum)) %></h1>
44
<%= h(forum.description) %>
55
<% if !forum.children.empty? %>
6-
<br /><%= t(:Subforums) %>: <% forum.children.each do |forum| %> <%= link_to(h(forum.title), forum_path(forum)) %> <% end %>
6+
<br /><%= t(:Subforums) %>: <% forum.children(Configuration['subforums_display'].to_i).each do |forum| %> <%= link_to(h(forum.title), forum_path(forum)) %> <% end %>
77
<% end %>
88
</td>
99
<td align='center'><%= forum.topics.size %></td>

config/locales/en.rb

+5
Original file line numberDiff line numberDiff line change
@@ -181,6 +181,9 @@
181181
:category_permission_denied => "You are not allowed to access that category",
182182
:Category_specific_permissions => "Category-specific permissions",
183183
:Child_of => "Child of",
184+
:Configuration_not_found => "The configuration option {{key}} does not exist.",
185+
:Configuration_Settings => "Configuration Settings",
186+
:configuration_settings_updated => "The configuration settings were updated.",
184187
:Confirm_Password => "Confirm Password",
185188
:confirm_deletion => "Are you sure you want to delete this {{thing}}?",
186189
:confirm_user_ban => "Are you sure you want to ban this user?",
@@ -409,6 +412,8 @@
409412
:Sticky => "Sticky",
410413
:Sticky_this_topic => "Sticky this topic",
411414
:Subforums => "Subforums",
415+
:subforums_display => "Number of Sub-forums to Display",
416+
:subforums_display_description => "Limits the number of sub-forums listed underneath a forum listing. Defaults to 3.",
412417
:Subforums_For => "Subforums For",
413418
:Subscribe => "Subscribe",
414419
:Subscriptions => "Subscriptions",

config/routes.rb

+2
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
end
1616

1717
admin.chronic 'chronic', :controller => 'chronic'
18+
19+
admin.resources :configurations, :collection => { :update_all => :put }
1820
admin.resources :forums, :member => { :move_up => :put, :move_down => :put, :move_to_top => :put, :move_to_bottom => :put } do |forum|
1921
forum.resources :permissions
2022
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class AddDescriptionToConfigurations < ActiveRecord::Migration
2+
def self.up
3+
add_column :configurations, :description, :text
4+
add_column :configurations, :title, :string
5+
end
6+
7+
def self.down
8+
9+
end
10+
end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
class AddCanManageConfigurationsToPermissions < ActiveRecord::Migration
2+
def self.up
3+
add_column :permissions, :can_manage_configurations, :boolean, :default => false
4+
end
5+
6+
def self.down
7+
end
8+
end

db/schema.rb

+4-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
#
1010
# It's strongly recommended to check this file into your version control system.
1111

12-
ActiveRecord::Schema.define(:version => 20090606004748) do
12+
ActiveRecord::Schema.define(:version => 20090607043542) do
1313

1414
create_table "banned_ips", :force => true do |t|
1515
t.string "ip"
@@ -29,6 +29,8 @@
2929
create_table "configurations", :force => true do |t|
3030
t.string "key"
3131
t.string "value"
32+
t.text "description"
33+
t.string "title"
3234
end
3335

3436
create_table "edits", :force => true do |t|
@@ -159,6 +161,7 @@
159161
t.boolean "can_delete_topics", :default => false
160162
t.boolean "can_manage_moderations", :default => false
161163
t.boolean "can_read_others_private_messages", :default => false
164+
t.boolean "can_manage_configurations", :default => false
162165
end
163166

164167
create_table "posts", :force => true do |t|

lib/tasks/install.rake

+1-1
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ task :install => :environment do
8989
:can_see_category => true)
9090

9191
puts "Generating some configuration options..."
92-
Configuration.create(:key => "default_group_id", :value => registered_group.id)
92+
Configuration.create(:key => "subforums_display", :title => I18n.t(:subforums_display), :value => 3, :description => I18n.t(:subforums_display_description))
9393

9494
if SEARCHING
9595
puts "Configuring thinking sphinx..."

public/themes/blue/style.css

+4
Original file line numberDiff line numberDiff line change
@@ -257,4 +257,8 @@ ul#admin-navlist, ul#moderator-navlist {
257257

258258
.list-table td {
259259
text-align: center;
260+
}
261+
262+
.lalign {
263+
text-align:left !important;
260264
}

spec/fixtures/configurations.yml

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
subforums_display:
2+
key: subforums_display
3+
value: "1"
4+
description: Limit the number of subforums displayed on the forums listing.
5+
title: Number of Subforums to Display

spec/models/configuration_spec.rb

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
2+
3+
describe Configuration do
4+
fixtures :configurations
5+
it "should be able to find a configuration with a valid key" do
6+
Configuration['subforums_display'].should_not be_nil
7+
end
8+
9+
it "should not be able to find a configuration with an invalid key" do
10+
lambda { Configuration['invalid_key'] }.should raise_error(Configuration::NotFound, "The configuration option invalid_key does not exist.")
11+
end
12+
13+
end

0 commit comments

Comments
 (0)