From a6c062bde7ebf59cc318ff6e79c1ad46d0e54417 Mon Sep 17 00:00:00 2001 From: jomo Date: Sat, 17 Jan 2015 18:28:38 +0100 Subject: [PATCH] make labels editable in threads --- app/assets/stylesheets/style.css.scss | 25 ++++++++++++++----- app/controllers/forumthreads_controller.rb | 2 +- app/controllers/sessions_controller.rb | 2 ++ app/models/label.rb | 1 - app/views/forumthreads/edit.html.erb | 24 ++++++++++++------ app/views/forumthreads/new.html.erb | 14 ++++++++++- .../20150117154652_remove_role_from_label.rb | 5 ++++ db/schema.rb | 7 +++--- 8 files changed, 60 insertions(+), 20 deletions(-) create mode 100644 db/migrate/20150117154652_remove_role_from_label.rb diff --git a/app/assets/stylesheets/style.css.scss b/app/assets/stylesheets/style.css.scss index fb383e3..fe7f560 100644 --- a/app/assets/stylesheets/style.css.scss +++ b/app/assets/stylesheets/style.css.scss @@ -572,6 +572,7 @@ input , select, textarea { option { padding: 0.5em; + height: 2em; &:hover { background: #0f0; @@ -588,14 +589,26 @@ input , select, textarea { } } -input[type=text], input[type=email], input[type=password], input[type=number], textarea, select { - background: #ddd; - border: none; - height: 3em; - margin: 4px 0 0; - padding: 0.5em 1em; +.table-cell { + display: table-cell; + + &.full-width { width: 100%; } +} + +input[type=text], input[type=email], input[type=password], input[type=number], textarea, select { + background: #ddd; + border: none; + height: 3em; + margin: 4px 0 0; + padding: 0.5em 1em; + width: 100%; + + &.auto-width { + width: auto; + } +} input, select, textarea { &.disabled, &[disabled] { diff --git a/app/controllers/forumthreads_controller.rb b/app/controllers/forumthreads_controller.rb index 8f8a1ce..675f907 100644 --- a/app/controllers/forumthreads_controller.rb +++ b/app/controllers/forumthreads_controller.rb @@ -83,7 +83,7 @@ class ForumthreadsController < ApplicationController end def thread_params(add = []) - a = [:title, :content] + a = [:title, :content, :label_id] a += add params.require(:forumthread).permit(a) end diff --git a/app/controllers/sessions_controller.rb b/app/controllers/sessions_controller.rb index 5fda8f1..f901b39 100644 --- a/app/controllers/sessions_controller.rb +++ b/app/controllers/sessions_controller.rb @@ -43,6 +43,7 @@ class SessionsController < ApplicationController logout_user = current_user session[:user_id] = original_user.try(:id) session.delete(:original_user_id) + puts "User #{original_user} reverted from #{logout_user}!" flash[:notice] = "You are no longer '#{logout_user.name}'!" redirect_to original_user else @@ -63,6 +64,7 @@ class SessionsController < ApplicationController else session[:original_user_id] = original_user.id session[:user_id] = new_user.id + puts "User #{original_user} became #{new_user}!" flash[:notice] = "You are now '#{new_user.name}'!" end end diff --git a/app/models/label.rb b/app/models/label.rb index e0cf98e..863546d 100644 --- a/app/models/label.rb +++ b/app/models/label.rb @@ -1,7 +1,6 @@ class Label < ActiveRecord::Base validates_presence_of :name validate :color_valid - belongs_to :role has_and_belongs_to_many :forums has_many :forumthreads diff --git a/app/views/forumthreads/edit.html.erb b/app/views/forumthreads/edit.html.erb index f40686c..a9be186 100644 --- a/app/views/forumthreads/edit.html.erb +++ b/app/views/forumthreads/edit.html.erb @@ -1,5 +1,16 @@ <% title "Edit Thread: #{@thread}" %> +<% + forums = [] + Forum.all.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f| + forums << ["#{f.forumgroup.name} → #{f.name}", f.id] if f.forumgroup + end + labels = [["Label", nil]] + Label.order(:name).each do |l| + labels << [l.name, l.id] + end +%> +

Edit thread

<%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → New thread <%= form_for @thread do |f|%> @@ -13,17 +24,16 @@ <%= f.label :forum_id, "Move thread" %> - <% - forums = [] - Forum.all.sort_by{ |f| f.forumgroup && f.forumgroup.position || 0 }.each do |f| - forums << ["#{f.forumgroup.name} → #{f.name}", f.id] if f.forumgroup - end - %> <%= f.select :forum_id, forums %> <% end %> - <%= f.text_field :title, placeholder: "Title" %> +
+ <%= f.select :label_id, labels, {}, class: "auto-width" %> +
+
+ <%= f.text_field :title, placeholder: "Title" %> +
<%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content, mini: false} %>

<%= f.submit "Update thread", class: "btn blue left" %>

<% end %> diff --git a/app/views/forumthreads/new.html.erb b/app/views/forumthreads/new.html.erb index 9c01633..fec08e7 100644 --- a/app/views/forumthreads/new.html.erb +++ b/app/views/forumthreads/new.html.erb @@ -1,5 +1,12 @@ <% title "New Thread: #{@thread.forum.name}" %> +<% + labels = [["Label", nil]] + Label.order(:name).each do |l| + labels << [l.name, l.id] + end +%> + <%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → New thread

New thread

<%= form_for @thread do |f|%> @@ -15,7 +22,12 @@ <% end %> - <%= f.text_field :title, placeholder: "Title" %> +
+ <%= f.select :label_id, labels, {}, class: "auto-width" %> +
+
+ <%= f.text_field :title, placeholder: "Title" %> +
<%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content, mini: false} %> <%= f.hidden_field :forum_id %>

<%= f.submit "Create thread", class: "btn blue left" %>

diff --git a/db/migrate/20150117154652_remove_role_from_label.rb b/db/migrate/20150117154652_remove_role_from_label.rb new file mode 100644 index 0000000..47fe48f --- /dev/null +++ b/db/migrate/20150117154652_remove_role_from_label.rb @@ -0,0 +1,5 @@ +class RemoveRoleFromLabel < ActiveRecord::Migration + def change + remove_column :labels, :role_id + end +end diff --git a/db/schema.rb b/db/schema.rb index cd86337..acd47c1 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20150117134404) do +ActiveRecord::Schema.define(version: 20150117154652) do create_table "blogposts", force: true do |t| t.string "title" @@ -70,9 +70,8 @@ ActiveRecord::Schema.define(version: 20150117134404) do end create_table "labels", force: true do |t| - t.string "name" - t.integer "role_id" - t.string "color" + t.string "name" + t.string "color" end create_table "register_tokens", force: true do |t|