Commit 14b5363d6eccde2944178b9558352f3b6bf354b2
1 parent
fc1168b8
Exists in
theme-brasil-digital-from-staging
and in
9 other branches
virtuoso: added ontology mapping management
Showing
6 changed files
with
84 additions
and
0 deletions
Show diff stats
plugins/virtuoso/controllers/admin/virtuoso_plugin_ontology_mapping_controller.rb
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +class VirtuosoPluginOntologyMappingController < AdminController | ||
2 | + | ||
3 | + def index | ||
4 | + @settings = VirtuosoPlugin.new(self).settings | ||
5 | + if request.post? | ||
6 | + @settings.ontology_mapping = params['ontology_mapping'] | ||
7 | + @settings.save! | ||
8 | + session[:notice] = _('Saved!') | ||
9 | + end | ||
10 | + @ontology_mapping = @settings.ontology_mapping | ||
11 | + end | ||
12 | + | ||
13 | +end |
@@ -0,0 +1,11 @@ | @@ -0,0 +1,11 @@ | ||
1 | +jQuery(document).ready(function($) { | ||
2 | + | ||
3 | + $('#new-ontology-button').on('click', function() { | ||
4 | + $('#ontology-table').append($('#ontology-item-template tr').clone()); | ||
5 | + }); | ||
6 | + | ||
7 | + $('#ontology-table').on('click', '.remove-ontology-button', function() { | ||
8 | + $(this).parents('tr').remove(); | ||
9 | + }); | ||
10 | + | ||
11 | +}); |
plugins/virtuoso/test/functional/virtuoso_plugin_ontology_mapping_controller.rb
0 → 100644
@@ -0,0 +1,32 @@ | @@ -0,0 +1,32 @@ | ||
1 | +require 'test_helper' | ||
2 | + | ||
3 | +class VirtuosoPluginOntologyMappingControllerTest < ActionController::TestCase | ||
4 | + | ||
5 | + setup do | ||
6 | + @environment = Environment.default | ||
7 | + @plugin = VirtuosoPlugin.new(self) | ||
8 | + login_as(create_admin_user(environment)) | ||
9 | + @ontology_mapping = [{'source' => 'title', 'target' => 'http://purl.org/dc/elements/1.1/title'}, | ||
10 | + {'source' => 'creator', 'target' => 'http://purl.org/dc/elements/1.1/creator'}] | ||
11 | + end | ||
12 | + | ||
13 | + attr_reader :environment, :plugin, :ontology_mapping | ||
14 | + | ||
15 | + should 'list saved mappings' do | ||
16 | + settings = plugin.settings | ||
17 | + settings.ontology_mapping = ontology_mapping | ||
18 | + settings.save! | ||
19 | + get :index | ||
20 | + assert_select "#ontology-table tr", 3 do | ||
21 | + assert_select "input[name='ontology_mapping[][source]']" | ||
22 | + assert_select "input[name='ontology_mapping[][target]']" | ||
23 | + end | ||
24 | + end | ||
25 | + | ||
26 | + should 'save ontology mappings' do | ||
27 | + post :index, 'ontology_mapping' => ontology_mapping | ||
28 | + @environment = environment.reload | ||
29 | + assert_equivalent ontology_mapping, plugin.settings.ontology_mapping | ||
30 | + end | ||
31 | + | ||
32 | +end |
plugins/virtuoso/views/virtuoso_plugin_admin/index.html.erb
@@ -43,5 +43,6 @@ | @@ -43,5 +43,6 @@ | ||
43 | <div class="actions"> | 43 | <div class="actions"> |
44 | <%= button :edit, _('Triples management'), :action => :triples_management %> | 44 | <%= button :edit, _('Triples management'), :action => :triples_management %> |
45 | <%= button :edit, _('Custom Queries'), :action => :index, :controller => 'virtuoso_plugin_custom_queries' %> | 45 | <%= button :edit, _('Custom Queries'), :action => :index, :controller => 'virtuoso_plugin_custom_queries' %> |
46 | + <%= button :edit, _('Ontology mapping'), :action => :index, :controller => 'virtuoso_plugin_ontology_mapping' %> | ||
46 | </div> | 47 | </div> |
47 | </div> | 48 | </div> |
plugins/virtuoso/views/virtuoso_plugin_ontology_mapping/_ontology_mapping_item.html.erb
0 → 100644
@@ -0,0 +1,5 @@ | @@ -0,0 +1,5 @@ | ||
1 | +<tr> | ||
2 | + <td><%= text_field_tag 'ontology_mapping[][source]', ontology_mapping_item[:source] %></td> | ||
3 | + <td><%= text_field_tag 'ontology_mapping[][target]', ontology_mapping_item[:target], :style => 'width: 100%' %></td> | ||
4 | + <td><%= button :remove, _('Remove'), '#', :class => "remove-ontology-button" %></td> | ||
5 | +</tr> |
plugins/virtuoso/views/virtuoso_plugin_ontology_mapping/index.html.erb
0 → 100644
@@ -0,0 +1,22 @@ | @@ -0,0 +1,22 @@ | ||
1 | +<h1><%= _('Ontology Mapping') %></h1> | ||
2 | + | ||
3 | +<%= form_for :ontology_mapping do |f| %> | ||
4 | +<table id="ontology-table"> | ||
5 | + <tr> | ||
6 | + <th width="30%"><%= _('Source') %></th> | ||
7 | + <th width="70%"><%= _('Target') %></th> | ||
8 | + <th></th> | ||
9 | + </tr> | ||
10 | + <%= render :partial => 'ontology_mapping_item', :collection => @ontology_mapping %> | ||
11 | +</table> | ||
12 | +<div class="actions"> | ||
13 | + <%= button :new, _('New'), '#', :id => 'new-ontology-button' %> | ||
14 | + <%= submit_button :save, _('Save') %> | ||
15 | +</div> | ||
16 | +<% end %> | ||
17 | + | ||
18 | +<table id="ontology-item-template" style="display: none"> | ||
19 | + <%= render :partial => 'ontology_mapping_item', :collection => [{:source => '', :target => ''}] %> | ||
20 | +</table> | ||
21 | + | ||
22 | +<%= javascript_include_tag '/plugins/virtuoso/ontology_mapping.js' %> |