diff --git a/app/controllers/admin/graphs_controller.rb b/app/controllers/admin/graphs_controller.rb new file mode 100644 index 0000000000..5fe793830d --- /dev/null +++ b/app/controllers/admin/graphs_controller.rb @@ -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 diff --git a/app/helpers/admin/graphs_helper.rb b/app/helpers/admin/graphs_helper.rb new file mode 100644 index 0000000000..23d7f8ea57 --- /dev/null +++ b/app/helpers/admin/graphs_helper.rb @@ -0,0 +1,2 @@ +module Admin::GraphsHelper +end diff --git a/app/views/admin/graphs/index.html.haml b/app/views/admin/graphs/index.html.haml new file mode 100644 index 0000000000..d5f5b9e94e --- /dev/null +++ b/app/views/admin/graphs/index.html.haml @@ -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) diff --git a/app/views/admin/index.html.haml b/app/views/admin/index.html.haml index da8f0cbdee..c513b63003 100644 --- a/app/views/admin/index.html.haml +++ b/app/views/admin/index.html.haml @@ -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 @@ -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') \ No newline at end of file + = 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') diff --git a/config/routes.rb b/config/routes.rb index 4894165a66..005f95a59c 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -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'