diff options
-rw-r--r-- | web/i18n/de.yml | 3 | ||||
-rw-r--r-- | web/i18n/en.yml | 3 | ||||
-rw-r--r-- | web/lib/api/v4/relation.rb | 61 | ||||
-rw-r--r-- | web/views/relation.erb | 6 | ||||
-rw-r--r-- | web/viewsjs/relation.js.erb | 24 |
5 files changed, 97 insertions, 0 deletions
diff --git a/web/i18n/de.yml b/web/i18n/de.yml index a5322b7..7ff3cf1 100644 --- a/web/i18n/de.yml +++ b/web/i18n/de.yml @@ -339,6 +339,9 @@ pages: none_found: Keine Wiki-Seiten für diesen Relation-Typ vorhanden. create: Wiki-Seite für diesen Relation-Typ anlegen wiki_page: Wiki-Seite + projects: + title: Projekte, die diesen Relation-Typ benutzen + description: Wie dieser Relation-Typ im Projekt benutzt wird project: overview: project_name: Projektname diff --git a/web/i18n/en.yml b/web/i18n/en.yml index 60ca12d..299229d 100644 --- a/web/i18n/en.yml +++ b/web/i18n/en.yml @@ -409,6 +409,9 @@ pages: none_found: No wiki page available for this relation type. create: Create wiki page for this relation type wiki_page: Wiki page + projects: + title: Projects using this relation type + description: How this relation type is used in the project project: overview: project_name: Project name diff --git a/web/lib/api/v4/relation.rb b/web/lib/api/v4/relation.rb index 32af96c..6400f1e 100644 --- a/web/lib/api/v4/relation.rb +++ b/web/lib/api/v4/relation.rb @@ -152,4 +152,65 @@ class Taginfo < Sinatra::Base }, json_opts(params[:format])) end + api(4, 'relation/projects', { + :description => 'Get projects using a given relation type.', + :parameters => { + :rtype => 'Relation type (required)', + :query => 'Only show results where the value matches this query (substring match, optional).' + }, + :paging => :optional, + :sort => %w( project_name ), + :result => paging_results([ + [:project_id, :STRING, 'Project ID'], + [:project_name, :STRING, 'Project name'], + [:project_icon_url, :STRING, 'Project icon URL'], + [:key, :STRING, 'Key'], + [:value, :STRING, 'Value'], + [:on_node, :BOOL, 'For nodes?'], + [:on_way, :BOOL, 'For ways?'], + [:on_relation, :BOOL, 'For relations?'], + [:on_area, :BOOL, 'For areas?'], + [:description, :STRING, 'Description'], + [:doc_url, :STRING, 'Documentation URL'], + [:icon_url, :STRING, 'Icon URL'] + ]), + :example => { :rtype => 'route', :page => 1, :rp => 10, :sortname => 'project_name', :sortorder => 'asc' }, + :ui => '/relations/route#projects' + }) do + rtype = params[:rtype] + q = like_contains(params[:query]) + + total = @db.select('SELECT count(*) FROM projects.projects p, projects.project_tags t ON p.id=t.project_id'). + condition("status = 'OK' AND on_relation = 1"). + condition("key = 'type' AND value = ?", rtype). + condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q). + get_first_value().to_i + + res = @db.select('SELECT t.project_id, p.name, p.icon_url AS project_icon_url, t.value, t.description, t.doc_url, t.icon_url FROM projects.projects p, projects.project_tags t ON p.id=t.project_id'). + condition("status = 'OK' AND on_relation = 1"). + condition("key = 'type' AND value = ?", rtype). + condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q). + order_by(@ap.sortname, @ap.sortorder) { |o| + o.project_name 'lower(p.name)' + }. + paging(@ap). + execute() + + return JSON.generate({ + :page => @ap.page, + :rp => @ap.results_per_page, + :total => total.to_i, + :url => request.url, + :data => res.map{ |row| { + :project_id => row['project_id'], + :project_name => row['name'], + :project_icon_url => row['project_icon_url'], + :rtype => row['value'], + :description => row['description'], + :doc_url => row['doc_url'], + :icon_url => row['icon_url'] + } } + }, json_opts(params[:format])) + end + end diff --git a/web/views/relation.erb b/web/views/relation.erb index be5feb7..caca294 100644 --- a/web/views/relation.erb +++ b/web/views/relation.erb @@ -17,6 +17,7 @@ <li><a href="#roles"><%= h(t.pages.relation.roles.tab) %></a></li> <li><a href="#graph"><%= h(t.pages.relation.graph.tab) %></a></li> <li><a href="#wiki"><%= h(t.sources.wiki.name) %></a></li> + <li><a href="#projects"><%= h(t.taginfo.projects) %></a></li> </ul> <div id="overview"> <% if @image_url %> @@ -57,6 +58,11 @@ <p><a class="extlink" target="_blank" rel="nofollow" href="//wiki.openstreetmap.org/w/index.php?action=edit&title=Relation:<%= @rtype_uri %>"><%= h(t.pages.relation.wiki_pages.create) %></a></p> <% end %> </div> + <div id="projects"> + <h2><%= h(t.pages.relation.projects.title) %></h2> + <table id="grid-projects"> + </table> + </div> </div> <iframe id="josmiframe" name="josmiframe"></iframe> <% javascript do diff --git a/web/viewsjs/relation.js.erb b/web/viewsjs/relation.js.erb index f192ffd..ad34fc3 100644 --- a/web/viewsjs/relation.js.erb +++ b/web/viewsjs/relation.js.erb @@ -1,6 +1,7 @@ <% osm = @trans.t.osm misc = @trans.t.misc + taginfo = @trans.t.taginfo page = @trans.t.pages.relation %> var create_flexigrid_for = { @@ -82,6 +83,29 @@ var create_flexigrid_for = { }; } }); + }, + projects: function(rtype) { + create_flexigrid('grid-projects', { + url: '/api/4/relation/projects?rtype=' + encodeURIComponent(rtype), + colModel: [ + { display: '<%= h(taginfo.project) %>', name: 'project_name', width: 280, sortable: true }, + { display: '<%= h(page.projects.description) %>', name: 'description', width: 600, sortable: false, align: 'left' } + ], + searchitems: [ + { display: '<%= h(taginfo.project) %>/<%= h(osm.value) %>', name: 'project_value' } + ], + sortname: 'project_name', + sortorder: 'asc', + preProcess: function(data) { + data.rows = jQuery.map(data.data, function(row, i) { + return { 'cell': [ + link_to_project(row.project_id, row.project_name, row.project_icon_url), + project_tag_desc(row.description, row.icon_url, row.doc_url) + ] }; + }); + return data; + } + }); } }; |