From 02da442f5f8c21730570dd5c74d56367f93d0f69 Mon Sep 17 00:00:00 2001 From: Mimi Date: Mon, 21 Apr 2014 23:45:23 +0200 Subject: [PATCH 01/17] addin hints controller and its view --- tutor/app/controllers/hints_controller.rb | 45 +++++++++++++++++++++++ tutor/app/views/hints/show.html.erb | 19 ++++++++++ tutor/config/routes.rb | 1 + 3 files changed, 65 insertions(+) create mode 100644 tutor/app/controllers/hints_controller.rb create mode 100644 tutor/app/views/hints/show.html.erb diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb new file mode 100644 index 00000000..e36e12a5 --- /dev/null +++ b/tutor/app/controllers/hints_controller.rb @@ -0,0 +1,45 @@ +class HintsController < ApplicationController + #t.text "message" + #t.boolean "category" + #t.integer "submission_counter" + #t.integer "model_answer_id" + #t.integer "owner_id" + #t.string "owner_type" + + + def show + @new_Tip = Problem.find_by_id(params[:id]) + end + + # [Edit helping hints - Story 4.13 ] + # Description: This action takes the passed parameters from + # the creation form, creates a new Hint record + # and assigns it to the respective problem. If the + # creation fails the user is redirected to the form + # with a "Failed" message. + # Parameters: + # hint_params[]: A list that has all fields entered by the user to in the + # create_topic_form + # Returns: + # flash[:notice]: A message indicating the success or failure of the creation + # Author: Mimi + def create + @new_Tip = Hint.new(hint_params) + bool = @new_Tip.save + if bool == true + flash[:notice] = "Hint successfully created" + #redirect_to :action => 'create' + redirect_to :back + else + if @new_Tip.errors.any? + flash[:notice] = @new_Tip.errors.full_messages.first + end + redirect_to :back + end + end + + private + def hint_params + params.require(:hint).permit(:message,:submission_counter) + end +end diff --git a/tutor/app/views/hints/show.html.erb b/tutor/app/views/hints/show.html.erb new file mode 100644 index 00000000..b38a2bb6 --- /dev/null +++ b/tutor/app/views/hints/show.html.erb @@ -0,0 +1,19 @@ +<% if flash[:notice] -%> +
<%= flash[:notice] %>
+ <% end %> +


+ + <%= form_for :hint, url: { :controller => "hints",action: "create"} do |f| %> +

+ <%= f.label "text" %>
+ <%= f.text_field :message, autofocus: true, class:"form-control", style: "width:300px", placeholder: "text", value: params[:message] %> +

+

+ <%= f.label :"The number of wrong submissions that hint appears after" %>
+ <%= f.text_area :submission_counter, class:"form-control", style: "margin-left:auto; + margin-right:auto;height:50px;width:500px;resize:none", value:params[:submission_counter] %> +

+

+ <%= f.submit "Save", class: "btn btn-success"%> +

