Skip to content

Commit

Permalink
hide analytics features if not enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jun 22, 2024
1 parent fdcfa5c commit 5c11845
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 8 deletions.
10 changes: 8 additions & 2 deletions app/controllers/home_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,15 @@ class HomeController < ApplicationController
include FairScoreHelper

def index
@analytics = helpers.ontologies_analytics
@analytics = helpers.ontologies_analytics
# Calculate BioPortal summary statistics
@ont_count = @analytics.keys.size

@ont_count = if @analytics.empty?
LinkedData::Client::Models::Ontology.all.size
else
@analytics.keys.size
end

metrics = LinkedData::Client::Models::Metrics.all
metrics = metrics.each_with_object(Hash.new(0)) do |h, sum|
h.to_hash.slice(:classes, :properties, :individuals).each { |k, v| sum[k] += v }
Expand Down
13 changes: 9 additions & 4 deletions app/helpers/application_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,14 @@ def search_json_link(link = @json_url, style: '')
def resolve_namespaces
RESOLVE_NAMESPACE
end

def ontologies_analytics
data = LinkedData::Client::Analytics.last_month.onts
data.map{|x| [x[:ont].to_s, x[:views]]}.to_h
begin
data = LinkedData::Client::Analytics.last_month.onts
data.map{|x| [x[:ont].to_s, x[:views]]}.to_h
rescue StandardError
{}
end
end

def get_apikey
Expand Down Expand Up @@ -293,7 +298,7 @@ def add_proposal_button(parent_id, parent_type)
class: "secondary-button regular-button slim", data: { show_modal_title_value: t('application.add_new_proposal')}
end
end


def link?(str)
# Regular expression to match strings starting with "http://" or "https://"
Expand Down Expand Up @@ -662,7 +667,7 @@ def cancel_button_component(class_name: nil, id: , value:, data: nil)
end
end
end



end
6 changes: 5 additions & 1 deletion app/views/admin/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@
- selected = params[:section] || sections.first.downcase
= render Layout::VerticalTabsComponent.new(header: t('admin.index.administration_console'), titles: sections, selected: selected, url_parameter: 'section') do |t|
- t.item_content do
= render 'analytics'
- if @ontology_visits[:visits].empty?
%div.d-flex.justify-content-center
Google analytics not enabled
- else
= render 'analytics'
- t.item_content do
= render 'main'
- t.item_content do
Expand Down
2 changes: 1 addition & 1 deletion app/views/home/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@
%h4
= format_number_abbreviated(@users_count)
%p= t("home.users")
.home-statistics-link.justify-content-end
.home-statistics-link.justify-content-end{style: @analytics.empty? && "visibility: hidden"}
= link_to t("home.see_details"),'/statistics', target: "_blank"

.home-section
Expand Down

0 comments on commit 5c11845

Please sign in to comment.