summaryrefslogtreecommitdiff
path: root/web/lib
diff options
context:
space:
mode:
authorJochen Topf <jochen@topf.org>2013-01-18 20:08:39 +0100
committerJochen Topf <jochen@topf.org>2013-01-18 20:08:39 +0100
commitab4f955593dfc671af4a4e75791324e0c205d64a (patch)
treea0bc16e857d81b3adab7c70ecad8a050573231a1 /web/lib
parent71e774e39117dc51e27902d64ee8a70341a08ef3 (diff)
downloadtaginfo-ab4f955593dfc671af4a4e75791324e0c205d64a.tar
taginfo-ab4f955593dfc671af4a4e75791324e0c205d64a.tar.gz
Add support for relation type images
Diffstat (limited to 'web/lib')
-rw-r--r--web/lib/ui/keys_tags.rb14
-rw-r--r--web/lib/ui/relation.rb5
-rw-r--r--web/lib/utils.rb14
3 files changed, 19 insertions, 14 deletions
diff --git a/web/lib/ui/keys_tags.rb b/web/lib/ui/keys_tags.rb
index 9d9653f..d944e91 100644
--- a/web/lib/ui/keys_tags.rb
+++ b/web/lib/ui/keys_tags.rb
@@ -1,20 +1,6 @@
# web/lib/ui/keys_tags.rb
class Taginfo < Sinatra::Base
- MAX_IMAGE_WIDTH = 300
-
- def build_image_url(row)
- w = row['width'].to_i
- h = row['height'].to_i
- if w <= MAX_IMAGE_WIDTH
- return row['image_url']
- end
- if w > 0 && h > 0
- return "#{row['thumb_url_prefix']}#{ h <= w ? MAX_IMAGE_WIDTH : (MAX_IMAGE_WIDTH * w / h).to_i }#{ row['thumb_url_suffix'] }"
- end
- return nil
- end
-
get %r{^/keys/(.*)} do |key|
if params[:key].nil?
@key = key
diff --git a/web/lib/ui/relation.rb b/web/lib/ui/relation.rb
index 1e1fe71..5801ae2 100644
--- a/web/lib/ui/relation.rb
+++ b/web/lib/ui/relation.rb
@@ -21,6 +21,11 @@ class Taginfo < Sinatra::Base
@desc = "<span title='#{ t.pages.relation.description_from_wiki }' tipsy='w'>#{ @desc }</span>"
end
+ @db.select("SELECT width, height, image_url, thumb_url_prefix, thumb_url_suffix FROM wiki.relation_pages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang=? AND rtype=? UNION SELECT width, height, image_url, thumb_url_prefix, thumb_url_suffix FROM wiki.relation_pages LEFT OUTER JOIN wiki.wiki_images USING(image) WHERE lang='en' AND rtype=? LIMIT 1", r18n.locale.code, @rtype, @rtype).
+ execute() do |row|
+ @image_url = build_image_url(row)
+ end
+
@count_relation_roles = @db.count('relation_roles').
condition("rtype=?", rtype).
get_first_value().to_i
diff --git a/web/lib/utils.rb b/web/lib/utils.rb
index 875584c..343c6df 100644
--- a/web/lib/utils.rb
+++ b/web/lib/utils.rb
@@ -200,3 +200,17 @@ def no_paging_results(array)
];
end
+MAX_IMAGE_WIDTH = 300
+
+def build_image_url(row)
+ w = row['width'].to_i
+ h = row['height'].to_i
+ if w <= MAX_IMAGE_WIDTH
+ return row['image_url']
+ end
+ if w > 0 && h > 0
+ return "#{row['thumb_url_prefix']}#{ h <= w ? MAX_IMAGE_WIDTH : (MAX_IMAGE_WIDTH * w / h).to_i }#{ row['thumb_url_suffix'] }"
+ end
+ return nil
+end
+