From 38bb3d01297fb3f67913a11148ca093cda41226c Mon Sep 17 00:00:00 2001 From: pabois <pierreandre.boissinot@noesya.coop> Date: Thu, 24 Feb 2022 12:22:04 +0100 Subject: [PATCH] close #210 --- app/models/communication/website.rb | 3 +- .../communication/website/configs/base_url.rb | 11 ++++++ .../website/configs/permalinks.rb | 11 ++++++ .../communication/website/index_page.rb | 2 +- .../communication/website/with_configs.rb | 15 ++++++++ .../website/configs/base_urls/static.html.erb | 1 + .../configs/permalinks/static.html.erb | 12 +++++++ .../communication/websites/_form.html.erb | 14 ++++---- package-lock.json | 34 +++++++++++++++++++ package.json | 1 + yarn.lock | 12 +++++++ 11 files changed, 107 insertions(+), 9 deletions(-) create mode 100644 app/models/communication/website/configs/base_url.rb create mode 100644 app/models/communication/website/configs/permalinks.rb create mode 100644 app/models/communication/website/with_configs.rb create mode 100644 app/views/admin/communication/website/configs/base_urls/static.html.erb create mode 100644 app/views/admin/communication/website/configs/permalinks/static.html.erb create mode 100644 package-lock.json diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index a5ff5c580..4220037d6 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -34,6 +34,7 @@ # class Communication::Website < ApplicationRecord include WithAbouts + include WithConfigs include WithGit include WithGitRepository include WithImport @@ -59,7 +60,7 @@ class Communication::Website < ApplicationRecord def git_dependencies(website) dependencies = ( - [self] + + [self, config_permalinks, config_base_url] + pages + pages.map(&:active_storage_blobs).flatten + posts + posts.map(&:active_storage_blobs).flatten + [index_for(:home)] + index_for(:home).active_storage_blobs + diff --git a/app/models/communication/website/configs/base_url.rb b/app/models/communication/website/configs/base_url.rb new file mode 100644 index 000000000..890fbc8cb --- /dev/null +++ b/app/models/communication/website/configs/base_url.rb @@ -0,0 +1,11 @@ +class Communication::Website::Configs::BaseUrl < Communication::Website + + def self.polymorphic_name + 'Communication::Website::Configs::BaseUrl' + end + + def git_path(website) + "config/production/config.yaml" + end + +end diff --git a/app/models/communication/website/configs/permalinks.rb b/app/models/communication/website/configs/permalinks.rb new file mode 100644 index 000000000..64df73301 --- /dev/null +++ b/app/models/communication/website/configs/permalinks.rb @@ -0,0 +1,11 @@ +class Communication::Website::Configs::Permalinks < Communication::Website + + def self.polymorphic_name + 'Communication::Website::Configs::Permalinks' + end + + def git_path(website) + "config/_default/permalinks.yaml" + end + +end diff --git a/app/models/communication/website/index_page.rb b/app/models/communication/website/index_page.rb index d1991abb1..9366722a9 100644 --- a/app/models/communication/website/index_page.rb +++ b/app/models/communication/website/index_page.rb @@ -58,7 +58,7 @@ class Communication::Website::IndexPage < ApplicationRecord end def git_dependencies(website) - [self] + active_storage_blobs + website.menus + [self] + active_storage_blobs + website.menus + [website.config_permalinks] end def git_destroy_dependencies(website) diff --git a/app/models/communication/website/with_configs.rb b/app/models/communication/website/with_configs.rb new file mode 100644 index 000000000..c08987ad4 --- /dev/null +++ b/app/models/communication/website/with_configs.rb @@ -0,0 +1,15 @@ +module Communication::Website::WithConfigs + extend ActiveSupport::Concern + + included do + + def config_permalinks + @config_permalinks ||= Communication::Website::Configs::Permalinks.find(id) + end + + def config_base_url + @config_base_url ||= Communication::Website::Configs::BaseUrl.find(id) + end + + end +end diff --git a/app/views/admin/communication/website/configs/base_urls/static.html.erb b/app/views/admin/communication/website/configs/base_urls/static.html.erb new file mode 100644 index 000000000..47d8819e1 --- /dev/null +++ b/app/views/admin/communication/website/configs/base_urls/static.html.erb @@ -0,0 +1 @@ +baseURL: <%= @website.url %> diff --git a/app/views/admin/communication/website/configs/permalinks/static.html.erb b/app/views/admin/communication/website/configs/permalinks/static.html.erb new file mode 100644 index 000000000..8a4a34596 --- /dev/null +++ b/app/views/admin/communication/website/configs/permalinks/static.html.erb @@ -0,0 +1,12 @@ +posts: /<%= @website.index_for(:communication_posts).path %>/:year/:month/:day/:slug/ +categories: /<%= @website.index_for(:communication_posts).path %>/:slug/ +persons: /<%= @website.index_for(:persons).path %>/:slug/ +authors: /<%= @website.index_for(:persons).path %>/:slug/<%= @website.index_for(:communication_posts).path %>/ +<%# ces paths complémentaires sont nécessairesà Hugo mais on ne les utilise pas %> +<% if @website.about_school? %> +administrators: /<%= @website.index_for(:persons).path %>/:slug/roles/ +teachers: /<%= @website.index_for(:persons).path %>/:slug/programs/ +<% end %> +<% if @website.about_journal? %> +researchers: /<%= @website.index_for(:persons).path %>/:slug/articles/ +<% end %> diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 300b47631..8227d6c68 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -3,10 +3,11 @@ <div class="col-md-4"> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title mb-0"><%= t('content') %></h5> + <h5 class="card-title mb-0"><%= t('metadata') %></h5> </div> <div class="card-body"> <%= f.input :name %> + <%= f.input :url %> <%= f.input :about_type, collection: Communication::Website.about_types, input_html: { data: { conditional: true } }, @@ -44,20 +45,19 @@ <div class="col-md-8"> <div class="card flex-fill w-100"> <div class="card-header"> - <h5 class="card-title mb-0"><%= t('metadata') %></h5> + <h5 class="card-title mb-0"><%= t('communication.website.git') %></h5> </div> <div class="card-body"> - - <p class="mt-4"><strong><%= t('communication.website.git') %></strong></p> <div class="row"> <div class="col-md-6"> - <%= f.input :url %> - <%= f.input :repository %> + <%= f.input :git_provider, include_blank: false %> </div> <div class="col-md-6"> - <%= f.input :git_provider, include_blank: false %> <%= f.input :access_token %> </div> + <div class="col-md-6"> + <%= f.input :repository %> + </div> </div> </div> diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 000000000..ed5d2d5dc --- /dev/null +++ b/package-lock.json @@ -0,0 +1,34 @@ +{ + "requires": true, + "lockfileVersion": 1, + "dependencies": { + "16": { + "version": "0.0.2", + "resolved": "https://registry.npmjs.org/16/-/16-0.0.2.tgz", + "integrity": "sha1-Hh9noWM+GADBZ+DnA9/wiQw+FTo=", + "requires": { + "numeric": "^1.2.6" + } + }, + "cropperjs": { + "version": "1.5.12" + }, + "jquery-cropper": { + "version": "1.0.1" + }, + "notyf": { + "version": "3.10.0" + }, + "numeric": { + "version": "1.2.6", + "resolved": "https://registry.npmjs.org/numeric/-/numeric-1.2.6.tgz", + "integrity": "sha1-dlsCvvl5iPz4gNTrPza4D6MTNao=" + }, + "slug": { + "version": "5.1.0" + }, + "sortablejs": { + "version": "1.14.0" + } + } +} diff --git a/package.json b/package.json index 706af3330..287e8a5c7 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "npm": "8" }, "dependencies": { + "16": "0.0.2", "cropperjs": "^1.5.12", "jquery-cropper": "^1.0.1", "notyf": "^3.10.0", diff --git a/yarn.lock b/yarn.lock index 9d2b82f2d..32fc5f3bc 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2,6 +2,13 @@ # yarn lockfile v1 +"16@0.0.2": + version "0.0.2" + resolved "https://registry.yarnpkg.com/16/-/16-0.0.2.tgz#1e1f67a1633e1800c167e0e703dff0890c3e153a" + integrity sha1-Hh9noWM+GADBZ+DnA9/wiQw+FTo= + dependencies: + numeric "^1.2.6" + "@babel/parser@^7.16.4": version "7.17.3" resolved "https://registry.yarnpkg.com/@babel/parser/-/parser-7.17.3.tgz#b07702b982990bf6fdc1da5049a23fece4c5c3d0" @@ -134,6 +141,11 @@ notyf@^3.10.0: resolved "https://registry.yarnpkg.com/notyf/-/notyf-3.10.0.tgz#67a64443c69ea0e6495c56ea0f91198860163d06" integrity sha512-Mtnp+0qiZxgrH+TzVlzhWyZceHdAZ/UWK0/ju9U0HQeDpap1mZ8cC7H5wSI5mwgni6yeAjaxsTw0sbMK+aSuHw== +numeric@^1.2.6: + version "1.2.6" + resolved "https://registry.yarnpkg.com/numeric/-/numeric-1.2.6.tgz#765b02bef97988fcf880d4eb3f36b80fa31335aa" + integrity sha1-dlsCvvl5iPz4gNTrPza4D6MTNao= + picocolors@^1.0.0: version "1.0.0" resolved "https://registry.yarnpkg.com/picocolors/-/picocolors-1.0.0.tgz#cb5bdc74ff3f51892236eaf79d68bc44564ab81c" -- GitLab