-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #228 from alaashafaee/C4_Husseny_208_edit_problem_4.5
- Loading branch information
Showing
10 changed files
with
188 additions
and
145 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 %> |
Oops, something went wrong.