diff --git a/app/assets/stylesheets/screen.css.scss b/app/assets/stylesheets/screen.css.scss index 759ff1f..a88487a 100644 --- a/app/assets/stylesheets/screen.css.scss +++ b/app/assets/stylesheets/screen.css.scss @@ -330,14 +330,17 @@ and (min-width: 0px) //TODO } } + .input { + height: 3em; + } input[type=text], input[type=email], input[type=password], input[type=number], textarea, select { background: #ddd; border: none; - display: block; height: 3em; margin: 0 0 1px 0; padding: 0.5em 1em; width: 100%; + display: block; } input, select, textarea { @@ -374,14 +377,14 @@ and (min-width: 0px) //TODO } .field_with_errors { - input { - &[type=text], &[type=email], &[type=password] { - border: 1px solid #f00; - box-shadow: 0 0 5px #faa inset; - } + input, select, textarea { + border: 1px solid #f00; + box-shadow: 0 0 5px #faa inset; } .error { color: #f60; + display: inline; + margin-left: 0.5em; } } @@ -518,6 +521,10 @@ and (min-width: 0px) //TODO #forum_groups { .group { margin: 10px 0; + &:hover .editlink { + opacity: 1; + margin-right: 0; + } .header { background: #ddd; border-radius: 5px 5px 0 0; diff --git a/app/controllers/blogposts_controller.rb b/app/controllers/blogposts_controller.rb index 86adbb3..789ed72 100644 --- a/app/controllers/blogposts_controller.rb +++ b/app/controllers/blogposts_controller.rb @@ -6,7 +6,7 @@ class BlogpostsController < ApplicationController def show @post = Blogpost.find(params[:id]) - @comment = Comment.new(:blogpost => @post) + @comment = Comment.new(blogpost: @post) end def new diff --git a/app/controllers/forumgroups_controller.rb b/app/controllers/forumgroups_controller.rb index bacadab..5b9528c 100644 --- a/app/controllers/forumgroups_controller.rb +++ b/app/controllers/forumgroups_controller.rb @@ -1,19 +1,18 @@ class ForumgroupsController < ApplicationController def index - @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]} + redirect_to forums_path end def show - redirect_to forumgroups_path + "#forums-#{params[:id]}" + redirect_to forums_path + "#forums-#{params[:id]}" + end + + def edit + end + + def update + end def new @@ -21,7 +20,7 @@ class ForumgroupsController < ApplicationController @group = Forumgroup.new else flash[:alert] = "You are not allowed to create forums." - redirect_to forumgroups_path + redirect_to forums_path end end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index 2ecb551..5c387a1 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -1,11 +1,23 @@ class ForumsController < ApplicationController - def index - redirect_to :forumgroups + def index + @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 @forum = Forum.find(params[:id]) - @threads = @forum.forumthreads + if @forum.role_read.nil? || current_user && @forum.role_read <= current_user.role + @threads = @forum.forumthreads.reverse + else + redirect_to forums_path + end end def new @@ -14,7 +26,7 @@ class ForumsController < ApplicationController @forum = Forum.new(forumgroup: @group) else flash[:alert] = "You are not allowed to create a forum." - redirect_to forumgroups_path + redirect_to forums_path end end diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index 27e2bb7..3508d55 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -3,4 +3,20 @@ class ForumthreadsController < ApplicationController f = Forum.find(params[:id]) redirect_to forum_path(f.forumgroup, f) end + + def new + @forum = Forum.find(params[:id]) + if @forum && current_user && (@forum.group.role_read.nil? || @forum.group.role_read <= current_user.role) && (@forum.role_read.nil? || @forum.role_read <= current_user.role) + @thread = Forumthread.new(forum: @forum) + else + flash[:alert] = "You are not allowed to create a new thread here!" + end + end + + def create + flash[:alert] = "Not yet ;(" + redirect_to forum_path(params[:id]) + end + + end \ No newline at end of file diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index d3260fe..33e38d6 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -3,8 +3,10 @@ class SessionsController < ApplicationController def new if current_user - redirect_to current_user flash[:alert] = "You are already logged in!" + redirect_to current_user + else + cookies[:return_path] = params[:return_path] if params[:return_path] end end @@ -23,23 +25,27 @@ class SessionsController < ApplicationController user.save if user.disabled? flash[:alert] = "Your account has been disabled!" - redirect_to login_path elsif user.banned? flash[:alert] = "You are banned!" - redirect_to user else session[:user_id] = user.id - flash[:alert] = "Remember to validate your email! Your account might be deleted" if user.unconfirmed? - redirect_to root_path, :notice => "Logged in!" + flash[:alert] = "Remember to validate your email! Your account may be deleted soon!" if user.unconfirmed? + flash[:notice] = "Logged in!" end else flash[:alert] = "You're doing it wrong!" render action: 'new' + return end else - redirect_to current_user flash[:alert] = "You are already logged in!" end + if cookies[:return_path] + redirect_to cookies[:return_path] + cookies.delete(:return_path) + else + redirect_to root_path + end end def destroy diff --git a/app/models/forumthread.rb b/app/models/forumthread.rb index d56c700..e72d157 100644 --- a/app/models/forumthread.rb +++ b/app/models/forumthread.rb @@ -3,6 +3,11 @@ class Forumthread < ActiveRecord::Base belongs_to :user_author, class_name: "User", foreign_key: "user_author_id" belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id" + attr_accessible :name, :content, :sticky, :locked, :user_author, :user_editor, :forum + + validates_presence_of :name + validates_presence_of :content + def to_s name end diff --git a/app/views/forumgroups/edit.html.erb b/app/views/forumgroups/edit.html.erb new file mode 100644 index 0000000..583bf25 --- /dev/null +++ b/app/views/forumgroups/edit.html.erb @@ -0,0 +1 @@ +

