Skip to content

Commit

Permalink
Get project icons from taginfo database
Browse files Browse the repository at this point in the history
This way we don't get a "mixed content" warning from the browser.
  • Loading branch information
joto committed Sep 14, 2020
1 parent b10074c commit b1ecbad
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 16 deletions.
8 changes: 6 additions & 2 deletions web/lib/api/v4/project.rb
Expand Up @@ -70,8 +70,12 @@ class Taginfo < Sinatra::Base
res = @db.select('SELECT icon_type, icon FROM projects.projects').
condition('id = ?', project_id).
execute()[0]
content_type res['icon_type']
res['icon']
if res['icon']
content_type res['icon_type']
res['icon']
else
redirect('/img/generic_project_icon.png');
end
end

end
9 changes: 3 additions & 6 deletions web/public/js/taginfo.js
Expand Up @@ -223,14 +223,11 @@ function link_to_rtype(rtype, attr) {
);
}

function link_to_project(id, name, icon_url, attr) {
if (icon_url === null) {
icon_url = '/img/generic_project_icon.png';
}
function link_to_project(id, name) {
icon_url = '/api/4/project/icon?project=' + id;
return img({ src: icon_url, width: 16, height: 16, alt: '' }) + ' ' + link(
url_for_project(id),
html_escape(name),
attr
html_escape(name)
);
}

Expand Down
11 changes: 6 additions & 5 deletions web/views/project.erb
Expand Up @@ -11,7 +11,12 @@
</ul>
<div id="overview">
<table class="desc">
<tr><th><%= h(t.pages.project.overview.project_name) %>:</th><td><span id="icon_url"></span> <%= h(@project['name']) %></td></tr>
<tr><th><%= h(t.pages.project.overview.project_name) %>:</th><td>
<% if @project['icon'] %>
<img src="/api/4/project/icon?project=<%= h(@project['id']) %>" width="16" height="16" alt=""/>
<% end %>
<%= h(@project['name']) %>
</td></tr>
<tr><th><%= h(t.pages.project.overview.project_url) %>:</th><td id="project_url"></td></tr>
<tr><th><%= h(t.pages.project.overview.description) %>:</th><td><%= h(@project['description']) %></td></tr>
<% if @project['doc_url'] %>
Expand All @@ -37,15 +42,11 @@ function page_init2() {
var project = #{ @project_id.to_json },
project_url = #{ @project['project_url'].to_json },
json_url = #{ @project['json_url'].to_json },
icon_url = #{ @project['icon_url'].to_json },
doc_url = #{ @project['doc_url'].to_json };
if (project_url) {
jQuery('#project_url').html(link_to_url_nofollow(project_url));
}
if (icon_url) {
jQuery('#icon_url').html(img({ src: icon_url, width: 16, height: 16, alt: ''}));
}
if (json_url) {
jQuery('#json_url').html(link_to_url_nofollow(json_url));
}
Expand Down
2 changes: 1 addition & 1 deletion web/viewsjs/key.js.erb
Expand Up @@ -160,7 +160,7 @@ var create_flexigrid_for = {
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),
link_to_project(row.project_id, row.project_name),
row.value === null ? (link_to_key(row.key) + '=*') : link_to_tag(row.key, row.value),
fmt_type_icon('node', row.on_node) +
fmt_type_icon('way', row.on_way) +
Expand Down
2 changes: 1 addition & 1 deletion web/viewsjs/projects.js.erb
Expand Up @@ -16,7 +16,7 @@ var create_flexigrid_for = {
preProcess: function(data) {
data.rows = jQuery.map(data.data, function(row, i) {
return { 'cell': [
link_to_project(row.id, row.name, row.icon_url),
link_to_project(row.id, row.name),
html_escape(row.unique_keys),
html_escape(row.unique_tags),
html_escape(row.description)
Expand Down
2 changes: 1 addition & 1 deletion web/viewsjs/tag.js.erb
Expand Up @@ -115,7 +115,7 @@ var create_flexigrid_for = {
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),
link_to_project(row.project_id, row.project_name),
row.value === null ? (link_to_key(row.key) + '=*') : link_to_tag(row.key, row.value),
fmt_type_icon('node', row.on_node) +
fmt_type_icon('way', row.on_way) +
Expand Down

0 comments on commit b1ecbad

Please sign in to comment.