-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: main
Are you sure you want to change the base?
Changes from 23 commits
473af6d
914d2fb
0a03182
a6b44f0
be94fbe
d8e29ff
5b0b7a3
2fcbce2
8d1e4e9
8bfd59d
44d03c7
f6108e5
3281e2e
34e344b
a11f431
9a6425f
d07a6a0
8bcf810
adf8361
ef6105c
87c0bd8
7cc6801
3783ec4
5935dd4
cf6ebfa
6c4313f
6a69302
41f947a
ab4b919
6afd341
01240ec
c845d7b
715141c
15dfcdd
901e018
25c6d2a
d0bf118
699fc2f
6f5ba24
29cc358
0776ad3
84646a6
21ef1b7
8824a1f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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> |
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> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
class Icons::GripComponent < ViewComponent::Base | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
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> |
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 |
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 %> |
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,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 |
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?) %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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| %> | ||
|
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 %> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. existuje takyto fajny helper https://www.bigbinary.com/blog/rails-6-1-introduces-class_names-helper |
||
<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 |
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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ooo toto nepoznam |
||
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> |
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 |
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 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. toto nejde bez helpers? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
@@ -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| | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
filter.update!(position: i + 1) | ||
end | ||
end | ||
|
||
redirect_back fallback_location: filters_path | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 | ||
|
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok