]> git.openstreetmap.org Git - rails.git/commitdiff
Allow trace descriptions and tags to be edited.
authorTom Hughes <tom@compton.nu>
Sun, 23 Sep 2007 17:05:31 +0000 (17:05 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 23 Sep 2007 17:05:31 +0000 (17:05 +0000)
app/controllers/trace_controller.rb
app/views/trace/edit.rhtml [new file with mode: 0644]
app/views/trace/view.rhtml
config/routes.rb

index 3b30977552feaf41a81990975558d75bfbc2f0be..3eb7f5c7ece1eb0a247e2748c07117f06d79e409 100644 (file)
@@ -120,6 +120,24 @@ class TraceController < ApplicationController
     render :nothing => true, :status => :not_found
   end
 
     render :nothing => true, :status => :not_found
   end
 
+  def edit
+    @trace = Trace.find(params[:id])
+
+    if @user and @trace.user == @user
+      if params[:trace]
+        @trace.description = params[:trace][:description]
+        @trace.tagstring = params[:trace][:tagstring]
+        if @trace.save
+          redirect_to :action => 'view'
+        end        
+      end
+    else
+      render :nothing, :status => :forbidden
+    end
+  rescue ActiveRecord::RecordNotFound
+    render :nothing => true, :status => :not_found
+  end
+
   def delete
     trace = Trace.find(params[:id])
 
   def delete
     trace = Trace.find(params[:id])
 
diff --git a/app/views/trace/edit.rhtml b/app/views/trace/edit.rhtml
new file mode 100644 (file)
index 0000000..22405c1
--- /dev/null
@@ -0,0 +1,43 @@
+<h2><%= @title %></h2>
+
+<img src="<%= url_for :controller => 'trace', :action => 'picture', :id => @trace.id, :display_name => @trace.user.display_name %>">
+
+<% form_for :trace, @trace do |f| %>
+
+<table border="0">
+  <tr>
+    <td>Filename:</td>
+    <td><%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>)</td>
+  </tr> 
+  <tr>
+    <td>Uploaded at:</td>
+    <td><%= @trace.timestamp %></td>
+  </tr>
+  <% if @trace.inserted? %>
+  <tr>
+    <td>Points:</td>
+    <td><%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %></td></tr>
+  <tr>
+    <td>Start coordinate:</td>
+    <td><div class="geo" style="display: inline"><span class="latitude"><%= @trace.latitude %></span>; <span class="longitude"><%= @trace.longitude %></span></div> (<%=link_to 'map', :controller => 'site', :action => 'index', :lat => @trace.latitude, :lon => @trace.longitude, :zoom => 14 %> / <%=link_to 'edit', :controller => 'site', :action => 'edit', :lat => @trace.latitude, :lon => @trace.longitude, :gpx=> @trace.id, :zoom => 14 %>)</td>
+  </tr>
+  <% end %>
+  <tr>
+    <td>Owner:</td>
+    <td><%= link_to @trace.user.display_name, {:controller => 'user', :action => 'view', :display_name => @trace.user.display_name} %></td>
+  </tr>
+  <tr>
+    <td>Description:</td>
+    <td><%= f.text_field :description %></td>
+  </tr>
+  <tr>
+    <td>Tags:</td>
+    <td><%= f.text_field :tagstring %></td>
+  </tr>
+</table>
+
+<br /><br />
+
+<%= submit_tag 'Save Changes' %>
+
+<% end %>
index 60f71b7c7482eec5b0fb1c8cd2be5e8a7eaf2f9f..a5b0cef099b3636614b7b6c01f52c7d71d9d47c8 100644 (file)
@@ -50,6 +50,9 @@
     <td><%= button_to 'Make this track public permanently', :controller => 'trace', :action => 'make_public', :id => @trace.id %></td>
     <% end %>
     <% if @trace.user.id == @user.id %>
     <td><%= button_to 'Make this track public permanently', :controller => 'trace', :action => 'make_public', :id => @trace.id %></td>
     <% end %>
     <% if @trace.user.id == @user.id %>
+    <td><%= button_to 'Edit this track', :controller => 'trace', :action => 'edit', :id => @trace.id %></td>
+    <% end %>
+    <% if @trace.user.id == @user.id %>
     <td><%= button_to 'Delete this track', :controller => 'trace', :action => 'delete', :id => @trace.id %></td>
     <% end %>
   </tr>
     <td><%= button_to 'Delete this track', :controller => 'trace', :action => 'delete', :id => @trace.id %></td>
     <% end %>
   </tr>
index b9d5d41c9aeefd69a193ee2c4e7a68ad39207049..0cbdd36a47dbab8447472e752008487a08f4aa04 100644 (file)
@@ -75,6 +75,7 @@ ActionController::Routing::Routes.draw do |map|
   map.connect '/traces/mine/tag/:tag', :controller => 'trace', :action => 'mine'
   map.connect '/traces/mine/tag/:tag/page/:page', :controller => 'trace', :action => 'mine'
   map.connect '/trace/create', :controller => 'trace', :action => 'create'
   map.connect '/traces/mine/tag/:tag', :controller => 'trace', :action => 'mine'
   map.connect '/traces/mine/tag/:tag/page/:page', :controller => 'trace', :action => 'mine'
   map.connect '/trace/create', :controller => 'trace', :action => 'create'
+  map.connect '/trace/:id/edit', :controller => 'trace', :action => 'edit'
   map.connect '/trace/:id/delete', :controller => 'trace', :action => 'delete'
   map.connect '/trace/:id/make_public', :controller => 'trace', :action => 'make_public'
   map.connect '/user/:display_name/traces', :controller => 'trace', :action => 'list'
   map.connect '/trace/:id/delete', :controller => 'trace', :action => 'delete'
   map.connect '/trace/:id/make_public', :controller => 'trace', :action => 'make_public'
   map.connect '/user/:display_name/traces', :controller => 'trace', :action => 'list'