]> git.openstreetmap.org Git - rails.git/commitdiff
GPX trace rails stuff
authorSteve Coast <steve@asklater.com>
Mon, 27 Nov 2006 19:52:18 +0000 (19:52 +0000)
committerSteve Coast <steve@asklater.com>
Mon, 27 Nov 2006 19:52:18 +0000 (19:52 +0000)
app/controllers/trace_controller.rb
app/models/trace.rb
app/views/layouts/site.rhtml
app/views/site/index.rhtml
app/views/trace/_trace.rhtml [new file with mode: 0644]
app/views/trace/list.rhtml [new file with mode: 0644]
app/views/trace/mine.rhtml [new file with mode: 0644]
config/routes.rb
db/migrate.sql

index 7420ea52d42c8c93799b94a64d188e12a2994d46..1c1b968d6fd6f8bc140f98dc4883861a27ce0dc8 100644 (file)
@@ -1,2 +1,24 @@
 class TraceController < ApplicationController
 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
 end
index a7e19bef860f98ad227f0edddba57ec2316eba55..0c3caa90c8e7bc8b08bc76dbdfda3ea92e9dc254 100644 (file)
@@ -1,4 +1,10 @@
 class Trace < ActiveRecord::Base
   set_table_name 'gpx_files'
 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
 end
index 70752f5e1f35323f31e69ab18837396ab17c63f8..e8e825153d4f083c57b6267bd913fb0cc699cfc5 100644 (file)
       <% if @user %>
         <li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps' } %></li>
         <li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps' } %></li>
       <% if @user %>
         <li><%= link_to 'View', {:controller => 'site', :action => 'index'}, {:id => 'viewanchor', :title => 'view maps' } %></li>
         <li><%= link_to 'Edit', {:controller => 'site', :action => 'edit'}, {:id => 'editanchor', :title => 'edit maps' } %></li>
-        <li><%= link_to 'GPS traces', {:controller => 'trace', :action => 'index'}, {:id => 'traceanchor', :title => 'manage traces' } %></li>
+        <li><%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces' } %></li>
       <% else %>
         <li><a id="viewanchor" href="/index.html" title="view maps">View</a></li>
         <li><a style="font-style:italic" href="/login.html" title="edit maps">Edit</a></li>
       <% else %>
         <li><a id="viewanchor" href="/index.html" title="view maps">View</a></li>
         <li><a style="font-style:italic" href="/login.html" title="edit maps">Edit</a></li>
-        <li><a href="/traces" title="manage traces">GPS traces</a></li>
+        <li><%= link_to 'GPS traces', {:controller => 'trace', :action => 'list'}, {:id => 'traceanchor', :title => 'manage traces'} %></li>
       <% end %>
     </ul>
   </div>
       <% end %>
     </ul>
   </div>
index aec6c10fe8dbd85a253c87f2dc39d588811f3b8d..d6b18346a261a70cf32c5837326b8c8954a5b73f 100644 (file)
@@ -63,9 +63,6 @@
     </script>
       
       </head>
     </script>
       
       </head>
-
-
 
   <% unless @user %>
   <div id="gads">
 
   <% unless @user %>
   <div id="gads">
diff --git a/app/views/trace/_trace.rhtml b/app/views/trace/_trace.rhtml
new file mode 100644 (file)
index 0000000..3149e4c
--- /dev/null
@@ -0,0 +1 @@
+bleh
diff --git a/app/views/trace/list.rhtml b/app/views/trace/list.rhtml
new file mode 100644 (file)
index 0000000..ce2e763
--- /dev/null
@@ -0,0 +1,6 @@
+<h1>Public GPS Traces</h1>
+<% 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 (file)
index 0000000..41aa0bc
--- /dev/null
@@ -0,0 +1,22 @@
+<h1>Your GPS Traces</h1>
+
+<%= link_to 'see all traces', {:controller => 'trace', :action => 'list'} %><br /><br />
+
+<% if @user %>
+<%= start_form_tag({:action => 'create'}, :multipart => true) %>
+<table>
+<table>
+<tr><td align="right">upload GPX file:</td><td><%= file_field('trace', 'gpx_file', {:size => 50, :maxlength => 255}) %></td></tr>
+<tr><td align="right">description:</td><td><%= text_field('trace', 'description', {:size => 50, :maxlength => 255}) %></td></tr>
+<tr><td align="right">tags:</td><td><%= text_field('trace', 'tags', {:size => 50, :maxlength => 255}) %></td></tr>
+<tr><td align="right">public?</td><td><%= check_box('trace', 'public', {:checked => 'checked'}) %></td></tr>
+<tr><td></td><td>
+<%= submit_tag 'Upload' %> | <a href="http://wiki.openstreetmap.org/index.php/Upload">help</a>
+</td></tr>
+</table>
+
+<br>
+
+<%= end_form_tag %> 
+<% end %>
+
index 3dad762ffa86b129caf22eae4b161810fb61ac28..6205094736cce633b7e57f8073bd73d674257a82 100644 (file)
@@ -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 '/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
 
   map.connect ':controller/:action/:id'
 end
index b6bc48135f4c95249fa19c7760f2ecc84e824a75..4638ba5a11b0aca294cbfc0b62678b3437b8e072 100644 (file)
@@ -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 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;
+
+