Skip to content

Commit 9e77ce4

Browse files
author
Mattia Roccoberton
committed
feat: handle params in pages
1 parent f86f934 commit 9e77ce4

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

lib/tiny_admin/router.rb

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,15 @@ def root_route(router)
5858
router.redirect route_for(TinyAdmin.settings.root[:redirect])
5959
else
6060
page_class = to_class(TinyAdmin.settings.root[:page])
61-
render_page prepare_page(page_class, attributes: TinyAdmin.settings.root.slice(:content, :title, :widgets))
61+
attributes = TinyAdmin.settings.root.slice(:content, :title, :widgets)
62+
render_page prepare_page(page_class, attributes: attributes, params: request.params)
6263
end
6364
end
6465

6566
def setup_page_route(router, slug, page_data)
6667
router.get slug do
6768
attributes = page_data.slice(:content, :title, :widgets)
68-
render_page prepare_page(page_data[:class], slug: slug, attributes: attributes)
69+
render_page prepare_page(page_data[:class], slug: slug, attributes: attributes, params: request.params)
6970
end
7071
end
7172

lib/tiny_admin/utils.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def params_to_s(params)
1414
list.join('&')
1515
end
1616

17-
def prepare_page(page_class, slug: nil, attributes: nil, options: nil)
17+
def prepare_page(page_class, slug: nil, attributes: nil, options: nil, params: nil)
1818
page_class.new.tap do |page|
1919
page.options = options
2020
page.head_component = TinyAdmin.settings.components[:head]&.new
@@ -27,9 +27,11 @@ def prepare_page(page_class, slug: nil, attributes: nil, options: nil)
2727
items: options&.include?(:no_menu) ? [] : TinyAdmin.settings.store&.navbar
2828
)
2929
attrs = attributes || {}
30+
attrs[:params] = params if params
3031
attrs[:widgets] = attrs[:widgets].map { to_class(_1) } if attrs[:widgets]
3132
page.update_attributes(attrs) unless attrs.empty?
3233
yield(page) if block_given?
34+
page.setup if page.respond_to?(:setup)
3335
end
3436
end
3537

lib/tiny_admin/views/basic_layout.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ module Views
55
class BasicLayout < Phlex::HTML
66
include Utils
77

8-
attr_accessor :content, :widgets
8+
attr_accessor :content, :params, :widgets
99

1010
def label_for(value, options: [])
1111
TinyAdmin.settings.helper_class.label_for(value, options: options)

0 commit comments

Comments
 (0)