Class: HakumiComponents::Table::Configs::Pagination
- Inherits:
-
Object
- Object
- HakumiComponents::Table::Configs::Pagination
- Extended by:
- T::Sig
- Defined in:
- app/components/hakumi_components/table/configs.rb
Constant Summary collapse
- ShowTotal =
T.type_alias { HakumiComponents::Pagination::Component::ShowTotal }
- Value =
T.type_alias { T.nilable(T.any(ViewComponent::Base, HakumiComponents::Table::Configs::Pagination)) }
- Input =
T.type_alias { T.nilable(T.any(ViewComponent::Base, InputHash, HakumiComponents::Table::Configs::Pagination)) }
Instance Attribute Summary collapse
-
#align ⇒ Object
readonly
Returns the value of attribute align.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#hide_on_single_page ⇒ Object
readonly
Returns the value of attribute hide_on_single_page.
-
#href ⇒ Object
readonly
Returns the value of attribute href.
-
#next_text ⇒ Object
readonly
Returns the value of attribute next_text.
-
#page_param ⇒ Object
readonly
Returns the value of attribute page_param.
-
#page_size ⇒ Object
readonly
Returns the value of attribute page_size.
-
#page_size_options ⇒ Object
readonly
Returns the value of attribute page_size_options.
-
#per_page_param ⇒ Object
readonly
Returns the value of attribute per_page_param.
-
#preserve_params ⇒ Object
readonly
Returns the value of attribute preserve_params.
-
#prev_text ⇒ Object
readonly
Returns the value of attribute prev_text.
-
#server_side ⇒ Object
readonly
Returns the value of attribute server_side.
-
#show_quick_jumper ⇒ Object
readonly
Returns the value of attribute show_quick_jumper.
-
#show_size_changer ⇒ Object
readonly
Returns the value of attribute show_size_changer.
-
#show_total ⇒ Object
readonly
Returns the value of attribute show_total.
-
#simple ⇒ Object
readonly
Returns the value of attribute simple.
-
#size ⇒ Object
readonly
Returns the value of attribute size.
-
#sort_field_param ⇒ Object
readonly
Returns the value of attribute sort_field_param.
-
#sort_order_param ⇒ Object
readonly
Returns the value of attribute sort_order_param.
-
#total ⇒ Object
readonly
Returns the value of attribute total.
-
#turbo_action ⇒ Object
readonly
Returns the value of attribute turbo_action.
-
#turbo_frame ⇒ Object
readonly
Returns the value of attribute turbo_frame.
Class Method Summary collapse
Instance Method Summary collapse
- #ajax? ⇒ Boolean
- #build_ajax_component ⇒ Object
- #build_component ⇒ Object
-
#initialize(total:, current: 1, page_size: 10, size: :default, align: :start, simple: false, show_size_changer: nil, show_quick_jumper: false, show_total: nil, page_size_options: HakumiComponents::Pagination::Component::DEFAULT_PAGE_SIZE_OPTIONS, hide_on_single_page: false, prev_text: nil, next_text: nil, href: nil, page_param: :page, per_page_param: :per_page, turbo_frame: nil, turbo_action: nil, preserve_params: nil, sort_field_param: nil, sort_order_param: nil, server_side: false) ⇒ Pagination
constructor
A new instance of Pagination.
Constructor Details
#initialize(total:, current: 1, page_size: 10, size: :default, align: :start, simple: false, show_size_changer: nil, show_quick_jumper: false, show_total: nil, page_size_options: HakumiComponents::Pagination::Component::DEFAULT_PAGE_SIZE_OPTIONS, hide_on_single_page: false, prev_text: nil, next_text: nil, href: nil, page_param: :page, per_page_param: :per_page, turbo_frame: nil, turbo_action: nil, preserve_params: nil, sort_field_param: nil, sort_order_param: nil, server_side: false) ⇒ Pagination
Returns a new instance of Pagination.
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 |
# File 'app/components/hakumi_components/table/configs.rb', line 314 def initialize( total:, current: 1, page_size: 10, size: :default, align: :start, simple: false, show_size_changer: nil, show_quick_jumper: false, show_total: nil, page_size_options: HakumiComponents::Pagination::Component::DEFAULT_PAGE_SIZE_OPTIONS, hide_on_single_page: false, prev_text: nil, next_text: nil, href: nil, page_param: :page, per_page_param: :per_page, turbo_frame: nil, turbo_action: nil, preserve_params: nil, sort_field_param: nil, sort_order_param: nil, server_side: false ) @total = T.let(total, Integer) @current = T.let(current, Integer) @page_size = T.let(page_size, Integer) @size = T.let(size, Symbol) @align = T.let(align, Symbol) @simple = T.let(simple, T::Boolean) @show_size_changer = T.let(show_size_changer, T.nilable(T::Boolean)) @show_quick_jumper = T.let(show_quick_jumper, T::Boolean) @show_total = T.let(show_total, ShowTotal) @page_size_options = T.let(, T::Array[Integer]) @hide_on_single_page = T.let(hide_on_single_page, T::Boolean) @prev_text = T.let(prev_text, T.nilable(String)) @next_text = T.let(next_text, T.nilable(String)) @href = T.let(href, T.nilable(String)) @page_param = T.let(page_param, Symbol) @per_page_param = T.let(per_page_param, Symbol) @turbo_frame = T.let(turbo_frame, T.nilable(String)) @turbo_action = T.let(turbo_action, T.nilable(String)) @preserve_params = T.let(preserve_params, T.nilable(String)) @sort_field_param = T.let(sort_field_param, T.nilable(String)) @sort_order_param = T.let(sort_order_param, T.nilable(String)) @server_side = T.let(server_side, T::Boolean) end |
Instance Attribute Details
#align ⇒ Object (readonly)
Returns the value of attribute align.
366 367 368 |
# File 'app/components/hakumi_components/table/configs.rb', line 366 def align @align end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
363 364 365 |
# File 'app/components/hakumi_components/table/configs.rb', line 363 def current @current end |
#hide_on_single_page ⇒ Object (readonly)
Returns the value of attribute hide_on_single_page.
369 370 371 |
# File 'app/components/hakumi_components/table/configs.rb', line 369 def hide_on_single_page @hide_on_single_page end |
#href ⇒ Object (readonly)
Returns the value of attribute href.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def href @href end |
#next_text ⇒ Object (readonly)
Returns the value of attribute next_text.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def next_text @next_text end |
#page_param ⇒ Object (readonly)
Returns the value of attribute page_param.
366 367 368 |
# File 'app/components/hakumi_components/table/configs.rb', line 366 def page_param @page_param end |
#page_size ⇒ Object (readonly)
Returns the value of attribute page_size.
363 364 365 |
# File 'app/components/hakumi_components/table/configs.rb', line 363 def page_size @page_size end |
#page_size_options ⇒ Object (readonly)
Returns the value of attribute page_size_options.
378 379 380 |
# File 'app/components/hakumi_components/table/configs.rb', line 378 def @page_size_options end |
#per_page_param ⇒ Object (readonly)
Returns the value of attribute per_page_param.
366 367 368 |
# File 'app/components/hakumi_components/table/configs.rb', line 366 def per_page_param @per_page_param end |
#preserve_params ⇒ Object (readonly)
Returns the value of attribute preserve_params.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def preserve_params @preserve_params end |
#prev_text ⇒ Object (readonly)
Returns the value of attribute prev_text.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def prev_text @prev_text end |
#server_side ⇒ Object (readonly)
Returns the value of attribute server_side.
369 370 371 |
# File 'app/components/hakumi_components/table/configs.rb', line 369 def server_side @server_side end |
#show_quick_jumper ⇒ Object (readonly)
Returns the value of attribute show_quick_jumper.
369 370 371 |
# File 'app/components/hakumi_components/table/configs.rb', line 369 def show_quick_jumper @show_quick_jumper end |
#show_size_changer ⇒ Object (readonly)
Returns the value of attribute show_size_changer.
372 373 374 |
# File 'app/components/hakumi_components/table/configs.rb', line 372 def show_size_changer @show_size_changer end |
#show_total ⇒ Object (readonly)
Returns the value of attribute show_total.
375 376 377 |
# File 'app/components/hakumi_components/table/configs.rb', line 375 def show_total @show_total end |
#simple ⇒ Object (readonly)
Returns the value of attribute simple.
369 370 371 |
# File 'app/components/hakumi_components/table/configs.rb', line 369 def simple @simple end |
#size ⇒ Object (readonly)
Returns the value of attribute size.
366 367 368 |
# File 'app/components/hakumi_components/table/configs.rb', line 366 def size @size end |
#sort_field_param ⇒ Object (readonly)
Returns the value of attribute sort_field_param.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def sort_field_param @sort_field_param end |
#sort_order_param ⇒ Object (readonly)
Returns the value of attribute sort_order_param.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def sort_order_param @sort_order_param end |
#total ⇒ Object (readonly)
Returns the value of attribute total.
363 364 365 |
# File 'app/components/hakumi_components/table/configs.rb', line 363 def total @total end |
#turbo_action ⇒ Object (readonly)
Returns the value of attribute turbo_action.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def turbo_action @turbo_action end |
#turbo_frame ⇒ Object (readonly)
Returns the value of attribute turbo_frame.
381 382 383 |
# File 'app/components/hakumi_components/table/configs.rb', line 381 def turbo_frame @turbo_frame end |
Class Method Details
.coerce(value, total:) ⇒ Object
424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 |
# File 'app/components/hakumi_components/table/configs.rb', line 424 def self.coerce(value, total:) return nil if value.nil? || value == false return value if value.is_a?(ViewComponent::Base) || value.is_a?(HakumiComponents::Table::Configs::Pagination) return nil unless value.is_a?(Hash) normalized = value.deep_symbolize_keys = Array(normalized[:page_size_options]).filter_map do |entry| entry.is_a?(Numeric) ? entry.to_i : nil end = HakumiComponents::Pagination::Component::DEFAULT_PAGE_SIZE_OPTIONS if .empty? raw_show_total = T.let(normalized[:show_total], HakumiComponents::Table::DefinitionTypes::RawEntry) show_total = T.let(nil, ShowTotal) if raw_show_total == true || raw_show_total == false || raw_show_total.is_a?(String) show_total = raw_show_total elsif raw_show_total.is_a?(Proc) show_total = lambda do |total_count, range| raw_show_total.call(total_count, range).to_s end end preserve_params = T.let(normalized[:preserve_params], HakumiComponents::Table::DefinitionTypes::RawEntry) preserve_params = preserve_params.to_s if preserve_params.is_a?(Symbol) preserve_params = nil unless preserve_params.nil? || preserve_params.is_a?(String) total_value = T.let(normalized[:total], HakumiComponents::Table::DefinitionTypes::RawEntry) resolved_total = total_value.is_a?(Numeric) ? total_value.to_i : total new( total: resolved_total, current: normalize_integer(normalized[:current] || normalized[:page], fallback: 1), page_size: normalize_integer(normalized[:page_size] || normalized[:pageSize], fallback: 10), size: normalize_symbol(normalized[:size], fallback: :default), align: normalize_symbol(normalized[:align], fallback: :start), simple: normalized[:simple] == true, show_size_changer: normalize_nullable_boolean(normalized[:show_size_changer]), show_quick_jumper: normalized[:show_quick_jumper] == true, show_total: show_total, page_size_options: , hide_on_single_page: normalized[:hide_on_single_page] == true, prev_text: normalize_string(normalized[:prev_text]), next_text: normalize_string(normalized[:next_text]), href: normalize_string(normalized[:href]), page_param: normalize_symbol(normalized[:page_param], fallback: :page), per_page_param: normalize_symbol(normalized[:per_page_param], fallback: :per_page), turbo_frame: normalize_string(normalized[:turbo_frame]), turbo_action: normalize_string(normalized[:turbo_action]), preserve_params: preserve_params, sort_field_param: normalize_string(normalized[:sort_field_param]), sort_order_param: normalize_string(normalized[:sort_order_param]), server_side: normalized[:server_side] == true ) end |
Instance Method Details
#ajax? ⇒ Boolean
384 385 386 |
# File 'app/components/hakumi_components/table/configs.rb', line 384 def ajax? @href.present? || @server_side end |
#build_ajax_component ⇒ Object
414 415 416 417 418 419 420 421 |
# File 'app/components/hakumi_components/table/configs.rb', line 414 def build_ajax_component HakumiComponents::Pagination::Component.new( current: 1, page_size: @page_size, total: 0, show_size_changer: @show_size_changer.nil? ? true : @show_size_changer ) end |
#build_component ⇒ Object
389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 |
# File 'app/components/hakumi_components/table/configs.rb', line 389 def build_component HakumiComponents::Pagination::Component.new( total: @total, current: @current, page_size: @page_size, size: @size, align: @align, simple: @simple, show_size_changer: @show_size_changer, show_quick_jumper: @show_quick_jumper, show_total: @show_total, page_size_options: @page_size_options, hide_on_single_page: @hide_on_single_page, prev_text: @prev_text, next_text: @next_text, href: @href, page_param: @page_param, per_page_param: @per_page_param, turbo_frame: @turbo_frame, turbo_action: @turbo_action, preserve_params: @preserve_params ) end |