Description:
[web] refactor problem description, some styling
git-svn-id: http://theory.cpe.ku.ac.th/grader/web/trunk@179 6386c4cd-e34a-4fa8-8920-d93eb39b512e
Commit status:
[Not Reviewed]
References:
Diff options:
Comments:
0 Commit comments
0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
r92:84da10c15f8a - - 13 files changed: 167 inserted, 17 deleted
@@ -0,0 +1,13 | |||||
|
|
1 | + class CreateDescriptions < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + create_table :descriptions do |t| | ||
|
|
4 | + t.column :body, :text | ||
|
|
5 | + t.column :markdowned, :boolean | ||
|
|
6 | + t.timestamps | ||
|
|
7 | + end | ||
|
|
8 | + end | ||
|
|
9 | + | ||
|
|
10 | + def self.down | ||
|
|
11 | + drop_table :descriptions | ||
|
|
12 | + end | ||
|
|
13 | + end |
@@ -0,0 +1,33 | |||||
|
|
1 | + class RefactorProblemBodyToDescription < ActiveRecord::Migration | ||
|
|
2 | + def self.up | ||
|
|
3 | + add_column :problems, :description_id, :integer | ||
|
|
4 | + Problem.reset_column_information | ||
|
|
5 | + | ||
|
|
6 | + Problem.find(:all).each do |problem| | ||
|
|
7 | + if problem.body!=nil | ||
|
|
8 | + description = Description.new | ||
|
|
9 | + description.body = problem.body | ||
|
|
10 | + description.markdowned = false | ||
|
|
11 | + description.save | ||
|
|
12 | + problem.description_id = description.id | ||
|
|
13 | + problem.save | ||
|
|
14 | + end | ||
|
|
15 | + end | ||
|
|
16 | + | ||
|
|
17 | + remove_column :problems, :body | ||
|
|
18 | + end | ||
|
|
19 | + | ||
|
|
20 | + def self.down | ||
|
|
21 | + add_column :problems, :body, :text | ||
|
|
22 | + Problem.reset_column_information | ||
|
|
23 | + | ||
|
|
24 | + Problem.find(:all).each do |problem| | ||
|
|
25 | + if problem.description_id != nil | ||
|
|
26 | + problem.body = Description.find(problem.description_id).body | ||
|
|
27 | + problem.save | ||
|
|
28 | + end | ||
|
|
29 | + end | ||
|
|
30 | + | ||
|
|
31 | + remove_column :problems, :description_id | ||
|
|
32 | + end | ||
|
|
33 | + end |
@@ -0,0 +1,7 | |||||
|
|
1 | + # Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html | ||
|
|
2 | + | ||
|
|
3 | + # one: | ||
|
|
4 | + # column: value | ||
|
|
5 | + # | ||
|
|
6 | + # two: | ||
|
|
7 | + # column: value |
@@ -0,0 +1,8 | |||||
|
|
1 | + require File.dirname(__FILE__) + '/../test_helper' | ||
|
|
2 | + | ||
|
|
3 | + class DescriptionTest < ActiveSupport::TestCase | ||
|
|
4 | + # Replace this with your real tests. | ||
|
|
5 | + def test_truth | ||
|
|
6 | + assert true | ||
|
|
7 | + end | ||
|
|
8 | + end |
@@ -22,30 +22,55 | |||||
|
22 | def show |
|
22 | def show |
|
23 | @problem = Problem.find(params[:id]) |
|
23 | @problem = Problem.find(params[:id]) |
|
24 | end |
|
24 | end |
|
25 |
|
25 | ||
|
26 | def new |
|
26 | def new |
|
27 | @problem = Problem.new |
|
27 | @problem = Problem.new |
|
|
28 | + @description = nil | ||
|
28 | end |
|
29 | end |
|
29 |
|
30 | ||
|
30 | def create |
|
31 | def create |
|
31 | @problem = Problem.new(params[:problem]) |
|
32 | @problem = Problem.new(params[:problem]) |
|
|
33 | + @description = Description.new(params[:description]) | ||
|
|
34 | + if @description.body!='' | ||
|
|
35 | + if !@description.save | ||
|
|
36 | + render :action => new and return | ||
|
|
37 | + end | ||
|
|
38 | + else | ||
|
|
39 | + @description = nil | ||
|
|
40 | + end | ||
|
|
41 | + @problem.description = @description | ||
|
32 | if @problem.save |
|
42 | if @problem.save |
|
33 | flash[:notice] = 'Problem was successfully created.' |
|
43 | flash[:notice] = 'Problem was successfully created.' |
|
34 | redirect_to :action => 'list' |
|
44 | redirect_to :action => 'list' |
|
35 | else |
|
45 | else |
|
36 | render :action => 'new' |
|
46 | render :action => 'new' |
|
37 | end |
|
47 | end |
|
38 | end |
|
48 | end |
|
39 |
|
49 | ||
|
40 | def edit |
|
50 | def edit |
|
41 | @problem = Problem.find(params[:id]) |
|
51 | @problem = Problem.find(params[:id]) |
|
|
52 | + @description = @problem.description | ||
|
42 | end |
|
53 | end |
|
43 |
|
54 | ||
|
44 | def update |
|
55 | def update |
|
45 | @problem = Problem.find(params[:id]) |
|
56 | @problem = Problem.find(params[:id]) |
|
|
57 | + @description = @problem.description | ||
|
|
58 | + if @description == nil and params[:description][:body]!='' | ||
|
|
59 | + @description = Description.new(params[:description]) | ||
|
|
60 | + if !@description.save | ||
|
|
61 | + flash[:notice] = 'Error saving description' | ||
|
|
62 | + render :action => 'edit' and return | ||
|
|
63 | + end | ||
|
|
64 | + @problem.description = @description | ||
|
|
65 | + elsif @description!=nil | ||
|
|
66 | + if !@description.update_attributes(params[:description]) | ||
|
|
67 | + flash[:notice] = 'Error saving description' | ||
|
|
68 | + render :action => 'edit' and return | ||
|
|
69 | + end | ||
|
|
70 | + end | ||
|
46 | if @problem.update_attributes(params[:problem]) |
|
71 | if @problem.update_attributes(params[:problem]) |
|
47 | flash[:notice] = 'Problem was successfully updated.' |
|
72 | flash[:notice] = 'Problem was successfully updated.' |
|
48 | redirect_to :action => 'show', :id => @problem |
|
73 | redirect_to :action => 'show', :id => @problem |
|
49 | else |
|
74 | else |
|
50 | render :action => 'edit' |
|
75 | render :action => 'edit' |
|
51 | end |
|
76 | end |
@@ -1,7 +1,9 | |||||
|
1 | class Problem < ActiveRecord::Base |
|
1 | class Problem < ActiveRecord::Base |
|
2 |
|
2 | ||
|
|
3 | + belongs_to :description | ||
|
|
4 | + | ||
|
3 | def self.find_available_problems |
|
5 | def self.find_available_problems |
|
4 | find(:all, :conditions => {:available => true}) |
|
6 | find(:all, :conditions => {:available => true}) |
|
5 | end |
|
7 | end |
|
6 |
|
8 | ||
|
7 | end |
|
9 | end |
@@ -10,16 +10,24 | |||||
|
10 | <p><label for="problem_full_score">Full score</label><br/> |
|
10 | <p><label for="problem_full_score">Full score</label><br/> |
|
11 | <%= text_field 'problem', 'full_score' %></p> |
|
11 | <%= text_field 'problem', 'full_score' %></p> |
|
12 |
|
12 | ||
|
13 | <p><label for="problem_date_added">Date added</label><br/> |
|
13 | <p><label for="problem_date_added">Date added</label><br/> |
|
14 | <%= date_select 'problem', 'date_added' %></p> |
|
14 | <%= date_select 'problem', 'date_added' %></p> |
|
15 |
|
15 | ||
|
16 | - <p><label for="problem_body">Body</label><br/> |
|
16 | + <%= error_messages_for 'description' %> |
|
17 | - <%= text_area 'problem', 'body', :rows => 10, :cols => 80 %></p> |
|
17 | + |
|
|
18 | + <p><label for="description_body">Description</label><br/> | ||
|
|
19 | + <%= text_area :description, :body, :rows => 10, :cols => 80 %></p> | ||
|
|
20 | + | ||
|
|
21 | + <p><label for="description_markdowned">Markdowned?</label> | ||
|
|
22 | + <%= select "description", | ||
|
|
23 | + "markdowned", | ||
|
|
24 | + [['True',true],['False',false]], | ||
|
|
25 | + {:selected => (@description) ? @description.markdowned : false } | ||
|
|
26 | + %></p> | ||
|
18 |
|
27 | ||
|
19 | <p><label for="problem_url">URL</label><br/> |
|
28 | <p><label for="problem_url">URL</label><br/> |
|
20 | <%= text_field 'problem', 'url' %></p> |
|
29 | <%= text_field 'problem', 'url' %></p> |
|
21 |
|
30 | ||
|
22 | <p><label for="problem_available">Available</label><br/> |
|
31 | <p><label for="problem_available">Available</label><br/> |
|
23 | <%= select("problem","available",[['True',true],['False',false]]) %></p> |
|
32 | <%= select("problem","available",[['True',true],['False',false]]) %></p> |
|
24 | <!--[eoform:problem]--> |
|
33 | <!--[eoform:problem]--> |
|
25 | - |
|
@@ -1,15 +1,18 | |||||
|
1 | <% for column in Problem.content_columns %> |
|
1 | <% for column in Problem.content_columns %> |
|
2 | <p> |
|
2 | <p> |
|
3 | <b><%= column.human_name %>:</b> |
|
3 | <b><%= column.human_name %>:</b> |
|
4 | - <% if column.name != 'body' %> |
|
||
|
5 |
|
|
4 | <%=h @problem.send(column.name) %> |
|
6 | - <% else %> |
|
5 | + </p> |
|
|
6 | + <% end %> | ||
|
|
7 | + | ||
|
|
8 | + <p> | ||
|
|
9 | + <b>Description:</b><br/> | ||
|
|
10 | + <% if @problem.description!=nil %> | ||
|
7 |
|
|
11 | <pre> |
|
8 |
- |
|
12 | + <%= @problem.description.body %> |
|
9 |
|
|
13 | </pre> |
|
10 |
|
|
14 | <% end %> |
|
11 | </p> |
|
15 | </p> |
|
12 | - <% end %> |
|
||
|
13 |
|
16 | ||
|
14 | <%= link_to 'Edit', :action => 'edit', :id => @problem %> | |
|
17 | <%= link_to 'Edit', :action => 'edit', :id => @problem %> | |
|
15 | <%= link_to 'Back', :action => 'list' %> |
|
18 | <%= link_to 'Back', :action => 'list' %> |
@@ -1,12 +1,22 | |||||
|
|
1 | + <tr class="name"> | ||
|
|
2 | + <td> | ||
|
1 | <a name="<%= problem.name %>"></a> |
|
3 | <a name="<%= problem.name %>"></a> |
|
2 | - <% back_color = ((problem_counter % 2) == 0) ? "#fefedd" : "#feeefe" %> |
|
||
|
3 | - <div style="border: 1px solid grey; background: <%= back_color %>; padding-left: 20px; padding-bottom: 5px"> |
|
||
|
4 | - <div style="border-bottom: 1px solid black; padding-top: 10px; padding-bottom: 5px; font-size: 18px; font-weight: bold"> |
|
||
|
5 | <%= "#{problem.full_name} (#{problem.name})" %> |
|
4 | <%= "#{problem.full_name} (#{problem.name})" %> |
|
6 |
- </d |
|
5 | + </td> |
|
7 | - <% if problem.body!=nil %> |
|
6 | + </tr> |
|
8 | - <%= markdown(problem.body) %> |
|
7 | + <tr> |
|
|
8 | + <% td_class = (problem_counter%2==0) ? "desc-even" : "desc-odd" %> | ||
|
|
9 | + <td class="<%= td_class %>"> | ||
|
|
10 | + <% if problem.description!=nil %> | ||
|
|
11 | + <% if problem.description.markdowned %> | ||
|
|
12 | + <%= markdown(problem.description.body) %> | ||
|
|
13 | + <% else %> | ||
|
|
14 | + <pre> | ||
|
|
15 | + <%= problem.description.body %> | ||
|
|
16 | + </pre> | ||
|
|
17 | + <% end %> | ||
|
9 | <% else %> |
|
18 | <% else %> |
|
10 | (not available) |
|
19 | (not available) |
|
11 | <% end %> |
|
20 | <% end %> |
|
12 |
- </d |
|
21 | + </td> |
|
|
22 | + </tr> |
@@ -1,12 +1,13 | |||||
|
1 | = user_title_bar(@user) |
|
1 | = user_title_bar(@user) |
|
2 |
|
2 | ||
|
3 | .task-menu |
|
3 | .task-menu |
|
4 | %b Task Listing: |
|
4 | %b Task Listing: |
|
5 |
|
5 | ||
|
6 | - @problems.each do |problem| |
|
6 | - @problems.each do |problem| |
|
7 |
- - if problem. |
|
7 | + - if problem.description!=nil |
|
8 | %a{:href => "\##{problem.name}"}= "[#{problem.full_name}]" |
|
8 | %a{:href => "\##{problem.name}"}= "[#{problem.full_name}]" |
|
9 | - else |
|
9 | - else |
|
10 | = "[#{problem.full_name}]" |
|
10 | = "[#{problem.full_name}]" |
|
11 |
|
11 | ||
|
|
12 | + %table.taskdesc | ||
|
12 | = render :partial => 'problem', :collection => @problems |
|
13 | = render :partial => 'problem', :collection => @problems |
@@ -6,22 +6,29 | |||||
|
6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
6 | # to create the application database on another system, you should be using db:schema:load, not running |
|
7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
7 | # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations |
|
8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
8 | # you'll amass, the slower it'll run and the greater likelihood for issues). |
|
9 | # |
|
9 | # |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
10 | # It's strongly recommended to check this file into your version control system. |
|
11 |
|
11 | ||
|
12 |
- ActiveRecord::Schema.define(:version => 2 |
|
12 | + ActiveRecord::Schema.define(:version => 28) do |
|
13 |
|
13 | ||
|
14 | create_table "configurations", :force => true do |t| |
|
14 | create_table "configurations", :force => true do |t| |
|
15 | t.string "key" |
|
15 | t.string "key" |
|
16 | t.string "value_type" |
|
16 | t.string "value_type" |
|
17 | t.string "value" |
|
17 | t.string "value" |
|
18 | t.datetime "created_at" |
|
18 | t.datetime "created_at" |
|
19 | t.datetime "updated_at" |
|
19 | t.datetime "updated_at" |
|
20 | end |
|
20 | end |
|
21 |
|
21 | ||
|
|
22 | + create_table "descriptions", :force => true do |t| | ||
|
|
23 | + t.text "body" | ||
|
|
24 | + t.boolean "markdowned" | ||
|
|
25 | + t.datetime "created_at" | ||
|
|
26 | + t.datetime "updated_at" | ||
|
|
27 | + end | ||
|
|
28 | + | ||
|
22 | create_table "grader_processes", :force => true do |t| |
|
29 | create_table "grader_processes", :force => true do |t| |
|
23 | t.string "host", :limit => 20 |
|
30 | t.string "host", :limit => 20 |
|
24 | t.integer "pid" |
|
31 | t.integer "pid" |
|
25 | t.string "mode" |
|
32 | t.string "mode" |
|
26 | t.boolean "active" |
|
33 | t.boolean "active" |
|
27 | t.datetime "created_at" |
|
34 | t.datetime "created_at" |
@@ -41,13 +48,13 | |||||
|
41 | t.string "name", :limit => 30 |
|
48 | t.string "name", :limit => 30 |
|
42 | t.string "full_name" |
|
49 | t.string "full_name" |
|
43 | t.integer "full_score" |
|
50 | t.integer "full_score" |
|
44 | t.date "date_added" |
|
51 | t.date "date_added" |
|
45 | t.boolean "available" |
|
52 | t.boolean "available" |
|
46 | t.string "url" |
|
53 | t.string "url" |
|
47 | - t.text "body" |
|
54 | + t.integer "description_id" |
|
48 | end |
|
55 | end |
|
49 |
|
56 | ||
|
50 | create_table "rights", :force => true do |t| |
|
57 | create_table "rights", :force => true do |t| |
|
51 | t.string "name" |
|
58 | t.string "name" |
|
52 | t.string "controller" |
|
59 | t.string "controller" |
|
53 | t.string "action" |
|
60 | t.string "action" |
@@ -118,6 +118,37 | |||||
|
118 | font-weight: bold; |
|
118 | font-weight: bold; |
|
119 | border-top: 1px solid black; |
|
119 | border-top: 1px solid black; |
|
120 | border-bottom: 1px solid black; |
|
120 | border-bottom: 1px solid black; |
|
121 | margin-top: 2px; |
|
121 | margin-top: 2px; |
|
122 | margin-bottom: 4px; |
|
122 | margin-bottom: 4px; |
|
123 | } |
|
123 | } |
|
|
124 | + | ||
|
|
125 | + /******************************* | ||
|
|
126 | + [Submission] | ||
|
|
127 | + ********************************/ | ||
|
|
128 | + table.taskdesc { | ||
|
|
129 | + border: 1px solid black; | ||
|
|
130 | + border-collapse: collapse; | ||
|
|
131 | + font-size: 12px; | ||
|
|
132 | + width: 100%; | ||
|
|
133 | + } | ||
|
|
134 | + | ||
|
|
135 | + table.taskdesc tr.name { | ||
|
|
136 | + border: 1px solid black; | ||
|
|
137 | + background: #aaaaaa; | ||
|
|
138 | + color: white; | ||
|
|
139 | + font-weight: bold; | ||
|
|
140 | + font-size: 14px; | ||
|
|
141 | + text-align: center; | ||
|
|
142 | + } | ||
|
|
143 | + | ||
|
|
144 | + table.taskdesc td.desc-odd { | ||
|
|
145 | + padding: 5px; | ||
|
|
146 | + padding-left: 10px; | ||
|
|
147 | + background: #fefeee; | ||
|
|
148 | + } | ||
|
|
149 | + | ||
|
|
150 | + table.taskdesc td.desc-even { | ||
|
|
151 | + padding: 5px; | ||
|
|
152 | + padding-left: 10px; | ||
|
|
153 | + background: #feeefe; | ||
|
|
154 | + } |
You need to be logged in to leave comments.
Login now