make labels editable in threads

This commit is contained in:
jomo
2015-01-17 18:28:38 +01:00
parent 5f00fc87a3
commit a6c062bde7
8 changed files with 60 additions and 20 deletions
+19 -6
View File
@@ -572,6 +572,7 @@ input , select, textarea {
option { option {
padding: 0.5em; padding: 0.5em;
height: 2em;
&:hover { &:hover {
background: #0f0; background: #0f0;
@@ -588,14 +589,26 @@ input , select, textarea {
} }
} }
input[type=text], input[type=email], input[type=password], input[type=number], textarea, select { .table-cell {
background: #ddd; display: table-cell;
border: none;
height: 3em; &.full-width {
margin: 4px 0 0;
padding: 0.5em 1em;
width: 100%; 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 { input, select, textarea {
&.disabled, &[disabled] { &.disabled, &[disabled] {
+1 -1
View File
@@ -83,7 +83,7 @@ class ForumthreadsController < ApplicationController
end end
def thread_params(add = []) def thread_params(add = [])
a = [:title, :content] a = [:title, :content, :label_id]
a += add a += add
params.require(:forumthread).permit(a) params.require(:forumthread).permit(a)
end end
+2
View File
@@ -43,6 +43,7 @@ class SessionsController < ApplicationController
logout_user = current_user logout_user = current_user
session[:user_id] = original_user.try(:id) session[:user_id] = original_user.try(:id)
session.delete(:original_user_id) session.delete(:original_user_id)
puts "User #{original_user} reverted from #{logout_user}!"
flash[:notice] = "You are no longer '#{logout_user.name}'!" flash[:notice] = "You are no longer '#{logout_user.name}'!"
redirect_to original_user redirect_to original_user
else else
@@ -63,6 +64,7 @@ class SessionsController < ApplicationController
else else
session[:original_user_id] = original_user.id session[:original_user_id] = original_user.id
session[:user_id] = new_user.id session[:user_id] = new_user.id
puts "User #{original_user} became #{new_user}!"
flash[:notice] = "You are now '#{new_user.name}'!" flash[:notice] = "You are now '#{new_user.name}'!"
end end
end end
-1
View File
@@ -1,7 +1,6 @@
class Label < ActiveRecord::Base class Label < ActiveRecord::Base
validates_presence_of :name validates_presence_of :name
validate :color_valid validate :color_valid
belongs_to :role
has_and_belongs_to_many :forums has_and_belongs_to_many :forums
has_many :forumthreads has_many :forumthreads
+17 -7
View File
@@ -1,5 +1,16 @@
<% title "Edit Thread: #{@thread}" %> <% 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
%>
<h1>Edit thread</h1> <h1>Edit thread</h1>
<%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %><%= link_to @thread.forum, @thread.forum %> → New thread <%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %><%= link_to @thread.forum, @thread.forum %> → New thread
<%= form_for @thread do |f|%> <%= form_for @thread do |f|%>
@@ -13,17 +24,16 @@
</tr> </tr>
<tr> <tr>
<td><%= f.label :forum_id, "Move thread" %></td> <td><%= f.label :forum_id, "Move thread" %></td>
<%
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
%>
<td><%= f.select :forum_id, forums %></td> <td><%= f.select :forum_id, forums %></td>
</tr> </tr>
<% end %> <% end %>
</table> </table>
<%= f.text_field :title, placeholder: "Title" %> <div class="table-cell">
<%= f.select :label_id, labels, {}, class: "auto-width" %>
</div>
<div class="table-cell full-width">
<%= f.text_field :title, placeholder: "Title" %>
</div>
<%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content, mini: false} %> <%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content, mini: false} %>
<p><%= f.submit "Update thread", class: "btn blue left" %></p> <p><%= f.submit "Update thread", class: "btn blue left" %></p>
<% end %> <% end %>
+13 -1
View File
@@ -1,5 +1,12 @@
<% title "New Thread: #{@thread.forum.name}" %> <% 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 <%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %><%= link_to @thread.forum, @thread.forum %> → New thread
<h1>New thread</h1> <h1>New thread</h1>
<%= form_for @thread do |f|%> <%= form_for @thread do |f|%>
@@ -15,7 +22,12 @@
</tr> </tr>
<% end %> <% end %>
</table> </table>
<%= f.text_field :title, placeholder: "Title" %> <div class="table-cell">
<%= f.select :label_id, labels, {}, class: "auto-width" %>
</div>
<div class="table-cell full-width">
<%= f.text_field :title, placeholder: "Title" %>
</div>
<%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content, mini: false} %> <%= render partial: "md_editor", locals: {name: "forumthread[content]", content: @thread.content, mini: false} %>
<%= f.hidden_field :forum_id %> <%= f.hidden_field :forum_id %>
<p><%= f.submit "Create thread", class: "btn blue left" %></p> <p><%= f.submit "Create thread", class: "btn blue left" %></p>
@@ -0,0 +1,5 @@
class RemoveRoleFromLabel < ActiveRecord::Migration
def change
remove_column :labels, :role_id
end
end
+3 -4
View File
@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # 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| create_table "blogposts", force: true do |t|
t.string "title" t.string "title"
@@ -70,9 +70,8 @@ ActiveRecord::Schema.define(version: 20150117134404) do
end end
create_table "labels", force: true do |t| create_table "labels", force: true do |t|
t.string "name" t.string "name"
t.integer "role_id" t.string "color"
t.string "color"
end end
create_table "register_tokens", force: true do |t| create_table "register_tokens", force: true do |t|