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

View File

@@ -290,9 +290,22 @@ and (min-width: 0px) //TODO
&[type=submit] {
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;
border: none;
display: block;
@@ -352,13 +365,13 @@ and (min-width: 0px) //TODO
float: left;
label {
display: block;
padding: 0 0 4px 0;
margin: 0 4px 4px;
height: 17px;
padding: 0.5em;
}
}
#form_inputs {
input, select, textarea {
width: 400px;
}
}
.profile-action {
@@ -397,6 +410,9 @@ and (min-width: 0px) //TODO
&.red {
background: #ee4040;
}
&.right {
float: right;
}
&:hover {
box-shadow: 0 0 5px #095fb7 inset;
color: #fff;
@@ -468,7 +484,7 @@ and (min-width: 0px) //TODO
.header {
background: #ddd;
border-radius: 5px 5px 0 0;
padding: 5px 10px;
padding: 0.5em;
border-bottom: 1px solid #ccc;
}
.forums {
@@ -478,7 +494,7 @@ and (min-width: 0px) //TODO
.forum {
display: block;
font-weight: bold;
padding: 5px 10px;
padding: 0.5em;
border-bottom: 1px solid #ddd;
}
}

View File

@@ -29,7 +29,7 @@ class BlogpostsController < ApplicationController
def create
if mod?
@post = Blogpost.new(params[:blogpost])
@post = Blogpost.new(params[:blogpost] ? params[:blogpost].slice(:title, :content) : {})
@post.user_author = current_user
if @post.save
redirect_to @post, notice: 'Post has been created.'

View File

@@ -1,9 +1,46 @@
class ForumgroupsController < ApplicationController
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
def show
redirect_to forumgroups_path + "#forum-#{params[:id]}"
redirect_to forumgroups_path + "#forums-#{params[:id]}"
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

View File

@@ -8,4 +8,31 @@ class ForumsController < ApplicationController
@threads = @forum.forumthreads
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

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

View File

@@ -1,6 +1,10 @@
class Forum < ActiveRecord::Base
belongs_to :forumgroup
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
name

View File

@@ -1,5 +1,13 @@
class Forumgroup < ActiveRecord::Base
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
name

View File

@@ -35,4 +35,10 @@ class Role < ActiveRecord::Base
end
end
def self.all_from(role)
Role.all.select do |r|
r >= role
end
end
end

View File

@@ -6,5 +6,5 @@
<%= f.submit "Update Post", :id => "edit_create_post", class: "btn blue" %>
<% end %>
<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>

View File

@@ -1,6 +1,7 @@
<%= button_to 'Make new Post', new_blogpost_path, method: "get", class: "btn blue" if mod? %>
<div id="posts">
<% @posts.each do |p| %>
<div class="post">
<div class="post" id="post-<%= p.id %>">
<div class="post-title">
<h2><%= link_to truncate(p.title, length: 60, omission: " …"), p %></h2>
<span class="comment-counter">
@@ -15,5 +16,4 @@
</div>
</div>
<% end %>
<%= button_to 'Make new Post', new_blogpost_path, method: "get", class: "btn blue" if mod? %>
</div>

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") %>
<% if mod? || c.author.is?(current_user) %>
<div class="editlink"><%= link_to "edit", edit_blogpost_comment_path(c.blogpost, c) %></div>

View File

@@ -5,5 +5,5 @@
<%= f.submit "Update Comment", :id => "edit_create_comment", class: "btn blue" %>
<% end %>
<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>

View File

@@ -1,15 +1,15 @@
<div id="forum_groups">
<% @groups.each do |group| %>
<div class="group" id="forum-<%= group.id %>">
<div class="group" id="forums-<%= group.id %>">
<div class="header">
<%= group.name %>
</div>
<div class="forums">
<% group.forums.sort_by{|s| s[:position]}.each do |f| %>
<div class="forum">
<%= link_to f.name, f %>
</div>
<% group.forums.each do |f| %>
<div class="forum">
<%= link_to f.name, f %>
</div>
<% end %>
</div>

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 %>

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 %>

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>
<div id="forum_threads">
<% @threads.each do |thread| %>

View File

@@ -17,6 +17,7 @@
<div id="menu">
<ul>
<%= 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 forumgroups_path do %><li>Forums</li><% end %>
<%= link_to root_path do %><li>Donate</li><% end %>

View File

@@ -1,5 +1,5 @@
<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| %>
<div id="form_labels">
<%= label_tag :email %>
@@ -7,9 +7,9 @@
</div>
<div id="form_inputs">
<%= text_field_tag :email %>
<%= password_field_tag :password %>
<%= text_field_tag :email, nil, placeholder: "email@example.com" %>
<%= password_field_tag :password, nil, placeholder: "••••••" %>
</div>
<%= submit_tag "Log in" %>
<%= submit_tag "Log in", class: "btn blue" %>
<% end %>

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>
<%= simple_form_for @user do |f| %>
@@ -32,15 +32,19 @@
</tr>
<tr>
<td>
Skype username<br>
Show to...
Skype username
</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_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>
</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>
<td>YouTube username</td>
<td>
@@ -61,8 +65,13 @@
</tr>
</tbody>
</table>
<%= f.submit "Save profile", disabled: @user.unconfirmed? %>
<%= f.submit "Save profile", class: "btn blue", disabled: @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 %>
<%= link_to "Cancel", @user, class: "btn red right" %>
<% end %>

View File

@@ -1,10 +1,19 @@
<h1>Register</h1>
<h1>Sign up</h1>
<%= simple_form_for @user do |f| %>
<%= f.input :name, label: "Display Name" %>
<%= f.input :ign, label: "Case sensitive Minecraft name" %>
<%= f.input :email %>
<%= f.input :password %>
<%= f.input :password_confirmation %>
<%= f.submit "Register" %>
<div id="form_labels">
<%= f.label :name, "Display name" %>
<%= f.label :ign, "Minecraft name" %>
<%= f.label :email, "Email" %>
<%= f.label :password, "Password" %>
<%= 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 %>

View File

@@ -16,13 +16,8 @@ Site::Application.routes.draw do
end
end
resources :forumgroups, :path => '/forums' do
member do
resources :forums, :path => 'f' do
member do
resources :forumthreads, :path => 't', :as => 'threads' do
end
end
end
resources :forums, :path => 'f' do
resources :forumthreads, :path => 't', :as => 'threads'
end
end

View File

@@ -3,8 +3,9 @@ class CreateForumgroups < ActiveRecord::Migration
create_table :forumgroups do |t|
t.string :name
t.integer :position
t.integer :read_permission
t.integer :write_permission
t.references :role_read
t.references :role_write
end
end
end

View File

@@ -3,8 +3,9 @@ class CreateForums < ActiveRecord::Migration
create_table :forums do |t|
t.string :name
t.integer :position
t.integer :read_permission
t.integer :write_permission
t.references :role_read
t.references :role_write
t.references :forumgroup
end

View File

@@ -11,7 +11,7 @@
#
# 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|
t.string "title"
@@ -34,15 +34,15 @@ ActiveRecord::Schema.define(:version => 20130922181339) do
create_table "forumgroups", :force => true do |t|
t.string "name"
t.integer "position"
t.integer "read_permission"
t.integer "write_permission"
t.integer "role_read_id"
t.integer "role_write_id"
end
create_table "forums", :force => true do |t|
t.string "name"
t.integer "position"
t.integer "read_permission"
t.integer "write_permission"
t.integer "role_read_id"
t.integer "role_write_id"
t.integer "forumgroup_id"
end