Skip to content

Commit

Permalink
Add button to mark as completed when the user has finished it.
Browse files Browse the repository at this point in the history
  • Loading branch information
ciscoLegrand committed Oct 21, 2024
1 parent cb654c7 commit 77d513b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 3 deletions.
9 changes: 9 additions & 0 deletions app/controllers/oodle/answers_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ def destroy
redirect_to answers_path, notice: "Answer was successfully destroyed.", status: :see_other
end

def mark_as_completed
questionnaire = Questionnaire.find(params[:id])
Current.user.user_questionnaires
.find_by(questionnaire_id: questionnaire.id)
.mark_as_completed

redirect_to questionnaire_path(questionnaire.id), notice: "Questionnaire completed"
end

private
# Use callbacks to share common setup or constraints between actions.
def set_answer
Expand Down
3 changes: 3 additions & 0 deletions app/views/oodle/questionnaires/_questionnaire.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@
</p>
</div>

<% if action_name == "show" %>
<%= button_to "Mark as completed", mark_as_completed_answer_path(params[:id]), method: :post, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" if questionnaire.available? && !@user_questionnaire.completed? %>
<% end %>
<% end %>

<% if action_name == "show" %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/oodle/questionnaires/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div class="flex justify-between gap-4 my-8">
<h1 class="text-3xl font-semibold text-gray-800">questionnaires</h1>
<%= link_to "New questionnaire", new_questionnaire_path, class: "px-3 py-1.5 border border-blue-500 text-blue-500 hover:bg-blue-200 hover:text-blue-700 rounded-md font-medium" %>
<%= link_to "New questionnaire", new_questionnaire_path, class: "px-3 py-1.5 border border-blue-500 text-blue-500 hover:bg-blue-200 hover:text-blue-700 rounded-md font-medium" if Current.user.manager? %>
</div>

<div id="questionnaires" class="grid grid-cols-4 gap-4 ">
Expand Down
2 changes: 1 addition & 1 deletion app/views/oodle/questions/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<div class="flex justify-between gap-4 my-8">
<h1 class="text-3xl font-semibold text-gray-800">questions</h1>
<%= link_to "New question", new_question_path, class: "px-3 py-1.5 border border-blue-500 text-blue-500 hover:bg-blue-200 hover:text-blue-700 rounded-md font-medium" %>
<%= link_to "New question", new_question_path, class: "px-3 py-1.5 border border-blue-500 text-blue-500 hover:bg-blue-200 hover:text-blue-700 rounded-md font-medium" if Current.user.manager? %>
</div>

<div id="questions" class="grid grid-cols-4 gap-4 ">
Expand Down
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
Oodle::Engine.routes.draw do
resources :answers
resources :answers do
post :mark_as_completed, on: :member
end
resources :items
resources :questions
resources :questionnaires
Expand Down

0 comments on commit 77d513b

Please sign in to comment.