Reduce duplication in Application Settings frontend
Everyone can contribute. Help move this issue forward while earning points, leveling up and collecting rewards.
admin/application_settings/show.html.haml
Example:
%section.settings.as-visibility-access.no-animate#js-visibility-settings{ class: ('expanded' if expanded) }
.settings-header
%h4
= _('Visibility and access controls')
%button.btn.js-settings-toggle{ type: 'button' }
= expanded ? _('Collapse') : _('Expand')
%p
= _('Set default and restrict visibility levels. Configure import sources and git access protocol.')
.settings-content
= render 'visibility_and_access'
%section.settings.as-account-limit.no-animate#js-account-settings{ class: ('expanded' if expanded) }
.settings-header
%h4
= _('Account and limit')
%button.btn.js-settings-toggle{ type: 'button' }
= expanded ? _('Collapse') : _('Expand')
%p
= _('Session expiration, projects limit and attachment size.')
.settings-content
= render 'account_and_limit'
%section.settings.as-signup.no-animate#js-signup-settings{ class: ('expanded' if expanded) }
.settings-header
%h4
= _('Sign-up restrictions')
%button.btn.js-settings-toggle{ type: 'button' }
= expanded ? _('Collapse') : _('Expand')
%p
= _('Configure the way a user creates a new account.')
.settings-content
= render 'signup'
The structure is always the same:
-
%sectiontag with.settings.no-animate, a section-specific class, a section-specific ID, and an optionalexpandedclass- A header with variable text
- A button to expand or collapse
- Some help text
- Render a partial
We can simplify with something like:
= setting_section(:signup, title: _('Sign-up restrictions'), description: _('Configure the way a user creates a new account.'))
Every other variable piece can be derived from the :signup argument (.as-signup, #js-signup-settings, render 'signup').
Some settings might not currently follow this convention, but they can be adapted to.
app/views/admin/application_settings/
Every partial starts with this preamble:
= form_for @application_setting, url: admin_application_settings_path, html: { class: 'fieldset-form' } do |f|
= form_errors(@application_setting)
and ends with
= f.submit 'Save changes', class: "btn btn-success"
We can add an application_setting_form helper that does something like this:
def application_setting_form(application_setting, &block)
form_for(application_setting, ...) do |f|
yield f
f.submit 'Save changes', class: 'btn btn-success'
end
end
Edited by 🤖 GitLab Bot 🤖