referral_box 0.1.6 → 0.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +28 -0
- data/app/views/referral_box/dashboard/analytics.html.erb +99 -0
- data/app/views/referral_box/dashboard/index.html.erb +98 -0
- data/app/views/referral_box/dashboard/referrals.html.erb +62 -0
- data/app/views/referral_box/dashboard/transactions.html.erb +54 -0
- data/app/views/referral_box/dashboard/user.html.erb +112 -0
- data/app/views/referral_box/dashboard/users.html.erb +55 -0
- data/lib/generators/referral_box/install/install_generator.rb +71 -28
- data/lib/referral_box/version.rb +1 -1
- metadata +7 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d8ba983787c512d738d87748d8aef25955fc322c491bdabfd47ad8fda6980984
|
4
|
+
data.tar.gz: 29a2e05f19614deee0edde3005fc56788efeea814c78bdd0eed3eee37953f054
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bddb9b69fa3af2ad73bbd3ff32ca2de283611f75853731bf704bcf98b976c5b61da069ff1ce4364fc5382c323fe63aefb9b4b45c5131e5fc556566dfdd3e0f5f
|
7
|
+
data.tar.gz: 76dd52bfcbff503d155135d408bb81d4ec1095c3021a642f42d7bbf2abb352ffcdc04519478765e7f0bfcc1291886dcda4b18113eb5054b6c19014cb224f1c54
|
data/CHANGELOG.md
CHANGED
@@ -7,6 +7,34 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
7
7
|
|
8
8
|
## [Unreleased]
|
9
9
|
|
10
|
+
## [0.1.8] - 2025-01-XX
|
11
|
+
|
12
|
+
### Added
|
13
|
+
- **Interactive Generator**: Generator now asks for model name and confirms the choice
|
14
|
+
- **Model Detection**: Automatically detects existing models in the app
|
15
|
+
- **Safe Migrations**: Migration now checks if columns exist before adding them
|
16
|
+
- **Duplicate Prevention**: Prevents adding duplicate columns and methods
|
17
|
+
|
18
|
+
### Fixed
|
19
|
+
- **Migration Errors**: Fixed "duplicate column name" errors by adding existence checks
|
20
|
+
- **Generator Flow**: Improved user experience with interactive prompts
|
21
|
+
- **Model Flexibility**: Better support for different model names (User, Customer, Account, etc.)
|
22
|
+
|
23
|
+
## [0.1.7] - 2025-01-XX
|
24
|
+
|
25
|
+
### Added
|
26
|
+
- **Admin Dashboard Views**: Added all missing view templates for the admin dashboard
|
27
|
+
- **Dashboard Index**: Overview with statistics, recent transactions, and top users
|
28
|
+
- **Users List**: Complete user management with points, tiers, and referral codes
|
29
|
+
- **User Details**: Individual user profiles with transaction history
|
30
|
+
- **Transactions**: Full transaction history with filtering and pagination
|
31
|
+
- **Referrals**: Referral tracking with device and browser analytics
|
32
|
+
- **Analytics**: Comprehensive analytics with device breakdown and daily trends
|
33
|
+
|
34
|
+
### Fixed
|
35
|
+
- **Missing Templates**: Resolved "ActionController::MissingExactTemplate" error
|
36
|
+
- **Dashboard Navigation**: All dashboard sections now have proper views
|
37
|
+
|
10
38
|
## [0.1.5] - 2025-01-XX
|
11
39
|
|
12
40
|
### Fixed
|
@@ -0,0 +1,99 @@
|
|
1
|
+
<div class="card">
|
2
|
+
<h2>📈 Referral Analytics</h2>
|
3
|
+
|
4
|
+
<div class="stats-grid">
|
5
|
+
<div class="stat-card">
|
6
|
+
<div class="stat-number"><%= @total_clicks %></div>
|
7
|
+
<div class="stat-label">Total Clicks</div>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="stat-card">
|
11
|
+
<div class="stat-number"><%= @total_conversions %></div>
|
12
|
+
<div class="stat-label">Total Conversions</div>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<div class="stat-card">
|
16
|
+
<div class="stat-number"><%= number_to_percentage(@conversion_rate, precision: 1) %></div>
|
17
|
+
<div class="stat-label">Conversion Rate</div>
|
18
|
+
</div>
|
19
|
+
</div>
|
20
|
+
</div>
|
21
|
+
|
22
|
+
<div class="card">
|
23
|
+
<h2>📱 Device Breakdown</h2>
|
24
|
+
|
25
|
+
<% if @referrals_by_device.any? %>
|
26
|
+
<table class="table">
|
27
|
+
<thead>
|
28
|
+
<tr>
|
29
|
+
<th>Device Type</th>
|
30
|
+
<th>Count</th>
|
31
|
+
<th>Percentage</th>
|
32
|
+
</tr>
|
33
|
+
</thead>
|
34
|
+
<tbody>
|
35
|
+
<% @referrals_by_device.each do |device, count| %>
|
36
|
+
<tr>
|
37
|
+
<td><%= device.titleize %></td>
|
38
|
+
<td><%= count %></td>
|
39
|
+
<td><%= number_to_percentage((count.to_f / @total_clicks) * 100, precision: 1) %></td>
|
40
|
+
</tr>
|
41
|
+
<% end %>
|
42
|
+
</tbody>
|
43
|
+
</table>
|
44
|
+
<% else %>
|
45
|
+
<p>No device data available.</p>
|
46
|
+
<% end %>
|
47
|
+
</div>
|
48
|
+
|
49
|
+
<div class="card">
|
50
|
+
<h2>🌐 Browser Breakdown</h2>
|
51
|
+
|
52
|
+
<% if @referrals_by_browser.any? %>
|
53
|
+
<table class="table">
|
54
|
+
<thead>
|
55
|
+
<tr>
|
56
|
+
<th>Browser</th>
|
57
|
+
<th>Count</th>
|
58
|
+
<th>Percentage</th>
|
59
|
+
</tr>
|
60
|
+
</thead>
|
61
|
+
<tbody>
|
62
|
+
<% @referrals_by_browser.each do |browser, count| %>
|
63
|
+
<tr>
|
64
|
+
<td><%= browser %></td>
|
65
|
+
<td><%= count %></td>
|
66
|
+
<td><%= number_to_percentage((count.to_f / @total_clicks) * 100, precision: 1) %></td>
|
67
|
+
</tr>
|
68
|
+
<% end %>
|
69
|
+
</tbody>
|
70
|
+
</table>
|
71
|
+
<% else %>
|
72
|
+
<p>No browser data available.</p>
|
73
|
+
<% end %>
|
74
|
+
</div>
|
75
|
+
|
76
|
+
<div class="card">
|
77
|
+
<h2>📅 Daily Click Trends (Last 30 Days)</h2>
|
78
|
+
|
79
|
+
<% if @daily_clicks.any? %>
|
80
|
+
<table class="table">
|
81
|
+
<thead>
|
82
|
+
<tr>
|
83
|
+
<th>Date</th>
|
84
|
+
<th>Clicks</th>
|
85
|
+
</tr>
|
86
|
+
</thead>
|
87
|
+
<tbody>
|
88
|
+
<% @daily_clicks.each do |date, count| %>
|
89
|
+
<tr>
|
90
|
+
<td><%= Date.parse(date).strftime("%b %d, %Y") %></td>
|
91
|
+
<td><%= count %></td>
|
92
|
+
</tr>
|
93
|
+
<% end %>
|
94
|
+
</tbody>
|
95
|
+
</table>
|
96
|
+
<% else %>
|
97
|
+
<p>No daily click data available.</p>
|
98
|
+
<% end %>
|
99
|
+
</div>
|
@@ -0,0 +1,98 @@
|
|
1
|
+
<div class="card">
|
2
|
+
<h2>📊 Dashboard Overview</h2>
|
3
|
+
|
4
|
+
<div class="stats-grid">
|
5
|
+
<div class="stat-card">
|
6
|
+
<div class="stat-number"><%= @total_users %></div>
|
7
|
+
<div class="stat-label">Total Users</div>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="stat-card">
|
11
|
+
<div class="stat-number"><%= @total_transactions %></div>
|
12
|
+
<div class="stat-label">Total Transactions</div>
|
13
|
+
</div>
|
14
|
+
|
15
|
+
<div class="stat-card">
|
16
|
+
<div class="stat-number"><%= @total_referrals %></div>
|
17
|
+
<div class="stat-label">Total Referrals</div>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class="stat-card">
|
21
|
+
<div class="stat-number"><%= number_to_percentage(@conversion_rate, precision: 1) %></div>
|
22
|
+
<div class="stat-label">Conversion Rate</div>
|
23
|
+
</div>
|
24
|
+
</div>
|
25
|
+
</div>
|
26
|
+
|
27
|
+
<div class="card">
|
28
|
+
<h2>🔄 Recent Transactions</h2>
|
29
|
+
|
30
|
+
<% if @recent_transactions.any? %>
|
31
|
+
<table class="table">
|
32
|
+
<thead>
|
33
|
+
<tr>
|
34
|
+
<th>User</th>
|
35
|
+
<th>Type</th>
|
36
|
+
<th>Points</th>
|
37
|
+
<th>Description</th>
|
38
|
+
<th>Date</th>
|
39
|
+
</tr>
|
40
|
+
</thead>
|
41
|
+
<tbody>
|
42
|
+
<% @recent_transactions.each do |transaction| %>
|
43
|
+
<tr>
|
44
|
+
<td><%= transaction.user&.email || transaction.user&.name || "Unknown" %></td>
|
45
|
+
<td>
|
46
|
+
<span class="badge <%= transaction.transaction_type %>">
|
47
|
+
<%= transaction.transaction_type.titleize %>
|
48
|
+
</span>
|
49
|
+
</td>
|
50
|
+
<td><%= transaction.points %></td>
|
51
|
+
<td><%= transaction.description %></td>
|
52
|
+
<td><%= transaction.created_at.strftime("%b %d, %Y") %></td>
|
53
|
+
</tr>
|
54
|
+
<% end %>
|
55
|
+
</tbody>
|
56
|
+
</table>
|
57
|
+
<% else %>
|
58
|
+
<p>No transactions yet.</p>
|
59
|
+
<% end %>
|
60
|
+
</div>
|
61
|
+
|
62
|
+
<div class="card">
|
63
|
+
<h2>🏆 Top Users by Points</h2>
|
64
|
+
|
65
|
+
<% if @top_users.any? %>
|
66
|
+
<table class="table">
|
67
|
+
<thead>
|
68
|
+
<tr>
|
69
|
+
<th>User</th>
|
70
|
+
<th>Points</th>
|
71
|
+
<th>Tier</th>
|
72
|
+
<th>Referrals</th>
|
73
|
+
</tr>
|
74
|
+
</thead>
|
75
|
+
<tbody>
|
76
|
+
<% @top_users.each do |user| %>
|
77
|
+
<tr>
|
78
|
+
<td>
|
79
|
+
<%= link_to user.email || user.name || "Unknown", referral_box.user_path(user), class: "btn btn-primary" %>
|
80
|
+
</td>
|
81
|
+
<td><%= ReferralBox.balance(user) %></td>
|
82
|
+
<td>
|
83
|
+
<% tier = ReferralBox.tier(user) %>
|
84
|
+
<% if tier %>
|
85
|
+
<span class="badge <%= tier.downcase %>"><%= tier %></span>
|
86
|
+
<% else %>
|
87
|
+
<span class="badge">None</span>
|
88
|
+
<% end %>
|
89
|
+
</td>
|
90
|
+
<td><%= user.referrals.count %></td>
|
91
|
+
</tr>
|
92
|
+
<% end %>
|
93
|
+
</tbody>
|
94
|
+
</table>
|
95
|
+
<% else %>
|
96
|
+
<p>No users with points yet.</p>
|
97
|
+
<% end %>
|
98
|
+
</div>
|
@@ -0,0 +1,62 @@
|
|
1
|
+
<div class="card">
|
2
|
+
<h2>🤝 Referral Tracking</h2>
|
3
|
+
|
4
|
+
<% if @referrals.any? %>
|
5
|
+
<table class="table">
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>Referral Code</th>
|
9
|
+
<th>Clicked At</th>
|
10
|
+
<th>Device</th>
|
11
|
+
<th>Browser</th>
|
12
|
+
<th>IP Address</th>
|
13
|
+
<th>Status</th>
|
14
|
+
<th>Signed Up</th>
|
15
|
+
</tr>
|
16
|
+
</thead>
|
17
|
+
<tbody>
|
18
|
+
<% @referrals.each do |referral| %>
|
19
|
+
<tr>
|
20
|
+
<td>
|
21
|
+
<code><%= referral.referral_code %></code>
|
22
|
+
</td>
|
23
|
+
<td><%= referral.clicked_at.strftime("%b %d, %Y at %I:%M") %></td>
|
24
|
+
<td>
|
25
|
+
<% if referral.device_type.present? %>
|
26
|
+
<span class="badge"><%= referral.device_type.titleize %></span>
|
27
|
+
<% else %>
|
28
|
+
<span class="text-muted">Unknown</span>
|
29
|
+
<% end %>
|
30
|
+
</td>
|
31
|
+
<td>
|
32
|
+
<% if referral.browser.present? %>
|
33
|
+
<%= referral.browser %>
|
34
|
+
<% else %>
|
35
|
+
<span class="text-muted">Unknown</span>
|
36
|
+
<% end %>
|
37
|
+
</td>
|
38
|
+
<td><%= referral.ip_address %></td>
|
39
|
+
<td>
|
40
|
+
<% if referral.converted? %>
|
41
|
+
<span class="badge earn">Converted</span>
|
42
|
+
<% else %>
|
43
|
+
<span class="badge">Clicked</span>
|
44
|
+
<% end %>
|
45
|
+
</td>
|
46
|
+
<td>
|
47
|
+
<% if referral.signed_up_at %>
|
48
|
+
<%= referral.signed_up_at.strftime("%b %d, %Y") %>
|
49
|
+
<% else %>
|
50
|
+
<span class="text-muted">Not signed up</span>
|
51
|
+
<% end %>
|
52
|
+
</td>
|
53
|
+
</tr>
|
54
|
+
<% end %>
|
55
|
+
</tbody>
|
56
|
+
</table>
|
57
|
+
|
58
|
+
<%= referral_box_paginate(@referrals) %>
|
59
|
+
<% else %>
|
60
|
+
<p>No referral tracking data found.</p>
|
61
|
+
<% end %>
|
62
|
+
</div>
|
@@ -0,0 +1,54 @@
|
|
1
|
+
<div class="card">
|
2
|
+
<h2>💳 All Transactions</h2>
|
3
|
+
|
4
|
+
<% if @transactions.any? %>
|
5
|
+
<table class="table">
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>User</th>
|
9
|
+
<th>Type</th>
|
10
|
+
<th>Points</th>
|
11
|
+
<th>Description</th>
|
12
|
+
<th>Date</th>
|
13
|
+
<th>Expires</th>
|
14
|
+
</tr>
|
15
|
+
</thead>
|
16
|
+
<tbody>
|
17
|
+
<% @transactions.each do |transaction| %>
|
18
|
+
<tr>
|
19
|
+
<td>
|
20
|
+
<% if transaction.user %>
|
21
|
+
<%= link_to transaction.user.email || transaction.user.name || "Unknown", referral_box.user_path(transaction.user), class: "btn btn-primary" %>
|
22
|
+
<% else %>
|
23
|
+
<span class="text-muted">Unknown User</span>
|
24
|
+
<% end %>
|
25
|
+
</td>
|
26
|
+
<td>
|
27
|
+
<span class="badge <%= transaction.transaction_type %>">
|
28
|
+
<%= transaction.transaction_type.titleize %>
|
29
|
+
</span>
|
30
|
+
</td>
|
31
|
+
<td><%= transaction.points %></td>
|
32
|
+
<td><%= transaction.description %></td>
|
33
|
+
<td><%= transaction.created_at.strftime("%b %d, %Y at %I:%M") %></td>
|
34
|
+
<td>
|
35
|
+
<% if transaction.expires_at %>
|
36
|
+
<% if transaction.expired? %>
|
37
|
+
<span class="text-danger">Expired</span>
|
38
|
+
<% else %>
|
39
|
+
<%= transaction.expires_at.strftime("%b %d, %Y") %>
|
40
|
+
<% end %>
|
41
|
+
<% else %>
|
42
|
+
<span class="text-muted">Never</span>
|
43
|
+
<% end %>
|
44
|
+
</td>
|
45
|
+
</tr>
|
46
|
+
<% end %>
|
47
|
+
</tbody>
|
48
|
+
</table>
|
49
|
+
|
50
|
+
<%= referral_box_paginate(@transactions) %>
|
51
|
+
<% else %>
|
52
|
+
<p>No transactions found.</p>
|
53
|
+
<% end %>
|
54
|
+
</div>
|
@@ -0,0 +1,112 @@
|
|
1
|
+
<div class="card">
|
2
|
+
<h2>👤 User Details: <%= @user.email || @user.name || "Unknown" %></h2>
|
3
|
+
|
4
|
+
<div class="stats-grid">
|
5
|
+
<div class="stat-card">
|
6
|
+
<div class="stat-number"><%= @balance %></div>
|
7
|
+
<div class="stat-label">Points Balance</div>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="stat-card">
|
11
|
+
<div class="stat-number">
|
12
|
+
<% if @tier %>
|
13
|
+
<span class="badge <%= @tier.downcase %>"><%= @tier %></span>
|
14
|
+
<% else %>
|
15
|
+
<span class="badge">None</span>
|
16
|
+
<% end %>
|
17
|
+
</div>
|
18
|
+
<div class="stat-label">Current Tier</div>
|
19
|
+
</div>
|
20
|
+
|
21
|
+
<div class="stat-card">
|
22
|
+
<div class="stat-number"><%= @user.referrals.count %></div>
|
23
|
+
<div class="stat-label">Total Referrals</div>
|
24
|
+
</div>
|
25
|
+
|
26
|
+
<div class="stat-card">
|
27
|
+
<div class="stat-number"><%= @transactions.count %></div>
|
28
|
+
<div class="stat-label">Total Transactions</div>
|
29
|
+
</div>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div class="user-info">
|
33
|
+
<h3>User Information</h3>
|
34
|
+
<table class="table">
|
35
|
+
<tr>
|
36
|
+
<td><strong>Email:</strong></td>
|
37
|
+
<td><%= @user.email %></td>
|
38
|
+
</tr>
|
39
|
+
<tr>
|
40
|
+
<td><strong>Name:</strong></td>
|
41
|
+
<td><%= @user.name %></td>
|
42
|
+
</tr>
|
43
|
+
<tr>
|
44
|
+
<td><strong>Referral Code:</strong></td>
|
45
|
+
<td>
|
46
|
+
<% if @user.respond_to?(:referral_code) && @user.referral_code.present? %>
|
47
|
+
<code><%= @user.referral_code %></code>
|
48
|
+
<% else %>
|
49
|
+
<span class="text-muted">Not generated</span>
|
50
|
+
<% end %>
|
51
|
+
</td>
|
52
|
+
</tr>
|
53
|
+
<tr>
|
54
|
+
<td><strong>Referrer:</strong></td>
|
55
|
+
<td>
|
56
|
+
<% if @user.referrer %>
|
57
|
+
<%= @user.referrer.email || @user.referrer.name || "Unknown" %>
|
58
|
+
<% else %>
|
59
|
+
<span class="text-muted">No referrer</span>
|
60
|
+
<% end %>
|
61
|
+
</td>
|
62
|
+
</tr>
|
63
|
+
<tr>
|
64
|
+
<td><strong>Joined:</strong></td>
|
65
|
+
<td><%= @user.created_at.strftime("%B %d, %Y at %I:%M %p") %></td>
|
66
|
+
</tr>
|
67
|
+
</table>
|
68
|
+
</div>
|
69
|
+
</div>
|
70
|
+
|
71
|
+
<div class="card">
|
72
|
+
<h2>📊 Transaction History</h2>
|
73
|
+
|
74
|
+
<% if @transactions.any? %>
|
75
|
+
<table class="table">
|
76
|
+
<thead>
|
77
|
+
<tr>
|
78
|
+
<th>Type</th>
|
79
|
+
<th>Points</th>
|
80
|
+
<th>Description</th>
|
81
|
+
<th>Date</th>
|
82
|
+
<th>Expires</th>
|
83
|
+
</tr>
|
84
|
+
</thead>
|
85
|
+
<tbody>
|
86
|
+
<% @transactions.each do |transaction| %>
|
87
|
+
<tr>
|
88
|
+
<td>
|
89
|
+
<span class="badge <%= transaction.transaction_type %>">
|
90
|
+
<%= transaction.transaction_type.titleize %>
|
91
|
+
</span>
|
92
|
+
</td>
|
93
|
+
<td><%= transaction.points %></td>
|
94
|
+
<td><%= transaction.description %></td>
|
95
|
+
<td><%= transaction.created_at.strftime("%b %d, %Y") %></td>
|
96
|
+
<td>
|
97
|
+
<% if transaction.expires_at %>
|
98
|
+
<%= transaction.expires_at.strftime("%b %d, %Y") %>
|
99
|
+
<% else %>
|
100
|
+
<span class="text-muted">Never</span>
|
101
|
+
<% end %>
|
102
|
+
</td>
|
103
|
+
</tr>
|
104
|
+
<% end %>
|
105
|
+
</tbody>
|
106
|
+
</table>
|
107
|
+
|
108
|
+
<%= referral_box_paginate(@transactions) %>
|
109
|
+
<% else %>
|
110
|
+
<p>No transactions found for this user.</p>
|
111
|
+
<% end %>
|
112
|
+
</div>
|
@@ -0,0 +1,55 @@
|
|
1
|
+
<div class="card">
|
2
|
+
<h2>👥 All Users</h2>
|
3
|
+
|
4
|
+
<% if @users.any? %>
|
5
|
+
<table class="table">
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<th>User</th>
|
9
|
+
<th>Points Balance</th>
|
10
|
+
<th>Tier</th>
|
11
|
+
<th>Referral Code</th>
|
12
|
+
<th>Referrals</th>
|
13
|
+
<th>Joined</th>
|
14
|
+
<th>Actions</th>
|
15
|
+
</tr>
|
16
|
+
</thead>
|
17
|
+
<tbody>
|
18
|
+
<% @users.each do |user| %>
|
19
|
+
<tr>
|
20
|
+
<td>
|
21
|
+
<strong><%= user.email || user.name || "Unknown" %></strong>
|
22
|
+
</td>
|
23
|
+
<td>
|
24
|
+
<strong><%= ReferralBox.balance(user) %></strong>
|
25
|
+
</td>
|
26
|
+
<td>
|
27
|
+
<% tier = ReferralBox.tier(user) %>
|
28
|
+
<% if tier %>
|
29
|
+
<span class="badge <%= tier.downcase %>"><%= tier %></span>
|
30
|
+
<% else %>
|
31
|
+
<span class="badge">None</span>
|
32
|
+
<% end %>
|
33
|
+
</td>
|
34
|
+
<td>
|
35
|
+
<% if user.respond_to?(:referral_code) && user.referral_code.present? %>
|
36
|
+
<code><%= user.referral_code %></code>
|
37
|
+
<% else %>
|
38
|
+
<span class="text-muted">Not generated</span>
|
39
|
+
<% end %>
|
40
|
+
</td>
|
41
|
+
<td><%= user.referrals.count %></td>
|
42
|
+
<td><%= user.created_at.strftime("%b %d, %Y") %></td>
|
43
|
+
<td>
|
44
|
+
<%= link_to "View Details", referral_box.user_path(user), class: "btn btn-primary" %>
|
45
|
+
</td>
|
46
|
+
</tr>
|
47
|
+
<% end %>
|
48
|
+
</tbody>
|
49
|
+
</table>
|
50
|
+
|
51
|
+
<%= referral_box_paginate(@users) %>
|
52
|
+
<% else %>
|
53
|
+
<p>No users found.</p>
|
54
|
+
<% end %>
|
55
|
+
</div>
|
@@ -11,37 +11,66 @@ module ReferralBox
|
|
11
11
|
template "initializer.rb", "config/initializers/referral_box.rb"
|
12
12
|
end
|
13
13
|
|
14
|
-
def
|
15
|
-
|
16
|
-
|
14
|
+
def ask_for_model_name
|
15
|
+
puts "\n" + "="*60
|
16
|
+
puts "ReferralBox Model Configuration"
|
17
|
+
puts "="*60
|
18
|
+
|
19
|
+
# Detect existing models
|
20
|
+
model_files = Dir.glob("app/models/*.rb")
|
21
|
+
existing_models = model_files.map { |f| File.basename(f, '.rb').classify }
|
22
|
+
|
23
|
+
if existing_models.any?
|
24
|
+
puts "\nExisting models found: #{existing_models.join(', ')}"
|
25
|
+
end
|
26
|
+
|
27
|
+
@model_class = ask("What is your user model class name? (e.g., User, Customer, Account, Member):", default: "User")
|
28
|
+
|
29
|
+
# Confirm the choice
|
30
|
+
puts "\nYou selected: #{@model_class}"
|
31
|
+
confirm = ask("Is this correct? (y/n):", default: "y")
|
32
|
+
|
33
|
+
unless confirm.downcase.start_with?('y')
|
34
|
+
puts "Please run the generator again with the correct model name."
|
35
|
+
exit
|
36
|
+
end
|
17
37
|
|
18
|
-
|
19
|
-
|
20
|
-
|
38
|
+
# Update the initializer with the selected model
|
39
|
+
update_initializer_with_model(@model_class)
|
40
|
+
end
|
41
|
+
|
42
|
+
def add_model_migration
|
43
|
+
if @model_class.present?
|
44
|
+
generate_migration = "AddReferralBoxTo#{@model_class.pluralize}"
|
45
|
+
migration_content = generate_migration_content(@model_class)
|
21
46
|
|
22
47
|
create_file "db/migrate/#{Time.current.strftime('%Y%m%d%H%M%S')}_#{generate_migration.underscore}.rb", migration_content
|
23
48
|
|
24
|
-
puts "
|
49
|
+
puts "\nMigration generated for #{@model_class} model!"
|
25
50
|
puts "Run 'rails db:migrate' to apply it."
|
26
51
|
else
|
27
|
-
puts "Warning: Could not determine model class name
|
52
|
+
puts "Warning: Could not determine model class name."
|
28
53
|
puts "Please manually create migration for your model."
|
29
54
|
end
|
30
55
|
end
|
31
56
|
|
32
57
|
def add_model_methods
|
33
|
-
model_class
|
34
|
-
|
35
|
-
if model_class.present?
|
36
|
-
model_file = "app/models/#{model_class.underscore}.rb"
|
58
|
+
if @model_class.present?
|
59
|
+
model_file = "app/models/#{@model_class.underscore}.rb"
|
37
60
|
|
38
61
|
if File.exist?(model_file)
|
39
|
-
|
40
|
-
|
62
|
+
# Check if methods already exist
|
63
|
+
content = File.read(model_file)
|
64
|
+
if content.include?('has_many :referral_box_transactions')
|
65
|
+
puts "ReferralBox methods already exist in #{@model_class} model."
|
66
|
+
else
|
67
|
+
inject_into_file model_file, after: "class #{@model_class} < ApplicationRecord" do
|
68
|
+
"\n " + generate_model_methods(@model_class)
|
69
|
+
end
|
70
|
+
puts "Added ReferralBox methods to #{@model_class} model."
|
41
71
|
end
|
42
|
-
puts "Added ReferralBox methods to #{model_class} model."
|
43
72
|
else
|
44
|
-
puts "Warning: #{model_file} not found. Please manually add ReferralBox methods to your #{model_class} model."
|
73
|
+
puts "Warning: #{model_file} not found. Please manually add ReferralBox methods to your #{@model_class} model."
|
45
74
|
end
|
46
75
|
end
|
47
76
|
end
|
@@ -60,19 +89,19 @@ module ReferralBox
|
|
60
89
|
|
61
90
|
private
|
62
91
|
|
63
|
-
def
|
64
|
-
# Try to read from existing initializer first
|
92
|
+
def update_initializer_with_model(model_class)
|
65
93
|
initializer_path = "config/initializers/referral_box.rb"
|
66
94
|
|
67
95
|
if File.exist?(initializer_path)
|
68
96
|
content = File.read(initializer_path)
|
69
|
-
|
70
|
-
|
71
|
-
|
97
|
+
updated_content = content.gsub(
|
98
|
+
/config\.reference_class_name\s*=\s*['"][^'"]*['"]/,
|
99
|
+
"config.reference_class_name = '#{model_class}'"
|
100
|
+
)
|
101
|
+
|
102
|
+
File.write(initializer_path, updated_content)
|
103
|
+
puts "Updated initializer with #{model_class} model."
|
72
104
|
end
|
73
|
-
|
74
|
-
# Default to 'User' if not found
|
75
|
-
'User'
|
76
105
|
end
|
77
106
|
|
78
107
|
def generate_migration_content(model_class)
|
@@ -81,11 +110,25 @@ module ReferralBox
|
|
81
110
|
|
82
111
|
class AddReferralBoxTo#{model_class.pluralize} < ActiveRecord::Migration[#{get_rails_version}]
|
83
112
|
def change
|
84
|
-
|
85
|
-
|
86
|
-
|
113
|
+
# Add referral_code column if it doesn't exist
|
114
|
+
unless column_exists?(:#{model_class.underscore.pluralize}, :referral_code)
|
115
|
+
add_column :#{model_class.underscore.pluralize}, :referral_code, :string
|
116
|
+
end
|
117
|
+
|
118
|
+
# Add tier column if it doesn't exist
|
119
|
+
unless column_exists?(:#{model_class.underscore.pluralize}, :tier)
|
120
|
+
add_column :#{model_class.underscore.pluralize}, :tier, :string
|
121
|
+
end
|
122
|
+
|
123
|
+
# Add referrer reference if it doesn't exist
|
124
|
+
unless column_exists?(:#{model_class.underscore.pluralize}, :referrer_id)
|
125
|
+
add_reference :#{model_class.underscore.pluralize}, :referrer, null: true, foreign_key: { to_table: :#{model_class.underscore.pluralize} }
|
126
|
+
end
|
87
127
|
|
88
|
-
|
128
|
+
# Add unique index on referral_code if it doesn't exist
|
129
|
+
unless index_exists?(:#{model_class.underscore.pluralize}, :referral_code)
|
130
|
+
add_index :#{model_class.underscore.pluralize}, :referral_code, unique: true
|
131
|
+
end
|
89
132
|
end
|
90
133
|
end
|
91
134
|
MIGRATION
|
data/lib/referral_box/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: referral_box
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Kapil Dev Pal
|
@@ -168,6 +168,12 @@ files:
|
|
168
168
|
- app/helpers/referral_box/application_helper.rb
|
169
169
|
- app/helpers/referral_box/dashboard_helper.rb
|
170
170
|
- app/views/layouts/referral_box/dashboard.html.erb
|
171
|
+
- app/views/referral_box/dashboard/analytics.html.erb
|
172
|
+
- app/views/referral_box/dashboard/index.html.erb
|
173
|
+
- app/views/referral_box/dashboard/referrals.html.erb
|
174
|
+
- app/views/referral_box/dashboard/transactions.html.erb
|
175
|
+
- app/views/referral_box/dashboard/user.html.erb
|
176
|
+
- app/views/referral_box/dashboard/users.html.erb
|
171
177
|
- config/routes.rb
|
172
178
|
- db/migrate/001_create_referral_box_transactions.rb
|
173
179
|
- db/migrate/002_create_referral_box_referral_logs.rb
|