Module: Solidstats::ApplicationHelper

Defined in:
app/helpers/solidstats/application_helper.rb

Instance Method Summary collapse

Instance Method Details

#quick_actionsObject



25
26
27
28
29
30
31
32
# File 'app/helpers/solidstats/application_helper.rb', line 25

def quick_actions
  [
    { icon: "refresh-ccw", label: "Refresh All", color: "blue" },
    { icon: "download", label: "Export Data", color: "green" },
    { icon: "bar-chart-2", label: "View Reports", color: "purple" },
    { icon: "tool", label: "Settings", color: "orange" }
  ]
end

#solidstats_cdn_dependenciesObject

CDN dependencies helper



150
151
152
153
154
155
156
157
# File 'app/helpers/solidstats/application_helper.rb', line 150

def solidstats_cdn_dependencies
  [
    tag(:meta, name: "viewport", content: "width=device-width,initial-scale=1"),
    stylesheet_link_tag("https://cdn.jsdelivr.net/npm/[email protected]/dist/full.min.css", media: "all"),
    javascript_include_tag("https://cdn.tailwindcss.com"),
    javascript_include_tag("https://unpkg.com/feather-icons")
  ].join.html_safe
end

#solidstats_scriptsObject

Inline JavaScript helper - reads all JS files and returns them as a script tag



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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
# File 'app/helpers/solidstats/application_helper.rb', line 59

def solidstats_scripts
  return @solidstats_scripts_cache if defined?(@solidstats_scripts_cache)

  begin
    engine_root = Solidstats::Engine.root
    js_files = Dir.glob("#{engine_root}/app/assets/javascripts/solidstats/**/*.js")

    if js_files.any?
      combined_js = js_files.map do |file_path|
        relative_path = file_path.gsub("#{engine_root}/app/assets/javascripts/solidstats/", "")
        javascript_content = File.read(file_path)
        # Remove Sprockets directives since we're inlining
        cleaned_js = javascript_content.gsub(/^\/\/=.*$/, "").strip

        "/* === #{relative_path} === */\n#{cleaned_js}"
      end.join("\n\n")

      dashboard_js = <<~JS
        /* === Dashboard Core Scripts === */
        document.addEventListener('DOMContentLoaded', function() {
          // Initialize Feather icons if available
          if (typeof feather !== 'undefined') {
            feather.replace();
          }
        #{'  '}
          // Auto-refresh functionality with animations
          setInterval(function() {
            document.querySelectorAll('.card').forEach(function(card) {
              card.style.transform = 'scale(1.02)';
              setTimeout(function() {
                card.style.transform = '';
              }, 200);
            });
          }, 30000);

          // Add loading states to forms
          document.querySelectorAll('form[data-turbo-submits-with]').forEach(function(form) {
            form.addEventListener('submit', function() {
              var submitBtn = form.querySelector('button[type="submit"]');
              if (submitBtn) {
                submitBtn.classList.add('loading');
                submitBtn.disabled = true;
              }
            });
          });
        });
      JS

      final_js = combined_js + "\n\n" + dashboard_js
    else
      # No JS files found, just include dashboard scripts
      final_js = <<~JS
        /* === Dashboard Core Scripts === */
        document.addEventListener('DOMContentLoaded', function() {
          // Initialize Feather icons if available
          if (typeof feather !== 'undefined') {
            feather.replace();
          }
        #{'  '}
          // Auto-refresh functionality with animations
          setInterval(function() {
            document.querySelectorAll('.card').forEach(function(card) {
              card.style.transform = 'scale(1.02)';
              setTimeout(function() {
                card.style.transform = '';
              }, 200);
            });
          }, 30000);

          // Add loading states to forms
          document.querySelectorAll('form[data-turbo-submits-with]').forEach(function(form) {
            form.addEventListener('submit', function() {
              var submitBtn = form.querySelector('button[type="submit"]');
              if (submitBtn) {
                submitBtn.classList.add('loading');
                submitBtn.disabled = true;
              }
            });
          });
        });
      JS
    end

    @solidstats_scripts_cache = (:script, final_js.html_safe, type: "text/javascript")
  rescue => e
    Rails.logger.error "Solidstats JavaScript loading error: #{e.message}"
    (:script, "console.error('Solidstats JavaScript loading failed: #{e.message}');", type: "text/javascript")
  end
end

#solidstats_stylesObject

Inline CSS helper - reads all CSS files and returns them as a style tag



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'app/helpers/solidstats/application_helper.rb', line 35

def solidstats_styles
  return @solidstats_styles_cache if defined?(@solidstats_styles_cache)

  begin
    engine_root = Solidstats::Engine.root
    css_files = Dir.glob("#{engine_root}/app/assets/stylesheets/solidstats/*.css")

    combined_css = css_files.map do |file_path|
      relative_path = file_path.gsub("#{engine_root}/app/assets/stylesheets/solidstats/", "")

      # Skip manifest files (application.css with require statements)
      next if relative_path == "application.css"

      "/* === #{relative_path} === */\n#{File.read(file_path)}"
    end.compact.join("\n\n")

    @solidstats_styles_cache = (:style, combined_css.html_safe, type: "text/css")
  rescue => e
    Rails.logger.error "Solidstats CSS loading error: #{e.message}"
    (:style, "/* Solidstats CSS loading failed: #{e.message} */", type: "text/css")
  end
end

#time_ago_in_words(from_time) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/helpers/solidstats/application_helper.rb', line 3

def time_ago_in_words(from_time)
  return "just now" if from_time.nil?

  distance_in_seconds = (Time.current - from_time).to_i

  case distance_in_seconds
  when 0..29
    "just now"
  when 30..59
    "#{distance_in_seconds} seconds"
  when 60..3599
    minutes = distance_in_seconds / 60
    "#{minutes} minute#{'s' if minutes != 1}"
  when 3600..86399
    hours = distance_in_seconds / 3600
    "#{hours} hour#{'s' if hours != 1}"
  else
    days = distance_in_seconds / 86400
    "#{days} day#{'s' if days != 1}"
  end
end