-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add bare-bones on-site settings editor
- Loading branch information
Showing
12 changed files
with
99 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# frozen_string_literal: true | ||
|
||
class ConfigController < ApplicationController | ||
def index | ||
end | ||
|
||
def show | ||
@definition = Sites.from_enum(params[:id]) | ||
end | ||
|
||
def modify | ||
custom_config = params.fetch(:config, {}).permit! | ||
custom_config[:scraper_request_rate_limit] = custom_config[:scraper_request_rate_limit].tr(",", ".").to_f if custom_config[:scraper_request_rate_limit] | ||
|
||
Config.write_custom_config(custom_config) | ||
Config.force_reload | ||
redirect_back fallback_location: config_index_path | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
<%= subnav_link_to "Listing", config_index_path %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<h1>General Settings</h1> | ||
|
||
<%= simple_form_for(:config, url: modify_config_index_path, method: :put) do |f| %> | ||
<%= f.input :app_name, input_html: { value: Config.app_name } %> | ||
<%= f.input :log_scraper_requests, as: :select, selected: Config.log_scraper_requests? %> | ||
<%= f.input :scraper_request_rate_limit, input_html: { value: Config.scraper_request_rate_limit } %> | ||
<%= f.input :time_zone, collection: ActiveSupport::TimeZone.all.map { |tz| [tz.to_s, tz.name] }, selected: Config.time_zone %> | ||
<%= f.submit %> | ||
<% end %> | ||
|
||
<% Sites.scraper_definitions.each do |definition| %> | ||
<div><%= link_to "#{definition.display_name} settings", config_path(definition.enum_value) %></div> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<h2>Settings for <%= @definition.display_name %></h2> | ||
<%= link_to @definition.homepage, @definition.homepage %><br> | ||
<%= simple_form_for(:config, url: modify_config_index_path, method: :put) do |f| %> | ||
<% @definition.all_config_keys.each do |key| %> | ||
<%= f.input key, label: key.to_s.delete_prefix("#{@definition.enum_value}_"), input_html: { value: Config.send(key) } %> | ||
<% end %> | ||
<%= f.input "#{@definition.enum_value}_disabled", as: :select, label: "disabled", selected: Config.send("#{@definition.enum_value}_disabled?").to_s %> | ||
<%= f.submit %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# frozen_string_literal: true | ||
|
||
require "test_helper" | ||
|
||
class ConfigControllerTest < ActionDispatch::IntegrationTest | ||
test "index renders" do | ||
get config_index_path | ||
assert_response :success | ||
end | ||
|
||
test "show renders" do | ||
get config_path("twitter") | ||
assert_response :success | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters