From 2c02a797b816f09460b5b3e49fb3466461ca6f6c Mon Sep 17 00:00:00 2001 From: MrYummy Date: Sun, 28 May 2017 17:40:50 -0400 Subject: Added Necropost Warning --- app/controllers/forumgroups_controller.rb | 2 +- app/controllers/forums_controller.rb | 4 +- app/views/forums/edit.html.erb | 6 ++- app/views/forums/new.html.erb | 6 ++- app/views/threadreplies/_new.html.erb | 17 ++++++++- .../20170409135858_add_necro_length_to_forums.rb | 5 +++ db/schema.rb | 43 +++++++++++----------- 7 files changed, 55 insertions(+), 28 deletions(-) create mode 100644 db/migrate/20170409135858_add_necro_length_to_forums.rb diff --git a/app/controllers/forumgroups_controller.rb b/app/controllers/forumgroups_controller.rb index a7b31ab..fe359af 100644 --- a/app/controllers/forumgroups_controller.rb +++ b/app/controllers/forumgroups_controller.rb @@ -77,4 +77,4 @@ class ForumgroupsController < ApplicationController params.require(:forumgroup).permit(a) end -end \ No newline at end of file +end diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index ecf570e..486d21c 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -89,7 +89,7 @@ class ForumsController < ApplicationController end def forum_params(add = []) - a = [:name, :position, :role_read_id, :role_write_id] + add + a = [:name, :position, :role_read_id, :role_write_id, :necro_length] + add params.require(:forum).permit(a) end -end \ No newline at end of file +end diff --git a/app/views/forums/edit.html.erb b/app/views/forums/edit.html.erb index 60b3fb1..571b3b7 100644 --- a/app/views/forums/edit.html.erb +++ b/app/views/forums/edit.html.erb @@ -21,8 +21,12 @@ <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + <%= f.label :necro_length, "Necropost warning delay (in days)" %> + <%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %> +

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

<% end %>

<%= button_to "Delete forum", @forum, method: "delete", data: {confirm: "Delete forum forever?\nThreads won't be accessible!"}, class: "btn red right" %>

-
\ No newline at end of file +
diff --git a/app/views/forums/new.html.erb b/app/views/forums/new.html.erb index f60e2b3..836a9b2 100644 --- a/app/views/forums/new.html.erb +++ b/app/views/forums/new.html.erb @@ -21,8 +21,12 @@ <%= f.label :role_write_id, "Min. write role" %> <%= f.select :role_write_id, role_selection, include_blank: false %> + + <%= f.label :necro_length, "Necropost warning delay (in days)" %> + <%= f.number_field :necro_length, placeholder: "Warning Delay (leave blank for no warning)" %> + <%= f.hidden_field :forumgroup_id %>

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

-<% end %> \ No newline at end of file +<% end %> diff --git a/app/views/threadreplies/_new.html.erb b/app/views/threadreplies/_new.html.erb index b0c4b5e..9d716d8 100644 --- a/app/views/threadreplies/_new.html.erb +++ b/app/views/threadreplies/_new.html.erb @@ -1,4 +1,17 @@ <%= form_for [reply.thread, reply] do |f| %> <%= render partial: "md_editor", locals: {name: "threadreply[content]", content: reply.content} %> -

<%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue" %>

-<% end %> \ No newline at end of file + <% nec_msg = "" %> + <% forum = Forum.find(reply.thread.forum_id) %> + <% if forum.necro_length != nil %> + <% if Threadreply.where(forumthread: reply.thread).count != 0 %> + <% prevAgo = Threadreply.where(forumthread: reply.thread).order(:id).last.created_at %> + <% if prevAgo <= forum.necro_length.days.ago.utc %> + <% nec_msg = "You may be necroposting, as the last reply was made at least #{forum.necro_length} days ago. If you still wish to make this reply, press 'Ok'." %> + <% end %> + <% elsif reply.thread.created_at <= forum.necro_length.days.ago.utc %> + <% nec_msg = "You may be necroposting, as this thread was posted at least #{forum.necro_length} days ago. If you still wish to make this reply, press 'Ok'." %> + <% end %> + <% end %> +

<%= f.submit "Reply#{ ' (Locked)' if reply.thread.locked? }", class: "btn blue", data: { confirm: nec_msg } %>

+ <% nec_msg = "" %> +<% end %> diff --git a/db/migrate/20170409135858_add_necro_length_to_forums.rb b/db/migrate/20170409135858_add_necro_length_to_forums.rb new file mode 100644 index 0000000..53199e4 --- /dev/null +++ b/db/migrate/20170409135858_add_necro_length_to_forums.rb @@ -0,0 +1,5 @@ +class AddNecroLengthToForums < ActiveRecord::Migration + def change + add_column :forums, :necro_length, :integer + end +end diff --git a/db/schema.rb b/db/schema.rb index b38ae38..353c482 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,10 +11,10 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20170319193517) do +ActiveRecord::Schema.define(version: 20170409135858) do create_table "blogposts", force: :cascade do |t| - t.string "title" + t.string "title", limit: 191 t.text "content", limit: 65535 t.integer "user_author_id", limit: 4 t.integer "user_editor_id", limit: 4 @@ -32,18 +32,19 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "forumgroups", force: :cascade do |t| - t.string "name" + t.string "name", limit: 191 t.integer "position", limit: 4 t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 end create_table "forums", force: :cascade do |t| - t.string "name" + t.string "name", limit: 191 t.integer "position", limit: 4 t.integer "role_read_id", limit: 4 t.integer "role_write_id", limit: 4 t.integer "forumgroup_id", limit: 4 + t.integer "necro_length", limit: 4, default: -1 end create_table "forums_labels", id: false, force: :cascade do |t| @@ -52,7 +53,7 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "forumthreads", force: :cascade do |t| - t.string "title" + t.string "title", limit: 191 t.text "content", limit: 65535 t.boolean "sticky", default: false t.boolean "locked", default: false @@ -65,29 +66,29 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "info", force: :cascade do |t| - t.string "title" + t.string "title", limit: 191 t.text "content", limit: 65535 t.datetime "created_at" t.datetime "updated_at" end create_table "labels", force: :cascade do |t| - t.string "name" - t.string "color" + t.string "name", limit: 191 + t.string "color", limit: 191 end create_table "register_tokens", force: :cascade do |t| - t.string "uuid", null: false - t.string "token", null: false - t.string "email", null: false + t.string "uuid", limit: 191, null: false + t.string "token", limit: 191, null: false + t.string "email", limit: 191, null: false end add_index "register_tokens", ["uuid"], name: "index_register_tokens_on_uuid", unique: true, using: :btree create_table "roles", force: :cascade do |t| - t.string "name" + t.string "name", limit: 191 t.integer "value", limit: 4 - t.string "color" + t.string "color", limit: 191 end create_table "badges", force: :cascade do |t| @@ -97,7 +98,7 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "sessions", force: :cascade do |t| - t.string "session_id", null: false + t.string "session_id", limit: 191, null: false t.text "data", limit: 65535 t.datetime "created_at" t.datetime "updated_at" @@ -116,14 +117,14 @@ ActiveRecord::Schema.define(version: 20170319193517) do end create_table "users", force: :cascade do |t| - t.string "uuid", null: false - t.string "name", null: false - t.string "password_digest", null: false - t.string "ign", null: false - t.string "email", null: false + t.string "uuid", limit: 191, null: false + t.string "name", limit: 191, null: false + t.string "password_digest", limit: 191, null: false + t.string "ign", limit: 191, null: false + t.string "email", limit: 191, null: false t.text "about", limit: 65535 - t.string "last_ip" - t.string "skype" + t.string "last_ip", limit: 191 + t.string "skype", limit: 191 t.boolean "skype_public", default: false t.string "youtube" t.string "youtube_channelname" -- cgit v1.2.3