From b9cd4e9daf340fc5b94128d8dfaab3af1b50eeb6 Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Tue, 15 Apr 2014 01:34:17 +0200 Subject: [PATCH 01/11] Issue #208 Linking to adding test cases & answers --- tutor/app/controllers/model_answers_controller.rb | 8 +++++--- tutor/app/controllers/problems_controller.rb | 2 ++ tutor/app/controllers/test_cases_controller.rb | 6 +++--- .../views/model_answers/{new.html.erb => _new.html.erb} | 1 + tutor/app/views/problems/edit.html.erb | 5 ++++- tutor/app/views/test_cases/_form.html.erb | 1 + .../views/test_cases/{index.html.erb => _index.html.erb} | 2 +- 7 files changed, 17 insertions(+), 8 deletions(-) rename tutor/app/views/model_answers/{new.html.erb => _new.html.erb} (86%) rename tutor/app/views/test_cases/{index.html.erb => _index.html.erb} (86%) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index ae8c8b6e..c2a96a71 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -21,10 +21,12 @@ def create @answer = ModelAnswer.new(post_params) if @answer.save flash[:notice] = "Your Answer is now added" - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @answer.problem_id + else flash[:notice] = "Your Answer can not be added " - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @answer.problem_id + end end @@ -56,6 +58,6 @@ def index # Author: Nadine Adel private def post_params - params.require(:model_answer).permit(:answer) + params.require(:model_answer).permit(:answer, :problem_id) end end \ No newline at end of file diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index 87756df6..041c16b9 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -50,6 +50,8 @@ def permitCreate # Author: Abdullrahman Elhusseny def edit @problem = Problem.find_by_id(params[:id]) + @test_cases = @problem.test_cases + @answers = @problem.model_answers end def new if lecturer_signed_in? diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index 6293d262..b0b2ceef 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -25,10 +25,10 @@ def create @test_case = TestCase.new(post_params) if @test_case.save flash[:notice] = "Post created successfully" - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @test_case.problem_id else flash[:notice] = "Can't add test case!" - redirect_to :back + redirect_to :controller => 'problems', :action => 'edit' , :id => @test_case.problem_id end end # [Add test case-story 4.8] @@ -38,6 +38,6 @@ def create # Author: Lin private def post_params - params.require(:test_case).permit(:input, :output) + params.require(:test_case).permit(:input, :output, :problem_id) end end diff --git a/tutor/app/views/model_answers/new.html.erb b/tutor/app/views/model_answers/_new.html.erb similarity index 86% rename from tutor/app/views/model_answers/new.html.erb rename to tutor/app/views/model_answers/_new.html.erb index 1bd0fb69..23d8626b 100644 --- a/tutor/app/views/model_answers/new.html.erb +++ b/tutor/app/views/model_answers/_new.html.erb @@ -12,6 +12,7 @@

Please Insert your model answer

<%= f.text_area :answer %> + <%= f.hidden_field :problem_id, value: params[:id] %>

<%= f.submit %> diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index 191bd913..3ad20f58 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -2,4 +2,7 @@ a header to view the problem title of the instance variable @problem and a paragraph to view the problem description of the instance variable @problem -->

<%= @problem.title %>

-

<%= @problem.description %>

\ No newline at end of file +

<%= @problem.description %>

+ +<%= render partial: "test_cases/index"%> +<%= render partial: "model_answers/new"%> \ No newline at end of file diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index 941c3b5d..771930ff 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -6,6 +6,7 @@ <%= f.text_field :input %> <%= f.label :Output %> <%= f.text_field :output %> + <%= f.hidden_field :problem_id, value: params[:id] %>

<%= f.submit 'Add test case' %> diff --git a/tutor/app/views/test_cases/index.html.erb b/tutor/app/views/test_cases/_index.html.erb similarity index 86% rename from tutor/app/views/test_cases/index.html.erb rename to tutor/app/views/test_cases/_index.html.erb index a92bc9ba..038f75fa 100644 --- a/tutor/app/views/test_cases/index.html.erb +++ b/tutor/app/views/test_cases/_index.html.erb @@ -7,4 +7,4 @@ <% end %> -<%= render "form"%> \ No newline at end of file +<%= render partial: "test_cases/form"%> From 22dc24f92265dd4f541b52dfd7fd5b9200d0714a Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Tue, 15 Apr 2014 16:41:36 +0200 Subject: [PATCH 02/11] Issue #208 fixing spaces --- tutor/app/controllers/model_answers_controller.rb | 6 +++--- tutor/app/controllers/problems_controller.rb | 2 +- tutor/app/controllers/test_cases_controller.rb | 6 +++--- tutor/app/views/model_answers/_new.html.erb | 2 +- tutor/app/views/problems/edit.html.erb | 4 ++-- tutor/app/views/test_cases/_form.html.erb | 4 ++-- tutor/app/views/test_cases/_index.html.erb | 2 +- tutor/app/views/test_cases/new.html.erb | 2 +- 8 files changed, 14 insertions(+), 14 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index c2a96a71..f814d287 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -21,11 +21,11 @@ def create @answer = ModelAnswer.new(post_params) if @answer.save flash[:notice] = "Your Answer is now added" - redirect_to :controller => 'problems', :action => 'edit' , :id => @answer.problem_id + redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id else - flash[:notice] = "Your Answer can not be added " - redirect_to :controller => 'problems', :action => 'edit' , :id => @answer.problem_id + flash[:notice] = "Your Answer can not be added" + redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id end end diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index 041c16b9..86854e07 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -60,4 +60,4 @@ def new render ('public/404') end end -end +end \ No newline at end of file diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index b0b2ceef..90d129f1 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -25,10 +25,10 @@ def create @test_case = TestCase.new(post_params) if @test_case.save flash[:notice] = "Post created successfully" - redirect_to :controller => 'problems', :action => 'edit' , :id => @test_case.problem_id + redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id else flash[:notice] = "Can't add test case!" - redirect_to :controller => 'problems', :action => 'edit' , :id => @test_case.problem_id + redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id end end # [Add test case-story 4.8] @@ -40,4 +40,4 @@ def create def post_params params.require(:test_case).permit(:input, :output, :problem_id) end -end +end \ No newline at end of file diff --git a/tutor/app/views/model_answers/_new.html.erb b/tutor/app/views/model_answers/_new.html.erb index 23d8626b..5add7782 100644 --- a/tutor/app/views/model_answers/_new.html.erb +++ b/tutor/app/views/model_answers/_new.html.erb @@ -1,6 +1,6 @@ <%= form_for :model_answer, url: model_answers_path do |f| %>

Previous Answers

-<%= flash[:notice]%> +<%= flash[:notice] %> <% @answers.each do |answer1| %>
diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index 3ad20f58..b043ce0d 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -4,5 +4,5 @@ and a paragraph to view the problem description of the instance variable @proble

<%= @problem.title %>

<%= @problem.description %>

-<%= render partial: "test_cases/index"%> -<%= render partial: "model_answers/new"%> \ No newline at end of file +<%= render partial: "test_cases/index" %> +<%= render partial: "model_answers/new" %> \ No newline at end of file diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index 771930ff..08fac962 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -1,7 +1,7 @@ <%-#Lin: This is a form where the TA can add a test case.It has 2 labels and 2 textfields -%> <%= form_for :test_case , url: test_cases_path do |f| %>

- <%= flash[:notice]%>
+ <%= flash[:notice] %>
<%= f.label :Input %> <%= f.text_field :input %> <%= f.label :Output %> @@ -11,4 +11,4 @@

<%= f.submit 'Add test case' %>

-<% end %> +<% end %> \ No newline at end of file diff --git a/tutor/app/views/test_cases/_index.html.erb b/tutor/app/views/test_cases/_index.html.erb index 038f75fa..14ed1fb0 100644 --- a/tutor/app/views/test_cases/_index.html.erb +++ b/tutor/app/views/test_cases/_index.html.erb @@ -7,4 +7,4 @@ <% end %>
-<%= render partial: "test_cases/form"%> +<%= render partial: "test_cases/form" %> \ No newline at end of file diff --git a/tutor/app/views/test_cases/new.html.erb b/tutor/app/views/test_cases/new.html.erb index 65b98868..a3714026 100644 --- a/tutor/app/views/test_cases/new.html.erb +++ b/tutor/app/views/test_cases/new.html.erb @@ -1,6 +1,6 @@ <%= form_for :test_case , url: test_cases_path do |f| %>

- <%= flash[:notice]%>
+ <%= flash[:notice] %>
<%= f.label :Input %> <%= f.text_field :input %> <%= f.label :Output %> From 2ca2beecb3adf3ca8164fef119b59d19f347cc8a Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Tue, 15 Apr 2014 16:46:15 +0200 Subject: [PATCH 03/11] Issue #208 fixing spaces 2 --- tutor/app/views/problems/edit.html.erb | 16 ++++++++++++++++ tutor/app/views/test_cases/_form.html.erb | 2 +- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index b043ce0d..2c8f9edd 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -3,6 +3,22 @@ and a paragraph to view the problem description of the instance variable @problem -->

<%= @problem.title %>

<%= @problem.description %>

+ +<%= form_for :Problem, url: {action: "create"} do |p| %> +

+ <%= p.label :title %>
+ <%= p.text_field :title %> +

+

+ <%= p.label :description %>
+ <%= p.text_area :description , :cols => "50", :rows => "10" %> +

