Class: ElderDocs::Engine::UiConfigController

Inherits:
ActionController::Base
  • Object
show all
Includes:
ActionController::MimeResponds
Defined in:
lib/elder_docs/engine/ui_config_controller.rb

Instance Method Summary collapse

Instance Method Details

#loginObject



21
22
23
24
25
26
27
28
29
30
# File 'lib/elder_docs/engine/ui_config_controller.rb', line 21

def 
  admin_password = ElderDocs.config.admin_password || ENV['ELDERDOCS_ADMIN_PASSWORD'] || 'admin'
  
  if params[:password] == admin_password
    session[:elderdocs_admin] = true
    render json: { success: true, message: 'Authentication successful' }
  else
    render json: { success: false, error: 'Invalid password' }, status: :unauthorized
  end
end

#logoutObject



85
86
87
88
# File 'lib/elder_docs/engine/ui_config_controller.rb', line 85

def logout
  session[:elderdocs_admin] = nil
  render json: { success: true, message: 'Logged out successfully' }
end

#showObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/elder_docs/engine/ui_config_controller.rb', line 32

def show
  # If requesting HTML, serve the UI configurator page
  if request.format.html? || request.headers['Accept']&.include?('text/html')
    ui_config_path = Engine.root.join('lib', 'elder_docs', 'assets', 'ui_config.html')
    if ui_config_path.exist?
      send_file ui_config_path, disposition: 'inline', type: 'text/html'
    else
      render plain: 'UI Configurator not found', status: :not_found
    end
  else
    # API endpoint - return JSON config (auth checked in check_auth_for_api)
    config_path = find_config_file
    current_config = load_config(config_path)
    
    render json: {
      ui_config: current_config['ui'] || {},
      config_path: config_path
    }
  end
end

#show_loginObject



17
18
19
# File 'lib/elder_docs/engine/ui_config_controller.rb', line 17

def 
  render json: { requires_auth: true }
end

#updateObject



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
# File 'lib/elder_docs/engine/ui_config_controller.rb', line 53

def update
  config_path = find_config_file
  
  # Load existing config
  config = load_config(config_path) || {}
  
  # Update UI config
  config['ui'] = {
    'font_heading' => params[:font_heading],
    'font_body' => params[:font_body],
    'colors' => {
      'primary' => params[:color_primary],
      'secondary' => params[:color_secondary],
      'background' => params[:color_background],
      'surface' => params[:color_surface]
    },
    'corner_radius' => params[:corner_radius]
  }
  
  # Save to file
  save_config(config_path, config)
  
  # Reload config in memory
  ElderDocs.config.load_config_file
  
  render json: {
    success: true,
    message: 'UI configuration saved successfully',
    ui_config: config['ui']
  }
end