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

wip

parent a09be0a7
No related branches found
No related tags found
No related merge requests found
.offcanvas
&__redirections
@include media-breakpoint-up(md)
width: 50vw !important
\ No newline at end of file
class Admin::Communication::Websites::PermalinksController < Admin::Communication::Websites::ApplicationController
def create
@about = PolymorphicObjectFinder.find(params, :about)
@permalink = Communication::Website::Permalink.create(
website: @website,
about: @about,
is_current: false,
path: path
)
end
protected
def path
unless @path
@path = params['communication_website_permalink']['path']
# Remove eventual host
@path = URI(@path).path
# Leading slash for absolute path
@path = "/#{@path}" unless @path.start_with?('/')
# Trailing slash for coherence
@path = "#{@path}/" unless @path.end_with?('/')
end
@path
end
end
\ No newline at end of file
......@@ -50,6 +50,7 @@ class Communication::Website::Permalink < ApplicationRecord
belongs_to :about, polymorphic: true
validates :about_id, :about_type, :path, presence: true
validate :no_double_path
before_validation :set_university, on: :create
......@@ -116,6 +117,10 @@ class Communication::Website::Permalink < ApplicationRecord
end
end
def to_s
"#{path}"
end
protected
def self.required_kinds_in_website(website)
......@@ -153,4 +158,10 @@ class Communication::Website::Permalink < ApplicationRecord
self.university_id = website.university_id
end
def no_double_path
if Communication::Website::Permalink.where(about: about, path: path).any?
errors.add(:path, :uniqueness)
end
end
end
<p>
<a class="action" data-bs-toggle="offcanvas" href="#offcanvasRedirects" role="button" aria-controls="offcanvasRedirects">
<%= t('admin.communication.website.redirects.button') %>
</a>
</p>
<div class="offcanvas offcanvas-end offcanvas__redirections" tabindex="-1" id="offcanvasRedirects" aria-labelledby="Redirections">
<div class="offcanvas-header">
<h2 class="offcanvas-title"><%= t('admin.communication.website.redirects.title') %></h2>
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
</div>
<div class="offcanvas-body">
<%= osuny_panel t('admin.communication.website.redirects.current_path'), small: true do %>
<p class="lead">
<%= @page.current_permalink_in_website(@website) %>
</p>
<% end %>
<%= osuny_panel t('admin.communication.website.redirects.previous_paths'), small: true do %>
<table class="table border-top">
<tbody>
<% @page.previous_permalinks_in_website(@website).each do |link| %>
<tr>
<td><%= link.to_s %></td>
</tr>
<% end %>
</tbody>
</table>
<%= simple_form_for Communication::Website::Permalink.new,
url: admin_communication_website_permalinks_path(
about_type: about.class,
about_id: about.id
),
remote: true do |f| %>
<%= f.input :path, label: t('admin.communication.website.redirects.add_path') %>
<%= submit f %>
<% end %>
<% end %>
</div>
</div>
\ No newline at end of file
......@@ -3,6 +3,7 @@
# @pa t'affole pas, c'est pas encore le cas
%>
<%= osuny_panel t('metadata'), small: true do %>
<p>
<% if @page.is_special_page? %>
<% page_type = t("communication.website.pages.defaults.#{@page.type_key}.title") %>
<% if page_type != @page.to_s %>
......@@ -16,12 +17,12 @@
<% if @page.parent && !@page.parent.is_home? %>
dans
<%= link_to_if can?(:read, @page.parent),
<%= link_to_if can?(:read, @page.parent),
@page.parent,
admin_communication_website_page_path(
website_id: @website.id,
id: @page.parent.id
) %>.
) %>
<% end %>
<% if @page.children.any? %>
......@@ -32,12 +33,13 @@
admin_communication_website_page_path( website_id: @website.id, id: child.id),
class: "#{'draft' unless child.published?}"
}.join(', ') %>.
}.join(', ') %>
<% end %>
<% if @page.full_width %>
<br>
Pleine largeur
en pleine largeur
<% end %>
</p>
<%= render 'admin/application/permalinks/redirects', about: @page %>
<% end %>
// TODO feedback, errors, add to table
\ No newline at end of file
......@@ -218,6 +218,8 @@ en:
text: Main page text
title: Title
website: Website
communication/website/permalink:
path: Path
communication/website/post:
author: Author
category: Category
......@@ -268,6 +270,12 @@ en:
publish:
button: Publish
notice: Publication in progress, it should take a few minutes to be online.
redirects:
button: Manage redirects
title: Manage redirects
current_path: Current path
previous_paths: Redirects (old paths)
add_path: Add a redirect
communication:
authors:
one: Author
......
......@@ -218,6 +218,8 @@ fr:
text: Texte principal de la page
title: Titre
website: Site Web
communication/website/permalink:
path: Chemin
communication/website/post:
author: Auteur·rice
category: Catégorie
......@@ -268,6 +270,12 @@ fr:
publish:
button: Publier
notice: Publication en cours, cela devrait prendre quelques minutes pour arriver en ligne.
redirects:
button: Gérer les redirections
title: Gérer les redirections
current_path: Chemin actuel
previous_paths: Redirections (anciens chemins)
add_path: Ajouter une redirection
communication:
authors:
one: Auteur·rice
......
......@@ -14,6 +14,7 @@ namespace :communication do
get 'assets/*path' => 'websites/preview#assets'
resources :dependencies, controller: 'websites/dependencies', only: :index
resources :connections, controller: 'websites/connections', only: [:index, :show]
resources :permalinks, controller: 'websites/permalinks', only: :create
resources :pages, controller: 'websites/pages', path: '/:lang/pages' do
collection do
post :reorder
......
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