+ +

+ <%= p.submit %> +

+<% end %> <%= render partial: "test_cases/index" %> <%= render partial: "model_answers/new" %> \ No newline at end of file diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index 08fac962..cbd5ad43 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -5,7 +5,7 @@ <%= f.label :Input %> <%= f.text_field :input %> <%= f.label :Output %> - <%= f.text_field :output %> + <%= f.text_field :output %> <%= f.hidden_field :problem_id, value: params[:id] %>

From 2eb73a55baae257d28ab52b7d4d927853ece782c Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Tue, 15 Apr 2014 16:46:37 +0200 Subject: [PATCH 04/11] Issue #208 fixing spaces 2 --- tutor/app/views/problems/edit.html.erb | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index 2c8f9edd..b043ce0d 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -3,22 +3,6 @@ and a paragraph to view the problem description of the instance variable @problem -->

<%= @problem.title %>

<%= @problem.description %>

- -<%= form_for :Problem, url: {action: "create"} do |p| %> -

- <%= p.label :title %>
- <%= p.text_field :title %> -

-

- <%= p.label :description %>
- <%= p.text_area :description , :cols => "50", :rows => "10" %> -

- -

- <%= p.submit %> -

-<% end %> <%= render partial: "test_cases/index" %> <%= render partial: "model_answers/new" %> \ No newline at end of file From ac8c82bd975eaf45e6b552ae458b4da990956df8 Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Tue, 15 Apr 2014 16:51:47 +0200 Subject: [PATCH 05/11] Issue #208 fixing spaces 3 --- .../controllers/model_answers_controller.rb | 64 +++++++++---------- 1 file changed, 31 insertions(+), 33 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index f814d287..2722973c 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -1,61 +1,59 @@ class ModelAnswersController < ApplicationController -# [Add answer story 4.6] -# It creates the new answer. -# Parameters: -# @answer: the new answer the user enters. -# @answers: All the previous answers that had been entered before. -# Return : none -# Author: Nadine Adel + # [Add answer story 4.6] + # It creates the new answer. + # Parameters: + # @answer: the new answer the user enters. + # @answers: All the previous answers that had been entered before. + # Return : none + # Author: Nadine Adel def new @answers = ModelAnswer.all @answer = ModelAnswer.new end -# [Add answer story 4.6] -# The new answer is saved. -# Parameters: -# @answer:answer provided by the user. -# Returns: Returns a message if the answer is added and another message if answer was not added. -# Author: Nadine Adel + # [Add answer story 4.6] + # The new answer is saved. + # Parameters: + # @answer:answer provided by the user. + # Returns: Returns a message if the answer is added and another message if answer was not added. + # Author: Nadine Adel def create @answer = ModelAnswer.new(post_params) if @answer.save flash[:notice] = "Your Answer is now added" redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id - else flash[:notice] = "Your Answer can not be added" redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id - end end -# [Add answer story 4.6] -# It shows answer that was entered before. -# Parameters: -# @answer:previous answer. -# Return : none -# Author: Nadine Adel + # [Add answer story 4.6] + # It shows answer that was entered before. + # Parameters: + # @answer:previous answer. + # Return : none + # Author: Nadine Adel def show @answer = ModelAnswer.find(params[:problem_id]) end -# [Add answer story 4.6] -# It shows all the answers that are saved in the database. -# Parameters: -# @answers:previous answer that are saved in the database. -# Return : none -# Author: Nadine Adel + # [Add answer story 4.6] + # It shows all the answers that are saved in the database. + # Parameters: + # @answers:previous answer that are saved in the database. + # Return : none + # Author: Nadine Adel def index @answers = ModelAnswer.all end -# [Add answer story 4.6] -# It requires the attributes from the form that we are interested in. -# Parameters: -# @answer:the answer that the user wants to add. -# Return : none -# Author: Nadine Adel + # [Add answer story 4.6] + # It requires the attributes from the form that we are interested in. + # Parameters: + # @answer:the answer that the user wants to add. + # Return : none + # Author: Nadine Adel private def post_params params.require(:model_answer).permit(:answer, :problem_id) From 6ac339e557fee0c30304385f1492efe119e695f2 Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Wed, 16 Apr 2014 12:43:34 +0200 Subject: [PATCH 06/11] Issue #208 #122 #173 adding authentication, linking flash notice & Onwer id initializing --- .../controllers/model_answers_controller.rb | 13 ++++++-- tutor/app/controllers/problems_controller.rb | 19 +++++++++--- .../app/controllers/test_cases_controller.rb | 14 +++++++-- tutor/app/views/model_answers/_new.html.erb | 3 +- tutor/app/views/problems/edit.html.erb | 7 +++-- tutor/app/views/problems/new.html.erb | 30 +++++++++---------- tutor/app/views/test_cases/_form.html.erb | 21 +++++++------ 7 files changed, 67 insertions(+), 40 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index 2722973c..db75fd6e 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -18,10 +18,19 @@ def new # Returns: Returns a message if the answer is added and another message if answer was not added. # Author: Nadine Adel def create - @answer = ModelAnswer.new(post_params) - if @answer.save + if lecturer_signed_in? + @answer = ModelAnswer.new(post_params) + @answer.owner_id = current_lecturer.id + else + if teaching_assistant_signed_in? + @answer = ModelAnswer.new(post_params) + @answer.owner_id = current_teaching_assistant.id + end + end + if @answer.save flash[:notice] = "Your Answer is now added" redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id + else flash[:notice] = "Your Answer can not be added" redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index 86854e07..52e95a41 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -25,6 +25,13 @@ def show # Author: Abdullrahman Elhusseny def create p = Problem.new(permitCreate) + if lecturer_signed_in? + p.owner_id = current_lecturer.id + else + if teaching_assistant_signed_in? + p.owner_id = current_teaching_assistant.id + end + end if p.save redirect_to :action => "edit", :id => p.id else @@ -49,12 +56,16 @@ def permitCreate # Returns: Redirects to edit page on success, refreshes on failure # Author: Abdullrahman Elhusseny def edit - @problem = Problem.find_by_id(params[:id]) - @test_cases = @problem.test_cases - @answers = @problem.model_answers + if lecturer_signed_in? || teaching_assistant_signed_in? + @problem = Problem.find_by_id(params[:id]) + @test_cases = @problem.test_cases + @answers = @problem.model_answers + else + render ('public/404') + end end def new - if lecturer_signed_in? + if lecturer_signed_in? || teaching_assistant_signed_in? render ('new') else render ('public/404') diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index 90d129f1..7ab51538 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -22,12 +22,20 @@ def new # In case of failure a flash notice will appear:"Can't add test case!" # Author: Lin def create - @test_case = TestCase.new(post_params) + if lecturer_signed_in? + @test_case = TestCase.new(post_params) + @test_case.owner_id = current_lecturer.id + else + if teaching_assistant_signed_in? + @test_case = TestCase.new(post_params) + @test_case.owner_id = current_teaching_assistant.id + end + end if @test_case.save - flash[:notice] = "Post created successfully" + flash[:notice] = "Your test case is now added" redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id else - flash[:notice] = "Can't add test case!" + flash[:notice] = "Your test case cannot added" redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id end end diff --git a/tutor/app/views/model_answers/_new.html.erb b/tutor/app/views/model_answers/_new.html.erb index 5add7782..eb0d818e 100644 --- a/tutor/app/views/model_answers/_new.html.erb +++ b/tutor/app/views/model_answers/_new.html.erb @@ -1,13 +1,12 @@ <%= form_for :model_answer, url: model_answers_path do |f| %>

