Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/go 368 filters #249

Open
wants to merge 44 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 23 commits
Commits
Show all changes
44 commits
Select commit Hold shift + click to select a range
473af6d
Pass filter via url params and tweak message threads table title base…
alhafoudh Dec 11, 2023
914d2fb
Tweak title text
alhafoudh Dec 11, 2023
0a03182
Implement pinning and unpinning filters in sidebar
alhafoudh Dec 11, 2023
a6b44f0
Remove dependency on tailwindcss-scoped-groups since it is a native t…
alhafoudh Dec 12, 2023
be94fbe
Implement filter sorting
alhafoudh Dec 13, 2023
d8e29ff
Replace bars icon with grip icon
alhafoudh Dec 13, 2023
5b0b7a3
Tweak styles
alhafoudh Jan 4, 2024
2fcbce2
Merge branch 'main' into feature/GO-368-filters
alhafoudh Jan 4, 2024
8d1e4e9
Fix FlashComponent renamed namespace
alhafoudh Jan 4, 2024
8bfd59d
Update schema.rb and tenant.rb annotation
alhafoudh Jan 4, 2024
44d03c7
User visibility settings for Tags, Filters v1
stage-rl Jan 8, 2024
f6108e5
Merge branch 'main' into feature/GO-368-filters
alhafoudh Feb 28, 2024
3281e2e
Resolve merge conflict
alhafoudh Feb 28, 2024
34e344b
Merge branch 'feature/tags_user_visibility_settings' into feature/GO-…
alhafoudh Feb 28, 2024
a11f431
Fix db schema
alhafoudh Feb 28, 2024
9a6425f
Fix wrong merge
alhafoudh Feb 28, 2024
d07a6a0
Merge branch 'refs/heads/main' into feature/GO-368-filters
alhafoudh May 23, 2024
8bcf810
Remove pinning from sidebar
alhafoudh May 23, 2024
adf8361
Tweak sidebar for filter list
alhafoudh May 23, 2024
ef6105c
Rename visibility model to UserItemVisibility and add reordering
alhafoudh May 23, 2024
87c0bd8
Reorganize filtering and enable TagFilter usage
alhafoudh Jun 24, 2024
7cc6801
Make first filter default
alhafoudh Jul 6, 2024
3783ec4
Redirect to default filter and fix active sidebar item tracking
alhafoudh Jul 6, 2024
5935dd4
Add buttons with icons for up down
alhafoudh Jul 6, 2024
cf6ebfa
Make Filter author nullable
alhafoudh Sep 10, 2024
6c4313f
Remove binding.pry
alhafoudh Sep 10, 2024
6a69302
Merge branch 'main' into feature/GO-368-filters
Sep 13, 2024
41f947a
Update filters and tags views, forms, icons, ..
Sep 13, 2024
ab4b919
Refactor routes
Sep 13, 2024
6afd341
Update filter editable scope
Sep 16, 2024
01240ec
Fix filter fixtures
Sep 16, 2024
c845d7b
FGRA-9973: Update tests
Sep 16, 2024
715141c
Update filters creation, scope, components
Sep 20, 2024
15dfcdd
Update tests
Sep 20, 2024
901e018
Try fix random failing notifications_test
Sep 20, 2024
25c6d2a
Merge branch 'main' into feature/GO-368-filters
Sep 20, 2024
d0bf118
Change default_max_wait_time for Capybara
Sep 20, 2024
699fc2f
Update notifications_test
Sep 20, 2024
6f5ba24
Fix migration and filtering by tag filters
Sep 25, 2024
29cc358
Remove is_pinned from filters
Sep 25, 2024
0776ad3
Refactoring after review
Sep 30, 2024
84646a6
Refactoring after review
Nov 15, 2024
21ef1b7
Merge branch 'main' into feature/GO-368-filters
Nov 17, 2024
8824a1f
Basic fix
Nov 17, 2024
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
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ gem 'jwt'
gem 'stimulus-rails'
gem 'jsbundling-rails'
gem 'pdf-reader'
gem "acts_as_list", "~> 1.1"
Copy link
Member

