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

Merge branch 'master' of github.com:noesya/osuny

parents 56104ea6 198792ca
No related branches found
No related tags found
No related merge requests found
Showing
with 178 additions and 31 deletions
class Admin::Communication::Website::BlocksController < Admin::Communication::Website::ApplicationController
load_and_authorize_resource class: Communication::Website::Block, through: :website
class Admin::Communication::BlocksController < Admin::Communication::ApplicationController
load_and_authorize_resource class: Communication::Block
def reorder
ids = params[:ids] || []
first_page = nil
ids.each.with_index do |id, index|
block = @website.blocks.find(id)
block = current_university.communication_blocks.find(id)
block.update position: index + 1
end
end
......@@ -25,8 +24,7 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We
end
def create
@block.university = @website.university
@block.website = @website
@block.university = current_university
if @block.save
redirect_to [:edit, :admin, @block], notice: t('admin.successfully_created_html', model: @block.to_s)
else
......@@ -37,7 +35,7 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We
def update
if @block.update(block_params)
@block.about.save_and_sync
redirect_to [:admin, @block.about], notice: t('admin.successfully_updated_html', model: @block.to_s)
redirect_to about_path, notice: t('admin.successfully_updated_html', model: @block.to_s)
else
render :edit, status: :unprocessable_entity
end
......@@ -51,20 +49,30 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We
protected
def website_id
params[:website_id] || @block.about&.website.id
rescue
end
def about_path
# La formation ou la page concernée
path_method = "admin_#{@block.about.class.to_s.parameterize.underscore}_path"
send path_method, id: @block.about_id, website_id: website_id
end
def breadcrumb
super
add_breadcrumb @block.about.model_name.human(count: 2), [:admin, @block.about.class]
add_breadcrumb @block.about, [:admin, @block.about]
short_breadcrumb
add_breadcrumb @block.about, about_path
# Le block
if @block.new_record?
add_breadcrumb t('communication.website.block.choose_template')
add_breadcrumb t('communication.block.choose_template')
else
add_breadcrumb @block
end
end
def block_params
params.require(:communication_website_block)
params.require(:communication_block)
.permit(:about_id, :about_type, :template, :data)
end
end
# == Schema Information
#
# Table name: communication_website_blocks
# Table name: communication_blocks
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# data :jsonb
# position :integer default(0), not null
# template :integer default(NULL), not null
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# communication_website_id :uuid not null, indexed
# university_id :uuid not null, indexed
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# data :jsonb
# position :integer default(0), not null
# template :integer default(NULL), not null
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_website_blocks_on_about (about_type,about_id)
# index_communication_website_blocks_on_communication_website_id (communication_website_id)
# index_communication_website_blocks_on_university_id (university_id)
# index_communication_blocks_on_university_id (university_id)
# index_communication_website_blocks_on_about (about_type,about_id)
#
# Foreign Keys
#
# fk_rails_18291ef65f (university_id => universities.id)
# fk_rails_75bd7c8d6c (communication_website_id => communication_websites.id)
#
class Communication::Website::Block < ApplicationRecord
class Communication::Block < ApplicationRecord
include WithPosition
belongs_to :university
belongs_to :website, foreign_key: :communication_website_id
belongs_to :about, polymorphic: true
enum template: {
......
# == Schema Information
#
# Table name: communication_websites
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# access_token :string
# git_provider :integer default("github")
# name :string
# repository :string
# static_pathname_administrators :string default("administrators")
# static_pathname_authors :string default("authors")
# static_pathname_posts :string default("posts")
# static_pathname_programs :string default("programs")
# static_pathname_research_articles :string default("articles")
# static_pathname_research_volumes :string default("volumes")
# static_pathname_researchers :string default("researchers")
# static_pathname_staff :string default("staff")
# static_pathname_teachers :string default("teachers")
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_websites_on_about (about_type,about_id)
# index_communication_websites_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_bb6a496c08 (university_id => universities.id)
#
class Communication::Website::Configs::BaseUrl < Communication::Website
def self.polymorphic_name
......
# == Schema Information
#
# Table name: communication_websites
#
# id :uuid not null, primary key
# about_type :string indexed => [about_id]
# access_token :string
# git_provider :integer default("github")
# name :string
# repository :string
# static_pathname_administrators :string default("administrators")
# static_pathname_authors :string default("authors")
# static_pathname_posts :string default("posts")
# static_pathname_programs :string default("programs")
# static_pathname_research_articles :string default("articles")
# static_pathname_research_volumes :string default("volumes")
# static_pathname_researchers :string default("researchers")
# static_pathname_staff :string default("staff")
# static_pathname_teachers :string default("teachers")
# url :string
# created_at :datetime not null
# updated_at :datetime not null
# about_id :uuid indexed => [about_type]
# university_id :uuid not null, indexed
#
# Indexes
#
# index_communication_websites_on_about (about_type,about_id)
# index_communication_websites_on_university_id (university_id)
#
# Foreign Keys
#
# fk_rails_bb6a496c08 (university_id => universities.id)
#
class Communication::Website::Configs::Permalinks < Communication::Website
def self.polymorphic_name
......
......@@ -2,7 +2,7 @@ module WithBlocks
extend ActiveSupport::Concern
included do
has_many :blocks, as: :about
has_many :blocks, as: :about, class_name: 'Communication::Block'
end
def git_block_dependencies
......
......@@ -51,6 +51,7 @@ class Education::Program < ApplicationRecord
include WithTree
include WithInheritance
include WithPosition
include WithBlocks
rich_text_areas_with_inheritance :accessibility,
:contacts,
......
......@@ -3,5 +3,6 @@ module University::WithCommunication
included do
has_many :communication_websites, class_name: 'Communication::Website', dependent: :destroy
has_many :communication_blocks, class_name: 'Communication::Block', dependent: :destroy
end
end
......@@ -2,27 +2,27 @@
<div class="card-header">
<div class="float-end">
<%= link_to t('add'),
new_admin_communication_website_block_path(about_id: about.id, about_type: about.class.name),
new_admin_communication_block_path(about_id: about.id, about_type: about.class.name),
class: button_classes %>
</div>
<h2 class="card-title mb-0 h5">
<%= Communication::Website::Block.model_name.human(count: 2) %>
<%= Communication::Block.model_name.human(count: 2) %>
</h2>
</div>
<table class="<%= table_classes %>">
<thead>
<tr>
<th width="20" class="ps-0">&nbsp;</th>
<th><%= Communication::Website::Block.human_attribute_name('name') %></th>
<th><%= Communication::Website::Block.human_attribute_name('template') %></th>
<th><%= Communication::Block.human_attribute_name('name') %></th>
<th><%= Communication::Block.human_attribute_name('template') %></th>
<th></th>
</tr>
</thead>
<tbody data-sortable data-sort-url="<%= reorder_admin_communication_website_blocks_path %>">
<tbody data-sortable data-sort-url="<%= reorder_admin_communication_blocks_path %>">
<% about.blocks.ordered.each do |block| %>
<tr data-id="<%= block.id %>">
<td><i class="fa fa-bars handle"></i></td>
<td><%= link_to block, admin_communication_website_block_path(block) %></td>
<td><%= link_to block, admin_communication_block_path(block) %></td>
<td><%= block.template_i18n %></td>
<td class="text-end">
<%= edit_link block %>
......
......@@ -3,5 +3,5 @@ blocks:
<% about.blocks.each do |block| %>
- template: <%= block.template %>
data:
<%= render "admin/communication/website/blocks/templates/#{block.template}/static", block: block if block.data %><% end %>
<%= render "admin/communication/blocks/templates/#{block.template}/static", block: block if block.data %><% end %>
<% end %>
......@@ -5,8 +5,8 @@
%>
<div id="app">
<%= simple_form_for [:admin, @block] do |f| %>
<%= render "admin/communication/website/blocks/templates/#{@block.template}/edit", f: f %>
<textarea name="communication_website_block[data]" rows="20" cols="200" class="d-none">
<%= render "admin/communication/blocks/templates/#{@block.template}/edit", f: f %>
<textarea name="communication_block[data]" rows="20" cols="200" class="d-none">
{{ JSON.stringify(data) }}
</textarea>
<% content_for :action_bar_right do %>
......@@ -24,7 +24,7 @@
draggable: VueDraggableNext.VueDraggableNext,
},
data() {
return {
return {
directUpload: {
url: "<%= rails_direct_uploads_url.html_safe %>",
blobUrlTemplate: "<%= rails_service_blob_url(":signed_id", ":filename").html_safe %>"
......
<% content_for :title, t('communication.website.block.choose_template') %>
<% content_for :title, t('communication.block.choose_template') %>
<div class="row">
<% Communication::Website::Block.templates.keys.each do |template| %>
<% Communication::Block.templates.keys.each do |template| %>
<% @block.template = template %>
<div class="col-lg-3 col-md-4">
<div class="card">
<% asset = "communication/websites/blocks/templates/#{template}.jpg" %>
<% asset = "communication/blocks/templates/#{template}.jpg" %>
<%= image_tag asset, alt: '' if Rails.application.assets.find_asset(asset) %>
<div class="card-body">
<h5 class="card-title"><%= t "enums.communication.website.block.template.#{template}" %></h5>
<h5 class="card-title"><%= t "enums.communication.block.template.#{template}" %></h5>
<%= simple_form_for [:admin, @block] do |f| %>
<%= f.input :about_type, as: :hidden %>
<%= f.input :about_id, as: :hidden %>
<%= f.input :template, as: :hidden %>
<%= f.submit t('communication.website.block.choose'),
<%= f.submit t('communication.block.choose'),
class: button_classes('stretched-link') %>
<% end %>
</div>
......
<% content_for :title, @block %>
<%= render "admin/communication/website/blocks/templates/#{@block.template}/show" %>
<%= render "admin/communication/blocks/templates/#{@block.template}/show" %>
<% content_for :action_bar_right do %>
<%= edit_link @block %>
......
......@@ -46,7 +46,7 @@
</div>
<div class="col-md-5">
<select class="form-select select" v-model="person.id">
<% @website.university.people.ordered.each_with_index do |person, index| %>
<% current_university.people.ordered.each_with_index do |person, index| %>
<option value="<%= person.id %>"><%= person.last_name %>, <%= person.first_name %></option>
<% end %>
</select>
......
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