diff --git a/app/controllers/admin/research/journal/articles_controller.rb b/app/controllers/admin/research/journal/articles_controller.rb index 15922af61d816a6086b18a16dba05a75b3e91ad2..f42168be20eeec033063b733e7cf350caa147f7c 100644 --- a/app/controllers/admin/research/journal/articles_controller.rb +++ b/app/controllers/admin/research/journal/articles_controller.rb @@ -24,7 +24,7 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A university: current_university, updated_by: current_user ) - if @article.save + if @article.save_and_sync redirect_to admin_research_journal_article_path(@article), notice: t('admin.successfully_created_html', model: @article.to_s) else breadcrumb @@ -34,7 +34,7 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A def update @article.updated_by = current_user - if @article.update(article_params) + if @article.update_and_sync(article_params) redirect_to admin_research_journal_article_path(@article), notice: t('admin.successfully_updated_html', model: @article.to_s) else breadcrumb @@ -44,7 +44,7 @@ class Admin::Research::Journal::ArticlesController < Admin::Research::Journal::A end def destroy - @article.destroy + @article.destroy_and_sync redirect_to admin_research_journal_path(@journal), notice: t('admin.successfully_destroyed_html', model: @article.to_s) end diff --git a/app/controllers/admin/research/journal/volumes_controller.rb b/app/controllers/admin/research/journal/volumes_controller.rb index 5156eced8538df0fcea8a0fd0f4d5bf4fd1aba62..5c9f49db20aa8bddcaa1b63db1dffa5caeac5693 100644 --- a/app/controllers/admin/research/journal/volumes_controller.rb +++ b/app/controllers/admin/research/journal/volumes_controller.rb @@ -21,7 +21,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap def create @volume.assign_attributes(journal: @journal, university: current_university) - if @volume.save + if @volume.save_and_sync redirect_to admin_research_journal_volume_path(@volume), notice: t('admin.successfully_created_html', model: @volume.to_s) else breadcrumb @@ -30,7 +30,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap end def update - if @volume.update(volume_params) + 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 breadcrumb @@ -40,7 +40,7 @@ class Admin::Research::Journal::VolumesController < Admin::Research::Journal::Ap end def destroy - @volume.destroy + @volume.destroy_and_sync redirect_to admin_research_journal_path(@journal), notice: t('admin.successfully_destroyed_html', model: @volume.to_s) end diff --git a/app/controllers/admin/research/journals_controller.rb b/app/controllers/admin/research/journals_controller.rb index 8bcd6454a07d7d401aa918eed48e4fb84d8d70b5..343082a6e9560021d93582600d18efe198bba1a7 100644 --- a/app/controllers/admin/research/journals_controller.rb +++ b/app/controllers/admin/research/journals_controller.rb @@ -23,7 +23,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll end def create - if @journal.save + if @journal.save_and_sync redirect_to [:admin, @journal], notice: t('admin.successfully_created_html', model: @journal.to_s) else breadcrumb @@ -32,7 +32,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll end def update - if @journal.update(journal_params) + if @journal.update_and_sync(journal_params) redirect_to [:admin, @journal], notice: t('admin.successfully_updated_html', model: @journal.to_s) else breadcrumb @@ -42,7 +42,7 @@ class Admin::Research::JournalsController < Admin::Research::ApplicationControll end def destroy - @journal.destroy + @journal.destroy_and_sync redirect_to admin_research_journals_url, notice: t('admin.successfully_destroyed_html', model: @journal.to_s) end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index 1b9d8372dfdbcf191ea928636b476120088edda9..878449d818c642ed86500d6c3cc06e6cf23cd433 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -33,7 +33,7 @@ class Communication::Website < ApplicationRecord include WithAbouts include WithImport - belongs_to :university + belongs_to :university scope :ordered, -> { order(:name) } @@ -46,6 +46,6 @@ class Communication::Website < ApplicationRecord end def git_dependencies_static - pages + posts + categories + menus + members + [home] + (pages + posts + categories + menus + members + [home] + [about]).compact end end diff --git a/app/models/communication/website/git_file.rb b/app/models/communication/website/git_file.rb index 2d9d3ed3b382a64489928ce3eb54170f3f170865..4cef3c3d00521f91174378570b745692c207b8e2 100644 --- a/app/models/communication/website/git_file.rb +++ b/app/models/communication/website/git_file.rb @@ -39,12 +39,11 @@ class Communication::Website::GitFile < ApplicationRecord end def should_update? - previous_path != path || previous_sha != sha + !path.nil? && (previous_path != path || previous_sha != sha) end def should_destroy? - # TODO - false + path.nil? end def path diff --git a/app/models/communication/website/with_git_repository.rb b/app/models/communication/website/with_git_repository.rb index c283b79495f4005fe578831c2385cb9aa1d85f35..436b1f64ef663f438eff86b1efabc1e93b935e83 100644 --- a/app/models/communication/website/with_git_repository.rb +++ b/app/models/communication/website/with_git_repository.rb @@ -2,7 +2,7 @@ module Communication::Website::WithGitRepository extend ActiveSupport::Concern included do - has_many :git_files, + has_many :website_git_files, class_name: 'Communication::Website::GitFile', dependent: :destroy end diff --git a/app/models/research/journal.rb b/app/models/research/journal.rb index 0a695ba4d94b53ce8769aa91dfd8c7d9a0bf2764..f1a607d21095a8059defe0491e3b85d6097560a0 100644 --- a/app/models/research/journal.rb +++ b/app/models/research/journal.rb @@ -27,6 +27,7 @@ class Research::Journal < ApplicationRecord has_many :websites, class_name: 'Communication::Website', as: :about has_many :volumes, foreign_key: :research_journal_id has_many :articles, foreign_key: :research_journal_id + has_many :researchers, through: :articles scope :ordered, -> { order(:title) } @@ -34,15 +35,11 @@ class Research::Journal < ApplicationRecord "#{title}" end - def git_path_static - "data/journal.yml" + def git_dependencies_static + articles + volumes + researchers end - def to_static(github_file) - { - title: title, - description: description, - issn: issn - }.deep_stringify_keys.to_yaml.lines[1..-1].join + def git_path_static + "data/journal.yml" end end diff --git a/app/models/research/journal/article.rb b/app/models/research/journal/article.rb index cc03d5896e40eff7a6bc6dea696e3a4c46981e5e..471619898b25d1859b2d4f873219867b121e5919 100644 --- a/app/models/research/journal/article.rb +++ b/app/models/research/journal/article.rb @@ -48,7 +48,6 @@ class Research::Journal::Article < ApplicationRecord has_many :websites, -> { distinct }, through: :journal validates :title, :published_at, presence: true - after_commit :update_researchers scope :ordered, -> { order(:published_at, :created_at) } @@ -56,6 +55,18 @@ class Research::Journal::Article < ApplicationRecord "/assets/articles/#{id}/#{pdf.filename}" end + def git_path_static + if published_at + "content/articles/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" + else + nil + end + end + + def git_dependencies_static + researchers + end + def to_s "#{ title }" end diff --git a/app/models/research/journal/volume.rb b/app/models/research/journal/volume.rb index b00038a2a192fa37cb89d32c54a916e69b7ee532..0537912b2f9c9fe85fdb2c36faec14f6a7eba934 100644 --- a/app/models/research/journal/volume.rb +++ b/app/models/research/journal/volume.rb @@ -34,6 +34,7 @@ class Research::Journal::Volume < ApplicationRecord belongs_to :journal, foreign_key: :research_journal_id has_many :articles, foreign_key: :research_journal_volume_id has_many :websites, -> { distinct }, through: :journal + has_many :researchers, through: :articles scope :ordered, -> { order(number: :desc, published_at: :desc) } @@ -45,6 +46,18 @@ class Research::Journal::Volume < ApplicationRecord journal.website end + def git_path_static + if published_at + "content/volumes/#{published_at.year}/#{published_at.strftime "%Y-%m-%d"}-#{slug}.html" + else + nil + end + end + + def git_dependencies_static + articles + researchers + end + def to_s "##{ number } #{ title }" end diff --git a/app/services/git/repository.rb b/app/services/git/repository.rb index ae190369fa0ae8674fabe4aade2055e3ade5f241..afbd697a9337b28c16027802edfd80d8a2987f93 100644 --- a/app/services/git/repository.rb +++ b/app/services/git/repository.rb @@ -38,7 +38,7 @@ class Git::Repository elsif file.should_update? provider.update_file file.path, file.previous_path, file.to_s elsif file.should_destroy? - provider.destroy_file file.path + provider.destroy_file file.previous_path end end end diff --git a/app/views/admin/education/schools/static.html.erb b/app/views/admin/education/schools/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..19933a14492793a2156e7cb73d0cb8a5462a33fb --- /dev/null +++ b/app/views/admin/education/schools/static.html.erb @@ -0,0 +1,14 @@ +--- +name: > + <%= @school.name %> +address: > + <%= @school.address %> +zipcode: > + <%= @school.zipcode %> +city: > + <%= @school.city %> +country: > + <%= ISO3166::Country[@school.country].translations[@school.country.downcase] %> +phone: > + <%= @school.phone %> +--- diff --git a/app/views/admin/research/journal/volumes/show.html.erb b/app/views/admin/research/journal/volumes/show.html.erb index 1e1644ef767689adb0850d73c05701c5fd6a6788..68e885b99d14da18b505e989277412b827a055e6 100644 --- a/app/views/admin/research/journal/volumes/show.html.erb +++ b/app/views/admin/research/journal/volumes/show.html.erb @@ -25,7 +25,7 @@ <h3 class="h5"><%= Research::Journal::Volume.human_attribute_name('number') %></h3> <p><%= @volume.number %></p> <h3 class="h5"><%= Research::Journal::Volume.human_attribute_name('published_at') %></h3> - <p><%=l @volume.published_at.to_time, format: :date_with_explicit_month %></p> + <p><%= l @volume.published_at.to_time, format: :date_with_explicit_month if @volume.published_at %></p> </div> </div> <% if @volume.cover.attached? %> diff --git a/app/views/admin/research/journals/static.html.erb b/app/views/admin/research/journals/static.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..d44e4ec185a045bc91b290be335075f1fe508f73 --- /dev/null +++ b/app/views/admin/research/journals/static.html.erb @@ -0,0 +1,8 @@ +--- +title: > + <%= @journal.title %> +description: > + <%= @journal.description %> +issn: > + <%= @journal.issn %> +---