rails-settings-cached-rails-admin 0.1.0
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 +7 -0
- data/.cursor/rules +12 -0
- data/Gemfile +17 -0
- data/LICENSE.txt +21 -0
- data/MANUAL_SETUP.md +68 -0
- data/README.md +180 -0
- data/Rakefile +6 -0
- data/app/views/rails_admin_settings_ui/settings/index.html.erb +435 -0
- data/example_app_setup.md +156 -0
- data/lib/locales/en.yml +8 -0
- data/lib/rails_admin_settings_ui/engine.rb +27 -0
- data/lib/rails_admin_settings_ui/helper.rb +20 -0
- data/lib/rails_admin_settings_ui/railtie.rb +14 -0
- data/lib/rails_admin_settings_ui/settings_ui.rb +375 -0
- data/lib/rails_admin_settings_ui/version.rb +3 -0
- data/lib/rails_admin_settings_ui.rb +12 -0
- data/screenshot.png +0 -0
- metadata +147 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5e431dea803a3efc3f5f6dca35206796f2aed72292c3ce827de4fb757f012f3a
|
4
|
+
data.tar.gz: 25a94de3d6f107892eaa7b9e377755b40ca7b73a7c63bfc1ee6e679b1aaffa1c
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: e77a8e3b0777b2130b547bdd1a5a2e094be9470c3d467a0c39f27dee53c47f386c9a29fc637da46bfdee79b2394c9df8e68648f132d0dbd2c7b7a46e646b688c
|
7
|
+
data.tar.gz: 58496e8fb456eb6a8002b3c5fbe10fed3ebb6f182fe4173da7c69e67eede28e8f189ed446a2abc8f89aeac9976c7ad63f89786e23e4ca4ccb31a3177c2e51b4f
|
data/.cursor/rules
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
This gem is solving following problem:
|
2
|
+
|
3
|
+
When we using two ruby gems:
|
4
|
+
|
5
|
+
rails_admin - for admin panel
|
6
|
+
rails-settings-cached - for storing settings
|
7
|
+
|
8
|
+
Problem is that on settings dasboard i want to have tab called Setting that will open settings in user friendly ui.
|
9
|
+
|
10
|
+
Default rails_admin behaviour is showing setting item in table with 0 records and it hard to understand for non-technical that to override default Setting need to create record with key value.
|
11
|
+
I want provide more user friendly interface for making it with default values that setted in class Setting < RailsSettings::Base model
|
12
|
+
Please make it as a gem, create good name for it reflected what it doing, i want to test it locally before publis
|
data/Gemfile
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
source "https://rubygems.org"
|
2
|
+
|
3
|
+
# Specify your gem's dependencies in rails_admin_settings_ui.gemspec
|
4
|
+
gemspec
|
5
|
+
|
6
|
+
gem "rake", "~> 13.0"
|
7
|
+
gem "rspec", "~> 3.0"
|
8
|
+
|
9
|
+
# For testing
|
10
|
+
gem "sqlite3", "~> 1.4"
|
11
|
+
gem "rails", "~> 7.0"
|
12
|
+
gem "rails_admin", "~> 3.0"
|
13
|
+
gem "rails-settings-cached", "~> 2.8"
|
14
|
+
|
15
|
+
# For development
|
16
|
+
gem "pry"
|
17
|
+
gem "byebug"
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2024 Rails Admin Settings UI
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/MANUAL_SETUP.md
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Manual Setup Instructions
|
2
|
+
|
3
|
+
Since Rails Admin action registration can have timing issues, here's how to manually configure the gem:
|
4
|
+
|
5
|
+
## Step 1: Add to your Rails Admin initializer
|
6
|
+
|
7
|
+
In your `config/initializers/rails_admin.rb`, modify it like this:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
# Load the settings action
|
11
|
+
require 'rails_admin_settings_ui'
|
12
|
+
|
13
|
+
RailsAdmin.config do |config|
|
14
|
+
# ... your existing config
|
15
|
+
|
16
|
+
config.actions do
|
17
|
+
dashboard
|
18
|
+
index
|
19
|
+
show
|
20
|
+
new
|
21
|
+
edit
|
22
|
+
delete
|
23
|
+
|
24
|
+
# Manually register the settings action
|
25
|
+
collection :settings_ui, RailsAdminSettingsUi::SettingsUi
|
26
|
+
end
|
27
|
+
|
28
|
+
# Hide the default Setting model from navigation
|
29
|
+
config.model 'Setting' do
|
30
|
+
visible false
|
31
|
+
end
|
32
|
+
end
|
33
|
+
```
|
34
|
+
|
35
|
+
## Step 2: Alternative approach using register
|
36
|
+
|
37
|
+
If the above doesn't work, try this approach:
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
# Load the settings action
|
41
|
+
require 'rails_admin_settings_ui'
|
42
|
+
|
43
|
+
# Register the action manually
|
44
|
+
RailsAdmin::Config::Actions.register(:settings_ui, RailsAdminSettingsUi::SettingsUi)
|
45
|
+
|
46
|
+
RailsAdmin.config do |config|
|
47
|
+
# ... your existing config
|
48
|
+
|
49
|
+
config.actions do
|
50
|
+
dashboard
|
51
|
+
index
|
52
|
+
show
|
53
|
+
new
|
54
|
+
edit
|
55
|
+
delete
|
56
|
+
settings_ui # Now this should work
|
57
|
+
end
|
58
|
+
|
59
|
+
# Hide the default Setting model from navigation
|
60
|
+
config.model 'Setting' do
|
61
|
+
visible false
|
62
|
+
end
|
63
|
+
end
|
64
|
+
```
|
65
|
+
|
66
|
+
## Step 3: Restart your Rails server
|
67
|
+
|
68
|
+
Make sure to restart your Rails server after making these changes.
|
data/README.md
ADDED
@@ -0,0 +1,180 @@
|
|
1
|
+
# RailsAdminSettingsUi
|
2
|
+
|
3
|
+
A user-friendly interface for managing application settings in Rails Admin, designed to work seamlessly with the `rails-settings-cached` gem.
|
4
|
+
|
5
|
+
## Features
|
6
|
+
|
7
|
+
- **User-friendly interface**: Replace the confusing default Rails Admin table view with an intuitive settings form
|
8
|
+
- **Automatic field type detection**: Smart field rendering based on your setting values (boolean, integer, email, URL, JSON, etc.)
|
9
|
+
- **Categorized settings**: Automatically groups settings by prefix for better organization
|
10
|
+
- **Default value management**: Shows default values and allows easy reset to defaults
|
11
|
+
- **Tab-based interface**: Clean, organized display with categories in separate tabs
|
12
|
+
- **Real-time validation**: Immediate feedback for invalid JSON and other field types
|
13
|
+
|
14
|
+
## Installation
|
15
|
+
|
16
|
+
Add this line to your application's Gemfile:
|
17
|
+
|
18
|
+
```ruby
|
19
|
+
gem 'rails-settings-cached-rails-admin'
|
20
|
+
```
|
21
|
+
|
22
|
+
And then execute:
|
23
|
+
|
24
|
+
```bash
|
25
|
+
$ bundle install
|
26
|
+
```
|
27
|
+
|
28
|
+
## Prerequisites
|
29
|
+
|
30
|
+
This gem requires:
|
31
|
+
- `rails_admin` gem
|
32
|
+
- `rails-settings-cached` gem
|
33
|
+
- A `Setting` model that inherits from `RailsSettings::Base`
|
34
|
+
|
35
|
+
## Usage
|
36
|
+
|
37
|
+
### 1. Set up your Setting model
|
38
|
+
|
39
|
+
Make sure you have a Setting model with default values:
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
class Setting < RailsSettings::Base
|
43
|
+
cache_prefix { "v1" }
|
44
|
+
|
45
|
+
# General settings
|
46
|
+
field :app_name, default: "My Application"
|
47
|
+
field :maintenance_mode, default: false
|
48
|
+
field :max_users, default: 1000
|
49
|
+
|
50
|
+
# Email settings
|
51
|
+
field :mail_from, default: "noreply@example.com"
|
52
|
+
field :mail_host, default: "smtp.example.com"
|
53
|
+
field :mail_port, default: 587
|
54
|
+
|
55
|
+
# API settings
|
56
|
+
field :api_key, default: ""
|
57
|
+
field :api_timeout, default: 30.0
|
58
|
+
field :api_endpoints, default: ["https://api.example.com"]
|
59
|
+
|
60
|
+
# Advanced settings
|
61
|
+
field :feature_flags, default: { "new_ui" => false, "beta_features" => false }
|
62
|
+
end
|
63
|
+
```
|
64
|
+
|
65
|
+
### 2. Configure Rails Admin
|
66
|
+
|
67
|
+
In your Rails Admin configuration, enable the settings action:
|
68
|
+
|
69
|
+
```ruby
|
70
|
+
# config/initializers/rails_admin.rb
|
71
|
+
RailsAdmin.config do |config|
|
72
|
+
# ... your existing configuration
|
73
|
+
|
74
|
+
# Enable the settings UI action
|
75
|
+
config.actions do
|
76
|
+
dashboard
|
77
|
+
index
|
78
|
+
show
|
79
|
+
new
|
80
|
+
edit
|
81
|
+
delete
|
82
|
+
settings_ui # Add this line
|
83
|
+
end
|
84
|
+
|
85
|
+
# Optional: Hide the default Setting model from the navigation
|
86
|
+
config.model 'Setting' do
|
87
|
+
visible false
|
88
|
+
end
|
89
|
+
end
|
90
|
+
```
|
91
|
+
|
92
|
+
### 3. Access the Settings UI
|
93
|
+
|
94
|
+
Once configured, you'll see a "Settings" tab in your Rails Admin dashboard. Click it to access the user-friendly settings interface.
|
95
|
+
|
96
|
+
## How it works
|
97
|
+
|
98
|
+
### Automatic categorization
|
99
|
+
|
100
|
+
Settings are automatically grouped into categories based on their key prefixes:
|
101
|
+
- `mail_*` settings → "Mail" category
|
102
|
+
- `api_*` settings → "API" category
|
103
|
+
- Other settings → "General" category
|
104
|
+
|
105
|
+
### Smart field types
|
106
|
+
|
107
|
+
The gem automatically detects appropriate field types:
|
108
|
+
- `Boolean` values → Checkbox
|
109
|
+
- `Integer` values → Number field
|
110
|
+
- `Float` values → Number field with decimals
|
111
|
+
- `Array` values → Comma-separated text field
|
112
|
+
- `Hash` values → JSON text area
|
113
|
+
- Email-like strings → Email field
|
114
|
+
- URL-like strings → URL field
|
115
|
+
- Long text → Text area
|
116
|
+
- Everything else → Text field
|
117
|
+
|
118
|
+
### Default value handling
|
119
|
+
|
120
|
+
- Shows current vs. default values
|
121
|
+
- Provides "Reset to Default" buttons for modified settings
|
122
|
+
- Displays default values as help text
|
123
|
+
|
124
|
+
## Customization
|
125
|
+
|
126
|
+
### Custom categorization
|
127
|
+
|
128
|
+
Override the `extract_category` method for custom grouping logic:
|
129
|
+
|
130
|
+
```ruby
|
131
|
+
RailsAdminSettingsUi::SettingsAction.class_eval do
|
132
|
+
private
|
133
|
+
|
134
|
+
def extract_category(key)
|
135
|
+
case key.to_s
|
136
|
+
when /notification|email|mail/
|
137
|
+
'Notifications'
|
138
|
+
when /payment|billing|stripe/
|
139
|
+
'Payments'
|
140
|
+
when /social|oauth|auth/
|
141
|
+
'Authentication'
|
142
|
+
else
|
143
|
+
super
|
144
|
+
end
|
145
|
+
end
|
146
|
+
end
|
147
|
+
```
|
148
|
+
|
149
|
+
## Development
|
150
|
+
|
151
|
+
After checking out the repo, run:
|
152
|
+
|
153
|
+
```bash
|
154
|
+
bundle install
|
155
|
+
```
|
156
|
+
|
157
|
+
To test the gem locally before publishing:
|
158
|
+
|
159
|
+
1. Build the gem:
|
160
|
+
```bash
|
161
|
+
gem build rails_admin_settings_ui.gemspec
|
162
|
+
```
|
163
|
+
|
164
|
+
2. Install locally:
|
165
|
+
```bash
|
166
|
+
gem install rails_admin_settings_ui-0.1.0.gem
|
167
|
+
```
|
168
|
+
|
169
|
+
3. Or use it directly from your Gemfile:
|
170
|
+
```ruby
|
171
|
+
gem 'rails_admin_settings_ui', path: '/path/to/rails_admin_settings_ui'
|
172
|
+
```
|
173
|
+
|
174
|
+
## Contributing
|
175
|
+
|
176
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/yourusername/rails_admin_settings_ui.
|
177
|
+
|
178
|
+
## License
|
179
|
+
|
180
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|