+<% end %> \ No newline at end of file diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index e9d7079c..ee73ee70 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -29,6 +29,7 @@ resources :solutions resources :problems resources :topics + resources :hints # Example resource route with options: # resources :products do From 0d447e031f717b73f60117dfde5e55757356be3b Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 00:02:59 +0200 Subject: [PATCH 02/17] Adding validations for the hint model --- tutor/app/controllers/hints_controller.rb | 2 ++ tutor/app/models/hint.rb | 5 ++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index e36e12a5..be440573 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -25,6 +25,7 @@ def show # Author: Mimi def create @new_Tip = Hint.new(hint_params) + @new_Tip.category = false bool = @new_Tip.save if bool == true flash[:notice] = "Hint successfully created" @@ -34,6 +35,7 @@ def create if @new_Tip.errors.any? flash[:notice] = @new_Tip.errors.full_messages.first end + #render "create" redirect_to :back end end diff --git a/tutor/app/models/hint.rb b/tutor/app/models/hint.rb index 660b3fb9..2716fbc5 100644 --- a/tutor/app/models/hint.rb +++ b/tutor/app/models/hint.rb @@ -1,11 +1,14 @@ class Hint < ActiveRecord::Base #Validations + validates :message, presence: true + validates :submission_counter, presence: true, numericality: {only_integer: true, greater_than_or_equal_to: 0, + message: "is not valid"} #Relations belongs_to :model_answer belongs_to :owner, polymorphic: true - + #Scoops #Methods From 3678bba4e854a2316eb30c02fe4cf335d85066fb Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 13:22:12 +0200 Subject: [PATCH 03/17] modifying hintsCntroller --- tutor/app/controllers/hints_controller.rb | 27 +++++++++-------------- tutor/app/views/hints/show.html.erb | 4 ++-- 2 files changed, 12 insertions(+), 19 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index be440573..89d7681b 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -1,39 +1,32 @@ class HintsController < ApplicationController - #t.text "message" - #t.boolean "category" - #t.integer "submission_counter" - #t.integer "model_answer_id" - #t.integer "owner_id" - #t.string "owner_type" - def show - @new_Tip = Problem.find_by_id(params[:id]) + @new_Tip = Hint.find_by_id(params[:id]) end # [Edit helping hints - Story 4.13 ] # Description: This action takes the passed parameters from - # the creation form, creates a new Hint record - # and assigns it to the respective problem. If the - # creation fails the user is redirected to the form + # the creation form, edits a Hint record + # which assigned to the respective problem. If the + # edit fails the user is redirected to the form # with a "Failed" message. # Parameters: # hint_params[]: A list that has all fields entered by the user to in the # create_topic_form # Returns: - # flash[:notice]: A message indicating the success or failure of the creation + # flash[:notice]: A message indicating the success or failure of the edit # Author: Mimi def create - @new_Tip = Hint.new(hint_params) - @new_Tip.category = false + @new_Tip = Hint.find_by_id(params[:id]) + @new_Tip.message = hint_params[:message] + @new_Tip.submission_counter = hint_params[:submission_counter] bool = @new_Tip.save if bool == true - flash[:notice] = "Hint successfully created" - #redirect_to :action => 'create' + flash[:notice] = "Hint successfully edited" redirect_to :back else if @new_Tip.errors.any? - flash[:notice] = @new_Tip.errors.full_messages.first + flash[:notice] = @new_Tip.errors.full_messages.first end #render "create" redirect_to :back diff --git a/tutor/app/views/hints/show.html.erb b/tutor/app/views/hints/show.html.erb index b38a2bb6..e5d29072 100644 --- a/tutor/app/views/hints/show.html.erb +++ b/tutor/app/views/hints/show.html.erb @@ -6,12 +6,12 @@ <%= form_for :hint, url: { :controller => "hints",action: "create"} do |f| %>

<%= f.label "text" %>
- <%= f.text_field :message, autofocus: true, class:"form-control", style: "width:300px", placeholder: "text", value: params[:message] %> + <%= f.text_field :message, autofocus: true, class:"form-control", style: "width:300px", placeholder: Hint.find_by_id(params[:id]).message, value: params[:message] %>

<%= f.label :"The number of wrong submissions that hint appears after" %>
<%= f.text_area :submission_counter, class:"form-control", style: "margin-left:auto; - margin-right:auto;height:50px;width:500px;resize:none", value:params[:submission_counter] %> + margin-right:auto;height:50px;width:500px;resize:none",placeholder: Hint.find_by_id(params[:id]).submission_counter, value:params[:submission_counter] %>

<%= f.submit "Save", class: "btn btn-success"%> From 3a27c1cddebcceaf650cefd8e239bd5940adfeb6 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 16:00:32 +0200 Subject: [PATCH 04/17] modify hint controller wen show view and add the route --- tutor/app/controllers/hints_controller.rb | 7 +++---- tutor/app/views/hints/show.html.erb | 25 +++++++++++++---------- tutor/config/routes.rb | 2 +- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 89d7681b..65bee09d 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -16,8 +16,8 @@ def show # Returns: # flash[:notice]: A message indicating the success or failure of the edit # Author: Mimi - def create - @new_Tip = Hint.find_by_id(params[:id]) + def edit + @new_Tip = Hint.find_by_id(hint_params[:id]) @new_Tip.message = hint_params[:message] @new_Tip.submission_counter = hint_params[:submission_counter] bool = @new_Tip.save @@ -28,13 +28,12 @@ def create if @new_Tip.errors.any? flash[:notice] = @new_Tip.errors.full_messages.first end - #render "create" redirect_to :back end end private def hint_params - params.require(:hint).permit(:message,:submission_counter) + params.require(:hint).permit(:message,:submission_counter,:id) end end diff --git a/tutor/app/views/hints/show.html.erb b/tutor/app/views/hints/show.html.erb index e5d29072..ac156c15 100644 --- a/tutor/app/views/hints/show.html.erb +++ b/tutor/app/views/hints/show.html.erb @@ -1,19 +1,22 @@ <% if flash[:notice] -%> -

