diff --git a/app/controllers/organizations/tasks_controller.rb b/app/controllers/organizations/tasks_controller.rb new file mode 100644 index 000000000..03be9c5fd --- /dev/null +++ b/app/controllers/organizations/tasks_controller.rb @@ -0,0 +1,72 @@ +class Organizations::TasksController < Organizations::BaseController + before_action :set_pet, only: [:new, :create, :edit, :update, :destroy] + before_action :set_task, only: [:edit, :update] + + def new + @task = @pet.tasks.build + render partial: "form", locals: {task: @task} + end + + def create + @task = @pet.tasks.build(task_params) + + if @task.save + respond_to do |format| + format.html { redirect_to pet_path(@pet, active_tab: "tasks") } + format.turbo_stream + end + else + render :new + end + end + + def edit + end + + def update + if @task.update(task_params) + respond_to do |format| + format.html { redirect_to @task, notice: "Task was successfully updated." } + format.turbo_stream { render turbo_stream: turbo_stream.replace("tasks_list", partial: "organizations/tasks/tasks", locals: {task: @task}) } + end + else + respond_to do |format| + format.html { render :edit } + end + end + end + + def destroy + @task = Task.find(params[:id]) + @task.destroy + + respond_to do |format| + format.html { redirect_to pet_path(@pet), notice: "Task was successfully deleted." } + format.turbo_stream + end + rescue ActiveRecord::RecordNotFound + redirect_to pets_path + end + + private + + def set_pet + @organization = current_user.organization + raise ActiveRecord::RecordNotFound if @organization.nil? + + pet_id = params[:pet_id] || params[:id] + @pet = @organization.pets.find(pet_id) + rescue ActiveRecord::RecordNotFound + redirect_to pets_path unless @pet + end + + def set_task + @task = @pet.tasks.find(params[:id]) + rescue ActiveRecord::RecordNotFound + redirect_to pets_path + end + + def task_params + params.require(:task).permit(:name, :description, :completed) + end +end diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 88870c1fc..ebe95da52 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -7,6 +7,10 @@ def organization_home_path(organization) home_index_path(script_name: "/#{organization.slug}") end + def path_to_partial(active_tab) + "pets/#{active_tab}" + end + def current_organization_name if Current.organization.present? Current.organization.name diff --git a/app/helpers/tasks_helper.rb b/app/helpers/tasks_helper.rb new file mode 100644 index 000000000..ce894d00c --- /dev/null +++ b/app/helpers/tasks_helper.rb @@ -0,0 +1,2 @@ +module TasksHelper +end diff --git a/app/models/pet.rb b/app/models/pet.rb index 9d351727e..afc66e710 100644 --- a/app/models/pet.rb +++ b/app/models/pet.rb @@ -31,6 +31,7 @@ class Pet < ApplicationRecord acts_as_tenant(:organization) has_many :adopter_applications, dependent: :destroy + has_many :tasks, dependent: :destroy has_one :match, dependent: :destroy has_many_attached :images enum species: ["Dog", "Cat"] diff --git a/app/models/task.rb b/app/models/task.rb new file mode 100644 index 000000000..772847569 --- /dev/null +++ b/app/models/task.rb @@ -0,0 +1,23 @@ +# == Schema Information +# +# Table name: tasks +# +# id :bigint not null, primary key +# completed :boolean default(FALSE) +# description :text +# name :string not null +# created_at :datetime not null +# updated_at :datetime not null +# pet_id :bigint not null +# +# Indexes +# +# index_tasks_on_pet_id (pet_id) +# +# Foreign Keys +# +# fk_rails_... (pet_id => pets.id) +# +class Task < ApplicationRecord + belongs_to :pet +end diff --git a/app/views/organizations/pets/show.html.erb b/app/views/organizations/pets/show.html.erb index 8b3a3b46b..22e246956 100644 --- a/app/views/organizations/pets/show.html.erb +++ b/app/views/organizations/pets/show.html.erb @@ -1,112 +1,113 @@ <% breadcrumb :dashboard_pet, @pet %> -<%= render "components/dashboard/page" do |p| %> - <% p.header_title @pet.name %> - <% p.nav_tabs do %> - <%= render "components/dashboard/nav_tab", url: pet_path(@pet, active_tab: "overview"), text: "Summary", options: { active: /overview/ } %> - <%= render "components/dashboard/nav_tab", url: pet_path(@pet, active_tab: "applications"), text: "Tasks", options: { active: /applications/ } %> - <% end %> - <% p.content do %> -
Paula finished figma task
+Georg commented on task.
+Paula finished figma task
-Georg commented on task.
- -Jitu send email to update design - for client Geeks UI.
- -Task status updatd for board is overdue.
+Jitu send email to update design for client Geeks UI.
+<%= @pet.description %>
- -<%= @pet.sex %>
-<%= @pet.description %>
+<%= @pet.breed %>
+<%= @pet.sex %>
+<%= "#{@pet.weight_from} - #{@pet.weight_to} #{@pet.weight_unit}" %>
+<%= @pet.breed %>
+<%= @pet.placement_type %>
+<%= "#{@pet.weight_from} - #{@pet.weight_to} #{@pet.weight_unit}" %>
+- <%= @pet.application_paused == false ? t('.application.active') : t('.application.paused') %> -
++ <%= @pet.application_paused == false ? t('.application.active') : t('.application.paused') %> +
+<%= task.description %>
+