From 9414b9c3e6d813553698470daf6eed4392138fec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Verg=C3=A9s?= Date: Tue, 2 Jul 2024 17:35:20 +0200 Subject: [PATCH] add iframe plausible --- app/controllers/admin/iframe_controller.rb | 9 +++++++++ app/views/admin/iframe/index.html.erb | 3 +++ app/views/layouts/decidim/_head_extra.html.erb | 3 +++ config/initializers/custom_admin_iframe.rb | 10 ++++++++++ config/routes.rb | 9 +++++++-- 5 files changed, 32 insertions(+), 2 deletions(-) create mode 100644 app/controllers/admin/iframe_controller.rb create mode 100644 app/views/admin/iframe/index.html.erb create mode 100644 app/views/layouts/decidim/_head_extra.html.erb create mode 100644 config/initializers/custom_admin_iframe.rb diff --git a/app/controllers/admin/iframe_controller.rb b/app/controllers/admin/iframe_controller.rb new file mode 100644 index 0000000..ede2e84 --- /dev/null +++ b/app/controllers/admin/iframe_controller.rb @@ -0,0 +1,9 @@ +# frozen_string_literal: true + +module Admin + class IframeController < Decidim::Admin::ApplicationController + def index + enforce_permission_to :read, :admin_dashboard + end + end +end diff --git a/app/views/admin/iframe/index.html.erb b/app/views/admin/iframe/index.html.erb new file mode 100644 index 0000000..392191b --- /dev/null +++ b/app/views/admin/iframe/index.html.erb @@ -0,0 +1,3 @@ + +
Stats powered by Plausible Analytics
+ diff --git a/app/views/layouts/decidim/_head_extra.html.erb b/app/views/layouts/decidim/_head_extra.html.erb new file mode 100644 index 0000000..e22c390 --- /dev/null +++ b/app/views/layouts/decidim/_head_extra.html.erb @@ -0,0 +1,3 @@ +<% if ENV["PLAUSIBLE_HOST"].present? %> + +<% end %> diff --git a/config/initializers/custom_admin_iframe.rb b/config/initializers/custom_admin_iframe.rb new file mode 100644 index 0000000..ec622bc --- /dev/null +++ b/config/initializers/custom_admin_iframe.rb @@ -0,0 +1,10 @@ +# frozen_string_literal: true + +Decidim.menu :admin_menu do |menu| + menu.add_item :custom_iframe, + "Estadístiques web", + Rails.application.routes.url_helpers.admin_iframe_index_path, + icon_name: "bar-chart-2-line", + position: 10, + if: ENV.fetch("PLAUSIBLE_IFRAME", nil).present? +end diff --git a/config/routes.rb b/config/routes.rb index 9c85405..09ed74f 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,13 +1,18 @@ # frozen_string_literal: true require "sidekiq/web" +require "sidekiq/cron/web" Rails.application.routes.draw do mount LetterOpenerWeb::Engine, at: "/letter_opener" if Rails.env.development? - mount Decidim::Core::Engine => "/" authenticate :user, ->(u) { u.admin? } do mount Sidekiq::Web => "/sidekiq" end - # For details on the DSL available within this file, see https://guides.rubyonrails.org/routing.html + + namespace :admin do + resources :iframe, only: [:index] + end + + mount Decidim::Core::Engine => "/" end