From: Steve Coast Date: Wed, 6 Dec 2006 17:10:59 +0000 (+0000) Subject: add tags to gpx files X-Git-Tag: live~8599 X-Git-Url: https://git.openstreetmap.org/rails.git/commitdiff_plain/a7e3b58b410c2f74a69eebbe3151866a5161dc09 add tags to gpx files --- diff --git a/app/controllers/trace_controller.rb b/app/controllers/trace_controller.rb index 06db32248..f7f323e9c 100644 --- a/app/controllers/trace_controller.rb +++ b/app/controllers/trace_controller.rb @@ -3,7 +3,7 @@ class TraceController < ApplicationController layout 'site' def list - @traces = Trace.find(:all) + @traces = Trace.find(:all, :conditions => ['public = true']) end def mine @@ -12,7 +12,11 @@ class TraceController < ApplicationController def view @trace = Trace.find(params[:id]) - render :nothing, :status => 401 if @trace.user.id != @user.id + unless @trace.public + if @user + render :nothing, :status => 401 if @trace.user.id != @user.id + end + end end def create diff --git a/app/controllers/tracetag_controller.rb b/app/controllers/tracetag_controller.rb new file mode 100644 index 000000000..ec44ee07b --- /dev/null +++ b/app/controllers/tracetag_controller.rb @@ -0,0 +1,2 @@ +class TracetagController < ApplicationController +end diff --git a/app/helpers/tracetag_helper.rb b/app/helpers/tracetag_helper.rb new file mode 100644 index 000000000..c1479e124 --- /dev/null +++ b/app/helpers/tracetag_helper.rb @@ -0,0 +1,2 @@ +module TracetagHelper +end diff --git a/app/models/trace.rb b/app/models/trace.rb index 014db4ae2..06e3dc1a1 100644 --- a/app/models/trace.rb +++ b/app/models/trace.rb @@ -2,10 +2,13 @@ class Trace < ActiveRecord::Base set_table_name 'gpx_files' belongs_to :user + has_many :tags, :class_name => 'Tracetag', :foreign_key => 'gpx_id' - def tags=(bleh) - end - - def mime_type=(bleh) + def tagstring=(s) + self.tags = s.split().collect {|tag| + tt = Tracetag.new + tt.tag = tag + tt + } end end diff --git a/app/models/tracetag.rb b/app/models/tracetag.rb new file mode 100644 index 000000000..d74a1e75a --- /dev/null +++ b/app/models/tracetag.rb @@ -0,0 +1,6 @@ +class Tracetag < ActiveRecord::Base + set_table_name 'gpx_file_tags' + + belongs_to :trace, :foreign_key => 'gpx_id' + +end diff --git a/app/views/trace/mine.rhtml b/app/views/trace/mine.rhtml index d651d1e8b..997e2c297 100644 --- a/app/views/trace/mine.rhtml +++ b/app/views/trace/mine.rhtml @@ -8,7 +8,7 @@ - +
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}) %>
tags:<%= text_field('trace', 'tagstring', {:size => 50, :maxlength => 255}) %>
public?<%= check_box('trace', 'public', {:checked => 'checked'}) %>
<%= submit_tag 'Upload' %> | help diff --git a/db/migrate.sql b/db/migrate.sql index 0bf3c3a90..92ae6b171 100644 --- a/db/migrate.sql +++ b/db/migrate.sql @@ -18,3 +18,9 @@ alter table current_way_tags change v v varchar(255) not null default ''; alter table gpx_files change private public boolean default 1 not null; update gpx_files set public = !public; +alter table gpx_file_tags change sequence_id sequence_id int(11); +alter table gpx_file_tags drop primary key; +alter table gpx_file_tags drop column sequence_id; +create index gpx_file_tags_gpxid_idx on gpx_file_tags(gpx_id); +alter table gpx_file_tags add id int(20) auto_increment not null, add primary key(id); + diff --git a/db/migrate/016_create_tracetags.rb b/db/migrate/016_create_tracetags.rb new file mode 100644 index 000000000..5ab57490f --- /dev/null +++ b/db/migrate/016_create_tracetags.rb @@ -0,0 +1,11 @@ +class CreateTracetags < ActiveRecord::Migration + def self.up + create_table :tracetags do |t| + # t.column :name, :string + end + end + + def self.down + drop_table :tracetags + end +end