diff options
author | Jochen Topf <jochen@topf.org> | 2013-01-17 22:44:42 +0100 |
---|---|---|
committer | Jochen Topf <jochen@topf.org> | 2013-01-17 22:44:42 +0100 |
commit | 363579cf17fe54c5ffcd5407164ceaa6be8e16fe (patch) | |
tree | 97c4fd17d3a19bb1cf748c7826a7d8efd84617c8 /web | |
parent | 2cc4f68ca65b7d9c8a20aed1875ed464ee8afa4d (diff) | |
download | taginfo-363579cf17fe54c5ffcd5407164ceaa6be8e16fe.tar taginfo-363579cf17fe54c5ffcd5407164ceaa6be8e16fe.tar.gz |
Add description and stats to relations page
Diffstat (limited to 'web')
-rw-r--r-- | web/i18n/en.yml | 5 | ||||
-rw-r--r-- | web/lib/api/v4/relation.rb | 35 | ||||
-rw-r--r-- | web/lib/ui/relation.rb | 8 | ||||
-rw-r--r-- | web/views/relation.erb | 4 | ||||
-rw-r--r-- | web/viewsjs/relation.js.erb | 23 |
5 files changed, 74 insertions, 1 deletions
diff --git a/web/i18n/en.yml b/web/i18n/en.yml index 36225fa..098c29c 100644 --- a/web/i18n/en.yml +++ b/web/i18n/en.yml @@ -221,9 +221,14 @@ pages: no_styles: No JOSM styles for this tag. relation: name: Relation type + description_from_wiki: Description of this relation type from the wiki (if available in your chosen language, otherwise in English). + no_description_in_wiki: No description for this relation type in the wiki. overview: tab: Overview title: Overview + member_type: Member type + member_count: Number of members + see_also: See also the tag page roles: tab: Roles title: Member roles diff --git a/web/lib/api/v4/relation.rb b/web/lib/api/v4/relation.rb index 4569be3..4982f07 100644 --- a/web/lib/api/v4/relation.rb +++ b/web/lib/api/v4/relation.rb @@ -68,4 +68,39 @@ class Taginfo < Sinatra::Base }.to_json end + api(4, 'relation/stats', { + :description => 'Show some database statistics for given relation type.', + :parameters => { :rtype => 'Relation type (required).' }, + :result => no_paging_results([ + [:type, :STRING, 'Member type ("all", "nodes", "ways", or "relations")'], + [:count, :INT, 'Number of members with this type.'] + ]), + :example => { :rtype => 'multipolygon' }, + :ui => '/relations/multipolygon#overview' + }) do + rtype = params[:rtype] + out = [] + + # default values + ['all', 'nodes', 'ways', 'relations'].each_with_index do |type, n| + out[n] = { :type => type, :count => 0 } + end + + @db.select('SELECT * FROM db.relation_types'). + condition('rtype = ?', rtype). + execute() do |row| + ['all', 'nodes', 'ways', 'relations'].each_with_index do |type, n| + out[n] = { + :type => type, + :count => row['members_' + type].to_i + } + end + end + + return { + :total => 4, + :data => out + }.to_json + end + end diff --git a/web/lib/ui/relation.rb b/web/lib/ui/relation.rb index 1a3a054..e55d02b 100644 --- a/web/lib/ui/relation.rb +++ b/web/lib/ui/relation.rb @@ -11,7 +11,13 @@ class Taginfo < Sinatra::Base @title = [escape_html(@rtype), t.osm.relations] section :relations - @desc = 'XXX' + @desc = h(@db.select("SELECT description FROM wiki.relation_pages WHERE lang=? AND rtype=?", r18n.locale.code, @rtype).get_first_value()) + @desc = h(@db.select("SELECT description FROM wiki.relation_pages WHERE lang='en' AND rtype=?", @rtype).get_first_value()) if @desc == '' + if @desc == '' + @desc = "<span class='empty'>#{ t.pages.relation.no_description_in_wiki }</span>" + else + @desc = "<span title='#{ t.pages.relation.description_from_wiki }' tipsy='w'>#{ @desc }</span>" + end @count_relation_roles = @db.count('relation_roles'). condition("rtype=?", rtype). diff --git a/web/views/relation.erb b/web/views/relation.erb index 4cee9a9..bf0044b 100644 --- a/web/views/relation.erb +++ b/web/views/relation.erb @@ -9,6 +9,9 @@ </ul> <div id="overview"> <h2><%= t.pages.relation.overview.title %></h2> + <table id="grid-overview"> + </table> + <p><%= t.pages.relation.overview.see_also %>: type=<span id="taglink"></span></p> </div> <div id="roles"> <h2><%= t.pages.relation.roles.title %></h2> @@ -25,6 +28,7 @@ function page_init2() { var rtype = #{ @rtype.to_json }; jQuery('h1').html("#{ t.pages.relation.name } '" + fmt_rtype(rtype) + "'"); + jQuery('span#taglink').html(link_to_value('type', rtype)); init_tabs([rtype]); } JAVASCRIPT diff --git a/web/viewsjs/relation.js.erb b/web/viewsjs/relation.js.erb index 26b83fa..931f33c 100644 --- a/web/viewsjs/relation.js.erb +++ b/web/viewsjs/relation.js.erb @@ -3,6 +3,29 @@ page = @trans.t.pages.relation %> var create_flexigrid_for = { + overview: function(rtype) { + create_flexigrid('grid-overview', { + url: '/api/4/relation/stats?rtype=' + encodeURIComponent(rtype), + colModel: [ + { display: '<%= page.overview.member_type %>', name: 'type', width: 100, sortable: true }, + { display: '<%= page.overview.member_count %>', name: 'count', width: 260, sortable: true, align: 'right' } + ], + usepager: false, + useRp: false, + preProcess: function(data) { + return { + total: 4, + page: 1, + rows: jQuery.map(data.data, function(row, i) { + return { 'cell': [ + fmt_type_image(row.type), + fmt_with_ts(row.count) + ]}; + }) + }; + } + }); + }, roles: function(rtype) { create_flexigrid('grid-roles', { url: '/api/4/relation/roles?type=' + encodeURIComponent(rtype), |