Skip to content
Snippets Groups Projects
Commit b9f1a496 authored by pabois's avatar pabois
Browse files

wip authors

parent 890359c0
No related branches found
No related tags found
No related merge requests found
Showing
with 306 additions and 14 deletions
class Admin::Communication::Website::AuthorsController < Admin::Communication::Website::ApplicationController
load_and_authorize_resource class: Communication::Website::Author
def index
@authors = @website.authors.ordered.page(params[:page])
breadcrumb
end
def show
breadcrumb
end
def new
@author.website = @website
breadcrumb
end
def edit
breadcrumb
add_breadcrumb t('edit')
end
def create
@author.university = current_university
@author.website = @website
if @author.save
redirect_to admin_communication_website_author_path(@author), notice: t('admin.successfully_created_html', model: @author.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
end
end
def update
if @author.update(author_params)
redirect_to admin_communication_website_author_path(@author), notice: t('admin.successfully_updated_html', model: @author.to_s)
else
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_entity
end
end
def destroy
@author.destroy
redirect_to admin_communication_website_authors_url, notice: t('admin.successfully_destroyed_html', model: @author.to_s)
end
protected
def breadcrumb
super
add_breadcrumb Communication::Website::Author.model_name.human(count: 2),
admin_communication_website_authors_path
breadcrumb_for @author
end
def author_params
params.require(:communication_website_author)
.permit(:university_id, :website_id, :first_name, :last_name, :biography, :slug, :user_id)
end
end
...@@ -25,9 +25,20 @@ ...@@ -25,9 +25,20 @@
class Communication::Website < ApplicationRecord class Communication::Website < ApplicationRecord
belongs_to :university belongs_to :university
belongs_to :about, polymorphic: true, optional: true belongs_to :about, polymorphic: true, optional: true
has_many :pages, foreign_key: :communication_website_id has_many :pages,
has_many :posts, foreign_key: :communication_website_id foreign_key: :communication_website_id,
has_many :categories, class_name: 'Communication::Website::Category', foreign_key: :communication_website_id dependent: :destroy
has_many :posts,
foreign_key: :communication_website_id,
dependent: :destroy
has_many :categories,
class_name: 'Communication::Website::Category',
foreign_key: :communication_website_id,
dependent: :destroy
has_many :authors,
class_name: 'Communication::Website::Author',
foreign_key: :communication_website_id,
dependent: :destroy
has_one :imported_website, has_one :imported_website,
class_name: 'Communication::Website::Imported::Website', class_name: 'Communication::Website::Imported::Website',
dependent: :destroy dependent: :destroy
......
# == Schema Information
#
# Table name: communication_website_authors
#
# id :uuid not null, primary key
# first_name :string
# last_name :string
# slug :string
# created_at :datetime not null
# updated_at :datetime not null
# communication_website_id :uuid not null
# university_id :uuid not null
# user_id :uuid
#
# Indexes
#
# idx_comm_website_authors_on_communication_website_id (communication_website_id)
# index_communication_website_authors_on_university_id (university_id)
# index_communication_website_authors_on_user_id (user_id)
#
# Foreign Keys
#
# fk_rails_... (communication_website_id => communication_websites.id)
# fk_rails_... (university_id => universities.id)
# fk_rails_... (user_id => users.id)
#
class Communication::Website::Author < ApplicationRecord
include WithSlug
has_rich_text :biography
belongs_to :university
belongs_to :user, optional: true
belongs_to :website,
foreign_key: :communication_website_id
scope :ordered, -> { order(:last_name, :first_name) }
def to_s
"#{last_name} #{first_name}"
end
end
...@@ -61,7 +61,8 @@ class User < ApplicationRecord ...@@ -61,7 +61,8 @@ class User < ApplicationRecord
belongs_to :university belongs_to :university
belongs_to :language belongs_to :language
has_one :researcher, class_name: 'Research::Researcher' has_one :researcher, class_name: 'Research::Researcher', dependent: :nullify
has_one :auhtor, class_name: 'Communication::Website::Author', dependent: :nullify
scope :ordered, -> { order(:last_name, :first_name) } scope :ordered, -> { order(:last_name, :first_name) }
......
<%= simple_form_for [:admin, author] do |f| %>
<div class="row">
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= t('communication.website.content') %></h5>
</div>
<div class="card-body">
<%= f.input :first_name %>
<%= f.input :last_name %>
<%= f.input :biography, as: :rich_text_area %>
</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 if author.persisted? %>
<%= f.association :user, collection: current_university.users.ordered %>
<ul>
</ul>
</div>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= submit f %>
<% end %>
<% end %>
<table class="<%= table_classes %>">
<thead>
<tr>
<th><%= Communication::Website::Author.human_attribute_name('name') %></th>
<th></th>
</tr>
</thead>
<tbody>
<% authors.each do |author| %>
<tr>
<td><%= link_to author, admin_communication_website_author_path(website_id: author.website.id, id: author.id) %></td>
<td class="text-end">
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_communication_website_author_path(website_id: author.website.id, id: author.id),
class: button_classes %>
<%= link_to t('delete'),
admin_communication_website_author_path(website_id: author.website.id, id: author.id),
method: :delete,
data: { confirm: t('please-confirm') },
class: button_classes_danger %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
<% content_for :title, @author %>
<%= render 'form', author: @author %>
<% content_for :title, "#{Communication::Website::Author.model_name.human(count: 2)} (#{@authors.total_count})" %>
<%= render 'admin/communication/website/authors/list', authors: @authors %>
<%= paginate @authors, theme: 'bootstrap-5' %>
<% content_for :action_bar_right do %>
<%= create_link Communication::Website::Author %>
<% end %>
<% content_for :title, Communication::Website::Author.model_name.human %>
<%= render 'form', author: @author %>
<% content_for :title, @author %>
<div class="row">
<div class="col-md-8">
<div class="card flex-fill w-100">
<div class="card-header">
<h5 class="card-title mb-0"><%= t('communication.website.content') %></h5>
</div>
<div class="card-body">
<p>
<strong><%= Communication::Website::Author.human_attribute_name('biography') %></strong>
</p>
<%= sanitize @author.biography %>
</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::Author.human_attribute_name('slug') %></td>
<td><%= @author.slug %></td>
</tr>
<% if @author.user %>
<tr>
<td width="150"><%= Communication::Website::Author.human_attribute_name('user') %></td>
<td><%= link_to_if can?(:read, @author.user), @author.user, admin_user_path(@author.user) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
</div>
</div>
<% content_for :action_bar_right do %>
<%= edit_link @author %>
<% end %>
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5> <h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<%= f.input :slug, as: :string %> <%= f.input :slug, as: :string if category.persisted? %>
<%= f.association :parent, collection: category.list_of_other_categories, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <%= f.association :parent, collection: category.list_of_other_categories, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %>
<ul> <ul>
</ul> </ul>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5> <h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<%= f.input :slug, as: :string %> <%= f.input :slug, as: :string if page.persisted? %>
<%= f.input :published %> <%= f.input :published %>
<%= f.association :parent, collection: page.list_of_other_pages, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %> <%= f.association :parent, collection: page.list_of_other_pages, label_method: ->(p) { sanitize p[:label] }, value_method: ->(p) { p[:id] } %>
<ul> <ul>
......
...@@ -18,7 +18,7 @@ ...@@ -18,7 +18,7 @@
<h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5> <h5 class="card-title mb-0"><%= t('communication.website.metadata') %></h5>
</div> </div>
<div class="card-body"> <div class="card-body">
<%= f.input :slug, as: :string %> <%= f.input :slug, as: :string if post.persisted? %>
<%= f.input :published %> <%= f.input :published %>
<%= f.input :published_at, html5: true %> <%= f.input :published_at, html5: true %>
<%= f.association :categories, as: :check_boxes if @website.categories.any? %> <%= f.association :categories, as: :check_boxes if @website.categories.any? %>
......
...@@ -25,6 +25,9 @@ en: ...@@ -25,6 +25,9 @@ en:
communication/website: communication/website:
one: Website one: Website
other: Websites other: Websites
communication/website/author:
one: Author
other: Authors
communication/website/category: communication/website/category:
one: Category one: Category
other: Categories other: Categories
...@@ -49,12 +52,19 @@ en: ...@@ -49,12 +52,19 @@ en:
about_: Independent website (no specific subject) about_: Independent website (no specific subject)
about_Research::Journal: Journal website about_Research::Journal: Journal website
about_Education::School: School website about_Education::School: School website
communication/website/author:
biography: Biography
first_name: First name
last_name: Last name
name: Name
slug: Slug
user: User
communication/website/category: communication/website/category:
children: Children categories children: Children categories
description: Description description: Description
name: Name name: Name
parent: Parent category parent: Parent category
slug: slug slug: Slug
communication/website/imported/category: communication/website/imported/category:
original: Original original: Original
communication/website/imported/medium: communication/website/imported/medium:
...@@ -67,13 +77,13 @@ en: ...@@ -67,13 +77,13 @@ en:
text: Text text: Text
published: Published ? published: Published ?
parent: Parent page parent: Parent page
slug: slug slug: Slug
website: Website website: Website
communication/website/post: communication/website/post:
title: Title title: Title
description: Description (SEO) description: Description (SEO)
featured_image: Featured image featured_image: Featured image
slug: slug slug: Slug
text: Text text: Text
published: Published ? published: Published ?
published_at: Publication date published_at: Publication date
......
...@@ -25,6 +25,9 @@ fr: ...@@ -25,6 +25,9 @@ fr:
communication/website: communication/website:
one: Site Web one: Site Web
other: Sites Web other: Sites Web
communication/website/author:
one: Auteur
other: Auteurs
communication/website/category: communication/website/category:
one: Catégorie one: Catégorie
other: Catégories other: Catégories
...@@ -48,12 +51,19 @@ fr: ...@@ -48,12 +51,19 @@ fr:
about_: Site indépendant (aucun sujet) about_: Site indépendant (aucun sujet)
about_Research::Journal: Site de revue scientifique about_Research::Journal: Site de revue scientifique
about_Education::School: Site d'école about_Education::School: Site d'école
communication/website/author:
biography: Biographie
first_name: Prénom
last_name: Nom de famille
name: Nom
slug: Slug
user: Utilisateur
communication/website/category: communication/website/category:
children: Catégories enfantes children: Catégories enfantes
description: Description description: Description
name: Nom name: Nom
parent: Catégorie parente parent: Catégorie parente
slug: slug slug: Slug
communication/website/imported/category: communication/website/imported/category:
original: Original original: Original
communication/website/imported/medium: communication/website/imported/medium:
...@@ -64,7 +74,7 @@ fr: ...@@ -64,7 +74,7 @@ fr:
featured_image: Image à la une featured_image: Image à la une
parent: Page parente parent: Page parente
published: Publié ? published: Publié ?
slug: slug slug: Slug
text: Texte text: Texte
title: Titre title: Titre
website: Site Web website: Site Web
...@@ -74,7 +84,7 @@ fr: ...@@ -74,7 +84,7 @@ fr:
featured_image: Image à la une featured_image: Image à la une
published: Publié ? published: Publié ?
published_at: Date de publication published_at: Date de publication
slug: slug slug: Slug
text: Texte text: Texte
title: Titre title: Titre
website: Site Web website: Site Web
......
...@@ -20,6 +20,7 @@ namespace :communication do ...@@ -20,6 +20,7 @@ namespace :communication do
get :children get :children
end end
end end
resources :authors, controller: 'website/authors'
resources :posts, controller: 'website/posts' resources :posts, controller: 'website/posts'
end end
end end
class CreateCommunicationWebsiteAuthors < ActiveRecord::Migration[6.1]
def change
create_table :communication_website_authors, id: :uuid do |t|
t.references :university, null: false, foreign_key: true, type: :uuid
t.references :user, foreign_key: true, type: :uuid
t.references :communication_website,
null: false,
foreign_key: { to_table: :communication_websites },
type: :uuid,
index: { name: 'idx_comm_website_authors_on_communication_website_id' }
t.string :last_name
t.string :first_name
t.string :slug
t.timestamps
end
end
end
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 2021_10_27_131939) do ActiveRecord::Schema.define(version: 2021_10_28_090402) do
# These are extensions that must be enabled in order to support this database # These are extensions that must be enabled in order to support this database
enable_extension "pgcrypto" enable_extension "pgcrypto"
...@@ -78,6 +78,20 @@ ActiveRecord::Schema.define(version: 2021_10_27_131939) do ...@@ -78,6 +78,20 @@ ActiveRecord::Schema.define(version: 2021_10_27_131939) do
t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id" t.index ["criterion_id"], name: "index_administration_qualiopi_indicators_on_criterion_id"
end end
create_table "communication_website_authors", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false
t.uuid "user_id"
t.uuid "communication_website_id", null: false
t.string "last_name"
t.string "first_name"
t.string "slug"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false
t.index ["communication_website_id"], name: "idx_comm_website_authors_on_communication_website_id"
t.index ["university_id"], name: "index_communication_website_authors_on_university_id"
t.index ["user_id"], name: "index_communication_website_authors_on_user_id"
end
create_table "communication_website_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| create_table "communication_website_categories", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t|
t.uuid "university_id", null: false t.uuid "university_id", null: false
t.uuid "communication_website_id", null: false t.uuid "communication_website_id", null: false
...@@ -426,6 +440,9 @@ ActiveRecord::Schema.define(version: 2021_10_27_131939) do ...@@ -426,6 +440,9 @@ ActiveRecord::Schema.define(version: 2021_10_27_131939) do
add_foreign_key "active_storage_attachments", "active_storage_blobs", column: "blob_id" 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 "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 "administration_qualiopi_indicators", "administration_qualiopi_criterions", column: "criterion_id"
add_foreign_key "communication_website_authors", "communication_websites"
add_foreign_key "communication_website_authors", "universities"
add_foreign_key "communication_website_authors", "users"
add_foreign_key "communication_website_categories", "communication_website_categories", column: "parent_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", "communication_websites"
add_foreign_key "communication_website_categories", "universities" add_foreign_key "communication_website_categories", "universities"
......
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