diff --git a/app/controllers/tasks_controller.rb b/app/controllers/tasks_controller.rb index 52b5f46..203770d 100644 --- a/app/controllers/tasks_controller.rb +++ b/app/controllers/tasks_controller.rb @@ -22,6 +22,16 @@ class TasksController < ApplicationController @task.destroy end + def complete + @task = @project.tasks.find(params[:id]) + @task.update(status: "done") + + respond_to do |format| + format.turbo_stream + format.html { redirect_to @project } + end +end + private def set_project diff --git a/app/views/projects/show.html.erb b/app/views/projects/show.html.erb index 1583b79..123e6c2 100644 --- a/app/views/projects/show.html.erb +++ b/app/views/projects/show.html.erb @@ -4,18 +4,23 @@ - +
+

Add New Task

<%= render partial: "tasks/form", locals: { project: @project, task: Task.new } %>
\ No newline at end of file diff --git a/app/views/tasks/_task.html.erb b/app/views/tasks/_task.html.erb new file mode 100644 index 0000000..77098b5 --- /dev/null +++ b/app/views/tasks/_task.html.erb @@ -0,0 +1,16 @@ + +
  • + <%= task.title %> (<%= task.status %>) + + <%= link_to "Destroy", project_task_path(task.project, task), data: { + turbo_method: :delete, + turbo_confirm: "Are you sure?" + } %> + + <% unless task.status == "completed" %> + <%= button_to "Complete", complete_project_task_path(task.project, task), + method: :patch, + form: { data: { turbo_frame: dom_id(task) } } %> + <% end %> +
  • +
    diff --git a/app/views/tasks/complete.turbo_stream.erb b/app/views/tasks/complete.turbo_stream.erb new file mode 100644 index 0000000..058bf2a --- /dev/null +++ b/app/views/tasks/complete.turbo_stream.erb @@ -0,0 +1,10 @@ +<%= turbo_stream.replace dom_id(@task) do %> +
  • + <%= @task.title %> (<%= @task.status %>) + + <%= link_to "Destroy", project_task_path(@project, @task), data: { + turbo_method: :delete, + turbo_confirm: "Are you sure?" + } %> +
  • +<% end %> diff --git a/app/views/tasks/create.turbo_stream.erb b/app/views/tasks/create.turbo_stream.erb index 24cb5e2..f63494f 100644 --- a/app/views/tasks/create.turbo_stream.erb +++ b/app/views/tasks/create.turbo_stream.erb @@ -1,11 +1,5 @@ <%= turbo_stream.append "tasks_list" do %> -
  • - <%= @task.title %> (<%= @task.status %>) - <%= link_to "Destroy", project_task_path(@project, @task), data: { - turbo_method: :delete, - turbo_confirm: "Are you sure?" - } %> -
  • + <%= render partial: "tasks/task", locals: { task: @task } %> <% end %> <%= turbo_stream.replace "new_task" do %> diff --git a/config/routes.rb b/config/routes.rb index d7c9dbc..fa9fbf6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -3,7 +3,11 @@ Rails.application.routes.draw do root "projects#index" resources :projects do - resources :tasks + resources :tasks do + member do + patch :complete + end + end end