From 4769eec5aab27cdb0ae6ac1b7bb713da720feb93 Mon Sep 17 00:00:00 2001 From: Richard Fairhurst Date: Mon, 28 May 2007 14:54:50 +0000 Subject: [PATCH] TomH's patches --- app/controllers/application.rb | 2 +- app/controllers/diary_entry_controller.rb | 4 ++-- app/controllers/user_controller.rb | 12 ++++++++++-- app/views/layouts/site.rhtml | 4 ++-- app/views/trace/list.rhtml | 2 +- config/routes.rb | 2 ++ lib/osm.rb | 12 +++++++----- 7 files changed, 25 insertions(+), 13 deletions(-) diff --git a/app/controllers/application.rb b/app/controllers/application.rb index 52aeff3cb..328148fe1 100644 --- a/app/controllers/application.rb +++ b/app/controllers/application.rb @@ -7,7 +7,7 @@ class ApplicationController < ActionController::Base end def require_user - redirect_to :controller => 'user', :action => 'login' unless @user + redirect_to :controller => 'user', :action => 'login', :next_controller => controller_name, :next_action => action_name unless @user end def authorize(realm='Web Password', errormessage="Couldn't authenticate you") diff --git a/app/controllers/diary_entry_controller.rb b/app/controllers/diary_entry_controller.rb index afa2722a1..f8e2a5761 100644 --- a/app/controllers/diary_entry_controller.rb +++ b/app/controllers/diary_entry_controller.rb @@ -1,12 +1,12 @@ class DiaryEntryController < ApplicationController layout 'site' - before_filter :authorize_web, :only => [:new] + before_filter :authorize_web before_filter :require_user, :only => [:new] def new if params[:diary_entry] - @entry = DiaryEntry.new(@params[:diary_entry]) + @entry = DiaryEntry.new(params[:diary_entry]) @entry.user = @user if @entry.save redirect_to :controller => 'user', :action => 'diary', :display_name => @user.display_name diff --git a/app/controllers/user_controller.rb b/app/controllers/user_controller.rb index cf1a176f1..fd8fff4dc 100644 --- a/app/controllers/user_controller.rb +++ b/app/controllers/user_controller.rb @@ -97,7 +97,11 @@ class UserController < ApplicationController u.timeout = 1.day.from_now u.save session[:token] = u.token - redirect_to :controller => 'site', :action => 'index' + if params[:next_controller] and params[:next_action] + redirect_to :controller => params[:next_controller], :action => params[:next_action] + else + redirect_to :controller => 'site', :action => 'index' + end return else flash[:notice] = "Couldn't log in with those details" @@ -115,7 +119,11 @@ class UserController < ApplicationController end end session[:token] = nil - redirect_to :controller => 'site', :action => 'index' + if params[:next_controller] and params[:next_action] + redirect_to :controller => params[:next_controller], :action => params[:next_action] + else + redirect_to :controller => 'site', :action => 'index' + end end def confirm diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index 8d2ac722e..f42048b88 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -26,9 +26,9 @@ <% if @user %> Welcome, <%= link_to @user.display_name, {:controller => 'user', :action => 'view', :display_name => @user.display_name}, {:id => 'loginanchor'}%> | - <%= link_to 'logout', {:controller => 'user', :action => 'logout'}, {:id => 'loginanchor'}%> + <%= link_to 'logout', {:controller => 'user', :action => 'logout', :next_controller => @controller.controller_name, :next_action => @controller.action_name}, {:id => 'loginanchor'}%> <% else %> - <%= link_to 'log in', {:controller => 'user', :action => 'login'}, {:id => 'loginanchor'}%> | + <%= link_to 'log in', {:controller => 'user', :action => 'login', :next_controller => @controller.controller_name, :next_action => @controller.action_name}, {:id => 'loginanchor'}%> | <%= link_to 'sign up', {:controller => 'user', :action => 'new'}, {:id => 'registeranchor'} %> <% end %> diff --git a/app/views/trace/list.rhtml b/app/views/trace/list.rhtml index 4ca59dabe..48d5e21c7 100644 --- a/app/views/trace/list.rhtml +++ b/app/views/trace/list.rhtml @@ -8,7 +8,7 @@ <% if @user %> <%= link_to 'See just your traces', {:controller => 'trace', :action => 'mine'} %> <% else %> - <%= link_to 'login', {:controller => 'user', :action => 'login'} %> to see just your traces + <%= link_to 'login', {:controller => 'user', :action => 'login', :next_controller => 'traces', :next_action => 'mine'} %> to see just your traces <% end %> <% if @tag %> | <%= link_to 'See all traces', {:controller => 'trace', :action => 'list'} %> diff --git a/config/routes.rb b/config/routes.rb index 2420de1ca..8f1dc9230 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -45,6 +45,8 @@ ActionController::Routing::Routes.draw do |map| map.connect '/user/confirm', :controller => 'user', :action => 'confirm' map.connect '/user/go_public', :controller => 'user', :action => 'go_public' map.connect '/user/reset_password', :controller => 'user', :action => 'reset_password' + map.connect '/user/login/:next_controller/:next_action', :controller => 'user', :action => 'login' + map.connect '/user/logout/:next_controller/:next_action', :controller => 'user', :action => 'logout' map.connect '/index.html', :controller => 'site', :action => 'index' map.connect '/edit.html', :controller => 'site', :action => 'edit' map.connect '/search.html', :controller => 'way_tag', :action => 'search' diff --git a/lib/osm.rb b/lib/osm.rb index 9e2ab04ad..6c3cf07c4 100644 --- a/lib/osm.rb +++ b/lib/osm.rb @@ -68,14 +68,12 @@ module OSM attr_reader :tracksegs def initialize(filename) - @filename = filename @possible_points = 0 @actual_points = 0 @tracksegs = 0 - end + @points = [] - def points - file = File.new(@filename) + file = File.new(filename) parser = REXML::Parsers::SAX2Parser.new( file ) lat = -1 @@ -114,7 +112,7 @@ module OSM ele = '0' unless gotele if lat < 90 && lat > -90 && lon > -180 && lon < 180 @actual_points += 1 - yield Hash['latitude' => lat,'longitude' => lon,'timestamp' => date,'altitude' => ele,'segment' => @tracksegs] + @points.push(Hash['latitude' => lat,'longitude' => lon,'timestamp' => date,'altitude' => ele,'segment' => @tracksegs]) end end gotlatlon = false @@ -124,6 +122,10 @@ module OSM parser.parse end + def points + @points.each { |p| yield p } + end + def get_picture(min_lat, min_lon, max_lat, max_lon, num_points) #puts "getting picfor bbox #{min_lat},#{min_lon} - #{max_lat},#{max_lon}" frames = 10 -- 2.43.2