Choose a reason for hiding this comment

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

pin na verziu nerobime pokym naozaj nie je treba

Copy link
Collaborator

Choose a reason for hiding this comment

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

ok


# Monitoring
gem 'rollbar'
Expand Down
3 changes: 3 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ GEM
minitest (>= 5.1)
mutex_m
tzinfo (~> 2.0)
acts_as_list (1.1.0)
activerecord (>= 4.2)
addressable (2.8.6)
public_suffix (>= 2.0.2, < 6.0)
afm (0.2.2)
Expand Down Expand Up @@ -490,6 +492,7 @@ PLATFORMS
x86_64-linux

DEPENDENCIES
acts_as_list (~> 1.1)
annotate
bootsnap (>= 1.4.4)
brakeman
Expand Down
10 changes: 8 additions & 2 deletions app/components/common/icon_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="<%= @stroke_width %>" stroke="currentColor" class="shrink-0 <%= @classes.present? ? @classes : "w-6 h-6" %>">
<path stroke-linecap="round" stroke-linejoin="round" d="<%= @svg %>" />
<svg xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke-width="<%= @stroke_width %>" stroke="currentColor" class="shrink-0 <%= @classes.presence || "w-6 h-6" %>">
<% if @svg.class == Array %>
<% @svg.each do |svg| %>
<path stroke-linecap="round" stroke-linejoin="round" d="<%= svg %>" />
<% end %>
<% else %>
<path stroke-linecap="round" stroke-linejoin="round" d="<%= @svg %>" />
<% end %>
</svg>
4 changes: 3 additions & 1 deletion app/components/common/icon_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@ class IconComponent < ViewComponent::Base
"exclamation-triangle" => "M12 9v3.75m-9.303 3.376c-.866 1.5.217 3.374 1.948 3.374h14.71c1.73 0 2.813-1.874 1.948-3.374L13.949 3.378c-.866-1.5-3.032-1.5-3.898 0L2.697 16.126ZM12 15.75h.007v.008H12v-.008Z",
"clock" => "M12 6v6h4.5m4.5 0a9 9 0 1 1-18 0 9 9 0 0 1 18 0Z",
"cloud-arrow-down" => "M12 9.75v6.75m0 0-3-3m3 3 3-3m-8.25 6a4.5 4.5 0 0 1-1.41-8.775 5.25 5.25 0 0 1 10.233-2.33 3 3 0 0 1 3.758 3.848A3.752 3.752 0 0 1 18 19.5H6.75Z",
"tag" => ["M9.568 3H5.25A2.25 2.25 0 0 0 3 5.25v4.318c0 .597.237 1.17.659 1.591l9.581 9.581c.699.699 1.78.872 2.607.33a18.095 18.095 0 0 0 5.223-5.223c.542-.827.369-1.908-.33-2.607L11.16 3.66A2.25 2.25 0 0 0 9.568 3Z", "M6 6h.008v.008H6V6Z"],
"bookmark" => "M17.593 3.322c1.1.128 1.907 1.077 1.907 2.185V21L12 17.25 4.5 21V5.507c0-1.108.806-2.057 1.907-2.185a48.507 48.507 0 0 1 11.186 0Z",
"paper-airplane" => "M6 12 3.269 3.125A59.769 59.769 0 0 1 21.485 12 59.768 59.768 0 0 1 3.27 20.875L5.999 12Zm0 0h7.5",
"document-arrow-down" => "M19.5 14.25v-2.625a3.375 3.375 0 0 0-3.375-3.375h-1.5A1.125 1.125 0 0 1 13.5 7.125v-1.5a3.375 3.375 0 0 0-3.375-3.375H8.25m.75 12 3 3m0 0 3-3m-3 3v-6m-1.5-9H5.625c-.621 0-1.125.504-1.125 1.125v17.25c0 .621.504 1.125 1.125 1.125h12.75c.621 0 1.125-.504 1.125-1.125V11.25a9 9 0 0 0-9-9Z",
"folder-arrow-down" => "m9 13.5 3 3m0 0 3-3m-3 3v-6m1.06-4.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z"
"folder-arrow-down" => "m9 13.5 3 3m0 0 3-3m-3 3v-6m1.06-4.19-2.12-2.12a1.5 1.5 0 0 0-1.061-.44H4.5A2.25 2.25 0 0 0 2.25 6v12a2.25 2.25 0 0 0 2.25 2.25h15A2.25 2.25 0 0 0 21.75 18V9a2.25 2.25 0 0 0-2.25-2.25h-5.379a1.5 1.5 0 0 1-1.06-.44Z",
}.freeze

