diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb
index 3b3097755..3eb7f5c7e 100644
--- a/app/controllers/trace_controller.rb
+++ b/app/controllers/trace_controller.rb
@@ -120,6 +120,24 @@ class TraceController < ApplicationController
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])
diff --git a/app/helpers/trace_helper.rb b/app/helpers/trace_helper.rb
index 1611b79ad..a0c3f56c9 100644
--- a/app/helpers/trace_helper.rb
+++ b/app/helpers/trace_helper.rb
@@ -1,9 +1,9 @@
module TraceHelper
def link_to_tag(tag)
if @action == "mine"
- return link_to tag, :tag => tag
+ return link_to(tag, :tag => tag)
else
- return link_to tag, :tag => tag, :display_name => @display_name
+ return link_to(tag, :tag => tag, :display_name => @display_name)
end
end
end
diff --git a/app/views/trace/edit.rhtml b/app/views/trace/edit.rhtml
new file mode 100644
index 000000000..22405c1fc
--- /dev/null
+++ b/app/views/trace/edit.rhtml
@@ -0,0 +1,43 @@
+
<%= @title %>
+
+
+
+<% form_for :trace, @trace do |f| %>
+
+
+
+ Filename: |
+ <%= @trace.name %> (<%= link_to 'download', :controller => 'trace', :action => 'data', :id => @trace.id %>) |
+
+
+ Uploaded at: |
+ <%= @trace.timestamp %> |
+
+ <% if @trace.inserted? %>
+
+ Points: |
+ <%= @trace.size.to_s.gsub(/(\d)(?=(\d{3})+$)/,'\1,') %> |
+
+ Start coordinate: |
+ <%= @trace.latitude %>; <%= @trace.longitude %> (<%=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 %>) |
+
+ <% end %>
+
+ Owner: |
+ <%= link_to @trace.user.display_name, {:controller => 'user', :action => 'view', :display_name => @trace.user.display_name} %> |
+
+
+ Description: |
+ <%= f.text_field :description %> |
+
+
+ Tags: |
+ <%= f.text_field :tagstring %> |
+
+
+
+
+
+<%= submit_tag 'Save Changes' %>
+
+<% end %>
diff --git a/app/views/trace/view.rhtml b/app/views/trace/view.rhtml
index 60f71b7c7..a5b0cef09 100644
--- a/app/views/trace/view.rhtml
+++ b/app/views/trace/view.rhtml
@@ -50,6 +50,9 @@
<%= button_to 'Make this track public permanently', :controller => 'trace', :action => 'make_public', :id => @trace.id %> |
<% end %>
<% if @trace.user.id == @user.id %>
+ <%= button_to 'Edit this track', :controller => 'trace', :action => 'edit', :id => @trace.id %> |
+ <% end %>
+ <% if @trace.user.id == @user.id %>
<%= button_to 'Delete this track', :controller => 'trace', :action => 'delete', :id => @trace.id %> |
<% end %>
diff --git a/config/routes.rb b/config/routes.rb
index d8fb6b95a..a1ddb4f49 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -73,6 +73,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 '/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'
diff --git a/db/migrate/006_tile_nodes.rb b/db/migrate/006_tile_nodes.rb
new file mode 100644
index 000000000..9624a0136
--- /dev/null
+++ b/db/migrate/006_tile_nodes.rb
@@ -0,0 +1,114 @@
+class TileNodes < ActiveRecord::Migration
+ def self.upgrade_table(from_table, to_table)
+ execute <<-END_SQL
+ INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp, tile)
+ SELECT id, ROUND(latitude * 10000000), ROUND(longitude * 10000000),
+ user_id, visible, tags, timestamp,
+ tile_for_point(CAST(ROUND(latitude * 10000000) AS UNSIGNED),
+ CAST(ROUND(longitude * 10000000) AS UNSIGNED))
+ FROM #{from_table}
+ END_SQL
+ end
+
+ def self.downgrade_table(from_table, to_table)
+ execute <<-END_SQL
+ INSERT INTO #{to_table} (id, latitude, longitude, user_id, visible, tags, timestamp)
+ SELECT id, latitude / 10000000, longitude / 10000000,
+ user_id, visible, tags, timestamp
+ FROM #{from_table}
+ END_SQL
+ end
+
+ def self.up
+ rename_table "current_nodes", "current_nodes_v5"
+
+ create_table "current_nodes", innodb_table do |t|
+ t.column "id", :bigint, :limit => 64, :null => false
+ t.column "latitude", :integer, :null => false
+ t.column "longitude", :integer, :null => false
+ t.column "user_id", :bigint, :limit => 20, :null => false
+ t.column "visible", :boolean, :null => false
+ t.column "tags", :text, :default => "", :null => false
+ t.column "timestamp", :datetime, :null => false
+ t.column "tile", :integer, :null => false
+ end
+
+ add_primary_key "current_nodes", ["id"]
+ add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
+ add_index "current_nodes", ["tile"], :name => "current_nodes_tile_idx"
+
+ change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
+ change_column "current_nodes", "tile", :integer, :null => false, :unsigned => true
+
+ upgrade_table "current_nodes_v5", "current_nodes"
+
+ drop_table "current_nodes_v5"
+
+ rename_table "nodes", "nodes_v5"
+
+ create_table "nodes", myisam_table do |t|
+ t.column "id", :bigint, :limit => 64, :null => false
+ t.column "latitude", :integer, :null => false
+ t.column "longitude", :integer, :null => false
+ t.column "user_id", :bigint, :limit => 20, :null => false
+ t.column "visible", :boolean, :null => false
+ t.column "tags", :text, :default => "", :null => false
+ t.column "timestamp", :datetime, :null => false
+ t.column "tile", :integer, :null => false
+ end
+
+ add_index "nodes", ["id"], :name => "nodes_uid_idx"
+ add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
+ add_index "nodes", ["tile"], :name => "nodes_tile_idx"
+
+ change_column "nodes", "tile", :integer, :null => false, :unsigned => true
+
+ upgrade_table "nodes_v5", "nodes"
+
+ drop_table "nodes_v5"
+ end
+
+ def self.down
+ rename_table "current_nodes", "current_nodes_v6"
+
+ create_table "current_nodes", innodb_table do |t|
+ t.column "id", :bigint, :limit => 64, :null => false
+ t.column "latitude", :double, :null => false
+ t.column "longitude", :double, :null => false
+ t.column "user_id", :bigint, :limit => 20, :null => false
+ t.column "visible", :boolean, :null => false
+ t.column "tags", :text, :default => "", :null => false
+ t.column "timestamp", :datetime, :null => false
+ end
+
+ add_primary_key "current_nodes", ["id"]
+ add_index "current_nodes", ["latitude", "longitude"], :name => "current_nodes_lat_lon_idx"
+ add_index "current_nodes", ["timestamp"], :name => "current_nodes_timestamp_idx"
+
+ change_column "current_nodes", "id", :bigint, :limit => 64, :null => false, :options => "AUTO_INCREMENT"
+
+ downgrade_table "current_nodes_v6", "current_nodes"
+
+ drop_table "current_nodes_v6"
+
+ rename_table "nodes", "nodes_v6"
+
+ create_table "nodes", myisam_table do |t|
+ t.column "id", :bigint, :limit => 64, :null => false
+ t.column "latitude", :double, :null => false
+ t.column "longitude", :double, :null => false
+ t.column "user_id", :bigint, :limit => 20, :null => false
+ t.column "visible", :boolean, :null => false
+ t.column "tags", :text, :default => "", :null => false
+ t.column "timestamp", :datetime, :null => false
+ end
+
+ add_index "nodes", ["id"], :name => "nodes_uid_idx"
+ add_index "nodes", ["latitude", "longitude"], :name => "nodes_latlon_idx"
+ add_index "nodes", ["timestamp"], :name => "nodes_timestamp_idx"
+
+ downgrade_table "nodes_v6", "nodes"
+
+ drop_table "nodes_v6"
+ end
+end
diff --git a/db/migrate/006_add_relations.rb b/db/migrate/007_add_relations.rb
similarity index 100%
rename from db/migrate/006_add_relations.rb
rename to db/migrate/007_add_relations.rb
diff --git a/db/migrate/007_remove_segments.rb b/db/migrate/008_remove_segments.rb
similarity index 96%
rename from db/migrate/007_remove_segments.rb
rename to db/migrate/008_remove_segments.rb
index 492beda63..cfa99adad 100644
--- a/db/migrate/007_remove_segments.rb
+++ b/db/migrate/008_remove_segments.rb
@@ -5,9 +5,9 @@ class RemoveSegments < ActiveRecord::Migration
have_segs = select_value("SELECT count(*) FROM current_segments").to_i != 0
if have_segs
- prefix = File.join Dir.tmpdir, "007_remove_segments.#{$$}."
+ prefix = File.join Dir.tmpdir, "008_remove_segments.#{$$}."
- cmd = "db/migrate/007_remove_segments_helper"
+ cmd = "db/migrate/008_remove_segments_helper"
src = "#{cmd}.cc"
if not File.exists? cmd or File.mtime(cmd) < File.mtime(src) then
system 'c++ -O3 -Wall `mysql_config --cflags --libs` ' +
diff --git a/db/migrate/007_remove_segments_helper.cc b/db/migrate/008_remove_segments_helper.cc
similarity index 98%
rename from db/migrate/007_remove_segments_helper.cc
rename to db/migrate/008_remove_segments_helper.cc
index 3034a8f53..8f9c25bd5 100644
--- a/db/migrate/007_remove_segments_helper.cc
+++ b/db/migrate/008_remove_segments_helper.cc
@@ -34,9 +34,9 @@ static T parse(const char *str) {
static void exit_mysql_err(MYSQL *mysql) {
const char *err = mysql_error(mysql);
if (err) {
- fprintf(stderr, "007_remove_segments_helper: MySQL error: %s\n", err);
+ fprintf(stderr, "008_remove_segments_helper: MySQL error: %s\n", err);
} else {
- fprintf(stderr, "007_remove_segments_helper: MySQL error\n");
+ fprintf(stderr, "008_remove_segments_helper: MySQL error\n");
}
abort();
exit(EXIT_FAILURE);
@@ -45,9 +45,9 @@ static void exit_mysql_err(MYSQL *mysql) {
static void exit_stmt_err(MYSQL_STMT *stmt) {
const char *err = mysql_stmt_error(stmt);
if (err) {
- fprintf(stderr, "007_remove_segments_helper: MySQL stmt error: %s\n", err);
+ fprintf(stderr, "008_remove_segments_helper: MySQL stmt error: %s\n", err);
} else {
- fprintf(stderr, "007_remove_segments_helper: MySQL stmt error\n");
+ fprintf(stderr, "008_remove_segments_helper: MySQL stmt error\n");
}
abort();
exit(EXIT_FAILURE);
@@ -615,7 +615,7 @@ int main(int argc, char **argv) {
char *tempfn;
if (argc != 8) {
- printf("Usage: 007_remove_segments_helper host user passwd database port socket prefix\n");
+ printf("Usage: 008_remove_segments_helper host user passwd database port socket prefix\n");
exit(EXIT_FAILURE);
}