iqvoc 4.2.0 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/Gemfile +15 -12
- data/Gemfile.lock +124 -90
- data/README.md +17 -1
- data/app/assets/images/iqvoc_logo.svg +41 -0
- data/app/assets/javascripts/framework.js +1 -1
- data/app/assets/javascripts/iqvoc/concept_mapper.js +62 -0
- data/app/assets/javascripts/iqvoc/concept_mapping_manager.js +137 -0
- data/app/assets/javascripts/iqvoc/entityselect.js.erb +51 -19
- data/app/assets/javascripts/iqvoc/federated_concept_mapper.js +75 -0
- data/app/assets/javascripts/iqvoc/iqvoc.js +16 -4
- data/app/assets/javascripts/iqvoc/label_resolver.js +23 -0
- data/app/assets/javascripts/iqvoc/manifest.js +4 -0
- data/app/assets/javascripts/iqvoc/onebox.js.erb +4 -4
- data/app/assets/javascripts/iqvoc/quicksearch.js +1 -1
- data/app/assets/stylesheets/framework.css.scss +2 -1
- data/app/assets/stylesheets/iqvoc/_settings.css.scss +12 -0
- data/app/assets/stylesheets/iqvoc/components/_components.css.scss +237 -0
- data/app/assets/stylesheets/iqvoc/{entity_select.css.scss → components/_entity_select.css.scss} +0 -2
- data/app/assets/stylesheets/iqvoc/{forms.css.scss → components/_forms.css.scss} +0 -0
- data/app/assets/stylesheets/iqvoc/{note.css.scss → components/_notes.css.scss} +2 -10
- data/app/assets/stylesheets/iqvoc/{panel.css.scss → components/_panels.css.scss} +3 -5
- data/app/assets/stylesheets/iqvoc/{sidebar.css.scss → components/_sidebars.css.scss} +0 -0
- data/app/assets/stylesheets/iqvoc/{visualization.css.scss → components/_visualization.css.scss} +0 -0
- data/app/assets/stylesheets/iqvoc/{bootstrap_extensions.css.scss → hacks/_bootstrap_extensions.css.scss} +0 -0
- data/app/assets/stylesheets/iqvoc/{hacks.css.scss → hacks/_hacks.css.scss} +0 -0
- data/app/assets/stylesheets/iqvoc/{jquery-ui_extensions.css.scss → hacks/_jquery-ui_extensions.css.scss} +0 -0
- data/app/assets/stylesheets/iqvoc/manifest.css.scss +10 -10
- data/app/controllers/concepts/alphabetical_controller.rb +23 -9
- data/app/controllers/concepts/scheme_controller.rb +19 -0
- data/app/controllers/concepts_controller.rb +13 -1
- data/app/controllers/concerns/dataset_initialization.rb +18 -0
- data/app/controllers/dashboard_controller.rb +17 -0
- data/app/controllers/hierarchy_controller.rb +65 -6
- data/app/controllers/{import_controller.rb → imports_controller.rb} +14 -11
- data/app/controllers/rdf_controller.rb +6 -0
- data/app/controllers/remote_labels_controller.rb +31 -0
- data/app/controllers/search_results_controller.rb +95 -14
- data/app/helpers/application_helper.rb +6 -4
- data/app/helpers/dashboard_helper.rb +3 -3
- data/app/helpers/link_helper.rb +14 -0
- data/app/helpers/search_results_helper.rb +5 -1
- data/app/jobs/import_job.rb +19 -0
- data/app/models/concept/base.rb +2 -2
- data/app/models/dataset/adaptors/iqvoc/alphabetical_search_adaptor.rb +38 -0
- data/app/models/dataset/adaptors/iqvoc/http_adaptor.rb +39 -0
- data/app/models/dataset/adaptors/iqvoc/label_adaptor.rb +15 -0
- data/app/models/dataset/adaptors/iqvoc/search_adaptor.rb +60 -0
- data/app/models/dataset/iqvoc_dataset.rb +39 -0
- data/app/models/import.rb +16 -0
- data/app/models/labeling/skos/base.rb +2 -1
- data/app/models/note/base.rb +2 -2
- data/app/models/note/skos/change_note.rb +3 -2
- data/app/presenters/alphabetical_search_result.rb +33 -0
- data/app/presenters/alphabetical_search_result_remote.rb +37 -0
- data/app/presenters/search_result.rb +33 -0
- data/app/presenters/search_result_collection.rb +8 -0
- data/app/presenters/search_result_remote.rb +52 -0
- data/app/views/collections/_sidebar.html.erb +3 -3
- data/app/views/concepts/_form.html.erb +1 -1
- data/app/views/concepts/alphabetical/_search_result.html.erb +16 -0
- data/app/views/concepts/alphabetical/_search_result_remote.html.erb +14 -0
- data/app/views/concepts/alphabetical/index.html.erb +5 -3
- data/app/views/concepts/expired/index.html.erb +5 -2
- data/app/views/concepts/scheme/_sidebar.html.erb +3 -3
- data/app/views/concepts/sidebars/_singular.html.erb +4 -4
- data/app/views/dashboard/_sidebar.html.erb +7 -4
- data/app/views/dashboard/index.html.erb +1 -1
- data/app/views/dashboard/reset.html.erb +6 -0
- data/app/views/imports/index.html.erb +44 -0
- data/app/views/imports/show.html.erb +7 -0
- data/app/views/layouts/application.html.erb +7 -1
- data/app/views/partials/labeling/skos/_search_result.html.erb +12 -16
- data/app/views/partials/match/_edit_base.html.erb +1 -1
- data/app/views/partials/note/_search_result.html.erb +8 -5
- data/app/views/partials/note/skos/change_note/_search_result.html.erb +7 -10
- data/app/views/partials/note/skos/definition/_search_result.html.erb +5 -5
- data/app/views/rdf/dataset.iqrdf +9 -0
- data/app/views/search_results/_search_result_remote.html.erb +13 -0
- data/app/views/search_results/_sidebar.html.erb +3 -3
- data/app/views/search_results/index.html.erb +4 -4
- data/app/views/search_results/index.iqrdf +7 -7
- data/app/views/search_results/sections/_datasets.html.erb +17 -0
- data/app/views/search_results/sections/_klass.html.erb +2 -2
- data/app/views/search_results/sections/_languages.html.erb +3 -3
- data/app/views/users/_sidebar.html.erb +1 -1
- data/config/application.rb +0 -2
- data/config/engine.rb +5 -0
- data/config/environments/heroku.rb +62 -16
- data/config/initializers/apipie.rb +17 -0
- data/config/initializers/secret_token.rb +25 -9
- data/config/locales/activerecord.de.yml +5 -0
- data/config/locales/activerecord.en.yml +5 -0
- data/config/locales/de.yml +14 -0
- data/config/locales/en.yml +14 -0
- data/config/locales/pt.yml +1 -0
- data/config/routes.rb +7 -4
- data/db/migrate/20131220134356_create_delayed_jobs.rb +22 -0
- data/db/migrate/20131220144601_create_imports.rb +11 -0
- data/db/schema.rb +26 -1
- data/iqvoc.gemspec +12 -3
- data/lib/iqvoc/ability.rb +2 -0
- data/lib/iqvoc/configuration/core.rb +36 -9
- data/lib/iqvoc/controller_extensions.rb +4 -0
- data/lib/iqvoc/environments/production.rb +1 -1
- data/lib/iqvoc/skos_importer.rb +31 -19
- data/lib/iqvoc/version.rb +1 -1
- data/lib/tasks/importer.rake +10 -2
- data/lib/tasks/release.rake +1 -1
- data/public/404.html +43 -11
- data/public/422.html +43 -11
- data/public/500.html +43 -12
- data/test/functional/{rdf_test.rb → rdf_rendering_test.rb} +1 -1
- data/test/integration/alphabetical_test.rb +5 -5
- data/test/integration/search_test.rb +16 -16
- data/test/unit/skos_import_test.rb +9 -9
- data/vendor/assets/images/animated-overlay.gif +0 -0
- data/vendor/assets/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
- data/vendor/assets/images/ui-bg_flat_55_fbec88_40x100.png +0 -0
- data/vendor/assets/images/ui-bg_glass_75_d0e5f5_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_glass_85_dfeffc_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
- data/vendor/assets/images/ui-bg_gloss-wave_55_5c9ccc_500x100.png +0 -0
- data/vendor/assets/images/ui-bg_inset-hard_100_f5f8f9_1x100.png +0 -0
- data/vendor/assets/images/ui-bg_inset-hard_100_fcfdfd_1x100.png +0 -0
- data/vendor/assets/images/ui-icons_217bc0_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_2e83ff_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_469bdd_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_6da8d5_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_cd0a0a_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_d8e7f3_256x240.png +0 -0
- data/vendor/assets/images/ui-icons_f9bd01_256x240.png +0 -0
- data/vendor/assets/javascripts/jquery-ui.custom.js +4538 -0
- data/vendor/assets/stylesheets/jquery-ui-1.10.3.custom.css.scss +724 -0
- metadata +214 -64
- data/app/assets/images/arrow_down.gif +0 -0
- data/app/assets/images/arrow_up.gif +0 -0
- data/app/assets/images/iqvoc_logo.png +0 -0
- data/app/assets/images/spinner_16x16.gif +0 -0
- data/app/assets/images/spinner_24x24.gif +0 -0
- data/app/assets/stylesheets/iqvoc/components.css.scss +0 -155
- data/app/assets/stylesheets/iqvoc/layout.css.scss +0 -0
- data/app/views/concepts/alphabetical/_pref_labeling.html.erb +0 -19
- data/app/views/import/import.html.erb +0 -7
- data/app/views/import/index.html.erb +0 -17
- data/vendor/assets/javascripts/jquery-ui-1.8.23.custom.js +0 -3399
- data/vendor/assets/stylesheets/jquery-ui-1.8.23.custom.css.scss +0 -405
@@ -97,11 +97,13 @@ module ApplicationHelper
|
|
97
97
|
end
|
98
98
|
end
|
99
99
|
|
100
|
-
def icon(name,
|
101
|
-
|
102
|
-
|
100
|
+
def icon(name, additional_css = "")
|
101
|
+
css_classes = %W(fa fa-#{name})
|
102
|
+
if additional_css.respond_to?(:split)
|
103
|
+
css_classes << additional_css.split(" ")
|
104
|
+
end
|
103
105
|
|
104
|
-
content_tag :i, "", :class =>
|
106
|
+
content_tag :i, "", :class => css_classes.join(" ")
|
105
107
|
end
|
106
108
|
|
107
109
|
def glyph(name)
|
@@ -17,10 +17,10 @@
|
|
17
17
|
module DashboardHelper
|
18
18
|
|
19
19
|
def sorting_controls_for(name)
|
20
|
-
content_tag :
|
21
|
-
link_to(
|
20
|
+
content_tag :div, :class => "sorting-controls" do
|
21
|
+
link_to(icon("arrow-circle-o-up", "sorting-arrow"),
|
22
22
|
dashboard_path(:order => "asc", :by => name.to_s)) +
|
23
|
-
link_to(
|
23
|
+
link_to(icon("arrow-circle-o-down", "sorting-arrow"),
|
24
24
|
dashboard_path(:order => "desc", :by => name.to_s))
|
25
25
|
end
|
26
26
|
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module LinkHelper
|
2
|
+
def link_to_object(object, name, html_options = nil, &block)
|
3
|
+
path = case object
|
4
|
+
when Iqvoc::Concept.base_class
|
5
|
+
concept_path(:id => object)
|
6
|
+
when Iqvoc::Collection.base_class
|
7
|
+
collection_path(:id => object)
|
8
|
+
when Label::Base
|
9
|
+
label_path(:id => object)
|
10
|
+
end
|
11
|
+
|
12
|
+
link_to name, path, html_options, &block
|
13
|
+
end
|
14
|
+
end
|
@@ -16,11 +16,15 @@
|
|
16
16
|
|
17
17
|
module SearchResultsHelper
|
18
18
|
|
19
|
-
def
|
19
|
+
def search_language_selected?(lang)
|
20
20
|
(params[:languages] && params[:languages].include?(lang.to_s)) ||
|
21
21
|
(!params[:query] && I18n.locale.to_s == lang.to_s)
|
22
22
|
end
|
23
23
|
|
24
|
+
def search_dataset_selected?(adaptor)
|
25
|
+
params[:datasets] && params[:datasets].include?(adaptor.to_s)
|
26
|
+
end
|
27
|
+
|
24
28
|
def highlight_query(text, query)
|
25
29
|
query.split(/\n/).each do |q|
|
26
30
|
# call to ActiveSupport's highlight
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'iqvoc/skos_importer'
|
2
|
+
|
3
|
+
class ImportJob < Struct.new(:import, :content, :user, :namespace, :publish)
|
4
|
+
def perform
|
5
|
+
strio = StringIO.new
|
6
|
+
|
7
|
+
importer = Iqvoc::SkosImporter.new(content.to_s.split("\n"), namespace, Logger.new(strio), publish)
|
8
|
+
importer.run
|
9
|
+
@messages = strio.string
|
10
|
+
end
|
11
|
+
|
12
|
+
def success(job)
|
13
|
+
import.finish!(@messages)
|
14
|
+
end
|
15
|
+
|
16
|
+
def error(job, exception)
|
17
|
+
import.fail!(exception)
|
18
|
+
end
|
19
|
+
end
|
data/app/models/concept/base.rb
CHANGED
@@ -206,11 +206,11 @@ class Concept::Base < ActiveRecord::Base
|
|
206
206
|
|
207
207
|
# Serialized setters and getters (\r\n or , separated) -- TODO: use Iqvoc::InlineDataHelper?
|
208
208
|
define_method("inline_#{match_class_name.to_relation_name}".to_sym) do
|
209
|
-
self.send(match_class_name.to_relation_name).map(&:value).join(
|
209
|
+
self.send(match_class_name.to_relation_name).map(&:value).join(Iqvoc::InlineDataHelper::JOINER)
|
210
210
|
end
|
211
211
|
|
212
212
|
define_method("inline_#{match_class_name.to_relation_name}=".to_sym) do |value|
|
213
|
-
urls = value.split(
|
213
|
+
urls = value.split(Iqvoc::InlineDataHelper::SPLITTER).map(&:strip).reject(&:blank?)
|
214
214
|
self.send(match_class_name.to_relation_name).each do |match|
|
215
215
|
if (urls.include?(match.value))
|
216
216
|
urls.delete(match.value) # We're done with that one
|
@@ -0,0 +1,38 @@
|
|
1
|
+
class Dataset::Adaptors::Iqvoc::AlphabeticalSearchAdaptor < Dataset::Adaptors::Iqvoc::SearchAdaptor
|
2
|
+
def search(prefix, locale)
|
3
|
+
fetch_results("/#{locale}/alphabetical_concepts/#{prefix}.html")
|
4
|
+
@results
|
5
|
+
end
|
6
|
+
|
7
|
+
def fetch_results(url, params = {})
|
8
|
+
begin
|
9
|
+
response = @conn.get(url, params)
|
10
|
+
@results ||= []
|
11
|
+
@results += extract_results(response.body)
|
12
|
+
while more = @doc.at_css('a[rel=next]')
|
13
|
+
fetch_results(more[:href], {})
|
14
|
+
end
|
15
|
+
rescue Faraday::Error::ConnectionFailed,
|
16
|
+
Faraday::Error::ResourceNotFound,
|
17
|
+
Faraday::Error::TimeoutError => e
|
18
|
+
Rails.logger.warn("HTTP error while querying remote source #{url}: #{e.message}")
|
19
|
+
return nil
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def extract_results(html)
|
24
|
+
@doc = Nokogiri::HTML(html)
|
25
|
+
|
26
|
+
@doc.css('.concept-item').map do |element|
|
27
|
+
link = element.at_css('.concept-item-link')
|
28
|
+
label, path = link.text, link['data-resource-path'] # href
|
29
|
+
|
30
|
+
options = {
|
31
|
+
:definition => element.at_css('.concept-item-definition').try(:content),
|
32
|
+
:definition_language => element.at_css('.concept-item-definition').try(:[], :lang)
|
33
|
+
}
|
34
|
+
|
35
|
+
result = AlphabeticalSearchResultRemote.new(url, path, label, options)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
|
3
|
+
class Dataset::Adaptors::Iqvoc::HTTPAdaptor
|
4
|
+
attr_reader :url
|
5
|
+
|
6
|
+
def initialize(url)
|
7
|
+
@url = url
|
8
|
+
@conn = Faraday.new(:url => url) do |conn|
|
9
|
+
#conn.use Faraday::Response::Logger if Rails.env.development?
|
10
|
+
conn.adapter Faraday.default_adapter
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
def http_get(path, redirect_count = 0)
|
15
|
+
begin
|
16
|
+
response = @conn.get(path)
|
17
|
+
rescue Faraday::Error::ConnectionFailed,
|
18
|
+
Faraday::Error::ResourceNotFound,
|
19
|
+
Faraday::Error::TimeoutError => e
|
20
|
+
return failed_request(path)
|
21
|
+
end
|
22
|
+
|
23
|
+
if response.status == 404
|
24
|
+
return failed_request(path)
|
25
|
+
end
|
26
|
+
|
27
|
+
if response.status == 302 && redirect_count < 3
|
28
|
+
response = http_get(response.headers["location"], redirect_count + 1)
|
29
|
+
end
|
30
|
+
|
31
|
+
response
|
32
|
+
end
|
33
|
+
|
34
|
+
private
|
35
|
+
def failed_request(path)
|
36
|
+
Rails.logger.warn "HTTP error while querying remote source #{path}"
|
37
|
+
return nil
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class Dataset::Adaptors::Iqvoc::LabelAdaptor < Dataset::Adaptors::Iqvoc::HTTPAdaptor
|
2
|
+
def find(concept_url)
|
3
|
+
path = URI.parse(concept_url).path
|
4
|
+
if response = http_get(path)
|
5
|
+
extract_label(response.body)
|
6
|
+
end
|
7
|
+
end
|
8
|
+
|
9
|
+
def extract_label(html)
|
10
|
+
doc = Nokogiri::HTML(html)
|
11
|
+
node = doc.at_css('h1')
|
12
|
+
node.at_css('small').remove
|
13
|
+
node.text.try(:strip)
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,60 @@
|
|
1
|
+
class Dataset::Adaptors::Iqvoc::SearchAdaptor < Dataset::Adaptors::Iqvoc::HTTPAdaptor
|
2
|
+
def search(raw_params = {})
|
3
|
+
languages = raw_params.fetch(:languages, I18n.locale)
|
4
|
+
languages = Array.wrap(languages).flatten.join(",")
|
5
|
+
|
6
|
+
params = {
|
7
|
+
:q => raw_params[:q],
|
8
|
+
:t => raw_params[:t],
|
9
|
+
:l => languages,
|
10
|
+
:c => raw_params[:c],
|
11
|
+
:qt => raw_params[:qt],
|
12
|
+
:page => 1 # hard code the first page as we need to follow pagination links
|
13
|
+
}
|
14
|
+
|
15
|
+
fetch_results('/search.html', params)
|
16
|
+
@results
|
17
|
+
end
|
18
|
+
|
19
|
+
def fetch_results(path, params = {})
|
20
|
+
begin
|
21
|
+
response = @conn.get(path, params)
|
22
|
+
@results ||= []
|
23
|
+
@results += extract_results(response.body)
|
24
|
+
while more = @doc.at_css('a[rel=next]')
|
25
|
+
fetch_results(more[:href], {})
|
26
|
+
end
|
27
|
+
rescue Faraday::Error::ConnectionFailed,
|
28
|
+
Faraday::Error::ResourceNotFound,
|
29
|
+
Faraday::Error::TimeoutError => e
|
30
|
+
Rails.logger.warn("HTTP error while querying remote source #{path}: #{e.message}")
|
31
|
+
return nil
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def extract_results(html)
|
36
|
+
@doc = Nokogiri::HTML(html)
|
37
|
+
|
38
|
+
@doc.css('.search-result').map do |element|
|
39
|
+
link = element.at_css('.search-result-link')
|
40
|
+
label, path = link.text, link['data-resource-path']
|
41
|
+
result = SearchResultRemote.new(url, path, label)
|
42
|
+
|
43
|
+
if (meta = element.css('.search-result-meta > .search-result-value')) && meta.any?
|
44
|
+
meta.each do |element|
|
45
|
+
result.add_meta_information(element['data-key'], element.text)
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
if body = element.at_css('.search-result-body')
|
50
|
+
result.body = body.text
|
51
|
+
end
|
52
|
+
|
53
|
+
result.rdf_namespace = element['data-rdf-namespace']
|
54
|
+
result.rdf_predicate = element['data-rdf-predicate']
|
55
|
+
result.language = element['data-rdf-language']
|
56
|
+
|
57
|
+
result
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
require 'linkeddata'
|
2
|
+
|
3
|
+
class Dataset::IqvocDataset
|
4
|
+
attr_reader :name, :url
|
5
|
+
|
6
|
+
def initialize(url)
|
7
|
+
@url = URI.parse(url)
|
8
|
+
@repository = RDF::Repository.load(URI.join(url, 'dataset.rdf')) rescue nil
|
9
|
+
@name = fetch_name
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{name} (#{url})"
|
14
|
+
end
|
15
|
+
|
16
|
+
def search(params)
|
17
|
+
Dataset::Adaptors::Iqvoc::SearchAdaptor.new(url).search(params)
|
18
|
+
end
|
19
|
+
|
20
|
+
def alphabetical_search(prefix, locale)
|
21
|
+
Dataset::Adaptors::Iqvoc::AlphabeticalSearchAdaptor.new(url).search(prefix, locale)
|
22
|
+
end
|
23
|
+
|
24
|
+
def find_label(concept_url)
|
25
|
+
Dataset::Adaptors::Iqvoc::LabelAdaptor.new(url).find(concept_url)
|
26
|
+
end
|
27
|
+
|
28
|
+
private
|
29
|
+
def fetch_name
|
30
|
+
return 'unknown' if @repository.nil?
|
31
|
+
|
32
|
+
void = RDF::Vocabulary.new('http://rdfs.org/ns/void#')
|
33
|
+
query = RDF::Query.new({:dataset => {RDF.type => void.Dataset, RDF::DC.title => :title}})
|
34
|
+
results = query.execute(@repository)
|
35
|
+
|
36
|
+
return 'unknown' if results.empty?
|
37
|
+
results.map { |solution| solution.title.to_s }.first
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
class Import < ActiveRecord::Base
|
2
|
+
belongs_to :user
|
3
|
+
|
4
|
+
def finish!(messages)
|
5
|
+
self.output = messages
|
6
|
+
self.success = true
|
7
|
+
self.finished_at = Time.now
|
8
|
+
save!
|
9
|
+
end
|
10
|
+
|
11
|
+
def fail!(exception)
|
12
|
+
self.output = exception.to_s + "\n\n" + exception.backtrace.join("\n")
|
13
|
+
self.finished_at = Time.now
|
14
|
+
save!
|
15
|
+
end
|
16
|
+
end
|
data/app/models/note/base.rb
CHANGED
@@ -109,8 +109,8 @@ class Note::Base < ActiveRecord::Base
|
|
109
109
|
def self.single_query(params = {})
|
110
110
|
query_str = build_query_string(params)
|
111
111
|
|
112
|
-
by_query_value(query_str).
|
113
|
-
|
112
|
+
scope = by_query_value(query_str).by_language(params[:languages].to_a)
|
113
|
+
scope.map { |result| SearchResult.new(result) }
|
114
114
|
end
|
115
115
|
|
116
116
|
def self.search_result_partial_name
|
@@ -29,8 +29,9 @@ class Note::SKOS::ChangeNote < Note::SKOS::Base
|
|
29
29
|
def self.single_query(params = {})
|
30
30
|
query_str = build_query_string(params)
|
31
31
|
|
32
|
-
|
33
|
-
|
32
|
+
scope = includes(:annotations)
|
33
|
+
scope = merge(Note::Annotated::Base.where(Note::Annotated::Base.arel_table[:value].matches(query_str)))
|
34
|
+
scope.map { |result| SearchResult.new(result) }
|
34
35
|
end
|
35
36
|
|
36
37
|
def build_rdf(document, subject)
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class AlphabeticalSearchResult
|
2
|
+
delegate :url_helpers, :to => 'Rails.application.routes'
|
3
|
+
|
4
|
+
def initialize(pref_labeling)
|
5
|
+
@labeling = pref_labeling
|
6
|
+
end
|
7
|
+
|
8
|
+
def label
|
9
|
+
@labeling.target
|
10
|
+
end
|
11
|
+
|
12
|
+
def concept
|
13
|
+
@labeling.owner
|
14
|
+
end
|
15
|
+
|
16
|
+
def path
|
17
|
+
url_helpers.rdf_path(@labeling.owner.origin, :lang => nil, :format => nil)
|
18
|
+
end
|
19
|
+
|
20
|
+
def definition?
|
21
|
+
relation_name = Note::SKOS::Definition.name.to_relation_name
|
22
|
+
@labeling.owner.respond_to?(relation_name) && @labeling.owner.send(relation_name).any?
|
23
|
+
end
|
24
|
+
|
25
|
+
def definition
|
26
|
+
relation_name = Note::SKOS::Definition.name.to_relation_name
|
27
|
+
@labeling.owner.send(relation_name).first
|
28
|
+
end
|
29
|
+
|
30
|
+
def partial_name
|
31
|
+
'concepts/alphabetical/search_result'
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
class AlphabeticalSearchResultRemote < AlphabeticalSearchResult
|
2
|
+
def initialize(host, path, label, options = {})
|
3
|
+
@host = host
|
4
|
+
@path = path
|
5
|
+
@label = label
|
6
|
+
@definition = options[:definition]
|
7
|
+
@definition_language = options[:definition_language]
|
8
|
+
end
|
9
|
+
|
10
|
+
def label
|
11
|
+
@label
|
12
|
+
end
|
13
|
+
|
14
|
+
def path
|
15
|
+
@path
|
16
|
+
end
|
17
|
+
|
18
|
+
def url
|
19
|
+
URI.join(@host, @path).to_s
|
20
|
+
end
|
21
|
+
|
22
|
+
def definition?
|
23
|
+
@definition.present?
|
24
|
+
end
|
25
|
+
|
26
|
+
def definition
|
27
|
+
@definition
|
28
|
+
end
|
29
|
+
|
30
|
+
def definition_language
|
31
|
+
@definition_language
|
32
|
+
end
|
33
|
+
|
34
|
+
def partial_name
|
35
|
+
'concepts/alphabetical/search_result_remote'
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
class SearchResult
|
2
|
+
extend Forwardable
|
3
|
+
def_delegators :@result_object, :build_search_result_rdf, :owner, :target,
|
4
|
+
:value, :label, :rdf_namespace, :rdf_predicate
|
5
|
+
|
6
|
+
def initialize(result_object)
|
7
|
+
@result_object = result_object
|
8
|
+
end
|
9
|
+
|
10
|
+
def model_name
|
11
|
+
@result_object.class.model_name
|
12
|
+
end
|
13
|
+
|
14
|
+
def search_result_partial_name
|
15
|
+
@result_object.class.search_result_partial_name
|
16
|
+
end
|
17
|
+
|
18
|
+
def language
|
19
|
+
if @result_object.is_a?(Labeling::Base)
|
20
|
+
@result_object.target.try(:language)
|
21
|
+
else
|
22
|
+
@result_object.try(:language)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def to_s
|
27
|
+
if @result_object.is_a?(Labeling::Base)
|
28
|
+
@result_object.target.value
|
29
|
+
else
|
30
|
+
@result_object.try(:owner).try(:pref_label).to_s
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|