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:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r92:84da10c15f8a - - 13 files changed: 167 inserted, 17 deleted

@@ -0,0 +1,2
1 + class Description < ActiveRecord::Base
2 + end
@@ -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
@@ -16,42 +16,67
16 16 :redirect_to => { :action => :list }
17 17
18 18 def list
19 19 @problems = Problem.find(:all, :order => 'date_added DESC')
20 20 end
21 21
22 22 def show
23 23 @problem = Problem.find(params[:id])
24 24 end
25 25
26 26 def new
27 27 @problem = Problem.new
28 + @description = nil
28 29 end
29 30
30 31 def create
31 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 42 if @problem.save
33 43 flash[:notice] = 'Problem was successfully created.'
34 44 redirect_to :action => 'list'
35 45 else
36 46 render :action => 'new'
37 47 end
38 48 end
39 49
40 50 def edit
41 51 @problem = Problem.find(params[:id])
52 + @description = @problem.description
42 53 end
43 54
44 55 def update
45 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 71 if @problem.update_attributes(params[:problem])
47 72 flash[:notice] = 'Problem was successfully updated.'
48 73 redirect_to :action => 'show', :id => @problem
49 74 else
50 75 render :action => 'edit'
51 76 end
52 77 end
53 78
54 79 def destroy
55 80 Problem.find(params[:id]).destroy
56 81 redirect_to :action => 'list'
57 82 end
@@ -1,7 +1,9
1 1 class Problem < ActiveRecord::Base
2 2
3 + belongs_to :description
4 +
3 5 def self.find_available_problems
4 6 find(:all, :conditions => {:available => true})
5 7 end
6 8
7 9 end
@@ -4,22 +4,30
4 4 <p><label for="problem_name">Name</label><br/>
5 5 <%= text_field 'problem', 'name' %></p>
6 6
7 7 <p><label for="problem_full_name">Full name</label><br/>
8 8 <%= text_field 'problem', 'full_name' %></p>
9 9
10 10 <p><label for="problem_full_score">Full score</label><br/>
11 11 <%= text_field 'problem', 'full_score' %></p>
12 12
13 13 <p><label for="problem_date_added">Date added</label><br/>
14 14 <%= date_select 'problem', 'date_added' %></p>
15 15
16 - <p><label for="problem_body">Body</label><br/>
17 - <%= text_area 'problem', 'body', :rows => 10, :cols => 80 %></p>
16 + <%= error_messages_for 'description' %>
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 28 <p><label for="problem_url">URL</label><br/>
20 29 <%= text_field 'problem', 'url' %></p>
21 30
22 31 <p><label for="problem_available">Available</label><br/>
23 32 <%= select("problem","available",[['True',true],['False',false]]) %></p>
24 33 <!--[eoform:problem]-->
25 -
@@ -1,15 +1,18
1 1 <% for column in Problem.content_columns %>
2 2 <p>
3 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 - <%= @problem.body %>
12 + <%= @problem.description.body %>
9 13 </pre>
10 14 <% end %>
11 15 </p>
12 - <% end %>
13 16
14 17 <%= link_to 'Edit', :action => 'edit', :id => @problem %> |
15 18 <%= link_to 'Back', :action => 'list' %>
@@ -1,12 +1,22
1 + <tr class="name">
2 + <td>
1 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 4 <%= "#{problem.full_name} (#{problem.name})" %>
6 - </div>
7 - <% if problem.body!=nil %>
8 - <%= markdown(problem.body) %>
5 + </td>
6 + </tr>
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 18 <% else %>
10 19 (not available)
11 20 <% end %>
12 - </div>
21 + </td>
22 + </tr>
@@ -1,12 +1,13
1 1 = user_title_bar(@user)
2 2
3 3 .task-menu
4 4 %b Task Listing:
5 5
6 6 - @problems.each do |problem|
7 - - if problem.body!=nil
7 + - if problem.description!=nil
8 8 %a{:href => "\##{problem.name}"}= "[#{problem.full_name}]"
9 9 - else
10 10 = "[#{problem.full_name}]"
11 11
12 + %table.taskdesc
12 13 = render :partial => 'problem', :collection => @problems
@@ -1,33 +1,40
1 1 # This file is auto-generated from the current state of the database. Instead of editing this file,
2 2 # please use the migrations feature of ActiveRecord to incrementally modify your database, and
3 3 # then regenerate this schema definition.
4 4 #
5 5 # Note that this schema.rb definition is the authoritative source for your database schema. If you need
6 6 # to create the application database on another system, you should be using db:schema:load, not running
7 7 # all the migrations from scratch. The latter is a flawed and unsustainable approach (the more migrations
8 8 # you'll amass, the slower it'll run and the greater likelihood for issues).
9 9 #
10 10 # It's strongly recommended to check this file into your version control system.
11 11
12 - ActiveRecord::Schema.define(:version => 26) do
12 + ActiveRecord::Schema.define(:version => 28) do
13 13
14 14 create_table "configurations", :force => true do |t|
15 15 t.string "key"
16 16 t.string "value_type"
17 17 t.string "value"
18 18 t.datetime "created_at"
19 19 t.datetime "updated_at"
20 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 29 create_table "grader_processes", :force => true do |t|
23 30 t.string "host", :limit => 20
24 31 t.integer "pid"
25 32 t.string "mode"
26 33 t.boolean "active"
27 34 t.datetime "created_at"
28 35 t.datetime "updated_at"
29 36 t.integer "task_id"
30 37 end
31 38
32 39 add_index "grader_processes", ["host", "pid"], :name => "index_grader_processes_on_ip_and_pid"
33 40
@@ -35,25 +42,25
35 42 t.string "name", :limit => 10
36 43 t.string "pretty_name"
37 44 t.string "ext", :limit => 10
38 45 end
39 46
40 47 create_table "problems", :force => true do |t|
41 48 t.string "name", :limit => 30
42 49 t.string "full_name"
43 50 t.integer "full_score"
44 51 t.date "date_added"
45 52 t.boolean "available"
46 53 t.string "url"
47 - t.text "body"
54 + t.integer "description_id"
48 55 end
49 56
50 57 create_table "rights", :force => true do |t|
51 58 t.string "name"
52 59 t.string "controller"
53 60 t.string "action"
54 61 end
55 62
56 63 create_table "rights_roles", :id => false, :force => true do |t|
57 64 t.integer "right_id"
58 65 t.integer "role_id"
59 66 end
@@ -112,12 +112,43
112 112 font-family: monospace;
113 113 }
114 114
115 115 div.task-menu {
116 116 text-align: center;
117 117 font-size: 13px;
118 118 font-weight: bold;
119 119 border-top: 1px solid black;
120 120 border-bottom: 1px solid black;
121 121 margin-top: 2px;
122 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