def initialize(icon, classes: "", stroke_width: 1.5)
Expand Down
3 changes: 3 additions & 0 deletions app/components/icons/grip_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<svg class="shrink-0 <%= @css_classes.present? ? @css_classes : "w-6 h-6" %>" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 320 512" stroke-width="<%= @stroke_width %>" stroke="currentColor" style="aspect-ratio: 1.6;">
<path d="M40 352l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40zm192 0l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40zM40 320c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0zM232 192l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40zM40 160c-22.1 0-40-17.9-40-40L0 72C0 49.9 17.9 32 40 32l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0zM232 32l48 0c22.1 0 40 17.9 40 40l0 48c0 22.1-17.9 40-40 40l-48 0c-22.1 0-40-17.9-40-40l0-48c0-22.1 17.9-40 40-40z"/>
</svg>
6 changes: 6 additions & 0 deletions app/components/icons/grip_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
class Icons::GripComponent < ViewComponent::Base
Copy link
Member

Choose a reason for hiding this comment

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

Ukazalo sa, ze lepsi sposob je cez Common::IconComponent. kukni tam.

luciajanikova marked this conversation as resolved.
Show resolved Hide resolved
def initialize(css_classes: nil, stroke_width: 1.5)
@css_classes = css_classes
@stroke_width = stroke_width
end
end
7 changes: 7 additions & 0 deletions app/components/icons/star_component.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<svg class="shrink-0 <%= @css_classes.present? ? @css_classes : "w-6 h-6" %>" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 576 512" stroke-width="<%= @stroke_width %>" stroke="currentColor">
<% if solid? %>
<path d="M316.9 18C311.6 7 300.4 0 288.1 0s-23.4 7-28.8 18L195 150.3 51.4 171.5c-12 1.8-22 10.2-25.7 21.7s-.7 24.2 7.9 32.7L137.8 329 113.2 474.7c-2 12 3 24.2 12.9 31.3s23 8 33.8 2.3l128.3-68.5 128.3 68.5c10.8 5.7 23.9 4.9 33.8-2.3s14.9-19.3 12.9-31.3L438.5 329 542.7 225.9c8.6-8.5 11.7-21.2 7.9-32.7s-13.7-19.9-25.7-21.7L381.2 150.3 316.9 18z"/>
<% elsif light? %>
<path d="M287.9 0c9.2 0 17.6 5.2 21.6 13.5l68.6 141.3 153.2 22.6c9 1.3 16.5 7.6 19.3 16.3s.5 18.1-5.9 24.5L433.6 328.4l26.2 155.6c1.5 9-2.2 18.1-9.7 23.5s-17.3 6-25.3 1.7l-137-73.2L151 509.1c-8.1 4.3-17.9 3.7-25.3-1.7s-11.2-14.5-9.7-23.5l26.2-155.6L31.1 218.2c-6.5-6.4-8.7-15.9-5.9-24.5s10.3-14.9 19.3-16.3l153.2-22.6L266.3 13.5C270.4 5.2 278.7 0 287.9 0zm0 79L235.4 187.2c-3.5 7.1-10.2 12.1-18.1 13.3L99 217.9 184.9 303c5.5 5.5 8.1 13.3 6.8 21L171.4 443.7l105.2-56.2c7.1-3.8 15.6-3.8 22.6 0l105.2 56.2L384.2 324.1c-1.3-7.7 1.2-15.5 6.8-21l85.9-85.1L358.6 200.5c-7.8-1.2-14.6-6.1-18.1-13.3L287.9 79z"/>
<% end %>
</svg>
15 changes: 15 additions & 0 deletions app/components/icons/star_component.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Icons::StarComponent < ViewComponent::Base
luciajanikova marked this conversation as resolved.
Show resolved Hide resolved
def initialize(css_classes: nil, stroke_width: 1.5, variant: :solid)
@css_classes = css_classes
@stroke_width = stroke_width
@variant = variant
end