Previous Answers

-<%= flash[:notice] %> <% @answers.each do |answer1| %>
- <% end %> +<% end %>
<%= answer1.answer %>

Please Insert your model answer

diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index b043ce0d..5de71483 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -3,6 +3,9 @@ and a paragraph to view the problem description of the instance variable @problem -->

<%= @problem.title %>

<%= @problem.description %>

- <%= render partial: "test_cases/index" %> -<%= render partial: "model_answers/new" %> \ No newline at end of file +<%= render partial: "model_answers/new" %> + +<% if flash[:notice] %> +
<%= flash[:notice] %>
+<% end %> \ No newline at end of file diff --git a/tutor/app/views/problems/new.html.erb b/tutor/app/views/problems/new.html.erb index b1dbe5cf..704e81a1 100644 --- a/tutor/app/views/problems/new.html.erb +++ b/tutor/app/views/problems/new.html.erb @@ -1,23 +1,21 @@

Add a problem

-
<%= form_for :Problem, url: {action: "create"} do |p| %> -

- <%= p.label :title %>
- <%= p.text_field :title %> -

-

- <%= p.label :description %>
- <%= p.text_area :description , :cols => "50", :rows => "10" %> -

- -

- <%= p.submit %> -

+

+ <%= p.label :title %>
+ <%= p.text_field :title %> +

+

+ <%= p.label :description %>
+ <%= p.text_area :description , :cols => "50", :rows => "10" %> +

+

+ <%= p.submit %> +

<% end %> - <% if flash[:notice] %> -
<%= flash[:notice] %>
- <% end %> \ No newline at end of file +<% if flash[:notice] %> +
<%= flash[:notice] %>
+<% end %> \ No newline at end of file diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index cbd5ad43..6df25186 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -1,14 +1,13 @@ <%-#Lin: This is a form where the TA can add a test case.It has 2 labels and 2 textfields -%> <%= form_for :test_case , url: test_cases_path do |f| %> -

