diff --git a/app/assets/stylesheets/admin/forms.sass b/app/assets/stylesheets/admin/forms.sass index f0f382c3312db8e69e03110774f2ee0ab4ff0282..45a124c7136f9743681fce5ecb9f64f738b14ef9 100644 --- a/app/assets/stylesheets/admin/forms.sass +++ b/app/assets/stylesheets/admin/forms.sass @@ -1,4 +1,6 @@ .simple_form - clear: both + clear: both .form-group - margin-top: 10px + margin-top: 10px +::-webkit-calendar-picker-indicator + filter: invert(1) diff --git a/app/controllers/admin/application_controller.rb b/app/controllers/admin/application_controller.rb index 777f3157b93d64fff50bb2cb22bb82d7246c9f85..0e72a394ed8a500d32d61242aaceb3114b457b3b 100644 --- a/app/controllers/admin/application_controller.rb +++ b/app/controllers/admin/application_controller.rb @@ -6,7 +6,7 @@ class Admin::ApplicationController < ApplicationController protected def breadcrumb - add_breadcrumb 'Tableau de bord', :admin_root_path + add_breadcrumb t('dashboard'), :admin_root_path end def breadcrumb_for(object, **options) diff --git a/app/controllers/admin/communication/website/application_controller.rb b/app/controllers/admin/communication/website/application_controller.rb index bc230a8e6ce743c1b51058bc67c2828879144cd0..ebf2579c9822540259e0eb4fa2066a43431ee924 100644 --- a/app/controllers/admin/communication/website/application_controller.rb +++ b/app/controllers/admin/communication/website/application_controller.rb @@ -4,8 +4,8 @@ class Admin::Communication::Website::ApplicationController < Admin::Communicatio protected def breadcrumb - super - add_breadcrumb Communication::Website.model_name.human(count: 2), admin_communication_websites_path(journal_id: nil) + add_breadcrumb t('dashboard'), :admin_root_path + add_breadcrumb '...' breadcrumb_for @website, website_id: nil end diff --git a/app/controllers/admin/communication/website/pages_controller.rb b/app/controllers/admin/communication/website/pages_controller.rb index 9dbc5af3e03f4d124bc39ebec1470f16931a7621..f7ddbfa470f82c9134c93fdd0699ea4304097988 100644 --- a/app/controllers/admin/communication/website/pages_controller.rb +++ b/app/controllers/admin/communication/website/pages_controller.rb @@ -55,7 +55,7 @@ class Admin::Communication::Website::PagesController < Admin::Communication::Web def page_params params.require(:communication_website_page) .permit(:university_id, :communication_website_id, :title, - :description, :about_type, :about_id, :slug, :published_at, + :description, :text, :about_type, :about_id, :slug, :published, :parent_id) end end diff --git a/app/controllers/admin/research/journal/application_controller.rb b/app/controllers/admin/research/journal/application_controller.rb index 7c57ae0be3016f5246491216966e68d169b7bc68..43064c7e660f1a4d38676e2978438a533fc63288 100644 --- a/app/controllers/admin/research/journal/application_controller.rb +++ b/app/controllers/admin/research/journal/application_controller.rb @@ -4,8 +4,8 @@ class Admin::Research::Journal::ApplicationController < Admin::Research::Applica protected def breadcrumb - super - add_breadcrumb Research::Journal.model_name.human(count: 2), admin_research_journals_path(journal_id: nil) + add_breadcrumb t('dashboard'), :admin_root_path + add_breadcrumb '...' breadcrumb_for @journal, journal_id: nil end diff --git a/app/controllers/admin/research/journal/articles_controller.rb b/app/controllers/admin/research/journal/articles_controller.rb index 51cc02d2e73e40b98527ec5e3aaf31318edb4e5b..563dac6ab4f1ed4fe6f2f4470aa1674ec93f6fcb 100644 --- a/app/controllers/admin/research/journal/articles_controller.rb +++ b/app/controllers/admin/research/journal/articles_controller.rb @@ -56,6 +56,6 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A end def article_params - params.require(:research_journal_article).permit(:title, :text, :published_at, :abstract, :references, :research_journal_volume_id, researcher_ids: []) + params.require(:research_journal_article).permit(:title, :text, :published_at, :abstract, :references, :keywords, :research_journal_volume_id, researcher_ids: []) end end diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb index 1f6061bd1aa3055bf3a520f3176fca45969ea475..0ded5136e6e54c3e286ff812f1810f05f1188919 100644 --- a/app/controllers/admin/research/journals_controller.rb +++ b/app/controllers/admin/research/journals_controller.rb @@ -1,4 +1,4 @@ -class Admin::Research::JournalsController < Admin::Research::Journal::ApplicationController +class Admin::Research::JournalsController < Admin::Research::ApplicationController load_and_authorize_resource class: Research::Journal def index @@ -45,6 +45,12 @@ class Admin::Research::JournalsController < Admin::Research::Journal::Applicatio protected + def breadcrumb + super + add_breadcrumb Research::Journal.model_name.human(count: 2), admin_research_journals_path(journal_id: nil) + breadcrumb_for @journal + end + def journal_params params.require(:research_journal).permit(:title, :description, :access_token, :repository) end diff --git a/app/models/communication/website/page.rb b/app/models/communication/website/page.rb index 75be9941856d2aefbb194100631c8a8867e8f267..16bc9c870a7cf5826b01d5f8febd8b68f02c023d 100644 --- a/app/models/communication/website/page.rb +++ b/app/models/communication/website/page.rb @@ -70,7 +70,6 @@ class Communication::Website::Page < ApplicationRecord end def publish_to_github - return if website&.repository.blank? github.publish kind: :pages, file: "#{ id }.html", title: to_s, diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index f3627ed7652566caa7f64c2e83e72b4d57e9be9b..063cc29b82efc35f305be9c8c47dd4157e82702c 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -45,8 +45,6 @@ class Research::Journal::Article < ApplicationRecord protected def publish_to_github - return if journal.website&.repository.blank? - github = Github.new journal.website.access_token, journal.website.repository github.publish kind: :articles, file: "#{id}.md", title: title, @@ -56,14 +54,11 @@ class Research::Journal::Article < ApplicationRecord assigns: { article: self } ) researchers.each do |researcher| - github.publish kind: :researchers, - file: "#{ researcher.id }.md", - title: researcher.to_s, - data: ApplicationController.render( - template: 'admin/research/researchers/jekyll', - layout: false, - assigns: { researcher: researcher } - ) + researcher.publish_to_website(journal.website) end end + + def github + @github ||= Github.with_site(journal.website) + end end diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index bf21a98f05dc2c6b075da61d4ada18e4199fadb7..d3f62db40e0ce82f0c66cb09a1c44387dbe6528c 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -38,13 +38,6 @@ class Research::Journal::Volume < ApplicationRecord protected def publish_to_github - return if journal.website&.repository.blank? - github = Github.new journal.website.access_token, journal.website.repository - data = ApplicationController.render( - template: 'admin/research/journal/volumes/jekyll', - layout: false, - assigns: { volume: self } - ) github.publish kind: :volumes, file: "#{id}.md", title: title, @@ -54,4 +47,8 @@ class Research::Journal::Volume < ApplicationRecord assigns: { volume: self } ) end + + def github + @github ||= Github.with_site(journal.website) + end end diff --git a/app/models/research/researcher.rb b/app/models/research/researcher.rb index bd621703995eab2c6d2872560835f79f822a7c44..e1fe55a2fc6a9a7ab4b160a72d5d61db73596015 100644 --- a/app/models/research/researcher.rb +++ b/app/models/research/researcher.rb @@ -21,8 +21,25 @@ class Research::Researcher < ApplicationRecord belongs_to :user, optional: true has_and_belongs_to_many :articles, class_name: 'Research::Journal::Article' + has_many :journals, through: :articles - after_save :update_articles + after_save :publish_to_github + + def websites + @websites ||= journals.collect(&:website).uniq.compact + end + + def publish_to_website(website) + github = Github.new website.access_token, website.repository + github.publish kind: :researchers, + file: "#{ id }.md", + title: to_s, + data: ApplicationController.render( + template: 'admin/research/researchers/jekyll', + layout: false, + assigns: { researcher: self } + ) + end def to_s "#{ first_name } #{ last_name }" @@ -30,7 +47,7 @@ class Research::Researcher < ApplicationRecord protected - def update_articles - articles.find_each &:save + def publish_to_github + websites.each { |website| publish_to_website(website) } end end diff --git a/app/services/github.rb b/app/services/github.rb index 7edb4597ebee1b10d1644e7ddce1cf9526d1c89f..c777f22ce87fd626c8720cdf8de2d2849e1fdb28 100644 --- a/app/services/github.rb +++ b/app/services/github.rb @@ -23,6 +23,7 @@ class Github sha = nil end commit_message ||= "[#{kind}] Save #{ title }" + return unless repository? client.create_contents repository, remote_file, commit_message, diff --git a/app/views/admin/communication/website/pages/_form.html.erb b/app/views/admin/communication/website/pages/_form.html.erb index 687ca8ffd316e90b660576524967962ff9fd601e..42653ea6252276951c4c119ef6a41b12e34d42a2 100644 --- a/app/views/admin/communication/website/pages/_form.html.erb +++ b/app/views/admin/communication/website/pages/_form.html.erb @@ -1,17 +1,25 @@ <%= simple_form_for [:admin, page] do |f| %> - <div class="row"> - <div class="col-md-8"> - <%= f.input :title %> - <%= f.input :slug %> - <%= f.input :description %> - </div> - <div class="col-md-4"> - <%= f.input :published_at, html5: true %> - <%= f.association :parent, collection: page.website.pages.where.not(id: page) %> - <%= f.association :website, include_blank: false %> +<div class="row"> + <div class="col-md-8"> + <%= f.input :title %> + <%= f.input :description %> + <%= f.input :text, input_html: { rows: 20 } %> + </div> + <div class="col-md-4"> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0">Metadata</h5> + </div> + <div class="card-body"> + <%= f.input :slug %> + <%= f.input :published %> + <%= f.association :parent, collection: page.website.pages.where.not(id: page) %> + <%= f.association :website, include_blank: false %> + </div> </div> </div> - <% content_for :buttons do %> - <%= submit f %> - <% end %> +</div> +<% content_for :buttons do %> + <%= submit f %> +<% end %> <% end %> diff --git a/app/views/admin/communication/website/pages/jekyll.html.erb b/app/views/admin/communication/website/pages/jekyll.html.erb index d4e12cef2a567cd9b2321f54bc2c0a6b8ad73d92..e130d6d2e1c398bc7559073bca61c42d5837b664 100644 --- a/app/views/admin/communication/website/pages/jekyll.html.erb +++ b/app/views/admin/communication/website/pages/jekyll.html.erb @@ -3,5 +3,6 @@ title: "<%= @page.title %>" permalink: "<%= @page.path %>" parent: "<%= @page.parent_id %>" description: "<%= @page.description %>" +text: "<%= @page.text %>" --- <%= @page.content_without_frontmatter.html_safe %> diff --git a/app/views/admin/research/journal/articles/_form.html.erb b/app/views/admin/research/journal/articles/_form.html.erb index 92e78c5edcffec79764348b0c7ae562a210e978e..073a5f10d6f9c284ee6deb968711c8c18d544753 100644 --- a/app/views/admin/research/journal/articles/_form.html.erb +++ b/app/views/admin/research/journal/articles/_form.html.erb @@ -8,6 +8,7 @@ </div> <div class="col-md-8"> <%= f.input :abstract, as: :text, input_html: { rows: 6 } %> + <%= f.input :keywords, as: :text, input_html: { rows: 2 } %> <%= f.input :text, input_html: { rows: 20 } %> <%= f.input :references, as: :text, input_html: { rows: 10 } %> </div> diff --git a/app/views/admin/research/journal/articles/jekyll.html.erb b/app/views/admin/research/journal/articles/jekyll.html.erb index 084ca62a91b537c1e98c8af1ad4c6b48008a0d23..9b9825573cb7b965f427126c18b6547083363806 100644 --- a/app/views/admin/research/journal/articles/jekyll.html.erb +++ b/app/views/admin/research/journal/articles/jekyll.html.erb @@ -3,12 +3,12 @@ title: "<%= @article.title %>" volume: "<%= @article.volume.id %>" publication: "<%= @article.published_at %>" abstract: "<%= @article.abstract %>" +keywords: "<%= @article.keywords %>" description: "<%= @article.abstract %>" references: "<%= @article.references %>" authors: <% @article.researchers.each do |researcher| %> - "<%= researcher.id %>" <% end %> -tags: --- <%= simple_format @article.text %> diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index b87fa77778e453a89e7d3f7599d0855efaf4e9fc..479a20a20ffa645aca7d0d4f6bb6a09a5165c5e4 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -18,3 +18,11 @@ fr: about_: Aucun sujet (site indépendant) about_Research::Journal: Site de revue scientifique about_School: Site d'école + communication/website/page: + published: Publié ? + parent: Page parente + website: Site Web + simple_form: + hints: + communication/website/page: + slug: test diff --git a/db/migrate/20210909064436_add_keywords_to_research_journal_articles.rb b/db/migrate/20210909064436_add_keywords_to_research_journal_articles.rb new file mode 100644 index 0000000000000000000000000000000000000000..256d2c647b73a1f4886994cea1c5c3adaedc86a5 --- /dev/null +++ b/db/migrate/20210909064436_add_keywords_to_research_journal_articles.rb @@ -0,0 +1,5 @@ +class AddKeywordsToResearchJournalArticles < ActiveRecord::Migration[6.1] + def change + add_column :research_journal_articles, :keywords, :text + end +end diff --git a/db/migrate/20210909071812_add_text_to_communication_website_page.rb b/db/migrate/20210909071812_add_text_to_communication_website_page.rb new file mode 100644 index 0000000000000000000000000000000000000000..3e5e4df4f17013b563f51f494c31520296ea1f30 --- /dev/null +++ b/db/migrate/20210909071812_add_text_to_communication_website_page.rb @@ -0,0 +1,5 @@ +class AddTextToCommunicationWebsitePage < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_pages, :text, :text + end +end diff --git a/db/migrate/20210909072507_fix_pages.rb b/db/migrate/20210909072507_fix_pages.rb new file mode 100644 index 0000000000000000000000000000000000000000..13801ec1b6f91f672294d528aad59d79735f1140 --- /dev/null +++ b/db/migrate/20210909072507_fix_pages.rb @@ -0,0 +1,6 @@ +class FixPages < ActiveRecord::Migration[6.1] + def change + add_column :communication_website_pages, :published, :boolean, default: false + remove_column :communication_website_pages, :published_at + end +end diff --git a/db/schema.rb b/db/schema.rb index 89830e39fbacb312ee0e70c0155b64de4e5c03f9..774a1738d61bfc7b45db4358e5e1355c8c29ad36 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_09_08_094427) do +ActiveRecord::Schema.define(version: 2021_09_09_072507) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -45,13 +45,14 @@ ActiveRecord::Schema.define(version: 2021_09_08_094427) do t.text "description" t.string "slug" t.text "path" - t.datetime "published_at" t.uuid "parent_id" t.integer "position", default: 0, null: false t.string "about_type" t.uuid "about_id" t.datetime "created_at", precision: 6, null: false t.datetime "updated_at", precision: 6, null: false + t.text "text" + t.boolean "published", default: false t.index ["about_type", "about_id"], name: "index_communication_website_pages_on_about" t.index ["communication_website_id"], name: "index_communication_website_pages_on_communication_website_id" t.index ["parent_id"], name: "index_communication_website_pages_on_parent_id" @@ -105,6 +106,7 @@ ActiveRecord::Schema.define(version: 2021_09_08_094427) do t.uuid "updated_by_id" t.text "abstract" t.text "references" + t.text "keywords" 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"