From: Steve Coast Date: Mon, 27 Nov 2006 19:52:18 +0000 (+0000) Subject: GPX trace rails stuff X-Git-Tag: live~8562 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/fb1467a94487cfdfcb19e4f88e05be7aa88096f0 GPX trace rails stuff --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 7420ea52d..1c1b968d6 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -1,2 +1,24 @@ class TraceController < ApplicationController + before_filter :authorize_web + layout 'site' + + def list + @traces = Trace.find(:all) + end + + def create + @params['trace']['name'] = @params['trace']['gpx_file'].original_filename.gsub(/[^a-zA-Z0-9.]/, '_') # This makes sure filenames are sane + @params['trace']['data'] = @params['trace']['gpx_file'].read + @params['trace']['mime_type'] = @params['trace']['gpx_file'].content_type.chomp + @params['trace'].delete('gpx_file') # let's remove the field from the hash, because there's no such field in the DB anyway. + @trace = Trace.new(@params['trace']) + @trace.inserted = false + @trace.user_id = @user.id + @trace.timestamp = Time.now + if @trace.save + flash[:notice] = "Your GPX file has been uploaded and is awaiting insertion in to the database. This will usually happen within half an hour, and an email will be sent to you on completion." + end + + redirect_to :action => 'mine' + end end diff --git a/app/models/trace.rb b/app/models/trace.rb index a7e19bef8..0c3caa90c 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -1,4 +1,10 @@ class Trace < ActiveRecord::Base set_table_name 'gpx_files' - has_many :trace_points, :foreign_key => 'gpx_id' + + has_many :old_nodes, :foreign_key => :id + belongs_to :user + + def tags=(bleh) + + end end diff --git a/app/views/layouts/site.rhtml b/app/views/layouts/site.rhtml index 70752f5e1..e8e825153 100644 --- a/app/views/layouts/site.rhtml +++ b/app/views/layouts/site.rhtml @@ -35,11 +35,11 @@ <% if @user %>
  • <%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps' } %>
  • <%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps' } %>
  • -
  • <%= link_to 'GPS traces', {:controller => 'trace', :action => 'index'}, {:id => 'traceanchor', :title => 'manage traces' } %>
  • +
  • <%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces' } %>
  • <% else %>
  • View
  • Edit
  • -
  • GPS traces
  • +
  • <%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces'} %>
  • <% end %> diff --git a/app/views/site/index.rhtml b/app/views/site/index.rhtml index aec6c10fe..d6b18346a 100644 --- a/app/views/site/index.rhtml +++ b/app/views/site/index.rhtml @@ -63,9 +63,6 @@ - - - <% unless @user %>
    diff --git a/app/views/trace/_trace.rhtml b/app/views/trace/_trace.rhtml new file mode 100644 index 000000000..3149e4c0a --- /dev/null +++ b/app/views/trace/_trace.rhtml @@ -0,0 +1 @@ +bleh diff --git a/app/views/trace/list.rhtml b/app/views/trace/list.rhtml new file mode 100644 index 000000000..ce2e76349 --- /dev/null +++ b/app/views/trace/list.rhtml @@ -0,0 +1,6 @@ +

    Public GPS Traces

    +<% if @user %> + <%= link_to 'See just your traces', {:controller => 'trace', :action => 'mine'} %> +<% end %> + +<%= render :partial => 'trace', :collection => @traces %> diff --git a/app/views/trace/mine.rhtml b/app/views/trace/mine.rhtml new file mode 100644 index 000000000..41aa0bc1e --- /dev/null +++ b/app/views/trace/mine.rhtml @@ -0,0 +1,22 @@ +

    Your GPS Traces

    + +<%= link_to 'see all traces', {:controller => 'trace', :action => 'list'} %>

    + +<% if @user %> +<%= start_form_tag({:action => 'create'}, :multipart => true) %> + +
    + + + + + +
    upload GPX file:<%= file_field('trace', 'gpx_file', {:size => 50, :maxlength => 255}) %>
    description:<%= text_field('trace', 'description', {:size => 50, :maxlength => 255}) %>
    tags:<%= text_field('trace', 'tags', {:size => 50, :maxlength => 255}) %>
    public?<%= check_box('trace', 'public', {:checked => 'checked'}) %>
    +<%= submit_tag 'Upload' %> | help +
    + +
    + +<%= end_form_tag %> +<% end %> + diff --git a/config/routes.rb b/config/routes.rb index 3dad762ff..620509473 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -25,6 +25,10 @@ ActionController::Routing::Routes.draw do |map| map.connect '/logout.html', :controller => 'user', :action => 'logout' map.connect '/create-account.html', :controller => 'user', :action => 'new' map.connect '/forgot-password.html', :controller => 'user', :action => 'lost_password' + + map.connect '/traces', :controller => 'trace', :action => 'list' + map.connect '/traces/mine', :controller => 'trace', :action => 'users' + map.connect '/traces/user/:user_login/:id', :controller => 'trace', :action => 'user' map.connect ':controller/:action/:id' end diff --git a/db/migrate.sql b/db/migrate.sql index b6bc48135..4638ba5a1 100644 --- a/db/migrate.sql +++ b/db/migrate.sql @@ -15,3 +15,9 @@ alter table current_ways modify id bigint(64) not null auto_increment, add prima alter table current_way_tags change k k varchar(255) not null default ''; alter table current_way_tags change v v varchar(255) not null default ''; +alter table gpx_files add column data longblob; +alter table gpx_files add column mime_type varchar(255); +alter table gpx_files change private public boolean default 1 not null; +update gpx_files set public = !public; + +