- <%= flash[:notice] %>
- <%= f.label :Input %> - <%= f.text_field :input %> - <%= f.label :Output %> - <%= f.text_field :output %> - <%= f.hidden_field :problem_id, value: params[:id] %> -

-

- <%= f.submit 'Add test case' %> -

+

+ <%= f.label :Input %> + <%= f.text_field :input %> + <%= f.label :Output %> + <%= f.text_field :output %> + <%= f.hidden_field :problem_id, value: params[:id] %> +

+

+ <%= f.submit 'Add test case' %> +

<% end %> \ No newline at end of file From 6963f51d2767728a40622caf5f86e4ae293401cb Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Thu, 17 Apr 2014 21:37:07 +0200 Subject: [PATCH 07/11] Issue #208 #122 #173 Onwer type initializing & fixing indentation --- .../controllers/model_answers_controller.rb | 4 +- tutor/app/controllers/problems_controller.rb | 2 + .../app/controllers/test_cases_controller.rb | 82 ++++++++++--------- tutor/app/views/model_answers/_new.html.erb | 34 ++++---- tutor/app/views/problems/new.html.erb | 20 ++--- tutor/app/views/test_cases/_form.html.erb | 2 +- 6 files changed, 75 insertions(+), 69 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index db75fd6e..a976ab65 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -21,10 +21,12 @@ def create if lecturer_signed_in? @answer = ModelAnswer.new(post_params) @answer.owner_id = current_lecturer.id + @answer.owner_type = "lecturer" else if teaching_assistant_signed_in? @answer = ModelAnswer.new(post_params) @answer.owner_id = current_teaching_assistant.id + @answer.owner_type = "teaching assistant" end end if @answer.save @@ -67,4 +69,4 @@ def index def post_params params.require(:model_answer).permit(:answer, :problem_id) end - end \ No newline at end of file +end \ No newline at end of file diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index 52e95a41..88317202 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -27,9 +27,11 @@ def create p = Problem.new(permitCreate) if lecturer_signed_in? p.owner_id = current_lecturer.id + p.owner_type = "lecturer" else if teaching_assistant_signed_in? p.owner_id = current_teaching_assistant.id + p.owner_type = "teaching assistant" end end if p.save diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index 7ab51538..22cf86a8 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -1,51 +1,53 @@ class TestCasesController < ApplicationController -# [Add test case-story 4.8] -# Shows all the test cases. -# Parameters: None -# Returns:List of all the test cases related to a certain problem. -# Author: Lin -def index - @test_cases = TestCase.all -end -# [Add test case-story 4.8] -# Display the form that is used to add a test case. -# Parameters: None -# Returns: None -# Author: Lin -def new - @test_case = TestCase.new() -end -# [Add test case-story 4.8] -# Saves the new test case into the database.(What the form the 'new' method will submit to) -# Parameters: None -# Returns: In case of success a flash notice will appear:"Post created successfully" -# In case of failure a flash notice will appear:"Can't add test case!" -# Author: Lin -def create + # [Add test case-story 4.8] + # Shows all the test cases. + # Parameters: None + # Returns:List of all the test cases related to a certain problem. + # Author: Lin + def index + @test_cases = TestCase.all + end + # [Add test case-story 4.8] + # Display the form that is used to add a test case. + # Parameters: None + # Returns: None + # Author: Lin + def new + @test_case = TestCase.new() + end + # [Add test case-story 4.8] + # Saves the new test case into the database.(What the form the 'new' method will submit to) + # Parameters: None + # Returns: In case of success a flash notice will appear:"Post created successfully" + # In case of failure a flash notice will appear:"Can't add test case!" + # Author: Lin + def create if lecturer_signed_in? @test_case = TestCase.new(post_params) @test_case.owner_id = current_lecturer.id + @test_case.owner_type = "lecturer" else if teaching_assistant_signed_in? @test_case = TestCase.new(post_params) @test_case.owner_id = current_teaching_assistant.id + @test_case.owner_type = "teaching assistant" end end - if @test_case.save - flash[:notice] = "Your test case is now added" - redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id - else - flash[:notice] = "Your test case cannot added" - redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id - end -end -# [Add test case-story 4.8] -# private method. Controls the test case parameters that can be accessed. -# Parameters: None -# Returns: None -# Author: Lin -private -def post_params - params.require(:test_case).permit(:input, :output, :problem_id) -end + if @test_case.save + flash[:notice] = "Your test case is now added" + redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id + else + flash[:notice] = "Your test case cannot added" + redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id + end + end + # [Add test case-story 4.8] + # private method. Controls the test case parameters that can be accessed. + # Parameters: None + # Returns: None + # Author: Lin + private + def post_params + params.require(:test_case).permit(:input, :output, :problem_id) + end end \ No newline at end of file diff --git a/tutor/app/views/model_answers/_new.html.erb b/tutor/app/views/model_answers/_new.html.erb index eb0d818e..c2f3721f 100644 --- a/tutor/app/views/model_answers/_new.html.erb +++ b/tutor/app/views/model_answers/_new.html.erb @@ -1,19 +1,19 @@ <%= form_for :model_answer, url: model_answers_path do |f| %> -

Previous Answers

- - <% @answers.each do |answer1| %> -
- - - -<% end %> -
<%= answer1.answer %>
-

-

Please Insert your model answer

- <%= f.text_area :answer %> - <%= f.hidden_field :problem_id, value: params[:id] %> -

-

- <%= f.submit %> -

+

Previous Answers

+ + <% @answers.each do |answer1| %> +
+ + + + <% end %> +
<%= answer1.answer %>
+

+

Please Insert your model answer

+ <%= f.text_area :answer %> + <%= f.hidden_field :problem_id, value: params[:id] %> +

+

+ <%= f.submit %> +

<% end %> \ No newline at end of file diff --git a/tutor/app/views/problems/new.html.erb b/tutor/app/views/problems/new.html.erb index 704e81a1..3b0ca32b 100644 --- a/tutor/app/views/problems/new.html.erb +++ b/tutor/app/views/problems/new.html.erb @@ -4,16 +4,16 @@ through two text fields :title and description --> <%= form_for :Problem, url: {action: "create"} do |p| %>

- <%= p.label :title %>
- <%= p.text_field :title %> -

-

- <%= p.label :description %>
- <%= p.text_area :description , :cols => "50", :rows => "10" %> -

-

- <%= p.submit %> -

+ <%= p.label :title %>
+ <%= p.text_field :title %> +

+

+ <%= p.label :description %>
+ <%= p.text_area :description , :cols => "50", :rows => "10" %> +

+

+ <%= p.submit %> +

<% end %> <% if flash[:notice] %> diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index 6df25186..2b0f6a6c 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -1,6 +1,6 @@ <%-#Lin: This is a form where the TA can add a test case.It has 2 labels and 2 textfields -%> <%= form_for :test_case , url: test_cases_path do |f| %> -

+

<%= f.label :Input %> <%= f.text_field :input %> <%= f.label :Output %> From 022746516f955820e85c0933255762ec75ca69aa Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Thu, 17 Apr 2014 23:14:12 +0200 Subject: [PATCH 08/11] Issue #208 #122 #173 documentation modif. --- tutor/app/controllers/problems_controller.rb | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index 88317202..aab7a191 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -66,6 +66,13 @@ def edit render ('public/404') end end + # [Edit Problem - 4.5] + # Checks if a lecturer or TA is signed in and shows the problem's add page(title & description) + # on success and renders 404 on failure + # Parameters: + # none + # Returns: Redirects to add page on success or 404 on failure + # Author: Abdullrahman Elhusseny def new if lecturer_signed_in? || teaching_assistant_signed_in? render ('new') From d3be6b68f575d3216946dfc3640eb95a9955b48b Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Fri, 18 Apr 2014 19:53:39 +0200 Subject: [PATCH 09/11] Issue #208 #122 #173 using elsif --- tutor/app/controllers/model_answers_controller.rb | 10 ++++------ tutor/app/controllers/problems_controller.rb | 8 +++----- tutor/app/controllers/test_cases_controller.rb | 10 ++++------ 3 files changed, 11 insertions(+), 17 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index a976ab65..9fc21ce6 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -22,12 +22,10 @@ def create @answer = ModelAnswer.new(post_params) @answer.owner_id = current_lecturer.id @answer.owner_type = "lecturer" - else - if teaching_assistant_signed_in? - @answer = ModelAnswer.new(post_params) - @answer.owner_id = current_teaching_assistant.id - @answer.owner_type = "teaching assistant" - end + elsif teaching_assistant_signed_in? + @answer = ModelAnswer.new(post_params) + @answer.owner_id = current_teaching_assistant.id + @answer.owner_type = "teaching assistant" end if @answer.save flash[:notice] = "Your Answer is now added" diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index aab7a191..8d82d064 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -28,11 +28,9 @@ def create if lecturer_signed_in? p.owner_id = current_lecturer.id p.owner_type = "lecturer" - else - if teaching_assistant_signed_in? - p.owner_id = current_teaching_assistant.id - p.owner_type = "teaching assistant" - end + elsif teaching_assistant_signed_in? + p.owner_id = current_teaching_assistant.id + p.owner_type = "teaching assistant" end if p.save redirect_to :action => "edit", :id => p.id diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index 22cf86a8..83702973 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -26,12 +26,10 @@ def create @test_case = TestCase.new(post_params) @test_case.owner_id = current_lecturer.id @test_case.owner_type = "lecturer" - else - if teaching_assistant_signed_in? - @test_case = TestCase.new(post_params) - @test_case.owner_id = current_teaching_assistant.id - @test_case.owner_type = "teaching assistant" - end + elsif teaching_assistant_signed_in? + @test_case = TestCase.new(post_params) + @test_case.owner_id = current_teaching_assistant.id + @test_case.owner_type = "teaching assistant" end if @test_case.save flash[:notice] = "Your test case is now added" From 12126c1ada00dc244e5936dd6731c75a5dacc63c Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Fri, 18 Apr 2014 20:44:07 +0200 Subject: [PATCH 10/11] Issue #208 #122 #173 fixing spaces and tabs --- .../controllers/model_answers_controller.rb | 21 ++++----- tutor/app/controllers/problems_controller.rb | 46 +++++++++---------- .../app/controllers/test_cases_controller.rb | 20 ++++---- tutor/app/views/test_cases/_form.html.erb | 2 +- 4 files changed, 44 insertions(+), 45 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index 9fc21ce6..4bb40582 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -1,7 +1,7 @@ class ModelAnswersController < ApplicationController # [Add answer story 4.6] # It creates the new answer. - # Parameters: + # Parameters: # @answer: the new answer the user enters. # @answers: All the previous answers that had been entered before. # Return : none @@ -12,13 +12,13 @@ def new end # [Add answer story 4.6] - # The new answer is saved. + # The new answer is saved. # Parameters: # @answer:answer provided by the user. # Returns: Returns a message if the answer is added and another message if answer was not added. # Author: Nadine Adel def create - if lecturer_signed_in? + if lecturer_signed_in? @answer = ModelAnswer.new(post_params) @answer.owner_id = current_lecturer.id @answer.owner_type = "lecturer" @@ -27,10 +27,9 @@ def create @answer.owner_id = current_teaching_assistant.id @answer.owner_type = "teaching assistant" end - if @answer.save + if @answer.save flash[:notice] = "Your Answer is now added" redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id - else flash[:notice] = "Your Answer can not be added" redirect_to :controller => 'problems', :action => 'edit', :id => @answer.problem_id @@ -38,8 +37,8 @@ def create end # [Add answer story 4.6] - # It shows answer that was entered before. - # Parameters: + # It shows answer that was entered before. + # Parameters: # @answer:previous answer. # Return : none # Author: Nadine Adel @@ -48,8 +47,8 @@ def show end # [Add answer story 4.6] - # It shows all the answers that are saved in the database. - # Parameters: + # It shows all the answers that are saved in the database. + # Parameters: # @answers:previous answer that are saved in the database. # Return : none # Author: Nadine Adel @@ -58,8 +57,8 @@ def index end # [Add answer story 4.6] - # It requires the attributes from the form that we are interested in. - # Parameters: + # It requires the attributes from the form that we are interested in. + # Parameters: # @answer:the answer that the user wants to add. # Return : none # Author: Nadine Adel diff --git a/tutor/app/controllers/problems_controller.rb b/tutor/app/controllers/problems_controller.rb index d3d0b66d..fbe1a307 100644 --- a/tutor/app/controllers/problems_controller.rb +++ b/tutor/app/controllers/problems_controller.rb @@ -18,7 +18,7 @@ def show # [Add Problem - 4.4] # Creates a new record to Problem Table - # Parameters: + # Parameters: # title: problem's title through permitCreate action # description: problem's description through permitCreate action # Returns: Redirects to edit page on success, refreshes on failure @@ -32,53 +32,53 @@ def create p.owner_id = current_teaching_assistant.id p.owner_type = "teaching assistant" end - if p.save - redirect_to :action => "edit", :id => p.id + if p.save + redirect_to :action => "edit", :id => p.id else - flash.keep[:notice] = "Problem is missing paramaters" + flash.keep[:notice] = "Problem is missing paramaters" redirect_to :back end end # [Add Problem - 4.4] # Passes the input of the form as paramaters for create action to use it - # Parameters: + # Parameters: # title: problem's title # description: problem's description # Returns: params to create action # Author: Abdullrahman Elhusseny def permitCreate - params.require(:Problem).permit(:title , :description) - end + params.require(:Problem).permit(:title , :description) + end # [Edit Problem - 4.5] # Shows the problem's title and description (Further development is in Sprint 1) - # Parameters: + # Parameters: # id: The id of the problem to be edited or newly created # Returns: Redirects to edit page on success, refreshes on failure # Author: Abdullrahman Elhusseny def edit if lecturer_signed_in? || teaching_assistant_signed_in? - @problem = Problem.find_by_id(params[:id]) - @test_cases = @problem.test_cases - @answers = @problem.model_answers - else - render ('public/404') - end - end + @problem = Problem.find_by_id(params[:id]) + @test_cases = @problem.test_cases + @answers = @problem.model_answers + else + render ('public/404') + end + end - # [Edit Problem - 4.5] + # [Edit Problem - 4.5] # Checks if a lecturer or TA is signed in and shows the problem's add page(title & description) # on success and renders 404 on failure - # Parameters: - # none + # Parameters: + # none # Returns: Redirects to add page on success or 404 on failure # Author: Abdullrahman Elhusseny - def new - if lecturer_signed_in? || teaching_assistant_signed_in? - render ('new') - else + def new + if lecturer_signed_in? || teaching_assistant_signed_in? + render ('new') + else render ('public/404') - end + end end end \ No newline at end of file diff --git a/tutor/app/controllers/test_cases_controller.rb b/tutor/app/controllers/test_cases_controller.rb index bd9a2161..2875de54 100644 --- a/tutor/app/controllers/test_cases_controller.rb +++ b/tutor/app/controllers/test_cases_controller.rb @@ -3,28 +3,28 @@ class TestCasesController < ApplicationController # Shows all the test cases. # Parameters: None # Returns:List of all the test cases related to a certain problem. - # Author: Lin - def index + # Author: Lin + def index @test_cases = TestCase.all end # [Add test case-story 4.8] - # Display the form that is used to add a test case. + # Display the form that is used to add a test case. # Parameters: None # Returns: None - # Author: Lin - def new - @test_case = TestCase.new() + # Author: Lin + def new + @test_case = TestCase.new() end # [Add test case-story 4.8] - # Saves the new test case into the database.(What the form the 'new' method will submit to) + # Saves the new test case into the database.(What the form the 'new' method will submit to) # Parameters: None # Returns: In case of success a flash notice will appear:"Post created successfully" # In case of failure a flash notice will appear:"Can't add test case!" # Author: Lin def create - if lecturer_signed_in? + if lecturer_signed_in? @test_case = TestCase.new(post_params) @test_case.owner_id = current_lecturer.id @test_case.owner_type = "lecturer" @@ -39,9 +39,9 @@ def create else flash[:notice] = "Your test case cannot added" redirect_to :controller => 'problems', :action => 'edit', :id => @test_case.problem_id - end + end end - + # [Add test case-story 4.8] # private method. Controls the test case parameters that can be accessed. # Parameters: None diff --git a/tutor/app/views/test_cases/_form.html.erb b/tutor/app/views/test_cases/_form.html.erb index 2b0f6a6c..6df25186 100644 --- a/tutor/app/views/test_cases/_form.html.erb +++ b/tutor/app/views/test_cases/_form.html.erb @@ -1,6 +1,6 @@ <%-#Lin: This is a form where the TA can add a test case.It has 2 labels and 2 textfields -%> <%= form_for :test_case , url: test_cases_path do |f| %> -

