aboutsummaryrefslogtreecommitdiff
path: root/web/lib
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2012-01-23 12:11:49 +0100
committerJochen Topf <jochen@topf.org>2012-01-23 12:11:49 +0100
commit44e35a370ce6dd2bfbf93f3722c2859fc1703860 (patch)
treec91d0f2196a8f1bc52da330f3537fa080b1d2058 /web/lib
parent46d84e2b9c9c4a95931f5bb9412bd000bcd79fdf (diff)
downloadtaginfo-44e35a370ce6dd2bfbf93f3722c2859fc1703860.tar
taginfo-44e35a370ce6dd2bfbf93f3722c2859fc1703860.tar.gz
Add lang parameter to db/keys/values API call, it now shows description from wiki; add this to values tab on key page.
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/api/db.rb21
1 files changed, 19 insertions, 2 deletions
diff --git a/web/lib/api/db.rb b/web/lib/api/db.rb
index 742d151..e9239f4 100644
--- a/web/lib/api/db.rb
+++ b/web/lib/api/db.rb
@@ -332,6 +332,7 @@ class Taginfo < Sinatra::Base
:description => 'Get values used with a given key.',
:parameters => {
:key => 'Tag key (required).',
+ :lang => "Language (optional, default: 'en').",
:query => 'Only show results where the value matches this query (substring match, optional).'
},
:paging => :optional,
@@ -342,11 +343,12 @@ class Taginfo < Sinatra::Base
:relations => { :doc => 'Only values on tags used on relations.' }
},
:sort => %w( value count_all count_nodes count_ways count_relations ),
- :result => { :value => :STRING, :count => :INT, :fraction => :FLOAT },
+ :result => { :value => :STRING, :count => :INT, :fraction => :FLOAT, :description => :STRING },
:example => { :key => 'highway', :page => 1, :rp => 10, :sortname => 'count_ways', :sortorder => 'desc' },
:ui => '/keys/highway#values'
}) do
key = params[:key]
+ lang = params[:lang] || 'en'
filter_type = get_filter()
if params[:sortname] == 'count'
@@ -379,6 +381,20 @@ class Taginfo < Sinatra::Base
paging(params[:rp], params[:page]).
execute()
+ # Read description for tag from wikipages, first in English then in the chosen
+ # language. This way the chosen language description will overwrite the default
+ # English one.
+ wikidesc = {}
+ ['en', lang].uniq.each do |lang|
+ @db.select('SELECT value, description FROM wiki.wikipages').
+ condition('lang = ?', lang).
+ condition('key = ?', key).
+ condition("value IN (#{ res.map{ |row| "'" + SQLite3::Database.quote(row['value']) + "'" }.join(',') })").
+ execute().each do |row|
+ wikidesc[row['value']] = row['description']
+ end
+ end
+
return {
:page => params[:page].to_i,
:rp => params[:rp].to_i,
@@ -386,7 +402,8 @@ class Taginfo < Sinatra::Base
:data => res.map{ |row| {
:value => row['value'],
:count => row['count_' + filter_type].to_i,
- :fraction => (row['count_' + filter_type].to_f / this_key_count.to_f).round_to(4)
+ :fraction => (row['count_' + filter_type].to_f / this_key_count.to_f).round_to(4),
+ :description => wikidesc[row['value']]
} }
}.to_json
end