diff --git a/app/controllers/admin/graphs_controller.rb b/app/controllers/admin/graphs_controller.rb index 597e733cc..0663780e6 100644 --- a/app/controllers/admin/graphs_controller.rb +++ b/app/controllers/admin/graphs_controller.rb @@ -12,6 +12,16 @@ class Admin::GraphsController < ApplicationController def index @graphs = LinkedData::Client::HTTP.get(GRAPHS_URL.dup, { raw: true }, { raw: true }) @graphs = MultiJson.load(@graphs) + @zombie_graphs = @graphs.select { |_, v| v[1] } + all_onts = LinkedData::Client::Models::Ontology.all + @empty_ontologies = all_onts.select { |ont| !@graphs.any? { |k, _| k.include?(ont.acronym) } } + end + + def create + message = 'Graphs counts created successfully' + # response = LinkedData::Client::HTTP.post(GRAPHS_URL, {}) + # message = response.status == 200 ? response.message : 'Error creating graphs counts' + redirect_to admin_index_path(section: 'graphs'), notice: message end end diff --git a/app/helpers/components_helper.rb b/app/helpers/components_helper.rb index 53a5e34cb..6226c83f0 100644 --- a/app/helpers/components_helper.rb +++ b/app/helpers/components_helper.rb @@ -274,8 +274,8 @@ def properties_dropdown(id, title, tooltip, properties, is_open: false, &block) end end - def regular_button(id, value, variant: "secondary", state: "regular", size: "slim", href: nil, &block) - render Buttons::RegularButtonComponent.new(id:id, value: value, variant: variant, state: state, size: size, href: href) do |btn| + def regular_button(id, value, variant: "secondary", state: "regular", size: "slim", href: nil, type: 'button', &block) + render Buttons::RegularButtonComponent.new(id:id, value: value, variant: variant, state: state, type: type, size: size, href: href) do |btn| capture(btn, &block) if block_given? end end diff --git a/app/views/admin/graphs/index.html.haml b/app/views/admin/graphs/index.html.haml index ab0dfb9cf..1b127f072 100644 --- a/app/views/admin/graphs/index.html.haml +++ b/app/views/admin/graphs/index.html.haml @@ -2,11 +2,26 @@ = render_alerts_container %div#site-admin-clear-caches.my-2 %div + %div + + - unless @zombie_graphs.empty? + %div.my-1 + = render Display::AlertComponent.new(id: 'graphs-admin-zombie', type: 'danger') do + There are #{@zombie_graphs.size} zombie graphs in the system. Please check the list below and take action. + + - unless @empty_ontologies.empty? + %div.my-1 + = render Display::AlertComponent.new(id: 'graphs-admin-empty-ontologies', type: 'danger') do + There are #{@empty_ontologies.size} ontologies with no graphs in the system: #{@empty_ontologies.map{|o| o[:acronym]}.join(", ")} + + %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/graphs/', method: 'post', data:{turbo: true, turbo_frame: '_top', turbo_confirm: 'This may take a while, are you sure you want to run this?'} do + = regular_button('graphs-generate', 'Generate Graphs count report', type: 'submit') %div = render TableComponent.new(id: 'graphs_table', paging: true, searching: true, sort_column: 1) do |t| - t.header do |h| diff --git a/config/routes.rb b/config/routes.rb index b2c56cebe..9657fda07 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -87,6 +87,7 @@ scope :graphs do get '/', to: 'graphs#index' + post '/', to: 'graphs#create' end scope :logs do