Skip to content
This repository has been archived by the owner on Dec 21, 2023. It is now read-only.

Commit

Permalink
Replace best_in_place editor on admin settings page (mastodon#2789)
Browse files Browse the repository at this point in the history
* Remove best_in_place

* Replace best_in_place usage with rails helpers

* Move admin/settings#index to #edit action

* Remove click_to__edit from i18n
  • Loading branch information
mjankowski authored and Gargron committed May 4, 2017
1 parent 91ddd34 commit 2bd132d
Show file tree
Hide file tree
Showing 28 changed files with 117 additions and 97 deletions.
1 change: 0 additions & 1 deletion Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ gem 'hamlit-rails'
gem 'pg'
gem 'pghero'
gem 'dotenv-rails'
gem 'best_in_place', '~> 3.0.1'

gem 'aws-sdk', '>= 2.0'
gem 'paperclip', '~> 5.1'
Expand Down
4 changes: 0 additions & 4 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ GEM
babel-source (>= 4.0, < 6)
execjs (~> 2.0)
bcrypt (3.1.11)
best_in_place (3.0.3)
actionpack (>= 3.2)
railties (>= 3.2)
better_errors (2.1.1)
coderay (>= 1.0.0)
erubis (>= 2.6.6)
Expand Down Expand Up @@ -478,7 +475,6 @@ DEPENDENCIES
addressable
annotate
aws-sdk (>= 2.0)
best_in_place (~> 3.0.1)
better_errors
binding_of_caller
bullet
Expand Down
37 changes: 21 additions & 16 deletions app/controllers/admin/settings_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,43 @@

module Admin
class SettingsController < BaseController
ADMIN_SETTINGS = %w(
site_contact_username
site_contact_email
site_title
site_description
site_extended_description
open_registrations
closed_registrations_message
).freeze
BOOLEAN_SETTINGS = %w(open_registrations).freeze

def index
def edit
@settings = Setting.all_as_records
end

def update
@setting = Setting.where(var: params[:id]).first_or_initialize(var: params[:id])
@setting.update(value: value_for_update)

respond_to do |format|
format.html { redirect_to admin_settings_path }
format.json { respond_with_bip(@setting) }
settings_params.each do |key, value|
setting = Setting.where(var: key).first_or_initialize(var: key)
setting.update(value: value_for_update(key, value))
end

flash[:notice] = 'Success!'
redirect_to edit_admin_settings_path
end

private

def settings_params
params.require(:setting).permit(:value)
params.permit(ADMIN_SETTINGS)
end

def value_for_update
if updating_boolean_setting?
settings_params[:value] == 'true'
def value_for_update(key, value)
if BOOLEAN_SETTINGS.include?(key)
value == 'true'
else
settings_params[:value]
value
end
end

def updating_boolean_setting?
BOOLEAN_SETTINGS.include?(params[:id])
end
end
end
6 changes: 6 additions & 0 deletions app/javascript/styles/forms.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,12 @@ code {
margin: 0 auto;
}

.admin {
input, textarea {
width: 100%;
}
}

.simple_form {
.input {
margin-bottom: 15px;
Expand Down
58 changes: 58 additions & 0 deletions app/views/admin/settings/edit.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
- content_for :page_title do
= t('admin.settings.title')

= form_tag(admin_settings_path, method: :put) do
%table.table
%thead
%tr
%th{width: '40%'}
= t('admin.settings.setting')
%th
%tbody
%tr
%td
%strong= t('admin.settings.contact_information.label')
%td= text_field_tag :site_contact_username,
@settings['site_contact_username'].value,
place_holder: t('admin.settings.contact_information.username')
%tr
%td
%strong= t('admin.accounts.email')
%td= text_field_tag :site_contact_email,
@settings['site_contact_email'].value,
place_holder: t('admin.settings.contact_information.email')
%tr
%td
%strong= t('admin.settings.site_title')
%td= text_field_tag :site_title,
@settings['site_title'].value
%tr
%td
%strong= t('admin.settings.site_description.title')
%p= t('admin.settings.site_description.desc_html')
%td= text_area_tag :site_description,
@settings['site_description'].value,
rows: 8
%tr
%td
%strong= t('admin.settings.site_description_extended.title')
%p= t('admin.settings.site_description_extended.desc_html')
%td= text_area_tag :site_extended_description,
@settings['site_extended_description'].value,
rows: 8
%tr
%td
%strong= t('admin.settings.registrations.open.title')
%td
= select_tag :open_registrations,
options_for_select({ t('admin.settings.registrations.open.disabled') => false, t('admin.settings.registrations.open.enabled') => true }, @settings['open_registrations'].value)
%tr
%td
%strong= t('admin.settings.registrations.closed_message.title')
%p= t('admin.settings.registrations.closed_message.desc_html')
%td= text_area_tag :closed_registrations_message,
@settings['closed_registrations_message'].value,
rows: 8

.simple_form.actions
= button_tag t('generic.save_changes'), type: :submit, class: :btn
40 changes: 0 additions & 40 deletions app/views/admin/settings/index.html.haml

This file was deleted.

1 change: 0 additions & 1 deletion config/locales/de.yml
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ de:
unresolved: Ungelöst
view: Ansehen
settings:
click_to_edit: Klicken zum Bearbeiten
contact_information:
email: Eine öffentliche E-Mail-Adresse angeben
label: Kontaktinformationen
Expand Down
1 change: 0 additions & 1 deletion config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@ en:
unresolved: Unresolved
view: View
settings:
click_to_edit: Click to edit
contact_information:
email: Enter a public e-mail address
label: Contact information
Expand Down
3 changes: 1 addition & 2 deletions config/locales/fa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ fa:
unresolved: حل‌نشده
view: نمایش
settings:
click_to_edit: برای ویرایش کلیک کنید
contact_information:
email: یک نشانی ایمیل عمومی وارد کنید
label: اطلاعات تماس
Expand Down Expand Up @@ -297,7 +296,7 @@ fa:
visibilities:
private: نمایش تنها به پیگیران
public: عمومی
unlisted: عمومی، ولی در فهرست نوشته‌ها نمایش نده
unlisted: عمومی، ولی در فهرست نوشته‌ها نمایش نده
stream_entries:
click_to_show: برای نمایش کلیک کنید
reblogged: بازبوقیده
Expand Down
1 change: 0 additions & 1 deletion config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ fr:
unresolved: Non résolus
view: Voir
settings:
click_to_edit: Cliquez pour éditer
contact_information:
email: Entrez une adresse courriel publique
label: Informations de contact
Expand Down
1 change: 0 additions & 1 deletion config/locales/he.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ he:
unresolved: לא פתור
view: תצוגה
settings:
click_to_edit: לחיצה כדי לערוך
contact_information:
email: 'נא להקליד כתובת דוא"ל פומבית'
label: פרטי התקשרות
Expand Down
1 change: 0 additions & 1 deletion config/locales/id.yml
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ id:
unresolved: Belum Terseleseikan
view: Tampilan
settings:
click_to_edit: Klik untuk mengubah
contact_information:
email: Masukkan alamat email
label: Informasi kontak
Expand Down
1 change: 0 additions & 1 deletion config/locales/io.yml
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ io:
unresolved: Unresolved
view: View
settings:
click_to_edit: Click to edit
contact_information:
email: Enter a public e-mail address
label: Contact information
Expand Down
1 change: 0 additions & 1 deletion config/locales/ja.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ ja:
unresolved: 未解決
view: 表示
settings:
click_to_edit: クリックして編集
contact_information:
email: 公開するメールアドレスを入力
label: 連絡先情報
Expand Down
1 change: 0 additions & 1 deletion config/locales/nl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@ nl:
unfollow: Ontvolgen
admin:
settings:
click_to_edit: Klik om te bewerken
contact_information:
email: Vul een openbaar gebruikt e-mailadres in
label: Contactgegevens
Expand Down
1 change: 0 additions & 1 deletion config/locales/oc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,6 @@ oc:
unresolved: Pas resolguts
view: Veire
settings:
click_to_edit: Clicatz per modificar
contact_information:
email: Picatz una adreça de corrièl
label: Informacions de contacte
Expand Down
3 changes: 1 addition & 2 deletions config/locales/pl.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pl:
domain_count_before: Serwer połączony z
features:
api: Otwarte API dla aplikacji i usług
blocks: Rozbudowane narzędzia blokowania i ukrywania
blocks: Rozbudowane narzędzia blokowania i ukrywania
characters: 500 znaków na wpis
chronology: Chronologiczny porządek wyświetlania
ethics: 'Etyczne założenia: nie śledzimy, bez reklam'
Expand Down Expand Up @@ -158,7 +158,6 @@ pl:
unresolved: Nierozwiązane
view: Wyświetl
settings:
click_to_edit: Naciśnij, aby edytować
contact_information:
email: Wprowadź publiczny adres e-mail
label: Informacje kontaktowe
Expand Down
1 change: 0 additions & 1 deletion config/locales/pt-BR.yml
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,6 @@ pt-BR:
unresolved: Unresolved
view: View
settings:
click_to_edit: Clique para editar
contact_information:
email: Entre um endereço de email público
label: Informação de contato
Expand Down
1 change: 0 additions & 1 deletion config/locales/pt.yml
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,6 @@ pt:
unresolved: Por resolver
view: Ver
settings:
click_to_edit: Clique para editar
contact_information:
email: Inserir um endereço de email para tornar público
label: Informação de contacto
Expand Down
3 changes: 1 addition & 2 deletions config/locales/ru.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ ru:
terms: Условия
user_count_after: пользователей
user_count_before: Здесь живет
version: Версия
version: Версия
accounts:
follow: Подписаться
followers: Подписчики
Expand Down Expand Up @@ -139,7 +139,6 @@ ru:
unresolved: Неразрешенные
view: Просмотреть
settings:
click_to_edit: Нажмите для изменения
contact_information:
email: Введите публичный e-mail
label: Контактная информация
Expand Down
3 changes: 1 addition & 2 deletions config/locales/th.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ th:
followers: ผู้ติดตาม
following: กำลังติดตาม
nothing_here: ไม่พบสิ่งใดที่นี่!
people_followed_by: ถูกติดตามโดย %{name}
people_followed_by: ถูกติดตามโดย %{name}
people_who_follow: คนที่ติดตาม %{name}
posts: โพสต์
remote_follow: Remote follow
Expand Down Expand Up @@ -157,7 +157,6 @@ th:
unresolved: Unresolved
view: วิว
settings:
click_to_edit: คลิ๊กเพื่อแก้ไข
contact_information:
email: กรอกที่อยู่อีเมล์สาธารณะ
label: ข้อมูลที่ติดต่อ
Expand Down
1 change: 0 additions & 1 deletion config/locales/zh-CN.yml
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,6 @@ zh-CN:
unresolved: 未处理
view: 查看
settings:
click_to_edit: 点击编辑
contact_information:
email: 输入一个公开的电邮地址
label: 联系数据
Expand Down
1 change: 0 additions & 1 deletion config/locales/zh-HK.yml
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,6 @@ zh-HK:
unresolved: 未處理
view: 檢視
settings:
click_to_edit: 點擊編輯
contact_information:
email: 輸入一個公開的電郵地址
label: 聯絡資料
Expand Down
1 change: 0 additions & 1 deletion config/locales/zh-TW.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,6 @@ zh-TW:
unresolved: 未解決
view: 檢視
settings:
click_to_edit: 點選以編輯
contact_information:
email: 請輸入輸入一個公開電子信箱
label: 聯絡資訊
Expand Down
2 changes: 1 addition & 1 deletion config/navigation.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
admin.item :domain_blocks, safe_join([fa_icon('lock fw'), t('admin.domain_blocks.title')]), admin_domain_blocks_url, highlights_on: %r{/admin/domain_blocks}
admin.item :sidekiq, safe_join([fa_icon('diamond fw'), 'Sidekiq']), sidekiq_url, link_html: { target: 'sidekiq' }
admin.item :pghero, safe_join([fa_icon('database fw'), 'PgHero']), pghero_url, link_html: { target: 'pghero' }
admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), admin_settings_url
admin.item :settings, safe_join([fa_icon('cogs fw'), t('admin.settings.title')]), edit_admin_settings_url
end

primary.item :logout, safe_join([fa_icon('sign-out fw'), t('auth.logout')]), destroy_user_session_url, link_html: { 'data-method' => 'delete' }
Expand Down
2 changes: 1 addition & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@
namespace :admin do
resources :pubsubhubbub, only: [:index]
resources :domain_blocks, only: [:index, :new, :create, :show, :destroy]
resources :settings, only: [:index, :update]
resource :settings, only: [:edit, :update]
resources :instances, only: [:index]

resources :reports, only: [:index, :show, :update] do
Expand Down
Loading

0 comments on commit 2bd132d

Please sign in to comment.