add basic support for labels
This commit is contained in:
@@ -984,4 +984,13 @@ nav.pagination {
|
|||||||
color: #000;
|
color: #000;
|
||||||
display: inline-block;
|
display: inline-block;
|
||||||
padding: 2px 5px;
|
padding: 2px 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.label {
|
||||||
|
background: #d40;
|
||||||
|
padding: 0.1em 0.2em;
|
||||||
|
border-radius: 0.2em;
|
||||||
|
color: #b20;
|
||||||
|
border: 1px solid #B20;
|
||||||
|
text-shadow: -1px -1px #e50, 1px 1px #a10;
|
||||||
}
|
}
|
||||||
@@ -3,6 +3,7 @@ class Forum < ActiveRecord::Base
|
|||||||
has_many :forumthreads
|
has_many :forumthreads
|
||||||
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
|
belongs_to :role_read, class_name: "Role", foreign_key: "role_read_id"
|
||||||
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
|
belongs_to :role_write, class_name: "Role", foreign_key: "role_write_id"
|
||||||
|
has_and_belongs_to_many :labels
|
||||||
|
|
||||||
def to_s
|
def to_s
|
||||||
name
|
name
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ class Forumthread < ActiveRecord::Base
|
|||||||
belongs_to :forum
|
belongs_to :forum
|
||||||
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
|
belongs_to :user_author, class_name: "User", foreign_key: "user_author_id"
|
||||||
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
|
belongs_to :user_editor, class_name: "User", foreign_key: "user_editor_id"
|
||||||
|
belongs_to :label
|
||||||
has_many :threadreplies
|
has_many :threadreplies
|
||||||
|
|
||||||
validates_presence_of :title, :author, :forum
|
validates_presence_of :title, :author, :forum
|
||||||
|
|||||||
11
app/models/label.rb
Normal file
11
app/models/label.rb
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
class Label < ActiveRecord::Base
|
||||||
|
validates_presence_of :name
|
||||||
|
belongs_to :role
|
||||||
|
has_and_belongs_to_many :forums
|
||||||
|
has_many :forumthreads
|
||||||
|
|
||||||
|
def to_s
|
||||||
|
name.upcase
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,5 +1,5 @@
|
|||||||
<%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → <%=truncate(@thread.title, length: 60, omission: " …") %>
|
<%= link_to @thread.forum.group, forumgroup_path(@thread.forum.group) %> → <%= link_to @thread.forum, @thread.forum %> → <%=truncate(@thread.title, length: 60, omission: " …") %>
|
||||||
<h1><%= title @thread.title %></h1>
|
<h1><%= render partial: "labels/label", locals: {label: @thread.label} %><%= title @thread.title %></h1>
|
||||||
|
|
||||||
<div class="item-group thread with-avatar" id="thread-<%= @thread.id %>">
|
<div class="item-group thread with-avatar" id="thread-<%= @thread.id %>">
|
||||||
<div class="header">
|
<div class="header">
|
||||||
|
|||||||
3
app/views/labels/_label.html.erb
Normal file
3
app/views/labels/_label.html.erb
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
<% if label %>
|
||||||
|
<span class="label label-<%= label.name.downcase %>"><%= label %></span>
|
||||||
|
<% end %>
|
||||||
15
db/migrate/20141120202853_add_labels.rb
Normal file
15
db/migrate/20141120202853_add_labels.rb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
class AddLabels < ActiveRecord::Migration
|
||||||
|
def change
|
||||||
|
create_table :labels do |t|
|
||||||
|
t.string :name
|
||||||
|
t.references :role
|
||||||
|
end
|
||||||
|
|
||||||
|
add_column :forumthreads, :label_id, :integer
|
||||||
|
|
||||||
|
create_table :forums_labels, id: false do |t|
|
||||||
|
t.references :forum
|
||||||
|
t.references :label
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
42
db/schema.rb
42
db/schema.rb
@@ -11,15 +11,15 @@
|
|||||||
#
|
#
|
||||||
# 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: 20140617183755) do
|
ActiveRecord::Schema.define(version: 20141120202853) do
|
||||||
|
|
||||||
create_table "blogposts", force: true do |t|
|
create_table "blogposts", force: true do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "content"
|
t.text "content"
|
||||||
t.integer "user_author_id"
|
t.integer "user_author_id"
|
||||||
t.integer "user_editor_id"
|
t.integer "user_editor_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "comments", force: true do |t|
|
create_table "comments", force: true do |t|
|
||||||
@@ -27,8 +27,8 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
t.integer "user_author_id"
|
t.integer "user_author_id"
|
||||||
t.integer "user_editor_id"
|
t.integer "user_editor_id"
|
||||||
t.integer "blogpost_id"
|
t.integer "blogpost_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "forumgroups", force: true do |t|
|
create_table "forumgroups", force: true do |t|
|
||||||
@@ -46,6 +46,11 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
t.integer "forumgroup_id"
|
t.integer "forumgroup_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
create_table "forums_labels", id: false, force: true do |t|
|
||||||
|
t.integer "forum_id"
|
||||||
|
t.integer "label_id"
|
||||||
|
end
|
||||||
|
|
||||||
create_table "forumthreads", force: true do |t|
|
create_table "forumthreads", force: true do |t|
|
||||||
t.string "title"
|
t.string "title"
|
||||||
t.text "content"
|
t.text "content"
|
||||||
@@ -54,8 +59,9 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
t.integer "user_author_id"
|
t.integer "user_author_id"
|
||||||
t.integer "user_editor_id"
|
t.integer "user_editor_id"
|
||||||
t.integer "forum_id"
|
t.integer "forum_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at"
|
||||||
|
t.integer "label_id"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "info", force: true do |t|
|
create_table "info", force: true do |t|
|
||||||
@@ -63,9 +69,15 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
t.text "content"
|
t.text "content"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "register_tokens", primary_key: "uuid", force: true do |t|
|
create_table "labels", force: true do |t|
|
||||||
t.string "token", limit: 6, null: false
|
t.string "name"
|
||||||
t.string "email", null: false
|
t.integer "role_id"
|
||||||
|
end
|
||||||
|
|
||||||
|
create_table "register_tokens", force: true do |t|
|
||||||
|
t.string "uuid", limit: 32, null: false
|
||||||
|
t.string "token", limit: 6, null: false
|
||||||
|
t.string "email", null: false
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "roles", force: true do |t|
|
create_table "roles", force: true do |t|
|
||||||
@@ -76,8 +88,8 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
create_table "sessions", force: true do |t|
|
create_table "sessions", force: true do |t|
|
||||||
t.string "session_id", null: false
|
t.string "session_id", null: false
|
||||||
t.text "data"
|
t.text "data"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
|
add_index "sessions", ["session_id"], name: "index_sessions_on_session_id", using: :btree
|
||||||
@@ -88,8 +100,8 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
t.integer "user_author_id"
|
t.integer "user_author_id"
|
||||||
t.integer "user_editor_id"
|
t.integer "user_editor_id"
|
||||||
t.integer "forumthread_id"
|
t.integer "forumthread_id"
|
||||||
t.datetime "created_at", null: false
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at", null: false
|
t.datetime "updated_at"
|
||||||
end
|
end
|
||||||
|
|
||||||
create_table "users", force: true do |t|
|
create_table "users", force: true do |t|
|
||||||
@@ -109,7 +121,7 @@ ActiveRecord::Schema.define(version: 20140617183755) do
|
|||||||
t.string "email_token"
|
t.string "email_token"
|
||||||
t.boolean "confirmed", default: false
|
t.boolean "confirmed", default: false
|
||||||
t.datetime "last_seen"
|
t.datetime "last_seen"
|
||||||
t.integer "role_id", default: 3, null: false
|
t.integer "role_id", null: false
|
||||||
t.datetime "created_at"
|
t.datetime "created_at"
|
||||||
t.datetime "updated_at"
|
t.datetime "updated_at"
|
||||||
t.boolean "mail_own_thread_reply", default: true
|
t.boolean "mail_own_thread_reply", default: true
|
||||||
|
|||||||
Reference in New Issue
Block a user