aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-04-18 16:14:54 +0200
committercedricnjanga2018-04-19 23:12:34 -0700
commite6567cbfc987d8488492e2b1ce66a03db3a3d37d (patch)
treedbace69e87473783624c89e3351be153ba7f9bed
parent7c0ce4a2f39f6d7386734016452c594ee7ee8797 (diff)
downloadchouette-core-e6567cbfc987d8488492e2b1ce66a03db3a3d37d.tar.bz2
Refs #6193; Show journey length in VJs editor
If `journey_length_in_vehicle_journeys` feature is enabled
-rw-r--r--app/controllers/vehicle_journeys_controller.rb1
-rw-r--r--app/javascript/vehicle_journeys/actions/index.js12
-rw-r--r--app/javascript/vehicle_journeys/components/VehicleJourney.js9
-rw-r--r--app/javascript/vehicle_journeys/components/VehicleJourneys.js5
-rw-r--r--app/models/chouette/journey_pattern.rb37
-rw-r--r--app/models/chouette/stop_point.rb4
-rw-r--r--app/views/vehicle_journeys/show.rabl2
-rw-r--r--config/locales/vehicle_journeys.en.yml3
-rw-r--r--config/locales/vehicle_journeys.fr.yml1
9 files changed, 52 insertions, 22 deletions
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index 220f2d29e..921a2cf7f 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -208,6 +208,7 @@ class VehicleJourneysController < ChouetteController
short_id: item.get_objectid.short_id,
full_schedule: item.full_schedule?,
costs: item.costs,
+ journey_length: item.journey_length,
stop_area_short_descriptions: item.stop_areas.map do |stop|
{
stop_area_short_description: {
diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js
index d51012cdb..70d6e953a 100644
--- a/app/javascript/vehicle_journeys/actions/index.js
+++ b/app/javascript/vehicle_journeys/actions/index.js
@@ -48,16 +48,10 @@ const actions = {
}),
selectJPCreateModal : (selectedJP) => ({
type : 'SELECT_JP_CREATE_MODAL',
- selectedItem: {
- id: selectedJP.id,
+ selectedItem: _.assign({}, selectedJP, {
objectid: selectedJP.object_id,
- short_id: selectedJP.short_id,
- name: selectedJP.name,
- published_name: selectedJP.published_name,
- stop_areas: selectedJP.stop_area_short_descriptions,
- costs: selectedJP.costs,
- full_schedule: selectedJP.full_schedule
- }
+ stop_areas: selectedJP.stop_area_short_descriptions
+ })
}),
openEditModal : (vehicleJourney) => ({
type : 'EDIT_VEHICLEJOURNEY_MODAL',
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js
index 73d99d120..5eb73de0e 100644
--- a/app/javascript/vehicle_journeys/components/VehicleJourney.js
+++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js
@@ -10,6 +10,10 @@ export default class VehicleJourney extends Component {
this.previousCity = undefined
}
+ journey_length() {
+ return this.props.value.journey_pattern.journey_length + "km"
+ }
+
cityNameChecker(sp) {
return this.props.vehicleJourneys.showHeader(sp.stop_point_objectid)
}
@@ -115,6 +119,11 @@ export default class VehicleJourney extends Component {
<div key={i}>{this.extraHeaderValue(header)}</div>
)
}
+ { this.hasFeature('journey_length_in_vehicle_journeys') &&
+ <div>
+ {this.journey_length()}
+ </div>
+ }
{ this.hasFeature('purchase_windows') &&
<div>
{purchase_windows.slice(0,3).map((tt, i)=>
diff --git a/app/javascript/vehicle_journeys/components/VehicleJourneys.js b/app/javascript/vehicle_journeys/components/VehicleJourneys.js
index e4f5ad11c..27e147b37 100644
--- a/app/javascript/vehicle_journeys/components/VehicleJourneys.js
+++ b/app/javascript/vehicle_journeys/components/VehicleJourneys.js
@@ -224,6 +224,11 @@ export default class VehicleJourneys extends Component {
<div key={i}>{this.extraHeaderLabel(header)}</div>
)
}
+ { this.hasFeature('journey_length_in_vehicle_journeys') &&
+ <div>
+ {I18n.attribute_name("vehicle_journey", "journey_length")}
+ </div>
+ }
{ this.hasFeature('purchase_windows') &&
<div>
{ detailed_purchase_windows &&
diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb
index 1e4041798..4b4cc2c73 100644
--- a/app/models/chouette/journey_pattern.rb
+++ b/app/models/chouette/journey_pattern.rb
@@ -86,10 +86,8 @@ module Chouette
def state_stop_points_update item
item['stop_points'].each do |sp|
- exist = stop_area_ids.include?(sp['id'])
- next if exist && sp['checked']
-
- stop_point = route.stop_points.find_by(stop_area_id: sp['id'])
+ stop_point = route.stop_points.find_by(stop_area_id: sp['id'], position: sp['position'])
+ exist = stop_points.include?(stop_point)
if !exist && sp['checked']
stop_points << stop_point
end
@@ -175,11 +173,12 @@ module Chouette
full
end
- def distance_to stop
+ def distance_between start, stop
+ return 0 unless start.position < stop.position
val = 0
- i = 0
- _end = stop_points.first
- while _end != stop
+ i = stop_points.index(start)
+ _end = start
+ while _end && _end != stop
i += 1
_start = _end
_end = stop_points[i]
@@ -188,6 +187,28 @@ module Chouette
val
end
+ def distance_to stop
+ distance_between stop_points.first, stop
+ end
+
+ def journey_length
+ i = 0
+ j = stop_points.length - 1
+ start = stop_points[i]
+ stop = stop_points[j]
+ while i < j && start.kind == "non_commercial"
+ i+= 1
+ start = stop_points[i]
+ end
+
+ while i < j && stop.kind == "non_commercial"
+ j-= 1
+ stop = stop_points[j]
+ end
+ return 0 unless start && stop
+ distance_between start, stop
+ end
+
def set_distances distances
raise "inconsistent data: #{distances.count} values for #{stop_points.count} stops" unless distances.count == stop_points.count
prev = distances[0].to_i
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index 1df1a664a..6f2d89578 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -9,7 +9,6 @@ module Chouette
include ForAlightingEnumerations
include ObjectidSupport
-
belongs_to :stop_area
belongs_to :route, inverse_of: :stop_points
has_many :vehicle_journey_at_stops, :dependent => :destroy
@@ -17,7 +16,6 @@ module Chouette
acts_as_list :scope => :route, top_of_list: 0
-
validates_presence_of :stop_area
validate :stop_area_id_validation
def stop_area_id_validation
@@ -28,7 +26,7 @@ module Chouette
scope :default_order, -> { order("position") }
- delegate :name, to: :stop_area
+ delegate :name, :kind, :area_type, to: :stop_area
before_destroy :remove_dependent_journey_pattern_stop_points
def remove_dependent_journey_pattern_stop_points
diff --git a/app/views/vehicle_journeys/show.rabl b/app/views/vehicle_journeys/show.rabl
index d218038a6..6c588416c 100644
--- a/app/views/vehicle_journeys/show.rabl
+++ b/app/views/vehicle_journeys/show.rabl
@@ -17,7 +17,7 @@ child(:route) do |route|
end
child(:journey_pattern) do |journey_pattern|
- attributes :id, :objectid, :name, :published_name
+ attributes :id, :objectid, :name, :published_name, :journey_length
node(:short_id) {journey_pattern.get_objectid.short_id}
end
diff --git a/config/locales/vehicle_journeys.en.yml b/config/locales/vehicle_journeys.en.yml
index 12d8d0da4..8bc268197 100644
--- a/config/locales/vehicle_journeys.en.yml
+++ b/config/locales/vehicle_journeys.en.yml
@@ -4,7 +4,7 @@ en:
filters:
id: Filter by ID...
journey_pattern: Filter by journey pattern...
- timetable: Filter by timetable...
+ timetable: Filter by timetable...
cancel_selection: "Cancel Selection"
fetching_error: "There has been a problem fetching the data. Please reload the page to try again."
line_routes: "Line's routes"
@@ -133,6 +133,7 @@ en:
journey_pattern_id: "Pattern ID"
journey_pattern: "Journey Pattern"
journey_pattern_published_name: "Journey Pattern published name"
+ journey_length: "Journey length"
line: "Line"
mobility_restricted_suitability: "PRM accessibility"
name: "Journey Name"
diff --git a/config/locales/vehicle_journeys.fr.yml b/config/locales/vehicle_journeys.fr.yml
index 466eca684..18703be9b 100644
--- a/config/locales/vehicle_journeys.fr.yml
+++ b/config/locales/vehicle_journeys.fr.yml
@@ -134,6 +134,7 @@ fr:
journey_pattern_id: "ID Mission"
journey_pattern: "Mission"
journey_pattern_published_name: "Nom public de la mission"
+ journey_length: "Parcours commercial"
line: "Ligne"
mobility_restricted_suitability: "Accessibilité PMR"
name: "Nom Course"