<%= flash[:notice] %>
- <% end %> -


- - <%= form_for :hint, url: { :controller => "hints",action: "create"} do |f| %> +
+ <%= flash[:notice] %> +
+<% end %> +
+
+
+ +<%= form_for :hint,url:{:controller => "hints",action:"edit"} do |f| %> + <%= f.hidden_field :id , value: params[:id] %>

- <%= f.label "text" %>
- <%= f.text_field :message, autofocus: true, class:"form-control", style: "width:300px", placeholder: Hint.find_by_id(params[:id]).message, value: params[:message] %> + <%= f.label "Hint description" %>
+ <%= f.text_area :message, :cols => "100" , :rows => "8",autofocus:true,class:"form-control",style:"width:300px",value:Hint.find_by_id(params[:id]).message %>

<%= f.label :"The number of wrong submissions that hint appears after" %>
- <%= f.text_area :submission_counter, class:"form-control", style: "margin-left:auto; - margin-right:auto;height:50px;width:500px;resize:none",placeholder: Hint.find_by_id(params[:id]).submission_counter, value:params[:submission_counter] %> -

+ <%= f.text_area :submission_counter, :rows => "1", class:"form-control", style: "width:300px",value:Hint.find_by_id(params[:id]).submission_counter %>

- <%= f.submit "Save", class: "btn btn-success"%> + <%= f.submit"Save",class:"btn btn-success"%>

<% end %> \ No newline at end of file diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index ee73ee70..2e82e850 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -11,6 +11,7 @@ # get 'products/:id' => 'catalog#view' # get 'products/index' post 'courses/new' => 'courses#new' + post '/hints/:id' => 'hints#edit' get 'courses/sign_up' @@ -30,7 +31,6 @@ resources :problems resources :topics resources :hints - # Example resource route with options: # resources :products do # member do From 3bda4ee5b074872d398e51d3f42cd119f6ea8430 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 16:47:47 +0200 Subject: [PATCH 05/17] method documentation --- tutor/app/controllers/hints_controller.rb | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 65bee09d..33e4741d 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -1,9 +1,15 @@ class HintsController < ApplicationController - + # [Edit helping hints - Story 4.13 ] + # Description: This action creates the form and retrives the data of the selected problem + # to be being edited + # Parameters: + # ID of the hint + # Returns: + # none + # Author: Mimi def show @new_Tip = Hint.find_by_id(params[:id]) end - # [Edit helping hints - Story 4.13 ] # Description: This action takes the passed parameters from # the creation form, edits a Hint record @@ -31,9 +37,15 @@ def edit redirect_to :back end end - + # [Edit helping hints - Story 4.13 ] + # Description: + # take the parameters from the from + # Parameters: + # none + # Returns: + # Author: Mimi private def hint_params params.require(:hint).permit(:message,:submission_counter,:id) end -end +end \ No newline at end of file From ef07314e21de42c878e4941f71111b142d784bb4 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 17:43:31 +0200 Subject: [PATCH 06/17] modify controller hint --- tutor/app/controllers/hints_controller.rb | 23 ++++++++++--------- .../hints/{show.html.erb => edit.html.erb} | 2 +- tutor/app/views/model_answers/edit.html.erb | 1 + tutor/config/routes.rb | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) rename tutor/app/views/hints/{show.html.erb => edit.html.erb} (90%) create mode 100644 tutor/app/views/model_answers/edit.html.erb diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 33e4741d..64d14d10 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -7,9 +7,9 @@ class HintsController < ApplicationController # Returns: # none # Author: Mimi - def show + def edit @new_Tip = Hint.find_by_id(params[:id]) - end + end # [Edit helping hints - Story 4.13 ] # Description: This action takes the passed parameters from # the creation form, edits a Hint record @@ -17,26 +17,27 @@ def show # edit fails the user is redirected to the form # with a "Failed" message. # Parameters: - # hint_params[]: A list that has all fields entered by the user to in the - # create_topic_form + # hint_params[]: A list that has all fields entered by the user to in the + # edit_hint form # Returns: - # flash[:notice]: A message indicating the success or failure of the edit - # Author: Mimi - def edit + # flash[:notice]: A message indicating the success or failure of the edit + # Author: Mimi + def update @new_Tip = Hint.find_by_id(hint_params[:id]) @new_Tip.message = hint_params[:message] @new_Tip.submission_counter = hint_params[:submission_counter] + @model_answer = @new_Tip.model_answer_id bool = @new_Tip.save if bool == true - flash[:notice] = "Hint successfully edited" - redirect_to :back + flash[:notice] = "Hint successfully edited" + redirect_to :controller => 'model_answers', :action => 'edit',:id => @model_answer else if @new_Tip.errors.any? - flash[:notice] = @new_Tip.errors.full_messages.first + flash[:notice] = @new_Tip.errors.full_messages.first end redirect_to :back end - end + end # [Edit helping hints - Story 4.13 ] # Description: # take the parameters from the from diff --git a/tutor/app/views/hints/show.html.erb b/tutor/app/views/hints/edit.html.erb similarity index 90% rename from tutor/app/views/hints/show.html.erb rename to tutor/app/views/hints/edit.html.erb index ac156c15..ceb7f83a 100644 --- a/tutor/app/views/hints/show.html.erb +++ b/tutor/app/views/hints/edit.html.erb @@ -7,7 +7,7 @@

