Class: Solidstats::DashboardController

Inherits:
ApplicationController show all
Defined in:
app/controllers/solidstats/dashboard_controller.rb

Constant Summary collapse

TODO_CACHE_FILE =
Rails.root.join("tmp", "solidstats_todos.json")
AUDIT_CACHE_HOURS =

Configure how many hours before refreshing

12

Instance Method Summary collapse

Instance Method Details

#indexObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'app/controllers/solidstats/dashboard_controller.rb', line 6

def index
  # Use new services for data collection
  audit_service = AuditService.new
  todo_service = TodoService.new
  log_monitor_service = LogSizeMonitorService.new

  # Get full data for detailed views
  @audit_output = audit_service.fetch
  @todo_items = todo_service.fetch
  @log_data = log_monitor_service.collect_data
  @gems = Solidstats::::FetcherService.call

  # Get summary data for dashboard cards
  @audit_summary = audit_service.summary
  @todo_summary = todo_service.summary

  # TODO: Refactor these to use services as well
  @rubocop_output = "JSON.parse(`rubocop --format json`)"
  @coverage = "100"
end

#refreshObject

Force refresh all dashboard data



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
# File 'app/controllers/solidstats/dashboard_controller.rb', line 28

def refresh
  # Create services
  audit_service = AuditService.new
  todo_service = TodoService.new
  log_monitor_service = LogSizeMonitorService.new

  # Force refresh of data
  audit_output = audit_service.fetch(true) # Force refresh
  todo_items = todo_service.fetch(true)    # Force refresh
  log_data = log_monitor_service.collect_data
   = ::FetcherService.call(nil, true) # Force refresh

  # Get updated summaries
  audit_summary = audit_service.summary
  todo_summary = todo_service.summary

  # Get current time for last updated display
  last_updated = Time.now.strftime("%B %d, %Y at %H:%M")

  # Return JSON response with refreshed data
  render json: {
    audit_output: audit_output,
    todo_items: todo_items,
    audit_summary: audit_summary,
    todo_summary: todo_summary,
    log_data: log_data,
    gem_metadata: ,
    last_updated: last_updated,
    status: "success"
  }
rescue StandardError => e
  # Return error information
  render json: {
    status: "error",
    message: "Failed to refresh data: #{e.message}"
  }, status: :internal_server_error
end

#truncate_logObject



66
67
68
69
70
71
72
73
74
75
76
77
78
# File 'app/controllers/solidstats/dashboard_controller.rb', line 66

def truncate_log
  log_monitor_service = LogSizeMonitorService.new
  filename = params[:filename]

  # Add .log extension if not included in the filename
  if filename.present? && !filename.end_with?(".log")
    filename = "#{filename}.log"
  end

  result = log_monitor_service.truncate_log(filename)

  render json: result
end