Class: Monolith::TablesController::Show
- Inherits:
-
View
- Object
- View
- Monolith::TablesController::Show
- Defined in:
- app/controllers/monolith/tables_controller.rb
Instance Attribute Summary collapse
-
#page ⇒ Object
writeonly
Sets the attribute page.
-
#per_page ⇒ Object
writeonly
Sets the attribute per_page.
-
#rows ⇒ Object
writeonly
Sets the attribute rows.
-
#table ⇒ Object
writeonly
Sets the attribute table.
-
#total ⇒ Object
writeonly
Sets the attribute total.
Instance Method Summary collapse
Instance Attribute Details
#page=(value) ⇒ Object (writeonly)
Sets the attribute page
122 123 124 |
# File 'app/controllers/monolith/tables_controller.rb', line 122 def page=(value) @page = value end |
#per_page=(value) ⇒ Object (writeonly)
Sets the attribute per_page
122 123 124 |
# File 'app/controllers/monolith/tables_controller.rb', line 122 def per_page=(value) @per_page = value end |
#rows=(value) ⇒ Object (writeonly)
Sets the attribute rows
122 123 124 |
# File 'app/controllers/monolith/tables_controller.rb', line 122 def rows=(value) @rows = value end |
#table=(value) ⇒ Object (writeonly)
Sets the attribute table
122 123 124 |
# File 'app/controllers/monolith/tables_controller.rb', line 122 def table=(value) @table = value end |
#total=(value) ⇒ Object (writeonly)
Sets the attribute total
122 123 124 |
# File 'app/controllers/monolith/tables_controller.rb', line 122 def total=(value) @total = value end |
Instance Method Details
#end_row ⇒ Object
156 |
# File 'app/controllers/monolith/tables_controller.rb', line 156 def end_row = [@page * @per_page, @total].min |
#format_cell(v) ⇒ Object
158 159 160 161 162 163 164 165 |
# File 'app/controllers/monolith/tables_controller.rb', line 158 def format_cell(v) case v when Hash, Array then code { v.ai(plain: true) rescue v.to_json } when Time, DateTime, Date then v.iso8601 else v.nil? ? em { "NULL" } : v.to_s end end |
#start_row ⇒ Object
155 |
# File 'app/controllers/monolith/tables_controller.rb', line 155 def start_row = ((@page - 1) * @per_page) + 1 |
#view_template ⇒ Object
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
# File 'app/controllers/monolith/tables_controller.rb', line 124 def view_template div(class: "p-6 space-y-4") do h1(class: "text-2xl font-bold") { @table.name } p do plain "Rows " strong { "#{start_row}-#{end_row}" } plain " of #{@total} (per page: #{@per_page})" if @table.primary_key span(class: "ml-2 text-sm") { "PK: #{@table.primary_key}" } end end Table @table.columns do it.row(col) { format_cell(it[col]) } end div(class: "flex items-center gap-3") do if @page > 1 nav_link "← Prev", controller: "/monolith/tables", action: :show, id: @table.name, page: @page - 1, per_page: @per_page end if end_row < @total nav_link "Next →", controller: "/monolith/tables", action: :show, id: @table.name, page: @page + 1, per_page: @per_page end span(class: "text-sm ml-auto") { "Page #{@page}" } nav_link "All tables", controller: "/monolith/tables", action: :index end end end |