diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index 185fae448f1818f3fa23ae57521f5ac14a415814..32ef3f170647e60d18a2e2a7c341e1c444c49a9d 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -79,7 +79,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro def program_params params.require(:education_program) - .permit(:name, :level, :capacity, :ects, :continuing, + .permit(:name, :slug, :level, :capacity, :ects, :continuing, :prerequisites, :objectives, :duration, :registration, :pedagogy, :evaluation, :accessibility, :pricing, :contacts, :opportunities, :other, :parent_id, school_ids: [], teacher_ids: []) end diff --git a/app/controllers/admin/research/journal/articles_controller.rb b/app/controllers/admin/research/journal/articles_controller.rb index 19869023556ab657e2aa4799f99de7365c01ab41..15922af61d816a6086b18a16dba05a75b3e91ad2 100644 --- a/app/controllers/admin/research/journal/articles_controller.rb +++ b/app/controllers/admin/research/journal/articles_controller.rb @@ -58,7 +58,7 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A def article_params params.require(:research_journal_article) - .permit(:title, :text, :published_at, :abstract, :pdf, :references, :keywords, :research_journal_volume_id, researcher_ids: []) + .permit(:title, :slug, :text, :published_at, :abstract, :pdf, :references, :keywords, :research_journal_volume_id, researcher_ids: []) .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb index 3090f916839bb42f9fc6dbd41e882a155046f168..ed2b0699c8dcc31c60e734de60ef3d073ea63a00 100644 --- a/app/controllers/admin/research/journal/volumes_controller.rb +++ b/app/controllers/admin/research/journal/volumes_controller.rb @@ -54,7 +54,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap def volume_params params.require(:research_journal_volume) - .permit(:title, :number, :cover, :cover_infos, :cover_delete, :keywords, :published_at, :description) + .permit(:title, :slug, :number, :cover, :cover_infos, :cover_delete, :keywords, :published_at, :description) .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/research/researchers_controller.rb b/app/controllers/admin/research/researchers_controller.rb index 2bff223c04e2e04a9c963c4663aff4ecf40dd7b2..47253a65106ba598322038fd665ec067cf0d05a0 100644 --- a/app/controllers/admin/research/researchers_controller.rb +++ b/app/controllers/admin/research/researchers_controller.rb @@ -55,7 +55,7 @@ class Admin::Research::ResearchersController < Admin::Research::ApplicationContr def researcher_params params.require(:research_researcher) - .permit(:first_name, :last_name, :biography, :user_id) + .permit(:first_name, :last_name, :slug, :biography, :user_id) .merge(university_id: current_university.id) end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index bd0029f95fb7abb2a83b4f9d18cb203971abd6c7..9d46a22aebbab5271b4648972f8468b00529f141 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -9,6 +9,7 @@ # level :integer # name :string # position :integer default(0) +# slug :string # created_at :datetime not null # updated_at :datetime not null # parent_id :uuid diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index bde49caaa5be0920e8d249c9210af88a6afa95b8..5d28a34f01fed642f9a5c048c477a48dc7566270 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -8,6 +8,7 @@ # old_text :text # published_at :date # references :text +# slug :string # title :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 676a48bfaac96e54bbb05d04ae32fb3bc1561892..f2dc30611c70108b630a15741633ba7a0fc673f8 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -7,6 +7,7 @@ # keywords :text # number :integer # published_at :date +# slug :string # title :string # created_at :datetime not null # updated_at :datetime not null diff --git a/app/models/research/researcher.rb b/app/models/research/researcher.rb index 9416996071e165c7cf5165bee23459b97ae796c3..582522b866e8ddfcc24e0a3a3e88253c12bd85e2 100644 --- a/app/models/research/researcher.rb +++ b/app/models/research/researcher.rb @@ -5,6 +5,7 @@ # id :uuid not null, primary key # first_name :string # last_name :string +# slug :string # created_at :datetime not null # updated_at :datetime not null # university_id :uuid diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index cdc86993056e44d1363ebbf701d53bf18a5015a5..595a8b4ab2017c0480bda988f85c0b7401b9de83 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -7,6 +7,12 @@ </div> <div class="card-body"> <%= f.input :name %> + <%= f.input :slug, + as: :string, + input_html: program.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#education_program_name' } + } %> <%= f.input :level, include_blank: false, label_method: -> (p) { I18n.t(p[1], scope: 'enums.education/program.level') } %> <%= f.input :capacity %> <%= f.input :ects %> diff --git a/app/views/admin/research/journal/articles/_form.html.erb b/app/views/admin/research/journal/articles/_form.html.erb index 6e15aaefd25c8c83671a7721649e385dbb634729..a37138e11d88486046989f1d9ca85f82cfa622af 100644 --- a/app/views/admin/research/journal/articles/_form.html.erb +++ b/app/views/admin/research/journal/articles/_form.html.erb @@ -7,6 +7,12 @@ </div> <div class="card-body"> <%= f.input :title, as: :text, input_html: { rows: 3 } %> + <%= f.input :slug, + as: :string, + input_html: article.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#research_journal_article_title' } + } %> <%= f.input :abstract, as: :text, input_html: { rows: 8 } %> <%= f.input :pdf %> <%= f.input :text, as: :rich_text_area %> diff --git a/app/views/admin/research/journal/volumes/_form.html.erb b/app/views/admin/research/journal/volumes/_form.html.erb index 0523acd7877f2f029836185e13ce54b81ab2b8a5..2ebadb0993d9666482c325c82688aee6f518e686 100644 --- a/app/views/admin/research/journal/volumes/_form.html.erb +++ b/app/views/admin/research/journal/volumes/_form.html.erb @@ -7,6 +7,12 @@ </div> <div class="card-body"> <%= f.input :title %> + <%= f.input :slug, + as: :string, + input_html: volume.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#research_journal_volume_title' } + } %> <%= f.input :cover, as: :single_deletable_file, input_html: { accept: '.jpg,.jpeg,.png' }, diff --git a/app/views/admin/research/researchers/_form.html.erb b/app/views/admin/research/researchers/_form.html.erb index 5cc8e6c65fabd907be3eea7b9ef693e4652e8967..aecb1a41694cc74c808767e5d38b0e293f35983f 100644 --- a/app/views/admin/research/researchers/_form.html.erb +++ b/app/views/admin/research/researchers/_form.html.erb @@ -5,6 +5,12 @@ <div class="card-body"> <%= f.input :first_name %> <%= f.input :last_name %> + <%= f.input :slug, + as: :string, + input_html: researcher.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#research_researcher_first_name, #research_researcher_last_name' } + } %> <%= f.association :user, collection: current_university.users.ordered %> </div> </div> diff --git a/db/migrate/20211209144737_add_slug_to_education_and_research_models.rb b/db/migrate/20211209144737_add_slug_to_education_and_research_models.rb new file mode 100644 index 0000000000000000000000000000000000000000..8072ebc07598a5cb6c82c700ae850fe4c136172d --- /dev/null +++ b/db/migrate/20211209144737_add_slug_to_education_and_research_models.rb @@ -0,0 +1,8 @@ +class AddSlugToEducationAndResearchModels < ActiveRecord::Migration[6.1] + def change + add_column :education_programs, :slug, :string + add_column :research_journal_articles, :slug, :string + add_column :research_journal_volumes, :slug, :string + add_column :research_researchers, :slug, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index 3d52f5d0b550994e8ce1eed622ef92c71f0f0149..27a6a46e36c55048519fd18a8bed19d286520535 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -10,7 +10,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 2021_12_09_110929) do +ActiveRecord::Schema.define(version: 2021_12_09_144737) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -364,6 +364,7 @@ ActiveRecord::Schema.define(version: 2021_12_09_110929) do t.datetime "updated_at", precision: 6, null: false t.uuid "parent_id" t.integer "position", default: 0 + t.string "slug" t.index ["parent_id"], name: "index_education_programs_on_parent_id" t.index ["university_id"], name: "index_education_programs_on_university_id" end @@ -429,6 +430,7 @@ ActiveRecord::Schema.define(version: 2021_12_09_110929) do t.text "abstract" t.text "references" t.text "keywords" + t.string "slug" t.index ["research_journal_id"], name: "index_research_journal_articles_on_research_journal_id" t.index ["research_journal_volume_id"], name: "index_research_journal_articles_on_research_journal_volume_id" t.index ["university_id"], name: "index_research_journal_articles_on_university_id" @@ -452,6 +454,7 @@ ActiveRecord::Schema.define(version: 2021_12_09_110929) do t.datetime "updated_at", precision: 6, null: false t.text "description" t.text "keywords" + t.string "slug" t.index ["research_journal_id"], name: "index_research_journal_volumes_on_research_journal_id" t.index ["university_id"], name: "index_research_journal_volumes_on_university_id" end @@ -475,6 +478,7 @@ ActiveRecord::Schema.define(version: 2021_12_09_110929) do t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false t.uuid "university_id" + t.string "slug" t.index ["university_id"], name: "idx_researcher_university" t.index ["user_id"], name: "index_research_researchers_on_user_id" end diff --git a/lib/tasks/app.rake b/lib/tasks/app.rake index 3766374c1aa663522a35360ab948ae858214b637..402a331c29dbdf9ddfc3b6ea91a2ed1eef9df6e9 100644 --- a/lib/tasks/app.rake +++ b/lib/tasks/app.rake @@ -17,12 +17,18 @@ namespace :app do website.update_column(:url, "https://#{website.url}") unless website.url.blank? || website.url.starts_with?('https://') } + Education::Program.where(slug: [nil, '']).find_each { |program| program.update_column(:slug, program.name.parameterize) } + Research::Journal::Article.where(slug: [nil, '']).find_each { |article| article.update_column(:slug, article.title.parameterize) } + Research::Journal::Volume.where(slug: [nil, '']).find_each { |volume| volume.update_column(:slug, volume.title.parameterize) } + Research::Researcher.where(slug: [nil, '']).find_each { |researcher| researcher.update_column(:slug, "#{researcher.first_name} #{researcher.last_name}".parameterize) } + [ Communication::Website::Author, Communication::Website::Category, Communication::Website::Home, Communication::Website::Menu, Communication::Website::Page, Communication::Website::Post ].each do |model| model.includes(:website).find_each do |object| + next unless Github.with_website(object.website).valid? object.github_manifest.each do |manifest_item| Communication::Website::GithubFile.where(website: object.website, about: object, manifest_identifier: manifest_item[:identifier]).first_or_create do |github_file| github_file.github_path = object.github_path if manifest_item[:identifier] == 'primary' @@ -37,6 +43,7 @@ namespace :app do ].each do |model| model.includes(:websites).find_each do |object| object.websites.each do |website| + next unless Github.with_website(website).valid? object.github_manifest.each do |manifest_item| Communication::Website::GithubFile.where(website: website, about: object, manifest_identifier: manifest_item[:identifier]).first_or_create do |github_file| github_file.github_path = object.github_path_generated if manifest_item[:identifier] == 'primary'