Skip to content
Browse files

routes polishing

  • Loading branch information...
1 parent 72d0fb3 commit 652d5ab8ccd0af85985895209e241842412dda98 @akwiatkowski committed Jun 10, 2012
View
25 app/models/route.rb
@@ -4,4 +4,29 @@ class Route < ActiveRecord::Base
belongs_to :area
validates_presence_of :area
+
+ # Total route distance
+ def distance
+ _d = 0
+ self.route_elements.each do |route_element|
+ if route_element.real_distance
+ _d += route_element.real_distance
+ else
+ _d += route_element.distance
+ end
+ end
+ return _d
+ end
+
+ def time_distance
+ _d = 0
+ self.route_elements.each do |route_element|
+ if route_element.real_distance
+ _d += route_element.real_distance
+ else
+ _d += route_element.distance
+ end
+ end
+ return _d
+ end
end
View
2 app/models/route_element.rb
@@ -1,5 +1,5 @@
class RouteElement < ActiveRecord::Base
- attr_accessible :real_distance, :real_d_elevation, :waypoint_start_id, :waypoint_finish_id
+ attr_accessible :real_distance, :real_d_elevation, :real_time_distance, :waypoint_start_id, :waypoint_finish_id
belongs_to :route
belongs_to :start, foreign_key: 'waypoint_start_id', class_name: 'Waypoint'
View
2 app/views/areas/index.html.haml
@@ -18,7 +18,7 @@
%td= image_tag "garmin/#{area.img_symbol}"
%td= area.area_type
%td= area.name
- %td= link_to 'Waypoints', area_waypoints_path(area)
+ %td= link_to "Waypoints (#{area.waypoints.count})", area_waypoints_path(area)
%td= link_to 'Show', area
%td= link_to 'Edit', edit_area_path(area)
%td= link_to 'Destroy', area, :confirm => 'Are you sure?', :method => :delete
View
4 app/views/layouts/application.html.haml
@@ -18,7 +18,9 @@
#menu
= link_to "Areas", areas_path
|
- = link_to "Waypoints", waypoints_path(page: 1)
+ = link_to "Waypoints", waypoints_path
+ |
+ = link_to "Routes", routes_path
|
= link_to "Importer", new_importer_path
- if controller_name == "waypoints"
View
12 app/views/routes/index.html.haml
@@ -2,18 +2,24 @@
%table
%tr
+ %th Area
%th Name
%th Url
- %th
+ %th Distance [m]
+ %th Distance [min]
%th
%th
%th
- @routes.each do |route|
%tr
+ %td= route.area.name
%td= route.name
- %td= route.url
- %td= route.url
+ %td
+ - unless route.url.blank?
+ = link_to "URL", route.url
+ %td= route.distance
+ %td= route.time_distance
%td= link_to 'Elements', route_route_elements_path(route)
%td= link_to 'Show', route
%td= link_to 'Edit', edit_route_path(route)
View
3 db/schema.rb
@@ -11,7 +11,7 @@
#
# It's strongly recommended to check this file into your version control system.
-ActiveRecord::Schema.define(:version => 20120607124455) do
+ActiveRecord::Schema.define(:version => 20120610115741) do
create_table "areas", :force => true do |t|
t.string "name"
@@ -30,6 +30,7 @@
t.datetime "updated_at", :null => false
t.integer "real_distance"
t.integer "real_d_elevation"
+ t.integer "real_time_distance"
end
create_table "routes", :force => true do |t|

0 comments on commit 652d5ab

Please sign in to comment.
Something went wrong with that request. Please try again.