Not yet

\ No newline at end of file diff --git a/app/views/forumgroups/index.html.erb b/app/views/forums/index.html.erb similarity index 81% rename from app/views/forumgroups/index.html.erb rename to app/views/forums/index.html.erb index b54c68b..49eeb03 100644 --- a/app/views/forumgroups/index.html.erb +++ b/app/views/forums/index.html.erb @@ -3,6 +3,7 @@
<%= group.name %> + <%= link_to "edit", edit_forumgroup_path(group), class: "editlink" if admin? %>
diff --git a/app/views/forums/show.html.erb b/app/views/forums/show.html.erb index 7400e8d..4fddd79 100644 --- a/app/views/forums/show.html.erb +++ b/app/views/forums/show.html.erb @@ -1,20 +1,12 @@ -<%= link_to "Forums", forumgroups_path %> → <%= link_to @forum.group, "#{forumgroups_path}#forums-#{@forum.group.id}" %> → <%= link_to @forum %> +<%= link_to "Forums", forumgroups_path %> → <%= link_to @forum.group, @forum.group %> → <%= link_to @forum %>

<%= @forum.name %>

+<%= link_to "New thread", new_forumthread_path, class: "btn blue" %>
<% @threads.each do |thread| %>
<%= thread.name %>
- -
- <% thread.forums.sort_by{|s| s[:position]}.each do |f| %> -
- <%= link_to f.name, f %> -
- <% end %> -
-
<% end %>
\ No newline at end of file diff --git a/app/views/forumthreads/new.html.erb b/app/views/forumthreads/new.html.erb new file mode 100644 index 0000000..d2ac2fd --- /dev/null +++ b/app/views/forumthreads/new.html.erb @@ -0,0 +1,18 @@ +<%= link_to @forum.group, @forum.group %> → <%= link_to @forum, @forum %> → New thread +

New thread

+<%= simple_form_for @thread do |f|%> +
+ <%= f.label :title %> + <%= f.label :sticky if mod? %> + <%= f.label :locked if mod? %> + <%= f.label :content, "Text" %> +
+
+ <%= f.input :title, placeholder: "Title" %> + <%= f.input :sticky, as: :select, collection: [["No", false], ["Yes", true]], include_blank: false if mod? %> + <%= f.input :locked, as: :select, collection: [["No", false], ["Yes", true]], include_blank: false if mod? %> + <%= f.input :content, placeholder: "Text" %> +
+ <%= f.submit "Create forum", class: "btn blue" %>
+ Yea i know this is ugly :D +<% end %> \ No newline at end of file diff --git a/app/views/layouts/_head.html.erb b/app/views/layouts/_head.html.erb index 45a5085..096d64e 100644 --- a/app/views/layouts/_head.html.erb +++ b/app/views/layouts/_head.html.erb @@ -10,7 +10,7 @@ <%= link_to image_tag(avatar_url(current_user.id, 32), :class => "avatar"), current_user %> <% else %> - <%= link_to "Log in", login_path, :action => "new" %> | <%= link_to "Sign up", signup_path %> + <%= link_to "Log in", login_path(return_path: request.env['PATH_INFO']), action: "new" %> | <%= link_to "Sign up", signup_path %> <% end %>
diff --git a/app/views/layouts/application.html.erb b/app/views/layouts/application.html.erb index 11336fb..9dd651a 100644 --- a/app/views/layouts/application.html.erb +++ b/app/views/layouts/application.html.erb @@ -9,7 +9,7 @@ <%= javascript_include_tag "application" %> -
We don't have a mobile style yet. It might look shitty.
Tip: Turn your device to landscape.
+
We don't have a mobile style yet. It might look shitty.
Tip: Hold your device in landscape mode.
<%= render "/layouts/head" %>
<%= "
#{alert}
".html_safe if alert %> diff --git a/config/routes.rb b/config/routes.rb index 5697824..8fbe199 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,6 +1,6 @@ Site::Application.routes.draw do - resources :blogposts, :path => '/blog' do + resources :blogposts, path: '/blog' do resources :comments end @@ -15,10 +15,14 @@ Site::Application.routes.draw do get 'unbecome' end end - resources :forumgroups, :path => '/forums' do - resources :forums, :path => 'f' do - resources :forumthreads, :path => 't', :as => 'threads' - end + + resources :forums, path: 'forums', as: 'forums' do + collection do + resources :forumgroups, path: 'groups' + end + member do + resources :forumthreads, path: 'threads' + end end match '/status' => 'status#show' @@ -30,5 +34,5 @@ Site::Application.routes.draw do post 'paypal' => 'paypal#create' - root :to => 'blogposts#index' + root to: 'blogposts#index' end \ No newline at end of file