panda_cms 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.md +71 -0
- data/Rakefile +8 -0
- data/app/assets/builds/panda_cms.css +1 -0
- data/app/assets/config/panda_cms_manifest.js +1 -0
- data/app/assets/stylesheets/panda_cms/application.tailwind.css +61 -0
- data/app/builders/panda_cms/form_builder.rb +118 -0
- data/app/components/panda_cms/admin/button_component.rb +65 -0
- data/app/components/panda_cms/admin/container_component.html.erb +13 -0
- data/app/components/panda_cms/admin/container_component.rb +11 -0
- data/app/components/panda_cms/admin/flash_message_component.html.erb +30 -0
- data/app/components/panda_cms/admin/flash_message_component.rb +44 -0
- data/app/components/panda_cms/admin/heading_component.rb +43 -0
- data/app/components/panda_cms/admin/panel_component.html.erb +7 -0
- data/app/components/panda_cms/admin/panel_component.rb +11 -0
- data/app/components/panda_cms/admin/slideover_component.html.erb +9 -0
- data/app/components/panda_cms/admin/slideover_component.rb +13 -0
- data/app/components/panda_cms/admin/statistics_component.html.erb +4 -0
- data/app/components/panda_cms/admin/statistics_component.rb +15 -0
- data/app/components/panda_cms/admin/tab_bar_component.html.erb +35 -0
- data/app/components/panda_cms/admin/tab_bar_component.rb +13 -0
- data/app/components/panda_cms/admin/table_component.html.erb +21 -0
- data/app/components/panda_cms/admin/table_component.rb +43 -0
- data/app/components/panda_cms/admin/tag_component.rb +33 -0
- data/app/components/panda_cms/admin/user_activity_component.html.erb +5 -0
- data/app/components/panda_cms/admin/user_activity_component.rb +19 -0
- data/app/components/panda_cms/admin/user_display_component.html.erb +11 -0
- data/app/components/panda_cms/admin/user_display_component.rb +19 -0
- data/app/components/panda_cms/grid_component.html.erb +6 -0
- data/app/components/panda_cms/grid_component.rb +13 -0
- data/app/components/panda_cms/menu_component.html.erb +3 -0
- data/app/components/panda_cms/menu_component.rb +18 -0
- data/app/components/panda_cms/page_menu_component.html.erb +24 -0
- data/app/components/panda_cms/page_menu_component.rb +24 -0
- data/app/components/panda_cms/rich_text_component.html.erb +40 -0
- data/app/components/panda_cms/rich_text_component.rb +35 -0
- data/app/components/panda_cms/text_component.rb +67 -0
- data/app/constraints/panda_cms/admin_constraint.rb +16 -0
- data/app/controllers/panda_cms/admin/block_contents_controller.rb +44 -0
- data/app/controllers/panda_cms/admin/dashboard_controller.rb +31 -0
- data/app/controllers/panda_cms/admin/files_controller.rb +19 -0
- data/app/controllers/panda_cms/admin/forms_controller.rb +51 -0
- data/app/controllers/panda_cms/admin/menus_controller.rb +81 -0
- data/app/controllers/panda_cms/admin/pages_controller.rb +88 -0
- data/app/controllers/panda_cms/admin/posts_controller.rb +34 -0
- data/app/controllers/panda_cms/admin/sessions_controller.rb +83 -0
- data/app/controllers/panda_cms/admin/settings/bulk_editor_controller.rb +35 -0
- data/app/controllers/panda_cms/admin/settings_controller.rb +18 -0
- data/app/controllers/panda_cms/application_controller.rb +55 -0
- data/app/controllers/panda_cms/errors_controller.rb +31 -0
- data/app/controllers/panda_cms/form_submissions_controller.rb +21 -0
- data/app/controllers/panda_cms/pages_controller.rb +56 -0
- data/app/controllers/panda_cms/posts_controller.rb +17 -0
- data/app/helpers/panda_cms/admin/files_helper.rb +4 -0
- data/app/helpers/panda_cms/admin/pages_helper.rb +4 -0
- data/app/helpers/panda_cms/application_helper.rb +96 -0
- data/app/helpers/panda_cms/pages_helper.rb +4 -0
- data/app/helpers/panda_cms/theme_helper.rb +16 -0
- data/app/javascript/base.js +37 -0
- data/app/javascript/controllers/menu_controller.js +19 -0
- data/app/javascript/controllers/text_controller.js +78 -0
- data/app/javascript/controllers/text_field_update_controller.js +23 -0
- data/app/javascript/vendor/stimulus-components-rails-nested-form.js +2 -0
- data/app/javascript/vendor/tailwindcss-stimulus-components.js +2 -0
- data/app/jobs/panda_cms/application_job.rb +4 -0
- data/app/jobs/panda_cms/record_visit_job.rb +29 -0
- data/app/lib/panda_cms/bulk_editor.rb +169 -0
- data/app/lib/panda_cms/demo_site_generator.rb +70 -0
- data/app/lib/panda_cms/slug.rb +22 -0
- data/app/mailers/panda_cms/application_mailer.rb +6 -0
- data/app/mailers/panda_cms/form_mailer.rb +19 -0
- data/app/models/panda_cms/application_record.rb +5 -0
- data/app/models/panda_cms/block.rb +32 -0
- data/app/models/panda_cms/block_content.rb +16 -0
- data/app/models/panda_cms/block_content_version.rb +6 -0
- data/app/models/panda_cms/breadcrumb.rb +10 -0
- data/app/models/panda_cms/current.rb +15 -0
- data/app/models/panda_cms/form.rb +7 -0
- data/app/models/panda_cms/form_submission.rb +5 -0
- data/app/models/panda_cms/menu.rb +50 -0
- data/app/models/panda_cms/menu_item.rb +56 -0
- data/app/models/panda_cms/page.rb +81 -0
- data/app/models/panda_cms/page_version.rb +6 -0
- data/app/models/panda_cms/post.rb +25 -0
- data/app/models/panda_cms/post_version.rb +6 -0
- data/app/models/panda_cms/redirect.rb +9 -0
- data/app/models/panda_cms/template.rb +117 -0
- data/app/models/panda_cms/template_version.rb +6 -0
- data/app/models/panda_cms/user.rb +15 -0
- data/app/models/panda_cms/version.rb +6 -0
- data/app/models/panda_cms/visit.rb +7 -0
- data/app/views/layouts/panda_cms/application.html.erb +44 -0
- data/app/views/layouts/panda_cms/public.html.erb +3 -0
- data/app/views/panda_cms/admin/dashboard/show.html.erb +11 -0
- data/app/views/panda_cms/admin/files/index.html.erb +124 -0
- data/app/views/panda_cms/admin/files/show.html.erb +2 -0
- data/app/views/panda_cms/admin/forms/edit.html.erb +0 -0
- data/app/views/panda_cms/admin/forms/index.html.erb +13 -0
- data/app/views/panda_cms/admin/forms/new.html.erb +16 -0
- data/app/views/panda_cms/admin/forms/show.html.erb +35 -0
- data/app/views/panda_cms/admin/menus/_form.html.erb +21 -0
- data/app/views/panda_cms/admin/menus/_menu_item_fields.html.erb +7 -0
- data/app/views/panda_cms/admin/menus/edit.html.erb +58 -0
- data/app/views/panda_cms/admin/menus/index.html.erb +10 -0
- data/app/views/panda_cms/admin/menus/new.html.erb +5 -0
- data/app/views/panda_cms/admin/pages/edit.html.erb +26 -0
- data/app/views/panda_cms/admin/pages/index.html.erb +16 -0
- data/app/views/panda_cms/admin/pages/new.html.erb +16 -0
- data/app/views/panda_cms/admin/pages/show.html.erb +1 -0
- data/app/views/panda_cms/admin/posts/index.html.erb +16 -0
- data/app/views/panda_cms/admin/sessions/new.html.erb +18 -0
- data/app/views/panda_cms/admin/settings/bulk_editor/new.html.erb +68 -0
- data/app/views/panda_cms/admin/settings/index.html.erb +19 -0
- data/app/views/panda_cms/admin/shared/_breadcrumbs.html.erb +28 -0
- data/app/views/panda_cms/admin/shared/_flash.html.erb +5 -0
- data/app/views/panda_cms/admin/shared/_sidebar.html.erb +45 -0
- data/app/views/panda_cms/form_mailer/notification_email.html.erb +11 -0
- data/app/views/panda_cms/shared/_favicons.html.erb +9 -0
- data/app/views/panda_cms/shared/_footer.html.erb +2 -0
- data/app/views/panda_cms/shared/_header.html.erb +15 -0
- data/config/importmap.rb +9 -0
- data/config/initializers/panda_cms/form_errors.rb +38 -0
- data/config/initializers/panda_cms/healthcheck_log_silencer.rb +11 -0
- data/config/initializers/panda_cms.rb +52 -0
- data/config/locales/en.yml +29 -0
- data/config/routes.rb +43 -0
- data/config/tailwind.config.js +35 -0
- data/config/tailwind.embed.config.js +20 -0
- data/db/migrate/20240205223709_create_panda_cms_pages.rb +9 -0
- data/db/migrate/20240219213327_create_panda_cms_page_versions.rb +14 -0
- data/db/migrate/20240303002805_create_panda_cms_templates.rb +11 -0
- data/db/migrate/20240303003434_create_panda_cms_template_versions.rb +14 -0
- data/db/migrate/20240303022441_create_panda_cms_blocks.rb +13 -0
- data/db/migrate/20240303024256_create_panda_cms_block_contents.rb +10 -0
- data/db/migrate/20240303024746_create_panda_cms_block_content_versions.rb +14 -0
- data/db/migrate/20240303233238_add_panda_cms_menu_table.rb +10 -0
- data/db/migrate/20240303234724_add_panda_cms_menu_item_table.rb +12 -0
- data/db/migrate/20240304134343_add_parent_id_to_panda_cms_pages.rb +5 -0
- data/db/migrate/20240315125421_add_nested_sets_to_panda_cms_pages.rb +16 -0
- data/db/migrate/20240316212822_add_kind_to_panda_cms_menus.rb +6 -0
- data/db/migrate/20240316221425_add_start_page_to_panda_cms_menus.rb +5 -0
- data/db/migrate/20240316230706_add_nested_to_panda_cms_menu_items.rb +24 -0
- data/db/migrate/20240317010532_create_panda_cms_users.rb +12 -0
- data/db/migrate/20240317161534_add_max_uses_to_panda_cms_template.rb +7 -0
- data/db/migrate/20240317163053_reset_counter_cache_on_panda_cms_template.rb +5 -0
- data/db/migrate/20240317214827_create_panda_cms_redirects.rb +14 -0
- data/db/migrate/20240317230622_create_panda_cms_visits.rb +13 -0
- data/db/migrate/20240324205703_create_active_storage_tables.active_storage.rb +58 -0
- data/db/migrate/20240408084718_default_panda_cms_users_admin_to_false.rb +5 -0
- data/db/migrate/20240701225422_add_service_name_to_active_storage_blobs.active_storage.rb +22 -0
- data/db/migrate/20240701225423_create_active_storage_variant_records.active_storage.rb +28 -0
- data/db/migrate/20240701225424_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb +8 -0
- data/db/migrate/20240804110225_add_status_to_panda_cms_pages.rb +7 -0
- data/db/migrate/20240804235210_create_panda_cms_forms.rb +11 -0
- data/db/migrate/20240805013612_create_panda_cms_form_submissions.rb +9 -0
- data/db/migrate/20240805121123_create_panda_cms_posts.rb +27 -0
- data/db/migrate/20240805123104_create_panda_cms_post_versions.rb +14 -0
- data/db/migrate/20240806112735_fix_panda_cms_visits_column_names.rb +13 -0
- data/db/migrate/20240806204412_add_completion_path_to_panda_cms_forms.rb +5 -0
- data/db/migrate/20240820081917_change_form_submissions_to_submission_count.rb +5 -0
- data/db/seeds.rb +4 -0
- data/lib/generators/panda_cms/install_generator.rb +24 -0
- data/lib/panda_cms/engine.rb +167 -0
- data/lib/panda_cms/exceptions_app.rb +24 -0
- data/lib/panda_cms/version.rb +3 -0
- data/lib/panda_cms.rb +15 -0
- data/lib/tasks/panda_cms.rake +92 -0
- data/lib/templates/erb/scaffold/_form.html.erb.tt +43 -0
- data/lib/templates/erb/scaffold/edit.html.erb.tt +8 -0
- data/lib/templates/erb/scaffold/index.html.erb.tt +14 -0
- data/lib/templates/erb/scaffold/new.html.erb.tt +7 -0
- data/lib/templates/erb/scaffold/partial.html.erb.tt +22 -0
- data/lib/templates/erb/scaffold/show.html.erb.tt +15 -0
- data/public/panda-cms-assets/favicons/android-chrome-192x192.png +0 -0
- data/public/panda-cms-assets/favicons/android-chrome-512x512.png +0 -0
- data/public/panda-cms-assets/favicons/apple-touch-icon.png +0 -0
- data/public/panda-cms-assets/favicons/browserconfig.xml +9 -0
- data/public/panda-cms-assets/favicons/favicon-16x16.png +0 -0
- data/public/panda-cms-assets/favicons/favicon-32x32.png +0 -0
- data/public/panda-cms-assets/favicons/favicon.ico +0 -0
- data/public/panda-cms-assets/favicons/mstile-150x150.png +0 -0
- data/public/panda-cms-assets/favicons/safari-pinned-tab.svg +61 -0
- data/public/panda-cms-assets/favicons/site.webmanifest +14 -0
- data/public/panda-cms-assets/javascripts/base.js +37 -0
- data/public/panda-cms-assets/javascripts/controllers/menu_controller.js +19 -0
- data/public/panda-cms-assets/javascripts/controllers/text_field_update_controller.js +23 -0
- data/public/panda-cms-assets/javascripts/embed/editable.js +308 -0
- data/public/panda-cms-assets/javascripts/vendor/stimulus-components-rails-nested-form.js +2 -0
- data/public/panda-cms-assets/javascripts/vendor/stimulus-loading.js +113 -0
- data/public/panda-cms-assets/javascripts/vendor/tailwindcss-stimulus-components.js +2 -0
- data/public/panda-cms-assets/panda-logo-screenprint.png +0 -0
- data/public/panda-cms-assets/panda-nav.png +0 -0
- metadata +1034 -0
@@ -0,0 +1,88 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class PagesController < ApplicationController
|
6
|
+
before_action :set_initial_breadcrumb, only: %i[index edit new create update]
|
7
|
+
before_action :set_paper_trail_whodunnit, only: %i[create update]
|
8
|
+
before_action :authenticate_admin_user!
|
9
|
+
|
10
|
+
# Lists all pages which can be managed by the administrator
|
11
|
+
# @type GET
|
12
|
+
# @return ActiveRecord::Collection A list of all pages
|
13
|
+
def index
|
14
|
+
homepage = PandaCms::Page.find_by(path: "/")
|
15
|
+
render :index, locals: {root_page: homepage}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Loads the add page form
|
19
|
+
# @type GET
|
20
|
+
def new
|
21
|
+
locals = setup_new_page_form(page: PandaCms::Page.new)
|
22
|
+
render :new, locals: locals
|
23
|
+
end
|
24
|
+
|
25
|
+
# Loads the page editor
|
26
|
+
# @type GET
|
27
|
+
def edit
|
28
|
+
add_breadcrumb page.title, edit_admin_page_path(page)
|
29
|
+
render :edit, locals: {page: page, template: page.template}
|
30
|
+
end
|
31
|
+
|
32
|
+
# POST /admin/pages
|
33
|
+
def create
|
34
|
+
page = PandaCms::Page.new(page_params)
|
35
|
+
if page.save
|
36
|
+
page.update(path: page.parent.path + page.path) unless page.parent.path == "/"
|
37
|
+
redirect_to edit_admin_page_path(page), notice: "The page was successfully created."
|
38
|
+
else
|
39
|
+
flash[:error] = "There was an error creating the page."
|
40
|
+
locals = setup_new_page_form(page: page)
|
41
|
+
render :new, locals: locals, status: :unprocessable_entity
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# @type PATCH/PUT
|
46
|
+
# @return
|
47
|
+
def update
|
48
|
+
if page.update(page_params)
|
49
|
+
redirect_to edit_admin_page_path(page),
|
50
|
+
status: :see_other,
|
51
|
+
flash: {success: "This page was successfully updated!"}
|
52
|
+
else
|
53
|
+
flash[:error] = "There was an error updating the page."
|
54
|
+
render :edit, status: :unprocessable_entity
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
private
|
59
|
+
|
60
|
+
# Get the page from the ID
|
61
|
+
# @type private
|
62
|
+
# @return PandaCms::Page
|
63
|
+
def page
|
64
|
+
@page ||= if params[:id]
|
65
|
+
PandaCms::Page.find(params[:id])
|
66
|
+
else
|
67
|
+
PandaCms::Page.new
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
def set_initial_breadcrumb
|
72
|
+
add_breadcrumb "Pages", admin_pages_path
|
73
|
+
end
|
74
|
+
|
75
|
+
def setup_new_page_form(page:)
|
76
|
+
add_breadcrumb "Add Page", new_admin_page_path
|
77
|
+
{page: page}
|
78
|
+
end
|
79
|
+
|
80
|
+
# Only allow a list of trusted parameters through.
|
81
|
+
# @type private
|
82
|
+
# @return ActionController::StrongParameters
|
83
|
+
def page_params
|
84
|
+
params.require(:page).permit(:title, :path, :panda_cms_template_id, :parent_id, :status)
|
85
|
+
end
|
86
|
+
end
|
87
|
+
end
|
88
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class PostsController < ApplicationController
|
6
|
+
before_action :set_initial_breadcrumb, only: %i[index]
|
7
|
+
# before_action :set_paper_trail_whodunnit, only: %i[create update]
|
8
|
+
before_action :authenticate_admin_user!
|
9
|
+
|
10
|
+
# Get all posts
|
11
|
+
# @type GET
|
12
|
+
# @return ActiveRecord::Collection A list of all posts
|
13
|
+
def index
|
14
|
+
posts = PandaCms::Post.order(:published_at)
|
15
|
+
render :index, locals: {posts: posts}
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def set_initial_breadcrumb
|
21
|
+
add_breadcrumb "Posts", admin_posts_path
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
# Only allow a list of trusted parameters through
|
27
|
+
# @type private
|
28
|
+
# @return ActionController::StrongParameters
|
29
|
+
def form_params
|
30
|
+
params.require(:post).permit(:title, :slug, :content, :published_at)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class SessionsController < ApplicationController
|
6
|
+
layout "panda_cms/public"
|
7
|
+
|
8
|
+
def new
|
9
|
+
@providers = PandaCms.authentication.select { |_, v| v[:enabled] && !v[:hidden] }.keys
|
10
|
+
end
|
11
|
+
|
12
|
+
def create
|
13
|
+
user_info = request.env.dig("omniauth.auth", "info")
|
14
|
+
provider = params[:provider].to_sym
|
15
|
+
|
16
|
+
unless PandaCms.authentication.dig(provider, :enabled)
|
17
|
+
Rails.logger.error "Authentication provider '#{provider}' is not enabled"
|
18
|
+
redirect_to admin_login_path, flash: {error: t("panda_cms.admin.sessions.create.error")}
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
user = PandaCms::User.find_by(email: user_info["email"])
|
23
|
+
|
24
|
+
if !user && PandaCms.authentication.dig(provider, :create_account_on_first_login)
|
25
|
+
create_as_admin = PandaCms.authentication.dig(provider, :create_as_admin)
|
26
|
+
|
27
|
+
# Always create the first user as admin, regardless of what our settings look like
|
28
|
+
# else we can't ever really login. :)
|
29
|
+
create_as_admin = true if !create_as_admin && PandaCms::User.count.zero?
|
30
|
+
|
31
|
+
if user_info["first_name"] && user_info["last_name"]
|
32
|
+
firstname = user_info["first_name"]
|
33
|
+
lastname = user_info["last_name"]
|
34
|
+
elsif user_info["name"]
|
35
|
+
firstname, lastname = user_info["name"].split(" ", 2)
|
36
|
+
end
|
37
|
+
|
38
|
+
user = User.find_or_create_by(
|
39
|
+
email: user_info["email"]
|
40
|
+
) do |u|
|
41
|
+
u.firstname = firstname
|
42
|
+
u.lastname = lastname
|
43
|
+
u.admin = create_as_admin
|
44
|
+
u.image_url = user_info["image"]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
if user.nil? || !user.admin?
|
49
|
+
# User can't be found with this email address or can't login
|
50
|
+
Rails.logger.info "User #{user.id} attempted admin login, is not admin." if user && !user.admin
|
51
|
+
redirect_to admin_login_path, flash: {error: t("panda_cms.admin.sessions.create.error")}
|
52
|
+
return
|
53
|
+
end
|
54
|
+
|
55
|
+
session[:user_id] = user.id
|
56
|
+
PandaCms::Current.user = user
|
57
|
+
|
58
|
+
redirect_path = request.env["omniauth.origin"] || admin_dashboard_path
|
59
|
+
redirect_to redirect_path, flash: {success: t("panda_cms.admin.sessions.create.success")}
|
60
|
+
rescue ::OmniAuth::Strategies::OAuth2::CallbackError => e
|
61
|
+
Rails.logger.error "OAuth2 login callback error: #{e.message}"
|
62
|
+
redirect_to admin_login_path, flash: {error: t("panda_cms.admin.sessions.create.error")}
|
63
|
+
rescue ::OAuth2::Error => e
|
64
|
+
Rails.logger.error "OAuth2 login error: #{e.message}"
|
65
|
+
redirect_to admin_login_path, flash: {error: t("panda_cms.admin.sessions.create.error")}
|
66
|
+
rescue => e
|
67
|
+
Rails.logger.error "Unknown login error: #{e.message}"
|
68
|
+
redirect_to admin_login_path, flash: {error: t("panda_cms.admin.sessions.create.error")}
|
69
|
+
end
|
70
|
+
|
71
|
+
def failure
|
72
|
+
Rails.logger.error "Login failure: #{params[:message]} from #{params[:origin]} using #{params[:strategy]}"
|
73
|
+
redirect_to admin_login_path, flash: {error: t("panda_cms.admin.sessions.create.error")}
|
74
|
+
end
|
75
|
+
|
76
|
+
def destroy
|
77
|
+
PandaCms::Current.user = nil
|
78
|
+
session[:user_id] = nil
|
79
|
+
redirect_to admin_login_path, flash: {success: t("panda_cms.admin.sessions.destroy.success")}
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class Admin::Settings::BulkEditorController < ApplicationController
|
3
|
+
before_action :set_initial_breadcrumb, only: %i[new]
|
4
|
+
|
5
|
+
def new
|
6
|
+
@json_data = BulkEditor.export
|
7
|
+
end
|
8
|
+
|
9
|
+
def create
|
10
|
+
begin
|
11
|
+
debug_output = BulkEditor.import(params[:site_content])
|
12
|
+
rescue JSON::ParserError
|
13
|
+
redirect_to admin_settings_bulk_editor_path, flash: {error: "Error parsing content; are you sure this update is valid? Reverting..."}
|
14
|
+
return
|
15
|
+
end
|
16
|
+
|
17
|
+
# Grab the latest content back so it's all formatted properly
|
18
|
+
@json_data = BulkEditor.export
|
19
|
+
|
20
|
+
if debug_output[:error].empty? && debug_output[:warning].empty? && debug_output[:success].empty?
|
21
|
+
redirect_to admin_settings_bulk_editor_path, flash: {success: "No changes were found!"}
|
22
|
+
else
|
23
|
+
@debug = debug_output
|
24
|
+
render :new, flash: {warning: "Please review the output below for more information."}
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
|
30
|
+
def set_initial_breadcrumb
|
31
|
+
add_breadcrumb "Settings", admin_settings_path
|
32
|
+
add_breadcrumb "Bulk Editor", "#"
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class Admin::SettingsController < ApplicationController
|
3
|
+
before_action :set_initial_breadcrumb, only: %i[index show]
|
4
|
+
before_action :authenticate_admin_user!
|
5
|
+
|
6
|
+
def index
|
7
|
+
end
|
8
|
+
|
9
|
+
def show
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def set_initial_breadcrumb
|
15
|
+
add_breadcrumb "Settings", admin_settings_path
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class ApplicationController < ::ActionController::Base
|
3
|
+
include ApplicationHelper
|
4
|
+
include ::ApplicationHelper
|
5
|
+
|
6
|
+
protect_from_forgery with: :exception
|
7
|
+
|
8
|
+
# Add flash types for improved alert support with Tailwind
|
9
|
+
add_flash_types :success, :warning, :error, :info
|
10
|
+
|
11
|
+
before_action :set_current_request_details
|
12
|
+
|
13
|
+
helper_method :breadcrumbs
|
14
|
+
helper_method :current_user
|
15
|
+
helper_method :user_signed_in?
|
16
|
+
|
17
|
+
def breadcrumbs
|
18
|
+
@breadcrumbs ||= []
|
19
|
+
end
|
20
|
+
|
21
|
+
def add_breadcrumb(name, path = nil)
|
22
|
+
breadcrumbs << Breadcrumb.new(name, path)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Set the current request details
|
26
|
+
# @return [void]
|
27
|
+
def set_current_request_details
|
28
|
+
PandaCms::Current.request_id = request.uuid
|
29
|
+
PandaCms::Current.user_agent = request.user_agent
|
30
|
+
PandaCms::Current.ip_address = request.ip
|
31
|
+
PandaCms::Current.root = request.base_url
|
32
|
+
PandaCms::Current.page = nil
|
33
|
+
PandaCms::Current.user ||= User.find_by(id: session[:user_id]) if session[:user_id]
|
34
|
+
|
35
|
+
PandaCms.url ||= PandaCms::Current.root
|
36
|
+
end
|
37
|
+
|
38
|
+
def authenticate_user!
|
39
|
+
redirect_to root_path, flash: {error: "Please login to view this!"} unless user_signed_in?
|
40
|
+
end
|
41
|
+
|
42
|
+
def authenticate_admin_user!
|
43
|
+
redirect_to root_path, flash: {error: "Please login to view this!"} unless user_signed_in? && current_user.admin?
|
44
|
+
end
|
45
|
+
|
46
|
+
# Required for paper_trail and seems as good as convention these days
|
47
|
+
def current_user
|
48
|
+
PandaCms::Current.user
|
49
|
+
end
|
50
|
+
|
51
|
+
def user_signed_in?
|
52
|
+
!!PandaCms::Current.user
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class ErrorsController < ApplicationController
|
3
|
+
layout "error"
|
4
|
+
|
5
|
+
def show
|
6
|
+
exception = request.env["action_dispatch.exception"]
|
7
|
+
status_code = exception.try(:status_code) || ActionDispatch::ExceptionWrapper.new(request.env, exception).status_code
|
8
|
+
|
9
|
+
render view_for_code(status_code), status: status_code
|
10
|
+
end
|
11
|
+
|
12
|
+
def error_503
|
13
|
+
render view_for_code(503), status: 503
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def view_for_code(code)
|
19
|
+
supported_error_codes.fetch(code) { "404" }
|
20
|
+
end
|
21
|
+
|
22
|
+
def supported_error_codes
|
23
|
+
{
|
24
|
+
403 => "403",
|
25
|
+
404 => "404",
|
26
|
+
500 => "500",
|
27
|
+
503 => "503"
|
28
|
+
}
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class FormSubmissionsController < ApplicationController
|
3
|
+
def create
|
4
|
+
vars = params.except(:authenticity_token, :controller, :action, :id)
|
5
|
+
|
6
|
+
form = PandaCms::Form.find(params[:id])
|
7
|
+
form_submission = PandaCms::FormSubmission.create(form_id: params[:id], data: vars.to_unsafe_h)
|
8
|
+
form.update(submission_count: form.submission_count + 1)
|
9
|
+
|
10
|
+
PandaCms::FormMailer.notification_email(form: form, form_submission: form_submission).deliver_now
|
11
|
+
|
12
|
+
if (completion_path = form&.completion_path)
|
13
|
+
redirect_to completion_path
|
14
|
+
else
|
15
|
+
# TODO: This isn't a great fallback, we should do something nice here...
|
16
|
+
# Perhaps a simple JS alert when sent?
|
17
|
+
redirect_to "/"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class PagesController < ApplicationController
|
3
|
+
include ActionView::Helpers::TagHelper
|
4
|
+
|
5
|
+
def root
|
6
|
+
params[:path] = ""
|
7
|
+
show
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
if PandaCms.require_login_to_view && !user_signed_in?
|
12
|
+
redirect_to panda_cms_maintenance_path and return
|
13
|
+
end
|
14
|
+
|
15
|
+
path_to_find = "/" + params[:path].to_s
|
16
|
+
page = Page.find_by(path: path_to_find) || Page.find_by(path: "/404")
|
17
|
+
PandaCms::Current.page = page
|
18
|
+
|
19
|
+
if page
|
20
|
+
globals = {
|
21
|
+
page: page,
|
22
|
+
title: page.title
|
23
|
+
}
|
24
|
+
|
25
|
+
unless ignore_visit?
|
26
|
+
RecordVisitJob.perform_later(
|
27
|
+
url: request.url,
|
28
|
+
user_agent: request.user_agent,
|
29
|
+
referrer: request.referrer,
|
30
|
+
ip_address: request.remote_ip,
|
31
|
+
page_id: page.id,
|
32
|
+
current_user_id: current_user&.id,
|
33
|
+
params: params.to_unsafe_h.except(:controller, :action, :path),
|
34
|
+
visited_at: Time.zone.now
|
35
|
+
)
|
36
|
+
end
|
37
|
+
|
38
|
+
render inline: "", assigns: globals, status: :ok, layout: page.template.file_path
|
39
|
+
else
|
40
|
+
# This works for now, but we may want to override in future (e.g. custom 404s)
|
41
|
+
render file: "#{Rails.root}/public/404.html", layout: false, status: :not_found
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def ignore_visit?
|
48
|
+
# Ignore visits from bots (TODO: make this configurable)
|
49
|
+
# return true if request.user_agent =~ /bot/i
|
50
|
+
# Ignore visits from Honeybadger
|
51
|
+
return true if request.headers.to_h.key? "Honeybadger-Token"
|
52
|
+
|
53
|
+
false
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class PostsController < ApplicationController
|
3
|
+
def index
|
4
|
+
end
|
5
|
+
|
6
|
+
def show
|
7
|
+
post = PandaCms::Post.find_by(slug: params[:slug])
|
8
|
+
# TODO: Make this much nicer in future
|
9
|
+
globals = {
|
10
|
+
post: post,
|
11
|
+
title: ""
|
12
|
+
}
|
13
|
+
|
14
|
+
render inline: "", assigns: globals, status: :ok, layout: "layouts/post"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
module PandaCms
|
2
|
+
module ApplicationHelper
|
3
|
+
def title_tag
|
4
|
+
PandaCms.title
|
5
|
+
end
|
6
|
+
|
7
|
+
def panda_cms_editor
|
8
|
+
if Current.user&.admin
|
9
|
+
content_tag(:a, "🐼", href: edit_admin_page_url(Current.page), class: "text-3xl inline absolute right-2 top-2")
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def active_link?(path, match: :starts_with)
|
14
|
+
if match == :starts_with
|
15
|
+
return request.path.starts_with?(path)
|
16
|
+
elsif match == :exact
|
17
|
+
return (request.path == path)
|
18
|
+
end
|
19
|
+
|
20
|
+
false
|
21
|
+
end
|
22
|
+
|
23
|
+
def block_link_to(name = nil, options = nil, html_options = {}, &)
|
24
|
+
html_options[:class] = "block-link"
|
25
|
+
link_to(name, options, html_options, &)
|
26
|
+
end
|
27
|
+
|
28
|
+
def panda_cms_form_with(**options, &)
|
29
|
+
options[:builder] = PandaCms::FormBuilder
|
30
|
+
options[:class] ||= ""
|
31
|
+
form_with(**options, &)
|
32
|
+
end
|
33
|
+
|
34
|
+
def nav_class(mode)
|
35
|
+
if mode == "mobile"
|
36
|
+
"-mx-3 block rounded-lg px-3 py-2 font-semibold leading-6 text-white hover:text-white hover:underline focus:underline"
|
37
|
+
else
|
38
|
+
"font-semibold leading-6 text-white hover:text-white hover:underline focus:underline"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def selected_nav_highlight_colour_classes(request)
|
43
|
+
"bg-mid text-white relative flex transition-all py-3 px-2 mb-2 rounded-md group flex gap-x-3 rounded-md text-base leading-6 font-normal "
|
44
|
+
end
|
45
|
+
|
46
|
+
def nav_highlight_colour_classes(request)
|
47
|
+
"text-white hover:bg-mid/60 transition-all group flex gap-x-3 py-3 px-2 mb-2 rounded-md text-base leading-6 font-normal "
|
48
|
+
end
|
49
|
+
|
50
|
+
def table_indent(item_with_level_attribute)
|
51
|
+
case item_with_level_attribute.level
|
52
|
+
when 0
|
53
|
+
"ml-0"
|
54
|
+
when 1
|
55
|
+
"ml-4"
|
56
|
+
when 2
|
57
|
+
"ml-8"
|
58
|
+
when 3
|
59
|
+
"ml-12"
|
60
|
+
when 4
|
61
|
+
"ml-16"
|
62
|
+
when 5
|
63
|
+
"ml-20"
|
64
|
+
when 6
|
65
|
+
"ml-24"
|
66
|
+
when 7
|
67
|
+
"ml-28"
|
68
|
+
when 8
|
69
|
+
"ml-32"
|
70
|
+
when 9
|
71
|
+
"ml-36"
|
72
|
+
when 10
|
73
|
+
"ml-40" # We can go to 72...
|
74
|
+
else
|
75
|
+
"ml-48"
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
def menu_indent(item_with_level_attribute)
|
80
|
+
case item_with_level_attribute.level
|
81
|
+
when 0
|
82
|
+
"pl-0"
|
83
|
+
when 1
|
84
|
+
"pl-4"
|
85
|
+
when 2
|
86
|
+
"pl-8"
|
87
|
+
when 3
|
88
|
+
"pl-12"
|
89
|
+
when 4
|
90
|
+
"pl-16"
|
91
|
+
else
|
92
|
+
"pl-20"
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PandaCms
|
2
|
+
module ThemeHelper
|
3
|
+
# TODO: Move these into one method?
|
4
|
+
def h1(text, icon: "", additional_styles: "")
|
5
|
+
render HeadingComponent.new(text: text, level: 1, icon: icon, additional_styles: additional_styles)
|
6
|
+
end
|
7
|
+
|
8
|
+
def h2(text, icon: "", additional_styles: "")
|
9
|
+
render HeadingComponent.new(text: text, level: 2, icon: icon, additional_styles: additional_styles)
|
10
|
+
end
|
11
|
+
|
12
|
+
def h3(text, icon: "", additional_styles: "")
|
13
|
+
render HeadingComponent.new(text: text, level: 3, icon: icon, additional_styles: additional_styles)
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
import { Application as PandaCmsApplication } from "@hotwired/stimulus";
|
2
|
+
|
3
|
+
const panda_cms = PandaCmsApplication.start();
|
4
|
+
|
5
|
+
// Configure Stimulus development experience
|
6
|
+
panda_cms.debug = location.hostname === "localhost";
|
7
|
+
window.pandaStimulus = panda_cms;
|
8
|
+
|
9
|
+
export { panda_cms };
|
10
|
+
|
11
|
+
// Eager load all controllers defined in the import map under controllers/**/*_controller
|
12
|
+
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading";
|
13
|
+
eagerLoadControllersFrom("panda_cms/controllers", panda_cms);
|
14
|
+
|
15
|
+
import {
|
16
|
+
Alert,
|
17
|
+
Autosave,
|
18
|
+
ColorPreview,
|
19
|
+
Dropdown,
|
20
|
+
Modal,
|
21
|
+
Tabs,
|
22
|
+
Popover,
|
23
|
+
Toggle,
|
24
|
+
Slideover,
|
25
|
+
} from "panda_cms/vendor/tailwindcss-stimulus-components";
|
26
|
+
panda_cms.register("alert", Alert);
|
27
|
+
panda_cms.register("autosave", Autosave);
|
28
|
+
panda_cms.register("color-preview", ColorPreview);
|
29
|
+
panda_cms.register("dropdown", Dropdown);
|
30
|
+
panda_cms.register("modal", Modal);
|
31
|
+
panda_cms.register("popover", Popover);
|
32
|
+
panda_cms.register("slideover", Slideover);
|
33
|
+
panda_cms.register("tabs", Tabs);
|
34
|
+
panda_cms.register("toggle", Toggle);
|
35
|
+
|
36
|
+
import RailsNestedForm from "panda_cms/vendor/stimulus-components-rails-nested-form";
|
37
|
+
panda_cms.register("nested-form", RailsNestedForm);
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import { Controller as PandaCmsController } from "@hotwired/stimulus"
|
2
|
+
|
3
|
+
export default class extends PandaCmsController {
|
4
|
+
static targets = ["pandaCmsMenu"]
|
5
|
+
static values = {
|
6
|
+
open: { type: Boolean, default: false }
|
7
|
+
}
|
8
|
+
|
9
|
+
toggle(event) {
|
10
|
+
this.openValue = !this.openValue
|
11
|
+
this.animate()
|
12
|
+
}
|
13
|
+
|
14
|
+
animate() {
|
15
|
+
this.toggleableTargets.forEach(target => {
|
16
|
+
transition(target, this.openValue)
|
17
|
+
})
|
18
|
+
}
|
19
|
+
}
|