From 4fa2f7e82d68c974ecfdb8896f15a5a3aba25828 Mon Sep 17 00:00:00 2001 From: David Yip Date: Sun, 15 Oct 2017 03:17:33 -0500 Subject: Set up /settings/keyword_mutes. #164. This should eventually be accessible via the API and the web frontend, but I find it easier to set up an editing interface using Rails templates and the like. We can always take it out if it turns out we don't need it. --- config/locales/en.yml | 1 + config/navigation.rb | 1 + config/routes.rb | 1 + 3 files changed, 3 insertions(+) (limited to 'config') diff --git a/config/locales/en.yml b/config/locales/en.yml index 45929e97d..6b4e602bd 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -491,6 +491,7 @@ en: export: Data export followers: Authorized followers import: Import + keyword_mutes: Muted keywords notifications: Notifications preferences: Preferences settings: Settings diff --git a/config/navigation.rb b/config/navigation.rb index 50bfbd480..9fa029b72 100644 --- a/config/navigation.rb +++ b/config/navigation.rb @@ -7,6 +7,7 @@ SimpleNavigation::Configuration.run do |navigation| primary.item :settings, safe_join([fa_icon('cog fw'), t('settings.settings')]), settings_profile_url do |settings| settings.item :profile, safe_join([fa_icon('user fw'), t('settings.edit_profile')]), settings_profile_url settings.item :preferences, safe_join([fa_icon('sliders fw'), t('settings.preferences')]), settings_preferences_url + settings.item :keyword_mutes, safe_join([fa_icon('volume-off fw'), t('settings.keyword_mutes')]), settings_keyword_mutes_url settings.item :notifications, safe_join([fa_icon('bell fw'), t('settings.notifications')]), settings_notifications_url settings.item :password, safe_join([fa_icon('lock fw'), t('auth.change_password')]), edit_user_registration_url, highlights_on: %r{/auth/edit|/settings/delete} settings.item :two_factor_authentication, safe_join([fa_icon('mobile fw'), t('settings.two_factor_authentication')]), settings_two_factor_authentication_url, highlights_on: %r{/settings/two_factor_authentication} diff --git a/config/routes.rb b/config/routes.rb index 9ed081e50..686914239 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,6 +66,7 @@ Rails.application.routes.draw do namespace :settings do resource :profile, only: [:show, :update] + resources :keyword_mutes resource :preferences, only: [:show, :update] resource :notifications, only: [:show, :update] resource :import, only: [:show, :create] -- cgit From 2e03a10059889cb05d4fab7736447a4315f90bf5 Mon Sep 17 00:00:00 2001 From: David Yip Date: Sun, 15 Oct 2017 04:51:42 -0500 Subject: Spike out index and new views for keyword mutes controller. --- .../settings/keyword_mutes_controller.rb | 23 ++++++++++++++++++++++ .../settings/keyword_mutes/_keyword_mute.html.haml | 7 +++++++ app/views/settings/keyword_mutes/index.html.haml | 13 ++++++++++++ app/views/settings/keyword_mutes/new.html.haml | 19 ++++++++++++++++++ config/locales/en.yml | 5 +++++ 5 files changed, 67 insertions(+) create mode 100644 app/views/settings/keyword_mutes/_keyword_mute.html.haml create mode 100644 app/views/settings/keyword_mutes/new.html.haml (limited to 'config') diff --git a/app/controllers/settings/keyword_mutes_controller.rb b/app/controllers/settings/keyword_mutes_controller.rb index ffe94e33a..4b3e01b9c 100644 --- a/app/controllers/settings/keyword_mutes_controller.rb +++ b/app/controllers/settings/keyword_mutes_controller.rb @@ -4,4 +4,27 @@ class Settings::KeywordMutesController < ApplicationController layout 'admin' before_action :authenticate_user! + before_action :set_account + + def index + @keyword_mutes = paginated_keyword_mutes_for_account + end + + def new + @keyword_mute = keyword_mutes_for_account.build + end + + private + + def set_account + @account = current_user.account + end + + def keyword_mutes_for_account + KeywordMute.where(account: @account) + end + + def paginated_keyword_mutes_for_account + keyword_mutes_for_account.order(:keyword).page params[:page] + end end diff --git a/app/views/settings/keyword_mutes/_keyword_mute.html.haml b/app/views/settings/keyword_mutes/_keyword_mute.html.haml new file mode 100644 index 000000000..a2698ac7b --- /dev/null +++ b/app/views/settings/keyword_mutes/_keyword_mute.html.haml @@ -0,0 +1,7 @@ +%tr + %td + = keyword_mute.keyword + %td + = table_link_to 'edit', t('settings.keyword_mutes.edit'), edit_settings_keyword_mute_path(keyword_mute) + %td + = table_link_to 'times', t('settings.keyword_mutes.delete'), settings_keyword_mute_path(keyword_mute), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } diff --git a/app/views/settings/keyword_mutes/index.html.haml b/app/views/settings/keyword_mutes/index.html.haml index 421fbeba2..6b212895d 100644 --- a/app/views/settings/keyword_mutes/index.html.haml +++ b/app/views/settings/keyword_mutes/index.html.haml @@ -1,2 +1,15 @@ - content_for :page_title do = t('settings.keyword_mutes') + +.table-wrapper + %table.table + %thead + %tr + %th= t('settings.keyword_mutes.keyword') + %th + %th + %tbody + = render @keyword_mutes + += paginate @keyword_mutes += link_to t('settings.keyword_mutes.add_keyword'), new_settings_keyword_mute_path, class: 'button' diff --git a/app/views/settings/keyword_mutes/new.html.haml b/app/views/settings/keyword_mutes/new.html.haml new file mode 100644 index 000000000..5e8268e97 --- /dev/null +++ b/app/views/settings/keyword_mutes/new.html.haml @@ -0,0 +1,19 @@ +- content_for :page_title do + = t('settings.keyword_mutes.add_keyword') + += simple_form_for @keyword_mute, url: settings_keyword_mutes_path do |f| + = render 'shared/error_messages', object: @keyword_mute + + %p.muted-hint + Keywords match word boundaries case-insensitively. For example: + %ul + %li + alice matches alice, Alice, and Alice's + %li + bob matches bob and Bob but not bobcat + + .fields-group + = f.input :keyword + + .actions + = f.button :button, t('admin.keyword_mutes.add_keyword'), type: :submit diff --git a/config/locales/en.yml b/config/locales/en.yml index 6b4e602bd..5b91f8320 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -215,6 +215,11 @@ en: contact_information: email: Business e-mail username: Contact username + keyword_mutes: + edit: Edit + delete: Delete + add_keyword: Add keyword + keyword: Keyword registrations: closed_message: desc_html: Displayed on frontpage when registrations are closed. You can use HTML tags -- cgit From cd04e3df58c09b0faca81ccc820b2cd5e12c2890 Mon Sep 17 00:00:00 2001 From: David Yip Date: Fri, 20 Oct 2017 15:12:45 -0500 Subject: Fill in create, edit, update, and destroy for keyword mutes interface. Also add a destroy-all action, which can be useful if you're flushing an old list entirely to start a new one. --- .../settings/keyword_mutes_controller.rb | 42 ++++++++++++++++++++++ app/views/settings/keyword_mutes/_fields.html.haml | 11 ++++++ .../settings/keyword_mutes/_keyword_mute.html.haml | 3 ++ app/views/settings/keyword_mutes/edit.html.haml | 6 ++++ app/views/settings/keyword_mutes/index.html.haml | 7 ++-- app/views/settings/keyword_mutes/new.html.haml | 17 ++------- config/locales/en.yml | 13 ++++--- config/routes.rb | 8 ++++- 8 files changed, 84 insertions(+), 23 deletions(-) create mode 100644 app/views/settings/keyword_mutes/_fields.html.haml create mode 100644 app/views/settings/keyword_mutes/edit.html.haml (limited to 'config') diff --git a/app/controllers/settings/keyword_mutes_controller.rb b/app/controllers/settings/keyword_mutes_controller.rb index 4b3e01b9c..d9f99af09 100644 --- a/app/controllers/settings/keyword_mutes_controller.rb +++ b/app/controllers/settings/keyword_mutes_controller.rb @@ -5,6 +5,7 @@ class Settings::KeywordMutesController < ApplicationController before_action :authenticate_user! before_action :set_account + before_action :load_keyword_mute, only: [:edit, :update, :destroy] def index @keyword_mutes = paginated_keyword_mutes_for_account @@ -14,6 +15,39 @@ class Settings::KeywordMutesController < ApplicationController @keyword_mute = keyword_mutes_for_account.build end + def create + @keyword_mute = keyword_mutes_for_account.create(keyword_mute_params) + + if @keyword_mute.persisted? + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + else + render :new + end + end + + def update + if @keyword_mute.update(keyword_mute_params) + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + else + render :new + end + end + + def destroy + if @keyword_mute.destroy + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + else + # FIXME + redirect_to settings_keyword_mutes_path, notice: "huh that didn't work right" + end + end + + def destroy_all + keyword_mutes_for_account.delete_all + + redirect_to settings_keyword_mutes_path, notice: I18n.t('generic.changes_saved_msg') + end + private def set_account @@ -24,6 +58,14 @@ class Settings::KeywordMutesController < ApplicationController KeywordMute.where(account: @account) end + def load_keyword_mute + @keyword_mute = keyword_mutes_for_account.find(params[:id]) + end + + def keyword_mute_params + params.require(:keyword_mute).permit(:keyword, :whole_word) + end + def paginated_keyword_mutes_for_account keyword_mutes_for_account.order(:keyword).page params[:page] end diff --git a/app/views/settings/keyword_mutes/_fields.html.haml b/app/views/settings/keyword_mutes/_fields.html.haml new file mode 100644 index 000000000..892676f18 --- /dev/null +++ b/app/views/settings/keyword_mutes/_fields.html.haml @@ -0,0 +1,11 @@ +.fields-group + = f.input :keyword + = f.check_box :whole_word + = f.label :whole_word, t('keyword_mutes.match_whole_word') + +.actions + - if f.object.persisted? + = f.button :button, t('generic.save_changes'), type: :submit + = link_to t('keyword_mutes.remove'), settings_keyword_mute_path(f.object), class: 'negative button', method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } + - else + = f.button :button, t('keyword_mutes.add_keyword'), type: :submit diff --git a/app/views/settings/keyword_mutes/_keyword_mute.html.haml b/app/views/settings/keyword_mutes/_keyword_mute.html.haml index a2698ac7b..7e191d79b 100644 --- a/app/views/settings/keyword_mutes/_keyword_mute.html.haml +++ b/app/views/settings/keyword_mutes/_keyword_mute.html.haml @@ -1,6 +1,9 @@ %tr %td = keyword_mute.keyword + %td + - if keyword_mute.whole_word + %i.fa.fa-check %td = table_link_to 'edit', t('settings.keyword_mutes.edit'), edit_settings_keyword_mute_path(keyword_mute) %td diff --git a/app/views/settings/keyword_mutes/edit.html.haml b/app/views/settings/keyword_mutes/edit.html.haml new file mode 100644 index 000000000..2b52f4018 --- /dev/null +++ b/app/views/settings/keyword_mutes/edit.html.haml @@ -0,0 +1,6 @@ +- content_for :page_title do + = t('keyword_mutes.edit_keyword') + += simple_form_for @keyword_mute, url: settings_keyword_mute_path(@keyword_mute) do |f| + = render 'shared/error_messages', object: @keyword_mute + = render 'fields', f: f diff --git a/app/views/settings/keyword_mutes/index.html.haml b/app/views/settings/keyword_mutes/index.html.haml index 6b212895d..b359eea4a 100644 --- a/app/views/settings/keyword_mutes/index.html.haml +++ b/app/views/settings/keyword_mutes/index.html.haml @@ -5,11 +5,14 @@ %table.table %thead %tr - %th= t('settings.keyword_mutes.keyword') + %th= t('keyword_mutes.keyword') + %th= t('keyword_mutes.match_whole_word') %th %th %tbody = render @keyword_mutes = paginate @keyword_mutes -= link_to t('settings.keyword_mutes.add_keyword'), new_settings_keyword_mute_path, class: 'button' +.simple_form + = link_to t('keyword_mutes.add_keyword'), new_settings_keyword_mute_path, class: 'button' + = link_to t('keyword_mutes.remove_all'), destroy_all_settings_keyword_mutes_path, class: 'button negative', method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } diff --git a/app/views/settings/keyword_mutes/new.html.haml b/app/views/settings/keyword_mutes/new.html.haml index 5e8268e97..197f10cd7 100644 --- a/app/views/settings/keyword_mutes/new.html.haml +++ b/app/views/settings/keyword_mutes/new.html.haml @@ -1,19 +1,6 @@ - content_for :page_title do - = t('settings.keyword_mutes.add_keyword') + = t('keyword_mutes.add_keyword') = simple_form_for @keyword_mute, url: settings_keyword_mutes_path do |f| = render 'shared/error_messages', object: @keyword_mute - - %p.muted-hint - Keywords match word boundaries case-insensitively. For example: - %ul - %li - alice matches alice, Alice, and Alice's - %li - bob matches bob and Bob but not bobcat - - .fields-group - = f.input :keyword - - .actions - = f.button :button, t('admin.keyword_mutes.add_keyword'), type: :submit + = render 'fields', f: f diff --git a/config/locales/en.yml b/config/locales/en.yml index 5b91f8320..22aa29be3 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -215,11 +215,6 @@ en: contact_information: email: Business e-mail username: Contact username - keyword_mutes: - edit: Edit - delete: Delete - add_keyword: Add keyword - keyword: Keyword registrations: closed_message: desc_html: Displayed on frontpage when registrations are closed. You can use HTML tags @@ -378,6 +373,14 @@ en: following: Following list muting: Muting list upload: Upload + keyword_mutes: + add_keyword: Add keyword + delete: Delete + edit: Edit + edit_keyword: Edit keyword + keyword: Keyword + match_whole_word: Match whole word + remove_all: Remove all landing_strip_html: "%{name} is a user on %{link_to_root_path}. You can follow them or interact with them if you have an account anywhere in the fediverse." landing_strip_signup_html: If you don't, you can sign up here. media_attachments: diff --git a/config/routes.rb b/config/routes.rb index 686914239..5d83ef2ab 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,7 +66,13 @@ Rails.application.routes.draw do namespace :settings do resource :profile, only: [:show, :update] - resources :keyword_mutes + + resources :keyword_mutes do + collection do + delete :destroy_all + end + end + resource :preferences, only: [:show, :update] resource :notifications, only: [:show, :update] resource :import, only: [:show, :create] -- cgit From 1a60445a5fa8208b54afaedf5e5796fb2ac0a80a Mon Sep 17 00:00:00 2001 From: David Yip Date: Sun, 22 Oct 2017 01:05:56 -0500 Subject: Address unused translation errors. --- app/views/settings/keyword_mutes/_keyword_mute.html.haml | 4 ++-- config/locales/en.yml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) (limited to 'config') diff --git a/app/views/settings/keyword_mutes/_keyword_mute.html.haml b/app/views/settings/keyword_mutes/_keyword_mute.html.haml index 7e191d79b..c45cc64fb 100644 --- a/app/views/settings/keyword_mutes/_keyword_mute.html.haml +++ b/app/views/settings/keyword_mutes/_keyword_mute.html.haml @@ -5,6 +5,6 @@ - if keyword_mute.whole_word %i.fa.fa-check %td - = table_link_to 'edit', t('settings.keyword_mutes.edit'), edit_settings_keyword_mute_path(keyword_mute) + = table_link_to 'edit', t('keyword_mutes.edit'), edit_settings_keyword_mute_path(keyword_mute) %td - = table_link_to 'times', t('settings.keyword_mutes.delete'), settings_keyword_mute_path(keyword_mute), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } + = table_link_to 'times', t('keyword_mutes.remove'), settings_keyword_mute_path(keyword_mute), method: :delete, data: { confirm: t('admin.accounts.are_you_sure') } diff --git a/config/locales/en.yml b/config/locales/en.yml index 22aa29be3..7d46df327 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -375,11 +375,11 @@ en: upload: Upload keyword_mutes: add_keyword: Add keyword - delete: Delete edit: Edit edit_keyword: Edit keyword keyword: Keyword match_whole_word: Match whole word + remove: Remove remove_all: Remove all landing_strip_html: "%{name} is a user on %{link_to_root_path}. You can follow them or interact with them if you have an account anywhere in the fediverse." landing_strip_signup_html: If you don't, you can sign up here. -- cgit