summaryrefslogtreecommitdiff
path: root/web/lib/ui
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2014-05-17 09:47:34 +0200
committerJochen Topf <jochen@topf.org>2014-05-17 09:47:34 +0200
commitb187abceaf7732d25724552cf667d1f6b50f0cab (patch)
tree57e9c61cd37bc48f31ed68cadd3f8990b0a238b6 /web/lib/ui
parent82c16006d6204909c72711b3ecfb91a92e1288d2 (diff)
downloadtaginfo-b187abceaf7732d25724552cf667d1f6b50f0cab.tar
taginfo-b187abceaf7732d25724552cf667d1f6b50f0cab.tar.gz
Refactoring: Add get_first_i() function to sql lib.
Diffstat (limited to 'web/lib/ui')
-rw-r--r--web/lib/ui/comparison.rb18
-rw-r--r--web/lib/ui/keys.rb8
-rw-r--r--web/lib/ui/relation.rb10
-rw-r--r--web/lib/ui/tags.rb12
4 files changed, 23 insertions, 25 deletions
diff --git a/web/lib/ui/comparison.rb b/web/lib/ui/comparison.rb
index 4bc5d46..ad876c4 100644
--- a/web/lib/ui/comparison.rb
+++ b/web/lib/ui/comparison.rb
@@ -27,10 +27,10 @@ class Taginfo < Sinatra::Base
value = data[:value]
if value.nil?
- data[:count_all] = @db.select("SELECT count_all FROM db.keys").condition('key = ?', key).get_first_value().to_i
- data[:count_nodes] = @db.select("SELECT count_nodes FROM db.keys").condition('key = ?', key).get_first_value().to_i
- data[:count_ways] = @db.select("SELECT count_ways FROM db.keys").condition('key = ?', key).get_first_value().to_i
- data[:count_relations] = @db.select("SELECT count_relations FROM db.keys").condition('key = ?', key).get_first_value().to_i
+ data[:count_all] = @db.select("SELECT count_all FROM db.keys").condition('key = ?', key).get_first_i
+ data[:count_nodes] = @db.select("SELECT count_nodes FROM db.keys").condition('key = ?', key).get_first_i
+ data[:count_ways] = @db.select("SELECT count_ways FROM db.keys").condition('key = ?', key).get_first_i
+ data[:count_relations] = @db.select("SELECT count_relations FROM db.keys").condition('key = ?', key).get_first_i
desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value IS NULL", r18n.locale.code, key).get_first_value())
desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value IS NULL", key).get_first_value()) if desc == ''
@@ -46,10 +46,10 @@ class Taginfo < Sinatra::Base
data[:has_map] = data[:count_all] > 0
else
- data[:count_all] = @db.select("SELECT count_all FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i
- data[:count_nodes] = @db.select("SELECT count_nodes FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i
- data[:count_ways] = @db.select("SELECT count_ways FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i
- data[:count_relations] = @db.select("SELECT count_relations FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_value().to_i
+ data[:count_all] = @db.select("SELECT count_all FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_i
+ data[:count_nodes] = @db.select("SELECT count_nodes FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_i
+ data[:count_ways] = @db.select("SELECT count_ways FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_first_i
+ data[:count_relations] = @db.select("SELECT count_relations FROM db.tags").condition('key = ?', key).condition('value = ?', value).get_i
desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value=?", r18n.locale.code, key, value).get_first_value())
desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value=?", key, value).get_first_value()) if desc == ''
@@ -59,7 +59,7 @@ class Taginfo < Sinatra::Base
data[:wiki_pages] = @db.select("SELECT DISTINCT lang FROM wiki.wikipages WHERE key=? AND value=? ORDER BY lang", key, value).execute().map{ |row| row['lang'] }
- data[:has_map] = (@db.count('tag_distributions').condition('key = ?', key).condition('value = ?', value).get_first_value().to_i > 0)
+ data[:has_map] = (@db.count('tag_distributions').condition('key = ?', key).condition('value = ?', value).get_first_i > 0)
end
end
diff --git a/web/lib/ui/keys.rb b/web/lib/ui/keys.rb
index 5b8af23..162792e 100644
--- a/web/lib/ui/keys.rb
+++ b/web/lib/ui/keys.rb
@@ -18,7 +18,7 @@ class Taginfo < Sinatra::Base
@sel[@filter_type] = ' selected="selected"'
@filter_xapi = { 'all' => '*', nil => '*', 'nodes' => 'node', 'ways' => 'way', 'relations' => 'relation' }[@filter_type];
- @count_all_values = @db.select("SELECT count_#{@filter_type} FROM db.keys").condition('key = ?', @key).get_first_value().to_i
+ @count_all_values = @db.select("SELECT count_#{@filter_type} FROM db.keys").condition('key = ?', @key).get_first_i
@desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value IS NULL", r18n.locale.code, @key).get_first_value())
@desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value IS NULL", @key).get_first_value()) if @desc == ''
@@ -45,9 +45,9 @@ class Taginfo < Sinatra::Base
@prevalent_values << { 'value' => '(other)', 'count' => @count_all_values - sum }
end
- @josm_count = @db.count('josm_style_rules').condition('k = ?', @key).get_first_value().to_i
- @wiki_count = @db.count('wiki.wikipages').condition('value IS NULL').condition('key=?', @key).get_first_value().to_i
- @user_count = @db.select('SELECT users_all FROM db.keys').condition('key=?', @key).get_first_value().to_i
+ @josm_count = @db.count('josm_style_rules').condition('k = ?', @key).get_first_i
+ @wiki_count = @db.count('wiki.wikipages').condition('value IS NULL').condition('key=?', @key).get_first_i
+ @user_count = @db.select('SELECT users_all FROM db.keys').condition('key=?', @key).get_first_i
@img_width = TaginfoConfig.get('geodistribution.width') * TaginfoConfig.get('geodistribution.scale_image')
@img_height = TaginfoConfig.get('geodistribution.height') * TaginfoConfig.get('geodistribution.scale_image')
diff --git a/web/lib/ui/relation.rb b/web/lib/ui/relation.rb
index e3bffa7..8656083 100644
--- a/web/lib/ui/relation.rb
+++ b/web/lib/ui/relation.rb
@@ -13,8 +13,8 @@ class Taginfo < Sinatra::Base
@title = [escape_html(@rtype), t.osm.relations]
section :relations
- @wiki_count = @db.count('wiki.relation_pages').condition('rtype=?', @rtype).get_first_value().to_i
- @count_all_values = @db.select("SELECT count FROM db.relation_types").condition('rtype = ?', @rtype).get_first_value().to_i
+ @wiki_count = @db.count('wiki.relation_pages').condition('rtype=?', @rtype).get_first_i
+ @count_all_values = @db.select("SELECT count FROM db.relation_types").condition('rtype = ?', @rtype).get_first_i
@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 == ''
@@ -29,11 +29,9 @@ class Taginfo < Sinatra::Base
@image_url = build_image_url(row)
end
- @count_relation_roles = @db.count('relation_roles').
- condition("rtype=?", @rtype).
- get_first_value().to_i
+ @count_relation_roles = @db.count('relation_roles').condition("rtype=?", @rtype).get_first_i
- sum_count_all = @db.select("SELECT members_all FROM db.relation_types WHERE rtype=?", @rtype).get_first_value().to_i
+ sum_count_all = @db.select("SELECT members_all FROM db.relation_types WHERE rtype=?", @rtype).get_first_i
@roles = []
sum = { 'nodes' => 0, 'ways' => 0, 'relations' => 0 }
diff --git a/web/lib/ui/tags.rb b/web/lib/ui/tags.rb
index 4ba184c..342be55 100644
--- a/web/lib/ui/tags.rb
+++ b/web/lib/ui/tags.rb
@@ -30,12 +30,12 @@ class Taginfo < Sinatra::Base
@sel[@filter_type] = ' selected="selected"'
@filter_xapi = { 'all' => '*', nil => '*', 'nodes' => 'node', 'ways' => 'way', 'relations' => 'relation' }[@filter_type];
- @josm_count = @db.count('josm_style_rules').condition('k = ?', @key).condition('v = ?', @value).get_first_value().to_i
- @wiki_count = @db.count('wiki.wikipages').condition('key=?', @key).condition('value=?', @value).get_first_value().to_i
+ @josm_count = @db.count('josm_style_rules').condition('k = ?', @key).condition('v = ?', @value).get_first_i
+ @wiki_count = @db.count('wiki.wikipages').condition('key=?', @key).condition('value=?', @value).get_first_i
if @wiki_count == 0
- @wiki_count_key = @db.count('wiki.wikipages').condition('key=?', @key).condition('value IS NULL').get_first_value().to_i
+ @wiki_count_key = @db.count('wiki.wikipages').condition('key=?', @key).condition('value IS NULL').get_first_i
end
- @count_all = @db.select("SELECT count_#{@filter_type} FROM db.tags").condition('key = ? AND value = ?', @key, @value).get_first_value().to_i
+ @count_all = @db.select("SELECT count_#{@filter_type} FROM db.tags").condition('key = ? AND value = ?', @key, @value).get_first_i
@desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang=? AND key=? AND value=?", r18n.locale.code, @key, @value).get_first_value())
@desc = h(@db.select("SELECT description FROM wiki.wikipages WHERE lang='en' AND key=? AND value=?", @key, @value).get_first_value()) if @desc == ''
@@ -51,11 +51,11 @@ class Taginfo < Sinatra::Base
end
@has_rtype_link = false
- if @key == 'type' && @db.count('relation_types').condition('rtype = ?', @value).get_first_value().to_i > 0
+ if @key == 'type' && @db.count('relation_types').condition('rtype = ?', @value).get_first_i > 0
@has_rtype_link = true
end
- @has_map = @db.count('tag_distributions').condition('key = ?', @key).condition('value = ?', @value).get_first_value().to_i > 0
+ @has_map = @db.count('tag_distributions').condition('key = ?', @key).condition('value = ?', @value).get_first_i > 0
@img_width = TaginfoConfig.get('geodistribution.width') * TaginfoConfig.get('geodistribution.scale_image')
@img_height = TaginfoConfig.get('geodistribution.height') * TaginfoConfig.get('geodistribution.scale_image')