+

<%= f.label :Input %> <%= f.text_field :input %> <%= f.label :Output %> From b3f7a755f5d2c40b6cb56308cc1be47e6f4ce19a Mon Sep 17 00:00:00 2001 From: AbdullRahman ElHusseini Date: Fri, 18 Apr 2014 20:49:30 +0200 Subject: [PATCH 11/11] Issue #208 #122 #173 fixing spaces and tabs 2 --- tutor/app/controllers/model_answers_controller.rb | 2 +- tutor/app/views/problems/edit.html.erb | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/tutor/app/controllers/model_answers_controller.rb b/tutor/app/controllers/model_answers_controller.rb index 4bb40582..f1f15621 100644 --- a/tutor/app/controllers/model_answers_controller.rb +++ b/tutor/app/controllers/model_answers_controller.rb @@ -13,7 +13,7 @@ def new # [Add answer story 4.6] # The new answer is saved. - # Parameters: + # Parameters: # @answer:answer provided by the user. # Returns: Returns a message if the answer is added and another message if answer was not added. # Author: Nadine Adel diff --git a/tutor/app/views/problems/edit.html.erb b/tutor/app/views/problems/edit.html.erb index 5de71483..61b4f592 100644 --- a/tutor/app/views/problems/edit.html.erb +++ b/tutor/app/views/problems/edit.html.erb @@ -1,11 +1,11 @@ -

<%= @problem.title %>

<%= @problem.description %>

<%= render partial: "test_cases/index" %> <%= render partial: "model_answers/new" %> - + <% if flash[:notice] %>
<%= flash[:notice] %>
<% end %> \ No newline at end of file