Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sélecteur de langues pour les universités #2020

Merged
merged 6 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
window.osuny.communication.websites.form = {
window.osuny.defaultLanguageSelector = {
init: function () {
'use strict';
this.languagesCheckboxes = document.querySelectorAll('.js-languages input[type="checkbox"]');
Expand Down Expand Up @@ -47,7 +47,5 @@ window.osuny.communication.websites.form = {

window.addEventListener('DOMContentLoaded', function () {
'use strict';
if (window.osuny.isInControllerForm('websites')) {
window.osuny.communication.websites.form.init();
}
window.osuny.defaultLanguageSelector.init();
});
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
//= require_self
//= require ./form
//= require ./lang_switch
//= require ./menu_items

Expand Down
1 change: 1 addition & 0 deletions app/assets/javascripts/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
//= require_self
//= require ./admin/commons/nav
//= require ./admin/commons/conditional
//= require ./admin/commons/default_language_selector
//= require_tree ./application/plugins
//= require ./admin/plugins/sortable
//= require_tree ./server
Expand Down
1 change: 1 addition & 0 deletions app/models/language.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ class Language < ApplicationRecord
include Sanitizable

has_many :users
has_and_belongs_to_many :universities
has_and_belongs_to_many :communication_websites,
class_name: 'Communication::Website',
join_table: :communication_websites_languages,
Expand Down
3 changes: 0 additions & 3 deletions app/models/research/journal/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
# updated_at :datetime not null
# kind_id :uuid indexed
# language_id :uuid not null, indexed
# original_id :uuid indexed
# research_journal_id :uuid not null, indexed
# research_journal_volume_id :uuid indexed
# university_id :uuid not null, indexed
Expand All @@ -32,7 +31,6 @@
#
# index_research_journal_papers_on_kind_id (kind_id)
# index_research_journal_papers_on_language_id (language_id)
# index_research_journal_papers_on_original_id (original_id)
# index_research_journal_papers_on_research_journal_id (research_journal_id)
# index_research_journal_papers_on_research_journal_volume_id (research_journal_volume_id)
# index_research_journal_papers_on_slug (slug)
Expand All @@ -43,7 +41,6 @@
#
# fk_rails_05213f4f24 (research_journal_id => research_journals.id)
# fk_rails_0da55970b1 (language_id => languages.id)
# fk_rails_15719086eb (original_id => research_journal_papers.id)
# fk_rails_22f161a6a7 (research_journal_volume_id => research_journal_volumes.id)
# fk_rails_2713063b85 (updated_by_id => users.id)
# fk_rails_935541e014 (university_id => universities.id)
Expand Down
3 changes: 0 additions & 3 deletions app/models/research/journal/volume.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,12 @@
# created_at :datetime not null
# updated_at :datetime not null
# language_id :uuid not null, indexed
# original_id :uuid indexed
# research_journal_id :uuid not null, indexed
# university_id :uuid not null, indexed
#
# Indexes
#
# index_research_journal_volumes_on_language_id (language_id)
# index_research_journal_volumes_on_original_id (original_id)
# index_research_journal_volumes_on_research_journal_id (research_journal_id)
# index_research_journal_volumes_on_slug (slug)
# index_research_journal_volumes_on_university_id (university_id)
Expand All @@ -33,7 +31,6 @@
#
# fk_rails_4f1170147a (language_id => languages.id)
# fk_rails_814e97604b (research_journal_id => research_journals.id)
# fk_rails_ae1a55581c (original_id => research_journal_volumes.id)
# fk_rails_c83d5e9068 (university_id => universities.id)
#
class Research::Journal::Volume < ApplicationRecord
Expand Down
1 change: 1 addition & 0 deletions app/models/university.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ class University < ApplicationRecord
has_many :imports, dependent: :destroy
has_many :apps, dependent: :destroy
belongs_to :default_language, class_name: "Language"
has_and_belongs_to_many :languages

validates_presence_of :name
validates :sms_sender_name, presence: true, length: { maximum: 11 }
Expand Down
23 changes: 9 additions & 14 deletions app/views/server/languages/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@

<div class="row">
<div class="col-md-5">
<div class="card">
<div class="card-header">
<h2 class="card-title"><%= t('admin.infos') %></h2>
</div>
<div class="table-responsive">
<table class="<%= table_classes %>">
<% ['iso_code', 'summernote_locale'].each do |attribute| %>
<tr>
<td><%= Language.human_attribute_name(attribute) %></td>
<td class="text-end"><%= @language.public_send attribute %></td>
</tr>
<% end %>
</table>
</div>
<div class="table-responsive">
<table class="<%= table_classes %>">
<% ['iso_code', 'summernote_locale'].each do |attribute| %>
<tr>
<td><%= Language.human_attribute_name(attribute) %></td>
<td class="text-end"><%= @language.public_send attribute %></td>
</tr>
<% end %>
</table>
</div>
</div>
</div>
Expand Down
20 changes: 19 additions & 1 deletion app/views/server/universities/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<div class="col-md-4">
<%= f.input :name %>
<%= f.input :identifier %>
<%= f.association :default_language, include_blank: false %>
<%= f.input :is_really_a_university %>
<%= f.input :private %>
<%= f.input :sms_sender_name,
Expand All @@ -33,6 +32,25 @@
</div>
</div>

<h3 class="mt-5"><%= Language.model_name.human(count: 2) %></h3>
<div class="row">
<div class="col-lg-6">
<%= f.association :languages,
as: :check_boxes,
required: true,
wrapper_html: { class: "js-languages" },
label_method: lambda { |l| language_name(l.iso_code) } %>
</div>
<div class="col-lg-6">
<%= f.association :default_language,
include_blank: t('simple_form.include_blanks.defaults.language'),
label_method: lambda { |l| language_name(l.iso_code) },
input_html: { class: "js-default-language" },
required: true %>
</div>
</div>


<h3 class="mt-5"><%= t('university.sso') %></h3>
<div class="row">
<div class="col-md-6">
Expand Down
4 changes: 3 additions & 1 deletion app/views/server/universities/index.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<th><%= University.human_attribute_name('name') %></th>
<th><%= University.human_attribute_name('url') %></th>
<th><%= University.human_attribute_name('public_or_private') %></th>
<th><%= Language.model_name.human(count: 2) %></th>
<th><%= User.model_name.human(count: 2) %></th>
<th><%= University.human_attribute_name('invoice_date') %></th>
<th><%= University.human_attribute_name('contribution_amount') %></th>
Expand All @@ -30,6 +31,7 @@
<%= university.private ? University.human_attribute_name('private') :
University.human_attribute_name('public') %>
</td>
<td><%= university.languages.count %></td>
<td><%= link_to university.users.not_server_admin.count, "#{university.url}/admin/users", target: :_blank %></td>
<% if university.contribution_amount.to_i.zero? %>
<td></td>
Expand Down Expand Up @@ -59,7 +61,7 @@
</tbody>
<tfoot>
<tr>
<th class="text-start" colspan="5"><%= t('server_admin.universities.contributions_total') %></th>
<th class="text-start" colspan="6"><%= t('server_admin.universities.contributions_total') %></th>
<td class="text-start" colspan="2"><%= number_to_currency University.sum(:contribution_amount), precision: 0, locale: :fr %></td>
</tr>
</tfoot>
Expand Down
4 changes: 4 additions & 0 deletions app/views/server/universities/show.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
<td class="text-end"><%= t(@university.public_send attribute) %></td>
</tr>
<% end %>
<tr>
<td><%= Language.model_name.human(count: @university.languages.count) %></td>
<td class="text-end"><%= @university.languages.ordered.join(', ') %></td>
</tr>
<tr>
<td><%= t('server_admin.universities.users_count') %></td>
<td class="text-end"><%= link_to @university.users.not_server_admin.count, "#{@university.url}/admin/users", target: :_blank %></td>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class AddLanguageUniversityJoinTable < ActiveRecord::Migration[7.1]
def change
create_join_table :languages, :universities, column_options: {type: :uuid} do |t|
t.index [:university_id, :language_id]
end
end
end
13 changes: 13 additions & 0 deletions db/migrate/20240613084620_connect_universities_to_languages.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class ConnectUniversitiesToLanguages < ActiveRecord::Migration[7.1]
def change
University.all.each do |university|
persons_languages_ids = university.university_people.pluck(:language_id).uniq
orgas_languages_ids = university.university_organizations.pluck(:language_id).uniq
websites_languages_ids = university.communication_websites.map(&:language_ids).flatten.uniq
journals_languages_ids = university.research_journals.pluck(:language_id).uniq
programs_languages_ids = university.education_programs.pluck(:language_id).uniq
languages = Language.where(id: persons_languages_ids + orgas_languages_ids + websites_languages_ids + journals_languages_ids + programs_languages_ids + [university.default_language_id])
university.languages = languages
end
end
end
Loading
Loading