Commit e517e511a96006da3e0ffdb57d16d5b778bcf80d
1 parent
e7db5197
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: improve triples management feature
Showing
4 changed files
with
67 additions
and
37 deletions
Show diff stats
plugins/virtuoso/controllers/virtuoso_plugin_admin_controller.rb
... | ... | @@ -34,18 +34,25 @@ class VirtuosoPluginAdminController < AdminController |
34 | 34 | render :action => 'triple_management' |
35 | 35 | end |
36 | 36 | |
37 | - def triple_update | |
38 | - graph_uri = params[:graph_uri] | |
39 | - triples = params[:triples] | |
37 | + def update_triple | |
38 | + if request.post? | |
39 | + from_triple = VirtuosoPlugin::Triple.new | |
40 | + from_triple.graph = params[:from_triple][:graph] | |
41 | + from_triple.subject = params[:from_triple][:subject] | |
42 | + from_triple.predicate = params[:from_triple][:predicate] | |
43 | + from_triple.object = params[:from_triple][:object] | |
40 | 44 | |
41 | - triples_management = VirtuosoPlugin::TriplesManagement.new(environment) | |
45 | + to_triple = VirtuosoPlugin::Triple.new | |
46 | + to_triple.graph = params[:to_triple][:graph] | |
47 | + to_triple.subject = params[:to_triple][:subject] | |
48 | + to_triple.predicate = params[:to_triple][:predicate] | |
49 | + to_triple.object = params[:to_triple][:object] | |
42 | 50 | |
43 | - triples.each { |triple_key, triple_content| | |
44 | - triples_management.update_triple(graph_uri, triple_content[:from], triple_content[:to]) | |
45 | - } | |
51 | + triples_management = VirtuosoPlugin::TriplesManagement.new(environment) | |
52 | + triples_management.update_triple(from_triple, to_triple) | |
46 | 53 | |
47 | - session[:notice] = _('Triple(s) succesfully updated.') | |
48 | - redirect_to :action => :triple_management | |
54 | + render json: { :ok => true, :message => _('Triple succesfully updated.') } | |
55 | + end | |
49 | 56 | end |
50 | 57 | |
51 | 58 | def add_triple |
... | ... | @@ -65,16 +72,18 @@ class VirtuosoPluginAdminController < AdminController |
65 | 72 | end |
66 | 73 | |
67 | 74 | def remove_triple |
68 | - triple = VirtuosoPlugin::Triple.new | |
69 | - triple.graph = params[:triple][:graph] | |
70 | - triple.subject = params[:triple][:subject] | |
71 | - triple.predicate = params[:triple][:predicate] | |
72 | - triple.object = params[:triple][:object] | |
75 | + if request.post? | |
76 | + triple = VirtuosoPlugin::Triple.new | |
77 | + triple.graph = params[:triple][:graph] | |
78 | + triple.subject = params[:triple][:subject] | |
79 | + triple.predicate = params[:triple][:predicate] | |
80 | + triple.object = params[:triple][:object] | |
73 | 81 | |
74 | - triples_management = VirtuosoPlugin::TriplesManagement.new(environment) | |
75 | - triples_management.remove_triple(triple) | |
82 | + triples_management = VirtuosoPlugin::TriplesManagement.new(environment) | |
83 | + triples_management.remove_triple(triple) | |
76 | 84 | |
77 | - render json: { :ok => true, :message => _('Triple succesfully removed.') } | |
85 | + render json: { :ok => true, :message => _('Triple succesfully removed.') } | |
86 | + end | |
78 | 87 | end |
79 | 88 | |
80 | 89 | end | ... | ... |
plugins/virtuoso/lib/virtuoso_plugin/triples_management.rb
... | ... | @@ -15,16 +15,8 @@ class VirtuosoPlugin::TriplesManagement |
15 | 15 | plugin.virtuoso_client.query(query) |
16 | 16 | end |
17 | 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 = format_triple_term(from_triple[:object]) | |
22 | - | |
23 | - to_subject = to_triple[:subject] | |
24 | - to_predicate = to_triple[:predicate] | |
25 | - to_object = format_triple_term(to_triple[:object]) | |
26 | - | |
27 | - query = "WITH <#{graph_uri}> DELETE { <#{from_subject}> <#{from_predicate}> #{from_object} } INSERT { <#{to_subject}> <#{to_predicate}> #{to_object} }" | |
18 | + def update_triple(from_triple, to_triple) | |
19 | + query = "WITH <#{from_triple.graph}> DELETE { <#{from_triple.subject}> <#{from_triple.predicate}> #{from_triple.object} } INSERT { <#{to_triple.subject}> <#{to_triple.predicate}> #{to_triple.object} }" | |
28 | 20 | |
29 | 21 | plugin.virtuoso_client.query(query) |
30 | 22 | end |
... | ... | @@ -39,10 +31,4 @@ class VirtuosoPlugin::TriplesManagement |
39 | 31 | plugin.virtuoso_client.query(query) |
40 | 32 | end |
41 | 33 | |
42 | - protected | |
43 | - | |
44 | - def format_triple_term(term) | |
45 | - term =~ /^(http|https):\/\// ? "<#{term}>" : "'#{term}'" | |
46 | - end | |
47 | - | |
48 | 34 | end | ... | ... |
plugins/virtuoso/public/triples_management.js
1 | +function update_triple(triple_id) { | |
2 | + graph = jQuery("input#graph_uri").val(); | |
3 | + | |
4 | + from_subject = jQuery("input#triples_triple" + triple_id + "_from_subject").val(); | |
5 | + from_predicate = jQuery("input#triples_triple" + triple_id + "_from_predicate").val(); | |
6 | + from_object = jQuery("input#triples_triple" + triple_id + "_from_object").val(); | |
7 | + | |
8 | + to_subject = jQuery("input#triples_triple" + triple_id + "_to_subject").val(); | |
9 | + to_predicate = jQuery("input#triples_triple" + triple_id + "_to_predicate").val(); | |
10 | + to_object = jQuery("input#triples_triple" + triple_id + "_to_object").val(); | |
11 | + | |
12 | + var formData = { | |
13 | + from_triple: { graph: graph, subject: from_subject, predicate: from_predicate, object: from_object }, | |
14 | + to_triple: { graph: graph, subject: to_subject, predicate: to_predicate, object: to_object } | |
15 | + } | |
16 | + | |
17 | + jQuery.ajax({ | |
18 | + cache: false, | |
19 | + type: 'POST', | |
20 | + url: '/admin/plugin/virtuoso/update_triple', | |
21 | + data: formData, | |
22 | + dataType: 'json', | |
23 | + success: function(data, status, ajax){ | |
24 | + if ( !data.ok ) { | |
25 | + display_notice(data.error.message); | |
26 | + } | |
27 | + else { | |
28 | + display_notice(data.message); | |
29 | + jQuery("input#triples_triple" + triple_id + "_from_object").val(jQuery("input#triples_triple" + triple_id + "_to_object").val()); | |
30 | + } | |
31 | + }, | |
32 | + error: function(ajax, status, errorThrown) { | |
33 | + alert('Send request - HTTP '+status+': '+errorThrown); | |
34 | + } | |
35 | + }); | |
36 | + | |
37 | +} | |
38 | + | |
1 | 39 | function add_triple() { |
2 | 40 | graph = jQuery("input#triple_graph").val(); |
3 | 41 | subject = jQuery("input#triple_subject").val(); | ... | ... |
plugins/virtuoso/views/virtuoso_plugin_admin/triple_management.html.erb
... | ... | @@ -36,6 +36,7 @@ |
36 | 36 | <%= labelled_form_field(_('Object:'), text_field_tag("triples[triple#{triple_counter}[to][object]]", triple[:o].to_s) ) %> |
37 | 37 | </li> |
38 | 38 | <li class="triple-actions"> |
39 | + <%= button :save, _('Update triple'), {}, :href => '#', :onclick => "update_triple(#{triple_counter}); return false;" %> | |
39 | 40 | <%= button :remove, _('Remove triple'), {}, :href => '#', :onclick => "remove_triple(#{triple_counter}); return false;" %> |
40 | 41 | </li> |
41 | 42 | </ul> |
... | ... | @@ -47,10 +48,6 @@ |
47 | 48 | |
48 | 49 | </ul> |
49 | 50 | |
50 | - <% button_bar do %> | |
51 | - <%= submit_button(:save, _('Save')) %> | |
52 | - <% end %> | |
53 | - | |
54 | 51 | <% end %> |
55 | 52 | |
56 | 53 | <% end %> | ... | ... |