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,21 @@
|
|
1
|
+
<div class="table overflow-x-auto mb-12 w-full rounded-lg border border-mid">
|
2
|
+
<div class="table-header-group">
|
3
|
+
<div class="table-row text-base font-medium text-white bg-mid">
|
4
|
+
<% columns.each_with_index do |column, i| %>
|
5
|
+
<div class="table-cell sticky top-0 z-10 p-4 <% if i.zero? %>rounded-tl-md<% elsif i == columns.size - 1 %>rounded-tr-md<% end %>"><%= column.label %></div>
|
6
|
+
<% end %>
|
7
|
+
</div>
|
8
|
+
</div>
|
9
|
+
|
10
|
+
<div class="table-row-group">
|
11
|
+
<% @rows.each do |row| %>
|
12
|
+
<div class="table-row relative bg-mid/5 hover:bg-mid/20">
|
13
|
+
<% @columns.each do |column| %>
|
14
|
+
<div class="table-cell py-5 px-3 h-20 text-sm align-middle whitespace-nowrap border-b border-mid/20">
|
15
|
+
<%= view_context.capture(row, &column.cell) %>
|
16
|
+
</div>
|
17
|
+
<% end %>
|
18
|
+
</div>
|
19
|
+
<% end %>
|
20
|
+
</div>
|
21
|
+
</div>
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class TableComponent < ViewComponent::Base
|
6
|
+
attr_reader :columns
|
7
|
+
|
8
|
+
def initialize(rows:)
|
9
|
+
@rows = rows
|
10
|
+
@columns = []
|
11
|
+
end
|
12
|
+
|
13
|
+
def column(label, &)
|
14
|
+
@columns << Column.new(label, &)
|
15
|
+
end
|
16
|
+
|
17
|
+
private
|
18
|
+
|
19
|
+
# Ensures @columns gets populated [https://dev.to/rolandstuder/supercharged-table-component-built-with-viewcomponent-3j6i]
|
20
|
+
def before_render
|
21
|
+
content
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
class Column
|
26
|
+
attr_reader :label, :cell
|
27
|
+
|
28
|
+
def initialize(label, &block)
|
29
|
+
@label = label
|
30
|
+
@cell = block
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class TagColumn < Column
|
35
|
+
attr_reader :label, :cell
|
36
|
+
|
37
|
+
def initialize(label, &block)
|
38
|
+
@label = label
|
39
|
+
@cell = PandaCms::Admin::TagComponent.new(status: block)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class TagComponent < ViewComponent::Base
|
6
|
+
attr_accessor :status, :text
|
7
|
+
|
8
|
+
def initialize(status: :active, text: nil)
|
9
|
+
@status = status.to_sym
|
10
|
+
@text = text || status.to_s.humanize
|
11
|
+
end
|
12
|
+
|
13
|
+
def call
|
14
|
+
classes = "inline-flex items-center py-1 px-2 text-xs font-medium rounded-md ring-1 ring-inset "
|
15
|
+
|
16
|
+
classes += case @status
|
17
|
+
when :active
|
18
|
+
"text-black ring-black/30 bg-active border-0 "
|
19
|
+
when :draft
|
20
|
+
"text-black ring-black/30 bg-warning "
|
21
|
+
when :inactive, :hidden
|
22
|
+
"text-black ring-black/30 bg-black/5 bg-white "
|
23
|
+
else
|
24
|
+
"text-black bg-white "
|
25
|
+
end
|
26
|
+
|
27
|
+
content_tag :span, class: classes do
|
28
|
+
@text
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class UserActivityComponent < ViewComponent::Base
|
6
|
+
attr_accessor :model
|
7
|
+
attr_accessor :updated_at
|
8
|
+
attr_accessor :user
|
9
|
+
|
10
|
+
# @param whodunnit_to [ActiveRecord::Base] Model instance to which the user activity is related
|
11
|
+
def initialize(whodunnit_to: nil)
|
12
|
+
@model = whodunnit_to
|
13
|
+
whodunnit_id = @model.versions&.last&.whodunnit
|
14
|
+
@user = User.find(whodunnit_id) if whodunnit_id
|
15
|
+
@updated_at = @model.updated_at
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<a href="#" class="block flex-shrink-0 group">
|
2
|
+
<div class="flex items-center">
|
3
|
+
<div>
|
4
|
+
<img class="inline-block w-10 h-10 rounded-full" src="https://avatars.githubusercontent.com/u/663625?v=4" alt="">
|
5
|
+
</div>
|
6
|
+
<div class="ml-3">
|
7
|
+
<p class="text-sm text-black group-hover:text-black/60"><%= user.firstname %> <%= user.lastname %></p>
|
8
|
+
<% if metadata %><p class="text-sm text-black/60"><%= metadata %></p><% end %>
|
9
|
+
</div>
|
10
|
+
</div>
|
11
|
+
</a>
|
@@ -0,0 +1,19 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class UserDisplayComponent < ViewComponent::Base
|
6
|
+
attr_accessor :user_id, :user, :metadata
|
7
|
+
|
8
|
+
def initialize(user_id: nil, user: nil, metadata: "")
|
9
|
+
@user = if user.nil? && user_id.present? && PandaCms::User.find(user_id)
|
10
|
+
PandaCms::User.find(user_id)
|
11
|
+
else
|
12
|
+
user
|
13
|
+
end
|
14
|
+
|
15
|
+
@metadata = metadata
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
class GridComponent < ViewComponent::Base
|
5
|
+
def initialize(columns: 1, spans: [1])
|
6
|
+
@columns = "grid-cols-#{columns}"
|
7
|
+
@colspans = []
|
8
|
+
spans.each do |span|
|
9
|
+
@colspans << "col-span-#{span}"
|
10
|
+
end
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
class MenuComponent < ViewComponent::Base
|
5
|
+
attr_accessor :menu_item
|
6
|
+
attr_accessor :children
|
7
|
+
|
8
|
+
def initialize(name:, item_styles: "")
|
9
|
+
@menu = PandaCms::Menu.find_by(name: name)
|
10
|
+
@menu_items = @menu.menu_items.order(:lft) if @menu.present?
|
11
|
+
@item_styles = item_styles
|
12
|
+
end
|
13
|
+
|
14
|
+
def render?
|
15
|
+
@menu_items.present?
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<% inactive_nav_styles = "border-gray-200 text-slate-600 " %>
|
2
|
+
<% active_nav_styles = "bg-gray-100 text-blue-900 border-blue-900" %>
|
3
|
+
|
4
|
+
<nav class="flex flex-col flex-1">
|
5
|
+
<ul role="list" class="flex flex-col flex-1">
|
6
|
+
<li>
|
7
|
+
<a href="<%= menu_item.page.path %>" class="border-l-2 hover:bg-gray-50 group flex px-3 py-2.5 text-lg leading-6 font-semibold <%= menu_item.page == PandaCms::Current.page ? active_nav_styles : inactive_nav_styles %>">
|
8
|
+
<%= menu_item.text %>
|
9
|
+
</a>
|
10
|
+
</li>
|
11
|
+
|
12
|
+
<div>
|
13
|
+
<ul class="mt-1">
|
14
|
+
<% PandaCms::MenuItem.each_with_level(menu_item.descendants) do |submenu_item, level| %>
|
15
|
+
<li data-level="<%= level %>" data-page-id="<%= submenu_item.page.id %>" <% if level > 1 && !PandaCms::Current.page.id.in?(submenu_item.page.self_and_ancestors.ids + submenu_item.page.siblings.ids) %> class="hidden"<% end %>>
|
16
|
+
<a href="<%= submenu_item.page.path %>" class="border-l-2 <%= helpers.menu_indent(submenu_item) %> hover:bg-gray-50 block px-3 py-2.5 text-base leading-6 font-regular <%= submenu_item.page == PandaCms::Current.page ? active_nav_styles : inactive_nav_styles %>">
|
17
|
+
<%= submenu_item.page.title %>
|
18
|
+
</a>
|
19
|
+
</li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
22
|
+
</div>
|
23
|
+
</ul>
|
24
|
+
</nav>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
class PageMenuComponent < ViewComponent::Base
|
5
|
+
attr_accessor :menu_item
|
6
|
+
attr_accessor :children
|
7
|
+
|
8
|
+
def initialize(page:, start_depth:)
|
9
|
+
start_page = if page.depth == start_depth
|
10
|
+
page
|
11
|
+
else
|
12
|
+
page.ancestors.find { |anc| anc.depth == start_depth }
|
13
|
+
end
|
14
|
+
|
15
|
+
menu = PandaCms::Menu.find_by(kind: "auto", start_page: start_page)
|
16
|
+
@menu_item = menu.menu_items.order(:lft)&.first unless menu.nil?
|
17
|
+
@children = menu_item&.descendants unless menu_item.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
def render?
|
21
|
+
@menu_item
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
<%= content_tag(:div, @content, @options) %>
|
2
|
+
|
3
|
+
<script type="text/javascript">
|
4
|
+
document.addEventListener("pandaCmsRichTextEditorLoaded", function() {
|
5
|
+
console.debug("[Panda CMS] Called event listener: pandaCmsRichTextEditorLoaded for <%= @options[:id] %>");
|
6
|
+
|
7
|
+
// Allowing per-element toolbar configuration, if needed
|
8
|
+
let quillOptions = {
|
9
|
+
modules: {
|
10
|
+
toolbar: [
|
11
|
+
[{ header: [1, 2, 3, false] }],
|
12
|
+
["bold", "italic", "underline"],
|
13
|
+
[{ list: "ordered" }, { list: "bullet" }],
|
14
|
+
[{ script: "sub" }, { script: "super" }],
|
15
|
+
[{ color: [] }, { background: [] }],
|
16
|
+
[{ align: [] }],
|
17
|
+
["link", "image", "video", "code-block", "clean"],
|
18
|
+
],
|
19
|
+
magicUrl: true,
|
20
|
+
imageCompressor: {
|
21
|
+
quality: 0.9,
|
22
|
+
maxWidth: 2000,
|
23
|
+
maxHeight: 2000,
|
24
|
+
imageType: "image/png",
|
25
|
+
keepImageTypes: ["image/jpeg", "image/jpg", "image/png"],
|
26
|
+
},
|
27
|
+
},
|
28
|
+
theme: "bubble",
|
29
|
+
};
|
30
|
+
|
31
|
+
let quillVar = "<%= @options[:id] %>";
|
32
|
+
console.debug(`[Panda CMS] Enabling Quill editor: ${quillVar}`);
|
33
|
+
|
34
|
+
console.debug(`[Panda CMS] Quill options for ${quillVar}: `, quillOptions);
|
35
|
+
|
36
|
+
Quill.register("modules/imageCompressor", imageCompressor);
|
37
|
+
|
38
|
+
quillVar = new Quill("#" + quillVar, quillOptions);
|
39
|
+
});
|
40
|
+
</script>
|
@@ -0,0 +1,35 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
# Text component
|
5
|
+
# @param key [Symbol] The key to use for the text component
|
6
|
+
# @param text [String] The text to display
|
7
|
+
# @param editable [Boolean] If the text is editable or not (defaults to true)
|
8
|
+
# @param options [Hash] The options to pass to the content_tag
|
9
|
+
class RichTextComponent < ViewComponent::Base
|
10
|
+
KIND = "rich_text"
|
11
|
+
|
12
|
+
def initialize(key: :text_component, text: "Lorem ipsum...", editable: true, **options)
|
13
|
+
@key = key
|
14
|
+
@text = text
|
15
|
+
@options = options || {}
|
16
|
+
@editable = editable
|
17
|
+
end
|
18
|
+
|
19
|
+
# Check if the element is editable and set up the content
|
20
|
+
def before_render
|
21
|
+
@editable &&= params[:embed_id].present? && params[:embed_id] == Current.page.id && Current.user&.admin?
|
22
|
+
|
23
|
+
block = PandaCms::Block.find_by(kind: "rich_text", key: @key, panda_cms_template_id: Current.page.panda_cms_template_id)
|
24
|
+
block_content = block.block_contents.find_by(panda_cms_page_id: Current.page.id)
|
25
|
+
@content = block_content.content.html_safe
|
26
|
+
@options[:id] = "editor_rich_text_#{block_content&.id&.tr("-", "_")}"
|
27
|
+
|
28
|
+
if @editable
|
29
|
+
@options[:data] = {
|
30
|
+
block_content_id: block_content&.id
|
31
|
+
}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
# Text component
|
5
|
+
# @param key [Symbol] The key to use for the text component
|
6
|
+
# @param text [String] The text to display
|
7
|
+
# @param editable [Boolean] If the text is editable or not (defaults to true)
|
8
|
+
# @param options [Hash] The options to pass to the content_tag
|
9
|
+
class TextComponent < ViewComponent::Base
|
10
|
+
KIND = "plain_text"
|
11
|
+
|
12
|
+
# Allows accessing the plain text of the component directly
|
13
|
+
attr_accessor :plain_text
|
14
|
+
|
15
|
+
def initialize(key: :text_component, text: "Lorem ipsum...", editable: true, **options)
|
16
|
+
@key = key
|
17
|
+
@text = text
|
18
|
+
@options = options || {}
|
19
|
+
@options[:id] ||= "text-#{key.to_s.dasherize}"
|
20
|
+
@editable = editable
|
21
|
+
end
|
22
|
+
|
23
|
+
def call
|
24
|
+
# TODO: For the non-editable version, grab this from a cache or similar?
|
25
|
+
block = PandaCms::Block.find_by(kind: KIND, key: @key, panda_cms_template_id: Current.page.panda_cms_template_id)
|
26
|
+
|
27
|
+
if block.nil?
|
28
|
+
raise PandaCms::MissingBlockError("Block with key #{@key} not found") unless Rails.env.production?
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
|
32
|
+
block_content = block.block_contents.find_by(panda_cms_page_id: Current.page.id)
|
33
|
+
plain_text = block_content&.content.to_s
|
34
|
+
|
35
|
+
if @editable
|
36
|
+
@options[:contenteditable] = "plaintext-only"
|
37
|
+
@options[:data] = {
|
38
|
+
"editable-kind": "plain_text",
|
39
|
+
"editable-page-id": Current.page.id,
|
40
|
+
"editable-block-content-id": block_content&.id
|
41
|
+
}
|
42
|
+
|
43
|
+
@options[:id] = "editor-#{block_content&.id}"
|
44
|
+
content = plain_text
|
45
|
+
else
|
46
|
+
content = prepare_content_for_display(plain_text)
|
47
|
+
end
|
48
|
+
|
49
|
+
content_tag(:span, content, @options, false) # Don't escape the content
|
50
|
+
end
|
51
|
+
|
52
|
+
#
|
53
|
+
# Prepares content for display
|
54
|
+
#
|
55
|
+
# @usage Do not use this when rendering editable content
|
56
|
+
def prepare_content_for_display(content)
|
57
|
+
# Replace \n characters with <br> tags
|
58
|
+
content.gsub("\n", "<br>")
|
59
|
+
end
|
60
|
+
|
61
|
+
# Check if the element is editable
|
62
|
+
# TODO: Check user permissions
|
63
|
+
def before_render
|
64
|
+
@editable &&= params[:embed_id].present? && params[:embed_id] == Current.page.id
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class AdminConstraint
|
3
|
+
def initialize(&block)
|
4
|
+
@block = block
|
5
|
+
end
|
6
|
+
|
7
|
+
def matches?(request)
|
8
|
+
user = current_user(request)
|
9
|
+
user.present? && user.admin? && @block&.call(user)
|
10
|
+
end
|
11
|
+
|
12
|
+
def current_user(request)
|
13
|
+
User.find_by(id: request.session[:user_id])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class BlockContentsController < ApplicationController
|
6
|
+
before_action :set_page, only: %i[update]
|
7
|
+
before_action :set_block_content, only: %i[update]
|
8
|
+
before_action :set_paper_trail_whodunnit, only: %i[update]
|
9
|
+
before_action :authenticate_admin_user!
|
10
|
+
|
11
|
+
# @type PATCH/PUT
|
12
|
+
# @return
|
13
|
+
def update
|
14
|
+
if @block_content.update(block_content_params)
|
15
|
+
@block_content.page.touch # Update the page's updated_at
|
16
|
+
render json: @block_content, status: :ok
|
17
|
+
else
|
18
|
+
render json: @block_content.errors, status: :unprocessable_entity
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
private
|
23
|
+
|
24
|
+
# @type private
|
25
|
+
# @return PandaCms::Page
|
26
|
+
def set_page
|
27
|
+
@page = PandaCms::Page.find(params[:page_id])
|
28
|
+
end
|
29
|
+
|
30
|
+
# @type private
|
31
|
+
# @return PandaCms::BlockContent
|
32
|
+
def set_block_content
|
33
|
+
@block_content = PandaCms::BlockContent.find(params[:id])
|
34
|
+
end
|
35
|
+
|
36
|
+
# Only allow a list of trusted parameters through.
|
37
|
+
# @type private
|
38
|
+
# @return ActionController::StrongParameters
|
39
|
+
def block_content_params
|
40
|
+
params.require(:block_content).permit(:content)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require "groupdate"
|
2
|
+
require "whois-parser"
|
3
|
+
|
4
|
+
module PandaCms
|
5
|
+
class Admin::DashboardController < ApplicationController
|
6
|
+
before_action :set_initial_breadcrumb, only: %i[show]
|
7
|
+
before_action :authenticate_admin_user!
|
8
|
+
|
9
|
+
# GET /admin
|
10
|
+
def show
|
11
|
+
@domain_expiry = domain_expiry
|
12
|
+
end
|
13
|
+
|
14
|
+
private
|
15
|
+
|
16
|
+
def set_initial_breadcrumb
|
17
|
+
add_breadcrumb "Dashboard", PandaCms.admin_path
|
18
|
+
end
|
19
|
+
|
20
|
+
def domain_expiry
|
21
|
+
return "" if request.domain == "localhost"
|
22
|
+
|
23
|
+
whois_record = Whois.whois(request.domain)
|
24
|
+
if (parser = whois_record&.parser)
|
25
|
+
" (expiry date: #{parser.expires_on&.strftime("%d %b %Y")})"
|
26
|
+
else
|
27
|
+
" (error parsing WHOIS data)"
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module PandaCms
|
2
|
+
class Admin::FilesController < ApplicationController
|
3
|
+
before_action :set_initial_breadcrumb, only: %i[index show]
|
4
|
+
before_action :authenticate_admin_user!
|
5
|
+
|
6
|
+
def index
|
7
|
+
redirect_to admin_dashboard_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def show
|
11
|
+
end
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def set_initial_breadcrumb
|
16
|
+
add_breadcrumb "Media", admin_files_path
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class FormsController < ApplicationController
|
6
|
+
before_action :set_initial_breadcrumb, only: %i[index show]
|
7
|
+
# before_action :set_paper_trail_whodunnit, only: %i[create update]
|
8
|
+
before_action :authenticate_admin_user!
|
9
|
+
|
10
|
+
# Lists all forms
|
11
|
+
# @type GET
|
12
|
+
# @return ActiveRecord::Collection A list of all forms
|
13
|
+
def index
|
14
|
+
forms = PandaCms::Form.order(:name)
|
15
|
+
render :index, locals: {forms: forms}
|
16
|
+
end
|
17
|
+
|
18
|
+
def show
|
19
|
+
form = PandaCms::Form.find(params[:id])
|
20
|
+
|
21
|
+
add_breadcrumb form.name, admin_form_path(form)
|
22
|
+
submissions = form.form_submissions.order(created_at: :desc)
|
23
|
+
# TODO: Set a whitelist of fields we allow to be submitted for the form, shown in this view
|
24
|
+
# and a formatting array of how to display them... eventually?
|
25
|
+
|
26
|
+
fields = if submissions.last
|
27
|
+
submissions.last.data.keys.reverse.map { |field| [field, field.titleize] }
|
28
|
+
else
|
29
|
+
[]
|
30
|
+
end
|
31
|
+
|
32
|
+
render :show, locals: {form: form, submissions: submissions, fields: fields}
|
33
|
+
end
|
34
|
+
|
35
|
+
private
|
36
|
+
|
37
|
+
def set_initial_breadcrumb
|
38
|
+
add_breadcrumb "Forms", admin_forms_path
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# Only allow a list of trusted parameters through
|
44
|
+
# @type private
|
45
|
+
# @return ActionController::StrongParameters
|
46
|
+
def form_params
|
47
|
+
params.require(:form).permit(:name, :completion_path)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,81 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module PandaCms
|
4
|
+
module Admin
|
5
|
+
class MenusController < ApplicationController
|
6
|
+
before_action :set_initial_breadcrumb, only: %i[index new edit create update]
|
7
|
+
before_action :set_paper_trail_whodunnit, only: %i[create update]
|
8
|
+
before_action :authenticate_admin_user!
|
9
|
+
|
10
|
+
# Lists all menus which can be managed by the administrator
|
11
|
+
# @type GET
|
12
|
+
# @return ActiveRecord::Collection An array of all menus
|
13
|
+
def index
|
14
|
+
menus = PandaCms::Menu.order(:name)
|
15
|
+
render :index, locals: {menus: menus}
|
16
|
+
end
|
17
|
+
|
18
|
+
# Loads the menu editor
|
19
|
+
# @type GET
|
20
|
+
def edit
|
21
|
+
add_breadcrumb menu.name, edit_admin_menu_path(menu)
|
22
|
+
end
|
23
|
+
|
24
|
+
# GET /admin/menus/new
|
25
|
+
# @type GET
|
26
|
+
def new
|
27
|
+
@menu = PandaCms::Menu.new
|
28
|
+
@menu.menu_items.new
|
29
|
+
set_new_menu_breadcrumb
|
30
|
+
end
|
31
|
+
|
32
|
+
# POST /admin/menus
|
33
|
+
def create
|
34
|
+
@menu = PandaCms::Menu.new(menu_params)
|
35
|
+
|
36
|
+
if @menu.save
|
37
|
+
redirect_to admin_menus_path, notice: "Menu was successfully created."
|
38
|
+
else
|
39
|
+
flash[:error] = @menu.errors.full_messages.join(", ")
|
40
|
+
set_new_menu_breadcrumb
|
41
|
+
render :new, status: :unprocessable_entity
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
# @type PATCH/PUT
|
46
|
+
# @return
|
47
|
+
def update
|
48
|
+
if menu.update!(menu_params)
|
49
|
+
redirect_to edit_admin_menu_path(menu),
|
50
|
+
status: :see_other,
|
51
|
+
flash: {success: "This menu was successfully updated!"}
|
52
|
+
else
|
53
|
+
add_breadcrumb menu.name, edit_admin_menu_path(menu)
|
54
|
+
flash[:error] = "There was an error updating the menu."
|
55
|
+
render :edit, status: :unprocessable_entity
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
private
|
60
|
+
|
61
|
+
def menu
|
62
|
+
@menu ||= PandaCms::Menu.find(params[:id])
|
63
|
+
end
|
64
|
+
|
65
|
+
def set_initial_breadcrumb
|
66
|
+
add_breadcrumb "Menus", admin_menus_path
|
67
|
+
end
|
68
|
+
|
69
|
+
def set_new_menu_breadcrumb
|
70
|
+
add_breadcrumb "Add New Menu", new_admin_menu_path
|
71
|
+
end
|
72
|
+
|
73
|
+
# Only allow a list of trusted parameters through.
|
74
|
+
# @type private
|
75
|
+
# @return ActionController::StrongParameters
|
76
|
+
def menu_params
|
77
|
+
params.require(:menu).permit(:name, menu_items_attributes: %i[id text external_url sort_order panda_cms_page_id _destroy])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|