Refactor admin settings, add all service settings
This commit is contained in:
parent
295d486761
commit
ca1221e9f3
13
app/components/form_elements/fieldset_component.html.erb
Normal file
13
app/components/form_elements/fieldset_component.html.erb
Normal file
@ -0,0 +1,13 @@
|
||||
<%= tag.public_send(@tag, class: "mb-6 last:mb-0") do %>
|
||||
<label class="block">
|
||||
<p class="font-bold <%= @descripton.present? ? "mb-1" : "mb-2" %>">
|
||||
<%= @title %>
|
||||
</p>
|
||||
<% if @descripton.present? %>
|
||||
<p class="text-gray-500">
|
||||
<%= @descripton %>
|
||||
</p>
|
||||
<% end %>
|
||||
<%= content %>
|
||||
</label>
|
||||
<% end %>
|
11
app/components/form_elements/fieldset_component.rb
Normal file
11
app/components/form_elements/fieldset_component.rb
Normal file
@ -0,0 +1,11 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
module FormElements
|
||||
class FieldsetComponent < ViewComponent::Base
|
||||
def initialize(tag: "div", title:, description: nil)
|
||||
@tag = tag
|
||||
@title = title
|
||||
@descripton = description
|
||||
end
|
||||
end
|
||||
end
|
@ -4,25 +4,7 @@ class Admin::Settings::RegistrationsController < Admin::SettingsController
|
||||
end
|
||||
|
||||
def create
|
||||
@errors = ActiveModel::Errors.new(Setting.new)
|
||||
|
||||
setting_params.keys.each do |key|
|
||||
next if setting_params[key].nil?
|
||||
|
||||
setting = Setting.new(var: key)
|
||||
setting.value = setting_params[key].strip
|
||||
unless setting.valid?
|
||||
@errors.merge!(setting.errors)
|
||||
end
|
||||
end
|
||||
|
||||
if @errors.any?
|
||||
render :index
|
||||
end
|
||||
|
||||
setting_params.keys.each do |key|
|
||||
Setting.send("#{key}=", setting_params[key].strip) unless setting_params[key].nil?
|
||||
end
|
||||
update_settings
|
||||
|
||||
redirect_to admin_settings_registrations_path, flash: {
|
||||
success: "Settings saved"
|
||||
|
@ -1,9 +1,35 @@
|
||||
class Admin::Settings::ServicesController < Admin::SettingsController
|
||||
|
||||
def index
|
||||
@service = params[:s]
|
||||
|
||||
if @service.blank?
|
||||
redirect_to admin_settings_services_path(params: { s: "discourse" })
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
def create
|
||||
service = params.require(:service)
|
||||
|
||||
update_settings
|
||||
|
||||
redirect_to admin_settings_services_path(params: { s: service }), flash: {
|
||||
success: "Settings saved"
|
||||
}
|
||||
end
|
||||
|
||||
def setting_params
|
||||
params.require(:setting).permit(
|
||||
:discourse_enabled,
|
||||
:ejabberd_enabled,
|
||||
:gitea_enabled,
|
||||
:lndhub_enabled,
|
||||
:lndhub_admin_enabled,
|
||||
:lndhub_keysend_enabled,
|
||||
:mastodon_enabled,
|
||||
:mediawiki_enabled,
|
||||
:nostr_enabled,
|
||||
)
|
||||
end
|
||||
|
||||
end
|
||||
|
@ -4,6 +4,30 @@ class Admin::SettingsController < Admin::BaseController
|
||||
def index
|
||||
end
|
||||
|
||||
def update_settings
|
||||
@errors = ActiveModel::Errors.new(Setting.new)
|
||||
changed_keys = []
|
||||
|
||||
setting_params.keys.each do |key|
|
||||
next if setting_params[key].nil? ||
|
||||
(Setting.send(key).to_s == setting_params[key].strip)
|
||||
changed_keys.push(key)
|
||||
setting = Setting.new(var: key)
|
||||
setting.value = setting_params[key].strip
|
||||
unless setting.valid?
|
||||
@errors.merge!(setting.errors)
|
||||
end
|
||||
end
|
||||
|
||||
if @errors.any?
|
||||
render :index and return
|
||||
end
|
||||
|
||||
changed_keys.each do |key|
|
||||
Setting.send("#{key}=", setting_params[key].strip)
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def set_current_section
|
||||
|
7
app/views/admin/settings/_errors.html.erb
Normal file
7
app/views/admin/settings/_errors.html.erb
Normal file
@ -0,0 +1,7 @@
|
||||
<section>
|
||||
<ul>
|
||||
<% errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</section>
|
@ -4,14 +4,9 @@
|
||||
<%= form_for(Setting.new, url: admin_settings_registrations_path) do |f| %>
|
||||
<section>
|
||||
<h3>Registrations</h3>
|
||||
|
||||
<% if @errors && @errors.any? %>
|
||||
<div>
|
||||
<ul>
|
||||
<% @errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<%= render partial: "admin/settings/errors", locals: { errors: @errors } %>
|
||||
<% end %>
|
||||
|
||||
<label class="block">
|
||||
@ -29,7 +24,7 @@
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<p class="pt-6 border-t border-gray-200">
|
||||
<p class="pt-6 border-t border-gray-200 text-right">
|
||||
<%= f.submit 'Save', class: "btn-md btn-blue w-full md:w-auto" %>
|
||||
</p>
|
||||
</section>
|
||||
|
17
app/views/admin/settings/services/_discourse.html.erb
Normal file
17
app/views/admin/settings/services/_discourse.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<h3>Discourse</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :discourse_enabled,
|
||||
enabled: Setting.discourse_enabled?,
|
||||
title: "Enable Discourse integration",
|
||||
description: "Discourse configuration present and features enabled"
|
||||
) %>
|
||||
</ul>
|
||||
<% if Setting.discourse_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Public URL") do %>
|
||||
<%= f.text_field :discourse_public_url,
|
||||
value: Setting.discourse_public_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
22
app/views/admin/settings/services/_ejabberd.html.erb
Normal file
22
app/views/admin/settings/services/_ejabberd.html.erb
Normal file
@ -0,0 +1,22 @@
|
||||
<h3>ejabberd (XMPP)</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :ejabberd_enabled,
|
||||
enabled: Setting.ejabberd_enabled?,
|
||||
title: "Enable ejabberd integration",
|
||||
description: "ejabberd configuration present and features enabled"
|
||||
) %>
|
||||
</ul>
|
||||
<% if Setting.ejabberd_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "API URL") do %>
|
||||
<%= f.text_field :ejabberd_api_url,
|
||||
value: Setting.ejabberd_api_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Admin URL") do %>
|
||||
<%= f.text_field :ejabberd_admin_url,
|
||||
value: Setting.ejabberd_admin_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
17
app/views/admin/settings/services/_gitea.html.erb
Normal file
17
app/views/admin/settings/services/_gitea.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<h3>Gitea</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :gitea_enabled,
|
||||
enabled: Setting.gitea_enabled?,
|
||||
title: "Enable Gitea integration",
|
||||
description: "Gitea configuration present and features enabled"
|
||||
) %>
|
||||
</ul>
|
||||
<% if Setting.gitea_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Public URL") do %>
|
||||
<%= f.text_field :gitea_public_url,
|
||||
value: Setting.gitea_public_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
40
app/views/admin/settings/services/_lndhub.html.erb
Normal file
40
app/views/admin/settings/services/_lndhub.html.erb
Normal file
@ -0,0 +1,40 @@
|
||||
<h3>Lightning Network</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :lndhub_enabled,
|
||||
enabled: Setting.lndhub_enabled?,
|
||||
title: "Enable LNDHub integration",
|
||||
description: "LNDHub configuration present and wallet features enabled"
|
||||
) %>
|
||||
<% if Setting.lndhub_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "API URL") do %>
|
||||
<%= f.text_field :lndhub_api_url,
|
||||
tag: "li",
|
||||
value: Setting.lndhub_api_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :lndhub_admin_enabled,
|
||||
enabled: Setting.lndhub_admin_enabled?,
|
||||
title: "Enable LNDHub admin panel",
|
||||
description: "LNDHub database configuration present and admin panel enabled"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :lndhub_keysend_enabled,
|
||||
enabled: Setting.lndhub_keysend_enabled?,
|
||||
title: "Enable keysend payments",
|
||||
description: "Allow users to receive invoice-less payments to their Lightning Address"
|
||||
) %>
|
||||
<% if Setting.lndhub_keysend_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Public key", description: "The public key of the Lightning node used by LNDHub") do %>
|
||||
<%= f.text_field :lndhub_public_key,
|
||||
tag: "li",
|
||||
value: Setting.lndhub_public_key,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</ul>
|
17
app/views/admin/settings/services/_mastodon.html.erb
Normal file
17
app/views/admin/settings/services/_mastodon.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<h3>Mastodon</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :mastodon_enabled,
|
||||
enabled: Setting.mastodon_enabled?,
|
||||
title: "Enable Mastodon integration",
|
||||
description: "Mastodon configuration present and features enabled"
|
||||
) %>
|
||||
</ul>
|
||||
<% if Setting.mastodon_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Public URL") do %>
|
||||
<%= f.text_field :mastodon_public_url,
|
||||
value: Setting.mastodon_public_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
17
app/views/admin/settings/services/_mediawiki.html.erb
Normal file
17
app/views/admin/settings/services/_mediawiki.html.erb
Normal file
@ -0,0 +1,17 @@
|
||||
<h3>MediaWiki</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :mediawiki_enabled,
|
||||
enabled: Setting.mediawiki_enabled?,
|
||||
title: "Enable MediaWiki integration",
|
||||
description: "MediaWiki configuration present and features enabled"
|
||||
) %>
|
||||
</ul>
|
||||
<% if Setting.mediawiki_enabled? %>
|
||||
<%= render FormElements::FieldsetComponent.new(title: "Public URL") do %>
|
||||
<%= f.text_field :mediawiki_public_url,
|
||||
value: Setting.mediawiki_public_url,
|
||||
class: "w-full", disabled: true %>
|
||||
<% end %>
|
||||
<% end %>
|
10
app/views/admin/settings/services/_nostr.html.erb
Normal file
10
app/views/admin/settings/services/_nostr.html.erb
Normal file
@ -0,0 +1,10 @@
|
||||
<h3>Nostr</h3>
|
||||
<ul role="list">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
form: f,
|
||||
attribute: :nostr_enabled,
|
||||
enabled: Setting.nostr_enabled?,
|
||||
title: "Enable Nostr integration (experimental)",
|
||||
description: "Allow adding nostr pubkeys and resolve user addresses via NIP-05"
|
||||
) %>
|
||||
</ul>
|
@ -1,35 +1,23 @@
|
||||
<%= render HeaderComponent.new(title: "Settings") %>
|
||||
|
||||
<%= render MainWithSidenavComponent.new(sidenav_partial: 'shared/admin_sidenav_settings') do %>
|
||||
<section>
|
||||
<h3>Lightning Network</h3>
|
||||
<%= form_for(Setting.new, url: admin_settings_services_path) do |f| %>
|
||||
<% if @errors && @errors.any? %>
|
||||
<div>
|
||||
<ul>
|
||||
<% @errors.full_messages.each do |msg| %>
|
||||
<li><%= msg %></li>
|
||||
<% end %>
|
||||
</ul>
|
||||
</div>
|
||||
<% end %>
|
||||
<%= form_for(Setting.new, url: admin_settings_services_path) do |f| %>
|
||||
<%= hidden_field_tag :service, @service %>
|
||||
|
||||
<ul role="list" class="mt-2 divide-y divide-gray-200">
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
tag: "li",
|
||||
enabled: Setting.lndhub_enabled?,
|
||||
input_enabled: false,
|
||||
title: "Enable LNDHub integration",
|
||||
description: "LNDHub configuration present and wallet features enabled"
|
||||
) %>
|
||||
<%= render FormElements::FieldsetToggleComponent.new(
|
||||
tag: "li",
|
||||
enabled: Setting.lndhub_admin_enabled?,
|
||||
input_enabled: false,
|
||||
title: "Enable LNDHub admin panel",
|
||||
description: "LNDHub database configuration present and admin panel enabled"
|
||||
) %>
|
||||
</ul>
|
||||
<% if @errors && @errors.any? %>
|
||||
<section>
|
||||
<%= render partial: "admin/settings/errors", locals: { errors: @errors } %>
|
||||
</section>
|
||||
<% end %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<%= render partial: @service, locals: { f: f } %>
|
||||
</section>
|
||||
|
||||
<section>
|
||||
<p class="pt-6 border-t border-gray-200 text-right">
|
||||
<%= f.submit 'Save', class: "btn-md btn-blue w-full md:w-auto" %>
|
||||
</p>
|
||||
</section>
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
@ -1 +1 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-x <%= custom_class %>"><line x1="18" y1="6" x2="6" y2="18"></line><line x1="6" y1="6" x2="18" y2="18"></line></svg>
|
||||
|
Before Width: | Height: | Size: 299 B After Width: | Height: | Size: 320 B |
@ -6,6 +6,9 @@
|
||||
name: "Services", path: admin_settings_services_path, icon: "grid",
|
||||
active: current_page?(admin_settings_services_path)
|
||||
) %>
|
||||
<% if current_page?(admin_settings_services_path) %>
|
||||
<%= render partial: "shared/admin_sidenav_settings_services" %>
|
||||
<% end %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
name: "Security", path: "#", icon: "shield", disabled: true
|
||||
) %>
|
||||
|
49
app/views/shared/_admin_sidenav_settings_services.html.erb
Normal file
49
app/views/shared/_admin_sidenav_settings_services.html.erb
Normal file
@ -0,0 +1,49 @@
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "Discourse",
|
||||
path: admin_settings_services_path(params: { s: "discourse" }),
|
||||
icon: Setting.discourse_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "discourse" })),
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "ejabberd",
|
||||
path: admin_settings_services_path(params: { s: "ejabberd" }),
|
||||
icon: Setting.ejabberd_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "ejabberd" })),
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "Gitea",
|
||||
path: admin_settings_services_path(params: { s: "gitea" }),
|
||||
icon: Setting.gitea_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "gitea" })),
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "LNDHub",
|
||||
path: admin_settings_services_path(params: { s: "lndhub" }),
|
||||
icon: Setting.lndhub_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "lndhub" })),
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "Mastodon",
|
||||
path: admin_settings_services_path(params: { s: "mastodon" }),
|
||||
icon: Setting.mastodon_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "mastodon" })),
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "MediaWiki",
|
||||
path: admin_settings_services_path(params: { s: "mediawiki" }),
|
||||
icon: Setting.mediawiki_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "mediawiki" })),
|
||||
) %>
|
||||
<%= render SidenavLinkComponent.new(
|
||||
level: 2,
|
||||
name: "Nostr",
|
||||
path: admin_settings_services_path(params: { s: "nostr" }),
|
||||
icon: Setting.nostr_enabled? ? "check" : "x",
|
||||
active: current_page?(admin_settings_services_path(params: { s: "nostr" })),
|
||||
) %>
|
Loading…
x
Reference in New Issue
Block a user