aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--web/lib/api/v4/key.rb14
-rw-r--r--web/lib/api/v4/tag.rb14
-rw-r--r--web/viewsjs/key.js.erb2
-rw-r--r--web/viewsjs/tag.js.erb4
4 files changed, 31 insertions, 3 deletions
diff --git a/web/lib/api/v4/key.rb b/web/lib/api/v4/key.rb
index f53376e..83d09fd 100644
--- a/web/lib/api/v4/key.rb
+++ b/web/lib/api/v4/key.rb
@@ -330,6 +330,12 @@ class Taginfo < Sinatra::Base
:query => 'Only show results where the value matches this query (substring match, optional).'
},
:paging => :optional,
+ :filter => {
+ :all => { :doc => 'No filter.' },
+ :nodes => { :doc => 'Only values on tags used on nodes.' },
+ :ways => { :doc => 'Only values on tags used on ways.' },
+ :relations => { :doc => 'Only values on tags used on relations.' }
+ },
:sort => %w( project_name tag ),
:result => paging_results([
[:project_id, :STRING, 'Project ID'],
@@ -350,16 +356,24 @@ class Taginfo < Sinatra::Base
}) do
key = params[:key]
q = like_contains(params[:query])
+ filter_type = get_filter()
+
total = @db.select('SELECT count(*) FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
condition("status = 'OK'").
condition('key = ?', key).
condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
+ condition_if("on_node = ?", filter_type == 'nodes' ? 1 : '').
+ condition_if("on_way = ? OR on_area = 1", filter_type == 'ways' ? 1 : '').
+ condition_if("on_relation = ? OR on_area = 1", filter_type == 'relations' ? 1 : '').
get_first_value().to_i
res = @db.select('SELECT t.project_id, p.name, p.icon_url AS project_icon_url, t.key, t.value, t.description, t.doc_url, t.icon_url, t.on_node, t.on_way, t.on_relation, t.on_area FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
condition("status = 'OK'").
condition('key = ?', key).
condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
+ condition_if("on_node = ?", filter_type == 'nodes' ? 1 : '').
+ condition_if("on_way = ? OR on_area = 1", filter_type == 'ways' ? 1 : '').
+ condition_if("on_relation = ? OR on_area = 1", filter_type == 'relations' ? 1 : '').
order_by(@ap.sortname, @ap.sortorder) { |o|
o.project_name 'lower(p.name)'
o.project_name :value
diff --git a/web/lib/api/v4/tag.rb b/web/lib/api/v4/tag.rb
index d46f03c..b6fdbbe 100644
--- a/web/lib/api/v4/tag.rb
+++ b/web/lib/api/v4/tag.rb
@@ -256,6 +256,12 @@ class Taginfo < Sinatra::Base
:query => 'Only show results where the value matches this query (substring match, optional).'
},
:paging => :optional,
+ :filter => {
+ :all => { :doc => 'No filter.' },
+ :nodes => { :doc => 'Only values on tags used on nodes.' },
+ :ways => { :doc => 'Only values on tags used on ways.' },
+ :relations => { :doc => 'Only values on tags used on relations.' }
+ },
:sort => %w( project_name tag ),
:result => paging_results([
[:project_id, :STRING, 'Project ID'],
@@ -276,17 +282,25 @@ class Taginfo < Sinatra::Base
}) do
key = params[:key]
value = params[:value]
+ filter_type = get_filter()
q = like_contains(params[:query])
+
total = @db.select('SELECT count(distinct project_id) FROM projects.projects p, projects.project_tags t ON p.id=t.project_id').
condition("status = 'OK'").
condition('key = ?', key).
condition('value = ? OR VALUE IS NULL', value).
condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
+ condition_if("on_node = ?", filter_type == 'nodes' ? 1 : '').
+ condition_if("on_way = ? OR on_area = 1", filter_type == 'ways' ? 1 : '').
+ condition_if("on_relation = ? OR on_area = 1", filter_type == 'relations' ? 1 : '').
get_first_value().to_i
res = @db.select("SELECT p.name, p.icon_url AS project_icon_url, t.* FROM (SELECT project_id, key, MAX(value) AS value FROM projects.project_tags WHERE key=? AND (value=? OR value IS NULL) GROUP BY project_id, key) AS s JOIN projects.project_tags t JOIN projects.projects p ON p.id=t.project_id AND t.project_id=s.project_id AND t.key=s.key AND (t.value=s.value OR (t.value IS NULL AND s.value IS NULL))", key, value).
condition("p.status = 'OK'").
condition_if("value LIKE ? ESCAPE '@' OR name LIKE ? ESCAPE '@'", q, q).
+ condition_if("on_node = ?", filter_type == 'nodes' ? 1 : '').
+ condition_if("on_way = ? OR on_area = 1", filter_type == 'ways' ? 1 : '').
+ condition_if("on_relation = ? OR on_area = 1", filter_type == 'relations' ? 1 : '').
order_by(@ap.sortname, @ap.sortorder) { |o|
o.project_name 'lower(p.name)'
o.project_name :value
diff --git a/web/viewsjs/key.js.erb b/web/viewsjs/key.js.erb
index 945b2e6..9b8698f 100644
--- a/web/viewsjs/key.js.erb
+++ b/web/viewsjs/key.js.erb
@@ -147,7 +147,7 @@ var create_flexigrid_for = {
},
projects: function(key, filter_type) {
create_flexigrid('grid-projects', {
- url: '/api/4/key/projects?key=' + encodeURIComponent(key),
+ url: '/api/4/key/projects?key=' + encodeURIComponent(key) + '&filter=' + encodeURIComponent(filter_type),
colModel: [
{ display: '<%= h(taginfo.project) %>', name: 'project_name', width: 280, sortable: true },
{ display: '<%= h(osm.tag) %>', name: 'tag', width: 220, sortable: true },
diff --git a/web/viewsjs/tag.js.erb b/web/viewsjs/tag.js.erb
index 7cd9787..4616acc 100644
--- a/web/viewsjs/tag.js.erb
+++ b/web/viewsjs/tag.js.erb
@@ -125,9 +125,9 @@ var create_flexigrid_for = {
}
});
},
- projects: function(key, value) {
+ projects: function(key, value, filter_type) {
create_flexigrid('grid-projects', {
- url: '/api/4/tag/projects?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value),
+ url: '/api/4/tag/projects?key=' + encodeURIComponent(key) + '&value=' + encodeURIComponent(value) + '&filter=' + encodeURIComponent(filter_type),
colModel: [
{ display: '<%= h(taginfo.project) %>', name: 'project_name', width: 280, sortable: true },
{ display: '<%= h(osm.tag) %>', name: 'tag', width: 220, sortable: true },