Class: Records::HeaderActions

Inherits:
Components::Base
  • Object
show all
Includes:
Phlex::Rails::Helpers::ButtonTo, Phlex::Rails::Helpers::LinkTo, Phlex::Rails::Helpers::Routes, Phlex::Rails::Helpers::TurboFrameTag
Defined in:
app/components/databasium/records/header_actions.rb

Constant Summary collapse

LIMITS =
[ 10, 20, 50, 100 ].freeze

Instance Method Summary collapse

Constructor Details

#initialize(filter:, table:, limit:) ⇒ HeaderActions

Returns a new instance of HeaderActions.



11
12
13
14
15
# File 'app/components/databasium/records/header_actions.rb', line 11

def initialize(filter:, table:, limit:)
  @filter = filter
  @table = table
  @limit = limit
end

Instance Method Details

#view_templateObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'app/components/databasium/records/header_actions.rb', line 17

def view_template
  div(id: "header_actions", class: "flex max-w-full items-center overflow-x-auto") do
    limit = @limit.to_i
    div(class: "flex items-center gap-2 mr-2") do
      p(class: "text-sm font-bold") { "#{@table}" }
    end
    button(
      type: "submit",
      form: "delete_records_form",
      data: {
        turbo_stream: true
      },
      class: "hidden bg-accent px-4 py-1 rounded-xl text-base me-2"
    ) { span(data: { table_target: "deleteButton" }) { } }

    render Components::Databasium::Navigation::IconPanel.new(
             icons_with_text: [
               {
                 icon: "funnel",
                 text: "filter",
                 method: :frontend,
                 data_params: {
                   toggle: "filter",
                   action: "click->toggle#toggle"
                 }
               },
               {
                 icon: "plus-circle",
                 text: "add",
                 method: :frontend,
                 data_params: {
                   toggle: "addRecord",
                   action: "click->toggle#toggle"
                 }
               },
               {
                 icon: "pencil-square",
                 text: "edit",
                 method: :frontend,
                 data_params: {
                   toggle: "editRecord",
                   action: "click->toggle#toggleSticky"
                 }
               },
               {
                 icon: "chevron-double-up",
                 text: "10",
                 method: :get,
                 turbo_frame: "records_list",
                 path: records_path(),
                 active: limit == 10
               },
               {
                 icon: "chevron-double-up",
                 text: "20",
                 method: :get,
                 turbo_frame: "records_list",
                 path: records_path(limit: 20),
                 active: limit == 20
               },
               {
                 icon: "chevron-double-up",
                 text: "50",
                 method: :get,
                 turbo_frame: "records_list",
                 path: records_path(limit: 50),
                 active: limit == 50
               },
               {
                 icon: "chevron-double-up",
                 text: "100",
                 method: :get,
                 turbo_frame: "records_list",
                 path: records_path(limit: 100),
                 active: limit == 100
               }
             ]
           )
  end
end