Permalink
Browse files

imported pois with owner, private/public got "is_" prefix

  • Loading branch information...
1 parent 666e020 commit d7fcde9b0b099984799f090fde18d5450c52a69e @akwiatkowski committed Aug 9, 2012
@@ -7,7 +7,7 @@ def new
def create
authorize! :manage, Importer
- result = Importer.process_path(params[:path])
+ result = Importer.process_path(params[:path], current_user)
flash[:notice] = "Processed path with #{result.size} waypoints"
render 'new'
end
@@ -3,8 +3,9 @@ class WaypointsController < InheritedResources::Base
has_scope :page, default: 1, if: Proc.new{ |r| r.request.format == 'html'}
has_scope :area_id
- has_scope :private
- has_scope :public
+ has_scope :wo_area
+ has_scope :is_private
+ has_scope :is_public
has_scope :sorted, as: :sort
respond_to :gpx, :xml, :json, :csv
View
@@ -3,9 +3,9 @@ class Ability
def initialize(user)
can :read, Area
- can :read, Waypoint, private: false
- can :read, Route, private: false
- can :read, RouteElement, route: {private: false}
+ can :read, Waypoint, is_private: false
+ can :read, Route, is_private: false
+ can :read, RouteElement, route: {is_private: false}
if user
can :manage, Waypoint, user_id: user.id
@@ -4,7 +4,7 @@ def self.export(_private = nil)
pois = Waypoint.order("created_at ASC")
unless _private.nil?
puts _private.inspect
- pois = pois.where(private: _private)
+ pois = pois.where(is_private: _private)
end
pois = pois.all
View
@@ -1,6 +1,6 @@
class Importer
- def self.process_path(path)
- g = GarminUtils::GpxWaypointParser.new
+ def self.process_path(path, current_user)
+ g = GpxUtils::WaypointsImporter.new
dir = Dir[File.join(path, "*")]
dir.each do |f|
if f =~ /\.gpx$/i
@@ -22,6 +22,9 @@ def self.process_path(path)
w.created_at = p[:time]
w.updated_at = p[:time]
w.imported_at = Time.now
+ w.user = current_user
+ w.is_private = true # private by default
+
w.save!
end
View
@@ -1,12 +1,13 @@
class Waypoint < ActiveRecord::Base
- attr_accessible :elevation, :lat, :lon, :name, :sym, :area_id, :private, :dms_coords, :url
+ attr_accessible :elevation, :lat, :lon, :name, :sym, :area_id, :is_private, :dms_coords, :url
belongs_to :area
has_many :route_elements
belongs_to :user
scope :area_id, lambda { |_area_id| where(area_id: _area_id) }
- scope :private, lambda { |v| where(private: true) }
- scope :public, lambda { |v| where(private: false) }
+ scope :wo_area, lambda { |v| where(area_id: nil) }
+ scope :is_private, lambda { |v| where(is_private: true) }
+ scope :is_public, lambda { |v| where(is_private: false) }
# http://stackoverflow.com/questions/639171/what-is-causing-this-activerecordreadonlyrecord-error
#default_scope lambda { order(:created_at).joins("LEFT JOIN `areas` ON waypoints.area_id = areas.id") }
@@ -30,6 +30,17 @@
- if can? :destroy, area
= link_to 'Destroy', area, :confirm => 'Are you sure?', :method => :delete
+ %tr
+ %td
+ %td= "N/A"
+ %td
+ - if can? :read, Waypoint
+ = link_to "Waypoints (#{Waypoint.wo_area.count})", waypoints_path(wo_area: 't')
+ %td
+ %td
+ %td
+
+
= paginate collection
%br
@@ -30,13 +30,13 @@
- if false
- unless params[:public]
|
- = link_to "Public", public: :true
- - unless params[:private]
+ = link_to "Public", is_public: :true
+ - unless params[:is_private]
|
- = link_to "Private", private: :true
- - unless params[:public].nil? and params[:private].nil?
+ = link_to "Private", is_private: :true
+ - unless params[:is_public].nil? and params[:is_private].nil?
|
- = link_to "All", public: nil, private: nil
+ = link_to "All", is_public: nil, is_private: nil
- if action_name == 'index'
|
= link_to "Export to GPX", format: :gpx
@@ -1,5 +1,5 @@
<%=
- g = GarminUtils::WaypointListGenerator.new
+ g = GpxUtils::WaypointsExporter.new
collection.each do |poi|
g.add(
poi.lat,
@@ -27,7 +27,7 @@
%tr
%td= image_tag "garmin/#{waypoint.img_symbol}"
%td
- - if waypoint.private
+ - if waypoint.is_private
= image_tag 'padlock.png'
= waypoint.name
- unless waypoint.area.nil?
@@ -51,14 +51,14 @@
%td
- if can? :edit, waypoint
= form_for waypoint do |f|
- = f.hidden_field :private, value: (! waypoint.private)
- = f.submit waypoint.private ? "Enable" : "Disable"
+ = f.hidden_field :is_private, value: (! waypoint.is_private)
+ = f.submit waypoint.is_private ? "Enable" : "Disable"
- else
- = waypoint.private ? "Private" : "Public"
+ = waypoint.is_private ? "Private" : "Public"
%td= link_to 'Show', waypoint
%td
- - if waypoint.url
+ - unless waypoint.url.blank?
= link_to 'Url', waypoint.url
%td
= waypoint_map_link_to(waypoint)
@@ -2,37 +2,40 @@
%p
%b Lat:
- = @waypoint.lat
+ = resource.lat
%p
%b Lon:
- = @waypoint.lon
+ = resource.lon
%p
%b Elevation:
- = @waypoint.elevation
+ = resource.elevation
%p
%b Name:
- = @waypoint.name
+ = resource.name
- if resource.url
%p
%b Url:
- = link_to @waypoint.url, @waypoint.url, target: '_blank'
+ = link_to resource.url, resource.url, target: '_blank'
%p
%b Symbol:
- = @waypoint.sym
-- unless @waypoint.area.nil?
+ = resource.sym
+- unless resource.area.nil?
%p
%b
Area:
- = link_to area_waypoints_path(@waypoint.area) do
- = @waypoint.area.name
+ = link_to area_waypoints_path(resource.area) do
+ = resource.area.name
%p
%b Maps:
- = waypoint_map_link_to(@waypoint)
+ = waypoint_map_link_to(resource)
%p
%b Owner:
- = link_to @waypoint.user.name, @waypoint.user
+ - if resource.user.nil?
+ = "N/A"
+ - else
+ = link_to resource.user.name, resource.user
-- if can? :edit, @waypoint
- = link_to 'Edit', edit_waypoint_path(@waypoint)
+- if can? :edit, resource
+ = link_to 'Edit', edit_resource_path(resource)
|
-= link_to 'Back', waypoints_path
+= link_to 'Back', collection_path
@@ -0,0 +1,9 @@
+class WaypointPrivateRenameToIsPrivate < ActiveRecord::Migration
+ def up
+ rename_column :waypoints, :private, :is_private
+ end
+
+ def down
+ rename_column :waypoints, :is_private, :private
+ end
+end
@@ -0,0 +1,9 @@
+class RoutePrivateRenameToIsPrivate < ActiveRecord::Migration
+ def up
+ rename_column :routes, :private, :is_private
+ end
+
+ def down
+ rename_column :routes, :is_private, :private
+ end
+end
View
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120716174634) do
+ActiveRecord::Schema.define(:version => 20120809105817) do
create_table "areas", :force => true do |t|
t.string "name"
@@ -40,7 +40,7 @@
t.datetime "updated_at", :null => false
t.integer "area_id"
t.integer "user_id"
- t.boolean "private", :default => false, :null => false
+ t.boolean "is_private", :default => false, :null => false
end
create_table "users", :force => true do |t|
@@ -73,7 +73,7 @@
t.datetime "imported_at"
t.string "sym"
t.integer "area_id"
- t.boolean "private", :default => false, :null => false
+ t.boolean "is_private", :default => false, :null => false
t.string "url"
t.integer "user_id"
end

0 comments on commit d7fcde9

Please sign in to comment.