Skip to content

Commit

Permalink
Merge branch 'feature/add-graphs-count-admin-page' into stage
Browse files Browse the repository at this point in the history
  • Loading branch information
syphax-bouazzouni committed Jan 13, 2025
2 parents 2ddaa4c + c5c613a commit 7bed61f
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 5 deletions.
23 changes: 23 additions & 0 deletions app/controllers/admin/graphs_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
require 'multi_json'
class Admin::GraphsController < ApplicationController

include TurboHelper

layout :determine_layout
before_action :authorize_admin

GRAPHS_URL = "#{LinkedData::Client.settings.rest_url}/admin/graphs"

def index
@graphs = LinkedData::Client::HTTP.get("#{GRAPHS_URL}", { raw: true }, { raw: true })
@graphs = MultiJson.load(@graphs)
end

def create

end

def destroy

end
end
2 changes: 2 additions & 0 deletions app/helpers/admin/graphs_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
module Admin::GraphsHelper
end
4 changes: 2 additions & 2 deletions app/helpers/federation_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ def external_canonical_ontology_portal(ontologies)
def most_referred_portal(ontology_submissions)
portal_counts = Hash.new(0)
ontology_submissions.each do |submission|
federated_portals.keys.each do |portal|
portal_counts[portal] += 1 if submission[:pullLocation]&.include?(portal.to_s)
request_portals.each do |portal|
portal_counts[portal.downcase] += 1 if submission[:pullLocation]&.include?(portal.downcase)
end
end
portal_counts.max_by { |_, count| count }&.first
Expand Down
32 changes: 32 additions & 0 deletions app/views/admin/graphs/index.html.haml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
= turbo_frame_tag 'graphs-admin' do
= render_alerts_container
%div#site-admin-clear-caches.my-2
%div
%div.d-flex.justify-content-between.w-100
%div
%p Total graphs: #{@graphs.size}
%p Total triples: #{@graphs.reduce(0){|sum, (k,v)| sum + v[0]}}
%p Total zombie graphs: #{@graphs.reduce(0){|sum, (k,v)| sum + (v[1] ? 1 : 0)}}
%div
= form_with url: admin_index_batch_path, method: 'post', data:{turbo: true, turbo_frame: '_top'} do
= regular_button('graphs-genrate', 'Generate Graphs count report')
%div
= render TableComponent.new(id: 'search_collections', custom_class: 'border rounded', paging: true, searching: true, sort_column: 1) do |t|
- t.header do |h|
- h.th { "#" }
- h.th { "Graph URI" }
- h.th { "Triples count" }
- h.th { "Zombie graph?" }
- h.th { t('admin.search.index.actions') }
- @graphs.each_with_index do |graph_count, i|
- graph, values = graph_count
- t.row do |r|
- r.td{ i.to_s }
- r.td{ graph }
- r.td{ values[0].to_s}
- r.td{ values[1].to_s}
- r.td do
.d-flex.align-items-center
- if values[1]
%span
= action_button('Delete', "/admin/graphs/#{graph}", method: :delete)
6 changes: 4 additions & 2 deletions app/views/admin/index.html.haml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

%div
%div.mx-1
- sections = [t('admin.index.analytics'), t('admin.index.site_administration'),t('admin.index.ontology_administration'), t('admin.index.licensing'), t('admin.index.users'), t('admin.index.metadata_administration'), t('admin.index.groups'), t('admin.index.categories'), t('admin.index.persons_and_organizations'), t('admin.index.sparql'), t('admin.index.search')]
- sections = [t('admin.index.analytics'), t('admin.index.site_administration'),t('admin.index.ontology_administration'), t('admin.index.licensing'), t('admin.index.users'), t('admin.index.metadata_administration'), t('admin.index.groups'), t('admin.index.categories'), t('admin.index.persons_and_organizations'), t('admin.index.sparql'), t('admin.index.search'), 'Graphs']
- 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
Expand Down Expand Up @@ -62,4 +62,6 @@
- t.item_content do
= sparql_query_container
- t.item_content do
= render TurboFrameComponent.new(id: 'search-admin', src: '/admin/search', loading: 'lazy')
= render TurboFrameComponent.new(id: 'search-admin', src: '/admin/search', loading: 'lazy')
- t.item_content do
= render TurboFrameComponent.new(id: 'graphs-admin', src: '/admin/graphs', loading: 'lazy')
7 changes: 6 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,13 @@
post ':collection/init_schema', to: 'search#init_schema'
get ':collection/schema', to: 'search#show'
get ':collection/data', to: 'search#search'
end

end
scope :graphs do
get '/', to: 'graphs#index'
post '/', to: 'graphs#generate'
delete '/', to: 'graphs#delete'
end
end

post 'admin/clearcache', to: 'admin#clearcache'
Expand Down

0 comments on commit 7bed61f

Please sign in to comment.