Skip to content

Commit

Permalink
Merge pull request #228 from alaashafaee/C4_Husseny_208_edit_problem_4.5
Browse files Browse the repository at this point in the history
Merging (Issues #208 #122 #173 Linking to adding test cases & answers) for @husseny
  • Loading branch information
rami-khalil committed Apr 18, 2014
2 parents fedd560 + b3f7a75 commit bbdb841
Show file tree
Hide file tree
Showing 10 changed files with 188 additions and 145 deletions.
82 changes: 45 additions & 37 deletions tutor/app/controllers/model_answers_controller.rb
Original file line number Diff line number Diff line change
@@ -1,61 +1,69 @@
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 lecturer_signed_in?
@answer = ModelAnswer.new(post_params)
@answer.owner_id = current_lecturer.id
@answer.owner_type = "lecturer"
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"
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
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)
params.require(:model_answer).permit(:answer, :problem_id)
end
end
end
52 changes: 36 additions & 16 deletions tutor/app/controllers/problems_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,47 +18,67 @@ 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
# Author: Abdullrahman Elhusseny
def create
p = Problem.new(permitCreate)
if p.save
redirect_to :action => "edit", :id => p.id
if lecturer_signed_in?
p.owner_id = current_lecturer.id
p.owner_type = "lecturer"
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
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
@problem = Problem.find_by_id(params[:id])
end
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?
render ('new')
else
# [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')
else
render ('public/404')
end
end
end
end
end
95 changes: 53 additions & 42 deletions tutor/app/controllers/test_cases_controller.rb
Original file line number Diff line number Diff line change
@@ -1,43 +1,54 @@
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
@test_case = TestCase.new(post_params)
if @test_case.save
flash[:notice] = "Post created successfully"
redirect_to :back
else
flash[:notice] = "Can't add test case!"
redirect_to :back
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)
end
end
# [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"
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"
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
19 changes: 19 additions & 0 deletions tutor/app/views/model_answers/_new.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<%= form_for :model_answer, url: model_answers_path do |f| %>
<h1>Previous Answers</h1>
<table>
<% @answers.each do |answer1| %>
<table border ="1">
<tr>
<td><%= answer1.answer %></td>
</tr>
<% end %>
</table>
<p>
<h2>Please Insert your model answer</h2>
<%= f.text_area :answer %>
<%= f.hidden_field :problem_id, value: params[:id] %>
</p>
<p>
<%= f.submit %>
</p>
<% end %>
19 changes: 0 additions & 19 deletions tutor/app/views/model_answers/new.html.erb

This file was deleted.

10 changes: 8 additions & 2 deletions tutor/app/views/problems/edit.html.erb
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
<!-- The html web page consists of two tags
<!-- The html web page consists of two tags
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 -->
<h2 align ="center"><%= @problem.title %></h2>
<p><%= @problem.description %></p>
<p><%= @problem.description %></p>
<%= render partial: "test_cases/index" %>
<%= render partial: "model_answers/new" %>
<!-- A division for the flash message output to view the action's output -->
<% if flash[:notice] %>
<div class="notice"><%= flash[:notice] %></div>
<% end %>
30 changes: 14 additions & 16 deletions tutor/app/views/problems/new.html.erb
Original file line number Diff line number Diff line change
@@ -1,23 +1,21 @@
<h1 align ="center">Add a problem</h1>

<br>
<!--A form that takes the input for the model Problem and calls the action create
through two text fields :title and description -->
<%= form_for :Problem, url: {action: "create"} do |p| %>
<p>
<%= p.label :title %><br>
<%= p.text_field :title %>
</p>
<p>
<%= p.label :description %><br>
<%= p.text_area :description , :cols => "50", :rows => "10" %>
</p>

<p>
<%= p.submit %>
</p>
<p>
<%= p.label :title %><br>
<%= p.text_field :title %>
</p>
<p>
<%= p.label :description %><br>
<%= p.text_area :description , :cols => "50", :rows => "10" %>
</p>
<p>
<%= p.submit %>
</p>
<% end %>
<!-- A division for the flash message output to view the action's output -->
<% if flash[:notice] %>
<div class="notice"><%= flash[:notice] %></div>
<% end %>
<% if flash[:notice] %>
<div class="notice"><%= flash[:notice] %></div>
<% end %>
Loading

0 comments on commit bbdb841

Please sign in to comment.