Skip to content
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
20 changes: 3 additions & 17 deletions app/controllers/bubbles_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,9 @@ class BubblesController < ApplicationController

before_action :set_bubble, only: %i[ show edit update ]
before_action :clear_assignees, only: :index
before_action :set_view, :set_tag_filters, :set_assignee_filters, only: :index
before_action :set_view, :set_bubbles, only: :index

def index
@bubbles = @bucket.bubbles
@bubbles = @bubbles.ordered_by(params[:order_by] || Bubble.default_order_by)
@bubbles = @bubbles.with_status(params[:status] || Bubble.default_status)
@bubbles = @bubbles.tagged_with(@tag_filters) if @tag_filters
@bubbles = @bubbles.assigned_to(@assignee_filters) if @assignee_filters
@bubbles = @bubbles.mentioning(params[:term]) if params[:term]
end

def new
Expand Down Expand Up @@ -53,15 +47,7 @@ def set_view
params[:view_id] = @view&.id
end

def set_tag_filters
if params[:tag_ids]
@tag_filters = Current.account.tags.where id: params[:tag_ids]
end
end

def set_assignee_filters
if params[:assignee_ids]
@assignee_filters = Current.account.users.where id: params[:assignee_ids]
end
def set_bubbles
@bubbles = @bucket.filtered_bubbles helpers.view_filter_params
end
end
8 changes: 4 additions & 4 deletions app/helpers/filters_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ def main_filter_text
end

def tag_filter_text
if @tag_filters
@tag_filters.map(&:hashtag).to_choice_sentence
if @bucket&.tag_filters
@bucket.tag_filters.map(&:hashtag).to_choice_sentence
else
"any tag"
end
end

def assignee_filter_text
if @assignee_filters
"assigned to #{@assignee_filters.map(&:name).to_choice_sentence}"
if @bucket&.assignee_filters
"assigned to #{@bucket.assignee_filters.map(&:name).to_choice_sentence}"
else
"assigned to anyone"
end
Expand Down
2 changes: 1 addition & 1 deletion app/models/bucket.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class Bucket < ApplicationRecord
include Accessible, Views
include Accessible, Filterable, Views

belongs_to :account
belongs_to :creator, class_name: "User", default: -> { Current.user }
Expand Down
30 changes: 30 additions & 0 deletions app/models/bucket/filterable.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
module Bucket::Filterable
extend ActiveSupport::Concern

included do
attr_accessor :tag_filters, :assignee_filters
end
Comment on lines +2 to +6
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ope, doesn't need to be a concern: bd2f4fc


def filtered_bubbles(params = {})
result = bubbles
result = result.ordered_by(params["order_by"] || Bubble.default_order_by)
result = result.with_status(params["status"] || Bubble.default_status)
result = result.tagged_with(self.tag_filters) if set_tag_filters(params["tag_ids"])
result = result.assigned_to(self.assignee_filters) if set_assignee_filters(params["assignee_ids"])
result = result.mentioning(params["term"]) if params["term"]
result
end

private
def set_tag_filters(tag_ids)
if tag_ids
self.tag_filters = account.tags.where id: tag_ids
end
end

def set_assignee_filters(assignee_ids)
if assignee_ids
self.assignee_filters = account.users.where id: assignee_ids
end
end
end
4 changes: 4 additions & 0 deletions app/models/bucket/view.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ def default_filters
end
end

def filtered_bubbles
bucket.filtered_bubbles filters
end

private
def must_not_be_the_default_view
if filters.values.all?(&:blank?) || filters == self.class.default_filters
Expand Down
2 changes: 1 addition & 1 deletion app/views/bubbles/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<% end %>

<header class="txt-align-center">
<%= render "bubbles/filters", bucket: @bucket, view: @view, tag_filters: @tag_filters, assignee_filters: @assignee_filters %>
<%= render "bubbles/filters", bucket: @bucket, view: @view %>
</header>

<%= button_to bucket_bubbles_path(@bucket), method: :post, class: "btn btn--plain", form_class: "flex-item-justify-end" do %>
Expand Down
2 changes: 1 addition & 1 deletion app/views/buckets/_view.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<li class="bucket flex flex-column txt-align-center max-width position-relative">
<%= link_to path, class: "windshield__container flex justify-center align-center position-relative" do %>
<div class="windshield bucket__windshield flex flex-wrap gap justify-center align-end" style="view-transition-name: windshield_<%= view.bucket.id %>">
<% view.bucket.bubbles.not_popped.ordered_by_activity.limit(10).each do |bubble| %>
<% view.filtered_bubbles.not_popped.ordered_by_activity.limit(10).each do |bubble| %>
<div class="bubble" style="--bubble-color: <%= bubble.color %>; <%= bubble_rotation(bubble) %> <%= bubble_size(bubble) %>">
<svg class="bubble__svg" style="fill: <%= bubble.color %>; stroke: <%= bubble.color %>;" viewBox="0 0 990 990" xmlns="http://www.w3.org/2000/svg">
<path d="m0 0h990v990h-990z" fill="none" stroke="none" />
Expand Down