From 355e144ddcf01e54944b4b7ce6f8655d7f775663 Mon Sep 17 00:00:00 2001 From: Jeffrey Hardy Date: Wed, 18 Sep 2024 13:06:25 -0400 Subject: [PATCH] Nest bubbles et al under projects --- app/controllers/assignments_controller.rb | 30 ++++++++------------ app/controllers/boosts_controller.rb | 2 +- app/controllers/bubbles/images_controller.rb | 4 +-- app/controllers/bubbles_controller.rb | 14 +++++---- app/controllers/comments_controller.rb | 4 +-- app/controllers/concerns/bubble_scoped.rb | 2 +- app/controllers/projects_controller.rb | 7 ++--- app/controllers/tags_controller.rb | 8 ++++-- app/views/boosts/_boosts.html.erb | 2 +- app/views/boosts/new.html.erb | 2 +- app/views/bubbles/_assignments.html.erb | 2 +- app/views/bubbles/_boosts.html.erb | 2 +- app/views/bubbles/_bubble.html.erb | 4 +-- app/views/bubbles/_color.html.erb | 2 +- app/views/bubbles/_date.html.erb | 4 +-- app/views/bubbles/_image.html.erb | 4 +-- app/views/bubbles/_tags.html.erb | 4 +-- app/views/bubbles/edit.html.erb | 4 +-- app/views/bubbles/index.html.erb | 4 +-- app/views/bubbles/list/_bubble.html.erb | 4 +-- app/views/bubbles/new.html.erb | 2 +- app/views/bubbles/show.html.erb | 4 +-- app/views/comments/_comment.html.erb | 2 +- app/views/comments/_new.html.erb | 2 +- app/views/projects/index.html.erb | 2 +- app/views/projects/show.html.erb | 2 -- app/views/tags/new.html.erb | 2 +- config/routes.rb | 24 ++++++++-------- db/schema.rb | 1 - test/fixtures/assignments.yml | 10 +++---- 30 files changed, 75 insertions(+), 85 deletions(-) delete mode 100644 app/views/projects/show.html.erb diff --git a/app/controllers/assignments_controller.rb b/app/controllers/assignments_controller.rb index d21cbb59f..77b742618 100644 --- a/app/controllers/assignments_controller.rb +++ b/app/controllers/assignments_controller.rb @@ -1,30 +1,24 @@ class AssignmentsController < ApplicationController - before_action :set_bubble, only: %i[ create update ] + include BubbleScoped, ProjectScoped + before_action :set_assignment, only: :update def create - @assignment = @bubble.assignments.build(assignment_params) - @assignment.save - - redirect_to @bubble + @assignment = @bubble.assignments.create!(assignment_params) + redirect_to project_bubble_url(@project, @bubble) end def update - @assignment.update(assignment_params) - redirect_to @bubble + @assignment.update!(assignment_params) + redirect_to project_bubble_url(@project, @bubble) end private + def assignment_params + params.require(:assignment).permit(:user_id) + end - def assignment_params - params.require(:assignment).permit(:user_id) - end - - def set_assignment - @assignment = @bubble.assignments.find(params[:id]) - end - - def set_bubble - @bubble = Bubble.find(params[:bubble_id]) - end + def set_assignment + @assignment = @bubble.assignments.find(params[:id]) + end end diff --git a/app/controllers/boosts_controller.rb b/app/controllers/boosts_controller.rb index 7489c92f6..260478ecc 100644 --- a/app/controllers/boosts_controller.rb +++ b/app/controllers/boosts_controller.rb @@ -1,5 +1,5 @@ class BoostsController < ApplicationController - include BubbleScoped + include BubbleScoped, ProjectScoped def index end diff --git a/app/controllers/bubbles/images_controller.rb b/app/controllers/bubbles/images_controller.rb index b7dc7da97..d77902dec 100644 --- a/app/controllers/bubbles/images_controller.rb +++ b/app/controllers/bubbles/images_controller.rb @@ -1,8 +1,8 @@ class Bubbles::ImagesController < ApplicationController - include BubbleScoped + include BubbleScoped, ProjectScoped def destroy @bubble.image.purge_later - redirect_to @bubble + redirect_to project_bubble_url(@bubble.project, @bubble) end end diff --git a/app/controllers/bubbles_controller.rb b/app/controllers/bubbles_controller.rb index 681be01a4..486b38d44 100644 --- a/app/controllers/bubbles_controller.rb +++ b/app/controllers/bubbles_controller.rb @@ -1,4 +1,6 @@ class BubblesController < ApplicationController + include ProjectScoped + before_action :set_bubble, only: %i[ show edit update ] def index @@ -8,17 +10,17 @@ class BubblesController < ApplicationController @most_active_bubbles = @tag.bubbles.left_joins(:comments, :boosts).group(:id).order(Arel.sql("COUNT(comments.id) + COUNT(boosts.id) DESC")).limit(10) else @bubbles = Bubble.all.order(created_at: :desc) - @most_active_bubbles = Bubble.left_joins(:comments, :boosts).group(:id).order(Arel.sql("COUNT(comments.id) + COUNT(boosts.id) DESC")).limit(10) + @most_active_bubbles = @project.bubbles.left_joins(:comments, :boosts).group(:id).order(Arel.sql("COUNT(comments.id) + COUNT(boosts.id) DESC")).limit(10) end end def new - @bubble = Bubble.new + @bubble = @project.bubbles.build end def create - @bubble = Bubble.create!(bubble_params) - redirect_to @bubble + @bubble = @project.bubbles.create!(bubble_params) + redirect_to project_bubble_url(@project, @bubble) end def show @@ -29,13 +31,13 @@ class BubblesController < ApplicationController def update @bubble.update!(bubble_params) - redirect_to @bubble + redirect_to project_bubble_url(@project, @bubble) end private def set_bubble - @bubble = Bubble.find(params[:id]) + @bubble = @project.bubbles.find(params[:id]) end def bubble_params diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index a8cc4ad15..c0e2f4fd5 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -1,9 +1,9 @@ class CommentsController < ApplicationController - include BubbleScoped + include BubbleScoped, ProjectScoped def create @bubble.comments.create!(comment_params) - redirect_to @bubble + redirect_to project_bubble_url(@project, @bubble) end private diff --git a/app/controllers/concerns/bubble_scoped.rb b/app/controllers/concerns/bubble_scoped.rb index a03a01ddf..db7798cc3 100644 --- a/app/controllers/concerns/bubble_scoped.rb +++ b/app/controllers/concerns/bubble_scoped.rb @@ -7,6 +7,6 @@ module BubbleScoped private def set_bubble - @bubble = Bubble.find(params[:bubble_id]) + @bubble = @project.bubbles.find(params[:bubble_id]) end end diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index efb80c99e..bfe308cf6 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -11,10 +11,7 @@ class ProjectsController < ApplicationController def create @project = Current.account.projects.create!(project_params) - redirect_to @project - end - - def show + redirect_to project_url(@project) end def edit @@ -22,7 +19,7 @@ class ProjectsController < ApplicationController def update @project.update!(project_params) - redirect_to @project + redirect_to project_url(@project) end def destroy diff --git a/app/controllers/tags_controller.rb b/app/controllers/tags_controller.rb index 95402f7e8..1e0e7eb80 100644 --- a/app/controllers/tags_controller.rb +++ b/app/controllers/tags_controller.rb @@ -1,4 +1,6 @@ class TagsController < ApplicationController + include ProjectScoped + before_action :set_bubble, only: %i[ new create ] before_action :set_tag, only: :destroy @@ -11,12 +13,12 @@ class TagsController < ApplicationController def create @bubble.tags << Tag.find_or_create_by!(tag_params) - redirect_to @bubble + redirect_to project_bubble_url(@project, @bubble) end def destroy @tag.destroy - redirect_to tags_path + redirect_to project_tags_url(@project) end private @@ -29,6 +31,6 @@ class TagsController < ApplicationController end def set_bubble - @bubble = Bubble.find(params[:bubble_id]) + @bubble = @project.bubbles.find(params[:bubble_id]) end end diff --git a/app/views/boosts/_boosts.html.erb b/app/views/boosts/_boosts.html.erb index 93bf2789d..67eaad5bb 100644 --- a/app/views/boosts/_boosts.html.erb +++ b/app/views/boosts/_boosts.html.erb @@ -1,3 +1,3 @@ -<%= link_to new_bubble_boost_path(bubble), data: { action: "toggle-class#toggle" } do %> +<%= link_to new_project_bubble_boost_path(bubble.project, bubble), data: { action: "toggle-class#toggle" } do %> + <%= bubble.boosts.size if bubble.boosts.any? %> <% end %> diff --git a/app/views/boosts/new.html.erb b/app/views/boosts/new.html.erb index bc9a89f4d..b582be4a3 100644 --- a/app/views/boosts/new.html.erb +++ b/app/views/boosts/new.html.erb @@ -1,5 +1,5 @@ <%= turbo_frame_tag dom_id(@bubble, :boosts) do %> - <%= form_with url: bubble_boosts_path(@bubble), data: { controller: "auto-submit" } do |form| %> + <%= form_with url: project_bubble_boosts_path(@bubble.project, @bubble), data: { controller: "auto-submit" } do |form| %> <%= form.submit "Boost this", hidden: true %> <% end %> <% end %> diff --git a/app/views/bubbles/_assignments.html.erb b/app/views/bubbles/_assignments.html.erb index 95168595b..65f923f3a 100644 --- a/app/views/bubbles/_assignments.html.erb +++ b/app/views/bubbles/_assignments.html.erb @@ -1,5 +1,5 @@ "> - <%= form_with model: [bubble, Assignment.new], data: { controller: "form" } do |form| %> + <%= form_with model: Assignment.new, url: project_bubble_assignments_path(bubble.project, bubble), data: { controller: "form" } do |form| %>