Module: Dbviewer::ApplicationHelper
- Defined in:
- app/helpers/dbviewer/application_helper.rb
Instance Method Summary collapse
-
#active_nav_class(controller_name, action_name = nil) ⇒ Object
Helper method to determine if current controller and action match.
-
#code_block_bg_class ⇒ Object
Helper method for code blocks background that adapts to dark mode.
-
#column_type_icon(column_type) ⇒ Object
Get appropriate icon for column data type.
-
#current_table?(table_name) ⇒ Boolean
Determine if the current table should be active in the sidebar.
-
#dashboard_nav_class ⇒ Object
Helper for highlighting dashboard link.
-
#erd_nav_class ⇒ Object
Helper for highlighting ERD link.
- #format_cell_value(value) ⇒ Object
-
#format_table_name(table_name) ⇒ Object
Format table name for display - truncate if too long.
-
#logs_nav_class ⇒ Object
Helper for highlighting SQL Logs link.
-
#stat_card_bg_class ⇒ Object
Returns the appropriate background class for stat cards that adapts to dark mode.
-
#tables_nav_class ⇒ Object
Helper for highlighting tables link.
-
#theme_toggle_icon ⇒ Object
Returns the theme toggle icon based on the current theme.
-
#theme_toggle_label ⇒ Object
Returns the aria label for the theme toggle button.
Instance Method Details
#active_nav_class(controller_name, action_name = nil) ⇒ Object
Helper method to determine if current controller and action match
87 88 89 90 91 92 93 94 95 96 |
# File 'app/helpers/dbviewer/application_helper.rb', line 87 def active_nav_class(controller_name, action_name = nil) current_controller = params[:controller].split("/").last active = current_controller == controller_name if action_name.present? active = active && params[:action] == action_name end active ? "active" : "" end |
#code_block_bg_class ⇒ Object
Helper method for code blocks background that adapts to dark mode
48 49 50 |
# File 'app/helpers/dbviewer/application_helper.rb', line 48 def code_block_bg_class "sql-code-block" end |
#column_type_icon(column_type) ⇒ Object
Get appropriate icon for column data type
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'app/helpers/dbviewer/application_helper.rb', line 67 def column_type_icon(column_type) case column_type.to_s.downcase when /int/, /serial/, /number/, /decimal/, /float/, /double/ "bi-123" when /char/, /text/, /string/, /uuid/ "bi-fonts" when /date/, /time/ "bi-calendar" when /bool/ "bi-toggle-on" when /json/, /jsonb/ "bi-braces" when /array/ "bi-list-ol" else "bi-file-earmark" end end |
#current_table?(table_name) ⇒ Boolean
Determine if the current table should be active in the sidebar
53 54 55 |
# File 'app/helpers/dbviewer/application_helper.rb', line 53 def current_table?(table_name) @table_name.present? && @table_name == table_name end |
#dashboard_nav_class ⇒ Object
Helper for highlighting dashboard link
99 100 101 |
# File 'app/helpers/dbviewer/application_helper.rb', line 99 def dashboard_nav_class active_nav_class("home") end |
#erd_nav_class ⇒ Object
Helper for highlighting ERD link
109 110 111 |
# File 'app/helpers/dbviewer/application_helper.rb', line 109 def erd_nav_class active_nav_class("entity_relationship_diagrams") end |
#format_cell_value(value) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'app/helpers/dbviewer/application_helper.rb', line 3 def format_cell_value(value) return "NULL" if value.nil? return value.to_s.truncate(100) unless value.is_a?(String) case value when /\A\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}/ # ISO 8601 datetime begin Time.parse(value).strftime("%Y-%m-%d %H:%M:%S") rescue value.to_s.truncate(100) end when /\A\d{4}-\d{2}-\d{2}\z/ # Date value when /\A{.+}\z/, /\A\[.+\]\z/ # JSON begin JSON.pretty_generate(JSON.parse(value)).truncate(100) rescue value.to_s.truncate(100) end else value.to_s.truncate(100) end end |
#format_table_name(table_name) ⇒ Object
Format table name for display - truncate if too long
58 59 60 61 62 63 64 |
# File 'app/helpers/dbviewer/application_helper.rb', line 58 def format_table_name(table_name) if table_name.length > 20 "#{table_name.first(17)}..." else table_name end end |
#logs_nav_class ⇒ Object
Helper for highlighting SQL Logs link
114 115 116 |
# File 'app/helpers/dbviewer/application_helper.rb', line 114 def logs_nav_class active_nav_class("logs") end |
#stat_card_bg_class ⇒ Object
Returns the appropriate background class for stat cards that adapts to dark mode
43 44 45 |
# File 'app/helpers/dbviewer/application_helper.rb', line 43 def stat_card_bg_class "stat-card-bg" end |
#tables_nav_class ⇒ Object
Helper for highlighting tables link
104 105 106 |
# File 'app/helpers/dbviewer/application_helper.rb', line 104 def tables_nav_class active_nav_class("tables") end |
#theme_toggle_icon ⇒ Object
Returns the theme toggle icon based on the current theme
33 34 35 |
# File 'app/helpers/dbviewer/application_helper.rb', line 33 def theme_toggle_icon '<i class="bi bi-moon"></i><i class="bi bi-sun"></i>'.html_safe end |
#theme_toggle_label ⇒ Object
Returns the aria label for the theme toggle button
38 39 40 |
# File 'app/helpers/dbviewer/application_helper.rb', line 38 def theme_toggle_label "Toggle dark mode" end |