-<%= form_for :hint,url:{:controller => "hints",action:"edit"} do |f| %> +<%= form_for @new_Tip,url:{:controller => "hints",action:"update"} do |f| %> <%= f.hidden_field :id , value: params[:id] %>

<%= f.label "Hint description" %>
diff --git a/tutor/app/views/model_answers/edit.html.erb b/tutor/app/views/model_answers/edit.html.erb new file mode 100644 index 00000000..9ee4edcf --- /dev/null +++ b/tutor/app/views/model_answers/edit.html.erb @@ -0,0 +1 @@ +

NADINE

\ No newline at end of file diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index 2e82e850..78fa83bc 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -11,7 +11,7 @@ # get 'products/:id' => 'catalog#view' # get 'products/index' post 'courses/new' => 'courses#new' - post '/hints/:id' => 'hints#edit' + #post '/hints/:id/edit' => 'hints#edit' get 'courses/sign_up' From 1957ba091883c72a1fcc6090d450d29586284710 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 17:44:55 +0200 Subject: [PATCH 07/17] modify route --- tutor/config/routes.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index 78fa83bc..6d5ab96d 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -11,7 +11,6 @@ # get 'products/:id' => 'catalog#view' # get 'products/index' post 'courses/new' => 'courses#new' - #post '/hints/:id/edit' => 'hints#edit' get 'courses/sign_up' From 7a13a21fd62dd945c3a89d54269b1c26076a7fa0 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 18:35:17 +0200 Subject: [PATCH 08/17] #212 , adjust identation and documentation --- tutor/app/controllers/hints_controller.rb | 37 ++++++++++++----------- tutor/app/models/hint.rb | 11 ++----- tutor/app/views/hints/edit.html.erb | 6 ++-- tutor/config/routes.rb | 1 + 4 files changed, 27 insertions(+), 28 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 64d14d10..9b6867ae 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -1,27 +1,28 @@ class HintsController < ApplicationController # [Edit helping hints - Story 4.13 ] - # Description: This action creates the form and retrives the data of the selected problem - # to be being edited + # This action creates the form and retrives the data of the selected problem + # to be being edited # Parameters: - # ID of the hint + # ID of the hint # Returns: - # none + # none # Author: Mimi def edit @new_Tip = Hint.find_by_id(params[:id]) end + # [Edit helping hints - Story 4.13 ] - # Description: This action takes the passed parameters from - # the creation form, edits a Hint record - # which assigned to the respective problem. If the - # edit fails the user is redirected to the form - # with a "Failed" message. + # This action takes the passed parameters from + # the creation form, edits a Hint record + # which assigned to the respective problem. If the + # edit fails the user is redirected to the form + # with a "Failed" message. # Parameters: - # hint_params[]: A list that has all fields entered by the user to in the - # edit_hint form + # hint_params[]: A list that has all fields entered by the user to in the + # edit_hint form # Returns: - # flash[:notice]: A message indicating the success or failure of the edit - # Author: Mimi + # flash[:notice]: A message indicating the success or failure of the edit + # Author: Mimi def update @new_Tip = Hint.find_by_id(hint_params[:id]) @new_Tip.message = hint_params[:message] @@ -29,8 +30,8 @@ def update @model_answer = @new_Tip.model_answer_id bool = @new_Tip.save if bool == true - flash[:notice] = "Hint successfully edited" - redirect_to :controller => 'model_answers', :action => 'edit',:id => @model_answer + flash[:notice] = "Hint successfully edited" + redirect_to :controller => 'model_answers', :action => 'edit',:id => @model_answer else if @new_Tip.errors.any? flash[:notice] = @new_Tip.errors.full_messages.first @@ -38,12 +39,14 @@ def update redirect_to :back end end + # [Edit helping hints - Story 4.13 ] # Description: - # take the parameters from the from + # take the parameters from the from # Parameters: # none - # Returns: + # Returns: + # Hash of paramas # Author: Mimi private def hint_params diff --git a/tutor/app/models/hint.rb b/tutor/app/models/hint.rb index 2716fbc5..7517bede 100644 --- a/tutor/app/models/hint.rb +++ b/tutor/app/models/hint.rb @@ -1,16 +1,11 @@ class Hint < ActiveRecord::Base - + #Validations validates :message, presence: true - validates :submission_counter, presence: true, numericality: {only_integer: true, greater_than_or_equal_to: 0, - message: "is not valid"} + validates :submission_counter, presence: true, numericality: { + only_integer: true, greater_than_or_equal_to: 0, message: "is not valid"} #Relations belongs_to :model_answer belongs_to :owner, polymorphic: true - - #Scoops - - #Methods - end diff --git a/tutor/app/views/hints/edit.html.erb b/tutor/app/views/hints/edit.html.erb index ceb7f83a..dc08b6e0 100644 --- a/tutor/app/views/hints/edit.html.erb +++ b/tutor/app/views/hints/edit.html.erb @@ -1,14 +1,14 @@ <% if flash[:notice] -%> -
+
<%= flash[:notice] %> -
+
<% end %>


