diff --git a/Gemfile.lock b/Gemfile.lock index d85d58665eccb63be9445b8142567f993b181461..b2c73314f932c4f9a5d11aa3d74cd627c1445fcc 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -330,7 +330,7 @@ GEM simple_form_bs5_file_input (0.0.3) rails simple_form - simple_form_password_with_hints (0.0.4) + simple_form_password_with_hints (0.0.5) rails simple_form sinatra (2.1.0) diff --git a/app/assets/stylesheets/admin/treeview.sass b/app/assets/stylesheets/admin/treeview.sass index fa8dfffbf0c3a3fb998a41db9901938e5ff182f5..929f7613f8adebb9589e033e63dad2ad5e56da91 100644 --- a/app/assets/stylesheets/admin/treeview.sass +++ b/app/assets/stylesheets/admin/treeview.sass @@ -52,8 +52,9 @@ .open_btn--without_children display: inline - & > .treeview__children .treeview__empty - display: inline + &.treeview__element--loaded + & > .treeview__children .treeview__empty + display: inline &--sortable .treeview__element diff --git a/app/controllers/admin/communication/website/categories_controller.rb b/app/controllers/admin/communication/website/categories_controller.rb index e4ed189322b48bf825a59f7a31cccf10fc940eed..b44e5031507bc4cd1f9aee91c6316cffcffb04fc 100644 --- a/app/controllers/admin/communication/website/categories_controller.rb +++ b/app/controllers/admin/communication/website/categories_controller.rb @@ -1,13 +1,30 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication::Website::ApplicationController load_and_authorize_resource class: Communication::Website::Category - include Admin::Reorderable + before_action :get_root_categories, only: [:index, :new, :create, :edit, :update] def index - @categories = @website.categories.ordered breadcrumb end + def reorder + parent_id = params['parentId'].blank? ? nil : params['parentId'] + ids = params['ids'] + ids.each.with_index do |id, index| + category = @website.categories.find(id) + category.update( + parent_id: parent_id, + position: index + 1 + ) + end + end + + def children + return unless request.xhr? + @category = @website.categories.find(params[:id]) + @children = @category.children.ordered + end + def show breadcrumb end @@ -50,6 +67,10 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication protected + def get_root_categories + @root_categories = @website.categories.root.ordered + end + def breadcrumb super add_breadcrumb Communication::Website::Category.model_name.human(count: 2), @@ -59,6 +80,6 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication def category_params params.require(:communication_website_category) - .permit(:university_id, :website_id, :name, :description) + .permit(:university_id, :website_id, :name, :description, :slug, :parent_id) end end diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 3238ed54087aed073c24b3539b264f388fc90b24..fbdae9c6831a15a1054abdf91c28a225f4a8bf26 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -4,7 +4,6 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web before_action :get_root_pages, only: [:index, :new, :create, :edit, :update] def index - breadcrumb end diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index 66cff8d0661bb0171f51bf64488eea16c95d8b35..48bf0cbcdc7abe68f13d9c8f123302ab2cacfd4b 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -22,6 +22,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati @imported_website = @website.imported_website @imported_pages = @imported_website.pages.page params[:pages_page] @imported_posts = @imported_website.posts.page params[:posts_page] + @imported_categories = @imported_website.categories @imported_media = @imported_website.media.includes(file_attachment: :blob ).page params[:media_page] @imported_media_total_size = @imported_website.media.joins(file_attachment: :blob).sum(:byte_size) breadcrumb diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 8f8fec3a190be72815628ff8da92fa582ab7be89..c1e4482a63cc429fa9fb0a002293f8f208da8593 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -6,38 +6,63 @@ # description :text # name :string # position :integer +# slug :string # created_at :datetime not null # updated_at :datetime not null # communication_website_id :uuid not null +# parent_id :uuid # university_id :uuid not null # # Indexes # # idx_communication_website_post_cats_on_communication_website_id (communication_website_id) +# index_communication_website_categories_on_parent_id (parent_id) # index_communication_website_categories_on_university_id (university_id) # # Foreign Keys # # fk_rails_... (communication_website_id => communication_websites.id) +# fk_rails_... (parent_id => communication_website_categories.id) # fk_rails_... (university_id => universities.id) # class Communication::Website::Category < ApplicationRecord + include WithSlug + include WithTree belongs_to :university belongs_to :website, foreign_key: :communication_website_id + belongs_to :parent, + class_name: 'Communication::Website::Category', + optional: true + has_one :imported_category, + class_name: 'Communication::Website::Imported::Category', + dependent: :destroy + has_many :children, + class_name: 'Communication::Website::Category', + foreign_key: :parent_id, + dependent: :destroy has_and_belongs_to_many :posts, class_name: 'Communication::Website::Post', join_table: 'communication_website_categories_posts', foreign_key: 'communication_website_category_id', association_foreign_key: 'communication_website_post_id' + validates :name, presence: true scope :ordered, -> { order(:position) } before_create :set_position + def list_of_other_categories + categories = [] + website.categories.where.not(id: id).root.ordered.each do |category| + categories.concat(category.self_and_children(0)) + end + categories.reject! { |p| p[:id] == id } + categories + end def to_s "#{name}" diff --git a/app/models/communication/website/imported/category.rb b/app/models/communication/website/imported/category.rb new file mode 100644 index 0000000000000000000000000000000000000000..f4689184d7e9061672f05343bcfe395c43198fdd --- /dev/null +++ b/app/models/communication/website/imported/category.rb @@ -0,0 +1,73 @@ +# == Schema Information +# +# Table name: communication_website_imported_categories +# +# id :uuid not null, primary key +# data :jsonb +# description :text +# identifier :string +# name :string +# parent :string +# slug :string +# url :string +# created_at :datetime not null +# updated_at :datetime not null +# category_id :uuid not null +# university_id :uuid not null +# website_id :uuid not null +# +# Indexes +# +# idx_communication_website_imported_cat_on_category (category_id) +# idx_communication_website_imported_cat_on_university (university_id) +# idx_communication_website_imported_cat_on_website (website_id) +# +# Foreign Keys +# +# fk_rails_... (category_id => communication_website_categories.id) +# fk_rails_... (university_id => universities.id) +# fk_rails_... (website_id => communication_website_imported_websites.id) +# +class Communication::Website::Imported::Category < ApplicationRecord + + belongs_to :university + belongs_to :website, + class_name: 'Communication::Website::Imported::Website' + belongs_to :category, + class_name: 'Communication::Website::Category', + optional: true + + before_validation :sync + + default_scope { order(:name) } + + def data=(value) + super value + self.url = value['link'] + self.slug = value['slug'] + self.name = value['name'] + self.description = value['description'] + self.parent = value['parent'] + end + + def to_s + "#{name}" + end + + protected + + def sync + if category.nil? + self.category = Communication::Website::Category.new university: university, + website: website.website # Real website, not imported website + self.category.name = "Untitled" # No title yet + self.category.save + end + puts "Update category #{category.id}" + sanitized_name = Wordpress.clean_string self.name.to_s + category.name = sanitized_name unless sanitized_name.blank? # If there is no title, leave it with "Untitled" + category.slug = slug + category.description = Wordpress.clean_string description.to_s + category.save + end +end diff --git a/app/models/communication/website/imported/website.rb b/app/models/communication/website/imported/website.rb index 6ff87c07c80cdf0fa74dfc41e1eebc834d304ba3..e10a5376d95ea35275fc7c967f6c9486fe6f07b5 100644 --- a/app/models/communication/website/imported/website.rb +++ b/app/models/communication/website/imported/website.rb @@ -23,6 +23,8 @@ class Communication::Website::Imported::Website < ApplicationRecord belongs_to :university belongs_to :website, class_name: 'Communication::Website' + has_many :categories, + class_name: 'Communication::Website::Imported::Category' has_many :media, class_name: 'Communication::Website::Imported::Medium' has_many :pages, @@ -31,6 +33,7 @@ class Communication::Website::Imported::Website < ApplicationRecord class_name: 'Communication::Website::Imported::Post' def run! + sync_categories sync_media sync_pages sync_posts @@ -43,6 +46,14 @@ class Communication::Website::Imported::Website < ApplicationRecord @wordpress ||= Wordpress.new website.domain_url end + def sync_categories + wordpress.categories.each do |data| + category = categories.where(university: university, identifier: data['id']).first_or_initialize + category.data = data + category.save + end + end + def sync_media wordpress.media.each do |data| medium = media.where(university: university, identifier: data['id']).first_or_initialize diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 7f2e3da5448cf75bab7511b9499578448b6114ba..e7434dc8071c843e85601bf9b9b63f2100da80a4 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -49,7 +49,8 @@ class Communication::Website::Page < ApplicationRecord optional: true has_many :children, class_name: 'Communication::Website::Page', - foreign_key: :parent_id + foreign_key: :parent_id, + dependent: :nullify validates :title, presence: true diff --git a/app/services/wordpress.rb b/app/services/wordpress.rb index 6eda98ebd7d11869424d9c327015387aac068d64..ad6add34dff068d9233ca83fb2f31a610fa00d6c 100644 --- a/app/services/wordpress.rb +++ b/app/services/wordpress.rb @@ -51,6 +51,10 @@ class Wordpress @domain = domain end + def categories + load "#{domain}/wp-json/wp/v2/categories" + end + def posts load "#{domain}/wp-json/wp/v2/posts" end diff --git a/app/views/admin/communication/website/categories/_form.html.erb b/app/views/admin/communication/website/categories/_form.html.erb index 1d988e3fa744856c5353c2aef0df3e1a7ce668c2..d1d631c95751c2c36ac48ad0ef2d1cec0b2655c7 100644 --- a/app/views/admin/communication/website/categories/_form.html.erb +++ b/app/views/admin/communication/website/categories/_form.html.erb @@ -11,6 +11,19 @@ </div> </div> </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5> + </div> + <div class="card-body"> + <%= f.input :slug, as: :string %> + <%= f.association :parent, collection: category.list_of_other_categories, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> + <ul> + </ul> + </div> + </div> + </div> </div> <% content_for :action_bar_right do %> <%= submit f %> diff --git a/app/views/admin/communication/website/categories/_list.html.erb b/app/views/admin/communication/website/categories/_list.html.erb index dad41187f932bc67d1d0a660a9a80ac7a5156b2d..6b0f36e715a7d3d4196e24c86203887c3bcc68ef 100644 --- a/app/views/admin/communication/website/categories/_list.html.erb +++ b/app/views/admin/communication/website/categories/_list.html.erb @@ -1,24 +1,24 @@ -<table class="<%= table_classes %> table-sortable"> +<table class="<%= table_classes %>"> <thead> <tr> - <% if can? :reorder, Communication::Website::Category %> - <th width="20"> </th> - <% end %> <th><%= Communication::Website::Category.human_attribute_name('title') %></th> <th></th> </tr> </thead> - <tbody data-reorder-url="<%= reorder_admin_communication_website_categories_path(@website) %>"> + <tbody> <% categories.each do |category| %> - <tr data-id="<%= category.id %>"> - <% if can? :reorder, Communication::Website::Category %> - <td><i class="fa fa-bars handle"></i></td> - <% end %> + <tr> <td><%= link_to category, admin_communication_website_category_path(website_id: category.website.id, id: category.id) %></td> <td class="text-end"> <div class="btn-group" role="group"> - <%= edit_link category %> - <%= destroy_link category %> + <%= link_to t('edit'), + edit_admin_communication_website_category_path(website_id: category.website.id, id: category.id), + class: button_classes %> + <%= link_to t('delete'), + admin_communication_website_category_path(website_id: category.website.id, id: category.id), + method: :delete, + data: { confirm: t('please-confirm') }, + class: button_classes_danger %> </div> </td> </tr> diff --git a/app/views/admin/communication/website/categories/_treebranch.html.erb b/app/views/admin/communication/website/categories/_treebranch.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..7b9b979b7977ec1d033f5e33619629a19b9b4807 --- /dev/null +++ b/app/views/admin/communication/website/categories/_treebranch.html.erb @@ -0,0 +1,28 @@ +<% categories.each do |category| %> + <li class="treeview__element js-treeview-element <%= 'treeview__element--empty' unless category.has_children? %>" data-id="<%= category.id %>" data-parent="<%= category.parent_id %>"> + <div class="d-flex align-items-center treeview__label border-bottom p-1"> + <%= link_to children_admin_communication_website_category_path(website_id: category.website.id, id: category.id), + class: 'js-treeview-openzone d-inline-block p-2 ps-0', style: 'width: 22px', remote: true do %> + <% icon_style = category.has_children? ? 'fas' : 'far' %> + <span class="open_btn"> + <i class="open_btn--with_children fas fa-folder"></i> + <i class="open_btn--without_children far fa-folder"></i> + </span> + <span class="close_btn"> + <i class="close_btn--with_children fas fa-folder-open"></i> + <i class="close_btn--without_children far fa-folder-open"></i> + </span> + <% end %> + <%= link_to category, admin_communication_website_category_path(website_id: category.website.id, id: category.id) %> + <span class="move_btn py-2 ps-2"><i class="fas fa-sort"></i></span> + </div> + <ul class="list-unstyled treeview__children js-treeview-children js-treeview-sortable-container ms-4" data-id="<%= category.id %>"> + <li class="treeview__empty"> + <div class="d-flex align-items-center treeview__label border-bottom p-1"> + <span class="p-2 ps-0"><%= t('empty_folder') %></span> + </div> + </li> + <li class="treeview__loading border-bottom p-1"><%= t('loading') %></li> + </ul> + </li> +<% end %> diff --git a/app/views/admin/communication/website/categories/children.js.erb b/app/views/admin/communication/website/categories/children.js.erb new file mode 100644 index 0000000000000000000000000000000000000000..477bb23c099562a46bf4d1544a9208aeeb6d500e --- /dev/null +++ b/app/views/admin/communication/website/categories/children.js.erb @@ -0,0 +1,8 @@ +$branch = $('.js-treeview-element[data-id=<%= @category.id %>]'); +<% if @children.any? %> + $('.js-treeview-children', $branch).append("<%= escape_javascript(render 'treebranch', categories: @children) %>"); +<% else %> + $branch.addClass('treeview__element--empty'); +<% end %> +$branch.addClass('treeview__element--loaded'); +window.osuny.treeView.initSortable(); diff --git a/app/views/admin/communication/website/categories/index.html.erb b/app/views/admin/communication/website/categories/index.html.erb index bb47a5f4750937fd78a5d7a2c2141a87ae266782..dde54f4b5d2b768fc7ae793bc2dac21a680bbbc5 100644 --- a/app/views/admin/communication/website/categories/index.html.erb +++ b/app/views/admin/communication/website/categories/index.html.erb @@ -1,6 +1,8 @@ <% content_for :title, "#{Communication::Website::Category.model_name.human(count: 2)} (#{@categories.count})" %> -<%= render 'list', categories: @categories %> +<ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container" data-id="" data-sort-url="<%= reorder_admin_communication_website_categories_path %>"> + <%= render 'treebranch', categories: @root_categories %> +</ul> <% content_for :action_bar_right do %> <%= create_link Communication::Website::Category %> diff --git a/app/views/admin/communication/website/categories/show.html.erb b/app/views/admin/communication/website/categories/show.html.erb index 96aa0af3fe3d008b278a5d1891db34d087e95f12..b8a9ac28d13544b9df06d5db517a67936fe3a024 100644 --- a/app/views/admin/communication/website/categories/show.html.erb +++ b/app/views/admin/communication/website/categories/show.html.erb @@ -1,6 +1,7 @@ <% content_for :title, @category %> <div class="row"> + <div class="col-md-8"> <div class="card flex-fill w-100"> <div class="card-header"> @@ -14,6 +15,52 @@ </div> </div> </div> + + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5> + </div> + <table class="<%= table_classes %>"> + <tbody> + <tr> + <td width="150"><%= Communication::Website::Category.human_attribute_name('slug') %></td> + <td><%= @category.slug %></td> + </tr> + <% if @category.parent %> + <tr> + <td><%= Communication::Website::Category.human_attribute_name('parent') %></td> + <td><%= link_to_if can?(:read, @category.parent), + @category.parent, + admin_communication_website_category_path( + website_id: @website.id, + id: @category.parent.id + ) %></td> + </tr> + <% end %> + <% if @category.children.any? %> + <tr> + <td><%= Communication::Website::Category.human_attribute_name('children') %></td> + <td> + <ul class="list-unstyled mb-0"> + <% @category.children.each do |child| %> + <li><%= link_to_if can?(:read, child), + child, + admin_communication_website_category_path( + website_id: @website.id, + id: child.id + ) %></li> + <% end %> + </ul> + </td> + </tr> + <% end %> + </tbody> + </table> + </div> + + </div> + </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/pages/_treebranch.html.erb b/app/views/admin/communication/website/pages/_treebranch.html.erb index cad2da67b7a6c2bc2f675c889e8deb6e7758bb38..89110854f916f8ce1db42e46ca64b4a926d4cc72 100644 --- a/app/views/admin/communication/website/pages/_treebranch.html.erb +++ b/app/views/admin/communication/website/pages/_treebranch.html.erb @@ -22,7 +22,7 @@ <span class="p-2 ps-0"><%= t('empty_folder') %></span> </div> </li> - <li class="treeview__loading"><%= t('loading') %></li> + <li class="treeview__loading border-bottom p-1"><%= t('loading') %></li> </ul> </li> <% end %> diff --git a/app/views/admin/communication/website/pages/index.html.erb b/app/views/admin/communication/website/pages/index.html.erb index ddd2e1f5d519c555a389e30c190ea858aa295c3b..5acbb551c9fd1cbd253a2e1f6a9c9661c265fd4f 100644 --- a/app/views/admin/communication/website/pages/index.html.erb +++ b/app/views/admin/communication/website/pages/index.html.erb @@ -1,6 +1,5 @@ <% content_for :title, "#{Communication::Website::Page.model_name.human(count: 2)} (#{@website.pages.count})" %> - <ul class="list-unstyled treeview treeview--sortable js-treeview js-treeview-sortable js-treeview-sortable-container" data-id="" data-sort-url="<%= reorder_admin_communication_website_pages_path %>"> <%= render 'treebranch', pages: @root_pages %> </ul> diff --git a/app/views/admin/communication/websites/import.html.erb b/app/views/admin/communication/websites/import.html.erb index 0274d1e7abccbe17f75cb18e6154133d6327e82f..0510ac65e070d605219d95b9070dc067d7b9d078 100644 --- a/app/views/admin/communication/websites/import.html.erb +++ b/app/views/admin/communication/websites/import.html.erb @@ -103,3 +103,31 @@ <%= paginate @imported_media, param_name: :media_page, theme: 'bootstrap-5' %> </div> </div> + +<div class="card mt-5"> + <div class="card-header"> + <h2><%= @imported_categories.count %> categories</h2> + </div> + <table class="<%= table_classes %>"> + <thead> + <tr> + <th><%= Communication::Website::Category.human_attribute_name('name') %></th> + <th><%= Communication::Website::Imported::Category.human_attribute_name('original') %></th> + <th class="text-end" width="150"> </th> + </tr> + </thead> + <tbody> + <% @imported_categories.each do |category| %> + <tr> + <td><%= category.name %></td> + <td class="small"><%= link_to category.url, category.url, target: :_blank %></td> + <td class="text-end"> + <%= link_to t('show'), + admin_communication_website_category_path(website_id: category.category.website.id, id: category.category.id), + class: button_classes %> + </td> + </tr> + <% end %> + </tbody> + </table> +</div> diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 950960f1fb67b6f65c28b19c30fd25f8b18b536b..1d2fe5e25b8413d1dc7aa450671470e599981801 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -10,49 +10,30 @@ <% end %> <% end %> -<div class="card mt-5"> - <div class="card-header"> - <div class="float-end"> - <%= link_to_if can?(:create, Communication::Website::Post), - t('create'), - new_admin_communication_website_post_path(website_id: @website), - class: button_classes %> - </div> - <h2 class="card-title"> - <%= link_to admin_communication_website_posts_path(website_id: @website) do %> - <%= t('communication.website.last_posts') %> - <small> - - - <%= t('communication.website.see_all', number: @website.posts.count) %> - </small> - <% end %> - </h2> - </div> - <%= render 'admin/communication/website/posts/list', posts: @website.posts.recent %> -</div> - <div class="row"> <div class="col-md-7"> <div class="card mt-5"> <div class="card-header"> <div class="float-end"> - <%= link_to t('create'), - new_admin_communication_website_page_path(website_id: @website), + <%= link_to_if can?(:create, Communication::Website::Post), + t('create'), + new_admin_communication_website_post_path(website_id: @website), class: button_classes %> </div> <h2 class="card-title"> - <%= link_to admin_communication_website_pages_path(website_id: @website) do %> - <%= t('communication.website.last_pages') %> + <%= link_to admin_communication_website_posts_path(website_id: @website) do %> + <%= t('communication.website.last_posts') %> <small> - - <%= t('communication.website.see_all', number: @website.pages.count) %> + <%= t('communication.website.see_all', number: @website.posts.count) %> </small> <% end %> </h2> </div> - <%= render 'admin/communication/website/pages/list', pages: @website.pages.recent %> + <%= render 'admin/communication/website/posts/list', posts: @website.posts.recent %> </div> </div> + <div class="col-md-5"> <div class="card mt-5"> <div class="card-header"> @@ -71,11 +52,37 @@ <% end %> </h2> </div> - <%= render 'admin/communication/website/categories/list', categories: @website.categories.ordered %> + <%= render 'admin/communication/website/categories/list', categories: @website.categories.root.ordered %> + </div> + </div> +</div> + +<div class="row"> + <div class="col-md-12"> + <div class="card mt-5"> + <div class="card-header"> + <div class="float-end"> + <%= link_to t('create'), + new_admin_communication_website_page_path(website_id: @website), + class: button_classes %> + </div> + <h2 class="card-title"> + <%= link_to admin_communication_website_pages_path(website_id: @website) do %> + <%= t('communication.website.last_pages') %> + <small> + - + <%= t('communication.website.see_all', number: @website.pages.count) %> + </small> + <% end %> + </h2> + </div> + <%= render 'admin/communication/website/pages/list', pages: @website.pages.recent %> </div> </div> </div> + + <% content_for :action_bar_right do %> <% if @website.imported? %> <%= link_to t('communication.website.imported.show'), diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 52cb38cbc2ef08eed38723a066b8b39b4281a61d..0805e93a70dfdb3a057e729a997a7dd3fe8da131 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -50,22 +50,30 @@ en: about_Research::Journal: Journal website about_Education::School: School website communication/website/category: + children: Children categories description: Description - title: Title + name: Name + parent: Parent category + slug: slug + communication/website/imported/category: + original: Original communication/website/imported/medium: filename: Filename communication/website/page: + children: Children pages title: Title description: Description (SEO) featured_image: Featured image text: Text published: Published ? parent: Parent page + slug: slug website: Website communication/website/post: title: Title description: Description (SEO) featured_image: Featured image + slug: slug text: Text published: Published ? published_at: Publication date diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index ae1d3c0a4f86a07cd299721e0e2c94c358e094c4..341b927163c7485be7369432bd5dc563b897c989 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -49,15 +49,22 @@ fr: about_Research::Journal: Site de revue scientifique about_Education::School: Site d'école communication/website/category: + children: Catégories enfantes description: Description - title: Titre + name: Nom + parent: Catégorie parente + slug: slug + communication/website/imported/category: + original: Original communication/website/imported/medium: filename: Nom du fichier communication/website/page: + children: Pages enfantes description: Description (SEO) featured_image: Image à la une parent: Page parente published: Publié ? + slug: slug text: Texte title: Titre website: Site Web @@ -67,6 +74,7 @@ fr: featured_image: Image à la une published: Publié ? published_at: Date de publication + slug: slug text: Texte title: Titre website: Site Web diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index ece4457558c25348270668532e66de271dab4e7d..436bbdbb239629163535a325025ae4ebcdc72494 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -16,6 +16,9 @@ namespace :communication do collection do post :reorder end + member do + get :children + end end resources :posts, controller: 'website/posts' end diff --git a/db/migrate/20211027120202_create_communication_website_imported_category.rb b/db/migrate/20211027120202_create_communication_website_imported_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..a05e130c0e36e51d99c29340cb7a5b5d7ce1bcd8 --- /dev/null +++ b/db/migrate/20211027120202_create_communication_website_imported_category.rb @@ -0,0 +1,31 @@ +class CreateCommunicationWebsiteImportedCategory < ActiveRecord::Migration[6.1] + def change + create_table :communication_website_imported_categories, id: :uuid do |t| + t.references :university, + null: false, + foreign_key: true, + type: :uuid, + index: { name: 'idx_communication_website_imported_cat_on_university' } + t.references :website, + null: false, + foreign_key: { to_table: :communication_website_imported_websites }, + type: :uuid, + index: { name: 'idx_communication_website_imported_cat_on_website' } + t.references :category, + null: false, + foreign_key: { to_table: :communication_website_categories }, + type: :uuid, + index: { name: 'idx_communication_website_imported_cat_on_category' } + + t.string :name + t.text :description + t.string :identifier + t.string :slug + t.string :url + t.string :parent + + + t.timestamps + end + end +end diff --git a/db/migrate/20211027125123_add_infos_to_communication_website_category.rb b/db/migrate/20211027125123_add_infos_to_communication_website_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..52c519ea23baf9f6e208d156174aeb031063db07 --- /dev/null +++ b/db/migrate/20211027125123_add_infos_to_communication_website_category.rb @@ -0,0 +1,7 @@ +class AddInfosToCommunicationWebsiteCategory < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_categories, :slug, :string + add_reference :communication_website_categories, :parent, foreign_key: { to_table: :communication_website_categories }, type: :uuid + + end +end diff --git a/db/migrate/20211027131939_add_data_to_imported_category.rb b/db/migrate/20211027131939_add_data_to_imported_category.rb new file mode 100644 index 0000000000000000000000000000000000000000..a6d7ecfb3fb108f1e92086272a70561a2a2eeba4 --- /dev/null +++ b/db/migrate/20211027131939_add_data_to_imported_category.rb @@ -0,0 +1,5 @@ +class AddDataToImportedCategory < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_imported_categories, :data, :jsonb + end +end diff --git a/db/schema.rb b/db/schema.rb index 3b75d9b9f394c2c1f2e1f9c1611697d822dbdb7b..f07df88c2f8e043f1464f7ef7ae043ffd78b9afa 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_10_26_142142) do +ActiveRecord::Schema.define(version: 2021_10_27_131939) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -86,7 +86,10 @@ ActiveRecord::Schema.define(version: 2021_10_26_142142) do t.integer "position" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.string "slug" + t.uuid "parent_id" t.index ["communication_website_id"], name: "idx_communication_website_post_cats_on_communication_website_id" + t.index ["parent_id"], name: "index_communication_website_categories_on_parent_id" t.index ["university_id"], name: "index_communication_website_categories_on_university_id" end @@ -97,6 +100,24 @@ ActiveRecord::Schema.define(version: 2021_10_26_142142) do t.index ["communication_website_post_id", "communication_website_category_id"], name: "post_category" end + create_table "communication_website_imported_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.uuid "university_id", null: false + t.uuid "website_id", null: false + t.uuid "category_id", null: false + t.string "name" + t.text "description" + t.string "identifier" + t.string "slug" + t.string "url" + t.string "parent" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + t.jsonb "data" + t.index ["category_id"], name: "idx_communication_website_imported_cat_on_category" + t.index ["university_id"], name: "idx_communication_website_imported_cat_on_university" + t.index ["website_id"], name: "idx_communication_website_imported_cat_on_website" + end + create_table "communication_website_imported_media", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "identifier" t.jsonb "data" @@ -405,8 +426,12 @@ ActiveRecord::Schema.define(version: 2021_10_26_142142) do add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" add_foreign_key "active_storage_variant_records", "active_storage_blobs", column: "blob_id" add_foreign_key "administration_qualiopi_indicators", "administration_qualiopi_criterions", column: "criterion_id" + add_foreign_key "communication_website_categories", "communication_website_categories", column: "parent_id" add_foreign_key "communication_website_categories", "communication_websites" add_foreign_key "communication_website_categories", "universities" + add_foreign_key "communication_website_imported_categories", "communication_website_categories", column: "category_id" + add_foreign_key "communication_website_imported_categories", "communication_website_imported_websites", column: "website_id" + add_foreign_key "communication_website_imported_categories", "universities" add_foreign_key "communication_website_imported_media", "communication_website_imported_websites", column: "website_id" add_foreign_key "communication_website_imported_media", "universities" add_foreign_key "communication_website_imported_pages", "communication_website_imported_media", column: "featured_medium_id"