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

Diplôme ordonnables #2333

Merged
merged 4 commits into from
Oct 16, 2024
Merged
Show file tree
Hide file tree
Changes from all 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
Expand Up @@ -27,7 +27,6 @@ def edit
end

def create
@location.language_id = current_language.id
if @location.save
redirect_to [:admin, @location],
notice: t('admin.successfully_created_html', model: @location.to_s_in(current_language))
Expand Down
1 change: 1 addition & 0 deletions app/controllers/admin/education/diplomas_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ class Admin::Education::DiplomasController < Admin::Education::ApplicationContro

include Admin::HasStaticAction
include Admin::Localizable
include Admin::Reorderable

def index
@diplomas = @diplomas.ordered
Expand Down
1 change: 0 additions & 1 deletion app/controllers/admin/education/schools_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ def edit
end

def create
@school.language_id = current_language.id
if @school.save
redirect_to [:admin, @school], notice: t('admin.successfully_created_html', model: @school.to_s_in(current_language))
else
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/block.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@
#
class Communication::Block < ApplicationRecord
include AsIndirectObject
include Orderable
include WithAccessibility
include WithHeadingRanks
include WithHtmlClass
include WithPosition
include WithTemplate
include WithUniversity
include Sanitizable
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/block/heading.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
#
class Communication::Block::Heading < ApplicationRecord
include AsIndirectObject
include Orderable
include Sanitizable
include Sluggable
include WithPosition
include WithUniversity

belongs_to :university
Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/website/agenda/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
class Communication::Website::Agenda::Category < ApplicationRecord
include AsDirectObject
include Localizable
include Orderable
include Sanitizable
include WithMenuItemTarget
include WithPosition
include WithTree
include WithUniversity

Expand Down
2 changes: 1 addition & 1 deletion app/models/communication/website/menu/item.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
#
class Communication::Website::Menu::Item < ApplicationRecord
include Initials
include Orderable
include Sanitizable
include WithPosition
include WithTree
include WithUniversity

Expand Down
4 changes: 2 additions & 2 deletions app/models/communication/website/page.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ class Communication::Website::Page < ApplicationRecord
include AsDirectObject
include Duplicable
include Filterable
include Sanitizable
include Localizable
include Orderable
include Sanitizable
include WithAutomaticMenus
include WithMenuItemTarget
include WithSpecialPage # WithSpecialPage can set default publication status, so must be included before WithPublication
include WithPosition # Scope :ordered must override WithPublication
include WithTree
include WithUniversity

Expand Down
4 changes: 2 additions & 2 deletions app/models/communication/website/post/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@
#
class Communication::Website::Post::Category < ApplicationRecord
include AsDirectObject
include Sanitizable
include Localizable
include Orderable
include Sanitizable
include WithMenuItemTarget
include WithPosition
include WithTree
include WithUniversity

Expand Down
2 changes: 1 addition & 1 deletion app/models/concerns/as_category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module AsCategory
extend ActiveSupport::Concern

included do
include WithPosition
include Orderable
include WithTree

belongs_to :parent,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module WithPosition
module Orderable
extend ActiveSupport::Concern

included do
Expand Down
6 changes: 4 additions & 2 deletions app/models/education/diploma.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
# certification :string
# ects :integer
# level :integer default("not_applicable")
# position :integer default(0)
# created_at :datetime not null
# updated_at :datetime not null
# university_id :uuid not null, indexed
Expand All @@ -22,8 +23,9 @@ class Education::Diploma < ApplicationRecord
CERTIFICATIONS_DIRECTORY = "app/assets/images/education/diplomas/certifications"

include AsIndirectObject
include Sanitizable
include Localizable
include Orderable
include Sanitizable
include WithUniversity