<%= form_for @new_Tip,url:{:controller => "hints",action:"update"} do |f| %> - <%= f.hidden_field :id , value: params[:id] %> + <%= f.hidden_field :id, value: params[:id] %>

<%= f.label "Hint description" %>
<%= f.text_area :message, :cols => "100" , :rows => "8",autofocus:true,class:"form-control",style:"width:300px",value:Hint.find_by_id(params[:id]).message %> diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index 6d5ab96d..adcaf371 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -30,6 +30,7 @@ resources :problems resources :topics resources :hints + # Example resource route with options: # resources :products do # member do From 60235438921c5e8b8d4148795e930d16ba9d2e55 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 18:48:03 +0200 Subject: [PATCH 09/17] #212 adjust idenetation --- tutor/app/controllers/hints_controller.rb | 9 ++++----- tutor/app/views/model_answers/edit.html.erb | 1 - tutor/config/routes.rb | 3 ++- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 9b6867ae..6246cb88 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -10,8 +10,8 @@ class HintsController < ApplicationController def edit @new_Tip = Hint.find_by_id(params[:id]) end - - # [Edit helping hints - Story 4.13 ] + + # [Edit helping hints - Story 4.13 ] # This action takes the passed parameters from # the creation form, edits a Hint record # which assigned to the respective problem. If the @@ -19,7 +19,7 @@ def edit # with a "Failed" message. # Parameters: # hint_params[]: A list that has all fields entered by the user to in the - # edit_hint form + # edit_hint form # Returns: # flash[:notice]: A message indicating the success or failure of the edit # Author: Mimi @@ -43,8 +43,7 @@ def update # [Edit helping hints - Story 4.13 ] # Description: # take the parameters from the from - # Parameters: - # none + # Parameters: none # Returns: # Hash of paramas # Author: Mimi diff --git a/tutor/app/views/model_answers/edit.html.erb b/tutor/app/views/model_answers/edit.html.erb index 9ee4edcf..e69de29b 100644 --- a/tutor/app/views/model_answers/edit.html.erb +++ b/tutor/app/views/model_answers/edit.html.erb @@ -1 +0,0 @@ -

