Skip to content

Commit

Permalink
feature: JS for dashboard wide filters (#2754)
Browse files Browse the repository at this point in the history
* Add  cards_controller.js

* wip

* Integrate updateCards to dashboard_card_controller

* wip

* Refactoring card_filters_controller

* tweaks

* comment

* add card_classes method

---------

Co-authored-by: Paul Bob <[email protected]>
Co-authored-by: Paul Bob <[email protected]>
Co-authored-by: Adrian Marin <[email protected]>
  • Loading branch information
4 people authored May 17, 2024
1 parent 9db6761 commit 75f76a0
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 15 deletions.
27 changes: 15 additions & 12 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ GEM
erubi (~> 1.4)
parser (>= 2.4)
smart_properties
bigdecimal (3.1.7)
bigdecimal (3.1.8)
bindex (0.8.1)
bootsnap (1.18.3)
msgpack (~> 1.2)
Expand Down Expand Up @@ -184,6 +184,7 @@ GEM
crass (1.0.6)
cssbundling-rails (1.4.0)
railties (>= 6.0.0)
csv (3.3.0)
cuprite (0.15)
capybara (~> 3.0)
ferrum (~> 0.14.0)
Expand Down Expand Up @@ -280,10 +281,11 @@ GEM
listen (>= 3.0.0)
railties (>= 6.0.0)
htmlbeautifier (1.4.2)
httparty (0.21.0)
httparty (0.22.0)
csv
mini_mime (>= 1.0.0)
multi_xml (>= 0.5.2)
i18n (1.14.4)
i18n (1.14.5)
concurrent-ruby (~> 1.0)
i18n-tasks (1.0.13)
activesupport (>= 4.0.2)
Expand All @@ -304,8 +306,8 @@ GEM
activesupport (>= 3.0)
nokogiri (>= 1.6)
io-console (0.7.2)
irb (1.12.0)
rdoc
irb (1.13.1)
rdoc (>= 4.0.0)
reline (>= 0.4.2)
iso (0.4.0)
i18n
Expand Down Expand Up @@ -336,9 +338,9 @@ GEM
mapkick-rb (0.1.5)
marcel (1.0.2)
matrix (0.4.2)
meta-tags (2.20.0)
meta-tags (2.21.0)
actionpack (>= 6.0.0, < 7.2)
method_source (1.0.0)
method_source (1.1.0)
mini_magick (4.12.0)
mini_mime (1.1.5)
mini_portile2 (2.8.6)
Expand All @@ -353,7 +355,8 @@ GEM
money (~> 6.13)
railties (>= 3.0)
msgpack (1.7.2)
multi_xml (0.6.0)
multi_xml (0.7.1)
bigdecimal (~> 3.1)
mutex_m (0.2.0)
net-imap (0.4.10)
date
Expand Down Expand Up @@ -384,7 +387,7 @@ GEM
prettier_print (1.2.1)
psych (5.1.2)
stringio
public_suffix (5.0.4)
public_suffix (5.0.5)
puma (6.4.2)
nio4r (~> 2.0)
racc (1.7.3)
Expand Down Expand Up @@ -454,7 +457,7 @@ GEM
rainbow (>= 2.0, < 4.0)
rexml (~> 3.1)
regexp_parser (2.9.0)
reline (0.5.1)
reline (0.5.6)
io-console (~> 0.5)
responders (3.1.1)
actionpack (>= 5.2)
Expand Down Expand Up @@ -584,7 +587,7 @@ GEM
tilt (2.3.0)
timeout (0.4.1)
tty-which (0.5.0)
turbo-rails (2.0.1)
turbo-rails (2.0.5)
actionpack (>= 6.0.0)
activejob (>= 6.0.0)
railties (>= 6.0.0)
Expand All @@ -594,7 +597,7 @@ GEM
concurrent-ruby (~> 1.0)
unaccent (0.4.0)
unicode-display_width (2.5.0)
view_component (3.10.0)
view_component (3.12.1)
activesupport (>= 5.2.0, < 8.0)
concurrent-ruby (~> 1.0)
method_source (~> 1.0)
Expand Down
4 changes: 4 additions & 0 deletions app/helpers/avo/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,10 @@ def white_panel_classes
"bg-white rounded shadow-md"
end

def card_classes
"bg-white rounded shadow-panel"
end

def get_model_class(model)
if model.instance_of?(Class)
model
Expand Down
4 changes: 3 additions & 1 deletion app/javascript/js/controllers.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import ActionsPickerController from './controllers/actions_picker_controller'
import AttachmentsController from './controllers/attachments_controller'
import BelongsToFieldController from './controllers/fields/belongs_to_field_controller'
import BooleanFilterController from './controllers/boolean_filter_controller'
import CardFiltersController from './controllers/card_filters_controller'
import CodeFieldController from './controllers/fields/code_field_controller'
import CopyToClipboardController from './controllers/copy_to_clipboard_controller'
import DashboardCardController from './controllers/dashboard_card_controller'
Expand Down Expand Up @@ -39,15 +40,16 @@ import TabsController from './controllers/tabs_controller'
import TagsFieldController from './controllers/fields/tags_field_controller'
import TextFilterController from './controllers/text_filter_controller'
import TippyController from './controllers/tippy_controller'
import TiptapFieldController from './controllers/fields/tiptap_field_controller'
import ToggleController from './controllers/toggle_controller'
import TrixFieldController from './controllers/fields/trix_field_controller'
import TiptapFieldController from './controllers/fields/tiptap_field_controller'

application.register('action', ActionController)
application.register('actions-overflow', ActionsOverflowController)
application.register('actions-picker', ActionsPickerController)
application.register('attachments', AttachmentsController)
application.register('boolean-filter', BooleanFilterController)
application.register('card-filters', CardFiltersController)
application.register('copy-to-clipboard', CopyToClipboardController)
application.register('dashboard-card', DashboardCardController)
application.register('filter', FilterController)
Expand Down
13 changes: 13 additions & 0 deletions app/javascript/js/controllers/card_filters_controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { Controller } from '@hotwired/stimulus'
import URI from 'urijs'

export default class extends Controller {
static targets = ['cards']

updateCards(event) {
this.cardsTargets.forEach((frame) => {
// Add date param to the existing frame.src
frame.src = new URI(frame.src).setQuery('date', event.target.dataset.days).toString()
})
}
}
4 changes: 2 additions & 2 deletions app/javascript/js/controllers/dashboard_card_controller.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { Controller } from '@hotwired/stimulus'

export default class extends Controller {
static targets = ['card'];
static targets = ['card']

interval;
interval

get parentTurboFrame() {
return this.context.scope.element.closest('turbo-frame')
Expand Down

0 comments on commit 75f76a0

Please sign in to comment.