Description:
merge
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r840:b948bb241476 - - 9 files changed: 113 inserted, 49 deleted
@@ -0,0 +1,25 | |||
|
1 | + = simple_form_for(@announcement) do |f| | |
|
2 | + - if @announcement.errors.any? | |
|
3 | + .form-row | |
|
4 | + .col-sm-12 | |
|
5 | + #error_explanation.alert.alert-dismissable.alert-danger | |
|
6 | + %button.close{type: "button", data: { dismiss: "alert"}, aria: {hidden: "true"}} × | |
|
7 | + %h3= "เกิดปัญหาในการบันทึกข้อมูลเนื่องจาก" | |
|
8 | + %ul | |
|
9 | + - @announcement.errors.full_messages.each do |message| | |
|
10 | + %li= message | |
|
11 | + .form-row | |
|
12 | + .col-md-6.col-12 | |
|
13 | + -# = f.input :lock_version, as: :hidden | |
|
14 | + = f.input :title | |
|
15 | + = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' | |
|
16 | + = f.input :body | |
|
17 | + = f.input :author | |
|
18 | + = f.input :published | |
|
19 | + = f.input :frontpage, label: 'Display in the front page only?' | |
|
20 | + = f.input :on_nav_bar, label: 'Show on menu bar?', wrapper: :custom_boolean | |
|
21 | + = f.input :contest_only, label: 'Display in contest only?' | |
|
22 | + = f.submit "Create", class: 'btn btn-primary' | |
|
23 | + -if content_for?(:form_buttons) | |
|
24 | + = yield(:form_buttons) | |
|
25 | + / = link_to 'Back', announcements_path, class: 'btn btn-default' |
@@ -0,0 +1,5 | |||
|
1 | + class AddOnNavBarToAnnouncement < ActiveRecord::Migration[5.2] | |
|
2 | + def change | |
|
3 | + add_column :announcements, :on_nav_bar, :boolean, default: false | |
|
4 | + end | |
|
5 | + end |
@@ -90,27 +90,27 | |||
|
90 | 90 | def toggle_front |
|
91 | 91 | @announcement = Announcement.find(params[:id]) |
|
92 | 92 | @announcement.update_attributes( frontpage: !@announcement.frontpage? ) |
|
93 | 93 | respond_to do |format| |
|
94 | 94 | format.js { render partial: 'toggle_button', |
|
95 | 95 | locals: {button_id: "#announcement_toggle_front_#{@announcement.id}",button_on: @announcement.frontpage? } } |
|
96 | 96 | end |
|
97 | 97 | end |
|
98 | 98 | |
|
99 | 99 | # DELETE /announcements/1 |
|
100 | 100 | # DELETE /announcements/1.xml |
|
101 | 101 | def destroy |
|
102 | 102 | @announcement = Announcement.find(params[:id]) |
|
103 | 103 | @announcement.destroy |
|
104 | 104 | |
|
105 | 105 | respond_to do |format| |
|
106 | 106 | format.html { redirect_to(announcements_url) } |
|
107 | 107 | format.xml { head :ok } |
|
108 | 108 | end |
|
109 | 109 | end |
|
110 | 110 | |
|
111 | 111 | private |
|
112 | 112 | |
|
113 | 113 | def announcement_params |
|
114 | - params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only, :title) | |
|
114 | + params.require(:announcement).permit(:author, :body, :published, :frontpage, :contest_only, :title, :on_nav_bar) | |
|
115 | 115 | end |
|
116 | 116 | end |
@@ -1,48 +1,53 | |||
|
1 | 1 | require 'ipaddr' |
|
2 | 2 | |
|
3 | 3 | class ApplicationController < ActionController::Base |
|
4 | 4 | protect_from_forgery |
|
5 | 5 | |
|
6 | 6 | before_action :current_user |
|
7 | + before_action :nav_announcement | |
|
7 | 8 | |
|
8 | 9 | SINGLE_USER_MODE_CONF_KEY = 'system.single_user_mode' |
|
9 | 10 | MULTIPLE_IP_LOGIN_CONF_KEY = 'right.multiple_ip_login' |
|
10 | 11 | WHITELIST_IGNORE_CONF_KEY = 'right.whitelist_ignore' |
|
11 | 12 | WHITELIST_IP_CONF_KEY = 'right.whitelist_ip' |
|
12 | 13 | |
|
13 | 14 | #report and redirect for unauthorized activities |
|
14 | 15 | def unauthorized_redirect(notice = 'You are not authorized to view the page you requested') |
|
15 | 16 | flash[:notice] = notice |
|
16 | 17 | redirect_to login_main_path |
|
17 | 18 | end |
|
18 | 19 | |
|
19 | 20 | # Returns the current logged-in user (if any). |
|
20 | 21 | def current_user |
|
21 | 22 | return nil unless session[:user_id] |
|
22 | 23 | @current_user ||= User.find(session[:user_id]) |
|
23 | 24 | end |
|
24 | 25 | |
|
26 | + def nav_announcement | |
|
27 | + @nav_announcement = Announcement.where(on_nav_bar: true) | |
|
28 | + end | |
|
29 | + | |
|
25 | 30 | def admin_authorization |
|
26 | 31 | return false unless check_valid_login |
|
27 | 32 | user = User.includes(:roles).find(session[:user_id]) |
|
28 | 33 | unless user.admin? |
|
29 | 34 | unauthorized_redirect |
|
30 | 35 | return false |
|
31 | 36 | end |
|
32 | 37 | return true |
|
33 | 38 | end |
|
34 | 39 | |
|
35 | 40 | def authorization_by_roles(allowed_roles) |
|
36 | 41 | return false unless check_valid_login |
|
37 | 42 | unless @current_user.roles.detect { |role| allowed_roles.member?(role.name) } |
|
38 | 43 | unauthorized_redirect |
|
39 | 44 | return false |
|
40 | 45 | end |
|
41 | 46 | end |
|
42 | 47 | |
|
43 | 48 | def testcase_authorization |
|
44 | 49 | #admin always has privileged |
|
45 | 50 | if @current_user.admin? |
|
46 | 51 | return true |
|
47 | 52 | end |
|
48 | 53 |
@@ -1,34 +1,45 | |||
|
1 | - .container-fluid | |
|
2 | - %h1 Editing announcement | |
|
3 | - = error_messages_for :announcement | |
|
4 | - .row | |
|
5 | - .col-md-6 | |
|
6 | - = form_for(@announcement) do |f| | |
|
7 | - .form-group | |
|
8 | - %label Title | |
|
9 | - = f.text_field :title, class: 'form-control' | |
|
10 | - .form-group | |
|
11 | - %label Notes | |
|
12 | - (shown internally, used to organize announcements) | |
|
13 | - = f.text_field :notes, class: 'form-control' | |
|
14 | - .form-group | |
|
15 |
- %label |
|
|
16 |
- = f.text_ |
|
|
17 | - .form-group | |
|
18 |
- %label |
|
|
19 | - = f.text_field :author, class: 'form-control' | |
|
20 | - .checkbox | |
|
21 | - %label | |
|
22 | - = f.check_box :published | |
|
23 | - Published | |
|
24 | - .checkbox | |
|
25 | - %label | |
|
26 | - = f.check_box :frontpage | |
|
27 | - Show on front page? | |
|
28 | - .checkbox | |
|
29 | - %label | |
|
30 | - = f.check_box :contest_only | |
|
31 | - Show only in contest? | |
|
32 | - = f.submit "Update", class: 'btn btn-primary' | |
|
33 | - = link_to 'Show', @announcement, class: 'btn btn-default' | |
|
34 | - = link_to 'Back', announcements_path, class: 'btn btn-default' | |
|
1 | + %h1 Edit Announcement | |
|
2 | + | |
|
3 | + -content_for(:form_buttons) do | |
|
4 | + = link_to t(:back), announcements_path, class: 'card-link btn btn-secondary' | |
|
5 | + | |
|
6 | + = render 'form' | |
|
7 | + -# old style | |
|
8 | + .container-fluid | |
|
9 | + %h1 Editing announcement | |
|
10 | + = error_messages_for :announcement | |
|
11 | + .row | |
|
12 | + .col-md-6 | |
|
13 | + = form_for(@announcement) do |f| | |
|
14 | + .form-group | |
|
15 | + %label Title | |
|
16 | + = f.text_field :title, class: 'form-control' | |
|
17 | + .form-group | |
|
18 | + %label Notes | |
|
19 | + (shown internally, used to organize announcements) | |
|
20 | + = f.text_field :notes, class: 'form-control' | |
|
21 | + .form-group | |
|
22 | + %label Body | |
|
23 | + = f.text_area :body, class: 'form-control', style: 'height: 200px;' | |
|
24 | + .form-group | |
|
25 | + %label Author | |
|
26 | + = f.text_field :author, class: 'form-control' | |
|
27 | + .checkbox | |
|
28 | + %label | |
|
29 | + = f.check_box :published | |
|
30 | + Published | |
|
31 | + .checkbox | |
|
32 | + %label | |
|
33 | + = f.check_box :frontpage | |
|
34 | + Show on front page? | |
|
35 | + .checkbox | |
|
36 | + %label | |
|
37 | + = f.check_box :on_nav_bar | |
|
38 | + Show on top menu bar? | |
|
39 | + .checkbox | |
|
40 | + %label | |
|
41 | + = f.check_box :contest_only | |
|
42 | + Show only in contest? | |
|
43 | + = f.submit "Update", class: 'btn btn-primary' | |
|
44 | + = link_to 'Show', @announcement, class: 'btn btn-default' | |
|
45 | + = link_to 'Back', announcements_path, class: 'btn btn-default' |
@@ -1,14 +1,22 | |||
|
1 | 1 | %h1 New announcement |
|
2 | - = error_messages_for :announcement | |
|
3 | - = simple_form_for(@announcement) do |f| | |
|
4 | - .row | |
|
5 | - .col-md-6 | |
|
6 | - = f.input :title | |
|
7 | - = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' | |
|
8 | - = f.input :body | |
|
9 | - = f.input :author | |
|
10 | - = f.input :published | |
|
11 | - = f.input :frontpage, label: 'Display in the front page only?' | |
|
12 | - = f.input :contest_only, label: 'Display in contest only?' | |
|
13 | - = f.button :submit, "Create", class: 'btn btn-primary' | |
|
14 | - = link_to 'Back', announcements_path, class: 'btn btn-default' | |
|
2 | + | |
|
3 | + -content_for(:form_buttons) do | |
|
4 | + = link_to t(:back), announcements_path, class: 'card-link btn btn-secondary' | |
|
5 | + | |
|
6 | + = render 'form' | |
|
7 | + | |
|
8 | + -# old style | |
|
9 | + = error_messages_for :announcement | |
|
10 | + = simple_form_for(@announcement) do |f| | |
|
11 | + .row | |
|
12 | + .col-md-6 | |
|
13 | + = f.input :title | |
|
14 | + = f.input :notes, label: 'Notes (shown internally, used to organize announcements)' | |
|
15 | + = f.input :body | |
|
16 | + = f.input :author | |
|
17 | + = f.input :published | |
|
18 | + = f.input :frontpage, label: 'Display in the front page only?' | |
|
19 | + = f.input :contest_only, label: 'Display in contest only?' | |
|
20 | + = f.button :submit, "Create", class: 'btn btn-primary' | |
|
21 | + = link_to 'Back', announcements_path, class: 'btn btn-default' | |
|
22 | + |
@@ -1,24 +1,27 | |||
|
1 | 1 | %p |
|
2 | 2 | %b Author: |
|
3 | 3 | = h @announcement.author |
|
4 | 4 | %p |
|
5 | 5 | %b Title: |
|
6 | 6 | = h @announcement.title |
|
7 | 7 | %p |
|
8 | 8 | %b Notes: |
|
9 | 9 | = h @announcement.notes |
|
10 | 10 | %p |
|
11 | 11 | %b Body: |
|
12 | 12 | = h markdown(@announcement.body) |
|
13 | 13 | %p |
|
14 | 14 | %b Published: |
|
15 | 15 | = h @announcement.published |
|
16 | 16 | %p |
|
17 | 17 | %b Show on front page: |
|
18 | 18 | = h @announcement.frontpage |
|
19 | 19 | %p |
|
20 | + %b Show on top menu bar: | |
|
21 | + = h @announcement.on_nav_bar | |
|
22 | + %p | |
|
20 | 23 | %b Show only in contest: |
|
21 | 24 | = h @announcement.contest_only |
|
22 | 25 | = link_to 'Edit', edit_announcement_path(@announcement) |
|
23 | 26 | | |
|
24 | 27 | = link_to 'Back', announcements_path |
@@ -49,48 +49,54 | |||
|
49 | 49 | = add_menu( 'Tags', 'tags', 'index') |
|
50 | 50 | = add_menu( 'Users', 'user_admin', 'index') |
|
51 | 51 | = add_menu( 'User Groups', 'groups', 'index') |
|
52 | 52 | = add_menu( 'Graders', 'graders', 'list') |
|
53 | 53 | = add_menu( 'Message ', 'messages', 'console') |
|
54 | 54 | %li.divider{role: 'separator'} |
|
55 | 55 | = add_menu( 'System config', 'configurations', 'index') |
|
56 | 56 | %li.divider{role: 'separator'} |
|
57 | 57 | = add_menu( 'Sites', 'sites', 'index') |
|
58 | 58 | = add_menu( 'Contests', 'contest_management', 'index') |
|
59 | 59 | / report |
|
60 | 60 | %li.dropdown |
|
61 | 61 | %a.dropdown-toggle{href: '#', data: {toggle:'dropdown'}, aria: {haspopup:"true", expanded:"false"}, role: "button"} |
|
62 | 62 | Report |
|
63 | 63 | %span.caret |
|
64 | 64 | %ul.dropdown-menu |
|
65 | 65 | = add_menu( 'Current Score', 'report', 'current_score') |
|
66 | 66 | = add_menu( 'Score Report', 'report', 'max_score') |
|
67 | 67 | = add_menu( 'Submission Report', 'report', 'submission') |
|
68 | 68 | = add_menu( 'Login Report', 'report', 'login') |
|
69 | 69 | - if (ungraded = Submission.where('graded_at is null').where('submitted_at < ?', 1.minutes.ago).count) > 0 |
|
70 | 70 | =link_to "#{ungraded} backlogs!", |
|
71 | 71 | graders_list_path, |
|
72 | 72 | class: 'navbar-btn btn btn-default btn-warning', data: {toggle: 'tooltip'},title: 'Number of ungraded submission' |
|
73 | + / announcement | |
|
74 | + - @nav_announcement.each do |ann| | |
|
75 | + %p.navbar-text | |
|
76 | + = ann.body.html_safe | |
|
77 | + | |
|
78 | + | |
|
73 | 79 | |
|
74 | 80 | %ul.nav.navbar-nav.navbar-right |
|
75 | 81 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
76 | 82 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'index', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
77 | 83 | - if GraderConfiguration['system.user_setting_enabled'] |
|
78 | 84 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog', id: 'user_profile')}".html_safe, 'users', 'profile', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
79 | 85 | = add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{@current_user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
80 | 86 | |
|
81 | 87 | / |
|
82 | 88 | - if (@current_user!=nil) and (session[:admin]) |
|
83 | 89 | %nav.navbar.navbar-fixed-top.navbar-inverse.secondnavbar |
|
84 | 90 | .container-fluid |
|
85 | 91 | .collapse.navbar-collapse |
|
86 | 92 | %ul.nav.navbar-nav |
|
87 | 93 | = add_menu( '[Announcements]', 'announcements', 'index') |
|
88 | 94 | = add_menu( '[Msg console]', 'messages', 'console') |
|
89 | 95 | = add_menu( '[Problems]', 'problems', 'index') |
|
90 | 96 | = add_menu( '[Users]', 'user_admin', 'index') |
|
91 | 97 | = add_menu( '[Results]', 'user_admin', 'user_stat') |
|
92 | 98 | = add_menu( '[Report]', 'report', 'multiple_login') |
|
93 | 99 | = add_menu( '[Graders]', 'graders', 'list') |
|
94 | 100 | = add_menu( '[Contests]', 'contest_management', 'index') |
|
95 | 101 | = add_menu( '[Sites]', 'sites', 'index') |
|
96 | 102 | = add_menu( '[System config]', 'configurations', 'index') |
@@ -1,48 +1,49 | |||
|
1 | 1 | # This file is auto-generated from the current state of the database. Instead |
|
2 | 2 | # of editing this file, please use the migrations feature of Active Record to |
|
3 | 3 | # incrementally modify your database, and then regenerate this schema definition. |
|
4 | 4 | # |
|
5 | 5 | # Note that this schema.rb definition is the authoritative source for your |
|
6 | 6 | # database schema. If you need to create the application database on another |
|
7 | 7 | # system, you should be using db:schema:load, not running all the migrations |
|
8 | 8 | # from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
9 | 9 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
10 | 10 | # |
|
11 | 11 | # It's strongly recommended that you check this file into your version control system. |
|
12 | 12 | |
|
13 |
- ActiveRecord::Schema.define(version: 202 |
|
|
13 | + ActiveRecord::Schema.define(version: 2021_01_24_101028) do | |
|
14 | 14 | |
|
15 | 15 | create_table "announcements", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
16 | 16 | t.string "author" |
|
17 | 17 | t.text "body" |
|
18 | 18 | t.boolean "published" |
|
19 | 19 | t.datetime "created_at", null: false |
|
20 | 20 | t.datetime "updated_at", null: false |
|
21 | 21 | t.boolean "frontpage", default: false |
|
22 | 22 | t.boolean "contest_only", default: false |
|
23 | 23 | t.string "title" |
|
24 | 24 | t.string "notes" |
|
25 | + t.boolean "on_nav_bar", default: false | |
|
25 | 26 | end |
|
26 | 27 | |
|
27 | 28 | create_table "contests", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
28 | 29 | t.string "title" |
|
29 | 30 | t.boolean "enabled" |
|
30 | 31 | t.datetime "created_at", null: false |
|
31 | 32 | t.datetime "updated_at", null: false |
|
32 | 33 | t.string "name" |
|
33 | 34 | end |
|
34 | 35 | |
|
35 | 36 | create_table "contests_problems", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
36 | 37 | t.integer "contest_id" |
|
37 | 38 | t.integer "problem_id" |
|
38 | 39 | end |
|
39 | 40 | |
|
40 | 41 | create_table "contests_users", id: false, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
41 | 42 | t.integer "contest_id" |
|
42 | 43 | t.integer "user_id" |
|
43 | 44 | end |
|
44 | 45 | |
|
45 | 46 | create_table "countries", id: :integer, options: "ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci", force: :cascade do |t| |
|
46 | 47 | t.string "name" |
|
47 | 48 | t.datetime "created_at", null: false |
|
48 | 49 | t.datetime "updated_at", null: false |
You need to be logged in to leave comments.
Login now