Commit 9508e848351aefedbefb46792697b83c7c2356ce
1 parent
76aa0ada
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: added option to user admin search and edit triples
Showing
4 changed files
with
130 additions
and
1 deletions
Show diff stats
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
| ... | ... | @@ -20,4 +20,31 @@ class VirtuosoPluginAdminController < AdminController |
| 20 | 20 | redirect_to :action => :index |
| 21 | 21 | end |
| 22 | 22 | |
| 23 | + def triple_management | |
| 24 | + triples_management = VirtuosoPlugin::TriplesManagement.new(environment) | |
| 25 | + @triples = [] | |
| 26 | + if request.post? | |
| 27 | + @query = params[:query] | |
| 28 | + @graph_uri = params[:graph_uri] | |
| 29 | + @triples = triples_management.search_triples(@graph_uri, @query) | |
| 30 | + end | |
| 31 | + render :action => 'triple_management' | |
| 32 | + end | |
| 33 | + | |
| 34 | + def triple_update | |
| 35 | + graph_uri = params[:graph_uri] | |
| 36 | + triples = params[:triples] | |
| 37 | + | |
| 38 | + triples_management = VirtuosoPlugin::TriplesManagement.new(environment) | |
| 39 | + | |
| 40 | + triples.each { |triple| | |
| 41 | + from_triple = triple[:from] | |
| 42 | + to_triple = triple[:to] | |
| 43 | + triples_management.update_triple(graph_uri, from_triple, to_triple) | |
| 44 | + } | |
| 45 | + | |
| 46 | + session[:notice] = _('Triple(s) succesfully updated.') | |
| 47 | + redirect_to :action => :triple_management | |
| 48 | + end | |
| 49 | + | |
| 23 | 50 | end | ... | ... |
plugins/virtuoso/lib/virtuoso_plugin/triples_management.rb
0 → 100644
| ... | ... | @@ -0,0 +1,32 @@ |
| 1 | +class VirtuosoPlugin::TriplesManagement | |
| 2 | + | |
| 3 | + def initialize(environment) | |
| 4 | + @environment = environment | |
| 5 | + end | |
| 6 | + | |
| 7 | + attr_reader :environment | |
| 8 | + | |
| 9 | + def plugin | |
| 10 | + @plugin ||= VirtuosoPlugin.new(self) | |
| 11 | + end | |
| 12 | + | |
| 13 | + def search_triples(graph_uri, query_sparql) | |
| 14 | + query = "WITH <#{graph_uri}> #{query_sparql}" | |
| 15 | + plugin.virtuoso_client.query(query) | |
| 16 | + end | |
| 17 | + | |
| 18 | + def update_triple(graph_uri, from_triple, to_triple) | |
| 19 | + from_subject = from_triple[:subject] | |
| 20 | + from_predicate = from_triple[:predicate] | |
| 21 | + from_object = from_triple[:object] | |
| 22 | + | |
| 23 | + to_subject = to_triple[:subject] | |
| 24 | + to_predicate = to_triple[:predicate] | |
| 25 | + to_object = to_triple[:object] | |
| 26 | + | |
| 27 | + query = "WITH <#{graph_uri}> DELETE { <#{from_subject}> <#{from_predicate}> '#{from_object}' } INSERT { <#{to_subject}> <#{to_predicate}> '#{to_object}' }" | |
| 28 | + | |
| 29 | + plugin.virtuoso_client.query(query) | |
| 30 | + end | |
| 31 | + | |
| 32 | +end | ... | ... |
plugins/virtuoso/views/virtuoso_plugin_admin/index.html.erb
| ... | ... | @@ -23,7 +23,6 @@ |
| 23 | 23 | <span class="value"><%= time_ago_as_sentence @settings.last_harvest %></span> |
| 24 | 24 | </div> |
| 25 | 25 | <% end %> |
| 26 | - <br/> | |
| 27 | 26 | <div class="actions"> |
| 28 | 27 | <% if @harvest_running %> |
| 29 | 28 | <%= _('Running...') %> |
| ... | ... | @@ -33,3 +32,11 @@ |
| 33 | 32 | <% end %> |
| 34 | 33 | </div> |
| 35 | 34 | </div> |
| 35 | + | |
| 36 | +<hr /> | |
| 37 | + | |
| 38 | +<div class="triple-management"> | |
| 39 | + <div class="actions"> | |
| 40 | + <%= button :edit, _('Triple management'), :action => :triple_management %> | |
| 41 | + </div> | |
| 42 | +</div> | ... | ... |
plugins/virtuoso/views/virtuoso_plugin_admin/triple_management.html.erb
0 → 100644
| ... | ... | @@ -0,0 +1,63 @@ |
| 1 | +<h1><%= _('Virtuoso settings : Triples Management')%></h1> | |
| 2 | + | |
| 3 | +<%= form_tag('/admin/plugin/virtuoso/triple_management', :method => 'post') do %> | |
| 4 | + | |
| 5 | + <%= labelled_form_field(_('Default Graph IRI:'), text_field_tag(:graph_uri, @graph_uri, :style => 'width: 100%' ) ) %> | |
| 6 | + | |
| 7 | + <%= labelled_form_field(_('Query SPARQL:'), text_area_tag(:query, @query, { :rows => 7, :style => 'width: 99%' } )) %> | |
| 8 | + | |
| 9 | + <% button_bar do %> | |
| 10 | + <%= submit_button(:search, _('Search')) %> | |
| 11 | + <% end %> | |
| 12 | + | |
| 13 | +<% end %> | |
| 14 | + | |
| 15 | +<style> | |
| 16 | +.triple + .triple { | |
| 17 | + border-top: 1px solid #CCC; | |
| 18 | + margin-top: 20px; | |
| 19 | + padding-top: 15px; | |
| 20 | +} | |
| 21 | +</style> | |
| 22 | + | |
| 23 | +<% unless @triples.empty? %> | |
| 24 | + | |
| 25 | + <hr /> | |
| 26 | + | |
| 27 | + <%= form_tag('/admin/plugin/virtuoso/triple_update', :method => 'post') do %> | |
| 28 | + | |
| 29 | + <%= hidden_field_tag(:graph_uri, @graph_uri) %> | |
| 30 | + | |
| 31 | + <% @triples.each { |triple| %> | |
| 32 | + | |
| 33 | + <div class="triple"> | |
| 34 | + | |
| 35 | + <div class="triple-subject" style="margin: 3px 0 3px 0;"> | |
| 36 | + <label class="formlabel"><%= _('Subject:') %></label> | |
| 37 | + <%= hidden_field_tag('triples[][from[subject]]', triple[:s].to_s) %> | |
| 38 | + <%= text_field_tag('triples[][to[subject]]', triple[:s].to_s, :style => 'width: 99%;') %> | |
| 39 | + </div> | |
| 40 | + | |
| 41 | + <div class="triple-predicate" style="margin: 3px 0 3px 0;"> | |
| 42 | + <label class="formlabel"><%= _('Predicate:') %></label> | |
| 43 | + <%= hidden_field_tag('triples[][from[predicate]]', triple[:p].to_s) %> | |
| 44 | + <%= text_field_tag('triples[][to[predicate]]', triple[:p].to_s, :style => 'width: 99%;') %> | |
| 45 | + </div> | |
| 46 | + | |
| 47 | + <div class="triple-object" style="margin: 3px 0 3px 0;"> | |
| 48 | + <label class="formlabel"><%= _('Object:') %></label> | |
| 49 | + <%= hidden_field_tag('triples[][from[object]]', triple[:o].to_s) %> | |
| 50 | + <%= text_field_tag('triples[][to[object]]', triple[:o].to_s, :style => 'width: 99%;') %> | |
| 51 | + </div> | |
| 52 | + | |
| 53 | + </div> | |
| 54 | + | |
| 55 | + <% } %> | |
| 56 | + | |
| 57 | + <% button_bar do %> | |
| 58 | + <%= submit_button(:save, _('Save')) %> | |
| 59 | + <% end %> | |
| 60 | + | |
| 61 | + <% end %> | |
| 62 | + | |
| 63 | +<% end %> | ... | ... |