Class: RailsOnboarding::ProgressiveFeaturesController

Inherits:
ApplicationController show all
Includes:
RateLimitable
Defined in:
app/controllers/rails_onboarding/progressive_features_controller.rb

Overview

Controller for managing progressive feature disclosure Handles revealing and tracking progressive features

Instance Method Summary collapse

Instance Method Details

#dismissObject

POST /progressive_features/:feature_key/dismiss Dismiss a feature notification without revealing it



65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'app/controllers/rails_onboarding/progressive_features_controller.rb', line 65

def dismiss
  # Track dismissal in analytics
  if current_user.respond_to?(:track_analytics_event)
    current_user.track_analytics_event(
      "feature_dismissed",
      feature_key: @feature[:key].to_s
    )
  end

  respond_to do |format|
    format.json { render json: { success: true } }
  end
end

#indexObject

GET /progressive_features List all progressive features and their status



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'app/controllers/rails_onboarding/progressive_features_controller.rb', line 14

def index
  @all_features = RailsOnboarding.configuration.progressive_features || []
  @revealed_features = current_user.all_revealed_features
  @ready_features = current_user.features_ready_to_reveal

  respond_to do |format|
    format.html
    format.json do
      render json: {
        all_features: @all_features,
        revealed: @revealed_features,
        ready_to_reveal: @ready_features.map { |f| f[:key] }
      }
    end
  end
end

#readyObject

GET /progressive_features/ready Get features that are ready to be revealed



33
34
35
36
37
38
39
# File 'app/controllers/rails_onboarding/progressive_features_controller.rb', line 33

def ready
  @ready_features = current_user.features_ready_to_reveal

  respond_to do |format|
    format.json { render json: @ready_features }
  end
end

#revealObject

POST /progressive_features/:feature_key/reveal Manually reveal a feature



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'app/controllers/rails_onboarding/progressive_features_controller.rb', line 43

def reveal
  if current_user.reveal_feature(@feature[:key], source: :manual, revealed_by: current_user.id)
    respond_to do |format|
      format.html do
        flash[:success] = "Feature '#{@feature[:title]}' has been revealed!"
        redirect_back(fallback_location: root_path)
      end
      format.json { render json: { success: true, feature: @feature } }
    end
  else
    respond_to do |format|
      format.html do
        flash[:error] = "Failed to reveal feature"
        redirect_back(fallback_location: root_path)
      end
      format.json { render json: { success: false }, status: :unprocessable_entity }
    end
  end
end

#reveal_all_readyObject

POST /progressive_features/reveal_all_ready Reveal all features that are currently ready



81
82
83
84
85
86
87
88
89
90
91
# File 'app/controllers/rails_onboarding/progressive_features_controller.rb', line 81

def reveal_all_ready
  newly_revealed = current_user.reveal_ready_features!

  respond_to do |format|
    format.html do
      flash[:success] = "Revealed #{newly_revealed.size} new features!"
      redirect_back(fallback_location: root_path)
    end
    format.json { render json: { success: true, revealed: newly_revealed } }
  end
end

#statusObject

GET /progressive_features/status Get the current status of progressive disclosure for the user



95
96
97
98
99
100
101
102
103
# File 'app/controllers/rails_onboarding/progressive_features_controller.rb', line 95

def status
  render json: {
    enabled: RailsOnboarding.configuration.progressive_disclosure_enabled,
    total_features: RailsOnboarding.configuration.progressive_features&.size || 0,
    revealed_count: current_user.revealed_features_count,
    pending_count: current_user.pending_features_count,
    ready_to_reveal: current_user.features_ready_to_reveal.map { |f| f[:key] }
  }
end