From b02bc91ec308358e2fd820323d2ee8eefbd984a1 Mon Sep 17 00:00:00 2001 From: IanM Date: Mon, 19 Feb 2024 12:35:58 +0000 Subject: [PATCH] search source feature toggle --- extend.php | 10 ++++++---- js/src/admin/components/BestAnswerSettings.js | 12 +++++++++++- js/src/forum/extenders/extendSearch.ts | 5 ++++- resources/locale/en.yml | 3 +++ 4 files changed, 24 insertions(+), 6 deletions(-) diff --git a/extend.php b/extend.php index d7c1e41..7ef02d7 100644 --- a/extend.php +++ b/extend.php @@ -86,14 +86,16 @@ ->addSortField('bestAnswerCount'), (new Extend\Settings()) + ->default('fof-best-answer.schedule_on_one_server', false) + ->default('fof-best-answer.stop_overnight', false) + ->default('fof-best-answer.store_log_output', false) + ->default('fof-best-answer.enabled-tags', '[]') + ->default('fof-best-answer.search.solution_search', true) ->serializeToForum('canSelectBestAnswerOwnPost', 'fof-best-answer.allow_select_own_post', 'boolVal') ->serializeToForum('useAlternativeBestAnswerUi', 'fof-best-answer.use_alternative_ui', 'boolVal') ->serializeToForum('showBestAnswerFilterUi', 'fof-best-answer.show_filter_dropdown', 'boolVal') ->serializeToForum('fof-best-answer.show_max_lines', 'fof-best-answer.show_max_lines', 'intVal') - ->default('fof-best-answer.schedule_on_one_server', false) - ->default('fof-best-answer.stop_overnight', false) - ->default('fof-best-answer.store_log_output', false) - ->default('fof-best-answer.enabled-tags', '[]'), + ->serializeToForum('solutionSearchEnabled', 'fof-best-answer.search.solution_search', 'boolVal'), (new Extend\ApiController(ShowDiscussionController::class)) ->addInclude(['bestAnswerPost', 'bestAnswerUser']) diff --git a/js/src/admin/components/BestAnswerSettings.js b/js/src/admin/components/BestAnswerSettings.js index 40017ee..a2b5148 100644 --- a/js/src/admin/components/BestAnswerSettings.js +++ b/js/src/admin/components/BestAnswerSettings.js @@ -1,5 +1,5 @@ import app from 'flarum/admin/app'; -import ExtensionPage from 'flarum/admin/components/ExtensionPage'; +import ExtensionPage, { ExtensionPageAttrs } from 'flarum/admin/components/ExtensionPage'; import Button from 'flarum/common/components/Button'; import Link from 'flarum/common/components/Link'; @@ -115,6 +115,16 @@ export default class BestAnswerSettings extends ExtensionPage { })}
+
+

{app.translator.trans('fof-best-answer.admin.settings.label.search')}

+ {this.buildSettingComponent({ + type: 'boolean', + setting: 'fof-best-answer.search.solution_search', + label: app.translator.trans('fof-best-answer.admin.settings.solution_search'), + help: app.translator.trans('fof-best-answer.admin.settings.solution_search_help'), + })} +
+

{app.translator.trans('fof-best-answer.admin.settings.label.reminders')}

diff --git a/js/src/forum/extenders/extendSearch.ts b/js/src/forum/extenders/extendSearch.ts index 8945bbc..0b7595c 100644 --- a/js/src/forum/extenders/extendSearch.ts +++ b/js/src/forum/extenders/extendSearch.ts @@ -1,3 +1,4 @@ +import app from 'flarum/forum/app'; import { extend } from 'flarum/common/extend'; import ItemList from 'flarum/common/utils/ItemList'; import Search, { SearchSource } from 'flarum/forum/components/Search'; @@ -5,6 +6,8 @@ import SolutionSearchSource from '../components/SolutionSearchSource'; export default function extendSearch() { extend(Search.prototype, 'sourceItems', function (items: ItemList) { - items.add('solution', new SolutionSearchSource(), 110); + if (app.forum.attribute('solutionSearchEnabled')) { + items.add('solution', new SolutionSearchSource(), 110); + } }); } diff --git a/resources/locale/en.yml b/resources/locale/en.yml index 71d8e03..05c1294 100644 --- a/resources/locale/en.yml +++ b/resources/locale/en.yml @@ -8,6 +8,7 @@ fof-best-answer: tags: Best Answer Tags general: General reminders: Reminders + search: Search advanced: Advanced reminders_notice: For reminders to function, you must have set up the Flarum scheduler correctly. allow_select_own_post: Select own post @@ -34,6 +35,8 @@ fof-best-answer: remind_tags_help: Select which tags, if any, to send reminders for. Reminders will only be sent for discussions with these tags. tags_info: | When a tag is Best Answer enabled, assign permissions to each user group that may set answers (own discussion, any discussion). Permissions may be assigned globally (for any Best Answer anabled tag), or on a per tag basis. + solution_search: Solution search + solution_search_help: Enable the ability to search for discussions with Best Answers edit_tag: qna_label: Enable Best Answers to be set in this tag reminders: Send reminders to set a Best Answer for discussions in this tag