Skip to content

Commit

Permalink
Merge branch 'master' into openstreetbugs
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Jul 28, 2010
2 parents 02ad2f5 + 7298467 commit 52395b3
Show file tree
Hide file tree
Showing 63 changed files with 288 additions and 225 deletions.
27 changes: 14 additions & 13 deletions app/controllers/application_controller.rb
Expand Up @@ -249,18 +249,18 @@ def self.caches_action(*actions)
options = actions.extract_options!
cache_path = options[:cache_path] || Hash.new

options[:cache_path] = Proc.new do |controller|
user = controller.instance_variable_get("@user")

case
when user.nil? then user = :none
when user.display_name == controller.params[:display_name] then user = :self
when user.administrator? then user = :administrator
when user.moderator? then user = :moderator
else user = :other
end
options[:unless] = case options[:unless]
when NilClass then Array.new
when Array then options[:unless]
else unlessp = [ options[:unless] ]
end

options[:unless].push(Proc.new do |controller|
controller.params.include?(:page)
end)

cache_path.merge(controller.params).merge(:locale => I18n.locale, :user => user)
options[:cache_path] = Proc.new do |controller|
cache_path.merge(controller.params).merge(:locale => I18n.locale)
end

actions.push(options)
Expand All @@ -271,8 +271,9 @@ def self.caches_action(*actions)
##
# extend expire_action to expire all variants
def expire_action(options = {})
path = ActionCachePath.path_for(self, options, false).gsub('?', '.').gsub(':', '.')
expire_fragment(Regexp.new(Regexp.escape(path) + "\\..*"))
I18n.available_locales.each do |locale|
super options.merge(:locale => locale)
end
end

##
Expand Down
13 changes: 8 additions & 5 deletions app/controllers/trace_controller.rb
Expand Up @@ -15,18 +15,17 @@ class TraceController < ApplicationController
before_filter :offline_redirect, :only => [:create, :edit, :delete, :data, :api_data, :api_create]
around_filter :api_call_handle_error, :only => [:api_details, :api_data, :api_create]

caches_action :list, :unless => :logged_in?, :layout => false
caches_action :view, :layout => false
caches_action :list, :view, :layout => false
caches_action :georss, :layout => true
cache_sweeper :trace_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline
cache_sweeper :tracetag_sweeper, :only => [:create, :edit, :delete, :api_create], :unless => OSM_STATUS == :database_offline

# Counts and selects pages of GPX traces for various criteria (by user, tags, public etc.).
# target_user - if set, specifies the user to fetch traces for. if not set will fetch all traces
def list(target_user = nil, action = "list")
def list
# from display name, pick up user id if one user's traces only
display_name = params[:display_name]
if target_user.nil? and !display_name.blank?
if !display_name.blank?
target_user = User.find(:first, :conditions => { :status => ["active", "confirmed"], :display_name => display_name })
if target_user.nil?
@title = t'trace.no_such_user.title'
Expand Down Expand Up @@ -103,7 +102,7 @@ def list(target_user = nil, action = "list")
end

# final helper vars for view
@action = action
@target_user = target_user
@display_name = target_user.display_name if target_user
@all_tags = tagset.values
@trace = Trace.new(:visibility => default_visibility) if @user
Expand Down Expand Up @@ -143,6 +142,10 @@ def create
logger.info("id is #{@trace.id}")
flash[:notice] = t 'trace.create.trace_uploaded'

if @user.traces.count(:conditions => { :inserted => false }) > 4
flash[:warning] = t 'trace.trace_header.traces_waiting', :count => @user.traces.count(:conditions => { :inserted => false })
end

redirect_to :action => 'mine'
end
else
Expand Down
43 changes: 41 additions & 2 deletions app/helpers/application_helper.rb
Expand Up @@ -40,14 +40,53 @@ def javascript_strings
return js
end

def style_rules
css = ""

css << ".hidden { display: none }";
css << ".hide_unless_logged_in { display: none }" unless @user;
css << ".hide_if_logged_in { display: none }" if @user;
css << ".hide_if_user_#{@user.id} { display: none }" if @user;
css << ".show_if_user_#{@user.id} { display: inline }" if @user;
css << ".hide_unless_administrator { display: none }" unless @user and @user.administrator?;

return content_tag(:style, css)
end

def if_logged_in(tag = :div, &block)
concat(content_tag(tag, capture(&block), :class => "hide_unless_logged_in"))
end

def if_not_logged_in(tag = :div, &block)
concat(content_tag(tag, capture(&block), :class => "hide_if_logged_in"))
end

def if_user(user, tag = :div, &block)
if user
concat(content_tag(tag, capture(&block), :class => "hidden show_if_user_#{user.id}"))
end
end

def unless_user(user, tag = :div, &block)
if user
concat(content_tag(tag, capture(&block), :class => "hide_if_user_#{user.id}"))
else
concat(content_tag(tag, capture(&block)))
end
end

def if_administrator(tag = :div, &block)
concat(content_tag(tag, capture(&block), :class => "hide_unless_administrator"))
end

def describe_location(lat, lon, zoom = nil, language = nil)
zoom = zoom || 14
language = language || request.user_preferred_languages.join(',')
url = "http://nominatim.openstreetmap.org/reverse?lat=#{lat}&lon=#{lon}&zoom=#{zoom}&accept-language=#{language}"

begin
Timeout::timeout(4) do
response = REXML::Document.new(Net::HTTP.get(URI.parse(url)))
response = Timeout::timeout(4) do
REXML::Document.new(Net::HTTP.get(URI.parse(url)))
end
rescue Exception
response = nil
Expand Down
2 changes: 1 addition & 1 deletion app/models/notifier.rb
Expand Up @@ -48,7 +48,7 @@ def gpx_failure(trace, error)
def message_notification(message)
common_headers message.recipient
from_header message.sender.display_name, "m", message.id, message.digest
subject message.title
subject I18n.t('notifier.message_notification.subject_header', :subject => message.title, :locale => locale)
body :to_user => message.recipient.display_name,
:from_user => message.sender.display_name,
:body => message.body,
Expand Down
2 changes: 2 additions & 0 deletions app/models/user.rb
Expand Up @@ -28,6 +28,8 @@ class User < ActiveRecord::Base
validates_email_format_of :email
validates_email_format_of :new_email, :allow_blank => true
validates_format_of :display_name, :with => /^[^\/;.,?]*$/
validates_format_of :display_name, :with => /^\S/, :message => "has leading whitespace"
validates_format_of :display_name, :with => /\S$/, :message => "has trailing whitespace"
validates_numericality_of :home_lat, :allow_nil => true
validates_numericality_of :home_lon, :allow_nil => true
validates_numericality_of :home_zoom, :only_integer => true, :allow_nil => true
Expand Down
4 changes: 2 additions & 2 deletions app/views/diary_entry/_diary_comment.html.erb
@@ -1,7 +1,7 @@
<%= user_thumbnail diary_comment.user, :style => "float: right" %>
<h4 id="comment<%= diary_comment.id %>"><%= t('diary_entry.diary_comment.comment_from', :link_user => (link_to h(diary_comment.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_comment.user.display_name), :comment_created_at => l(diary_comment.created_at, :format => :friendly)) %></h4>
<%= htmlize(diary_comment.body) %>
<% if @user && @user.administrator? %>
<%= link_to t('diary_entry.diary_comment.hide_link'), {:action => 'hidecomment', :display_name => @user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id}, {:confirm => t('diary_entry.diary_comment.confirm')} %>
<% if_administrator(:span) do %>
<%= link_to t('diary_entry.diary_comment.hide_link'), {:action => 'hidecomment', :display_name => diary_comment.diary_entry.user.display_name, :id => diary_comment.diary_entry.id, :comment => diary_comment.id}, {:confirm => t('diary_entry.diary_comment.confirm')} %>
<% end %>
<hr />
31 changes: 18 additions & 13 deletions app/views/diary_entry/_diary_entry.html.erb
@@ -1,25 +1,30 @@
<b><%= link_to h(diary_entry.title), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id %></b><br />

<div xml:lang="<%= diary_entry.language_code %>" lang="<%= diary_entry.language_code %>">
<%= htmlize(diary_entry.body) %>
<%= htmlize(diary_entry.body) %>
</div>

<% if diary_entry.latitude and diary_entry.longitude %>
<%= render :partial => "location", :object => diary_entry %>
<br />
<%= render :partial => "location", :object => diary_entry %>
<br />
<% end %>
<%= t 'diary_entry.diary_entry.posted_by', :link_user => (link_to h(diary_entry.user.display_name), :controller => 'user', :action => 'view', :display_name => diary_entry.user.display_name), :created => l(diary_entry.created_at, :format => :friendly), :language_link => (link_to h(diary_entry.language.name), :controller => 'diary_entry', :action => 'list', :language => diary_entry.language_code) %>
<% if params[:action] == 'list' %>
<br />
<%= link_to t('diary_entry.diary_entry.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %>
|
<%= link_to t('diary_entry.diary_entry.reply_link'), :controller => 'message', :action => 'new', :display_name => diary_entry.user.display_name, :title => "Re: #{diary_entry.title}" %>
|
<%= link_to t('diary_entry.diary_entry.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %>
<br />
<%= link_to t('diary_entry.diary_entry.comment_link'), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'newcomment' %>
|
<%= link_to t('diary_entry.diary_entry.reply_link'), :controller => 'message', :action => 'new', :display_name => diary_entry.user.display_name, :title => "Re: #{diary_entry.title}" %>
|
<%= link_to t('diary_entry.diary_entry.comment_count', :count => diary_entry.visible_comments.count), :action => 'view', :display_name => diary_entry.user.display_name, :id => diary_entry.id, :anchor => 'comments' %>
<% end %>
<% if @user == diary_entry.user %>
| <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => @user.display_name, :id => diary_entry.id %>
<% if_user(diary_entry.user, :span) do %>
| <%= link_to t('diary_entry.diary_entry.edit_link'), :action => 'edit', :display_name => diary_entry.user.display_name, :id => diary_entry.id %>
<% end %>
<% if @user && @user.administrator? %>
| <%= link_to t('diary_entry.diary_entry.hide_link'), {:action => 'hide', :display_name => @user.display_name, :id => diary_entry.id}, {:confirm => t('diary_entry.diary_entry.confirm')} %>
<% if_administrator(:span) do %>
| <%= link_to t('diary_entry.diary_entry.hide_link'), {:action => 'hide', :display_name => diary_entry.user.display_name, :id => diary_entry.id}, {:confirm => t('diary_entry.diary_entry.confirm')} %>
<% end %>

<br />
<hr />
4 changes: 2 additions & 2 deletions app/views/diary_entry/list.html.erb
Expand Up @@ -5,11 +5,11 @@
<h2><%= h(@title) %></h2>

<% if @this_user %>
<% if @user == @this_user %>
<% if_user(@this_user) do %>
<%= link_to image_tag("new.png", :border=>0) + t('diary_entry.list.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('diary_entry.list.new_title')} %>
<% end %>
<% else %>
<% if @user %>
<% if_logged_in do %>
<%= link_to image_tag("new.png", :border=>0) + t('diary_entry.list.new'), {:controller => 'diary_entry', :action => 'new'}, {:title => t('diary_entry.list.new_title')} %>
<% end %>
<% end %>
Expand Down
24 changes: 12 additions & 12 deletions app/views/diary_entry/view.html.erb
Expand Up @@ -8,19 +8,19 @@

<%= render :partial => 'diary_comment', :collection => @entry.visible_comments %>
<% if @user %>

<h4 id="newcomment"><%= t 'diary_entry.view.leave_a_comment' %></h4>
<%= error_messages_for 'diary_comment' %>
<% form_for :diary_comment, @diary_comment, :url => { :action => 'comment' } do |f| %>
<%= f.text_area :body, :cols => 80, :rows => 5 %>
<br />
<br />
<%= submit_tag t('diary_entry.view.save_button') %>
<% end %>
<% if_logged_in(:div) do %>
<h4 id="newcomment"><%= t 'diary_entry.view.leave_a_comment' %></h4>

<% else %>
<%= error_messages_for 'diary_comment' %>
<h4 id="newcomment"><%= t("diary_entry.view.login_to_leave_a_comment", :login_link => link_to(t("diary_entry.view.login"), :controller => 'user', :action => 'login', :referer => request.request_uri)) %></h4>
<% form_for :diary_comment, @diary_comment, :url => { :action => 'comment' } do |f| %>
<%= f.text_area :body, :cols => 80, :rows => 5 %>
<br />
<br />
<%= submit_tag t('diary_entry.view.save_button') %>
<% end %>
<% end %>
<% if_not_logged_in(:div) do %>
<h4 id="newcomment"><%= t("diary_entry.view.login_to_leave_a_comment", :login_link => link_to(t("diary_entry.view.login"), :controller => 'user', :action => 'login', :referer => request.request_uri)) %></h4>
<% end %>
5 changes: 1 addition & 4 deletions app/views/layouts/site.html.erb
Expand Up @@ -13,6 +13,7 @@
<%= stylesheet_link_tag 'print', :media => "print" %>
<%= tag("link", { :rel => "search", :type => "application/opensearchdescription+xml", :title => "OpenStreetMap Search", :href => "/opensearch/osm.xml" }) %>
<%= tag("meta", { :name => "description", :content => "OpenStreetMap is the free wiki world map." }) %>
<%= style_rules %>
<%= yield :head %>
<title><%= t 'layouts.project_name.title' %><%= ' | '+ h(@title) if @title %></title>
</head>
Expand Down Expand Up @@ -123,10 +124,6 @@
<%= yield :left_menu %>
</div>

<div id="sotm" class="notice">
<%= link_to image_tag("sotm.png", :alt => t('layouts.sotm2010'), :title => t('layouts.sotm2010'), :border => "0"), "http://www.stateofthemap.org/register/" %>
</div>

<%= yield :optionals %>

<center>
Expand Down
13 changes: 0 additions & 13 deletions app/views/trace/_trace_form.html.erb

This file was deleted.

18 changes: 0 additions & 18 deletions app/views/trace/_trace_header.html.erb

This file was deleted.

13 changes: 0 additions & 13 deletions app/views/trace/_trace_list.html.erb

This file was deleted.

10 changes: 9 additions & 1 deletion app/views/trace/create.html.erb
Expand Up @@ -2,4 +2,12 @@

<%= error_messages_for 'trace' %>
<%= render :partial => 'trace_form' %>
<% form_for :trace, @trace, :url => { :action => "create" }, :html => { :multipart => true } do |f| %>
<table>
<tr><td align="right"><%= t'trace.trace_form.upload_gpx' %></td><td><%= f.file_field :gpx_file, :size => 50, :maxlength => 255 %></td></tr>
<tr><td align="right"><%= t'trace.trace_form.description' %></td><td><%= f.text_field :description, :size => 50, :maxlength => 255 %></td></tr>
<tr><td align="right"><%= t'trace.trace_form.tags' %></td><td><%= f.text_field :tagstring, :size => 50, :maxlength => 255 %> (<%= t'trace.trace_form.tags_help' %>)</td></tr>
<tr><td align="right"><%= t'trace.trace_form.visibility' %></td><td><%= f.select :visibility, [[t('trace.visibility.private'),"private"],[t('trace.visibility.public'),"public"],[t('trace.visibility.trackable'),"trackable"],[t('trace.visibility.identifiable'),"identifiable"]] %> <span class="minorNote">(<a href="<%= t'trace.trace_form.visibility_help_url' %>"><%= t'trace.trace_form.visibility_help' %></a>)</span></td></tr>
<tr><td></td><td><%= submit_tag t('trace.trace_form.upload_button') %> | <a href="<%= t'trace.trace_form.help_url' %>"><%= t'trace.trace_form.help' %></a></td></tr>
</table>
<% end %>
38 changes: 34 additions & 4 deletions app/views/trace/list.html.erb
@@ -1,5 +1,35 @@
<%= render :partial => 'trace_header' %>
<% if @user and @user.display_name == @display_name %>
<%= render :partial => 'trace_form' %>
<h1><%= h(@title) %></h1>

<% content_for :head do %>
<%= auto_discovery_link_tag :atom, :action => 'georss', :display_name => @display_name, :tag => @tag %>
<% end %>
<%= render :partial => 'trace_list' %>

<p>
<%= rss_link_to :action => 'georss', :display_name => @display_name, :tag => @tag %>
<% unless_user(@target_user, :span) do %>
| <%= link_to t('trace.trace_header.your_traces'), :action => 'mine' %>
<% end %>
| <%= link_to t('trace.trace_header.upload_trace'), :action => 'create' %>
<% if @tag %>
<% if @display_name %>
| <%= link_to t('trace.trace_header.see_all_traces'), :controller => 'trace', :action => 'list' %>
<% end %>
<% if_user(@target_user, :span) do %>
| <%= link_to t('trace.trace_header.see_your_traces'), :controller => 'trace', :action => 'mine' %>
<% end %>
<% end %>
</p>

<%= render :partial => 'trace_paging_nav' %>

<table id="trace_list" cellpadding="3">
<tr>
<th></th>
<th></th>
</tr>
<%= render :partial => 'trace', :collection => @traces unless @traces.nil? %>
</table>

<%= render :partial => 'trace_paging_nav' %>
<%= render :partial => 'trace_optionals' %>
18 changes: 8 additions & 10 deletions app/views/trace/view.html.erb
Expand Up @@ -52,13 +52,11 @@

<br /><br />

<table>
<tr>
<% if @trace.user == @user %>
<td><%= button_to t('trace.view.edit_track'), :controller => 'trace', :action => 'edit', :id => @trace.id %></td>
<% end %>
<% if @trace.user == @user %>
<td><%= button_to t('trace.view.delete_track'), :controller => 'trace', :action => 'delete', :id => @trace.id %></td>
<% end %>
</tr>
</table>
<% if_user(@trace.user) do %>
<table>
<tr>
<td><%= button_to t('trace.view.edit_track'), :controller => 'trace', :action => 'edit', :id => @trace.id %></td>
<td><%= button_to t('trace.view.delete_track'), :controller => 'trace', :action => 'delete', :id => @trace.id %></td>
</tr>
</table>
<% end %>

0 comments on commit 52395b3

Please sign in to comment.