Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

complete toggle for tasks #393

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/task.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ class Task < ApplicationRecord

validates :name, presence: true
validates :description, presence: true

default_scope { order(created_at: :asc) }
end
11 changes: 7 additions & 4 deletions app/views/organizations/pets/tasks/_tasks.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,18 @@
<li class="list-group-item">
<div class="d-flex justify-content-between
align-items-center">
<div>
<strong class="d-block mb-1" ><%= task.name %></strong>
<p><%= task.description %></p>

<div class="d-flex align-items-center">
<%= render '/organizations/pets/tasks/tasks_toggle', task: task %>
<div style="padding: 0 10px; margin-top: 15px;">
<strong class="d-block mb-1" ><%= task.name %></strong>
<p><%= task.description %></p>
</div>
</div>

<!-- Right side: Completion status and action buttons -->
<div class="text-right">
<div class="d-flex align-items-center justify-content-end">
<strong class="m-3"><%= task.completed %></strong>
<%= link_to 'Edit', edit_pet_task_path(@pet, task), class: 'btn btn-warning m-2' %>
<%= link_to 'Delete', pet_task_path(@pet, task), class: 'btn btn-danger m-2', data: { turbo_method: "delete", turbo_confirm: 'Are you sure?' } %>
</div>
Expand Down
11 changes: 11 additions & 0 deletions app/views/organizations/pets/tasks/_tasks_toggle.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div id=<%= "task_toggle_#{task.id}" %>>
<%= form_for [@pet, task] do |form| %>
<div class='form-group'>
<div class="form-check">
<%= form.check_box :completed,
{ class: "form-check-input",
onclick: "this.form.requestSubmit()"} %>
</div>
</div>
<% end %>
</div>