NADINE

\ No newline at end of file diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index adcaf371..09cf51d5 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -30,7 +30,7 @@ resources :problems resources :topics resources :hints - + # Example resource route with options: # resources :products do # member do @@ -42,6 +42,7 @@ # get 'sold' # end # end + resources :tracks do member do get 'getProblems' From 427ae00e74d790050277b663c103a5b88d376335 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 18:52:42 +0200 Subject: [PATCH 10/17] adjust identation again --- tutor/app/controllers/hints_controller.rb | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 6246cb88..c93237ba 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -4,8 +4,7 @@ class HintsController < ApplicationController # to be being edited # Parameters: # ID of the hint - # Returns: - # none + # Returns: none # Author: Mimi def edit @new_Tip = Hint.find_by_id(params[:id]) From 7813088dd74a0c7e8f2d1507018f78c3c7da353a Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 19:11:48 +0200 Subject: [PATCH 11/17] #212 check if the current user is not student --- tutor/app/controllers/hints_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index c93237ba..1d512d3d 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -7,9 +7,12 @@ class HintsController < ApplicationController # Returns: none # Author: Mimi def edit + if current_lecturer or current_teaching_assistant @new_Tip = Hint.find_by_id(params[:id]) + else + render "public/500.html" + end end - # [Edit helping hints - Story 4.13 ] # This action takes the passed parameters from # the creation form, edits a Hint record From 3c396d8a80f2715db9c524c1d10e465db9a995f4 Mon Sep 17 00:00:00 2001 From: Mimi Date: Tue, 22 Apr 2014 19:12:13 +0200 Subject: [PATCH 12/17] #212 remove line --- tutor/config/routes.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/tutor/config/routes.rb b/tutor/config/routes.rb index 09cf51d5..ee73ee70 100644 --- a/tutor/config/routes.rb +++ b/tutor/config/routes.rb @@ -42,7 +42,6 @@ # get 'sold' # end # end - resources :tracks do member do get 'getProblems' From eae5c2fa2bdc798dbd53a706517b867284bc04f0 Mon Sep 17 00:00:00 2001 From: Mimi Date: Wed, 23 Apr 2014 14:54:46 +0200 Subject: [PATCH 13/17] #212 ajust braces --- tutor/app/views/hints/edit.html.erb | 1 + 1 file changed, 1 insertion(+) diff --git a/tutor/app/views/hints/edit.html.erb b/tutor/app/views/hints/edit.html.erb index dc08b6e0..b74f37ce 100644 --- a/tutor/app/views/hints/edit.html.erb +++ b/tutor/app/views/hints/edit.html.erb @@ -16,6 +16,7 @@

<%= f.label :"The number of wrong submissions that hint appears after" %>
<%= f.text_area :submission_counter, :rows => "1", class:"form-control", style: "width:300px",value:Hint.find_by_id(params[:id]).submission_counter %> +

<%= f.submit"Save",class:"btn btn-success"%>

