Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add searchable field to page #2414

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/models/alchemy/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class Page < BaseRecord
:restricted,
:robot_index,
:robot_follow,
:searchable,
:sitemap,
:tag_list,
:title,
Expand Down
9 changes: 9 additions & 0 deletions app/views/alchemy/admin/pages/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,15 @@
<%= f.input :title,
input_html: {'data-alchemy-char-counter' => 60} %>

<% if Alchemy.enable_searchable %>
<div class="input check_boxes">
<label class="control-label"><%= Alchemy.t(:fulltext_search) %></label>
<div class="control_group">
<%= page_status_checkbox(@page, :searchable) %>
</div>
</div>
<% end %>

<div class="input check_boxes">
<label class="control-label"><%= Alchemy.t(:search_engines) %></label>
<div class="control_group">
Expand Down
2 changes: 2 additions & 0 deletions config/locales/alchemy.en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,7 @@ en:
saved_link: "Link saved."
search: "search"
search_engines: "Search engines"
fulltext_search: "Fulltext search"
select_element: "Select element"
seperate_tags_with_comma: "Seperate tags with comma"
show_element_content: "Show content of this element."
Expand Down Expand Up @@ -865,6 +866,7 @@ en:
page_layout: "Page type"
public: "public"
restricted: "restricted"
searchable: "show in search"
robot_follow: "robot may follow links"
robot_index: "allow robot to index"
sitemap: "visible in sitemap"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# frozen_string_literal: true

class AddSearchableToAlchemyPages < ActiveRecord::Migration[6.0]
def change
return if column_exists?(:alchemy_pages, :searchable)

add_column :alchemy_pages, :searchable, :boolean, default: true, null: false
end
end
13 changes: 13 additions & 0 deletions lib/alchemy.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,17 @@ def self.preview_sources=(sources)
def self.publish_targets
@_publish_targets ||= Set.new
end

# Enable full text search configuration
#
# It enables a searchable checkbox in the page form to toggle
# the searchable field. These information can used in a search
# plugin (e.g. https://github.com/AlchemyCMS/alchemy-pg_search).
#
# == Example
#
# # config/initializers/alchemy.rb
# Alchemy.enable_searchable = true
#
mattr_accessor :enable_searchable, default: false
end
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# frozen_string_literal: true

# This migration comes from alchemy (originally 20230123112425)
class AddSearchableToAlchemyPages < ActiveRecord::Migration[6.0]
def change
return if column_exists?(:alchemy_pages, :searchable)

add_column :alchemy_pages, :searchable, :boolean, default: true, null: false
end
end
3 changes: 2 additions & 1 deletion spec/dummy/db/schema.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.

ActiveRecord::Schema[7.0].define(version: 2023_01_22_210804) do
ActiveRecord::Schema[7.0].define(version: 2023_01_23_105660) do
create_table "alchemy_attachments", force: :cascade do |t|
t.string "name"
t.string "file_name"
Expand Down Expand Up @@ -172,6 +172,7 @@
t.datetime "legacy_public_on", precision: nil
t.datetime "legacy_public_until", precision: nil
t.datetime "locked_at", precision: nil
t.boolean "searchable", default: true, null: false
t.index ["creator_id"], name: "index_alchemy_pages_on_creator_id"
t.index ["language_id"], name: "index_alchemy_pages_on_language_id"
t.index ["locked_at", "locked_by"], name: "index_alchemy_pages_on_locked_at_and_locked_by"
Expand Down
27 changes: 27 additions & 0 deletions spec/features/admin/page_editing_feature_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,33 @@ class FooPreviewSource < Alchemy::Admin::PreviewUrl; end
expect(page).to_not have_selector('input[type="checkbox"]#page_sitemap')
end
end

context "enable_searchable" do
before do
Alchemy.enable_searchable = searchable
visit alchemy.configure_admin_page_path(a_page)
tvdeyen marked this conversation as resolved.
Show resolved Hide resolved
end

# reset default value
after { Alchemy.enable_searchable = false }

context "is enabled" do
let(:searchable) { true }

it "should show searchable checkbox" do
expect(page).to have_selector('input[type="checkbox"]#page_searchable')
end
end

context "is disabled" do
let(:searchable) { false }

it "should not show searchable checkbox" do
visit alchemy.configure_admin_page_path(a_page)
expect(page).to_not have_selector('input[type="checkbox"]#page_searchable')
end
end
end
end

context "when editing a global page" do
Expand Down