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 class Admin::Communication::BlocksController < Admin::Communication::ApplicationController
load_and_authorize_resource class: Communication::Website::Block, through: :website load_and_authorize_resource class: Communication::Block
def reorder def reorder
ids = params[:ids] || [] ids = params[:ids] || []
first_page = nil
ids.each.with_index do |id, index| ids.each.with_index do |id, index|
block = @website.blocks.find(id) block = current_university.communication_blocks.find(id)
block.update position: index + 1 block.update position: index + 1
end end
end end
...@@ -25,8 +24,7 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We ...@@ -25,8 +24,7 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We
end end
def create def create
@block.university = @website.university @block.university = current_university
@block.website = @website
if @block.save if @block.save
redirect_to [:edit, :admin, @block], notice: t('admin.successfully_created_html', model: @block.to_s) redirect_to [:edit, :admin, @block], notice: t('admin.successfully_created_html', model: @block.to_s)
else else
...@@ -37,7 +35,7 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We ...@@ -37,7 +35,7 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We
def update def update
if @block.update(block_params) if @block.update(block_params)
@block.about.save_and_sync @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 else
render :edit, status: :unprocessable_entity render :edit, status: :unprocessable_entity
end end
...@@ -51,20 +49,30 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We ...@@ -51,20 +49,30 @@ class Admin::Communication::Website::BlocksController < Admin::Communication::We
protected 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 def breadcrumb
super short_breadcrumb
add_breadcrumb @block.about.model_name.human(count: 2), [:admin, @block.about.class] add_breadcrumb @block.about, about_path
add_breadcrumb @block.about, [:admin, @block.about] # Le block
if @block.new_record? if @block.new_record?
add_breadcrumb t('communication.website.block.choose_template') add_breadcrumb t('communication.block.choose_template')
else else
add_breadcrumb @block add_breadcrumb @block
end end
end end
def block_params def block_params
params.require(:communication_website_block) params.require(:communication_block)
.permit(:about_id, :about_type, :template, :data) .permit(:about_id, :about_type, :template, :data)
end end
end end
# == Schema Information # == Schema Information
# #
# Table name: communication_website_blocks # Table name: communication_blocks
# #
# id :uuid not null, primary key # id :uuid not null, primary key
# about_type :string indexed => [about_id] # about_type :string indexed => [about_id]
# data :jsonb # data :jsonb
# position :integer default(0), not null # position :integer default(0), not null
# template :integer default(NULL), not null # template :integer default(NULL), not null
# created_at :datetime not null # created_at :datetime not null
# updated_at :datetime not null # updated_at :datetime not null
# about_id :uuid indexed => [about_type] # about_id :uuid indexed => [about_type]
# communication_website_id :uuid not null, indexed # university_id :uuid not null, indexed
# university_id :uuid not null, indexed
# #
# Indexes # Indexes
# #
# index_communication_website_blocks_on_about (about_type,about_id) # index_communication_blocks_on_university_id (university_id)
# index_communication_website_blocks_on_communication_website_id (communication_website_id) # index_communication_website_blocks_on_about (about_type,about_id)
# index_communication_website_blocks_on_university_id (university_id)
# #
# Foreign Keys # Foreign Keys
# #
# fk_rails_18291ef65f (university_id => universities.id) # 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 include WithPosition
belongs_to :university belongs_to :university
belongs_to :website, foreign_key: :communication_website_id
belongs_to :about, polymorphic: true belongs_to :about, polymorphic: true
enum template: { 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 class Communication::Website::Configs::BaseUrl < Communication::Website
def self.polymorphic_name 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 class Communication::Website::Configs::Permalinks < Communication::Website
def self.polymorphic_name def self.polymorphic_name
......
...@@ -2,7 +2,7 @@ module WithBlocks ...@@ -2,7 +2,7 @@ module WithBlocks
extend ActiveSupport::Concern extend ActiveSupport::Concern
included do included do
has_many :blocks, as: :about has_many :blocks, as: :about, class_name: 'Communication::Block'
end end
def git_block_dependencies def git_block_dependencies
......
...@@ -51,6 +51,7 @@ class Education::Program < ApplicationRecord ...@@ -51,6 +51,7 @@ class Education::Program < ApplicationRecord
include WithTree include WithTree
include WithInheritance include WithInheritance
include WithPosition include WithPosition
include WithBlocks
rich_text_areas_with_inheritance :accessibility, rich_text_areas_with_inheritance :accessibility,
:contacts, :contacts,
......
...@@ -3,5 +3,6 @@ module University::WithCommunication ...@@ -3,5 +3,6 @@ module University::WithCommunication
included do included do
has_many :communication_websites, class_name: 'Communication::Website', dependent: :destroy has_many :communication_websites, class_name: 'Communication::Website', dependent: :destroy
has_many :communication_blocks, class_name: 'Communication::Block', dependent: :destroy
end end
end end
...@@ -2,27 +2,27 @@ ...@@ -2,27 +2,27 @@
<div class="card-header"> <div class="card-header">
<div class="float-end"> <div class="float-end">
<%= link_to t('add'), <%= 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 %> class: button_classes %>
</div> </div>
<h2 class="card-title mb-0 h5"> <h2 class="card-title mb-0 h5">
<%= Communication::Website::Block.model_name.human(count: 2) %> <%= Communication::Block.model_name.human(count: 2) %>
</h2> </h2>
</div> </div>
<table class="<%= table_classes %>"> <table class="<%= table_classes %>">
<thead> <thead>
<tr> <tr>
<th width="20" class="ps-0">&nbsp;</th> <th width="20" class="ps-0">&nbsp;</th>
<th><%= Communication::Website::Block.human_attribute_name('name') %></th> <th><%= Communication::Block.human_attribute_name('name') %></th>
<th><%= Communication::Website::Block.human_attribute_name('template') %></th> <th><%= Communication::Block.human_attribute_name('template') %></th>
<th></th> <th></th>
</tr> </tr>
</thead> </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| %> <% about.blocks.ordered.each do |block| %>
<tr data-id="<%= block.id %>"> <tr data-id="<%= block.id %>">
<td><i class="fa fa-bars handle"></i></td> <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><%= block.template_i18n %></td>
<td class="text-end"> <td class="text-end">
<%= edit_link block %> <%= edit_link block %>
......
...@@ -3,5 +3,5 @@ blocks: ...@@ -3,5 +3,5 @@ blocks:
<% about.blocks.each do |block| %> <% about.blocks.each do |block| %>
- template: <%= block.template %> - template: <%= block.template %>
data: 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 %> <% end %>
...@@ -5,8 +5,8 @@ ...@@ -5,8 +5,8 @@
%> %>
<div id="app"> <div id="app">
<%= simple_form_for [:admin, @block] do |f| %> <%= simple_form_for [:admin, @block] do |f| %>
<%= render "admin/communication/website/blocks/templates/#{@block.template}/edit", f: f %> <%= render "admin/communication/blocks/templates/#{@block.template}/edit", f: f %>
<textarea name="communication_website_block[data]" rows="20" cols="200" class="d-none"> <textarea name="communication_block[data]" rows="20" cols="200" class="d-none">
{{ JSON.stringify(data) }} {{ JSON.stringify(data) }}
</textarea> </textarea>
<% content_for :action_bar_right do %> <% content_for :action_bar_right do %>
...@@ -24,7 +24,7 @@ ...@@ -24,7 +24,7 @@
draggable: VueDraggableNext.VueDraggableNext, draggable: VueDraggableNext.VueDraggableNext,
}, },
data() { data() {
return { return {
directUpload: { directUpload: {
url: "<%= rails_direct_uploads_url.html_safe %>", url: "<%= rails_direct_uploads_url.html_safe %>",
blobUrlTemplate: "<%= rails_service_blob_url(":signed_id", ":filename").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"> <div class="row">
<% Communication::Website::Block.templates.keys.each do |template| %> <% Communication::Block.templates.keys.each do |template| %>
<% @block.template = template %> <% @block.template = template %>
<div class="col-lg-3 col-md-4"> <div class="col-lg-3 col-md-4">
<div class="card"> <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) %> <%= image_tag asset, alt: '' if Rails.application.assets.find_asset(asset) %>
<div class="card-body"> <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| %> <%= simple_form_for [:admin, @block] do |f| %>
<%= f.input :about_type, as: :hidden %> <%= f.input :about_type, as: :hidden %>
<%= f.input :about_id, as: :hidden %> <%= f.input :about_id, as: :hidden %>
<%= f.input :template, 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') %> class: button_classes('stretched-link') %>
<% end %> <% end %>
</div> </div>
......
<% content_for :title, @block %> <% 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 %> <% content_for :action_bar_right do %>
<%= edit_link @block %> <%= edit_link @block %>
......
...@@ -46,7 +46,7 @@ ...@@ -46,7 +46,7 @@
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<select class="form-select select" v-model="person.id"> <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> <option value="<%= person.id %>"><%= person.last_name %>, <%= person.first_name %></option>
<% end %> <% end %>
</select> </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