def solid?
@variant == :solid
end

def light?
@variant == :light
end
end
36 changes: 26 additions & 10 deletions app/components/layout/filter_list_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
<% if @filters.present? %>
<div class="flex flex-col justify-start items-start gap-2" data-test="filters">
<div class="flex justify-start items-start px-4 py-2">
<p class="text-sm text-center text-gray-400">Filtre</p>
</div>
<div
<% if @sortable %>
data-controller="sortable"
data-sortable-url-value="<%= sort_filters_path %>"
data-sortable-draggable-class=".item"
data-sortable-handle-class=".handle"
<% end %>
class="w-full flex flex-col justify-start items-start gap-2"
data-test="filters"
>
<% if @sortable %>
<%= link_to 'Sort', '', class: 'hidden', data: { turbo_method: :patch, sortable_target: 'submit', url: sort_filters_path } %>
<% end %>
<% if @label.present? %>
<div class="flex justify-start items-start px-4 py-2">
<p class="text-sm text-center text-gray-400"><%= @label %></p>
</div>
<% end %>
<% @filters.each do |filter| %>
<% url = message_threads_path(q: filter.query) %>
<%= link_to url, class: "text-gray-700 hover:text-indigo-600 hover:bg-gray-50 group w-72 flex gap-x-3 rounded-md p-2 px-4 text-sm leading-6 font-semibold data-[active=true]:bg-gray-50 data-[active=true]:text-indigo-600", data: { active: current_page?(url) } do %>
<%= render Icons::BookmarkComponent.new %>
<p class="truncate text-base font-medium"><%= filter.name %></p>
<% end %>
<%= render TW::SidebarMenuItemComponent.new(
name: filter.name,
url: filtered_message_threads_path(filter:),
icon: icon_for(filter),
variant: :light,
classes: "item #{!@sortable ? 'pl-4' : ''}",
) %>
<% end %>
</div>
<% end %>
<% end %>
13 changes: 12 additions & 1 deletion app/components/layout/filter_list_component.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
class Layout::FilterListComponent < ViewComponent::Base
def initialize(filters:)
include MessageThreadHelper

def initialize(label: nil, filters:, sortable: false)
@label = label
@filters = filters
@sortable = sortable
end

def icon_for(filter)
case filter
when TagFilter then Icons::TagComponent.new
else Icons::BookmarkComponent.new
end
end
end
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
<%= tag.turbo_frame id: "bulk_actions" do %>
<div class="flex justify-stretch items-center gap-4 px-4 lg:py-4 border-t-0 border-r-0 border-b border-l-0 border-gray-200 min-h-[3rem] sm:min-h-[5rem]">
<%= check_box_tag("", nil, false, { class: "hidden sm:block h-4 w-4 rounded border-gray-300 text-blue-500 focus:ring-0", type: "checkbox", id: "checkbox-all", data: { action: "all-checkboxes#toggle", "all-checkboxes-target": "checkbox" } }) %>

