Description:
* add button size option to toggle_button helper
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r563:589243c81dda - - 2 files changed: 4 inserted, 3 deleted
@@ -14,164 +14,165 | |||||
|
14 |
|
14 | ||
|
15 | if GraderConfiguration['right.user_hall_of_fame'] |
|
15 | if GraderConfiguration['right.user_hall_of_fame'] |
|
16 | left_menu << add_menu("#{I18n.t 'menu.hall_of_fame'}", 'report', 'problem_hof') |
|
16 | left_menu << add_menu("#{I18n.t 'menu.hall_of_fame'}", 'report', 'problem_hof') |
|
17 | end |
|
17 | end |
|
18 |
|
18 | ||
|
19 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
19 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-question-sign')}".html_safe, 'main', 'help') |
|
20 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'list', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
20 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-comment')}".html_safe, 'messages', 'list', {title: I18n.t('menu.messages'), data: {toggle: 'tooltip'}}) |
|
21 | if GraderConfiguration['system.user_setting_enabled'] |
|
21 | if GraderConfiguration['system.user_setting_enabled'] |
|
22 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
22 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-cog')}".html_safe, 'users', 'index', {title: I18n.t('menu.settings'), data: {toggle: 'tooltip'}}) |
|
23 | end |
|
23 | end |
|
24 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
24 | right_menu << add_menu("#{content_tag(:span,'',class: 'glyphicon glyphicon-log-out')} #{user.full_name}".html_safe, 'main', 'login', {title: I18n.t('menu.log_out'), data: {toggle: 'tooltip'}}) |
|
25 |
|
25 | ||
|
26 |
|
26 | ||
|
27 | result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') |
|
27 | result = content_tag(:ul,left_menu.html_safe,class: 'nav navbar-nav') + content_tag(:ul,right_menu.html_safe,class: 'nav navbar-nav navbar-right') |
|
28 | end |
|
28 | end |
|
29 |
|
29 | ||
|
30 | def add_menu(title, controller, action,html_option = {}) |
|
30 | def add_menu(title, controller, action,html_option = {}) |
|
31 | link_option = {controller: controller, action: action} |
|
31 | link_option = {controller: controller, action: action} |
|
32 | html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) |
|
32 | html_option[:class] = (html_option[:class] || '') + " active" if current_page?(link_option) |
|
33 | content_tag(:li, link_to(title,link_option),html_option) |
|
33 | content_tag(:li, link_to(title,link_option),html_option) |
|
34 | end |
|
34 | end |
|
35 |
|
35 | ||
|
36 | def user_header |
|
36 | def user_header |
|
37 | menu_items = '' |
|
37 | menu_items = '' |
|
38 | user = User.find(session[:user_id]) |
|
38 | user = User.find(session[:user_id]) |
|
39 |
|
39 | ||
|
40 | if (user!=nil) and (session[:admin]) |
|
40 | if (user!=nil) and (session[:admin]) |
|
41 | # admin menu |
|
41 | # admin menu |
|
42 | menu_items << "<b>Administrative task:</b> " |
|
42 | menu_items << "<b>Administrative task:</b> " |
|
43 | append_to menu_items, '[Announcements]', 'announcements', 'index' |
|
43 | append_to menu_items, '[Announcements]', 'announcements', 'index' |
|
44 | append_to menu_items, '[Msg console]', 'messages', 'console' |
|
44 | append_to menu_items, '[Msg console]', 'messages', 'console' |
|
45 | append_to menu_items, '[Problems]', 'problems', 'index' |
|
45 | append_to menu_items, '[Problems]', 'problems', 'index' |
|
46 | append_to menu_items, '[Users]', 'user_admin', 'index' |
|
46 | append_to menu_items, '[Users]', 'user_admin', 'index' |
|
47 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' |
|
47 | append_to menu_items, '[Results]', 'user_admin', 'user_stat' |
|
48 | append_to menu_items, '[Report]', 'report', 'multiple_login' |
|
48 | append_to menu_items, '[Report]', 'report', 'multiple_login' |
|
49 | append_to menu_items, '[Graders]', 'graders', 'list' |
|
49 | append_to menu_items, '[Graders]', 'graders', 'list' |
|
50 | append_to menu_items, '[Contests]', 'contest_management', 'index' |
|
50 | append_to menu_items, '[Contests]', 'contest_management', 'index' |
|
51 | append_to menu_items, '[Sites]', 'sites', 'index' |
|
51 | append_to menu_items, '[Sites]', 'sites', 'index' |
|
52 | append_to menu_items, '[System config]', 'configurations', 'index' |
|
52 | append_to menu_items, '[System config]', 'configurations', 'index' |
|
53 | menu_items << "<br/>" |
|
53 | menu_items << "<br/>" |
|
54 | end |
|
54 | end |
|
55 |
|
55 | ||
|
56 | # main page |
|
56 | # main page |
|
57 | append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list' |
|
57 | append_to menu_items, "[#{I18n.t 'menu.main'}]", 'main', 'list' |
|
58 | append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list' |
|
58 | append_to menu_items, "[#{I18n.t 'menu.messages'}]", 'messages', 'list' |
|
59 |
|
59 | ||
|
60 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
60 | if (user!=nil) and (GraderConfiguration.show_tasks_to?(user)) |
|
61 | append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list' |
|
61 | append_to menu_items, "[#{I18n.t 'menu.tasks'}]", 'tasks', 'list' |
|
62 | append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission' |
|
62 | append_to menu_items, "[#{I18n.t 'menu.submissions'}]", 'main', 'submission' |
|
63 | append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' |
|
63 | append_to menu_items, "[#{I18n.t 'menu.test'}]", 'test', 'index' |
|
64 | end |
|
64 | end |
|
65 |
|
65 | ||
|
66 | if GraderConfiguration['right.user_hall_of_fame'] |
|
66 | if GraderConfiguration['right.user_hall_of_fame'] |
|
67 | append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' |
|
67 | append_to menu_items, "[#{I18n.t 'menu.hall_of_fame'}]", 'report', 'problem_hof' |
|
68 | end |
|
68 | end |
|
69 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' |
|
69 | append_to menu_items, "[#{I18n.t 'menu.help'}]", 'main', 'help' |
|
70 |
|
70 | ||
|
71 | if GraderConfiguration['system.user_setting_enabled'] |
|
71 | if GraderConfiguration['system.user_setting_enabled'] |
|
72 | append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index' |
|
72 | append_to menu_items, "[#{I18n.t 'menu.settings'}]", 'users', 'index' |
|
73 | end |
|
73 | end |
|
74 | append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login' |
|
74 | append_to menu_items, "[#{I18n.t 'menu.log_out'}]", 'main', 'login' |
|
75 |
|
75 | ||
|
76 | menu_items.html_safe |
|
76 | menu_items.html_safe |
|
77 | end |
|
77 | end |
|
78 |
|
78 | ||
|
79 | def append_to(option,label, controller, action) |
|
79 | def append_to(option,label, controller, action) |
|
80 | option << ' ' if option!='' |
|
80 | option << ' ' if option!='' |
|
81 | option << link_to_unless_current(label, |
|
81 | option << link_to_unless_current(label, |
|
82 | :controller => controller, |
|
82 | :controller => controller, |
|
83 | :action => action) |
|
83 | :action => action) |
|
84 | end |
|
84 | end |
|
85 |
|
85 | ||
|
86 | def format_short_time(time) |
|
86 | def format_short_time(time) |
|
87 | now = Time.now.gmtime |
|
87 | now = Time.now.gmtime |
|
88 | st = '' |
|
88 | st = '' |
|
89 | if (time.yday != now.yday) or |
|
89 | if (time.yday != now.yday) or |
|
90 | (time.year != now.year) |
|
90 | (time.year != now.year) |
|
91 | st = time.strftime("%x ") |
|
91 | st = time.strftime("%x ") |
|
92 | end |
|
92 | end |
|
93 | st + time.strftime("%X") |
|
93 | st + time.strftime("%X") |
|
94 | end |
|
94 | end |
|
95 |
|
95 | ||
|
96 | def format_short_duration(duration) |
|
96 | def format_short_duration(duration) |
|
97 | return '' if duration==nil |
|
97 | return '' if duration==nil |
|
98 | d = duration.to_f |
|
98 | d = duration.to_f |
|
99 | return Time.at(d).gmtime.strftime("%X") |
|
99 | return Time.at(d).gmtime.strftime("%X") |
|
100 | end |
|
100 | end |
|
101 |
|
101 | ||
|
102 | def read_textfile(fname,max_size=2048) |
|
102 | def read_textfile(fname,max_size=2048) |
|
103 | begin |
|
103 | begin |
|
104 | File.open(fname).read(max_size) |
|
104 | File.open(fname).read(max_size) |
|
105 | rescue |
|
105 | rescue |
|
106 | nil |
|
106 | nil |
|
107 | end |
|
107 | end |
|
108 | end |
|
108 | end |
|
109 |
|
109 | ||
|
110 | - def toggle_button(on,toggle_url,id) |
|
110 | + def toggle_button(on,toggle_url,id, option={}) |
|
|
111 | + btn_size = option[:size] || 'btn-xs' | ||
|
111 |
|
|
112 | link_to (on ? "Yes" : "No"), toggle_url, |
|
112 |
- |
|
113 | + {class: "btn btn-block #{btn_size} btn-#{on ? 'success' : 'default'} ajax-toggle", |
|
113 |
|
|
114 | id: id, |
|
114 |
|
|
115 | data: {remote: true, method: 'get'}} |
|
115 | end |
|
116 | end |
|
116 |
|
117 | ||
|
117 | def user_title_bar(user) |
|
118 | def user_title_bar(user) |
|
118 | header = '' |
|
119 | header = '' |
|
119 | time_left = '' |
|
120 | time_left = '' |
|
120 |
|
121 | ||
|
121 | # |
|
122 | # |
|
122 | # if the contest is over |
|
123 | # if the contest is over |
|
123 | if GraderConfiguration.time_limit_mode? |
|
124 | if GraderConfiguration.time_limit_mode? |
|
124 | if user.contest_finished? |
|
125 | if user.contest_finished? |
|
125 | header = <<CONTEST_OVER |
|
126 | header = <<CONTEST_OVER |
|
126 | <tr><td colspan="2" align="center"> |
|
127 | <tr><td colspan="2" align="center"> |
|
127 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
128 | <span class="contest-over-msg">THE CONTEST IS OVER</span> |
|
128 | </td></tr> |
|
129 | </td></tr> |
|
129 | CONTEST_OVER |
|
130 | CONTEST_OVER |
|
130 | end |
|
131 | end |
|
131 | if !user.contest_started? |
|
132 | if !user.contest_started? |
|
132 | time_left = " " + (t 'title_bar.contest_not_started') |
|
133 | time_left = " " + (t 'title_bar.contest_not_started') |
|
133 | else |
|
134 | else |
|
134 | time_left = " " + (t 'title_bar.remaining_time') + |
|
135 | time_left = " " + (t 'title_bar.remaining_time') + |
|
135 | " #{format_short_duration(user.contest_time_left)}" |
|
136 | " #{format_short_duration(user.contest_time_left)}" |
|
136 | end |
|
137 | end |
|
137 | end |
|
138 | end |
|
138 |
|
139 | ||
|
139 | # |
|
140 | # |
|
140 | # if the contest is in the anaysis mode |
|
141 | # if the contest is in the anaysis mode |
|
141 | if GraderConfiguration.analysis_mode? |
|
142 | if GraderConfiguration.analysis_mode? |
|
142 | header = <<ANALYSISMODE |
|
143 | header = <<ANALYSISMODE |
|
143 | <tr><td colspan="2" align="center"> |
|
144 | <tr><td colspan="2" align="center"> |
|
144 | <span class="contest-over-msg">ANALYSIS MODE</span> |
|
145 | <span class="contest-over-msg">ANALYSIS MODE</span> |
|
145 | </td></tr> |
|
146 | </td></tr> |
|
146 | ANALYSISMODE |
|
147 | ANALYSISMODE |
|
147 | end |
|
148 | end |
|
148 |
|
149 | ||
|
149 | contest_name = GraderConfiguration['contest.name'] |
|
150 | contest_name = GraderConfiguration['contest.name'] |
|
150 |
|
151 | ||
|
151 | # |
|
152 | # |
|
152 | # build real title bar |
|
153 | # build real title bar |
|
153 | result = <<TITLEBAR |
|
154 | result = <<TITLEBAR |
|
154 | <div class="title"> |
|
155 | <div class="title"> |
|
155 | <table> |
|
156 | <table> |
|
156 | #{header} |
|
157 | #{header} |
|
157 | <tr> |
|
158 | <tr> |
|
158 | <td class="left-col"> |
|
159 | <td class="left-col"> |
|
159 | #{user.full_name}<br/> |
|
160 | #{user.full_name}<br/> |
|
160 | #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} |
|
161 | #{t 'title_bar.current_time'} #{format_short_time(Time.zone.now)} |
|
161 | #{time_left} |
|
162 | #{time_left} |
|
162 | <br/> |
|
163 | <br/> |
|
163 | </td> |
|
164 | </td> |
|
164 | <td class="right-col">#{contest_name}</td> |
|
165 | <td class="right-col">#{contest_name}</td> |
|
165 | </tr> |
|
166 | </tr> |
|
166 | </table> |
|
167 | </table> |
|
167 | </div> |
|
168 | </div> |
|
168 | TITLEBAR |
|
169 | TITLEBAR |
|
169 | result.html_safe |
|
170 | result.html_safe |
|
170 | end |
|
171 | end |
|
171 |
|
172 | ||
|
172 | def markdown(text) |
|
173 | def markdown(text) |
|
173 | markdown = RDiscount.new(text) |
|
174 | markdown = RDiscount.new(text) |
|
174 | markdown.to_html.html_safe |
|
175 | markdown.to_html.html_safe |
|
175 | end |
|
176 | end |
|
176 |
|
177 | ||
|
177 | end |
|
178 | end |
@@ -1,36 +1,36 | |||||
|
1 | %h1 Listing announcements |
|
1 | %h1 Listing announcements |
|
2 |
|
2 | ||
|
3 | = link_to '+ Add announcement', new_announcement_path, class: 'btn btn-success' |
|
3 | = link_to '+ Add announcement', new_announcement_path, class: 'btn btn-success' |
|
4 | %br |
|
4 | %br |
|
5 | %br |
|
5 | %br |
|
6 |
|
6 | ||
|
7 | %table.table.table-striped |
|
7 | %table.table.table-striped |
|
8 | %tr |
|
8 | %tr |
|
9 | %th Updated |
|
9 | %th Updated |
|
10 | %th Announcement |
|
10 | %th Announcement |
|
11 | %th Author |
|
11 | %th Author |
|
12 | %th Published |
|
12 | %th Published |
|
13 | %th |
|
13 | %th |
|
14 | %th |
|
14 | %th |
|
15 | - for announcement in @announcements |
|
15 | - for announcement in @announcements |
|
16 | %tr |
|
16 | %tr |
|
17 | - @announcement = announcement |
|
17 | - @announcement = announcement |
|
18 | %td= time_ago_in_words announcement.updated_at |
|
18 | %td= time_ago_in_words announcement.updated_at |
|
19 | %td |
|
19 | %td |
|
20 | - if !announcement.title.blank? |
|
20 | - if !announcement.title.blank? |
|
21 | %b Title: |
|
21 | %b Title: |
|
22 | = h announcement.title |
|
22 | = h announcement.title |
|
23 | %br/ |
|
23 | %br/ |
|
24 | - if !announcement.notes.blank? |
|
24 | - if !announcement.notes.blank? |
|
25 | %b |
|
25 | %b |
|
26 | Notes: #{h announcement.notes} |
|
26 | Notes: #{h announcement.notes} |
|
27 | %br/ |
|
27 | %br/ |
|
28 | = h announcement.body |
|
28 | = h announcement.body |
|
29 | %td= h announcement.author |
|
29 | %td= h announcement.author |
|
30 | - %td= toggle_button(announcement.published?, toggle_announcement_url(@announcement), "announcement_toggle_#{@announcement.id}") |
|
30 | + %td= toggle_button(announcement.published?, toggle_announcement_url(@announcement), "announcement_toggle_#{@announcement.id}", {size: 'btn-sm'}) |
|
31 | //%td= link_to (announcement.published? ? "Yes" : "No"), url_for(controller: :announcements, action: :toggle, id: announcement), { class: "btn btn-block btn-sm btn-#{(announcement.published? ? 'success' : 'default')} ajax-toggle", id: "published-#{announcement.id}", data: {remote: true, method: 'post' } } |
|
31 | //%td= link_to (announcement.published? ? "Yes" : "No"), url_for(controller: :announcements, action: :toggle, id: announcement), { class: "btn btn-block btn-sm btn-#{(announcement.published? ? 'success' : 'default')} ajax-toggle", id: "published-#{announcement.id}", data: {remote: true, method: 'post' } } |
|
32 | %td= link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-block btn-sm btn-info' |
|
32 | %td= link_to 'Edit', edit_announcement_path(announcement), class: 'btn btn-block btn-sm btn-info' |
|
33 | %td= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete, class: "btn btn-block btn-sm btn-danger" |
|
33 | %td= link_to 'Destroy', announcement, :confirm => 'Are you sure?', :method => :delete, class: "btn btn-block btn-sm btn-danger" |
|
34 | %br |
|
34 | %br |
|
35 |
|
35 | ||
|
36 | = link_to '+ Add announcement', new_announcement_path, class: 'btn btn-success' |
|
36 | = link_to '+ Add announcement', new_announcement_path, class: 'btn btn-success' |
You need to be logged in to leave comments.
Login now