diff --git a/app/controllers/public/api/v1/portals/search_controller.rb b/app/controllers/public/api/v1/portals/search_controller.rb new file mode 100644 index 000000000..104741773 --- /dev/null +++ b/app/controllers/public/api/v1/portals/search_controller.rb @@ -0,0 +1,31 @@ +class Public::Api::V1::Portals::SearchController < Public::Api::V1::Portals::BaseController + before_action :ensure_custom_domain_request, only: [:index] + before_action :portal + before_action :set_portal_layout + before_action :set_view_variant + before_action :ensure_portal_feature_enabled + layout 'portal' + + def index + @query = params[:query].to_s.strip + @articles = @portal.articles.published.includes(:category).where(locale: params[:locale]) + + search_articles + + @articles = @articles.page(params[:page]).per(10) + end + + private + + def search_articles + @articles = @query.present? ? @articles.search(search_params) : @articles.none + end + + def search_params + params.permit(:query, :locale, :sort, :status, :page).tap do |permitted| + permitted[:query] = @query + end + end +end + +Public::Api::V1::Portals::SearchController.prepend_mod_with('Public::Api::V1::Portals::SearchController') diff --git a/app/helpers/portal_helper.rb b/app/helpers/portal_helper.rb index 65166145c..0c993ec59 100644 --- a/app/helpers/portal_helper.rb +++ b/app/helpers/portal_helper.rb @@ -45,9 +45,16 @@ module PortalHelper theme.present? && theme != 'system' ? "?theme=#{theme}" : '' end + def portal_query_string(theme, is_plain_layout_enabled) + query_params = {} + query_params[:theme] = theme if theme.present? && theme != 'system' + query_params[:show_plain_layout] = true if is_plain_layout_enabled + query_params.present? ? "?#{query_params.to_query}" : '' + end + def generate_home_link(portal_slug, portal_locale, theme, is_plain_layout_enabled) if is_plain_layout_enabled - "/hc/#{portal_slug}/#{portal_locale}#{theme_query_string(theme)}" + "/hc/#{portal_slug}/#{portal_locale}#{portal_query_string(theme, is_plain_layout_enabled)}" else "/hc/#{portal_slug}/#{portal_locale}" end @@ -61,7 +68,7 @@ module PortalHelper is_plain_layout_enabled = params[:is_plain_layout_enabled] if is_plain_layout_enabled - "/hc/#{portal_slug}/#{category_locale}/categories/#{category_slug}#{theme_query_string(theme)}" + "/hc/#{portal_slug}/#{category_locale}/categories/#{category_slug}#{portal_query_string(theme, is_plain_layout_enabled)}" else "/hc/#{portal_slug}/#{category_locale}/categories/#{category_slug}" end @@ -69,7 +76,7 @@ module PortalHelper def generate_article_link(portal_slug, article_slug, theme, is_plain_layout_enabled) if is_plain_layout_enabled - "/hc/#{portal_slug}/articles/#{article_slug}#{theme_query_string(theme)}" + "/hc/#{portal_slug}/articles/#{article_slug}#{portal_query_string(theme, is_plain_layout_enabled)}" else "/hc/#{portal_slug}/articles/#{article_slug}" end diff --git a/app/javascript/entrypoints/portal.js b/app/javascript/entrypoints/portal.js index 42493615d..a1b58e390 100644 --- a/app/javascript/entrypoints/portal.js +++ b/app/javascript/entrypoints/portal.js @@ -1,9 +1,9 @@ import Rails from '@rails/ujs'; -import Turbolinks from 'turbolinks'; +import { Turbo } from '@hotwired/turbo-rails'; import '../portal/application.scss'; import { InitializationHelpers } from '../portal/portalHelpers'; Rails.start(); -Turbolinks.start(); +Turbo.start(); -document.addEventListener('turbolinks:load', InitializationHelpers.onLoad); +document.addEventListener('turbo:load', InitializationHelpers.onLoad); diff --git a/app/javascript/portal/application.scss b/app/javascript/portal/application.scss index 6d83f701a..00368d26a 100644 --- a/app/javascript/portal/application.scss +++ b/app/javascript/portal/application.scss @@ -55,6 +55,6 @@ body { } } -.turbolinks-progress-bar { +.turbo-progress-bar { background-color: var(--dynamic-portal-color); } diff --git a/app/javascript/portal/components/PublicArticleSearch.vue b/app/javascript/portal/components/PublicArticleSearch.vue index 086073fed..ebfe5b390 100644 --- a/app/javascript/portal/components/PublicArticleSearch.vue +++ b/app/javascript/portal/components/PublicArticleSearch.vue @@ -138,21 +138,40 @@ export default { this.isLoading = false; } }, + handleSubmit() { + const query = this.normalizedSearchTerm; + if (!query) return; + + const searchParams = new URLSearchParams({ query }); + const { theme, isPlainLayoutEnabled } = window.portalConfig; + + if (theme) searchParams.set('theme', theme); + if (isPlainLayoutEnabled === 'true') { + searchParams.set('show_plain_layout', 'true'); + } + + window.location.href = `/hc/${this.portalSlug}/${this.localeCode}/search?${searchParams.toString()}`; + }, }, };