<span class="grow sm:text-xl text-base font-semibold text-left text-gray-900"><%= @ids.present? ? t(:selected_message, count: @ids.count) : "Správy v schránke" %>
<span class="grow sm:text-xl text-base font-semibold text-left text-gray-900"><%= title %>
<% if @filter %>
<% if @filter_subscription %>
<%= link_to edit_filter_filter_subscription_path(@filter, @filter_subscription), title: "Nastaviť notifikácie", "data-turbo-frame": :modal, form_class: "inline" do %>
Expand Down
11 changes: 10 additions & 1 deletion app/components/message_threads_bulk_actions_component.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,17 @@
class MessageThreadsBulkActionsComponent < ViewComponent::Base
def initialize(ids:, signable:, filter: nil, filter_subscription: nil)
def initialize(ids: nil, signable:, filter: nil, query: nil, filter_subscription: nil)
@ids = ids
@signable = signable
@filter = filter
@query = query
@filter_subscription = filter_subscription
end

def title
return t(:selected_message, count: @ids.count) if @ids.present?
return "Správy z filtra '#{@filter.name}'" if @filter.present?
return "Hľadaný výraz '#{@query}'" if @query.present?

"Správy v schránke"
end
end
2 changes: 1 addition & 1 deletion app/components/message_threads_table_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<div class="flex flex-col justify-stretch items-stretch gap-4 sm:p-4">
<div class="flex flex-col justify-stretch items-stretch sm:rounded-md bg-white sm:border sm:border-gray-200" data-controller="form all-checkboxes">
<%= render MessageThreadsBulkActionsComponent.new(ids: [], filter: @filter, filter_subscription: @filter_subscription, signable: Current.user.signer?) %>
<%= render MessageThreadsBulkActionsComponent.new(ids: [], filter:, query:, filter_subscription:, signable: Current.user.signer?) %>
Copy link
Member

Choose a reason for hiding this comment

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

Ak su toto nepovinne parametre tak ich tam neposielajme, ale zvlastne ze to nepotrebujeme.

Copy link
Collaborator

Choose a reason for hiding this comment

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

niesu nepovinne, ale ide zase o Shorthand Hash Syntax

<%= form_with url: bulk_actions_message_threads_path, data: { "form-target": "form", "all-checkboxes-target": "form" } do %>
<ul role="list" id="message_threads" class="divide-y divide-gray-100">
<% message_threads.each do |message_thread| %>
Expand Down
5 changes: 4 additions & 1 deletion app/components/message_threads_table_component.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,11 @@ class MessageThreadsTableComponent < ViewComponent::Base
renders_many :message_threads
renders_one :next_page_area

def initialize(filter:, filter_subscription:)
attr_reader :filter, :query, :filter_subscription

def initialize(filter: nil, query: nil, filter_subscription:)
@filter = filter
@query = query
@filter_subscription = filter_subscription
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<div class="w-full p-4 flex-col justify-start items-start gap-4 inline-flex">
<div class="self-stretch bg-white rounded-md border border-gray-200 flex-col justify-start items-start flex">
<div class="flex-col self-stretch p-6 border-b border-gray-200 justify-start items-start gap-4 inline-flex">
<div class="grow shrink basis-0 text-gray-900 text-xl font-semibold leading-[35px]">Filtre</div>
Nastavte si osobnú preferenciu viditeľnosti filtrov v ľavom menu
</div>
<div class="self-stretch flex-col justify-start items-start flex">
<%= render Settings::UserFilterVisibilities::ListRowComponent.with_collection(@visibilities) %>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class Settings::UserFilterVisibilities::ListComponent < ViewComponent::Base
def initialize(visibilities)
@visibilities = visibilities
end
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<div class="self-stretch p-6 border-b border-gray-200 items-center gap-4 inline-flex">
<div class="grow shrink basis-0 gap-1">
<div class="text-gray-900 text-lg font-medium leading-loose w-fit">
<%= @filter.name %>
</div>
</div>
<% if @visibility.new_record? %>
<%= form_with model: [:settings, Current.user.user_filter_visibilities.new(filter: @filter)], method: :post do |form| %>
<%= form.hidden_field :filter_id, value: @filter.id %>
<%= form.hidden_field :visible, value: [email protected] %>
<%= form.button class: "#{@visibility.hidden ? "bg-gray-200" : "bg-indigo-600"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @visibility.hidden.to_s } do %>
Copy link
Member

Choose a reason for hiding this comment

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

