panda_cms 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (193) hide show
  1. checksums.yaml +7 -0
  2. data/README.md +71 -0
  3. data/Rakefile +8 -0
  4. data/app/assets/builds/panda_cms.css +1 -0
  5. data/app/assets/config/panda_cms_manifest.js +1 -0
  6. data/app/assets/stylesheets/panda_cms/application.tailwind.css +61 -0
  7. data/app/builders/panda_cms/form_builder.rb +118 -0
  8. data/app/components/panda_cms/admin/button_component.rb +65 -0
  9. data/app/components/panda_cms/admin/container_component.html.erb +13 -0
  10. data/app/components/panda_cms/admin/container_component.rb +11 -0
  11. data/app/components/panda_cms/admin/flash_message_component.html.erb +30 -0
  12. data/app/components/panda_cms/admin/flash_message_component.rb +44 -0
  13. data/app/components/panda_cms/admin/heading_component.rb +43 -0
  14. data/app/components/panda_cms/admin/panel_component.html.erb +7 -0
  15. data/app/components/panda_cms/admin/panel_component.rb +11 -0
  16. data/app/components/panda_cms/admin/slideover_component.html.erb +9 -0
  17. data/app/components/panda_cms/admin/slideover_component.rb +13 -0
  18. data/app/components/panda_cms/admin/statistics_component.html.erb +4 -0
  19. data/app/components/panda_cms/admin/statistics_component.rb +15 -0
  20. data/app/components/panda_cms/admin/tab_bar_component.html.erb +35 -0
  21. data/app/components/panda_cms/admin/tab_bar_component.rb +13 -0
  22. data/app/components/panda_cms/admin/table_component.html.erb +21 -0
  23. data/app/components/panda_cms/admin/table_component.rb +43 -0
  24. data/app/components/panda_cms/admin/tag_component.rb +33 -0
  25. data/app/components/panda_cms/admin/user_activity_component.html.erb +5 -0
  26. data/app/components/panda_cms/admin/user_activity_component.rb +19 -0
  27. data/app/components/panda_cms/admin/user_display_component.html.erb +11 -0
  28. data/app/components/panda_cms/admin/user_display_component.rb +19 -0
  29. data/app/components/panda_cms/grid_component.html.erb +6 -0
  30. data/app/components/panda_cms/grid_component.rb +13 -0
  31. data/app/components/panda_cms/menu_component.html.erb +3 -0
  32. data/app/components/panda_cms/menu_component.rb +18 -0
  33. data/app/components/panda_cms/page_menu_component.html.erb +24 -0
  34. data/app/components/panda_cms/page_menu_component.rb +24 -0
  35. data/app/components/panda_cms/rich_text_component.html.erb +40 -0
  36. data/app/components/panda_cms/rich_text_component.rb +35 -0
  37. data/app/components/panda_cms/text_component.rb +67 -0
  38. data/app/constraints/panda_cms/admin_constraint.rb +16 -0
  39. data/app/controllers/panda_cms/admin/block_contents_controller.rb +44 -0
  40. data/app/controllers/panda_cms/admin/dashboard_controller.rb +31 -0
  41. data/app/controllers/panda_cms/admin/files_controller.rb +19 -0
  42. data/app/controllers/panda_cms/admin/forms_controller.rb +51 -0
  43. data/app/controllers/panda_cms/admin/menus_controller.rb +81 -0
  44. data/app/controllers/panda_cms/admin/pages_controller.rb +88 -0
  45. data/app/controllers/panda_cms/admin/posts_controller.rb +34 -0
  46. data/app/controllers/panda_cms/admin/sessions_controller.rb +83 -0
  47. data/app/controllers/panda_cms/admin/settings/bulk_editor_controller.rb +35 -0
  48. data/app/controllers/panda_cms/admin/settings_controller.rb +18 -0
  49. data/app/controllers/panda_cms/application_controller.rb +55 -0
  50. data/app/controllers/panda_cms/errors_controller.rb +31 -0
  51. data/app/controllers/panda_cms/form_submissions_controller.rb +21 -0
  52. data/app/controllers/panda_cms/pages_controller.rb +56 -0
  53. data/app/controllers/panda_cms/posts_controller.rb +17 -0
  54. data/app/helpers/panda_cms/admin/files_helper.rb +4 -0
  55. data/app/helpers/panda_cms/admin/pages_helper.rb +4 -0
  56. data/app/helpers/panda_cms/application_helper.rb +96 -0
  57. data/app/helpers/panda_cms/pages_helper.rb +4 -0
  58. data/app/helpers/panda_cms/theme_helper.rb +16 -0
  59. data/app/javascript/base.js +37 -0
  60. data/app/javascript/controllers/menu_controller.js +19 -0
  61. data/app/javascript/controllers/text_controller.js +78 -0
  62. data/app/javascript/controllers/text_field_update_controller.js +23 -0
  63. data/app/javascript/vendor/stimulus-components-rails-nested-form.js +2 -0
  64. data/app/javascript/vendor/tailwindcss-stimulus-components.js +2 -0
  65. data/app/jobs/panda_cms/application_job.rb +4 -0
  66. data/app/jobs/panda_cms/record_visit_job.rb +29 -0
  67. data/app/lib/panda_cms/bulk_editor.rb +169 -0
  68. data/app/lib/panda_cms/demo_site_generator.rb +70 -0
  69. data/app/lib/panda_cms/slug.rb +22 -0
  70. data/app/mailers/panda_cms/application_mailer.rb +6 -0
  71. data/app/mailers/panda_cms/form_mailer.rb +19 -0
  72. data/app/models/panda_cms/application_record.rb +5 -0
  73. data/app/models/panda_cms/block.rb +32 -0
  74. data/app/models/panda_cms/block_content.rb +16 -0
  75. data/app/models/panda_cms/block_content_version.rb +6 -0
  76. data/app/models/panda_cms/breadcrumb.rb +10 -0
  77. data/app/models/panda_cms/current.rb +15 -0
  78. data/app/models/panda_cms/form.rb +7 -0
  79. data/app/models/panda_cms/form_submission.rb +5 -0
  80. data/app/models/panda_cms/menu.rb +50 -0
  81. data/app/models/panda_cms/menu_item.rb +56 -0
  82. data/app/models/panda_cms/page.rb +81 -0
  83. data/app/models/panda_cms/page_version.rb +6 -0
  84. data/app/models/panda_cms/post.rb +25 -0
  85. data/app/models/panda_cms/post_version.rb +6 -0
  86. data/app/models/panda_cms/redirect.rb +9 -0
  87. data/app/models/panda_cms/template.rb +117 -0
  88. data/app/models/panda_cms/template_version.rb +6 -0
  89. data/app/models/panda_cms/user.rb +15 -0
  90. data/app/models/panda_cms/version.rb +6 -0
  91. data/app/models/panda_cms/visit.rb +7 -0
  92. data/app/views/layouts/panda_cms/application.html.erb +44 -0
  93. data/app/views/layouts/panda_cms/public.html.erb +3 -0
  94. data/app/views/panda_cms/admin/dashboard/show.html.erb +11 -0
  95. data/app/views/panda_cms/admin/files/index.html.erb +124 -0
  96. data/app/views/panda_cms/admin/files/show.html.erb +2 -0
  97. data/app/views/panda_cms/admin/forms/edit.html.erb +0 -0
  98. data/app/views/panda_cms/admin/forms/index.html.erb +13 -0
  99. data/app/views/panda_cms/admin/forms/new.html.erb +16 -0
  100. data/app/views/panda_cms/admin/forms/show.html.erb +35 -0
  101. data/app/views/panda_cms/admin/menus/_form.html.erb +21 -0
  102. data/app/views/panda_cms/admin/menus/_menu_item_fields.html.erb +7 -0
  103. data/app/views/panda_cms/admin/menus/edit.html.erb +58 -0
  104. data/app/views/panda_cms/admin/menus/index.html.erb +10 -0
  105. data/app/views/panda_cms/admin/menus/new.html.erb +5 -0
  106. data/app/views/panda_cms/admin/pages/edit.html.erb +26 -0
  107. data/app/views/panda_cms/admin/pages/index.html.erb +16 -0
  108. data/app/views/panda_cms/admin/pages/new.html.erb +16 -0
  109. data/app/views/panda_cms/admin/pages/show.html.erb +1 -0
  110. data/app/views/panda_cms/admin/posts/index.html.erb +16 -0
  111. data/app/views/panda_cms/admin/sessions/new.html.erb +18 -0
  112. data/app/views/panda_cms/admin/settings/bulk_editor/new.html.erb +68 -0
  113. data/app/views/panda_cms/admin/settings/index.html.erb +19 -0
  114. data/app/views/panda_cms/admin/shared/_breadcrumbs.html.erb +28 -0
  115. data/app/views/panda_cms/admin/shared/_flash.html.erb +5 -0
  116. data/app/views/panda_cms/admin/shared/_sidebar.html.erb +45 -0
  117. data/app/views/panda_cms/form_mailer/notification_email.html.erb +11 -0
  118. data/app/views/panda_cms/shared/_favicons.html.erb +9 -0
  119. data/app/views/panda_cms/shared/_footer.html.erb +2 -0
  120. data/app/views/panda_cms/shared/_header.html.erb +15 -0
  121. data/config/importmap.rb +9 -0
  122. data/config/initializers/panda_cms/form_errors.rb +38 -0
  123. data/config/initializers/panda_cms/healthcheck_log_silencer.rb +11 -0
  124. data/config/initializers/panda_cms.rb +52 -0
  125. data/config/locales/en.yml +29 -0
  126. data/config/routes.rb +43 -0
  127. data/config/tailwind.config.js +35 -0
  128. data/config/tailwind.embed.config.js +20 -0
  129. data/db/migrate/20240205223709_create_panda_cms_pages.rb +9 -0
  130. data/db/migrate/20240219213327_create_panda_cms_page_versions.rb +14 -0
  131. data/db/migrate/20240303002805_create_panda_cms_templates.rb +11 -0
  132. data/db/migrate/20240303003434_create_panda_cms_template_versions.rb +14 -0
  133. data/db/migrate/20240303022441_create_panda_cms_blocks.rb +13 -0
  134. data/db/migrate/20240303024256_create_panda_cms_block_contents.rb +10 -0
  135. data/db/migrate/20240303024746_create_panda_cms_block_content_versions.rb +14 -0
  136. data/db/migrate/20240303233238_add_panda_cms_menu_table.rb +10 -0
  137. data/db/migrate/20240303234724_add_panda_cms_menu_item_table.rb +12 -0
  138. data/db/migrate/20240304134343_add_parent_id_to_panda_cms_pages.rb +5 -0
  139. data/db/migrate/20240315125421_add_nested_sets_to_panda_cms_pages.rb +16 -0
  140. data/db/migrate/20240316212822_add_kind_to_panda_cms_menus.rb +6 -0
  141. data/db/migrate/20240316221425_add_start_page_to_panda_cms_menus.rb +5 -0
  142. data/db/migrate/20240316230706_add_nested_to_panda_cms_menu_items.rb +24 -0
  143. data/db/migrate/20240317010532_create_panda_cms_users.rb +12 -0
  144. data/db/migrate/20240317161534_add_max_uses_to_panda_cms_template.rb +7 -0
  145. data/db/migrate/20240317163053_reset_counter_cache_on_panda_cms_template.rb +5 -0
  146. data/db/migrate/20240317214827_create_panda_cms_redirects.rb +14 -0
  147. data/db/migrate/20240317230622_create_panda_cms_visits.rb +13 -0
  148. data/db/migrate/20240324205703_create_active_storage_tables.active_storage.rb +58 -0
  149. data/db/migrate/20240408084718_default_panda_cms_users_admin_to_false.rb +5 -0
  150. data/db/migrate/20240701225422_add_service_name_to_active_storage_blobs.active_storage.rb +22 -0
  151. data/db/migrate/20240701225423_create_active_storage_variant_records.active_storage.rb +28 -0
  152. data/db/migrate/20240701225424_remove_not_null_on_active_storage_blobs_checksum.active_storage.rb +8 -0
  153. data/db/migrate/20240804110225_add_status_to_panda_cms_pages.rb +7 -0
  154. data/db/migrate/20240804235210_create_panda_cms_forms.rb +11 -0
  155. data/db/migrate/20240805013612_create_panda_cms_form_submissions.rb +9 -0
  156. data/db/migrate/20240805121123_create_panda_cms_posts.rb +27 -0
  157. data/db/migrate/20240805123104_create_panda_cms_post_versions.rb +14 -0
  158. data/db/migrate/20240806112735_fix_panda_cms_visits_column_names.rb +13 -0
  159. data/db/migrate/20240806204412_add_completion_path_to_panda_cms_forms.rb +5 -0
  160. data/db/migrate/20240820081917_change_form_submissions_to_submission_count.rb +5 -0
  161. data/db/seeds.rb +4 -0
  162. data/lib/generators/panda_cms/install_generator.rb +24 -0
  163. data/lib/panda_cms/engine.rb +167 -0
  164. data/lib/panda_cms/exceptions_app.rb +24 -0
  165. data/lib/panda_cms/version.rb +3 -0
  166. data/lib/panda_cms.rb +15 -0
  167. data/lib/tasks/panda_cms.rake +92 -0
  168. data/lib/templates/erb/scaffold/_form.html.erb.tt +43 -0
  169. data/lib/templates/erb/scaffold/edit.html.erb.tt +8 -0
  170. data/lib/templates/erb/scaffold/index.html.erb.tt +14 -0
  171. data/lib/templates/erb/scaffold/new.html.erb.tt +7 -0
  172. data/lib/templates/erb/scaffold/partial.html.erb.tt +22 -0
  173. data/lib/templates/erb/scaffold/show.html.erb.tt +15 -0
  174. data/public/panda-cms-assets/favicons/android-chrome-192x192.png +0 -0
  175. data/public/panda-cms-assets/favicons/android-chrome-512x512.png +0 -0
  176. data/public/panda-cms-assets/favicons/apple-touch-icon.png +0 -0
  177. data/public/panda-cms-assets/favicons/browserconfig.xml +9 -0
  178. data/public/panda-cms-assets/favicons/favicon-16x16.png +0 -0
  179. data/public/panda-cms-assets/favicons/favicon-32x32.png +0 -0
  180. data/public/panda-cms-assets/favicons/favicon.ico +0 -0
  181. data/public/panda-cms-assets/favicons/mstile-150x150.png +0 -0
  182. data/public/panda-cms-assets/favicons/safari-pinned-tab.svg +61 -0
  183. data/public/panda-cms-assets/favicons/site.webmanifest +14 -0
  184. data/public/panda-cms-assets/javascripts/base.js +37 -0
  185. data/public/panda-cms-assets/javascripts/controllers/menu_controller.js +19 -0
  186. data/public/panda-cms-assets/javascripts/controllers/text_field_update_controller.js +23 -0
  187. data/public/panda-cms-assets/javascripts/embed/editable.js +308 -0
  188. data/public/panda-cms-assets/javascripts/vendor/stimulus-components-rails-nested-form.js +2 -0
  189. data/public/panda-cms-assets/javascripts/vendor/stimulus-loading.js +113 -0
  190. data/public/panda-cms-assets/javascripts/vendor/tailwindcss-stimulus-components.js +2 -0
  191. data/public/panda-cms-assets/panda-logo-screenprint.png +0 -0
  192. data/public/panda-cms-assets/panda-nav.png +0 -0
  193. metadata +1034 -0
