diff --git a/Gemfile b/Gemfile index 091adfff6bb319247b24736322e9757f745ba007..b01ab29ad62464c6031fec4e4bd16c404928a6fa 100644 --- a/Gemfile +++ b/Gemfile @@ -50,7 +50,7 @@ gem 'summernote-rails', git: 'https://github.com/noesya/summernote-rails.git', b # gem 'summernote-rails', path: '../summernote-rails' gem 'two_factor_authentication', git: 'https://github.com/noesya/two_factor_authentication.git' # gem 'two_factor_authentication', path: '../two_factor_authentication' - +gem 'unsplash' group :development, :test do gem 'byebug', platforms: [:mri, :mingw, :x64_mingw] diff --git a/Gemfile.lock b/Gemfile.lock index d75a15fd9f09afa158fcfefae57a0dbb3c21a274..92c4809d69efee91c96d0dd265033cdeab118141 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -85,10 +85,10 @@ GEM annotate (3.2.0) activerecord (>= 3.2, < 8.0) rake (>= 10.4, < 14.0) - autoprefixer-rails (10.4.2.0) + autoprefixer-rails (10.4.7.0) execjs (~> 2) aws-eventstream (1.2.0) - aws-partitions (1.580.0) + aws-partitions (1.585.0) aws-sdk-core (3.130.2) aws-eventstream (~> 1, >= 1.0.2) aws-partitions (~> 1, >= 1.525.0) @@ -97,7 +97,7 @@ GEM aws-sdk-kms (1.56.0) aws-sdk-core (~> 3, >= 3.127.0) aws-sigv4 (~> 1.1) - aws-sdk-s3 (1.113.2) + aws-sdk-s3 (1.114.0) aws-sdk-core (~> 3, >= 3.127.0) aws-sdk-kms (~> 1) aws-sigv4 (~> 1.4) @@ -133,7 +133,7 @@ GEM childprocess (4.1.0) cocoon (1.2.15) concurrent-ruby (1.1.10) - countries (5.0.0) + countries (5.0.1) i18n_data (~> 0.16.0) sixarm_ruby_unaccent (~> 1.1) country_select (7.0.0) @@ -166,7 +166,7 @@ GEM domain_name (0.5.20190701) unf (>= 0.0.5, < 1.0.0) encryptor (3.0.0) - enum_help (0.0.18) + enum_help (0.0.19) activesupport (>= 3.0.0) erubi (1.10.0) ethon (0.15.0) @@ -252,6 +252,7 @@ GEM js_cookie_rails (2.2.0) railties (>= 3.1) json (2.6.1) + jwt (2.3.0) kamifusen (1.11.2) image_processing rails @@ -270,7 +271,7 @@ GEM listen (3.7.1) rb-fsevent (~> 0.10, >= 0.10.3) rb-inotify (~> 0.9, >= 0.9.10) - loofah (2.16.0) + loofah (2.17.0) crass (~> 1.0.2) nokogiri (>= 1.5.9) mail (2.7.1) @@ -296,6 +297,7 @@ GEM mini_portile2 (2.8.0) minitest (5.15.0) msgpack (1.5.1) + multi_json (1.15.0) multi_xml (0.6.0) multipart-post (2.1.1) mustermann (1.1.1) @@ -305,6 +307,12 @@ GEM nokogiri (1.13.5) mini_portile2 (~> 2.8.0) racc (~> 1.4) + oauth2 (1.4.9) + faraday (>= 0.17.3, < 3.0) + jwt (>= 1.0, < 3.0) + multi_json (~> 1.3) + multi_xml (~> 0.5) + rack (>= 1.2, < 3) octokit (4.22.0) faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) @@ -442,6 +450,9 @@ GEM unf_ext (0.0.8.1) unicode-display_width (2.1.0) unicode_utils (1.4.0) + unsplash (2.1.0) + httparty (~> 0.16) + oauth2 (~> 1) vcr (6.1.0) warden (1.2.9) rack (>= 2.0.9) @@ -522,6 +533,7 @@ DEPENDENCIES summernote-rails! two_factor_authentication! tzinfo-data + unsplash vcr web-console (>= 4.1.0) webdrivers @@ -531,4 +543,4 @@ RUBY VERSION ruby 2.7.5p203 BUNDLED WITH - 2.3.9 + 2.3.12 diff --git a/app/assets/stylesheets/admin/treeview.sass b/app/assets/stylesheets/admin/treeview.sass index b77719ec75f72eac129591189104c62f3e22c9e8..a873aebfaaf3b5848df9459c684012961e4c882f 100644 --- a/app/assets/stylesheets/admin/treeview.sass +++ b/app/assets/stylesheets/admin/treeview.sass @@ -1,5 +1,8 @@ .treeview &__element + .show-on-hover + display: none + & > .treeview__children .treeview__empty display: none @@ -70,3 +73,5 @@ & > a .open_text, & > a .close_text opacity: 1 + .show-on-hover + display: inline diff --git a/app/assets/stylesheets/commons/_block.sass b/app/assets/stylesheets/commons/_block.sass index 4acd08cac2f9e8b41426a464b9c202efc055910c..6d8fcdc1a3527295cb0191346baad59bcff51963 100644 --- a/app/assets/stylesheets/commons/_block.sass +++ b/app/assets/stylesheets/commons/_block.sass @@ -1,5 +1,5 @@ [v-cloak] - form, .app-form + form, .app-form, .app-content display: none [data-v-app] .spinner-border diff --git a/app/controllers/admin/communication/unsplash_controller.rb b/app/controllers/admin/communication/unsplash_controller.rb new file mode 100644 index 0000000000000000000000000000000000000000..f3ecdc1479e1f2199f3108480e867f856889bf9d --- /dev/null +++ b/app/controllers/admin/communication/unsplash_controller.rb @@ -0,0 +1,22 @@ +class Admin::Communication::UnsplashController < Admin::Communication::ApplicationController + layout false + + def index + if params[:query].blank? + @search = [] + @total = 0 + @total_pages = 0 + else + p = { + query: params[:query], + page: (params[:page].presence || 1), + per_page: (params[:per_page].presence || 10), + orientation: (params[:orientation].presence || 'squarish'), + lang: (params[:lang].presence || 'en') + } + @search = Unsplash::Search.search "/search/photos", Unsplash::Photo, p + @total = @search.total + @total_pages = @search.total_pages + end + end +end diff --git a/app/controllers/admin/communication/website/categories_controller.rb b/app/controllers/admin/communication/website/categories_controller.rb index 0db5e29c4ff1a3c543660cfa3425fc76a959e7de..a6ca1a9b350a477ce2f6f6f68ff4a27eb3c76b4f 100644 --- a/app/controllers/admin/communication/website/categories_controller.rb +++ b/app/controllers/admin/communication/website/categories_controller.rb @@ -55,6 +55,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication def create @category.website = @website + @category.add_unsplash_image params[:unsplash] if @category.save_and_sync redirect_to admin_communication_website_category_path(@category), notice: t('admin.successfully_created_html', model: @category.to_s) else @@ -64,6 +65,7 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication end def update + @category.add_unsplash_image params[:unsplash] if @category.update_and_sync(category_params) redirect_to admin_communication_website_category_path(@category), notice: t('admin.successfully_updated_html', model: @category.to_s) else @@ -95,7 +97,8 @@ class Admin::Communication::Website::CategoriesController < Admin::Communication params.require(:communication_website_category) .permit( :website_id, :name, :description, :text, :slug, :parent_id, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt) + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit + ) .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index a1f81270301c6990dca361ab5c81d292db6f1556..4ff6e684dd1d13fecef999c7e55f5b90f0a6762c 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -46,6 +46,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def create @page.website = @website + @page.add_unsplash_image params[:unsplash] if @page.save_and_sync redirect_to admin_communication_website_page_path(@page), notice: t('admin.successfully_created_html', model: @page.to_s) else @@ -55,6 +56,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web end def update + @page.add_unsplash_image params[:unsplash] if @page.update_and_sync(page_params) redirect_to admin_communication_website_page_path(@page), notice: t('admin.successfully_updated_html', model: @page.to_s) else @@ -84,10 +86,12 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def page_params params.require(:communication_website_page) - .permit(:communication_website_id, :title, :breadcrumb_title, :bodyclass, + .permit( + :communication_website_id, :title, :breadcrumb_title, :bodyclass, :description, :description_short, :header_text, :text, :slug, :published, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, - :parent_id, :related_category_id, :language_id) + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, + :parent_id, :related_category_id, :language_id + ) .merge(university_id: current_university.id) end end diff --git a/app/controllers/admin/communication/website/posts_controller.rb b/app/controllers/admin/communication/website/posts_controller.rb index ed0dc79e12d090a29aa9ff9f47497aefc9fff1b8..b1fdd519511e9b1e13617466e267d86f162b7973 100644 --- a/app/controllers/admin/communication/website/posts_controller.rb +++ b/app/controllers/admin/communication/website/posts_controller.rb @@ -36,6 +36,11 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web breadcrumb end + def static + @about = @post + render layout: false + end + def new @post.website = @website @post.author_id = current_user.person&.id @@ -49,6 +54,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web def create @post.website = @website + @post.add_unsplash_image params[:unsplash] if @post.save_and_sync redirect_to admin_communication_website_post_path(@post), notice: t('admin.successfully_created_html', model: @post.to_s) else @@ -58,6 +64,7 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web end def update + @post.add_unsplash_image params[:unsplash] if @post.update_and_sync(post_params) redirect_to admin_communication_website_post_path(@post), notice: t('admin.successfully_updated_html', model: @post.to_s) else @@ -85,8 +92,8 @@ class Admin::Communication::Website::PostsController < Admin::Communication::Web params.require(:communication_website_post) .permit( :university_id, :website_id, :title, :description, :description_short, :text, - :published, :published_at, :featured_image, :featured_image_delete, - :featured_image_infos, :featured_image_alt, :slug, :pinned, + :published, :published_at, :slug, :pinned, + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, :author_id, :language_id, category_ids: [] ) .merge(university_id: current_university.id) diff --git a/app/controllers/admin/education/programs_controller.rb b/app/controllers/admin/education/programs_controller.rb index 393d6158a1efd57de6d9fcfbedf9dd6c51a3d317..2e23f18aee585409d4aa077adc491c74731f625d 100644 --- a/app/controllers/admin/education/programs_controller.rb +++ b/app/controllers/admin/education/programs_controller.rb @@ -54,6 +54,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro def create @program.university = current_university + @program.add_unsplash_image params[:unsplash] if @program.save_and_sync redirect_to [:admin, @program], notice: t('admin.successfully_created_html', model: @program.to_s) else @@ -63,6 +64,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro end def update + @program.add_unsplash_image params[:unsplash] if @program.update_and_sync(program_params) redirect_to [:admin, @program], notice: t('admin.successfully_updated_html', model: @program.to_s) else @@ -88,7 +90,7 @@ class Admin::Education::ProgramsController < Admin::Education::ApplicationContro def program_params params.require(:education_program).permit( :name, :slug, :level, :capacity, :ects, :continuing, :description, :published, - :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, + :featured_image, :featured_image_delete, :featured_image_infos, :featured_image_alt, :featured_image_credit, :prerequisites, :objectives, :duration, :presentation, :registration, :pedagogy, :content, :evaluation, :accessibility, :pricing, :contacts, :opportunities, :results, :other, :main_information, :parent_id, school_ids: [], diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb index 95413015794473f3e40693691de334d8a187ee3e..321de51ce7970433d87913b95f1dcafe23114192 100644 --- a/app/controllers/admin/research/journal/volumes_controller.rb +++ b/app/controllers/admin/research/journal/volumes_controller.rb @@ -21,6 +21,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap end def create + @volume.add_unsplash_image params[:unsplash] @volume.assign_attributes(journal: @journal, university: current_university) if @volume.save_and_sync redirect_to admin_research_journal_volume_path(@volume), notice: t('admin.successfully_created_html', model: @volume.to_s) @@ -31,6 +32,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap end def update + @volume.add_unsplash_image params[:unsplash] if @volume.update_and_sync(volume_params) redirect_to admin_research_journal_volume_path(@volume), notice: t('admin.successfully_updated_html', model: @volume.to_s) else @@ -57,7 +59,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap params.require(:research_journal_volume) .permit( :title, :slug, :number, :keywords, :published, :published_at, :description, :text, - :featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt + :featured_image, :featured_image_infos, :featured_image_delete, :featured_image_alt, :featured_image_credit ) .merge(university_id: current_university.id) end diff --git a/app/models/communication/block/template/page.rb b/app/models/communication/block/template/page.rb index 2a80625d176fdff00822cc720ebed7f651a3af98..dd60b571e3c046c63e06f055ddbece03b4b1b140 100644 --- a/app/models/communication/block/template/page.rb +++ b/app/models/communication/block/template/page.rb @@ -1,18 +1,19 @@ class Communication::Block::Template::Page < Communication::Block::Template def build_git_dependencies - # add_dependency category unless category.nil? - # add_dependency selected_posts - # selected_posts.each do |post| - # add_dependency post.active_storage_blobs - # if post.author.present?category.nil? ? free_posts : category_posts - # add_dependency [post.author, post.author.author] - # add_dependency post.author.active_storage_blobs - # end - # end + add_dependency main_page + selected_pages.each do |hash| + page = hash.page + add_dependency page + add_dependency page.active_storage_blobs + end end def selected_pages - @selected_pages ||= free_pages + @selected_pages ||= elements.map { |element| + p = page(element['id']) + next if p.nil? + hash_from_page(p, element) + }.compact end def main_page @@ -29,19 +30,19 @@ class Communication::Block::Template::Page < Communication::Block::Template protected - def free_pages - elements.map { |element| - { - page: page(element['id']), - show_description: element['show_description'] || false, - show_image: element['show_image'] || false - }.to_dot - } - .compact + def hash_from_page(page, element) + { + page: page, + show_description: element['show_description'] || false, + show_image: element['show_image'] || false + }.to_dot end def page(id) return if id.blank? - page = block.about&.website.pages.find_by id: id + page = block.about&.website + .pages + .published + .find_by(id: id) end end diff --git a/app/models/communication/block/template/post.rb b/app/models/communication/block/template/post.rb index aa4143e902a6f1ce6381973061d73b5013146d0e..90df81731bc1dc28b994b73cc4540f5fddf9ef44 100644 --- a/app/models/communication/block/template/post.rb +++ b/app/models/communication/block/template/post.rb @@ -12,11 +12,13 @@ class Communication::Block::Template::Post < Communication::Block::Template end def category - @category ||= block.about&.website.categories.find_by(id: data['category_id']) + @category ||= block.about&.website + .categories + .find_by(id: data['category_id']) end def selected_posts - # kind could be : selection, category, or all + # kind could be: selection, category, or all @selected_posts ||= send "selected_posts_#{kind}" end @@ -28,7 +30,11 @@ class Communication::Block::Template::Post < Communication::Block::Template def selected_posts_all quantity = data['posts_quantity'] || 3 - block.about&.website.posts.ordered.limit(quantity) + block.about&.website + .posts + .published + .ordered + .limit(quantity) end def selected_posts_category @@ -37,6 +43,7 @@ class Communication::Block::Template::Post < Communication::Block::Template university.communication_website_posts.joins(:categories) .where(categories: { id: category_ids }) .distinct + .published .ordered .limit(quantity) end @@ -48,6 +55,9 @@ class Communication::Block::Template::Post < Communication::Block::Template def post(id) return if id.blank? - block.about&.website.posts.find_by id: id + block.about&.website + .posts + .published + .find_by(id: id) end end diff --git a/app/models/communication/website/category.rb b/app/models/communication/website/category.rb index 111fb7a8e1637a280cc48a60a1ee2f56b2a3a38e..4a73a15d7fb05e5272638b4305e00038784ef933 100644 --- a/app/models/communication/website/category.rb +++ b/app/models/communication/website/category.rb @@ -5,6 +5,7 @@ # id :uuid not null, primary key # description :text # featured_image_alt :string +# featured_image_credit :text # github_path :text # is_programs_root :boolean default(FALSE) # name :string @@ -35,6 +36,7 @@ # class Communication::Website::Category < ApplicationRecord include Sanitizable + include WithUniversity include WithGit include WithFeaturedImage include WithBlobs diff --git a/app/models/communication/website/index_page.rb b/app/models/communication/website/index_page.rb deleted file mode 100644 index 4c80742baaf0e5c20f062c70e072ae5a84e4a355..0000000000000000000000000000000000000000 --- a/app/models/communication/website/index_page.rb +++ /dev/null @@ -1,64 +0,0 @@ -# == Schema Information -# -# Table name: communication_website_index_pages -# -# id :uuid not null, primary key -# breadcrumb_title :string -# description :text -# featured_image_alt :string -# header_text :text -# kind :integer -# path :string -# text :text -# title :string -# created_at :datetime not null -# updated_at :datetime not null -# communication_website_id :uuid not null, indexed -# university_id :uuid not null, indexed -# -# Indexes -# -# idx_comm_website_index_page_on_communication_website_id (communication_website_id) -# index_communication_website_index_pages_on_university_id (university_id) -# -# Foreign Keys -# -# fk_rails_5cd2482227 (communication_website_id => communication_websites.id) -# fk_rails_7eb45227ae (university_id => universities.id) -# -class Communication::Website::IndexPage < ApplicationRecord - include WithUniversity - include Sanitizable - include WithFeaturedImage - include WithBlobs - - enum kind: { - home: 0, - communication_posts: 10, - education_programs: 20, - research_articles: 30, - research_volumes: 32, - legal_terms: 80, - sitemap: 81, - privacy_policy: 82, - organizations: 90, - persons: 100, - administrators: 110, - authors: 120, - researchers: 130, - teachers: 140 - } - - belongs_to :website, foreign_key: :communication_website_id - - has_summernote :header_text - has_summernote :text - - validates :title, presence: true - validates :path, presence: true, unless: Proc.new { |p| p.home? } - - def to_s - "#{title}" - end - -end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 4f6d3b66d646ccc360971f7825a12a51027cceb8..121a75e1d55994fd6b5c4e206f7c320176be9943 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -8,6 +8,7 @@ # description :text # description_short :text # featured_image_alt :string +# featured_image_credit :text # github_path :text # header_text :text # kind :integer @@ -43,6 +44,7 @@ class Communication::Website::Page < ApplicationRecord include Sanitizable + include WithUniversity include WithBlobs include WithBlocks include WithGit @@ -51,7 +53,6 @@ class Communication::Website::Page < ApplicationRecord include WithMenuItemTarget include WithPosition include WithTree - include WithUniversity has_summernote :text @@ -74,9 +75,16 @@ class Communication::Website::Page < ApplicationRecord validates :title, presence: true - validates :slug, presence: true, unless: :kind_home? - validate :slug_must_be_unique - validates :slug, format: { with: /\A[a-z0-9\-]+\z/, message: I18n.t('slug_error') }, unless: :kind_home? + validates :slug, + presence: true, + unless: :kind_home? + validate :slug_must_be_unique + validates :slug, + format: { + with: /\A[a-z0-9\-]+\z/, + message: I18n.t('slug_error') + }, + unless: :kind_home? before_validation :check_slug, :make_path after_save :update_children_paths, if: :saved_change_to_path? @@ -89,7 +97,9 @@ class Communication::Website::Page < ApplicationRecord end def path_without_language - if parent_id.present? + if kind_home? + "/" + elsif parent_id.present? "#{parent&.path_without_language}#{slug}/".gsub(/\/+/, '/') else "/#{slug}/".gsub(/\/+/, '/') diff --git a/app/models/communication/website/post.rb b/app/models/communication/website/post.rb index 5a6f0d1e1bf524ff4d859b4301a88392a77b94a1..1df229eb4a0cdc2d7514dafc1094e16893ec0c6d 100644 --- a/app/models/communication/website/post.rb +++ b/app/models/communication/website/post.rb @@ -6,6 +6,7 @@ # description :text # description_short :text # featured_image_alt :string +# featured_image_credit :text # github_path :text # pinned :boolean default(FALSE) # published :boolean default(FALSE) diff --git a/app/models/communication/website/with_special_pages.rb b/app/models/communication/website/with_special_pages.rb index 9b898c81fa6bc1ffc53c67360a89cf0acfd2717c..4b01e1a9dceef3b4b743ab306330a559615abd4c 100644 --- a/app/models/communication/website/with_special_pages.rb +++ b/app/models/communication/website/with_special_pages.rb @@ -38,42 +38,14 @@ module Communication::Website::WithSpecialPages def create_special_page(kind, parent_id = nil) i18n_key = "communication.website.pages.defaults.#{kind}" - # TODO: remove legacy after migrations - legacy_index_page = Communication::Website::IndexPage.where(communication_website_id: id, kind: kind).first - if legacy_index_page.present? - page = pages.where(kind: kind).first - unless page.present? - page = pages.create( - kind: kind, - title: legacy_index_page.title, - slug: legacy_index_page.path, - description_short: legacy_index_page.description, - parent_id: parent_id, - published: true, - university_id: university_id, - breadcrumb_title: legacy_index_page.breadcrumb_title, - featured_image_alt: legacy_index_page.featured_image_alt, - header_text: legacy_index_page.header_text, - text: legacy_index_page.text - ) - if legacy_index_page.featured_image.attached? - blob_to_duplicate = legacy_index_page.featured_image.blob - page.featured_image.attach( - io: URI.open(blob_to_duplicate.url), - filename: blob_to_duplicate.filename.to_s - ) - end - end - else - page = pages.where(kind: kind).first_or_create( - title: I18n.t("#{i18n_key}.title"), - slug: I18n.t("#{i18n_key}.slug"), - description_short: I18n.t("#{i18n_key}.description_short"), - parent_id: parent_id, - published: true, - university_id: university_id - ) - end + page = pages.where(kind: kind).first_or_create( + title: I18n.t("#{i18n_key}.title"), + slug: I18n.t("#{i18n_key}.slug"), + description_short: I18n.t("#{i18n_key}.description_short"), + parent_id: parent_id, + published: true, + university_id: university_id + ) page end diff --git a/app/models/concerns/with_featured_image.rb b/app/models/concerns/with_featured_image.rb index c38424175eec9fd3d50f6c55d46f99aa1e1dc176..91f13b5938a301e3b5f30bfbac3500c685e514bb 100644 --- a/app/models/concerns/with_featured_image.rb +++ b/app/models/concerns/with_featured_image.rb @@ -9,4 +9,17 @@ module WithFeaturedImage def best_featured_image(fallback: true) featured_image end + + def add_unsplash_image(id) + return if id.blank? + photo = Unsplash::Photo.find id + url = photo['links']['download'] + filename = "#{photo['id']}.jpg" + begin + file = URI.open url + featured_image.attach(io: file, filename: filename) + photo.track_download + rescue + end + end end diff --git a/app/models/education/program.rb b/app/models/education/program.rb index 66348c20bd9ce683ebc67ea3bc96806afa2e7130..1a9704e336c663c6d356be844382b5e07b25b587 100644 --- a/app/models/education/program.rb +++ b/app/models/education/program.rb @@ -2,37 +2,38 @@ # # Table name: education_programs # -# id :uuid not null, primary key -# accessibility :text -# capacity :integer -# contacts :text -# content :text -# continuing :boolean -# description :text -# duration :text -# ects :integer -# evaluation :text -# featured_image_alt :string -# level :integer -# main_information :text -# name :string -# objectives :text -# opportunities :text -# other :text -# path :string -# pedagogy :text -# position :integer default(0) -# prerequisites :text -# presentation :text -# pricing :text -# published :boolean default(FALSE) -# registration :text -# results :text -# slug :string -# created_at :datetime not null -# updated_at :datetime not null -# parent_id :uuid indexed -# university_id :uuid not null, indexed +# id :uuid not null, primary key +# accessibility :text +# capacity :integer +# contacts :text +# content :text +# continuing :boolean +# description :text +# duration :text +# ects :integer +# evaluation :text +# featured_image_alt :string +# featured_image_credit :text +# level :integer +# main_information :text +# name :string +# objectives :text +# opportunities :text +# other :text +# path :string +# pedagogy :text +# position :integer default(0) +# prerequisites :text +# presentation :text +# pricing :text +# published :boolean default(FALSE) +# registration :text +# results :text +# slug :string +# created_at :datetime not null +# updated_at :datetime not null +# parent_id :uuid indexed +# university_id :uuid not null, indexed # # Indexes # diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index 6b76d17061ec0edbbc5ef60fda61bb39598c6add..dc0e9ae3868ab1f9029ac218ad9106a96de5b7fc 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -2,20 +2,21 @@ # # Table name: research_journal_volumes # -# id :uuid not null, primary key -# description :text -# featured_image_alt :string -# keywords :text -# number :integer -# published :boolean default(FALSE) -# published_at :datetime -# slug :string -# text :text -# title :string -# created_at :datetime not null -# updated_at :datetime not null -# research_journal_id :uuid not null, indexed -# university_id :uuid not null, indexed +# id :uuid not null, primary key +# description :text +# featured_image_alt :string +# featured_image_credit :text +# keywords :text +# number :integer +# published :boolean default(FALSE) +# published_at :datetime +# slug :string +# text :text +# title :string +# created_at :datetime not null +# updated_at :datetime not null +# research_journal_id :uuid not null, indexed +# university_id :uuid not null, indexed # # Indexes # @@ -36,7 +37,7 @@ class Research::Journal::Volume < ApplicationRecord include WithSlug has_summernote :text - + belongs_to :journal, foreign_key: :research_journal_id has_many :articles, foreign_key: :research_journal_volume_id, dependent: :nullify has_many :websites, -> { distinct }, through: :journal diff --git a/app/models/user.rb b/app/models/user.rb index 97c8b7767781e08d02385cc1a8f3b73b6c7b82e7..0b7266b7eee47105b9edd65fa93bd81db33a373d 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -22,6 +22,7 @@ # last_sign_in_ip :string # locked_at :datetime # mobile_phone :string +# picture_url :string # remember_created_at :datetime # reset_password_sent_at :datetime # reset_password_token :string indexed @@ -53,7 +54,7 @@ # fk_rails_bd6f7212a9 (university_id => universities.id) # class User < ApplicationRecord - has_one_attached_deletable :picture # In this order, "resize avatar" callback will be fired after the others. + include WithAvatar include WithUniversity include WithAuthentication include WithOmniauth diff --git a/app/models/user/with_avatar.rb b/app/models/user/with_avatar.rb new file mode 100644 index 0000000000000000000000000000000000000000..863b3d0a237145865bfcec2217b67d65d5f1cdec --- /dev/null +++ b/app/models/user/with_avatar.rb @@ -0,0 +1,37 @@ +module User::WithAvatar + extend ActiveSupport::Concern + + included do + has_one_attached_deletable :picture # Nota: user has a picture_url property for SSO mapping. If picture_url is set it will use the url to change the picture + + before_save :update_picture, if: :will_save_change_to_picture_url? + after_save :update_picture_url + + private + + def update_picture + if picture_url.blank? + do_purge_picture + else + do_update_picture + end + end + + def update_picture_url + if picture_url.present? && !picture.attached? + self.update_column(:picture_url, nil) + end + end + + def do_purge_picture + self.picture.purge if self.picture.attached? + end + + def do_update_picture + downloaded_image = open(picture_url) + content_type = downloaded_image.content_type + extension = content_type.split('/').last + self.picture.attach(io: downloaded_image, filename: "avatar.#{extension}") + end + end +end diff --git a/app/models/user/with_omniauth.rb b/app/models/user/with_omniauth.rb index f4a6e3fd15189a2ec28d3acf067fdf8f13ce4627..64ba7ddc5433e77746467b4deb1b35c2d82f0089 100644 --- a/app/models/user/with_omniauth.rb +++ b/app/models/user/with_omniauth.rb @@ -43,7 +43,7 @@ module User::WithOmniauth def self.update_data_for_mapping_element_standard(user, mapping_element, sso_value) case mapping_element['internal_key'] when 'language' - user = self.set_best_id_for(user, mapping_element['type'], sso_value.first) + user = self.set_best_id_for(user, 'language', sso_value.first) when 'role' value = mapping_element['roles'].select { |key, val| val == sso_value.first }.first&.first user['role'] = value if value @@ -59,7 +59,7 @@ module User::WithOmniauth end def self.set_best_id_for(user, type, iso) - element_id = eval(type.classify).find_by(iso_code: iso)&.id + element_id = type.classify.safe_constantize.find_by(iso_code: iso)&.id user["#{type}_id"] = element_id unless element_id.nil? user end diff --git a/app/models/user/with_person.rb b/app/models/user/with_person.rb index 730ff543ad60e056e5f30653ba95b3596bea6696..7dcb4f74910d7fb18506e2326f350a8b5e4a2f5b 100644 --- a/app/models/user/with_person.rb +++ b/app/models/user/with_person.rb @@ -4,7 +4,7 @@ module User::WithPerson included do has_one :person, class_name: 'University::Person', dependent: :nullify - after_create_commit :find_or_create_person unless :server_admin? + after_create_commit :find_or_create_person, unless: :server_admin? end protected diff --git a/app/views/admin/application/featured_image/_edit.html.erb b/app/views/admin/application/featured_image/_edit.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..849fdaa5655339cd2f4d7be1b08a48cf614739fc --- /dev/null +++ b/app/views/admin/application/featured_image/_edit.html.erb @@ -0,0 +1,20 @@ +<div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/post.featured_image') %></h5> + </div> + <div class="card-body"> + <%= f.input :featured_image, + as: :single_deletable_file, + direct_upload: true, + label: false, + input_html: { accept: '.jpg,.jpeg,.png,.svg' }, + preview: true %> + <%= f.input :featured_image_alt %> + <%= f.input :featured_image_credit, + as: :summernote, + input_html: { + data: { 'summernote-config' => 'mini' } + } %> + <%= render 'admin/communication/unsplash/selector', about: about, f:f %> + </div> +</div> diff --git a/app/views/admin/application/featured_image/_show.html.erb b/app/views/admin/application/featured_image/_show.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..31ded1fa4c23cf7b987ce7b664d5f702e0b7f656 --- /dev/null +++ b/app/views/admin/application/featured_image/_show.html.erb @@ -0,0 +1,24 @@ +<% if about.featured_image.attached? %> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0 h5"> + <%= about.class.human_attribute_name :featured_image %> + </h2> + </div> + <div class="card-body"> + <% image = about.featured_image.variable? ? about.featured_image.variant(resize: '600') + : about.featured_image %> + <%= image_tag image, class: 'img-fluid mb-2' %> + <% if about.featured_image_credit %> + <p class="mb-0"> + <%= about.featured_image_alt %> + </p> + <% end %> + <% if about.featured_image_credit %> + <p class="small mb-0"> + <%= about.featured_image_credit.html_safe %> + </p> + <% end %> + </div> + </div> +<% end %> diff --git a/app/views/admin/communication/blocks/_preview.html.erb b/app/views/admin/communication/blocks/_preview.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..72d57e3ae7ad6244f32e791ac6204ec3af38cd3a --- /dev/null +++ b/app/views/admin/communication/blocks/_preview.html.erb @@ -0,0 +1,6 @@ +<h2 class="h4 mt-5"><%= block.title %></h2> +<% +@block = block +@preview = true +%> +<%= render "admin/communication/blocks/templates/#{@block.template_kind}/show" %> diff --git a/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb b/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb index db8501c429ddb80d89d16d221a164b7d57c0e136..74caee4a0f55716c0f7d1eb925d5abbd42cbc358 100644 --- a/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/call_to_action/_edit.html.erb @@ -1,6 +1,5 @@ -<div class="row"> +<div class="row mb-5"> <div class="col-xxl-4 col-md-6"> - <h3>Contenu</h3> <label class="form-label" for="text"> <%= t '.text_label' %> @@ -12,88 +11,86 @@ data-summernote-config="mini" placeholder="<%= t '.text_placeholder' %>"></textarea> </div> - <h3 class="mt-4"><%= t '.image_title' %></h3> - <div class="row"> - <div class="col-md-6"> - <div v-if="!data.image"> - <%# TODO : create a uploader vue3 component %> - <label class="form-label" - for="image"> - <%= t '.image_label' %> - </label> - <input class="form-control mb-2" - type="file" - accept="image/*" - @change="onFileImageChange( $event, data, 'image' )" - id="image"> - </div> - <div v-if="data.image"> - <img :src="getImageUrl(data.image)" - class="img-fluid" - style="max-height: 80px" - /> - <br> - <a class="btn btn-sm btn-danger mt-2" - v-on:click="data.image=null"> - <i class="fas fa-times"></i> - <%= t '.remove_image' %> - </a> - </div> - </div> - <div class="col-md-6"> - <label class="form-label" - for="image_alt"> - <%= t '.image_alt_label' %> - </label> - <input id="image_alt" - type="text" - class="form-control" - v-model="data.image_alt" - placeholder="<%= t '.image_alt_placeholder' %>" /> - </div> - </div> </div> <div class="col-xxl-4 col-md-6"> - <h3>Bouton principal</h3> + <div v-if="!data.image"> + <%# TODO : create a uploader vue3 component %> + <label class="form-label" + for="image"> + <%= t '.image_title' %> + </label> + <input class="form-control mb-2" + type="file" + accept="image/*" + @change="onFileImageChange( $event, data, 'image' )" + id="image"> + </div> + <div v-if="data.image"> + <img :src="getImageUrl(data.image)" + class="img-fluid" + style="max-height: 80px" + /> + <br> + <a class="btn btn-sm btn-danger mt-2" + v-on:click="data.image=null"> + <i class="fas fa-times"></i> + <%= t '.remove_image' %> + </a> + </div> <label class="form-label" - for="url"> - <%= t '.url_label' %> + for="image_alt"> + <%= t '.image_alt_label' %> </label> - <input id="url" - type="url" + <input id="image_alt" + type="text" class="form-control" - v-model="data.url" - placeholder="<%= t '.url_placeholder' %>" /> + v-model="data.image_alt" + placeholder="<%= t '.image_alt_placeholder' %>" /> + </div> +</div> +<h2><%= t '.buttons' %></h2> +<div class="row"> + <div class="col-xxl-4 col-md-6"> + <h3 class="h4"><%= t '.button_1' %></h3> - <label class="form-label mt-3" - for="button"> + <label class="form-label" for="button"> <%= t '.button_label' %> </label> - <input id="button" + <input id="button" type="text" class="form-control" v-model="data.button" placeholder="<%= t '.button_placeholder' %>" /> - <h3 class="mt-4">Bouton secondaire</h3> - <label class="form-label" - for="url_secondary"> + <label class="form-label mt-3" for="url"> <%= t '.url_label' %> </label> - <input id="url_secondary" + <input id="url" type="url" class="form-control" - v-model="data.url_secondary" + v-model="data.url" placeholder="<%= t '.url_placeholder' %>" /> - <label class="form-label mt-3" - for="button"> + + </div> + <div class="col-xxl-4 col-md-6"> + <h3 class="h4"><%= t '.button_2' %></h3> + + <label class="form-label" for="button"> <%= t '.button_label' %> </label> - <input id="button_secondary" + <input id="button_secondary" type="text" class="form-control" v-model="data.button_secondary" placeholder="<%= t '.button_placeholder' %>" /> + <label class="form-label mt-3" for="url_secondary"> + <%= t '.url_label' %> + </label> + <input id="url_secondary" + type="url" + class="form-control" + v-model="data.url_secondary" + placeholder="<%= t '.url_placeholder' %>" /> </div> -</div> \ No newline at end of file +</div> diff --git a/app/views/admin/communication/blocks/templates/call_to_action/_show.html.erb b/app/views/admin/communication/blocks/templates/call_to_action/_show.html.erb index 6acdd62e330833956c01b7b1109f75ea3f4ed947..bb36af7503343bb9e10a3630df0e96522018e057 100644 --- a/app/views/admin/communication/blocks/templates/call_to_action/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/call_to_action/_show.html.erb @@ -1,23 +1,35 @@ -<div class="col-md-8 col-xl-6"> - <div class="card"> - <div class="card-body"> - <% if @block.template.image %> - <div style= "max-width: 200px;" class="me-3"> - <%= kamifusen_tag @block.template.image.blob, - width: 200, - alt: @block.template.image.alt, - class: 'img-fluid' %> - <caption><%= @block.template.image.alt %></caption> - </div> - <% end %> - <hr> - <%= @block.template.text.html_safe %> - <a href="<%= @block.template.url %>" class="btn btn-primary" target="_blank" rel="noopener"> - <%= @block.template.button %> - </a> - <a href="<%= @block.template.url_secondary %>" class="btn btn-secondary" target="_blank" rel="noopener"> - <%= @block.template.button_secondary %> - </a> +<div class="<%= 'row' unless @preview %>"> + <div class="<%= 'col-md-8 col-xl-6' unless @preview %>"> + <div class="card"> + <div class="card-body"> + <% if @block.template.image %> + <div style= "max-width: 200px;" class="me-3"> + <%= kamifusen_tag @block.template.image.blob, + width: 200, + alt: @block.template.image.alt, + class: 'img-fluid' %> + <caption><%= @block.template.image.alt %></caption> + </div> + <hr> + <% end %> + <%= @block.template.text.html_safe %> + <% unless @block.template.url.blank? %> + <a href="<%= @block.template.url %>" + class="btn btn-primary" + target="_blank" + rel="noopener"> + <%= @block.template.button %> + </a> + <% end %> + <% unless @block.template.url_secondary.blank? %> + <a href="<%= @block.template.url_secondary %>" + class="btn btn-secondary" + target="_blank" + rel="noopener"> + <%= @block.template.button_secondary %> + </a> + <% end %> + </div> </div> </div> </div> diff --git a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb index 0f570a940377bc1cb0e1c86608d893742bdc86f7..f9af3e9f1f779e9f5545b946b570b0abc9d331da 100644 --- a/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb +++ b/app/views/admin/communication/blocks/templates/chapter/_edit.html.erb @@ -1,5 +1,5 @@ -<div class="row"> - <div class="col-xxl-4 col-md-6"> +<div class="row mb-4"> + <div class="col-md-6"> <label class="form-label" for="text"> <%= t '.text_label' %> @@ -14,7 +14,7 @@ </div> </div> <div class="row"> - <div class="col-xxl-4 col-md-6"> + <div class="col-md-6"> <label class="form-label" for="notes"> <%= t '.notes_label' %> diff --git a/app/views/admin/communication/blocks/templates/gallery/_show.html.erb b/app/views/admin/communication/blocks/templates/gallery/_show.html.erb index 0317b5ab85c4ec3ae2e2434148c27e6d5fb6164e..85b3ef064ef15f41b44eeade08097b24746e3299 100644 --- a/app/views/admin/communication/blocks/templates/gallery/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/gallery/_show.html.erb @@ -1,6 +1,6 @@ -<div class="row"> +<div class="<%= 'row' unless @preview %>"> <% @block.template.images_with_alt.each do |image| %> - <div class="col-xxl-2 col-xl-3 col-6"> + <div class="<%= 'col-xxl-2 col-xl-3 col-6' unless @preview %>"> <article class="card"> <% if image.blob %> <%= kamifusen_tag image.blob, width: 500, class: 'img-fluid mb-2' %> diff --git a/app/views/admin/communication/blocks/templates/organization_chart/_show.html.erb b/app/views/admin/communication/blocks/templates/organization_chart/_show.html.erb index d3b94cf8375e02c1c775c1d7deace62577bb91a6..f0181c8f801110e335636fdf6937065c9b3c0b5c 100644 --- a/app/views/admin/communication/blocks/templates/organization_chart/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/organization_chart/_show.html.erb @@ -1,7 +1,7 @@ -<div class="row"> +<div class="<%= 'row' unless @preview %>"> <% @block.template.persons_with_role.each do |person_with_role| person = person_with_role.person %> - <div class="col-md-3"> + <div class="<%= 'col-md-3' unless @preview %>"> <article class="card"> <div class="card-body"> <% if person.best_picture.attached? %> diff --git a/app/views/admin/communication/blocks/templates/pages/_show.html.erb b/app/views/admin/communication/blocks/templates/pages/_show.html.erb index 4ea468c6f75c783707c3d7db3edb64c6ce2ac8b8..2175cc87a7b1a018eda00daa0059ecf2c3d2a79f 100644 --- a/app/views/admin/communication/blocks/templates/pages/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/pages/_show.html.erb @@ -3,9 +3,9 @@ <h2 class="mb-4"><%= @block.template.main_page.slug %></h2> <% end %> <% if @block.template.selected_pages.any? %> - <div class="row"> + <div class="<%= 'row' unless @preview %>"> <% @block.template.selected_pages.each do |element| %> - <div class="col-md-4"> + <div class="<%= 'col-md-4' unless @preview %>"> <div class="card"> <div class="card-header"> <h3 class="card-title h5"><%= element.page %></h3> diff --git a/app/views/admin/communication/blocks/templates/partners/_show.html.erb b/app/views/admin/communication/blocks/templates/partners/_show.html.erb index 5417072ca991d5276224c96957e1acd61ae51039..6c9a10ff598b736478c2963eee42186f3c0a2194 100644 --- a/app/views/admin/communication/blocks/templates/partners/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/partners/_show.html.erb @@ -1,6 +1,6 @@ -<div class="row"> +<div class="<%= 'row' unless @preview %>"> <% @block.template.partners.each do |partner| %> - <div class="col-md-2"> + <div class="<%= 'col-md-2' unless @preview %>"> <article class="card"> <%= kamifusen_tag partner.blob, width: 300, diff --git a/app/views/admin/communication/blocks/templates/posts/_show.html.erb b/app/views/admin/communication/blocks/templates/posts/_show.html.erb index 06a38ef4d9c3781774271dd075a20b6fa58ad964..7f6d68cf166042ca1dddb307bacb87b7910d598e 100644 --- a/app/views/admin/communication/blocks/templates/posts/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/posts/_show.html.erb @@ -3,9 +3,9 @@ <h2 class="mb-4"><%= @block.template.category %></h2> <% end %> <% if @block.template.selected_posts.any? %> - <div class="row"> + <div class="<%= 'row' unless @preview %>"> <% @block.template.selected_posts.each do |post| %> - <div class="col-md-4"> + <div class="<%= 'col-md-4' unless @preview %>"> <div class="card"> <div class="card-header"> <h3 class="card-title h5"><%= post %></h3> diff --git a/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb b/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb index 6d8007f766d71ce160ad4534ad0882239456c845..1237e4918d078c790a58ec14957646e7a873242d 100644 --- a/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/testimonials/_show.html.erb @@ -1,6 +1,6 @@ -<div class="row"> +<div class="<%= 'row' unless @preview %>"> <% @block.template.testimonials.each do |testimonial| %> - <div class="col-xxl-4 col-xl-6"> + <div class="<%= 'col-xxl-4 col-xl-6' unless @preview %>"> <article class="card"> <div class="card-body"> <p class="lead"> diff --git a/app/views/admin/communication/blocks/templates/timeline/_show.html.erb b/app/views/admin/communication/blocks/templates/timeline/_show.html.erb index 461a8243f8eaabd4a1e9dc28fdc4d4718fe1c337..0bbdf7c177564249e2b38b7bf99ccb84bce72848 100644 --- a/app/views/admin/communication/blocks/templates/timeline/_show.html.erb +++ b/app/views/admin/communication/blocks/templates/timeline/_show.html.erb @@ -1,7 +1,7 @@ <p><%= @block.template.description %></p> -<div class="row"> +<div class="<%= 'row' unless @preview %>"> <% @block.template.events.each do |event| %> - <div class="col-xxl-4 col-xl-6"> + <div class="<%= 'col-xxl-4 col-xl-6' unless @preview %>"> <article class="card"> <div class="card-body"> <p class="lead"><%= event.title %></p> diff --git a/app/views/admin/communication/unsplash/_photo.json.jbuilder b/app/views/admin/communication/unsplash/_photo.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..34175cfbd7f1daaedbc030b953bb03b2d294d643 --- /dev/null +++ b/app/views/admin/communication/unsplash/_photo.json.jbuilder @@ -0,0 +1,6 @@ +json.id photo['id'] +json.filename "#{photo['id']}.jpg" +json.alt photo['alt_description'] +json.credit "Photo by <a href=\"https://unsplash.com/@#{ photo['user']['username'] }?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\"> #{ photo['user']['name'] }</a> on <a href=\"https://unsplash.com/?utm_source=#{ Unsplash.configuration.utm_source }&utm_medium=referral\">Unsplash</a>" +json.thumb photo['urls']['thumb'] +json.preview photo['urls']['regular'] diff --git a/app/views/admin/communication/unsplash/_selector.html.erb b/app/views/admin/communication/unsplash/_selector.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..31a02eff1287f99878d8b7abf8a42480b7377287 --- /dev/null +++ b/app/views/admin/communication/unsplash/_selector.html.erb @@ -0,0 +1,205 @@ +<% +# L'Escale du livre 2022 +search = about.to_s +# communication_website_page +about_identifier = about.class.to_s.parameterize.underscore +# .communication_website_post_featured_image +about_featured_image_image = ".#{about_identifier}_featured_image" +# #communication_website_page_featured_image_alt +about_featured_image_alt = "##{about_identifier}_featured_image_alt" +# #communication_website_page_featured_image_credit +about_featured_image_credit = "##{about_identifier}_featured_image_credit" +# fr, en... +lang = about&.language&.iso_code if about.respond_to? :language +# /admin/communication/unsplash.json?query=Page%20de%20test&per_page=12&page=1&lang=fr +path = admin_communication_unsplash_path(website_id: nil, format: :json) +%> + +<div id="unsplash-app" v-cloak> + <div class="spinner-border text-primary" role="status"> + <span class="sr-only"><%= t 'loading' %></span> + </div> + <div class="app-content"> + <button type="button" + class="btn btn-secondary btn-sm" + data-bs-toggle="modal" + data-bs-target="#unsplashModal" + > + Chercher une image + </button> + <input class="form-control string optional" + type="hidden" + name="unsplash" + v-model="selected.id"> + <div class="modal fade" + id="unsplashModal" + tabindex="-1" + aria-labelledby="Unsplash" + aria-hidden="true"> + <div class="modal-dialog modal-xl modal-dialog-centered modal-dialog-scrollable"> + <div class="modal-content"> + <div class="modal-header"> + <h5 class="modal-title" id="exampleModalLabel">Recherche d'image sur Unsplash</h5> + <button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button> + </div> + <div class="modal-body"> + <div class="row mb-3"> + <div class="col-lg-9"> + <input type="text" + name="search" + placeholder="Recherche en anglais..." + v-model="query" + class="form-control"> + </div> + <div class="col-lg-3 d-grid"> + <button type="button" + class="btn btn-primary" + v-on:click="research" + aria-label="Chercher"> + Chercher + </button> + </div> + </div> + <div class="row" ref="results"> + <p v-if="data.results.length === 0 || !data" >Aucun résultat</p> + <div v-for="image in data.results" class="col-6 col-lg-2"> + <img + :src="image.thumb" + :alt="image.alt" + v-on:click="select(image)" + class="img-fluid img-thumbnail mb-3" + :class="image === selected ? 'bg-secondary' : ''"> + </div> + </div> + <div class="d-flex" + :class="page === 1 ? 'justify-content-end' : 'justify-content-between'"> + <div href="#" + v-if="page > 1" + v-on:click="page = page - 1" + class="btn btn-light btn-sm">Page précédente</div> + <div href="#" + v-if="page < data.total_pages" + v-on:click="page = page + 1" + class="btn btn-light bt-sm">Page suivante</div> + </div> + </div> + </div> + </div> + </div> + </div> +</div> + +<%# Include vue.js before call Vue.createApp %> +<%= javascript_include_tag 'vue' %> + +<script> + var app = Vue.createApp({ + data() { + return { + selected: {}, + parameters: { + url: '<%= path %>', + per_page: 12, + lang: '<%= lang %>', + }, + query: '<%= search || "" %>', + page: 1, + targets: { + image: '<%= about_featured_image_image %> img', + imageContainer: '<%= about_featured_image_image %> .sdfi-deletable-file__preview', + alt: '<%= about_featured_image_alt %>', + credit: '<%= about_featured_image_credit %>' + }, + data: { + results: [], + total: 0 + }, + isOpened: false, + isReady: false + } + }, + mounted() { + var modalElement = document.querySelector('#unsplashModal') + this.modal = bootstrap.Modal.getOrCreateInstance(modalElement); + + modalElement.addEventListener('show.bs.modal', function (){ + this.isOpened = true; + this.search() + }.bind(this)); + + modalElement.addEventListener('hide.bs.modal', function() { + this.isOpened = false; + }.bind(this)); + + document.addEventListener("keydown", function(event) { + if (event.key === "Enter" && this.isOpened) { + event.preventDefault(); + event.stopImmediatePropagation(); + this.research(); + } + }.bind(this)); + + this.isReady = true; + }, + watch: { + page(value) { + this.search(); + } + }, + methods: { + research() { + this.page = 1; + this.search(); + }, + search() { + if (!this.query) { + return null; + } + + var xmlHttp = new XMLHttpRequest(); + xmlHttp.onreadystatechange = function() { + if (xmlHttp.readyState == 4 && xmlHttp.status == 200) { + this.data = JSON.parse(xmlHttp.responseText); + } + }.bind(this); + + xmlHttp.open( "GET", + this.parameters.url + + '?query=' + this.query + + '&per_page=' + this.parameters.per_page + + '&page=' + this.page + + '&lang=' + this.parameters.lang, + false ); + xmlHttp.send( null ); + }, + select(image) { + var inputImage = document.querySelector(this.targets.image), + inputImageContainer = document.querySelector(this.targets.imageContainer), + inputAlt = document.querySelector(this.targets.alt), + inputCredit = document.querySelector(this.targets.credit); + + this.selected = image; + + if (!inputImage) { + inputImage = document.createElement('img'); + inputImage.classList.add('img-fluid', 'img-thumbnail'); + inputImage.width = 1000; + inputImageContainer.appendChild(inputImage); + } + + inputImage.setAttribute('src', image.preview); + inputImageContainer.parentElement.classList.add('sdfi-deletable-file--with-file'); + + inputAlt.value = image.alt; + $(inputCredit).summernote('code', image.credit); + this.modal.hide(); + } + } + }); + + window.addEventListener('load', function(){ + setTimeout(function() { + app.mount('#unsplash-app'); + }, 1000); + }); +</script> diff --git a/app/views/admin/communication/unsplash/_static.html.erb b/app/views/admin/communication/unsplash/_static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..2264bbf50564bb181d33d5edd4bfc9244073e96c --- /dev/null +++ b/app/views/admin/communication/unsplash/_static.html.erb @@ -0,0 +1,10 @@ +<% +featured_image = @about&.best_featured_image || @about.featured_image +if featured_image.attached? +%> +image: + id: "<%= featured_image.blob.id %>" + alt: "<%= @about.featured_image_alt %>" + credit: > + <%= prepare_html_for_static @about.featured_image_credit, @about.university %> +<% end %> diff --git a/app/views/admin/communication/unsplash/index.json.jbuilder b/app/views/admin/communication/unsplash/index.json.jbuilder new file mode 100644 index 0000000000000000000000000000000000000000..b086b20e32d7618a7812cbc37f9fcd5bd0a3f010 --- /dev/null +++ b/app/views/admin/communication/unsplash/index.json.jbuilder @@ -0,0 +1,5 @@ +json.total @total +json.total_pages @total_pages +json.results @search do |photo| + json.partial! 'admin/communication/unsplash/photo', photo: photo +end diff --git a/app/views/admin/communication/website/categories/_form.html.erb b/app/views/admin/communication/website/categories/_form.html.erb index 82a78b73b8813675bd6f7b00cfac40a0f7de011f..39f92fdb0060b689a8d3b36c8530388d2e889ba9 100644 --- a/app/views/admin/communication/website/categories/_form.html.erb +++ b/app/views/admin/communication/website/categories/_form.html.erb @@ -31,21 +31,7 @@ </ul> </div> </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/category.featured_image') %></h5> - </div> - <div class="card-body"> - <%= f.input :featured_image, - as: :single_deletable_file, - direct_upload: true, - label: false, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, - preview: true - %> - <%= f.input :featured_image_alt %> - </div> - </div> + <%= render 'admin/application/featured_image/edit', about: category, f: f %> <div class="card flex-fill w-100"> <div class="card-header"> <h5 class="card-title mb-0"><%= t('seo') %></h5> diff --git a/app/views/admin/communication/website/categories/static.html.erb b/app/views/admin/communication/website/categories/static.html.erb index 0b08b2db648365f167fca762e705fc307669b162..6d3b3a71493bd56077b705613117b413c24102f0 100644 --- a/app/views/admin/communication/website/categories/static.html.erb +++ b/app/views/admin/communication/website/categories/static.html.erb @@ -5,10 +5,7 @@ slug: "<%= @about.path %>" parent: "<%= @about.parent.path %>" <% end %> position: <%= @about.position %> -<% if @about.best_featured_image.attached? %> -image: "<%= @about.best_featured_image.blob.id %>" -image_alt: "<%= @about.featured_image_alt %>" -<% end %> +<%= render 'admin/communication/unsplash/static' %> description: > <%= prepare_text_for_static @about.description %> --- diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index 16ce0f956b5a3c56da1e761e41ecd0c02f534e4c..2b23ceddad7d26ddbf9442c7c3b2ba59c73e1289 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -21,6 +21,18 @@ value_method: ->(p) { p[:id] } if @website.categories.any? && page.is_regular_page? %> </div> </div> + <div class="row"> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('seo') %></h5> + </div> + <div class="card-body"> + <%= f.input :description %> + </div> + </div> + </div> + </div> </div> <div class="col-md-4"> <% unless page.kind_home? %> @@ -64,30 +76,7 @@ <%= f.input :language_id, as: :hidden, input_html: { value: @website.languages.first.id }, wrapper: false %> <% end %> <% end %> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/page.featured_image') %></h5> - </div> - <div class="card-body"> - <%= f.input :featured_image, - as: :single_deletable_file, - direct_upload: true, - label: false, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, - preview: true - %> - <%= f.input :featured_image_alt %> - </div> - </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('seo') %></h5> - </div> - <div class="card-body"> - <%= f.input :description %> - </div> - </div> - </div> + <%= render 'admin/application/featured_image/edit', about: @page, f: f %> </div> </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/pages/_treebranch.html.erb b/app/views/admin/communication/website/pages/_treebranch.html.erb index 2958456fd3882d3b4a6a5f63f06d3dc2efc861ba..e8a68621861420735d600bf3bf6aeaeede374857 100644 --- a/app/views/admin/communication/website/pages/_treebranch.html.erb +++ b/app/views/admin/communication/website/pages/_treebranch.html.erb @@ -23,7 +23,10 @@ <span class="open_text"><%= t 'folder.open' %></span> <span class="close_text"><%= t 'folder.close' %></span> <% end %> - <div class="btn-group ms-auto" role="group"> + <div class="btn-group ms-auto align-items-center" role="group"> + <% if page.is_special_page? %> + <span class="me-3 show-on-hover"><%= t("communication.website.pages.defaults.#{page.kind}.admin_description") %></span> + <% end %> <%= edit_link page %> <%= destroy_link page, confirm_message: page.children.any? ? t('please_confirm_with_children') : t('please_confirm') if page.is_regular_page? %> </div> diff --git a/app/views/admin/communication/website/pages/show.html.erb b/app/views/admin/communication/website/pages/show.html.erb index c21247fd9894e5bd6375e7431b857d2a463e67d0..c9de26166a1876c6cc903232e370c3e59b8f7bbe 100644 --- a/app/views/admin/communication/website/pages/show.html.erb +++ b/app/views/admin/communication/website/pages/show.html.erb @@ -95,21 +95,7 @@ <% end %> </div> </div> - <% if @page.best_featured_image && @page.best_featured_image.attached? && @page.best_featured_image.variable? %> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/page.featured_image') %></h5> - </div> - <div class="card-body"> - <%= image_tag @page.best_featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %><br> - <% unless @page.featured_image.attached? %> - <span class="small text-muted"> - <%= t 'admin.inheritance.sentence_without_link' %> - </span> - <% end %> - </div> - </div> - <% end %> + <%= render 'admin/application/featured_image/show', about: @page %> <% if @page.description.present? %> <div class="card flex-fill w-100"> <div class="card-header"> @@ -127,6 +113,9 @@ <% content_for :preview do %> <%= @page.text.to_s %> + <% @page.blocks.ordered.each do |block| %> + <%= render 'admin/communication/blocks/preview', block: block %> + <% end %> <% end %> <% content_for :action_bar_left do %> diff --git a/app/views/admin/communication/website/pages/static.html.erb b/app/views/admin/communication/website/pages/static.html.erb index 4d2c9f2f194ee2dce4bd7c91a775615558f3a377..d4cc6399d8ca35929319ac703da27812bc3185af 100644 --- a/app/views/admin/communication/website/pages/static.html.erb +++ b/app/views/admin/communication/website/pages/static.html.erb @@ -5,10 +5,7 @@ breadcrumb_title: "<%= @about.breadcrumb_title.blank? ? @about.title : @about.br url: "<%= @about.path %>" position: <%= @about.position %> bodyclass: <%= @about.best_bodyclass %> -<% if @about.best_featured_image && @about.best_featured_image.attached? %> -image: "<%= @about.best_featured_image.blob.id %>" -image_alt: "<%= @about.featured_image_alt %>" -<% end %> +<%= render 'admin/communication/unsplash/static' %> <% if @about.children.published.any? %> children: <% @about.children.published.ordered.each do |child| %> diff --git a/app/views/admin/communication/website/posts/_form.html.erb b/app/views/admin/communication/website/posts/_form.html.erb index 3e2cee109a807c8470dff609eb5145eb5992ebf7..94e9fd7707399d706c567690b54a9bd78d05bba7 100644 --- a/app/views/admin/communication/website/posts/_form.html.erb +++ b/app/views/admin/communication/website/posts/_form.html.erb @@ -11,6 +11,33 @@ <%= f.input :text, as: :summernote %> </div> </div> + <div class="row"> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"> + <%= t('activerecord.attributes.communication/website/post.categories') %> + </h5> + </div> + <div class="card-body"> + <%= f.association :categories, + label_text: false, + as: :check_boxes, + collection: collection_tree_for_checkboxes(@website.categories) if @website.categories.any? %> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('seo') %></h5> + </div> + <div class="card-body"> + <%= f.input :description %> + </div> + </div> + </div> + </div> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> @@ -18,63 +45,41 @@ <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> - <%= f.input :slug, - as: :string, - input_html: post.persisted? ? {} : { - class: 'js-slug-input', - data: { source: '#communication_website_post_title' } - } %> + <% if can? :publish, post %> + <div class="row"> + <div class="col-6"> + <%= f.input :published %> + </div> + <div class="col-6"> + <%= f.input :pinned %> + </div> + </div> + <%= f.input :published_at, html5: true %> + <% end %> <% if @website.languages.many? %> <%= f.input :language_id, collection: @website.languages, include_blank: false %> <% elsif @website.languages.any? %> <%= f.input :language_id, as: :hidden, input_html: { value: @website.languages.first.id }, wrapper: false %> <% end %> - <% if can? :publish, post %> - <%= f.input :published %> - <%= f.input :published_at, html5: true %> - <% end %> - <%= f.input :pinned %> <% if current_user.author? || current_user.contributor? %> - <%= f.input :author_id, as: :hidden, input_html: { value: current_user.person&.id }, wrapper: false %> + <%= f.input :author_id, + as: :hidden, + input_html: { value: current_user.person&.id }, + wrapper: false %> <% else %> - <%= f.association :author, collection: current_university.people.ordered, label_method: :to_s_alphabetical %> + <%= f.association :author, + collection: current_university.people.ordered, + label_method: :to_s_alphabetical %> <% end %> + <%= f.input :slug, + as: :string, + input_html: post.persisted? ? {} : { + class: 'js-slug-input', + data: { source: '#communication_website_post_title' } + } %> </div> </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/post.featured_image') %></h5> - </div> - <div class="card-body"> - <%= f.input :featured_image, - as: :single_deletable_file, - direct_upload: true, - label: false, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, - preview: true - %> - <%= f.input :featured_image_alt %> - </div> - </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/post.categories') %></h5> - </div> - <div class="card-body"> - <%= f.association :categories, - label_text: false, - as: :check_boxes, - collection: collection_tree_for_checkboxes(@website.categories) if @website.categories.any? %> - </div> - </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('seo') %></h5> - </div> - <div class="card-body"> - <%= f.input :description %> - </div> - </div> + <%= render 'admin/application/featured_image/edit', about: @post, f: f %> </div> </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/posts/show.html.erb b/app/views/admin/communication/website/posts/show.html.erb index 732c06463116c75af776182bbad9cef574b37f19..ba74369c47f153528f11ed50d26bdc45b09bf3c5 100644 --- a/app/views/admin/communication/website/posts/show.html.erb +++ b/app/views/admin/communication/website/posts/show.html.erb @@ -13,6 +13,37 @@ <%= render 'admin/application/property/summernote_embeds', object: @post, property: :medias %> </div> </div> + <div class="row"> + <% if @post.categories.any? %> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0"><%= Communication::Website::Post.human_attribute_name('categories') %></h2> + </div> + <div class="card-body"> + <ul class="list-unstyled mb-0"> + <% @post.categories.each do |category| %> + <li><%= link_to_if can?(:read, category), category, [:admin, category] %></li> + <% end %> + </ul> + </div> + </div> + </div> + <% end %> + <% if @post.description.present? %> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h2 class="card-title mb-0"><%= t('seo') %></h2> + </div> + <div class="card-body"> + <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('description') %></h3> + <%= simple_format @post.description %> + </div> + </div> + </div> + <% end %> + </div> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> @@ -28,51 +59,29 @@ <h2 class="card-title mb-0 h5"><%= t('metadata') %></h2> </div> <div class="card-body"> + <div class="row"> + <div class="col-6"> + <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('published') %></h3> + <p> + <%= t @post.published %><% if @post.published & @post.published_at %>, + <%= l @post.published_at.to_date, format: :long if @post.published_at %> + <% end %> + </p> + </div> + <div class="col-6"> + <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('pinned') %></h3> + <p><%= t @post.pinned %></p> + </div> + </div> <% if @post.author %> <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('author') %></h3> <p><%= link_to_if can?(:read, @post.author), @post.author, admin_communication_website_author_path(@post.author) %></p> <% end %> <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('slug') %></h3> <p><%= @post.slug %></p> - <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('published') %></h3> - <p> - <%= t @post.published %><% if @post.published & @post.published_at %>, - <%= l @post.published_at, format: :long if @post.published_at %> - <% end %> - </p> - <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('pinned') %></h3> - <p><%= t @post.pinned %></p> - <% if @post.categories.any? %> - <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('categories') %></h3> - <ul class="list-unstyled mb-0"> - <% @post.categories.each do |category| %> - <li><%= link_to_if can?(:read, category), category, [:admin, category] %></li> - <% end %> - </ul> - <% end %> </div> </div> - <% if @post.featured_image.attached? && @post.featured_image.variable? %> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.communication/website/post.featured_image') %></h5> - </div> - <div class="card-body"> - <%= image_tag @post.featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %><br> - </div> - </div> - <% end %> - <% if @post.description.present? %> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('seo') %></h5> - </div> - <div class="card-body"> - <h3 class="h5"><%= Communication::Website::Post.human_attribute_name('description') %></h3> - <%= simple_format @post.description %> - </div> - </div> - <% end %> + <%= render 'admin/application/featured_image/show', about: @post %> </div> </div> <% end %> @@ -83,6 +92,9 @@ <% content_for :action_bar_left do %> <%= destroy_link @post %> + <%= link_to t('static'), + static_admin_communication_website_post_path(@post), + class: button_classes('btn-light') if current_user.server_admin? %> <% end %> <% content_for :action_bar_right do %> diff --git a/app/views/admin/communication/website/posts/static.html.erb b/app/views/admin/communication/website/posts/static.html.erb index 277e081a6f6dcb5c9748567deff921d060b9d39a..038b4bd0d57ec4b176038b636ed1bffa2e86329c 100644 --- a/app/views/admin/communication/website/posts/static.html.erb +++ b/app/views/admin/communication/website/posts/static.html.erb @@ -15,10 +15,7 @@ categories: - "<%= category.path %>" <% end %> <% end %> -<% if @about.featured_image.attached? %> -image: "<%= @about.featured_image.blob.id %>" -image_alt: "<%= @about.featured_image_alt %>" -<% end %> +<%= render 'admin/communication/unsplash/static' %> description: > <%= prepare_text_for_static @about.description %> description_short: > diff --git a/app/views/admin/education/programs/_form.html.erb b/app/views/admin/education/programs/_form.html.erb index 9b3469db1a03326873a21fdca15621b59f159403..b6cab4099e0faa561b464e580c617847ec1f6a8e 100644 --- a/app/views/admin/education/programs/_form.html.erb +++ b/app/views/admin/education/programs/_form.html.erb @@ -27,21 +27,7 @@ value_method: ->(p) { p[:id] } %> </div> </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.education/program.featured_image') %></h5> - </div> - <div class="card-body"> - <%= f.input :featured_image, - as: :single_deletable_file, - direct_upload: true, - label: false, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, - preview: true - %> - <%= f.input :featured_image_alt %> - </div> - </div> + <%= render 'admin/application/featured_image/edit', about: program, f: f %> <div class="card flex-fill w-100"> <div class="card-header"> <h5 class="card-title mb-0"><%= t('seo') %></h5> diff --git a/app/views/admin/education/programs/show.html.erb b/app/views/admin/education/programs/show.html.erb index eaa6bd15373ed2fa49c50d2ebc02332e74965d50..01d89abdd71237e7bbe79fcb12b5fd0a5501a63a 100644 --- a/app/views/admin/education/programs/show.html.erb +++ b/app/views/admin/education/programs/show.html.erb @@ -28,16 +28,7 @@ <% end %> </div> </div> - <% if @program.featured_image.attached? && @program.featured_image.variable? %> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('activerecord.attributes.education/program.featured_image') %></h5> - </div> - <div class="card-body"> - <%= image_tag @program.featured_image.variant(resize: '600'), class: 'img-fluid mb-3' %><br> - </div> - </div> - <% end %> + <%= render 'admin/application/featured_image/show', about: @program %> <% if @program.description.present? %> <div class="card flex-fill w-100"> <div class="card-header"> diff --git a/app/views/admin/education/programs/static.html.erb b/app/views/admin/education/programs/static.html.erb index b8cc5b8211d9d5c76252c356f682d63374020a8c..80c1f3dde98a0ed852867eab4624d0951eccdcdd 100644 --- a/app/views/admin/education/programs/static.html.erb +++ b/app/views/admin/education/programs/static.html.erb @@ -7,10 +7,7 @@ url: <%= @website.special_page(:education_programs).path %><%= @about.path %>/ description: > <%= prepare_text_for_static @about.description %> position: <%= @about.position %> -<% if @about.best_featured_image.attached? %> -image: "<%= @about.best_featured_image.blob.id %>" -image_alt: "<%= @about.featured_image_alt %>" -<% end %> +<%= render 'admin/communication/unsplash/static' %> category: "<%= @website.categories.find_by(program_id: @about.id)&.path %>/" teachers: <% teacher_involvements.each do |involvement| %> diff --git a/app/views/admin/research/journal/volumes/_form.html.erb b/app/views/admin/research/journal/volumes/_form.html.erb index 786bcbe9ccbfecabb1de7dbddb605e1915bc97a6..434978164a332cb7a3202ef15abc192c729c7b42 100644 --- a/app/views/admin/research/journal/volumes/_form.html.erb +++ b/app/views/admin/research/journal/volumes/_form.html.erb @@ -7,15 +7,31 @@ </div> <div class="card-body"> <%= f.input :title %> - <%= f.input :featured_image, - as: :single_deletable_file, - input_html: { accept: '.jpg,.jpeg,.png,.svg' }, - preview: 200, - direct_upload: true %> - <%= f.input :featured_image_alt %> <%= f.input :text, as: :summernote %> </div> </div> + <div class="row"> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('seo') %></h5> + </div> + <div class="card-body"> + <%= f.input :description %> + </div> + </div> + </div> + </div> + <div class="col-md-6"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('seo') %></h5> + </div> + <div class="card-body"> + <%= f.input :description %> + </div> + </div> + </div> </div> <div class="col-md-4"> <div class="card flex-fill w-100"> @@ -35,14 +51,7 @@ <%= f.input :keywords %> </div> </div> - <div class="card flex-fill w-100"> - <div class="card-header"> - <h5 class="card-title mb-0"><%= t('seo') %></h5> - </div> - <div class="card-body"> - <%= f.input :description %> - </div> - </div> + <%= render 'admin/application/featured_image/edit', about: volume, f: f %> </div> </div> <% content_for :action_bar_right do %> diff --git a/app/views/admin/research/journal/volumes/show.html.erb b/app/views/admin/research/journal/volumes/show.html.erb index cfc3f72711d0b3ba98aa25e6ad491f1e2ee05c6c..e3eaaaf28d4e15ca483530da1a2178b002d8118a 100644 --- a/app/views/admin/research/journal/volumes/show.html.erb +++ b/app/views/admin/research/journal/volumes/show.html.erb @@ -1,7 +1,7 @@ <% content_for :title, @volume %> <div class="row"> - <div class="col-md-8"> + <div class="col-md-9"> <div class="card flex-fill w-100"> <div class="card-header"> <h2 class="card-title mb-0 h5"><%= t('content') %></h2> @@ -52,7 +52,7 @@ </div> </div> </div> - <div class="col-md-4"> + <div class="col-md-3"> <div class="card flex-fill w-100"> <div class="card-header"> <h2 class="card-title mb-0 h5"><%= t('metadata') %></h2> @@ -64,16 +64,7 @@ <p><%= l @volume.published_at.to_time, format: :date_with_explicit_month if @volume.published_at %></p> </div> </div> - <% if @volume.featured_image.attached? %> - <div class="card"> - <div class="card-header"> - <h2 class="card-title"><%= Research::Journal::Volume.human_attribute_name('featured_image') %></h2> - </div> - <div class="card-body"> - <%= kamifusen_tag @volume.featured_image, class: 'img-fluid' %> - </div> - </div> - <% end %> + <%= render 'admin/application/featured_image/show', about: @volume %> <% if @volume.description.present? %> <div class="card flex-fill w-100"> <div class="card-header"> diff --git a/app/views/admin/research/journal/volumes/static.html.erb b/app/views/admin/research/journal/volumes/static.html.erb index dca4bce639c1ce6b70d1cbea313c056567023253..2bba1c9be528fbe07dbeb1b1ddddffe3e05253d2 100644 --- a/app/views/admin/research/journal/volumes/static.html.erb +++ b/app/views/admin/research/journal/volumes/static.html.erb @@ -6,10 +6,7 @@ issn: "<%= @about.journal.issn %>" keywords: > <%= @about.keywords %> date: "<%= @about.published_at.iso8601 %>" -<% if @about.featured_image.attached? %> -image: "<%= @about.featured_image.blob.id %>" -image_alt: "<%= @about.featured_image_alt %>" -<% end %> +<%= render 'admin/communication/unsplash/static' %> description: > <%= prepare_text_for_static @about.description %> --- diff --git a/app/views/server/universities/_sso_mapping.html.erb b/app/views/server/universities/_sso_mapping.html.erb index a1fc7362a035003a0e4e5cc843a494d284017d58..7bdb320c2cdcf00863c2af89c69f1ae31dd29bae 100644 --- a/app/views/server/universities/_sso_mapping.html.erb +++ b/app/views/server/universities/_sso_mapping.html.erb @@ -9,13 +9,17 @@ </div> <div class="app-form"> - <draggable :list="fields"> + <draggable :list="fields" handle=".dragHandle" > <div v-for="(field, index) in fields"> <div class="card"> <div class="card-header d-flex justify-content-between"> - <a data-bs-toggle="collapse" :href="'#sso_mapping_collapse_' + index "> - {{index + 1}}. {{ field.sso_key }} -> {{ keys[field.internal_key]}} - </a> + <div> + <i class="fas fa-arrows-alt dragHandle"></i> + + <a data-bs-toggle="collapse" :href="'#sso_mapping_collapse_' + index "> + {{index + 1}}. {{ field.sso_key }} -> {{ keys[field.internal_key]}} + </a> + </div> <a v-on:click="fields.splice(fields.indexOf(field), 1)" title="Remove field"> diff --git a/config/initializers/unsplash.rb b/config/initializers/unsplash.rb new file mode 100644 index 0000000000000000000000000000000000000000..d2f4888f25957403926d68495af552ef21a77d0a --- /dev/null +++ b/config/initializers/unsplash.rb @@ -0,0 +1,5 @@ +Unsplash.configure do |config| + config.application_access_key = ENV['UNSPLASH_ACCESS_KEY'] + config.application_secret = ENV['UNSPLASH_SECRET'] + config.utm_source = 'osuny' +end diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 22b74a1f11458031f17f16d7a46bd3f5a2175128..8c7e55dd054111c2369e58cfb05888e27b468411 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -112,6 +112,7 @@ en: description_short: Lead text featured_image: Featured image featured_image_alt: Alt text + featured_image_credit: Credit pinned: Pinned published: Published? published_at: Publication date @@ -187,12 +188,15 @@ en: text_placeholder: Enter text here call_to_action: edit: - text_label: Texte - text_placeholder: Entrer le texte ici + text_label: Text + text_placeholder: Enter text here url_label: Lien - url_placeholder: Entrer le lien ici avec "https://..." - button_label: Bouton - button_placeholder: Entrer le texte du bouton ici + url_placeholder: Enter the URL with "https://..." + buttons: Action buttons + button_1: Primary button + button_2: Secondary button + button_label: Text + button_placeholder: Enter the button text here image_title: Image image_label: Fichier remove_image: Supprimer l'image diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 0fce32c9e07ef3652c8a2a1f5ccccd8ae127f402..d4784d66599ad50eb9fb350869b0a958b3c7183d 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -112,6 +112,7 @@ fr: description_short: Chapô featured_image: Image à la une featured_image_alt: Texte alternatif + featured_image_credit: Crédit pinned: Mis en avant published: Publié ? published_at: Date de publication @@ -193,7 +194,10 @@ fr: text_placeholder: Entrer le texte ici url_label: Lien url_placeholder: Entrer le lien ici avec "https://..." - button_label: Bouton + buttons: Boutons d'action + button_1: Bouton principal + button_2: Bouton secondaire + button_label: Texte button_placeholder: Entrer le texte du bouton ici image_title: Image image_label: Fichier diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 8e3cfeb11a6f02f1bd38a25c432cc4585f7f19e5..c6716a4fe9cfc57e0a62e2d51c3fe126525317af 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -1,4 +1,5 @@ namespace :communication do + get 'unsplash' => 'unsplash#index' resources :websites do get 'home' => 'website/home#edit' patch 'home' => 'website/home#update' @@ -27,6 +28,9 @@ namespace :communication do resources :authors, controller: 'website/authors', only: [:index, :show] resources :posts, controller: 'website/posts' do post :publish, on: :collection + member do + get :static + end end resources :curations, path: 'posts/curations', diff --git a/db/migrate/20220505083115_add_credit_to_communication_website_posts.rb b/db/migrate/20220505083115_add_credit_to_communication_website_posts.rb new file mode 100644 index 0000000000000000000000000000000000000000..a5ee1fa334b45cc52d7a183f74628bbc3b653b5a --- /dev/null +++ b/db/migrate/20220505083115_add_credit_to_communication_website_posts.rb @@ -0,0 +1,5 @@ +class AddCreditToCommunicationWebsitePosts < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_posts, :featured_image_credit, :text + end +end diff --git a/db/migrate/20220505101823_add_mission_featured_image_credits.rb b/db/migrate/20220505101823_add_mission_featured_image_credits.rb new file mode 100644 index 0000000000000000000000000000000000000000..42a614e2ae667638e31d61e131938f3d4129eda0 --- /dev/null +++ b/db/migrate/20220505101823_add_mission_featured_image_credits.rb @@ -0,0 +1,9 @@ +class AddMissionFeaturedImageCredits < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_categories, :featured_image_credit, :text + add_column :communication_website_pages, :featured_image_credit, :text + add_column :education_programs, :featured_image_credit, :text + add_column :research_journal_volumes, :featured_image_credit, :text + + end +end diff --git a/db/migrate/20220505105709_add_picture_url_to_users.rb b/db/migrate/20220505105709_add_picture_url_to_users.rb new file mode 100644 index 0000000000000000000000000000000000000000..9570a3173110bf0246236ad68a91b9e1d02a3508 --- /dev/null +++ b/db/migrate/20220505105709_add_picture_url_to_users.rb @@ -0,0 +1,5 @@ +class AddPictureUrlToUsers < ActiveRecord::Migration[6.1] + def change + add_column :users, :picture_url, :string + end +end diff --git a/db/migrate/20220505131539_drop_communication_website_index_page.rb b/db/migrate/20220505131539_drop_communication_website_index_page.rb new file mode 100644 index 0000000000000000000000000000000000000000..43b1d29b9195be3cfaedde8e1adad02ab8f643d9 --- /dev/null +++ b/db/migrate/20220505131539_drop_communication_website_index_page.rb @@ -0,0 +1,5 @@ +class DropCommunicationWebsiteIndexPage < ActiveRecord::Migration[6.1] + def change + drop_table :communication_website_index_pages + end +end diff --git a/db/schema.rb b/db/schema.rb index f5a8ea0a6798ca4cb2d4de9dd7a2a509c4170244..4c5f75e298ca6a282c02fd174577cd38ba7d4d40 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: 2022_04_28_171541) do +ActiveRecord::Schema.define(version: 2022_05_05_131539) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -121,6 +121,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.string "path" t.string "featured_image_alt" t.text "text" + t.text "featured_image_credit" t.index ["communication_website_id"], name: "idx_communication_website_post_cats_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_categories_on_parent_id" t.index ["program_id"], name: "index_communication_website_categories_on_program_id" @@ -254,23 +255,6 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.index ["website_id"], name: "index_communication_website_imported_websites_on_website_id" end - create_table "communication_website_index_pages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| - t.uuid "university_id", null: false - t.uuid "communication_website_id", null: false - t.string "title" - t.string "path" - t.text "description" - t.text "text" - t.string "featured_image_alt" - t.integer "kind" - t.datetime "created_at", precision: 6, null: false - t.datetime "updated_at", precision: 6, null: false - t.string "breadcrumb_title" - t.text "header_text" - t.index ["communication_website_id"], name: "idx_comm_website_index_page_on_communication_website_id" - t.index ["university_id"], name: "index_communication_website_index_pages_on_university_id" - end - create_table "communication_website_menu_items", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.uuid "university_id", null: false t.uuid "website_id", null: false @@ -325,6 +309,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.integer "kind" t.string "bodyclass" t.uuid "language_id" + t.text "featured_image_credit" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_pages_on_language_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" @@ -349,6 +334,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.text "text" t.text "description_short" t.uuid "language_id" + t.text "featured_image_credit" t.index ["author_id"], name: "index_communication_website_posts_on_author_id" t.index ["communication_website_id"], name: "index_communication_website_posts_on_communication_website_id" t.index ["language_id"], name: "index_communication_website_posts_on_language_id" @@ -464,6 +450,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.text "results" t.text "presentation" t.text "main_information" + t.text "featured_image_credit" t.index ["parent_id"], name: "index_education_programs_on_parent_id" t.index ["university_id"], name: "index_education_programs_on_university_id" end @@ -503,6 +490,23 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.index ["university_id"], name: "index_education_schools_on_university_id" end + create_table "external_organizations", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| + t.string "title" + t.text "description" + t.string "address" + t.string "zipcode" + t.string "city" + t.string "country" + t.string "website" + t.string "phone" + t.string "mail" + t.boolean "active" + t.string "sirene" + t.integer "kind" + t.datetime "created_at", precision: 6, null: false + t.datetime "updated_at", precision: 6, null: false + end + create_table "languages", id: :uuid, default: -> { "gen_random_uuid()" }, force: :cascade do |t| t.string "name" t.string "iso_code" @@ -554,6 +558,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.string "featured_image_alt" t.boolean "published", default: false t.text "text" + t.text "featured_image_credit" 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 @@ -692,8 +697,8 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.string "linkedin" t.boolean "is_alumnus", default: false t.text "description_short" - t.boolean "is_author" t.string "name" + t.boolean "is_author" t.index ["university_id"], name: "index_university_people_on_university_id" t.index ["user_id"], name: "index_university_people_on_user_id" end @@ -782,6 +787,7 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do t.datetime "direct_otp_sent_at" t.datetime "totp_timestamp" t.string "session_token" + t.string "picture_url" t.index ["confirmation_token"], name: "index_users_on_confirmation_token", unique: true t.index ["email", "university_id"], name: "index_users_on_email_and_university_id", unique: true t.index ["encrypted_otp_secret_key"], name: "index_users_on_encrypted_otp_secret_key", unique: true @@ -819,8 +825,6 @@ ActiveRecord::Schema.define(version: 2022_04_28_171541) do add_foreign_key "communication_website_imported_posts", "universities" add_foreign_key "communication_website_imported_websites", "communication_websites", column: "website_id" add_foreign_key "communication_website_imported_websites", "universities" - add_foreign_key "communication_website_index_pages", "communication_websites" - add_foreign_key "communication_website_index_pages", "universities" add_foreign_key "communication_website_menu_items", "communication_website_menu_items", column: "parent_id" add_foreign_key "communication_website_menu_items", "communication_website_menus", column: "menu_id" add_foreign_key "communication_website_menu_items", "communication_websites", column: "website_id" diff --git a/test/fixtures/communication/website/posts.yml b/test/fixtures/communication/website/posts.yml index a887bab47171e31a3b37e43de914544b5a9e7e45..6904e28b4bd860666f259c36e006a6dd472f8f00 100644 --- a/test/fixtures/communication/website/posts.yml +++ b/test/fixtures/communication/website/posts.yml @@ -6,6 +6,7 @@ # description :text # description_short :text # featured_image_alt :string +# featured_image_credit :text # github_path :text # pinned :boolean default(FALSE) # published :boolean default(FALSE)