diff --git a/app/controllers/problems_controller.rb b/app/controllers/problems_controller.rb
--- a/app/controllers/problems_controller.rb
+++ b/app/controllers/problems_controller.rb
@@ -25,10 +25,20 @@
def new
@problem = Problem.new
+ @description = nil
end
def create
@problem = Problem.new(params[:problem])
+ @description = Description.new(params[:description])
+ if @description.body!=''
+ if !@description.save
+ render :action => new and return
+ end
+ else
+ @description = nil
+ end
+ @problem.description = @description
if @problem.save
flash[:notice] = 'Problem was successfully created.'
redirect_to :action => 'list'
@@ -39,10 +49,25 @@
def edit
@problem = Problem.find(params[:id])
+ @description = @problem.description
end
def update
@problem = Problem.find(params[:id])
+ @description = @problem.description
+ if @description == nil and params[:description][:body]!=''
+ @description = Description.new(params[:description])
+ if !@description.save
+ flash[:notice] = 'Error saving description'
+ render :action => 'edit' and return
+ end
+ @problem.description = @description
+ elsif @description!=nil
+ if !@description.update_attributes(params[:description])
+ flash[:notice] = 'Error saving description'
+ render :action => 'edit' and return
+ end
+ end
if @problem.update_attributes(params[:problem])
flash[:notice] = 'Problem was successfully updated.'
redirect_to :action => 'show', :id => @problem
diff --git a/app/models/description.rb b/app/models/description.rb
new file mode 100644
--- /dev/null
+++ b/app/models/description.rb
@@ -0,0 +1,2 @@
+class Description < ActiveRecord::Base
+end
diff --git a/app/models/problem.rb b/app/models/problem.rb
--- a/app/models/problem.rb
+++ b/app/models/problem.rb
@@ -1,5 +1,7 @@
class Problem < ActiveRecord::Base
+ belongs_to :description
+
def self.find_available_problems
find(:all, :conditions => {:available => true})
end
diff --git a/app/views/problems/_form.rhtml b/app/views/problems/_form.rhtml
--- a/app/views/problems/_form.rhtml
+++ b/app/views/problems/_form.rhtml
@@ -13,8 +13,17 @@
<%= date_select 'problem', 'date_added' %>
-
-<%= text_area 'problem', 'body', :rows => 10, :cols => 80 %>
+<%= error_messages_for 'description' %>
+
+
+<%= text_area :description, :body, :rows => 10, :cols => 80 %>
+
+
+<%= select "description",
+ "markdowned",
+ [['True',true],['False',false]],
+ {:selected => (@description) ? @description.markdowned : false }
+%>
<%= text_field 'problem', 'url' %>
@@ -22,4 +31,3 @@
<%= select("problem","available",[['True',true],['False',false]]) %>
-
diff --git a/app/views/problems/show.rhtml b/app/views/problems/show.rhtml
--- a/app/views/problems/show.rhtml
+++ b/app/views/problems/show.rhtml
@@ -1,15 +1,18 @@
<% for column in Problem.content_columns %>
<%= column.human_name %>:
- <% if column.name != 'body' %>
- <%=h @problem.send(column.name) %>
- <% else %>
-
- <%= @problem.body %>
-
- <% end %>
+ <%=h @problem.send(column.name) %>
<% end %>
+
+Description:
+<% if @problem.description!=nil %>
+
+<%= @problem.description.body %>
+
+<% end %>
+
+
<%= link_to 'Edit', :action => 'edit', :id => @problem %> |
<%= link_to 'Back', :action => 'list' %>
diff --git a/app/views/tasks/_problem.html.erb b/app/views/tasks/_problem.html.erb
--- a/app/views/tasks/_problem.html.erb
+++ b/app/views/tasks/_problem.html.erb
@@ -1,12 +1,22 @@
-
-<% back_color = ((problem_counter % 2) == 0) ? "#fefedd" : "#feeefe" %>
-
-
+
+
+
<%= "#{problem.full_name} (#{problem.name})" %>
-
- <% if problem.body!=nil %>
-<%= markdown(problem.body) %>
+ |
+
+
+ <% td_class = (problem_counter%2==0) ? "desc-even" : "desc-odd" %>
+
+ <% if problem.description!=nil %>
+ <% if problem.description.markdowned %>
+<%= markdown(problem.description.body) %>
+ <% else %>
+
+<%= problem.description.body %>
+
+ <% end %>
<% else %>
(not available)
<% end %>
-
+ |
+
diff --git a/app/views/tasks/list.html.haml b/app/views/tasks/list.html.haml
--- a/app/views/tasks/list.html.haml
+++ b/app/views/tasks/list.html.haml
@@ -4,9 +4,10 @@
%b Task Listing:
- @problems.each do |problem|
- - if problem.body!=nil
+ - if problem.description!=nil
%a{:href => "\##{problem.name}"}= "[#{problem.full_name}]"
- else
= "[#{problem.full_name}]"
-= render :partial => 'problem', :collection => @problems
+%table.taskdesc
+ = render :partial => 'problem', :collection => @problems
diff --git a/db/migrate/027_create_descriptions.rb b/db/migrate/027_create_descriptions.rb
new file mode 100644
--- /dev/null
+++ b/db/migrate/027_create_descriptions.rb
@@ -0,0 +1,13 @@
+class CreateDescriptions < ActiveRecord::Migration
+ def self.up
+ create_table :descriptions do |t|
+ t.column :body, :text
+ t.column :markdowned, :boolean
+ t.timestamps
+ end
+ end
+
+ def self.down
+ drop_table :descriptions
+ end
+end
diff --git a/db/migrate/028_refactor_problem_body_to_description.rb b/db/migrate/028_refactor_problem_body_to_description.rb
new file mode 100644
--- /dev/null
+++ b/db/migrate/028_refactor_problem_body_to_description.rb
@@ -0,0 +1,33 @@
+class RefactorProblemBodyToDescription < ActiveRecord::Migration
+ def self.up
+ add_column :problems, :description_id, :integer
+ Problem.reset_column_information
+
+ Problem.find(:all).each do |problem|
+ if problem.body!=nil
+ description = Description.new
+ description.body = problem.body
+ description.markdowned = false
+ description.save
+ problem.description_id = description.id
+ problem.save
+ end
+ end
+
+ remove_column :problems, :body
+ end
+
+ def self.down
+ add_column :problems, :body, :text
+ Problem.reset_column_information
+
+ Problem.find(:all).each do |problem|
+ if problem.description_id != nil
+ problem.body = Description.find(problem.description_id).body
+ problem.save
+ end
+ end
+
+ remove_column :problems, :description_id
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
--- a/db/schema.rb
+++ b/db/schema.rb
@@ -9,7 +9,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 26) do
+ActiveRecord::Schema.define(:version => 28) do
create_table "configurations", :force => true do |t|
t.string "key"
@@ -19,6 +19,13 @@
t.datetime "updated_at"
end
+ create_table "descriptions", :force => true do |t|
+ t.text "body"
+ t.boolean "markdowned"
+ t.datetime "created_at"
+ t.datetime "updated_at"
+ end
+
create_table "grader_processes", :force => true do |t|
t.string "host", :limit => 20
t.integer "pid"
@@ -38,13 +45,13 @@
end
create_table "problems", :force => true do |t|
- t.string "name", :limit => 30
+ t.string "name", :limit => 30
t.string "full_name"
t.integer "full_score"
t.date "date_added"
t.boolean "available"
t.string "url"
- t.text "body"
+ t.integer "description_id"
end
create_table "rights", :force => true do |t|
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -121,3 +121,34 @@
margin-top: 2px;
margin-bottom: 4px;
}
+
+/*******************************
+ [Submission]
+********************************/
+table.taskdesc {
+ border: 1px solid black;
+ border-collapse: collapse;
+ font-size: 12px;
+ width: 100%;
+}
+
+table.taskdesc tr.name {
+ border: 1px solid black;
+ background: #aaaaaa;
+ color: white;
+ font-weight: bold;
+ font-size: 14px;
+ text-align: center;
+}
+
+table.taskdesc td.desc-odd {
+ padding: 5px;
+ padding-left: 10px;
+ background: #fefeee;
+}
+
+table.taskdesc td.desc-even {
+ padding: 5px;
+ padding-left: 10px;
+ background: #feeefe;
+}
diff --git a/test/fixtures/descriptions.yml b/test/fixtures/descriptions.yml
new file mode 100644
--- /dev/null
+++ b/test/fixtures/descriptions.yml
@@ -0,0 +1,7 @@
+# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html
+
+# one:
+# column: value
+#
+# two:
+# column: value
diff --git a/test/unit/description_test.rb b/test/unit/description_test.rb
new file mode 100644
--- /dev/null
+++ b/test/unit/description_test.rb
@@ -0,0 +1,8 @@
+require File.dirname(__FILE__) + '/../test_helper'
+
+class DescriptionTest < ActiveSupport::TestCase
+ # Replace this with your real tests.
+ def test_truth
+ assert true
+ end
+end