diff --git a/app/controllers/admin/communication/websites_controller.rb b/app/controllers/admin/communication/websites_controller.rb index cc504ae9b52e6b269ebc7c9a0117af03cf83deae..d56f1e72a085005dc13e5d8b92d505acfc65422f 100644 --- a/app/controllers/admin/communication/websites_controller.rb +++ b/app/controllers/admin/communication/websites_controller.rb @@ -22,6 +22,11 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati render body: @website.preview_style, content_type: "text/css" end + def analytics + breadcrumb + add_breadcrumb t('communication.website.analytics') + end + def new breadcrumb end @@ -76,7 +81,7 @@ class Admin::Communication::WebsitesController < Admin::Communication::Applicati def website_params params.require(:communication_website).permit( - :name, :url, :repository, :access_token, :about_type, :about_id, :git_provider, :git_endpoint, language_ids: [] + :name, :url, :repository, :access_token, :about_type, :about_id, :git_provider, :git_endpoint, :plausible_url, language_ids: [] ) end end diff --git a/app/models/communication/website.rb b/app/models/communication/website.rb index f557c652f31d6f1d74fc770307e661123c82580b..ec8ffed12ad4f46f3cac69fb9e2a8e1264d54b47 100644 --- a/app/models/communication/website.rb +++ b/app/models/communication/website.rb @@ -8,6 +8,7 @@ # git_endpoint :string # git_provider :integer default("github") # name :string +# plausible_url :string # repository :string # style :text # style_updated_at :date diff --git a/app/models/communication/website/configs/base_url.rb b/app/models/communication/website/configs/base_url.rb index f4eaa374522d9f886de6f95587f90d375e3294d2..2daeee8a29469d9f54419c721df481893f9f4e46 100644 --- a/app/models/communication/website/configs/base_url.rb +++ b/app/models/communication/website/configs/base_url.rb @@ -8,6 +8,7 @@ # git_endpoint :string # git_provider :integer default("github") # name :string +# plausible_url :string # repository :string # style :text # style_updated_at :date diff --git a/app/models/communication/website/configs/permalinks.rb b/app/models/communication/website/configs/permalinks.rb index 162ec50078308d86eebc5dce705f9515ceff59ae..df46d3c8fecc75aba6cf25a7418402a7e225dbca 100644 --- a/app/models/communication/website/configs/permalinks.rb +++ b/app/models/communication/website/configs/permalinks.rb @@ -8,6 +8,7 @@ # git_endpoint :string # git_provider :integer default("github") # name :string +# plausible_url :string # repository :string # style :text # style_updated_at :date diff --git a/app/services/icon.rb b/app/services/icon.rb index 54cdb9079508a4aa24d4148d461f9a03ff108a42..0f3dec930d82a624adc18d11b5261f3785760a92 100644 --- a/app/services/icon.rb +++ b/app/services/icon.rb @@ -4,8 +4,12 @@ class Icon COMMUNICATION_EXTRANET = 'project-diagram' COMMUNICATION_WEBSITE = 'sitemap' + COMMUNICATION_WEBSITE_HOME = 'home' COMMUNICATION_WEBSITE_POST = 'newspaper' COMMUNICATION_WEBSITE_PAGE = 'file' + COMMUNICATION_WEBSITE_PAGES = 'sitemap' + COMMUNICATION_WEBSITE_MENUS = 'bars' + COMMUNICATION_WEBSITE_ANALYTICS = 'chart-pie' EDUCATION_DIPLOMA = 'graduation-cap' EDUCATION_PROGRAM = 'chalkboard-teacher' diff --git a/app/views/admin/communication/websites/_form.html.erb b/app/views/admin/communication/websites/_form.html.erb index 99bbb9dd66925ba92bbf37a4defd5ea7cfd98067..9484c19f183c12611641295474bc4438b8f33d2a 100644 --- a/app/views/admin/communication/websites/_form.html.erb +++ b/app/views/admin/communication/websites/_form.html.erb @@ -34,6 +34,13 @@ </div> </div> </div> + <div class="card flex-fill w-100"> + <div class="card-header"> + <h5 class="card-title mb-0"><%= t('communication.website.analytics') %></h5> + </div> + <div class="card-body"> + <%= f.input :plausible_url %> + </div> </div> </div> diff --git a/app/views/admin/communication/websites/_sidebar.html.erb b/app/views/admin/communication/websites/_sidebar.html.erb index 2c69f37e5f1d21a5e4043b16f4e0569bdcba8b5c..c9b6d1d07be8bf13de08dc88b074b9aa0d2f70f7 100644 --- a/app/views/admin/communication/websites/_sidebar.html.erb +++ b/app/views/admin/communication/websites/_sidebar.html.erb @@ -3,39 +3,49 @@ <div class="card"> <div class="list-group list-group-flush" role="tablist"> <% - [ + navigation = [ { title: Communication::Website.model_name.human, - path: admin_communication_website_path(id: @website), - icon: 'fas fa-home', + path: admin_communication_website_path(id: @website, website_id: nil), + icon: Icon::COMMUNICATION_WEBSITE_HOME, ability: can?(:read, @website) }, { title: t('admin.communication.website.pages.structure'), path: admin_communication_website_pages_path(website_id: @website), - icon: 'fas fa-sitemap', + icon: Icon::COMMUNICATION_WEBSITE_PAGES, ability: can?(:read, Communication::Website::Page) }, { title: Communication::Website::Post.model_name.human(count: 2), path: admin_communication_website_posts_path(website_id: @website), - icon: 'fas fa-newspaper', + icon: Icon::COMMUNICATION_WEBSITE_POST, ability: can?(:read, Communication::Website::Post) }, { title: Communication::Website::Menu.model_name.human(count: 2), path: admin_communication_website_menus_path(website_id: @website), - icon: 'fas fa-bars', + icon: Icon::COMMUNICATION_WEBSITE_MENUS, ability: can?(:read, Communication::Website::Category) } - ].each do |object| + ] + + navigation << { + title: t('communication.website.analytics'), + path: analytics_admin_communication_website_path(@website.id, website_id: nil), + icon: Icon::COMMUNICATION_WEBSITE_ANALYTICS, + ability: can?(:read, @website) + } if @website.plausible_url.present? + + navigation.each_with_index do |object, index| next unless object[:ability] - active = object[:path].in? request.path + active = index.zero? ? object[:path] == request.path + : object[:path].in?(request.path) %> <a class="list-group-item list-group-item-action<%= ' active' if active %>" href="<%= object[:path] %>"> <%= object[:title].html_safe %> <span class="float-end"> - <i class="<%= object[:icon] %>"></i> + <i class="fas fa-<%= object[:icon] %>"></i> </span> </a> <% end %> diff --git a/app/views/admin/communication/websites/analytics.html.erb b/app/views/admin/communication/websites/analytics.html.erb new file mode 100644 index 0000000000000000000000000000000000000000..a33f7b6b7650bd8b6cd5331127e81dcb18e3db7c --- /dev/null +++ b/app/views/admin/communication/websites/analytics.html.erb @@ -0,0 +1,6 @@ +<% content_for :title, t('communication.website.analytics') %> +<%= render 'admin/communication/websites/sidebar' do %> + <iframe plausible-embed src="<%= @website.plausible_url %>&embed=true&theme=light&background=transparent" scrolling="no" frameborder="0" loading="lazy" style="width: 1px; min-width: 100%; height: 1600px;"></iframe> + <div style="font-size: 14px; padding-bottom: 14px;">Stats powered by <a target="_blank" style="color: #4F46E5; text-decoration: underline;" href="https://plausible.io">Plausible Analytics</a></div> + <script async src="https://plausible.io/js/embed.host.js"></script> +<% end %> \ No newline at end of file diff --git a/app/views/admin/communication/websites/show.html.erb b/app/views/admin/communication/websites/show.html.erb index 04543e484172bfef99ad86a914ce8a4cb4d54fa8..3362360524d3b3448fa74dc05decb4d56ddd905b 100644 --- a/app/views/admin/communication/websites/show.html.erb +++ b/app/views/admin/communication/websites/show.html.erb @@ -2,7 +2,7 @@ <% content_for :title_right do %> <% unless @website.url.blank? %> - <%= link_to @website.url, @website.url, target: :_blank %><br> + <%= link_to @website.url, @website.url, target: :_blank %> • <% end %> <%= I18n.t("activerecord.attributes.communication/website.about_#{@website.about_type}") %> <% if @website.about %> diff --git a/config/locales/communication/en.yml b/config/locales/communication/en.yml index 4715f3fe53e92842188d755e94bfd56a2d1f731b..13bef18e41ec344cfe97346ea2dc73c161f85f6d 100644 --- a/config/locales/communication/en.yml +++ b/config/locales/communication/en.yml @@ -433,6 +433,7 @@ en: manage_authors: Manage authors number_of_posts: Nunber of posts website: + analytics: Analytics git: Git imported: from: Imported from diff --git a/config/locales/communication/fr.yml b/config/locales/communication/fr.yml index 964ed1199f6693b7fead83cd574d39699b08519c..8926caa388db665b430a8e511212f3de46557b83 100644 --- a/config/locales/communication/fr.yml +++ b/config/locales/communication/fr.yml @@ -437,6 +437,7 @@ fr: manage_authors: Gérer les auteur·rice·s number_of_posts: Nombre d'actualités website: + analytics: Analytics git: Git imported: from: Importé depuis diff --git a/config/routes/admin/communication.rb b/config/routes/admin/communication.rb index 2d1b47145ac7924c0139c2e919947dc99029de03..e8e5152c5402e022459a4c9650fe37e4dd2b9bd3 100644 --- a/config/routes/admin/communication.rb +++ b/config/routes/admin/communication.rb @@ -5,6 +5,7 @@ namespace :communication do get :import post :import get :style + get :analytics end resources :pages, controller: 'websites/pages' do collection do diff --git a/db/migrate/20220701064111_add_plausible_to_communication_websites.rb b/db/migrate/20220701064111_add_plausible_to_communication_websites.rb new file mode 100644 index 0000000000000000000000000000000000000000..c3bf70eb266a7b3f55793c2e6d73bbaf3d539a26 --- /dev/null +++ b/db/migrate/20220701064111_add_plausible_to_communication_websites.rb @@ -0,0 +1,5 @@ +class AddPlausibleToCommunicationWebsites < ActiveRecord::Migration[6.1] + def change + add_column :communication_websites, :plausible_url, :string + end +end diff --git a/db/schema.rb b/db/schema.rb index c33a161b9f53fb5b0a2c23134993e541171fd31c..a2425b0647abfc1ec7271ad351396b9deb9dfb5d 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_06_30_192226) do +ActiveRecord::Schema.define(version: 2022_07_01_064111) do # These are extensions that must be enabled in order to support this database enable_extension "pgcrypto" @@ -353,6 +353,7 @@ ActiveRecord::Schema.define(version: 2022_06_30_192226) do t.string "git_endpoint" t.text "style" t.date "style_updated_at" + t.string "plausible_url" t.index ["about_type", "about_id"], name: "index_communication_websites_on_about" t.index ["university_id"], name: "index_communication_websites_on_university_id" end diff --git a/test/fixtures/communication/websites.yml b/test/fixtures/communication/websites.yml index 8eac768c7e99c5233fabd1fc516feb72868b3af5..78817fa75f2494d30e61980d680f224d40cc6ccb 100644 --- a/test/fixtures/communication/websites.yml +++ b/test/fixtures/communication/websites.yml @@ -8,6 +8,7 @@ # git_endpoint :string # git_provider :integer default("github") # name :string +# plausible_url :string # repository :string # style :text # style_updated_at :date