From 5aba0fa3207b14c2ed8cf67245283d47b7e2edd5 Mon Sep 17 00:00:00 2001 From: Mimi Date: Fri, 25 Apr 2014 10:41:08 +0200 Subject: [PATCH 14/17] adjust commas --- tutor/app/controllers/hints_controller.rb | 21 ++++++++------- tutor/app/views/hints/edit.html.erb | 8 +++--- tutor/db/seeds.rb | 32 +++++++++++------------ 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index 1d512d3d..e1ce85fd 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -8,11 +8,12 @@ class HintsController < ApplicationController # Author: Mimi def edit if current_lecturer or current_teaching_assistant - @new_Tip = Hint.find_by_id(params[:id]) + @new_tip = Hint.find_by_id(params[:id]) else render "public/500.html" end end + # [Edit helping hints - Story 4.13 ] # This action takes the passed parameters from # the creation form, edits a Hint record @@ -26,17 +27,17 @@ def edit # flash[:notice]: A message indicating the success or failure of the edit # Author: Mimi def update - @new_Tip = Hint.find_by_id(hint_params[:id]) - @new_Tip.message = hint_params[:message] - @new_Tip.submission_counter = hint_params[:submission_counter] - @model_answer = @new_Tip.model_answer_id - bool = @new_Tip.save + @new_tip = Hint.find_by_id(hint_params[:id]) + @new_tip.message = hint_params[:message] + @new_tip.submission_counter = hint_params[:submission_counter] + @model_answer = @new_tip.model_answer_id + bool = @new_tip.save if bool == true flash[:notice] = "Hint successfully edited" - redirect_to :controller => 'model_answers', :action => 'edit',:id => @model_answer + redirect_to :controller => 'model_answers', :action => 'edit', :id => @model_answer else - if @new_Tip.errors.any? - flash[:notice] = @new_Tip.errors.full_messages.first + if @new_tip.errors.any? + flash[:notice] = @new_tip.errors.full_messages.first end redirect_to :back end @@ -51,6 +52,6 @@ def update # Author: Mimi private def hint_params - params.require(:hint).permit(:message,:submission_counter,:id) + params.require(:hint).permit(:message, :submission_counter, :id) end end \ No newline at end of file diff --git a/tutor/app/views/hints/edit.html.erb b/tutor/app/views/hints/edit.html.erb index b74f37ce..63631ddc 100644 --- a/tutor/app/views/hints/edit.html.erb +++ b/tutor/app/views/hints/edit.html.erb @@ -7,17 +7,17 @@

-<%= form_for @new_Tip,url:{:controller => "hints",action:"update"} do |f| %> +<%= form_for @new_tip, url:{:controller => "hints", action:"update"} do |f| %> <%= f.hidden_field :id, value: params[:id] %>

<%= f.label "Hint description" %>
- <%= f.text_area :message, :cols => "100" , :rows => "8",autofocus:true,class:"form-control",style:"width:300px",value:Hint.find_by_id(params[:id]).message %> + <%= f.text_area :message, :cols => "100", :rows => "8", autofocus:true,class:"form-control", style:"width:300px", value:Hint.find_by_id(params[:id]).message %>

<%= f.label :"The number of wrong submissions that hint appears after" %>
- <%= f.text_area :submission_counter, :rows => "1", class:"form-control", style: "width:300px",value:Hint.find_by_id(params[:id]).submission_counter %> + <%= f.text_area :submission_counter, :rows => "1", class:"form-control", style: "width:300px", value:Hint.find_by_id(params[:id]).submission_counter %>

- <%= f.submit"Save",class:"btn btn-success"%> + <%= f.submit"Save", class:"btn btn-success"%>

<% end %> \ No newline at end of file diff --git a/tutor/db/seeds.rb b/tutor/db/seeds.rb index a8a27511..a58dab23 100644 --- a/tutor/db/seeds.rb +++ b/tutor/db/seeds.rb @@ -8,22 +8,6 @@ puts("**************************************************************") puts(" Creating records ") puts("**************************************************************") - -puts("# ---------------------------Admins-----------------------------------") - Admin.create(name: "Admin") - -puts("# ---------------------------Lecturers-----------------------------") - l = Lecturer.new(email: '1@lecturer.com', password: '123456789', - password_confirmation: '123456789', name: 'LecturerI', - confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, - degree: "PhD", university: "GUC", department: "MET") - l.save! - l = Lecturer.new(email: '2@lecturer.com', password: '123456789', - password_confirmation: '123456789', name: 'LecturerII', - confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, - degree: "PhD", university: "Uni", department: "Dep") - l.save! - puts("# ---------------------------Students-----------------------------") s = Student.new(email: '1@student.com', password: '123456789', password_confirmation: '123456789', name: 'StudentI', @@ -49,6 +33,22 @@ faculty: "Fac", university: "Uni", major: "Maj", semester: 8, advising: true, probation: false) s.save! +puts("# ---------------------------Admins-----------------------------------") + Admin.create(name: "Admin") + +puts("# ---------------------------Lecturers-----------------------------") + l = Lecturer.new(email: '1@lecturer.com', password: '123456789', + password_confirmation: '123456789', name: 'LecturerI', + confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, + degree: "PhD", university: "GUC", department: "MET") + l.save! + l = Lecturer.new(email: '2@lecturer.com', password: '123456789', + password_confirmation: '123456789', name: 'LecturerII', + confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, + degree: "PhD", university: "Uni", department: "Dep") + l.save! + + puts("# ---------------------------TeachingAssistants-----------------------------") t = TeachingAssistant.new(email: '1@ta.com', password: '123456789', From 7b2a4b834580552560603f19ac60ed2f6f67a4b7 Mon Sep 17 00:00:00 2001 From: Mimi Date: Fri, 25 Apr 2014 11:18:52 +0200 Subject: [PATCH 15/17] adjust the seeds --- tutor/db/seeds.rb | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/tutor/db/seeds.rb b/tutor/db/seeds.rb index a58dab23..a8a27511 100644 --- a/tutor/db/seeds.rb +++ b/tutor/db/seeds.rb @@ -8,6 +8,22 @@ puts("**************************************************************") puts(" Creating records ") puts("**************************************************************") + +puts("# ---------------------------Admins-----------------------------------") + Admin.create(name: "Admin") + +puts("# ---------------------------Lecturers-----------------------------") + l = Lecturer.new(email: '1@lecturer.com', password: '123456789', + password_confirmation: '123456789', name: 'LecturerI', + confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, + degree: "PhD", university: "GUC", department: "MET") + l.save! + l = Lecturer.new(email: '2@lecturer.com', password: '123456789', + password_confirmation: '123456789', name: 'LecturerII', + confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, + degree: "PhD", university: "Uni", department: "Dep") + l.save! + puts("# ---------------------------Students-----------------------------") s = Student.new(email: '1@student.com', password: '123456789', password_confirmation: '123456789', name: 'StudentI', @@ -33,22 +49,6 @@ faculty: "Fac", university: "Uni", major: "Maj", semester: 8, advising: true, probation: false) s.save! -puts("# ---------------------------Admins-----------------------------------") - Admin.create(name: "Admin") - -puts("# ---------------------------Lecturers-----------------------------") - l = Lecturer.new(email: '1@lecturer.com', password: '123456789', - password_confirmation: '123456789', name: 'LecturerI', - confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, - degree: "PhD", university: "GUC", department: "MET") - l.save! - l = Lecturer.new(email: '2@lecturer.com', password: '123456789', - password_confirmation: '123456789', name: 'LecturerII', - confirmed_at: Time.now, dob: DateTime.now.to_date, gender: true, - degree: "PhD", university: "Uni", department: "Dep") - l.save! - - puts("# ---------------------------TeachingAssistants-----------------------------") t = TeachingAssistant.new(email: '1@ta.com', password: '123456789', From 6d7e38ebe2ea6d8d1b613e231dd0c8de07ba8141 Mon Sep 17 00:00:00 2001 From: Mimi Date: Fri, 25 Apr 2014 11:50:21 +0200 Subject: [PATCH 16/17] add new line --- tutor/app/controllers/hints_controller.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/tutor/app/controllers/hints_controller.rb b/tutor/app/controllers/hints_controller.rb index e1ce85fd..26c3e540 100644 --- a/tutor/app/controllers/hints_controller.rb +++ b/tutor/app/controllers/hints_controller.rb @@ -1,4 +1,5 @@ class HintsController < ApplicationController + # [Edit helping hints - Story 4.13 ] # This action creates the form and retrives the data of the selected problem # to be being edited From b9bcafe0f2931ebdc196a0944fe322f06040224b Mon Sep 17 00:00:00 2001 From: Mimi Date: Fri, 25 Apr 2014 11:54:30 +0200 Subject: [PATCH 17/17] adjust comma --- tutor/app/views/hints/edit.html.erb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tutor/app/views/hints/edit.html.erb b/tutor/app/views/hints/edit.html.erb index 63631ddc..e199c630 100644 --- a/tutor/app/views/hints/edit.html.erb +++ b/tutor/app/views/hints/edit.html.erb @@ -11,7 +11,7 @@ <%= f.hidden_field :id, value: params[:id] %>

<%= f.label "Hint description" %>
- <%= f.text_area :message, :cols => "100", :rows => "8", autofocus:true,class:"form-control", style:"width:300px", value:Hint.find_by_id(params[:id]).message %> + <%= f.text_area :message, :cols => "100", :rows => "8", autofocus:true, class:"form-control", style:"width:300px", value:Hint.find_by_id(params[:id]).message %>

<%= f.label :"The number of wrong submissions that hint appears after" %>