Skip to content
Snippets Groups Projects
Commit 97d98f7b authored by Arnaud Levy's avatar Arnaud Levy
Browse files

working parents

parent fa50abf5
No related branches found
No related tags found
No related merge requests found
Showing
with 95 additions and 37 deletions
......@@ -42,7 +42,8 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web
end
def destroy
redirect_to admin_communication_website_url, notice: t('admin.successfully_destroyed_html', model: @page.to_s)
@page.destroy
redirect_to admin_communication_website_pages_url(@website), notice: t('admin.successfully_destroyed_html', model: @page.to_s)
end
protected
......
......@@ -42,7 +42,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web
end
def destroy
@communication_website_post.destroy
@post.destroy
redirect_to admin_communication_website_posts_url, notice: t('admin.successfully_destroyed_html', model: @post.to_s)
end
......
......@@ -64,10 +64,11 @@ class Communication::Website::Imported::Page < ApplicationRecord
self.page = Communication::Website::Page.new university: university,
website: website.website, # Real website, not imported website
slug: path
self.page.title = "TMP"
self.page.title = "Untitled"
self.page.save
end
# TODO only if not modified since import
page.slug = slug
page.title = Wordpress.clean title.to_s
page.description = Wordpress.clean excerpt.to_s
page.text = Wordpress.clean content.to_s
......
......@@ -64,11 +64,12 @@ class Communication::Website::Imported::Post < ApplicationRecord
if post.nil?
self.post = Communication::Website::Post.new university: university,
website: website.website # Real website, not imported website
self.post.title = "TMP" # No title yet
self.post.title = "Untitled" # No title yet
self.post.save
end
# TODO only if not modified since import
post.title = Wordpress.clean title.to_s
post.slug = slug
post.description = Wordpress.clean excerpt.to_s
post.text = Wordpress.clean content.to_s
post.published_at = published_at if published_at
......
......@@ -45,7 +45,15 @@ class Communication::Website::Imported::Website < ApplicationRecord
page.data = data
page.save
end
# TODO parents
pages.find_each do |page|
next if page.parent.blank?
parent = pages.where(identifier: page.parent).first
next if parent.nil?
generated_page = page.page
generated_page.parent = parent.page
generated_page.save
# TODO save children
end
end
def sync_posts
......
......@@ -39,9 +39,13 @@ class Communication::Website::Page < ApplicationRecord
belongs_to :parent,
class_name: 'Communication::Website::Page',
optional: true
has_many :children,
class_name: 'Communication::Website::Page',
foreign_key: :parent_id
has_one :imported_page,
class_name: 'Communication::Website::Imported::Page',
foreign_key: :page_id
foreign_key: :page_id,
dependent: :nullify
validates :title, presence: true
......
......@@ -6,6 +6,7 @@
# description :text
# published :boolean default(FALSE)
# published_at :datetime
# slug :text
# text :text
# title :string
# created_at :datetime not null
......@@ -29,7 +30,8 @@ class Communication::Website::Post < ApplicationRecord
foreign_key: :communication_website_id
has_one :imported_post,
class_name: 'Communication::Website::Imported::Post',
foreign_key: :post_id
foreign_key: :post_id,
dependent: :nullify
scope :ordered, -> { order(published_at: :desc, created_at: :desc) }
scope :recent, -> { order(published_at: :desc).limit(5) }
......
......@@ -3,6 +3,7 @@
<tr>
<th><%= Communication::Website::Page.human_attribute_name('title') %></th>
<th><%= Communication::Website::Page.human_attribute_name('path') %></th>
<th><%= Communication::Website::Page.human_attribute_name('parent') %></th>
<th width="150"></th>
</tr>
</thead>
......@@ -11,6 +12,7 @@
<tr>
<td><%= link_to page, admin_communication_website_page_path(website_id: page.website.id, id: page.id) %></td>
<td><%= page.path %></td>
<td><%= link_to page.parent, admin_communication_website_page_path(website_id: page.website.id, id: page.parent.id) if page.parent %></td>
<td class="text-end">
<%= link_to t('edit'),
edit_admin_communication_website_page_path(website_id: page.website.id, id: page.id),
......
......@@ -24,23 +24,50 @@
<div class="card-header">
<h5 class="card-title mb-0">Metadata</h5>
</div>
<div class="card-body">
<p>
<strong>Slug</strong>
<%= @page.slug %>
</p>
<p>
<strong>Path</strong>
<%= @page.path %>
</p>
<% if @page.imported_page %>
<p>
<strong>Imported from</strong><br>
<a href="<%= @page.imported_page.url %>" target="_blank"><%= @page.imported_page.url %></a>
</p>
<% end %>
</div>
<table class="<%= table_classes %>">
<tbody>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('slug') %></td>
<td><%= @page.slug %></td>
</tr>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('path') %></td>
<td><%= @page.path %></td>
</tr>
<% if @page.imported_page %>
<tr>
<td>Imported from</td>
<td><a href="<%= @page.imported_page.url %>" target="_blank">Original URL</a></td>
</tr>
<% end %>
<% if @page.parent %>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('parent') %></td>
<td><%= link_to @page.parent,
admin_communication_website_page_path(
website_id: @website.id,
id: @page.parent.id
) %></td>
</tr>
<% end %>
<% if @page.children.any? %>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('children') %></td>
<td>
<ul class="list-unstyled mb-0">
<% @page.children.each do |child| %>
<li><%= link_to child,
admin_communication_website_page_path(
website_id: @website.id,
id: child.id
) %></li>
<% end %>
</ul>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
......
......@@ -24,18 +24,24 @@
<div class="card-header">
<h5 class="card-title mb-0">Metadata</h5>
</div>
<div class="card-body">
<p>
<strong>Published</strong>
<%= @post.published %>
</p>
<% if @post.imported_post %>
<p>
<strong>Imported from</strong>
<a href="<%= @post.imported_post.url %>" target="_blank"><%= @post.imported_post.url %></a>
</p>
<% end %>
</div>
<table class="<%= table_classes %>">
<tbody>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('slug') %></td>
<td><%= @post.slug %></td>
</tr>
<tr>
<td><%= Communication::Website::Page.human_attribute_name('published') %></td>
<td><%= @post.published %></td>
</tr>
<% if @post.imported_post %>
<tr>
<td>Imported from</td>
<td><a href="<%= @post.imported_post.url %>" target="_blank">Original URL</a></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
......
class AddSlugToCommunicationWebsitePosts < ActiveRecord::Migration[6.1]
def change
add_column :communication_website_posts, :slug, :text
end
end
......@@ -10,7 +10,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_19_092503) do
ActiveRecord::Schema.define(version: 2021_10_19_100112) do
# These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto"
......@@ -151,6 +151,7 @@ ActiveRecord::Schema.define(version: 2021_10_19_092503) do
t.datetime "published_at"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.text "slug"
t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id"
t.index ["university_id"], name: "index_communication_website_posts_on_university_id"
end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment