Extract Bucket::Assignable and rename Assignment#user to #assignee
This commit is contained in:
@@ -1,24 +1,13 @@
|
||||
class AssignmentsController < ApplicationController
|
||||
include BubbleScoped, BucketScoped
|
||||
|
||||
before_action :set_assignment, only: :update
|
||||
|
||||
def create
|
||||
@assignment = @bubble.assignments.create!(assignment_params)
|
||||
redirect_to bucket_bubble_url(@bucket, @bubble)
|
||||
end
|
||||
|
||||
def update
|
||||
@assignment.update!(assignment_params)
|
||||
@bubble.assignments.create!(assignee: find_assignee)
|
||||
redirect_to bucket_bubble_url(@bucket, @bubble)
|
||||
end
|
||||
|
||||
private
|
||||
def assignment_params
|
||||
params.require(:assignment).permit(:user_id)
|
||||
end
|
||||
|
||||
def set_assignment
|
||||
@assignment = @bubble.assignments.find(params[:id])
|
||||
def find_assignee
|
||||
@bucket.users.active.find(params[:assignee_id])
|
||||
end
|
||||
end
|
||||
|
||||
@@ -29,7 +29,7 @@ module CommentsHelper
|
||||
|
||||
def initial_assignment_info(combined_collection)
|
||||
initial_assignment = combined_collection.find { |item| item.is_a?(Assignment) }
|
||||
"assigned to #{initial_assignment.user.name}" if initial_assignment
|
||||
"assigned to #{initial_assignment.assignee.name}" if initial_assignment
|
||||
end
|
||||
|
||||
def render_initial_boosts(combined_collection)
|
||||
@@ -75,6 +75,6 @@ module CommentsHelper
|
||||
end
|
||||
|
||||
def render_grouped_assignments(assignments)
|
||||
assignments.map { |assignment| "Assigned to #{assignment.user.name} #{time_ago_in_words(assignment.created_at)} ago" }
|
||||
assignments.map { |assignment| "Assigned to #{assignment.assignee.name} #{time_ago_in_words(assignment.created_at)} ago" }
|
||||
end
|
||||
end
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
class Assignment < ApplicationRecord
|
||||
belongs_to :user
|
||||
belongs_to :bubble
|
||||
belongs_to :assignee, class_name: "User"
|
||||
|
||||
validates :user_id, uniqueness: { scope: :bubble_id }
|
||||
validates :assignee, uniqueness: { scope: :bubble }
|
||||
end
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
class Bubble < ApplicationRecord
|
||||
include Colored, Searchable
|
||||
include Assignable, Colored, Searchable
|
||||
|
||||
belongs_to :bucket
|
||||
belongs_to :creator, class_name: "User", default: -> { Current.user }
|
||||
@@ -10,9 +10,6 @@ class Bubble < ApplicationRecord
|
||||
has_many :taggings, dependent: :destroy
|
||||
has_many :tags, through: :taggings
|
||||
|
||||
has_many :assignments, dependent: :destroy
|
||||
has_many :assignees, through: :assignments, source: :user
|
||||
|
||||
has_one_attached :image, dependent: :purge_later
|
||||
|
||||
scope :reverse_chronologically, -> { order(created_at: :desc, id: :desc) }
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
module Bubble::Assignable
|
||||
extend ActiveSupport::Concern
|
||||
|
||||
included do
|
||||
has_many :assignments, dependent: :destroy
|
||||
has_many :assignees, through: :assignments
|
||||
end
|
||||
end
|
||||
@@ -1,5 +1,5 @@
|
||||
<span class="bubble__bubble bubble__meta bubble__assignee <%= "bubble__assignee--new" if bubble.assignees.none? %>">
|
||||
<%= form_with model: Assignment.new, url: bucket_bubble_assignments_path(bubble.bucket, bubble), data: { controller: "form" } do |form| %>
|
||||
<%= form_with url: bucket_bubble_assignments_path(bubble.bucket, bubble), data: { controller: "form" } do |form| %>
|
||||
<label class="btn btn--plain position-relative fill-transparent" style="--btn-icon-size: 2em;">
|
||||
<% if bubble.assignees.any? %>
|
||||
<% if bubble.assignees.many? %>
|
||||
@@ -15,7 +15,7 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 17 17" fill="var(--bubble-color)"><path d="m11.5 10.3-.6-.2c-.2-.5-.3-1.1-.1-1.6 1.1-1.2 1.6-2.7 1.5-4.3 0-2.4-1.6-4.2-3.8-4.2S4.7 1.8 4.7 4.2c-.1 1.5.4 3.1 1.5 4.3.2.5.2 1.1-.1 1.6l-.6.2c-2.4.9-4.2 1.5-4.8 2.6-.4 1.2-.7 2.4-.7 3.6 0 .3.2.5.5.5h16c.3 0 .5-.2.5-.5 0-1.2-.3-2.4-.7-3.5-.6-1.1-2.4-1.8-4.8-2.7"/></svg>
|
||||
<% end %>
|
||||
|
||||
<%= form.collection_select :user_id, User.active, :id, :name, { prompt: "Assign to…", selected: bubble.assignees.pluck(:id) },
|
||||
<%= form.collection_select :assignee_id, bubble.bucket.users.active, :id, :name, { prompt: "Assign to…", selected: bubble.assignees.pluck(:id) },
|
||||
class: "input input--hidden txt-medium",
|
||||
data: { action: "change->form#submit click->form#showPicker" } %>
|
||||
<span class="for-screen-reader">Assign to…</span>
|
||||
|
||||
@@ -0,0 +1,5 @@
|
||||
class RenameAssignmentUserToAssignee < ActiveRecord::Migration[8.0]
|
||||
def change
|
||||
rename_column :assignments, :user_id, :assignee_id
|
||||
end
|
||||
end
|
||||
Generated
+3
-3
@@ -10,7 +10,7 @@
|
||||
#
|
||||
# It's strongly recommended that you check this file into your version control system.
|
||||
|
||||
ActiveRecord::Schema[8.0].define(version: 2024_10_02_103608) do
|
||||
ActiveRecord::Schema[8.0].define(version: 2024_10_02_161258) do
|
||||
create_table "accesses", force: :cascade do |t|
|
||||
t.integer "bucket_id", null: false
|
||||
t.integer "user_id", null: false
|
||||
@@ -59,12 +59,12 @@ ActiveRecord::Schema[8.0].define(version: 2024_10_02_103608) do
|
||||
end
|
||||
|
||||
create_table "assignments", force: :cascade do |t|
|
||||
t.integer "user_id", null: false
|
||||
t.integer "assignee_id", null: false
|
||||
t.integer "bubble_id", null: false
|
||||
t.datetime "created_at", null: false
|
||||
t.datetime "updated_at", null: false
|
||||
t.index ["assignee_id"], name: "index_assignments_on_assignee_id"
|
||||
t.index ["bubble_id"], name: "index_assignments_on_bubble_id"
|
||||
t.index ["user_id"], name: "index_assignments_on_user_id"
|
||||
end
|
||||
|
||||
create_table "boosts", force: :cascade do |t|
|
||||
|
||||
Vendored
+2
-2
@@ -1,7 +1,7 @@
|
||||
logo_kevin:
|
||||
user: kevin
|
||||
assignee: kevin
|
||||
bubble: logo
|
||||
|
||||
layout_jz:
|
||||
user: jz
|
||||
assignee: jz
|
||||
bubble: layout
|
||||
|
||||
Reference in New Issue
Block a user