about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDavid Yip <yipdw@member.fsf.org>2017-10-20 15:12:45 -0500
committerDavid Yip <yipdw@member.fsf.org>2017-10-21 14:54:36 -0500
commitcd04e3df58c09b0faca81ccc820b2cd5e12c2890 (patch)
tree932e00860dc94c03712222ba68bed19480e0a3b6
parent4a64181461cb02599da98166da4b527adbb705ad (diff)
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.
-rw-r--r--app/controllers/settings/keyword_mutes_controller.rb42
-rw-r--r--app/views/settings/keyword_mutes/_fields.html.haml11
-rw-r--r--app/views/settings/keyword_mutes/_keyword_mute.html.haml3
-rw-r--r--app/views/settings/keyword_mutes/edit.html.haml6
-rw-r--r--app/views/settings/keyword_mutes/index.html.haml7
-rw-r--r--app/views/settings/keyword_mutes/new.html.haml17
-rw-r--r--config/locales/en.yml13
-rw-r--r--config/routes.rb8
8 files changed, 84 insertions, 23 deletions
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
@@ -2,6 +2,9 @@
   %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
     = 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/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
-        <strong>alice</strong> matches <strong>alice</strong>, <strong>Alice</strong>, and <strong>Alice's</strong>
-      %li
-        <strong>bob</strong> matches <strong>bob</strong> and <strong>Bob</strong> but not <strong>bobcat</strong>
-
-  .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: "<strong>%{name}</strong> 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 <a href="%{sign_up_path}">sign up here</a>.
   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]