diff options
author | Jochen Topf <jochen@topf.org> | 2012-01-23 12:11:49 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2012-01-23 12:11:49 +0100 |
commit | 44e35a370ce6dd2bfbf93f3722c2859fc1703860 (patch) | |
tree | c91d0f2196a8f1bc52da330f3537fa080b1d2058 | |
parent | 46d84e2b9c9c4a95931f5bb9412bd000bcd79fdf (diff) | |
download | taginfo-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.
-rw-r--r-- | web/lib/api/db.rb | 21 | ||||
-rw-r--r-- | web/public/js/taginfo.js | 14 | ||||
-rw-r--r-- | web/views/key.erb | 2 |
3 files changed, 28 insertions, 9 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 diff --git a/web/public/js/taginfo.js b/web/public/js/taginfo.js index 2dadc3d..5e713cd 100644 --- a/web/public/js/taginfo.js +++ b/web/public/js/taginfo.js @@ -608,12 +608,13 @@ var create_flexigrid_for = { } }); }, - values: function(key, filter_type) { + values: function(key, filter_type, lang) { create_flexigrid('grid-values', { - url: '/api/2/db/keys/values?key=' + encodeURIComponent(key) + '&filter=' + encodeURIComponent(filter_type), + url: '/api/2/db/keys/values?key=' + encodeURIComponent(key) + '&filter=' + encodeURIComponent(filter_type) + '&lang=' + encodeURIComponent(lang), colModel: [ - { display: texts.osm.value, name: 'value', width: 500, sortable: true }, - { display: texts.misc.count, name: 'count', width: 300, sortable: true, align: 'center' } + { display: texts.osm.value, name: 'value', width: 200, sortable: true }, + { display: texts.misc.count, name: 'count', width: 240, sortable: true, align: 'center' }, + { display: 'Description', name: 'description', width: 600, sortable: false, align: 'left' } ], searchitems: [ { display: texts.osm.value, name: 'value' } @@ -623,8 +624,9 @@ var create_flexigrid_for = { preProcess: function(data) { data.rows = jQuery.map(data.data, function(row, i) { return { 'cell': [ - link_to_value(key, row.value), - print_value_with_percent(row.count, row.fraction) + hover_expand(link_to_value(key, row.value)), + print_value_with_percent(row.count, row.fraction), + row.description ] }; }); delete data.data; diff --git a/web/views/key.erb b/web/views/key.erb index 255f593..ba58402 100644 --- a/web/views/key.erb +++ b/web/views/key.erb @@ -126,7 +126,7 @@ function page_init() { window.location.search = jQuery.param(qs); }); - init_tabs('key', [#{ @key.to_json }, #{ @filter_type.to_json }]); + init_tabs('key', [#{ @key.to_json }, #{ @filter_type.to_json }, #{ r18n.locale.code.to_json }]); var data = #{ @prevalent_values.to_json() }; |