more forum stuff

This commit is contained in:
jomo
2013-10-16 00:51:50 +02:00
parent 7c578874c9
commit b6115970dd
25 changed files with 208 additions and 55 deletions
+23 -7
View File
@@ -290,9 +290,22 @@ and (min-width: 0px) //TODO
&[type=submit] { &[type=submit] {
margin: 0; margin: 0;
} }
option {
padding: 0.5em;
&:hover {
background: #0f0;
color: #00f;
}
&:nth-child(even) {
background: #eee;
}
&:nth-child(odd) {
background: #ccc;
}
}
} }
input[type=text], input[type=email], input[type=password], textarea { input[type=text], input[type=email], input[type=password], input[type=number], textarea, select {
background: #ddd; background: #ddd;
border: none; border: none;
display: block; display: block;
@@ -352,13 +365,13 @@ and (min-width: 0px) //TODO
float: left; float: left;
label { label {
display: block; display: block;
padding: 0 0 4px 0; padding: 0.5em;
margin: 0 4px 4px;
height: 17px;
} }
} }
#form_inputs { #form_inputs {
input, select, textarea {
width: 400px;
}
} }
.profile-action { .profile-action {
@@ -397,6 +410,9 @@ and (min-width: 0px) //TODO
&.red { &.red {
background: #ee4040; background: #ee4040;
} }
&.right {
float: right;
}
&:hover { &:hover {
box-shadow: 0 0 5px #095fb7 inset; box-shadow: 0 0 5px #095fb7 inset;
color: #fff; color: #fff;
@@ -468,7 +484,7 @@ and (min-width: 0px) //TODO
.header { .header {
background: #ddd; background: #ddd;
border-radius: 5px 5px 0 0; border-radius: 5px 5px 0 0;
padding: 5px 10px; padding: 0.5em;
border-bottom: 1px solid #ccc; border-bottom: 1px solid #ccc;
} }
.forums { .forums {
@@ -478,7 +494,7 @@ and (min-width: 0px) //TODO
.forum { .forum {
display: block; display: block;
font-weight: bold; font-weight: bold;
padding: 5px 10px; padding: 0.5em;
border-bottom: 1px solid #ddd; border-bottom: 1px solid #ddd;
} }
} }
+1 -1
View File
@@ -29,7 +29,7 @@ class BlogpostsController < ApplicationController
def create def create
if mod? if mod?
@post = Blogpost.new(params[:blogpost]) @post = Blogpost.new(params[:blogpost] ? params[:blogpost].slice(:title, :content) : {})
@post.user_author = current_user @post.user_author = current_user
if @post.save if @post.save
redirect_to @post, notice: 'Post has been created.' redirect_to @post, notice: 'Post has been created.'
+39 -2
View File
@@ -1,9 +1,46 @@
class ForumgroupsController < ApplicationController class ForumgroupsController < ApplicationController
def index def index
@groups = Forumgroup.all.sort_by{|s| s[:position]} @groups = Forumgroup.all
if current_user
@groups.select! do |g|
g.role_read == nil || g.role_read <= current_user.role
end
else
@groups.select!{|g| g.role_read == nil}
end
@groups.sort_by{|g| g[:position]}
end end
def show def show
redirect_to forumgroups_path + "#forum-#{params[:id]}" redirect_to forumgroups_path + "#forums-#{params[:id]}"
end end
def new
if admin?
@group = Forumgroup.new
else
flash[:alert] = "You are not allowed to create forums."
redirect_to forumgroups_path
end
end
def create
if admin?
@group = Forumgroup.new(params[:forumgroup])
if @group.save
flash[:notice] = "Forums created."
redirect_to @group
else
flash[:alert] = "Something went wrong"
render :new
end
else
flash[:alert] = "You are not allowed to create forums."
redirect_to forumgroups_path
end
end
end end
+27
View File
@@ -8,4 +8,31 @@ class ForumsController < ApplicationController
@threads = @forum.forumthreads @threads = @forum.forumthreads
end end
def new
if admin?
@group = Forumgroup.find(params[:forumgroup_id])
@forum = Forum.new(forumgroup: @group)
else
flash[:alert] = "You are not allowed to create a forum."
redirect_to forumgroups_path
end
end
def create
if admin?
@forum = Forum.new(params[:forum])
@forum.forumgroup = Forumgroup.find(params[:forumgroup_id])
if @forum.save
flash[:notice] = "Forum created."
redirect_to @forum
else
flash[:alert] = "Something went wrong"
render :new
end
else
flash[:alert] = "You are not allowed to create a forum."
redirect_to forums_path
end
end
end end
+6
View File
@@ -0,0 +1,6 @@
[yt](729o_Xwg1WU)
\[yt\]\(([a-zA-Z0-9\-_]+)\)
https://www.youtube.com/embed/{id}?theme=light&iv_load_policy=3&showinfo=1&showsearch=0&rel=0&modestbranding&hd=1&autohide=1
+4
View File
@@ -1,6 +1,10 @@
class Forum < ActiveRecord::Base class Forum < ActiveRecord::Base
belongs_to :forumgroup belongs_to :forumgroup
has_many :forumthreads has_many :forumthreads
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
attr_accessible :name, :position, :role_read, :role_write, :role_read_id, :role_write_id, :forumgroup, :forumgroup_id
def to_s def to_s
name name
+8
View File
@@ -1,5 +1,13 @@
class Forumgroup < ActiveRecord::Base class Forumgroup < ActiveRecord::Base
has_many :forums has_many :forums
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
accepts_nested_attributes_for :forums
attr_accessible :name, :position, :role_read, :role_write, :role_read_id, :role_write_id
validates_presence_of :name, :position
validates_length_of :name, in: 2..20
def to_s def to_s
name name
+6
View File
@@ -35,4 +35,10 @@ class Role < ActiveRecord::Base
end end
end end
def self.all_from(role)
Role.all.select do |r|
r >= role
end
end
end end
+1 -1
View File
@@ -6,5 +6,5 @@
<%= f.submit "Update Post", :id => "edit_create_post", class: "btn blue" %> <%= f.submit "Update Post", :id => "edit_create_post", class: "btn blue" %>
<% end %> <% end %>
<div id="delete_post"> <div id="delete_post">
<%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post + comments forever?", class: "btn red" %> <%= button_to "Delete post", @post, :method => "delete", :confirm => "Delete post & comments forever?", class: "btn red right" %>
</div> </div>
+2 -2
View File
@@ -1,6 +1,7 @@
<%= button_to 'Make new Post', new_blogpost_path, method: "get", class: "btn blue" if mod? %>
<div id="posts"> <div id="posts">
<% @posts.each do |p| %> <% @posts.each do |p| %>
<div class="post"> <div class="post" id="post-<%= p.id %>">
<div class="post-title"> <div class="post-title">
<h2><%= link_to truncate(p.title, length: 60, omission: " …"), p %></h2> <h2><%= link_to truncate(p.title, length: 60, omission: " …"), p %></h2>
<span class="comment-counter"> <span class="comment-counter">
@@ -15,5 +16,4 @@
</div> </div>
</div> </div>
<% end %> <% end %>
<%= button_to 'Make new Post', new_blogpost_path, method: "get", class: "btn blue" if mod? %>
</div> </div>
+1 -1
View File
@@ -1,4 +1,4 @@
<div class="comment <%= "author" if c.author == @post.author %>"> <div class="comment <%= "author" if c.author == @post.author %>" id="comment-<%= c.id %>">
<span class="comment-info"><%= link_to c.author.name, c.author %> <%= c.created_at.strftime("%e. %b %Y, %H:%m") %> <span class="comment-info"><%= link_to c.author.name, c.author %> <%= c.created_at.strftime("%e. %b %Y, %H:%m") %>
<% if mod? || c.author.is?(current_user) %> <% if mod? || c.author.is?(current_user) %>
<div class="editlink"><%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c) %></div> <div class="editlink"><%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c) %></div>
+1 -1
View File
@@ -5,5 +5,5 @@
<%= f.submit "Update Comment", :id => "edit_create_comment", class: "btn blue" %> <%= f.submit "Update Comment", :id => "edit_create_comment", class: "btn blue" %>
<% end %> <% end %>
<div id="delete_comment"> <div id="delete_comment">
<%= button_to "Delete comment", [@comment.blogpost, @comment] , :method => "delete", :confirm => "Delete comment forever?", class: "btn red" %> <%= button_to "Delete comment", [@comment.blogpost, @comment] , :method => "delete", :confirm => "Delete comment forever?", class: "btn red right" %>
</div> </div>
+5 -5
View File
@@ -1,15 +1,15 @@
<div id="forum_groups"> <div id="forum_groups">
<% @groups.each do |group| %> <% @groups.each do |group| %>
<div class="group" id="forum-<%= group.id %>"> <div class="group" id="forums-<%= group.id %>">
<div class="header"> <div class="header">
<%= group.name %> <%= group.name %>
</div> </div>
<div class="forums"> <div class="forums">
<% group.forums.sort_by{|s| s[:position]}.each do |f| %> <% group.forums.each do |f| %>
<div class="forum"> <div class="forum">
<%= link_to f.name, f %> <%= link_to f.name, f %>
</div> </div>
<% end %> <% end %>
</div> </div>
+16
View File
@@ -0,0 +1,16 @@
<h1>New forum group</h1>
<%= simple_form_for @group do |f|%>
<div id="form_labels">
<%= f.label :name %>
<%= f.label :position %>
<%= f.label :role_read_id, "Min read role" %>
<%= f.label :role_write_id, "Min write role" %>
</div>
<div id="form_inputs">
<%= f.input :name, placeholder: "Name" %>
<%= f.input :position, placeholder: "Position" %>
<%= f.input :role_read_id, as: :select, collection: Role.all_from(Role.get :default), include_blank: "None" %>
<%= f.input :role_write_id, as: :select, collection: Role.all_from(Role.get :default), include_blank: false %>
</div>
<%= f.submit "Create group", class: "btn blue" %>
<% end %>
+17
View File
@@ -0,0 +1,17 @@
<%= link_to @group %> → New forum
<h1>New forum</h1>
<%= simple_form_for [@group, @forum] do |f|%>
<div id="form_labels">
<%= f.label :name %>
<%= f.label :position %>
<%= f.label :role_read_id, "Min read role" %>
<%= f.label :role_write_id, "Min write role" %>
</div>
<div id="form_inputs">
<%= f.input :name, placeholder: "Name" %>
<%= f.input :position, placeholder: "Position" %>
<%= f.input :role_read_id, as: :select, collection: Role.all_from(Role.get :default), include_blank: "None" %>
<%= f.input :role_write_id, as: :select, collection: Role.all_from(Role.get :default), include_blank: false %>
</div>
<%= f.submit "Create forum", class: "btn blue" %>
<% end %>
+1 -1
View File
@@ -1,4 +1,4 @@
<div class='forum-path'><%= link_to @forum.group, forumgroup_path(@forum.group) %><%= link_to @forum %></div> <%= link_to "Forums", forumgroups_path %><%= link_to @forum.group, "#{forumgroups_path}#forums-#{@forum.group.id}" %><%= link_to @forum %>
<h1><%= @forum.name %></h1> <h1><%= @forum.name %></h1>
<div id="forum_threads"> <div id="forum_threads">
<% @threads.each do |thread| %> <% @threads.each do |thread| %>
+1
View File
@@ -17,6 +17,7 @@
<div id="menu"> <div id="menu">
<ul> <ul>
<%= link_to root_path do %><li>Home</li><% end %> <%= link_to root_path do %><li>Home</li><% end %>
<%= link_to users_path do %><li>Users</li><% end %>
<%= link_to root_path do %><li>Info</li><% end %> <%= link_to root_path do %><li>Info</li><% end %>
<%= link_to forumgroups_path do %><li>Forums</li><% end %> <%= link_to forumgroups_path do %><li>Forums</li><% end %>
<%= link_to root_path do %><li>Donate</li><% end %> <%= link_to root_path do %><li>Donate</li><% end %>
+4 -4
View File
@@ -1,5 +1,5 @@
<h1>Log in</h1> <h1>Log in</h1>
<p>Not a member? <%= link_to "Join us here", signup_path %>!</p> <p>Not a member? <%= link_to "Join us", signup_path %>!</p>
<%= form_tag login_path do |f| %> <%= form_tag login_path do |f| %>
<div id="form_labels"> <div id="form_labels">
<%= label_tag :email %> <%= label_tag :email %>
@@ -7,9 +7,9 @@
</div> </div>
<div id="form_inputs"> <div id="form_inputs">
<%= text_field_tag :email %> <%= text_field_tag :email, nil, placeholder: "email@example.com" %>
<%= password_field_tag :password %> <%= password_field_tag :password, nil, placeholder: "••••••" %>
</div> </div>
<%= submit_tag "Log in" %> <%= submit_tag "Log in", class: "btn blue" %>
<% end %> <% end %>
+16 -7
View File
@@ -1,4 +1,4 @@
<%= link_to "Your profile", current_user %> → Edit <%= link_to (@user.is?(current_user) ? "Your profile" : @user.name), current_user %> → Edit
<h1>Edit profile</h1> <h1>Edit profile</h1>
<%= simple_form_for @user do |f| %> <%= simple_form_for @user do |f| %>
@@ -32,15 +32,19 @@
</tr> </tr>
<tr> <tr>
<td> <td>
Skype username<br> Skype username
Show to...
</td> </td>
<td> <td>
<%= f.input :skype, label: false, placeholder: "Skype username", disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) %> <%= f.input :skype, label: false, placeholder: "Skype username", disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) %>
<%= f.input :skype_public, label: false, as: :radio_buttons, collection: [['all users', false], ['only staff', true]], input_html: { disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) } %>
</td>
</td> </td>
</tr> </tr>
<tr>
<td>
Show Skype to
</td>
<td>
<%= f.input :skype_public, label: false, as: :select, collection: [["Staff only", false], ["All users", true]], include_blank: false, input_html: { disabled: !((@user.is?(current_user) && confirmed?) || (mod? && current_user.role >= @user.role)) } %>
</td>
<tr> <tr>
<td>YouTube username</td> <td>YouTube username</td>
<td> <td>
@@ -61,8 +65,13 @@
</tr> </tr>
</tbody> </tbody>
</table> </table>
<%= f.submit "Save profile", disabled: @user.unconfirmed? %> <%= f.submit "Save profile", class: "btn blue", disabled: @user.unconfirmed? %>
<% if @user.unconfirmed? %> <% if @user.unconfirmed? %>
<span class='red-alert'>Please confirm your email adress first.</span> <% if @user.is?(current_user) %>
<span class='red-alert'>Please confirm your email adress first!</span>
<% else %>
<span class='red-alert'>This user has not confirmed his email!</span>
<% end %>
<% end %> <% end %>
<%= link_to "Cancel", @user, class: "btn red right" %>
<% end %> <% end %>
+16 -7
View File
@@ -1,10 +1,19 @@
<h1>Register</h1> <h1>Sign up</h1>
<%= simple_form_for @user do |f| %> <%= simple_form_for @user do |f| %>
<%= f.input :name, label: "Display Name" %> <div id="form_labels">
<%= f.input :ign, label: "Case sensitive Minecraft name" %> <%= f.label :name, "Display name" %>
<%= f.input :email %> <%= f.label :ign, "Minecraft name" %>
<%= f.input :password %> <%= f.label :email, "Email" %>
<%= f.input :password_confirmation %> <%= f.label :password, "Password" %>
<%= f.submit "Register" %> <%= f.label :password_confirmation, "Confirm" %>
</div>
<div id="form_inputs">
<%= f.input :name, placeholder: "John" %>
<%= f.input :ign, placeholder: "johndoe_1337" %>
<%= f.input :email, placeholder: "johndoe@example.com" %>
<%= f.input :password, placeholder: "••••••" %>
<%= f.input :password_confirmation, placeholder: "••••••" %>
</div>
<%= f.submit "Sign up", class: "btn blue" %>
<% end %> <% end %>
+2 -7
View File
@@ -16,13 +16,8 @@ Site::Application.routes.draw do
end end
end end
resources :forumgroups, :path => '/forums' do resources :forumgroups, :path => '/forums' do
member do resources :forums, :path => 'f' do
resources :forums, :path => 'f' do resources :forumthreads, :path => 't', :as => 'threads'
member do
resources :forumthreads, :path => 't', :as => 'threads' do
end
end
end
end end
end end
@@ -3,8 +3,9 @@ class CreateForumgroups < ActiveRecord::Migration
create_table :forumgroups do |t| create_table :forumgroups do |t|
t.string :name t.string :name
t.integer :position t.integer :position
t.integer :read_permission
t.integer :write_permission t.references :role_read
t.references :role_write
end end
end end
end end
+3 -2
View File
@@ -3,8 +3,9 @@ class CreateForums < ActiveRecord::Migration
create_table :forums do |t| create_table :forums do |t|
t.string :name t.string :name
t.integer :position t.integer :position
t.integer :read_permission
t.integer :write_permission t.references :role_read
t.references :role_write
t.references :forumgroup t.references :forumgroup
end end
+5 -5
View File
@@ -11,7 +11,7 @@
# #
# It's strongly recommended to check this file into your version control system. # It's strongly recommended to check this file into your version control system.
ActiveRecord::Schema.define(:version => 20130922181339) do ActiveRecord::Schema.define(:version => 8) do
create_table "blogposts", :force => true do |t| create_table "blogposts", :force => true do |t|
t.string "title" t.string "title"
@@ -34,15 +34,15 @@ ActiveRecord::Schema.define(:version => 20130922181339) do
create_table "forumgroups", :force => true do |t| create_table "forumgroups", :force => true do |t|
t.string "name" t.string "name"
t.integer "position" t.integer "position"
t.integer "read_permission" t.integer "role_read_id"
t.integer "write_permission" t.integer "role_write_id"
end end
create_table "forums", :force => true do |t| create_table "forums", :force => true do |t|
t.string "name" t.string "name"
t.integer "position" t.integer "position"
t.integer "read_permission" t.integer "role_read_id"
t.integer "write_permission" t.integer "role_write_id"
t.integer "forumgroup_id" t.integer "forumgroup_id"
end end