From 1e494756535422cad46ddb4cf796cf3800793605 Mon Sep 17 00:00:00 2001 From: Matt Jankowski Date: Sun, 22 Sep 2024 14:49:33 -0400 Subject: [PATCH] Move _filter_fields to _form partial --- app/views/filters/_filter_fields.html.haml | 61 ---------------------- app/views/filters/_form.html.haml | 61 ++++++++++++++++++++++ app/views/filters/edit.html.haml | 6 +-- app/views/filters/new.html.haml | 6 +-- 4 files changed, 67 insertions(+), 67 deletions(-) delete mode 100644 app/views/filters/_filter_fields.html.haml create mode 100644 app/views/filters/_form.html.haml diff --git a/app/views/filters/_filter_fields.html.haml b/app/views/filters/_filter_fields.html.haml deleted file mode 100644 index 797c969b24d..00000000000 --- a/app/views/filters/_filter_fields.html.haml +++ /dev/null @@ -1,61 +0,0 @@ -.fields-row - .fields-row__column.fields-row__column-6.fields-group - = f.input :title, - as: :string, - hint: false, - wrapper: :with_label - .fields-row__column.fields-row__column-6.fields-group - = f.input :expires_in, - collection: CustomFilter::EXPIRATION_DURATIONS.map(&:to_i), - include_blank: I18n.t('invites.expires_in_prompt'), - label_method: ->(i) { I18n.t("invites.expires_in.#{i}") }, - wrapper: :with_label - -.fields-group - = f.input :context, - as: :check_boxes, - collection_wrapper_tag: 'ul', - collection: CustomFilter::VALID_CONTEXTS, - include_blank: false, - item_wrapper_tag: 'li', - label_method: ->(context) { I18n.t("filters.contexts.#{context}") }, - wrapper: :with_block_label - -%hr.spacer/ - -.fields-group - = f.input :filter_action, - as: :radio_buttons, - collection: %i(warn hide), - hint: t('simple_form.hints.filters.action'), - include_blank: false, - label_method: ->(action) { filter_action_label(action) }, - required: true, - wrapper: :with_block_label - -%hr.spacer/ - -- unless f.object.statuses.empty? - %h4= t('filters.edit.statuses') - - %p.muted-hint= t('filters.edit.statuses_hint_html', path: filter_statuses_path(f.object)) - - %hr.spacer/ - -%h4= t('filters.edit.keywords') - -.table-wrapper - %table.table.keywords-table - %thead - %tr - %th= t('simple_form.labels.defaults.phrase') - %th= t('simple_form.labels.defaults.whole_word') - %th - %tbody - = f.simple_fields_for :keywords do |keyword| - = render 'keyword_fields', f: keyword - %tfoot - %tr - %td{ colspan: 3 } - = link_to_add_association f, :keywords, class: 'table-action-link', partial: 'keyword_fields', 'data-association-insertion-node': '.keywords-table tbody', 'data-association-insertion-method': 'append' do - = safe_join([material_symbol('add'), t('filters.edit.add_keyword')]) diff --git a/app/views/filters/_form.html.haml b/app/views/filters/_form.html.haml new file mode 100644 index 00000000000..a8337bfa2cd --- /dev/null +++ b/app/views/filters/_form.html.haml @@ -0,0 +1,61 @@ +.fields-row + .fields-row__column.fields-row__column-6.fields-group + = form.input :title, + as: :string, + hint: false, + wrapper: :with_label + .fields-row__column.fields-row__column-6.fields-group + = form.input :expires_in, + collection: CustomFilter::EXPIRATION_DURATIONS.map(&:to_i), + include_blank: I18n.t('invites.expires_in_prompt'), + label_method: ->(i) { I18n.t("invites.expires_in.#{i}") }, + wrapper: :with_label + +.fields-group + = form.input :context, + as: :check_boxes, + collection_wrapper_tag: 'ul', + collection: CustomFilter::VALID_CONTEXTS, + include_blank: false, + item_wrapper_tag: 'li', + label_method: ->(context) { I18n.t("filters.contexts.#{context}") }, + wrapper: :with_block_label + +%hr.spacer/ + +.fields-group + = form.input :filter_action, + as: :radio_buttons, + collection: %i(warn hide), + hint: t('simple_form.hints.filters.action'), + include_blank: false, + label_method: ->(action) { filter_action_label(action) }, + required: true, + wrapper: :with_block_label + +%hr.spacer/ + +- unless form.object.statuses.empty? + %h4= t('filters.edit.statuses') + + %p.muted-hint= t('filters.edit.statuses_hint_html', path: filter_statuses_path(form.object)) + + %hr.spacer/ + +%h4= t('filters.edit.keywords') + +.table-wrapper + %table.table.keywords-table + %thead + %tr + %th= t('simple_form.labels.defaults.phrase') + %th= t('simple_form.labels.defaults.whole_word') + %th + %tbody + = form.simple_fields_for :keywords do |keyword| + = render 'keyword_fields', f: keyword + %tfoot + %tr + %td{ colspan: 3 } + = link_to_add_association form, :keywords, class: 'table-action-link', partial: 'keyword_fields', 'data-association-insertion-node': '.keywords-table tbody', 'data-association-insertion-method': 'append' do + = safe_join([material_symbol('add'), t('filters.edit.add_keyword')]) diff --git a/app/views/filters/edit.html.haml b/app/views/filters/edit.html.haml index 3dc3f07b72c..d1857e2d868 100644 --- a/app/views/filters/edit.html.haml +++ b/app/views/filters/edit.html.haml @@ -1,8 +1,8 @@ - content_for :page_title do = t('filters.edit.title') -= simple_form_for @filter, url: filter_path(@filter), method: :put do |f| - = render 'filter_fields', f: f += simple_form_for @filter, url: filter_path(@filter), method: :put do |form| + = render form .actions - = f.button :button, t('generic.save_changes'), type: :submit + = form.button :button, t('generic.save_changes'), type: :submit diff --git a/app/views/filters/new.html.haml b/app/views/filters/new.html.haml index 5f400e604a7..9a3492744e0 100644 --- a/app/views/filters/new.html.haml +++ b/app/views/filters/new.html.haml @@ -1,8 +1,8 @@ - content_for :page_title do = t('filters.new.title') -= simple_form_for @filter, url: filters_path do |f| - = render 'filter_fields', f: f += simple_form_for @filter, url: filters_path do |form| + = render form .actions - = f.button :button, t('filters.new.save'), type: :submit + = form.button :button, t('filters.new.save'), type: :submit