Skip to content
Snippets Groups Projects
Unverified Commit 48af3c82 authored by Arnaud Levy's avatar Arnaud Levy Committed by GitHub
Browse files

Merge pull request #902 from noesya/extranet_post_categories

parents aab7a0e5 cc4f23a1
No related branches found
No related tags found
No related merge requests found
Showing
with 261 additions and 16 deletions
class Admin::Communication::Extranets::Posts::CategoriesController < Admin::Communication::Extranets::ApplicationController
load_and_authorize_resource class: Communication::Extranet::Post::Category, through: :extranet, through_association: :post_categories
def index
@categories = @categories.ordered
breadcrumb
end
def show
@posts = @category.posts.ordered.page params[:page]
breadcrumb
end
def new
breadcrumb
end
def edit
breadcrumb
add_breadcrumb t('edit')
end
def create
if @category.save
redirect_to admin_communication_extranet_post_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s)
else
breadcrumb
render :new, status: :unprocessable_entity
end
end
def update
if @category.update(category_params)
redirect_to admin_communication_extranet_post_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s)
else
breadcrumb
add_breadcrumb t('edit')
render :edit, status: :unprocessable_entity
end
end
def destroy
@category.destroy
redirect_to admin_communication_extranet_post_categories_url, notice: t('admin.successfully_destroyed_html', model: @category.to_s)
end
protected
def breadcrumb
super
add_breadcrumb Communication::Extranet.human_attribute_name(:feature_posts), admin_communication_extranet_posts_path
add_breadcrumb Communication::Extranet::Post::Category.model_name.human(count: 2), admin_communication_extranet_post_categories_path
breadcrumb_for @category
end
def category_params
params.require(:communication_extranet_post_category)
.permit(
:name,
:slug,
)
.merge(
university_id: current_university.id
)
end
end
\ No newline at end of file
......@@ -3,6 +3,7 @@ class Admin::Communication::Extranets::PostsController < Admin::Communication::E
def index
@posts = @posts.ordered.page params[:page]
@categories = @extranet.post_categories.ordered
breadcrumb
end
......@@ -17,7 +18,6 @@ class Admin::Communication::Extranets::PostsController < Admin::Communication::E
end
def new
@post.extranet = @extranet
if current_user.person.present?
@post.author = current_user.person
end
......@@ -30,7 +30,6 @@ class Admin::Communication::Extranets::PostsController < Admin::Communication::E
end
def create
@post.extranet = @extranet
@post.add_photo_import params[:photo_import]
if @post.save
redirect_to admin_communication_extranet_post_path(@post), notice: t('admin.successfully_created_html', model: @post.to_s)
......@@ -70,7 +69,7 @@ class Admin::Communication::Extranets::PostsController < Admin::Communication::E
:title, :summary, :text,
:published, :published_at, :slug,
:featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit,
:author_id
:author_id, :category_id
)
.merge(
university_id: current_university.id
......
class Extranet::Posts::CategoriesController < Extranet::Posts::ApplicationController
def index
@categories = current_extranet.post_categories.ordered
breadcrumb
add_breadcrumb Communication::Extranet::Post::Category.model_name.human(count: 2)
end
def show
@category = current_extranet.post_categories.find_by slug: params[:slug]
@posts = @category.posts.ordered.page params[:page]
breadcrumb
add_breadcrumb @category
end
end
......@@ -58,6 +58,7 @@ class Communication::Extranet < ApplicationRecord
end
has_many :posts
has_many :post_categories, class_name: 'Communication::Extranet::Post::Category'
has_many :documents
validates_presence_of :name, :host
......
......@@ -13,12 +13,14 @@
# created_at :datetime not null
# updated_at :datetime not null
# author_id :uuid indexed
# category_id :uuid indexed
# extranet_id :uuid not null, indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_extranet_posts_on_author_id (author_id)
# index_communication_extranet_posts_on_category_id (category_id)
# index_communication_extranet_posts_on_extranet_id (extranet_id)
# index_communication_extranet_posts_on_university_id (university_id)
#
......@@ -26,18 +28,20 @@
#
# fk_rails_0232de42a1 (university_id => universities.id)
# fk_rails_4341823eab (extranet_id => communication_extranets.id)
# fk_rails_7827da1fd1 (category_id => communication_extranet_post_categories.id)
# fk_rails_86cc935add (author_id => university_people.id)
#
class Communication::Extranet::Post < ApplicationRecord
include Sanitizable
include WithUniversity
include WithFeaturedImage
include WithBlocks
include WithPublication
include WithPermalink
include WithSlug
include WithUniversity
belongs_to :author, class_name: 'University::Person', optional: true
belongs_to :category, class_name: 'Communication::Extranet::Post::Category', optional: true
belongs_to :extranet, class_name: 'Communication::Extranet'
validates :title, presence: true
......
# == Schema Information
#
# Table name: communication_extranet_post_categories
#
# id :uuid not null, primary key
# name :string
# slug :string
# created_at :datetime not null
# updated_at :datetime not null
# extranet_id :uuid not null, indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_extranet_post_categories_on_extranet_id (extranet_id)
# index_communication_extranet_post_categories_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_aad7b8db63 (university_id => universities.id)
# fk_rails_e53c2a25fc (extranet_id => communication_extranets.id)
#
class Communication::Extranet::Post::Category < ApplicationRecord
include WithSlug
include WithUniversity
belongs_to :extranet, class_name: 'Communication::Extranet'
has_many :posts
validates :name, presence: true
scope :ordered, -> { order(:name) }
def to_s
"#{name}"
end
protected
def slug_unavailable?(slug)
self.class.unscoped
.where(extranet_id: self.extranet_id, slug: slug)
.where.not(id: self.id)
.exists?
end
end
......@@ -3,10 +3,10 @@ module Communication::Extranet::WithFeatures
included do
FEATURES = [
:alumni,
:contacts,
:posts,
:contacts,
:library,
:alumni,
:jobs,
]
end
......
......@@ -12,16 +12,14 @@
<div class="col-md-4">
<%= osuny_panel t('metadata') do %>
<% if can? :publish, post %>
<div class="row pure__row--small">
<div class="col-6">
<%= f.input :published %>
</div>
</div>
<%= f.input :published %>
<%= f.input :published_at, html5: true, as: :date %>
<% end %>
<%= f.association :category,
collection: @extranet.post_categories.ordered %>
<%= f.association :author,
collection: @extranet.connected_persons.ordered,
label_method: :to_s_alphabetical %>
collection: @extranet.connected_persons.ordered,
label_method: :to_s_alphabetical %>
<%= f.input :slug,
as: :string,
input_html: post.persisted? ? {} : {
......
<%= simple_form_for [:admin, category] do |f| %>
<%= f.error_notification %>
<%= f.error_notification message: f.object.errors[:base].to_sentence if f.object.errors[:base].present? %>
<div class="row">
<div class="col-md-8">
<%= osuny_panel t('content') do %>
<%= f.input :name %>
<% end %>
</div>
<div class="col-md-4">
<%= osuny_panel t('metadata') do %>
<%= f.input :slug,
as: :string,
input_html: category.persisted? ? {} : {
class: 'js-slug-input',
data: { source: '#communication_extranet_post_category_name' }
} %>
<% end %>
</div>
</div>
<% content_for :action_bar_right do %>
<%= submit f %>
<% end %>
<% end %>
<div class="table-responsive">
<table class="<%= table_classes %>">
<thead>
<tr>
<th class="ps-0" width="60%"><%= Communication::Extranet::Post::Category.human_attribute_name('name') %></th>
<th></th>
</tr>
</thead>
<tbody>
<% categories.each do |category| %>
<tr>
<td class="ps-0"><%= link_to category, admin_communication_extranet_post_category_path(extranet_id: category.extranet.id, id: category.id) %></td>
<td>
<div class="btn-group" role="group">
<%= link_to t('edit'),
edit_admin_communication_extranet_post_category_path(website_id: category.id, id: category.id),
class: button_classes if can?(:update, category) %>
<%= link_to t('delete'),
admin_communication_extranet_post_category_path(extranet_id: category.extranet.id, id: category.id),
method: :delete,
data: { confirm: t('please_confirm') },
class: button_classes_danger if can?(:destroy, category) %>
</div>
</td>
</tr>
<% end %>
</tbody>
</table>
</div>
<% content_for :title, @category %>
<%= render 'admin/communication/extranets/sidebar' do %>
<%= render 'form', category: @category %>
<% end %>
<% content_for :title, Communication::Extranet::Post::Category.model_name.human(count: 2) %>
<%= render 'admin/communication/extranets/sidebar' do %>
<%= render 'admin/communication/extranets/posts/categories/list', categories: @categories %>
<% end %>
<% content_for :action_bar_right do %>
<%= create_link Communication::Extranet::Post::Category %>
<% end %>
\ No newline at end of file
<% content_for :title, Communication::Extranet::Post::Category.model_name.human %>
<%= render 'admin/communication/extranets/sidebar' do %>
<%= render 'form', category: @category %>
<% end %>
<% content_for :title, @post.title %>
<% content_for :image, kamifusen_tag(@post.featured_image) if @post.featured_image.attached? %>
<%= render 'admin/communication/blocks/preview', about: @post %>
<% content_for :title, @category %>
<%= render 'admin/communication/extranets/sidebar' do %>
<%= render 'admin/communication/extranets/posts/list', posts: @posts %>
<%= paginate @posts, theme: 'bootstrap-5' %>
<% end %>
<% content_for :action_bar_left do %>
<%= destroy_link @category %>
<% end %>
<% content_for :action_bar_right do %>
<%= edit_link @category %>
<% end %>
<% content_for :title, Communication::Extranet.human_attribute_name(:feature_posts) %>
<%= render 'admin/communication/extranets/sidebar' do %>
<%= render 'admin/communication/extranets/posts/list', posts: @posts %>
<%= paginate @posts, theme: 'bootstrap-5' %>
<section class="mb-5">
<%= render 'admin/communication/extranets/posts/list', posts: @posts %>
<%= paginate @posts, theme: 'bootstrap-5' %>
</section>
<% action = link_to t('create'), new_admin_communication_extranet_post_category_path, class: button_classes %>
<%# action = create_link Communication::Website::Category %>
<%= osuny_panel Communication::Website::Category.model_name.human(count: 2), action: action do %>
<%= render 'admin/communication/extranets/posts/categories/list', categories: @categories %>
<% end %>
<% end %>
<% content_for :action_bar_right do %>
......
......@@ -25,6 +25,10 @@
</p>
</div>
</div>
<% if @post.category %>
<%= osuny_label Communication::Extranet::Post.human_attribute_name('category') %>
<p><%= link_to @post.category, [:admin, @post.category] %></p>
<% end %>
<% if @post.author %>
<%= osuny_label Communication::Extranet::Post.human_attribute_name('author') %>
<p><%= @post.author %></p>
......
......@@ -15,4 +15,5 @@
</div>
</div>
<% end %>
</div>
\ No newline at end of file
</div>
<%= paginate @documents, theme: 'bootstrap-5' %>
\ No newline at end of file
<% content_for :title, Communication::Extranet::Post::Category.model_name.human(count: 2) %>
<ul>
<% @categories.each do |category| %>
<li><%= link_to category, posts_category_path(slug: category.slug) %></li>
<% end %>
</ul>
\ No newline at end of file
<% content_for :title, @category %>
<%= render 'extranet/posts/posts/list', posts: @posts %>
<%= paginate @posts, theme: 'bootstrap-5' %>
\ No newline at end of file
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