<span class="sr-only">Use setting</span>
<span aria-hidden="true" class="<%= @visibility.hidden ? "translate-x-0" : "translate-x-5" %> pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
<% end %>
<% end %>
<% else %>
<%= form_with model: [:move_higher, :settings, @visibility], method: :post do |form| %>
<%= form.button do %>
Up
<% end %>
<% end %>
<%= form_with model: [:move_lower, :settings, @visibility], method: :post do |form| %>
<%= form.button do %>
Down
<% end %>
<% end %>
<%= form_with model: [:settings, @visibility], method: :patch do |form| %>
<%= form.hidden_field :visible, value: [email protected] %>
<%= form.button class: "#{@visibility.hidden ? "bg-gray-200" : "bg-indigo-600"} relative inline-flex h-6 w-11 flex-shrink-0 cursor-pointer rounded-full border-2 border-transparent transition-colors duration-200 ease-in-out focus:outline-none focus:ring-2 focus:ring-indigo-600 focus:ring-offset-2", role: :switch, aria: { checked: @visibility.hidden.to_s } do %>
<span class="sr-only">Use setting</span>
<span aria-hidden="true" class="<%= @visibility.hidden ? "translate-x-0" : "translate-x-5" %> pointer-events-none inline-block h-5 w-5 transform rounded-full bg-white shadow ring-0 transition duration-200 ease-in-out"></span>
<% end %>
<% end %>
<% end %>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class Settings::UserFilterVisibilities::ListRowComponent < ViewComponent::Base
with_collection_parameter :visibility
def initialize(visibility:)
@visibility = visibility
@filter = visibility.filter
end
end
23 changes: 18 additions & 5 deletions app/components/t_w/sidebar_menu_item_component.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,19 @@
<%= link_to @url, class: "items-center text-gray-700 hover:text-indigo-600 hover:bg-gray-50 w-full group flex gap-x-3 rounded-md p-4 leading-6 font-semibold data-[active=true]:bg-gray-50 data-[active=true]:text-indigo-600", data: { active: current_page?(@url, check_parameters: true) } do %>
<% if @icon_component %>
<%= render @icon_component %>
<div
class="flex items-center text-gray-700 hover:text-indigo-600 hover:bg-gray-50 w-full group rounded-md leading-6 font-semibold data-[active=true]:bg-gray-50 data-[active=true]:text-indigo-600 <%= @classes %>"
<%= tag.attributes(data: { active: current_page?(@url, check_parameters: true) } ) %>
>
<% if leading %>
<%= leading %>
<% end %>
<%= @name %>
<% end %>
<%= link_to \
@url,
Copy link
Member

Choose a reason for hiding this comment

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

ooo toto nepoznam \ naucil som sa.

class: "w-full flex gap-x-3 py-4 grow" do %>
<% if @icon_component %>
<%= render @icon_component %>
<% end %>
<span class="truncate text-base <%= light? ? 'font-medium' : '' %>"><%= @name %></span>
<% end %>
<% if trailing %>
<%= trailing %>
<% end %>
</div>
15 changes: 14 additions & 1 deletion app/components/t_w/sidebar_menu_item_component.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,20 @@
class TW::SidebarMenuItemComponent < ViewComponent::Base
def initialize(name:, url:, icon:)
renders_one :leading
renders_one :trailing

def initialize(name:, url:, icon:, variant: :regular, classes: 'pl-4')
@name = name
@url = url
@icon_component = icon
@variant = variant
@classes = classes
end

def regular?
@variant == :regular
end