enum level: {
Expand All @@ -43,7 +45,7 @@ class Education::Diploma < ApplicationRecord

validates :certification, inclusion: { in: -> { certifications } }, allow_blank: true

scope :ordered, -> (language = nil) { order(:level) }
scope :ordered, -> (language = nil) { order(:position, :level) }

def self.certifications
Dir.children(CERTIFICATIONS_DIRECTORY).map { |filename|
Expand Down
4 changes: 2 additions & 2 deletions app/models/education/program.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ class Education::Program < ApplicationRecord
include AsIndirectObject
include Filterable
include Localizable
include Orderable
include Sanitizable
include WebsitesLinkable
include WithAlumni
include WithDiploma
include WithLocations
include WithMenuItemTarget
include WithPosition
include WithSchools
include WithTeam
include WithTree
Expand All @@ -60,7 +60,7 @@ class Education::Program < ApplicationRecord

before_destroy :move_children

# can't use LocalizableOrderByNameScope because scope ordered is already defined by WithPosition
# can't use LocalizableOrderByNameScope because scope ordered is already defined by Orderable
scope :ordered_by_name, -> (language) {
localization_name_select = <<-SQL
COALESCE(
Expand Down
2 changes: 1 addition & 1 deletion app/models/research/journal/paper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@
class Research::Journal::Paper < ApplicationRecord
include AsIndirectObject
include Localizable
include Orderable
include Sanitizable
include WithPosition
include WithUniversity

belongs_to :journal,
Expand Down
2 changes: 1 addition & 1 deletion app/models/research/laboratory/axis.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@
class Research::Laboratory::Axis < ApplicationRecord
include Localizable
include LocalizableOrderByNameScope
include Orderable
include Sanitizable
include WithUniversity
include WithPosition

belongs_to :laboratory,
foreign_key: :research_laboratory_id
Expand Down
2 changes: 1 addition & 1 deletion app/models/university/organization/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class University::Organization::Category < ApplicationRecord
include AsIndirectObject
include Localizable
include WithPosition
include Orderable
include WithTree
include WithUniversity

Expand Down
2 changes: 1 addition & 1 deletion app/models/university/person/category.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class University::Person::Category < ApplicationRecord
include AsIndirectObject
include Localizable
include WithPosition
include Orderable
include WithTree
include WithUniversity

Expand Down
2 changes: 1 addition & 1 deletion app/models/university/person/involvement.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#
class University::Person::Involvement < ApplicationRecord
include Localizable
include WithPosition
include Orderable
include WithUniversity

enum kind: {
Expand Down
2 changes: 1 addition & 1 deletion app/models/university/person/localization.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Table name: university_person_localizations
#
# id :uuid not null, primary key
# biography :string
# biography :text
# first_name :string
# last_name :string
# linkedin :string
Expand Down
2 changes: 1 addition & 1 deletion app/models/university/role.rb
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
#
class University::Role < ApplicationRecord
include Localizable
include WithPosition
include Orderable
include WithUniversity

# Can be an Education::School or an Education::Program
Expand Down
2 changes: 1 addition & 1 deletion app/views/admin/administration/locations/static.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ location.programs.each do |program|
<% end %>
diplomas:
<%
location.diplomas.each do |diploma|
location.diplomas.ordered.each do |diploma|
diploma_l10n = diploma.best_localization_for(language)
programs = location.education_programs.where(diploma: diploma).root.ordered
next if programs.empty?
Expand Down
6 changes: 4 additions & 2 deletions app/views/admin/education/diplomas/_list.html.erb
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<div class="row g-2">
<div class="row g-2"
data-sortable
data-sort-url="<%= reorder_admin_education_diplomas_path %>">
<% diplomas.ordered.each do |diploma| %>
<div>
<div data-id="<%= diploma.id %>" class="handle">
<div class="<%= osuny_card_classes(horizontal: true) %>">
<%= osuny_thumbnail_localized diploma %>
<div class="card-body">
Expand Down
3 changes: 3 additions & 0 deletions config/routes/admin/education.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
resources :academic_years
resources :cohorts, only: [:index, :show]
resources :diplomas do
collection do
post :reorder
end
member do
get :static
end
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
class AddPositionToEducationDiplomas < ActiveRecord::Migration[7.1]
def change
add_column :education_diplomas, :position, :integer, default: 0
end
end
9 changes: 5 additions & 4 deletions db/schema.rb

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading