Skip to content

Commit

Permalink
Feauture: Update admin page and fix google analytics (#422)
Browse files Browse the repository at this point in the history
* remove no more used ontologies.js file

* add id argument to the alert component

* justify center tabs items if no actions button are pinned_right

* install latest version of Chart JS and create  chart_component helper

* add Analytics section to the admin page

* catch the case were the analytics are not existent
  • Loading branch information
syphax-bouazzouni authored Dec 28, 2023
1 parent 8e9c45d commit d18a700
Show file tree
Hide file tree
Showing 17 changed files with 291 additions and 156 deletions.
1 change: 0 additions & 1 deletion app/assets/javascripts/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
//= require home
//= require_tree ./helpers
//= require_tree ./components
//= require ontologies
//= require projects
//= require application_esbuild
customElements.define('data-table-loader', DataTableLoader );
Expand Down
73 changes: 0 additions & 73 deletions app/assets/javascripts/ontologies.js

This file was deleted.

14 changes: 14 additions & 0 deletions app/assets/stylesheets/admin.scss
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,20 @@
margin-bottom: 30px;
}

.analytics {
.card-header-1{
color: white; font-size: 60px; font-weight: 600; word-wrap: break-word
}

.card-header-2{
color: white; font-size: 14px; font-weight: 400; word-wrap: break-word
}

.card-header-3{
color: white; opacity: 0.6; font-size: 14px; font-weight: 400; word-wrap: break-word
}
}

.alert-box span {
font-weight: bold;
text-transform: uppercase;
Expand Down
3 changes: 0 additions & 3 deletions app/assets/stylesheets/ontologies.scss
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,6 @@ $widget-table-border-color: #EFEFEF;
margin-right: 15px;
}

#ontology-browse-help i {
margin-left: .25em;
}

/************************************
/* Schemes pane
Expand Down
3 changes: 2 additions & 1 deletion app/components/display/alert_component.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
class Display::AlertComponent < ViewComponent::Base
def initialize(message: nil, closable: true, type: "info", auto_close_delay: nil, button: nil)
def initialize(id: nil, message: nil, closable: true, type: "info", auto_close_delay: nil, button: nil)
@message = message
@closable = closable
@type = type
@auto_close_delay = auto_close_delay
@button = button
@id = id
end

def closable?
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.alert-container{data: {controller: "alert-component",
.alert-container{id: @id, data: {controller: "alert-component",
'alert-component-auto-close-value': auto_close?,
'alert-component-auto-close-after-value': @auto_close_delay,
},
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
%div{data: {controller:'tabs-container'}, class: container_class, id: @id}
%div
%div{class: !pinned_right? && 'justify-content-center'}
.tab-items.nav
- items.each do |item|
%div{data: tabs_container_data(item), class: item.active_class + ' nav-item'}
Expand Down
87 changes: 86 additions & 1 deletion app/controllers/admin_controller.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
class AdminController < ApplicationController
include TurboHelper
include TurboHelper, HomeHelper
layout :determine_layout
before_action :cache_setup

Expand All @@ -12,6 +12,11 @@ class AdminController < ApplicationController

def index
@users = LinkedData::Client::Models::User.all
@ontology_visits = ontology_visits_data
@users_visits = user_visits_data
@page_visits = page_visits_data
@ontologies_problems_count = _ontologies_report[:ontologies]&.select{|a,v| v[:problem]}&.size || 0

if session[:user].nil? || !session[:user].admin?
redirect_to :controller => 'login', :action => 'index', :redirect => '/admin'
else
Expand Down Expand Up @@ -315,4 +320,84 @@ def _users
response
end

def user_visits_data
begin
analytics = JSON.parse(LinkedData::Client::HTTP.get("#{rest_url}/data/analytics/users", {}, raw: true))
rescue
analytics = {}
end
visits_data = { visits: [], labels: [] }

return visits_data if analytics.empty?

analytics.each do |year, year_data|
year_data.each do |month, value|
visits_data[:visits] << value
visits_data[:labels] << DateTime.parse("#{year}/#{month}").strftime("%b %Y")
end
end
visits_data
end

def ontology_visits_data
begin
analytics = JSON.parse(LinkedData::Client::HTTP.get("#{rest_url}/data/analytics/ontologies", {}, raw: true))
rescue
analytics = {}
end
visits_data = { visits: [], labels: [] }
@new_ontologies_count = []
@ontologies_count = 0

return visits_data if analytics.empty?

aggregated_data = {}
analytics.each do |acronym, years_data|
current_year_count = 0
previous_year_count = 0
years_data.each do |year, months_data|
previous_year_count += current_year_count
current_year_count = 0
aggregated_data[year] ||= {}
months_data.each do |month, value|
if aggregated_data[year][month]
aggregated_data[year][month] += value
else
aggregated_data[year][month] = value
end
current_year_count += value
end
end
@ontologies_count += 1
if previous_year_count.zero? && current_year_count.positive?
@new_ontologies_count << [acronym]
end
end



aggregated_data.each do |year, year_data|
year_data.each do |month, value|
visits_data[:visits] << value
visits_data[:labels] << DateTime.parse("#{year}/#{month}").strftime("%b %Y")
end
end
visits_data
end

def page_visits_data
begin
analytics = JSON.parse(LinkedData::Client::HTTP.get("#{rest_url}/data/analytics/page_visits", {}, raw: true))
rescue
analytics = {}
end
visits_data = { visits: [], labels: [] }

return visits_data if analytics.empty?
analytics.each do |path, count|
visits_data[:labels] << path
visits_data[:visits] << count
end
visits_data
end
end
13 changes: 13 additions & 0 deletions app/helpers/admin_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,17 @@ def selected_admin_section?(section_title)
current_section = params[:section] || 'site'
current_section.eql?(section_title)
end


def new_ontologies_created_title
content_tag(:div,
"The following ontologies: #{@new_ontologies_count.join(', ')} were created in this year",
style: 'width: 400px; max-height: 300px')
end

def visits_evolution
return 0 if @users_visits[:visits].empty?

@users_visits[:visits].last - @users_visits[:visits][-2]
end
end
12 changes: 12 additions & 0 deletions app/helpers/components_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
module ComponentsHelper

def chart_component(title: '', type: , labels: , datasets: , index_axis: 'x')
data = {
controller: 'load-chart',
'load-chart-type-value': type,
'load-chart-title-value': title,
'load-chart-labels-value': labels,
'load-chart-index-axis-value': index_axis,
'load-chart-datasets-value': datasets
}
content_tag(:canvas, nil, data: data)
end
def info_tooltip(text)
render Display::InfoTooltipComponent.new(text: text)
end
Expand Down
20 changes: 12 additions & 8 deletions app/helpers/ontologies_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -384,14 +384,18 @@ def lazy_load_section(section_title, &block)
end

def visits_chart_dataset(visits_data)
[{
label: 'Visits',
data: visits_data,
backgroundColor: 'rgba(151, 187, 205, 0.2)',
borderColor: 'rgba(151, 187, 205, 1)',
pointBorderColor: 'rgba(151, 187, 205, 1)',
pointBackgroundColor: 'rgba(151, 187, 205, 1)',
}].to_json
[
{
label: 'Visits',
data: visits_data,
borderWidth: 2,
borderRadius: 5,
borderSkipped: false,
cubicInterpolationMode: 'monotone',
tension: 0.4,
fill: true
}
].to_json
end

def submission_ready?(submission)
Expand Down
Loading

0 comments on commit d18a700

Please sign in to comment.