def light?
@variant == :light
end
end
6 changes: 3 additions & 3 deletions app/components/t_w/top_navigation_component.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@
<div class="flex justify-start items-stretch grow relative gap-3 rounded-md bg-white">
<%= form_with url: message_threads_path, method: :get, html: { class: 'relative flex flex-1' } do |f| %>
<%= render Icons::MagnifyingGlassComponent.gray %>
<%= f.search_field :q, id: "search", value: params[:q], placeholder: 'Vyhľadaj správu', class: 'block h-full w-full border-0 py-0 pr-0 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-base' %>
<%= f.search_field :q, id: "search", value: query, placeholder: 'Vyhľadaj správu', class: 'block h-full w-full border-0 py-0 pr-0 text-gray-900 placeholder:text-gray-400 focus:ring-0 sm:text-base' %>
<% end %>
<% if params[:q].present? %>
<%= link_to new_filter_path(query: params[:q]), data: { turbo_frame: "modal" }, class: "flex items-center gap-2 text-gray-500 hover:text-gray-900", title: "Pridať filter" do %>
<% if query.present? %>
<%= link_to new_filter_path(query:), data: { turbo_frame: "modal" }, class: "flex items-center gap-2 text-gray-500 hover:text-gray-900", title: "Pridať filter" do %>
<%= render Icons::BookmarkComponent.new %>
<% end %>
<% end %>
Expand Down
12 changes: 12 additions & 0 deletions app/components/t_w/top_navigation_component.rb
Original file line number Diff line number Diff line change
@@ -1,2 +1,14 @@
class TW::TopNavigationComponent < ViewComponent::Base
include MessageThreadHelper

def query
query_params = params
.permit(:filter_id, :q)
.slice(:filter_id, :q)

Searchable::QueryBuilder.new(
filter_id: query_params[:filter_id],
query: query_params[:q],
).build
end
end
6 changes: 3 additions & 3 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ def pundit_user
def set_menu_context
return unless Current.user

@tags = policy_scope(Tag, policy_scope_class: TagPolicy::ScopeListable).where(visible: true).order(:name)
@filters = policy_scope(Filter, policy_scope_class: FilterPolicy::ScopeShowable).order(:position)
@menu = SidebarMenu.new(controller_name, action_name, { tags: @tags, filters: @filters }).menu
@filters = Current.user.visible_filters
@menu = SidebarMenu.new(controller_name, action_name, tags: @tags, filters: @filters).menu
@current_tenant_boxes_count = Current.tenant.boxes.count
end
end
25 changes: 22 additions & 3 deletions app/controllers/filters_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ def new
def create
authorize Filter

@filter = Current.tenant.filters.build(filter_params.merge({author_id: Current.user.id}))
@filter = Current.tenant.filters.build(filter_params.merge({ author_id: Current.user.id }))
if @filter.save
flash[:notice] = 'Filter bol úspešne vytvorený'
if params[:to] == 'search'
redirect_to message_threads_path(q: @filter.query)
redirect_to helpers.filtered_message_threads_path(filter: @filter)
Copy link
Member

Choose a reason for hiding this comment

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

toto nejde bez helpers?

Copy link
Member

Choose a reason for hiding this comment

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

Bez hanby by som to dal include do controllera

else
redirect_to filters_path
end
else
if params[:to] == 'search'
redirect_to message_threads_path(q: @filter.query), alert: 'Filter sa nepodarilo vytvoriť :('
redirect_to helpers.filtered_message_threads_path(query: @filter.query), alert: 'Filter sa nepodarilo vytvoriť :('
else
render :new
end
Expand All @@ -59,6 +59,25 @@ def destroy
redirect_to filters_path, notice: 'Filter bol úspešne odstránený'
end

def sort
filters = filter_scope
.where(id: params[:filter_ids])
.reorder('')
.in_order_of(:id, params[:filter_ids])

filters.map do |filter|
authorize filter
end

Filter.transaction do
filters.map.with_index do |filter, i|
Copy link
Member

Choose a reason for hiding this comment

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

each_with_index mozes tiez ak nepotrbujes vysledok

filter.update!(position: i + 1)
end
end

redirect_back fallback_location: filters_path
Copy link
Member

Choose a reason for hiding this comment

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

Toto je turbovina a vieme to lepsie, dnes sme @mirrec hutali 15 sposobov ako a asi mame ako treba. Pozri ako je v threadscontroller spraveny rename.

end

private

def filter_params
Expand Down
Loading
Loading