@@ -0,0 +1,9 @@
1
+ class CreatePandaCmsPages < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_pages, id: :uuid do |t|
4
+ t.string :title
5
+ t.string :path
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePandaCmsPageVersions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_page_versions, id: :uuid do |t|
4
+ t.string :item_type, null: false
5
+ t.string :item_id, null: false
6
+ t.string :event, null: false
7
+ t.string :whodunnit
8
+ t.jsonb :object
9
+ t.jsonb :object_changes
10
+ t.datetime :created_at
11
+ end
12
+ add_index :panda_cms_page_versions, %i[item_type item_id]
13
+ end
14
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePandaCmsTemplates < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_templates, id: :uuid do |t|
4
+ t.string :name
5
+ t.string :file_path
6
+ t.timestamps
7
+ end
8
+
9
+ add_reference :panda_cms_pages, :panda_cms_template, type: :uuid, foreign_key: {to_table: :panda_cms_templates}, null: false
10
+ end
11
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePandaCmsTemplateVersions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_template_versions, id: :uuid do |t|
4
+ t.string :item_type, null: false
5
+ t.string :item_id, null: false
6
+ t.string :event, null: false
7
+ t.string :whodunnit
8
+ t.jsonb :object
9
+ t.jsonb :object_changes
10
+ t.datetime :created_at
11
+ end
12
+ add_index :panda_cms_template_versions, %i[item_type item_id]
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePandaCmsBlocks < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_enum :panda_cms_block_kind, ["plain_text", "rich_text", "image", "video", "audio", "file", "code", "iframe", "quote", "list", "table", "form"]
4
+
5
+ create_table :panda_cms_blocks, id: :uuid do |t|
6
+ t.enum :kind, enum_type: :panda_cms_block_kind, default: "plain_text", null: false
7
+ t.string :name
8
+ t.string :key
9
+ t.references :panda_cms_template, type: :uuid, foreign_key: {to_table: :panda_cms_templates}, null: false
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,10 @@
1
+ class CreatePandaCmsBlockContents < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_block_contents, id: :uuid do |t|
4
+ t.references :panda_cms_page, null: false, foreign_key: true, type: :uuid
5
+ t.references :panda_cms_block, null: false, foreign_key: true, type: :uuid
6
+ t.jsonb :content, null: false, default: {}
7
+ t.timestamps
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePandaCmsBlockContentVersions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_block_content_versions, id: :uuid do |t|
4
+ t.string :item_type, null: false
5
+ t.string :item_id, null: false
6
+ t.string :event, null: false
7
+ t.string :whodunnit
8
+ t.jsonb :object
9
+ t.jsonb :object_changes
10
+ t.datetime :created_at
11
+ end
12
+ add_index :panda_cms_block_content_versions, %i[item_type item_id]
13
+ end
14
+ end
@@ -0,0 +1,10 @@
1
+ class AddPandaCmsMenuTable < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_menus, id: :uuid do |t|
4
+ t.string :name, null: false
5
+ t.timestamps
6
+ end
7
+
8
+ add_index :panda_cms_menus, :name, unique: true
9
+ end
10
+ end
@@ -0,0 +1,12 @@
1
+ class AddPandaCmsMenuItemTable < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_menu_items, id: :uuid do |t|
4
+ t.string :text, null: false
5
+ t.references :panda_cms_menu, null: false, foreign_key: true, type: :uuid
6
+ t.references :panda_cms_page, null: true, foreign_key: true, type: :uuid
7
+ t.string :external_url, null: true
8
+ t.integer :sort_order, default: 1
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ class AddParentIdToPandaCmsPages < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_reference :panda_cms_pages, :parent, type: :uuid, foreign_key: {to_table: :panda_cms_pages}
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ class AddNestedSetsToPandaCmsPages < ActiveRecord::Migration[7.1]
2
+ def self.up
3
+ PandaCms::Page.where(parent_id: 0).update_all(parent_id: nil)
4
+ add_column :panda_cms_pages, :lft, :integer
5
+ add_column :panda_cms_pages, :rgt, :integer
6
+
7
+ # This is necessary to update :lft and :rgt columns
8
+ PandaCms::Page.reset_column_information
9
+ PandaCms::Page.rebuild!
10
+ end
11
+
12
+ def self.down
13
+ remove_column :panda_cms_pages, :lft
14
+ remove_column :panda_cms_pages, :rgt
15
+ end
16
+ end
@@ -0,0 +1,6 @@
1
+ class AddKindToPandaCmsMenus < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_enum :panda_cms_menu_kind, ["static", "auto"]
4
+ add_column :panda_cms_menus, :kind, :enum, enum_type: :panda_cms_menu_kind, default: "static", null: false
5
+ end
6
+ end
@@ -0,0 +1,5 @@
1
+ class AddStartPageToPandaCmsMenus < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_reference :panda_cms_menus, :start_page, type: :uuid, foreign_key: {to_table: :panda_cms_pages}
4
+ end
5
+ end
@@ -0,0 +1,24 @@
1
+ class AddNestedToPandaCmsMenuItems < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :panda_cms_menu_items, :parent_id, :uuid
4
+ add_column :panda_cms_menu_items, :lft, :integer
5
+ add_column :panda_cms_menu_items, :rgt, :integer
6
+ add_column :panda_cms_menu_items, :depth, :integer
7
+ add_column :panda_cms_menu_items, :children_count, :integer, null: false, default: 0
8
+
9
+ add_index :panda_cms_menu_items, :lft
10
+ add_index :panda_cms_menu_items, :rgt
11
+
12
+ PandaCms::MenuItem.reset_column_information
13
+ PandaCms::MenuItem.rebuild!
14
+
15
+ # Update pages whilst we're at it
16
+ add_column :panda_cms_pages, :depth, :integer
17
+ add_column :panda_cms_pages, :children_count, :integer, null: false, default: 0
18
+ add_index :panda_cms_pages, :lft
19
+ add_index :panda_cms_pages, :rgt
20
+
21
+ PandaCms::Page.reset_column_information
22
+ PandaCms::Page.rebuild!
23
+ end
24
+ end
@@ -0,0 +1,12 @@
1
+ class CreatePandaCmsUsers < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_users, id: :uuid do |t|
4
+ t.string :firstname
5
+ t.string :lastname
6
+ t.string :email
7
+ t.string :image_url
8
+ t.boolean :admin
9
+ t.timestamps
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,7 @@
1
+ class AddMaxUsesToPandaCmsTemplate < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :panda_cms_templates, :max_uses, :integer, null: true, default: nil
4
+ add_column :panda_cms_templates, :pages_count, :integer, default: 0
5
+ PandaCms::Template.find_by(name: "Homepage")&.update(max_uses: 1)
6
+ end
7
+ end
@@ -0,0 +1,5 @@
1
+ class ResetCounterCacheOnPandaCmsTemplate < ActiveRecord::Migration[7.1]
2
+ def change
3
+ PandaCms::Template.find_each { |t| PandaCms::Template.reset_counters(t.id, :pages) }
4
+ end
5
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePandaCmsRedirects < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_redirects, id: :uuid do |t|
4
+ t.string :origin_path, null: true
5
+ t.string :destination_path, null: true
6
+ t.references :origin_panda_cms_page, null: true, foreign_key: {to_table: :panda_cms_pages}, type: :uuid
7
+ t.references :destination_panda_cms_page, null: true, foreign_key: {to_table: :panda_cms_pages}, type: :uuid
8
+ t.integer :status_code, default: 301, null: false
9
+ t.integer :visits, default: 0, null: false
10
+ t.datetime :last_visited_at, null: true
11
+ t.timestamps
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePandaCmsVisits < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_visits, id: :uuid do |t|
4
+ t.string :ip_address, null: true
5
+ t.string :user_agent, null: true
6
+
7
+ t.references :panda_cms_page, null: true, foreign_key: true, type: :uuid
8
+ t.references :panda_cms_redirect, null: true, foreign_key: true, type: :uuid
9
+ t.references :panda_cms_user, null: true, foreign_key: true, type: :uuid
10
+ t.timestamps
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,58 @@
1
+ # This migration comes from active_storage (originally 20170806125915)
2
+ class CreateActiveStorageTables < ActiveRecord::Migration[7.0]
3
+ def change
4
+ # Use Active Record's configured type for primary and foreign keys
5
+ primary_key_type, foreign_key_type = primary_and_foreign_key_types
6
+
7
+ create_table :active_storage_blobs, id: primary_key_type do |t|
8
+ t.string :key, null: false
9
+ t.string :filename, null: false
10
+ t.string :content_type
11
+ t.text :metadata
12
+ t.string :service_name, null: false
13
+ t.bigint :byte_size, null: false
14
+ t.string :checksum
15
+
16
+ if connection.supports_datetime_with_precision?
17
+ t.datetime :created_at, precision: 6, null: false
18
+ else
19
+ t.datetime :created_at, null: false
20
+ end
21
+
22
+ t.index [:key], unique: true
23
+ end
24
+
25
+ create_table :active_storage_attachments, id: primary_key_type do |t|
26
+ t.string :name, null: false
27
+ t.references :record, null: false, polymorphic: true, index: false, type: foreign_key_type
28
+ t.references :blob, null: false, type: foreign_key_type
29
+
30
+ if connection.supports_datetime_with_precision?
31
+ t.datetime :created_at, precision: 6, null: false
32
+ else
33
+ t.datetime :created_at, null: false
34
+ end
35
+
36
+ t.index [:record_type, :record_id, :name, :blob_id], name: :index_active_storage_attachments_uniqueness, unique: true
37
+ t.foreign_key :active_storage_blobs, column: :blob_id
38
+ end
39
+
40
+ create_table :active_storage_variant_records, id: primary_key_type do |t|
41
+ t.belongs_to :blob, null: false, index: false, type: foreign_key_type
42
+ t.string :variation_digest, null: false
43
+
44
+ t.index [:blob_id, :variation_digest], name: :index_active_storage_variant_records_uniqueness, unique: true
45
+ t.foreign_key :active_storage_blobs, column: :blob_id
46
+ end
47
+ end
48
+
49
+ private
50
+
51
+ def primary_and_foreign_key_types
52
+ config = Rails.configuration.generators
53
+ setting = config.options[config.orm][:primary_key_type]
54
+ primary_key_type = setting || :primary_key
55
+ foreign_key_type = setting || :bigint
56
+ [primary_key_type, foreign_key_type]
57
+ end
58
+ end
@@ -0,0 +1,5 @@
1
+ class DefaultPandaCmsUsersAdminToFalse < ActiveRecord::Migration[7.1]
2
+ def change
3
+ change_column :panda_cms_users, :admin, :boolean, default: false
4
+ end
5
+ end
@@ -0,0 +1,22 @@
1
+ # This migration comes from active_storage (originally 20190112182829)
2
+ class AddServiceNameToActiveStorageBlobs < ActiveRecord::Migration[6.0]
3
+ def up
4
+ return unless table_exists?(:active_storage_blobs)
5
+
6
+ unless column_exists?(:active_storage_blobs, :service_name)
7
+ add_column :active_storage_blobs, :service_name, :string
8
+
9
+ if (configured_service = ActiveStorage::Blob.service.name)
10
+ ActiveStorage::Blob.unscoped.update_all(service_name: configured_service)
11
+ end
12
+
13
+ change_column :active_storage_blobs, :service_name, :string, null: false
14
+ end
15
+ end
16
+
17
+ def down
18
+ return unless table_exists?(:active_storage_blobs)
19
+
20
+ remove_column :active_storage_blobs, :service_name
21
+ end
22
+ end
@@ -0,0 +1,28 @@
1
+ # This migration comes from active_storage (originally 20191206030411)
2
+ class CreateActiveStorageVariantRecords < ActiveRecord::Migration[6.0]
3
+ def change
4
+ return unless table_exists?(:active_storage_blobs)
5
+
6
+ # Use Active Record's configured type for primary key
7
+ create_table :active_storage_variant_records, id: primary_key_type, if_not_exists: true do |t|
8
+ t.belongs_to :blob, null: false, index: false, type: blobs_primary_key_type
9
+ t.string :variation_digest, null: false
10
+
11
+ t.index %i[blob_id variation_digest], name: "index_active_storage_variant_records_uniqueness", unique: true
12
+ t.foreign_key :active_storage_blobs, column: :blob_id
13
+ end
14
+ end
15
+
16
+ private
17
+
18
+ def primary_key_type
19
+ config = Rails.configuration.generators
20
+ config.options[config.orm][:primary_key_type] || :primary_key
21
+ end
22
+
23
+ def blobs_primary_key_type
24
+ pkey_name = connection.primary_key(:active_storage_blobs)
25
+ pkey_column = connection.columns(:active_storage_blobs).find { |c| c.name == pkey_name }
26
+ pkey_column.bigint? ? :bigint : pkey_column.type
27
+ end
28
+ end
@@ -0,0 +1,8 @@
1
+ # This migration comes from active_storage (originally 20211119233751)
2
+ class RemoveNotNullOnActiveStorageBlobsChecksum < ActiveRecord::Migration[6.0]
3
+ def change
4
+ return unless table_exists?(:active_storage_blobs)
5
+
6
+ change_column_null(:active_storage_blobs, :checksum, true)
7
+ end
8
+ end
@@ -0,0 +1,7 @@
1
+ class AddStatusToPandaCmsPages < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_enum :panda_cms_page_status, ["active", "draft", "hidden", "archived"]
4
+ add_column :panda_cms_pages, :status, :panda_cms_page_status, default: "active", null: false
5
+ add_index :panda_cms_pages, :status
6
+ end
7
+ end
@@ -0,0 +1,11 @@
1
+ class CreatePandaCmsForms < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_forms, id: :uuid do |t|
4
+ t.string :name
5
+ t.integer :submissions, default: 0
6
+ t.timestamps
7
+ end
8
+
9
+ add_index :panda_cms_forms, :name, unique: true
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ class CreatePandaCmsFormSubmissions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_form_submissions, id: :uuid do |t|
4
+ t.references :form, type: :uuid, null: false, foreign_key: {to_table: :panda_cms_forms}
5
+ t.jsonb :data, null: false, default: {}
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,27 @@
1
+ class CreatePandaCmsPosts < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_post_tags, id: :uuid do |t|
4
+ t.string :tag
5
+ t.string :description
6
+ t.string :slug
7
+ t.timestamps
8
+ t.index :tag, unique: true
9
+ t.index :slug, unique: true
10
+ end
11
+
12
+ create_table :panda_cms_posts, id: :uuid do |t|
13
+ t.string :title
14
+ t.string :slug
15
+ t.text :content
16
+ t.datetime :published_at
17
+ t.references :post_tag, type: :uuid, null: false, foreign_key: {to_table: :panda_cms_post_tags}
18
+ t.references :user, type: :uuid, null: false, foreign_key: {to_table: :panda_cms_users}
19
+ t.timestamps
20
+ t.index :slug, unique: true
21
+ end
22
+
23
+ create_enum :panda_cms_post_status, ["active", "draft", "hidden", "archived"]
24
+ add_column :panda_cms_posts, :status, :panda_cms_post_status, default: "draft", null: false
25
+ add_index :panda_cms_posts, :status
26
+ end
27
+ end
@@ -0,0 +1,14 @@
1
+ class CreatePandaCmsPostVersions < ActiveRecord::Migration[7.1]
2
+ def change
3
+ create_table :panda_cms_post_versions, id: :uuid do |t|
4
+ t.string :item_type, null: false
5
+ t.string :item_id, null: false
6
+ t.string :event, null: false
7
+ t.string :whodunnit
8
+ t.jsonb :object
9
+ t.jsonb :object_changes
10
+ t.datetime :created_at
11
+ end
12
+ add_index :panda_cms_post_versions, %i[item_type item_id]
13
+ end
14
+ end
@@ -0,0 +1,13 @@
1
+ class FixPandaCmsVisitsColumnNames < ActiveRecord::Migration[7.1]
2
+ def change
3
+ change_table :panda_cms_visits do |t|
4
+ t.rename :panda_cms_page_id, :page_id
5
+ t.rename :panda_cms_redirect_id, :redirect_id
6
+ t.rename :panda_cms_user_id, :user_id
7
+ t.string :referrer, null: true
8
+ t.datetime :visited_at
9
+ t.string :url, null: true
10
+ t.jsonb :params, null: true
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ class AddCompletionPathToPandaCmsForms < ActiveRecord::Migration[7.1]
2
+ def change
3
+ add_column :panda_cms_forms, :completion_path, :string
4
+ end
5
+ end
@@ -0,0 +1,5 @@
1
+ class ChangeFormSubmissionsToSubmissionCount < ActiveRecord::Migration[7.2]
2
+ def change
3
+ rename_column :panda_cms_forms, :submissions, :submission_count
4
+ end
5
+ end
data/db/seeds.rb ADDED
@@ -0,0 +1,4 @@
1
+ generator = PandaCms::DemoSiteGenerator.new
2
+ generator.create_templates
3
+ generator.create_pages
4
+ generator.create_menus
@@ -0,0 +1,24 @@
1
+ module Generators
2
+ module PandaCms
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ source_root File.expand_path("templates", __dir__)
5
+
6
+ namespace "panda_cms:install"
7
+ desc "Adds the basic configuration for Panda CMS to your Rails app."
8
+
9
+ def create_initializer_file
10
+ # Add the initializer
11
+ initializer_path = "config/initializers/panda_cms.rb"
12
+ unless File.exist?("#{::Rails.root}/#{initializer_path}")
13
+ FileUtils.cp "#{::PandaCms::Engine.root}/#{initializer_path}", "#{::Rails.root}/#{initializer_path}"
14
+ end
15
+
16
+ # Add the seed loader to the seeds.rb file
17
+ unless File.read("#{::Rails.root}/db/seeds.rb")&.include?("PandaCms::Engine.load_seed")
18
+ existing_seeds = File.read("#{::Rails.root}/db/seeds.rb")
19
+ IO.write("#{::Rails.root}/db/seeds.rb", "PandaCms::Engine.load_seed\n\n#{existing_seeds}")
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end