# HG changeset patch # User Nattee Niparnan # Date 2021-01-24 10:54:40 # Node ID b80b4e632bb0cd6599aaaa9a472164994fca3074 # Parent 30dd5b343f6bc85321ee40275bc7e34e6fe476b2 announcement on top menu bar diff --git a/app/controllers/announcements_controller.rb b/app/controllers/announcements_controller.rb --- a/app/controllers/announcements_controller.rb +++ b/app/controllers/announcements_controller.rb @@ -111,6 +111,6 @@ private def announcement_params - params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only, :title) + params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only, :title, :on_nav_bar) end end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -4,6 +4,7 @@ protect_from_forgery before_action :current_user + before_action :nav_announcement SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' @@ -22,6 +23,10 @@ @current_user ||= User.find(session[:user_id]) end + def nav_announcement + @nav_announcement = Announcement.where(on_nav_bar: true) + end + def admin_authorization return false unless check_valid_login user = User.includes(:roles).find(session[:user_id]) diff --git a/app/views/announcements/_form.html.haml b/app/views/announcements/_form.html.haml new file mode 100644 --- /dev/null +++ b/app/views/announcements/_form.html.haml @@ -0,0 +1,25 @@ += simple_form_for(@announcement) do |f| + - if @announcement.errors.any? + .form-row + .col-sm-12 + #error_explanation.alert.alert-dismissable.alert-danger + %button.close{type: "button", data: { dismiss: "alert"}, aria: {hidden: "true"}} × + %h3= "เกิดปัญหาในการบันทึกข้อมูลเนื่องจาก" + %ul + - @announcement.errors.full_messages.each do |message| + %li= message + .form-row + .col-md-6.col-12 + -# = f.input :lock_version, as: :hidden + = f.input :title + = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' + = f.input :body + = f.input :author + = f.input :published + = f.input :frontpage, label: 'Display in the front page only?' + = f.input :on_nav_bar, label: 'Show on menu bar?', wrapper: :custom_boolean + = f.input :contest_only, label: 'Display in contest only?' + = f.submit "Create", class: 'btn btn-primary' + -if content_for?(:form_buttons) + = yield(:form_buttons) + / = link_to 'Back', announcements_path, class: 'btn btn-default' diff --git a/app/views/announcements/edit.html.haml b/app/views/announcements/edit.html.haml --- a/app/views/announcements/edit.html.haml +++ b/app/views/announcements/edit.html.haml @@ -1,34 +1,45 @@ -.container-fluid - %h1 Editing announcement - = error_messages_for :announcement - .row - .col-md-6 - = form_for(@announcement) do |f| - .form-group - %label Title - = f.text_field :title, class: 'form-control' - .form-group - %label Notes - (shown internally, used to organize announcements) - = f.text_field :notes, class: 'form-control' - .form-group - %label Body - = f.text_area :body, class: 'form-control', style: 'height: 200px;' - .form-group - %label Author - = f.text_field :author, class: 'form-control' - .checkbox - %label - = f.check_box :published - Published - .checkbox - %label - = f.check_box :frontpage - Show on front page? - .checkbox - %label - = f.check_box :contest_only - Show only in contest? - = f.submit "Update", class: 'btn btn-primary' - = link_to 'Show', @announcement, class: 'btn btn-default' - = link_to 'Back', announcements_path, class: 'btn btn-default' +%h1 Edit Announcement + +-content_for(:form_buttons) do + = link_to t(:back), announcements_path, class: 'card-link btn btn-secondary' + += render 'form' +-# old style + .container-fluid + %h1 Editing announcement + = error_messages_for :announcement + .row + .col-md-6 + = form_for(@announcement) do |f| + .form-group + %label Title + = f.text_field :title, class: 'form-control' + .form-group + %label Notes + (shown internally, used to organize announcements) + = f.text_field :notes, class: 'form-control' + .form-group + %label Body + = f.text_area :body, class: 'form-control', style: 'height: 200px;' + .form-group + %label Author + = f.text_field :author, class: 'form-control' + .checkbox + %label + = f.check_box :published + Published + .checkbox + %label + = f.check_box :frontpage + Show on front page? + .checkbox + %label + = f.check_box :on_nav_bar + Show on top menu bar? + .checkbox + %label + = f.check_box :contest_only + Show only in contest? + = f.submit "Update", class: 'btn btn-primary' + = link_to 'Show', @announcement, class: 'btn btn-default' + = link_to 'Back', announcements_path, class: 'btn btn-default' diff --git a/app/views/announcements/new.html.haml b/app/views/announcements/new.html.haml --- a/app/views/announcements/new.html.haml +++ b/app/views/announcements/new.html.haml @@ -1,14 +1,22 @@ %h1 New announcement -= error_messages_for :announcement -= simple_form_for(@announcement) do |f| - .row - .col-md-6 - = f.input :title - = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' - = f.input :body - = f.input :author - = f.input :published - = f.input :frontpage, label: 'Display in the front page only?' - = f.input :contest_only, label: 'Display in contest only?' - = f.button :submit, "Create", class: 'btn btn-primary' - = link_to 'Back', announcements_path, class: 'btn btn-default' + +-content_for(:form_buttons) do + = link_to t(:back), announcements_path, class: 'card-link btn btn-secondary' + += render 'form' + +-# old style + = error_messages_for :announcement + = simple_form_for(@announcement) do |f| + .row + .col-md-6 + = f.input :title + = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' + = f.input :body + = f.input :author + = f.input :published + = f.input :frontpage, label: 'Display in the front page only?' + = f.input :contest_only, label: 'Display in contest only?' + = f.button :submit, "Create", class: 'btn btn-primary' + = link_to 'Back', announcements_path, class: 'btn btn-default' + diff --git a/app/views/announcements/show.html.haml b/app/views/announcements/show.html.haml --- a/app/views/announcements/show.html.haml +++ b/app/views/announcements/show.html.haml @@ -17,6 +17,9 @@ %b Show on front page: = h @announcement.frontpage %p + %b Show on top menu bar: + = h @announcement.on_nav_bar +%p %b Show only in contest: = h @announcement.contest_only = link_to 'Edit', edit_announcement_path(@announcement) diff --git a/app/views/layouts/_header.html.haml b/app/views/layouts/_header.html.haml --- a/app/views/layouts/_header.html.haml +++ b/app/views/layouts/_header.html.haml @@ -70,6 +70,12 @@ =link_to "#{ungraded} backlogs!", graders_list_path, class: 'navbar-btn btn btn-default btn-warning', data: {toggle: 'tooltip'},title: 'Number of ungraded submission' + / announcement + - @nav_announcement.each do |ann| + %p.navbar-text + = ann.body.html_safe + + %ul.nav.navbar-nav.navbar-right = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') diff --git a/db/migrate/20210124101028_add_on_nav_bar_to_announcement.rb b/db/migrate/20210124101028_add_on_nav_bar_to_announcement.rb new file mode 100644 --- /dev/null +++ b/db/migrate/20210124101028_add_on_nav_bar_to_announcement.rb @@ -0,0 +1,5 @@ +class AddOnNavBarToAnnouncement < ActiveRecord::Migration[5.2] + def change + add_column :announcements, :on_nav_bar, :boolean, default: false + end +end diff --git a/db/schema.rb b/db/schema.rb --- a/db/schema.rb +++ b/db/schema.rb @@ -10,71 +10,72 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2020_08_13_083020) do +ActiveRecord::Schema.define(version: 2021_01_24_101028) do - create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "author" t.text "body" t.boolean "published" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "frontpage", default: false t.boolean "contest_only", default: false t.string "title" t.string "notes" + t.boolean "on_nav_bar", default: false end - create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "title" t.boolean "enabled" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "name" end - create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "contest_id" t.integer "problem_id" end - create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "contest_id" t.integer "user_id" end - create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "name" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "descriptions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.text "body" t.boolean "markdowned" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "grader_configurations", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "key" t.string "value_type" t.string "value" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.text "description" end - create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "grader_processes", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "host" t.integer "pid" t.string "mode" t.boolean "active" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "task_id" t.string "task_type" t.boolean "terminated" - t.index ["host", "pid"], name: "index_grader_processes_on_host_and_pid" + t.index ["host", "pid"], name: "index_grader_processes_on_ip_and_pid" end create_table "groups", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| @@ -95,41 +96,41 @@ t.index ["user_id", "group_id"], name: "index_groups_users_on_user_id_and_group_id" end - create_table "heart_beats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "heart_beats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "user_id" t.string "ip_address" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.string "status" t.index ["updated_at"], name: "index_heart_beats_on_updated_at" end - create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "languages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "name", limit: 10 t.string "pretty_name" t.string "ext", limit: 10 t.string "common_ext" end - create_table "logins", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "logins", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "user_id" t.string "ip_address" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.index ["user_id"], name: "index_logins_on_user_id" end - create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "messages", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "sender_id" t.integer "receiver_id" t.integer "replying_message_id" t.text "body" t.boolean "replied" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "problems", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "name", limit: 30 t.string "full_name" t.integer "full_score" @@ -151,29 +152,29 @@ t.index ["tag_id"], name: "index_problems_tags_on_tag_id" end - create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "rights", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "name" t.string "controller" t.string "action" end - create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "rights_roles", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "right_id" t.integer "role_id" t.index ["role_id"], name: "index_rights_roles_on_role_id" end - create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "roles", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "name" end - create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "roles_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "role_id" t.integer "user_id" t.index ["user_id"], name: "index_roles_users_on_user_id" end - create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "sessions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "session_id" t.text "data" t.datetime "updated_at" @@ -181,24 +182,24 @@ t.index ["updated_at"], name: "index_sessions_on_updated_at" end - create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "sites", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "name" t.boolean "started" t.datetime "start_time" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.integer "country_id" t.string "password" end - create_table "submission_view_logs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "submission_view_logs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "user_id" t.integer "submission_id" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "submissions", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "user_id" t.integer "problem_id" t.integer "language_id" @@ -229,7 +230,7 @@ t.datetime "updated_at", null: false end - create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "tasks", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "submission_id" t.datetime "created_at" t.integer "status" @@ -237,15 +238,15 @@ t.index ["submission_id"], name: "index_tasks_on_submission_id" end - create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "test_pairs", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "problem_id" t.text "input", limit: 16777215 t.text "solution", limit: 16777215 - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false end - create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "test_requests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "user_id" t.integer "problem_id" t.integer "submission_id" @@ -253,13 +254,13 @@ t.string "output_file_name" t.string "running_stat" t.integer "status" - t.datetime "updated_at" + t.datetime "updated_at", null: false t.datetime "submitted_at" t.datetime "compiled_at" t.text "compiler_message" t.datetime "graded_at" t.string "grader_comment" - t.datetime "created_at" + t.datetime "created_at", null: false t.float "running_time" t.string "exit_status" t.integer "memory_usage" @@ -278,15 +279,15 @@ t.index ["problem_id"], name: "index_testcases_on_problem_id" end - create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "user_contest_stats", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.integer "user_id" t.datetime "started_at" - t.datetime "created_at" - t.datetime "updated_at" + t.datetime "created_at", null: false + t.datetime "updated_at", null: false t.boolean "forced_logout" end - create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=latin1", force: :cascade do |t| + create_table "users", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| t.string "login", limit: 50 t.string "full_name" t.string "hashed_password" @@ -298,10 +299,10 @@ t.boolean "activated", default: false t.datetime "created_at" t.datetime "updated_at" - t.string "section" t.boolean "enabled", default: true t.string "remark" t.string "last_ip" + t.string "section" t.index ["login"], name: "index_users_on_login", unique: true end