aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/javascript/helpers/CustomFieldsInputs.js17
-rw-r--r--app/javascript/vehicle_journeys/actions/index.js2
-rw-r--r--app/models/chouette/vehicle_journey.rb7
-rw-r--r--app/models/concerns/metadata_support.rb4
-rw-r--r--app/views/stop_areas/_filters.html.slim4
-rw-r--r--spec/controllers/stop_areas_controller_spec.rb35
-rw-r--r--spec/features/stop_areas_spec.rb6
-rw-r--r--spec/models/chouette/vehicle_journey_spec.rb20
8 files changed, 84 insertions, 11 deletions
diff --git a/app/javascript/helpers/CustomFieldsInputs.js b/app/javascript/helpers/CustomFieldsInputs.js
index 9547021eb..0a57e7566 100644
--- a/app/javascript/helpers/CustomFieldsInputs.js
+++ b/app/javascript/helpers/CustomFieldsInputs.js
@@ -8,15 +8,24 @@ export default class CustomFieldsInputs extends Component {
super(props)
}
+ options(cf){
+ if(cf.options){
+ return cf.options
+ }
+ return {
+ default: ""
+ }
+ }
+
listInput(cf){
return(
<Select2
- data={_.map(cf.options.list_values, (v, k) => {
+ data={_.map(this.options(cf).list_values, (v, k) => {
return {id: k, text: (v.length > 0 ? v : '\u00A0')}
})}
ref={'custom_fields.' + cf.code}
className='form-control'
- defaultValue={cf.value || cf.options.default}
+ defaultValue={cf.value || this.options(cf).default}
disabled={this.props.disabled}
options={{
theme: 'bootstrap',
@@ -34,7 +43,7 @@ export default class CustomFieldsInputs extends Component {
ref={'custom_fields.' + cf.code}
className='form-control'
disabled={this.props.disabled}
- value={cf.value || cf.options.default}
+ value={cf.value || this.options(cf).default}
onChange={(e) => {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} }
/>
)
@@ -47,7 +56,7 @@ export default class CustomFieldsInputs extends Component {
ref={'custom_fields.' + cf.code}
className='form-control'
disabled={this.props.disabled}
- value={cf.value || cf.options.default}
+ value={cf.value || this.options(cf).default}
onChange={(e) => {this.props.onUpdate(cf.code, e.target.value); this.forceUpdate()} }
/>
)
diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js
index c67f9f0cf..60496e0ff 100644
--- a/app/javascript/vehicle_journeys/actions/index.js
+++ b/app/javascript/vehicle_journeys/actions/index.js
@@ -332,7 +332,7 @@ const actions = {
sep = '&'
}
let urlJSON = url + str
- if (queryString){
+ if (!returnJourneys && queryString){
urlJSON = urlJSON + sep + queryString
}
let hasError = false
diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb
index 8a29057e2..8b5354863 100644
--- a/app/models/chouette/vehicle_journey.rb
+++ b/app/models/chouette/vehicle_journey.rb
@@ -369,10 +369,15 @@ module Chouette
if before_cost && before_cost[:distance] && after_cost && after_cost[:distance]
before_distance = before_cost[:distance].to_f
after_distance = after_cost[:distance].to_f
- time = previous_stop.departure_time + before_distance / (before_distance+after_distance) * (vjas.arrival_time - previous_stop.departure_time)
+ arrival_time = vjas.arrival_time + (vjas.arrival_day_offset - previous_stop.departure_day_offset)*24.hours
+ time = previous_stop.departure_time + before_distance / (before_distance+after_distance) * (arrival_time - previous_stop.departure_time)
+ day_offset = time.day - 1
+ time -= day_offset*24.hours
encountered_borders.each do |b|
b.update_attribute :arrival_time, time
+ b.update_attribute :arrival_day_offset, previous_stop.arrival_day_offset + day_offset
b.update_attribute :departure_time, time
+ b.update_attribute :departure_day_offset, previous_stop.departure_day_offset + day_offset
end
end
encountered_borders = []
diff --git a/app/models/concerns/metadata_support.rb b/app/models/concerns/metadata_support.rb
index 182ab8310..96bd099cc 100644
--- a/app/models/concerns/metadata_support.rb
+++ b/app/models/concerns/metadata_support.rb
@@ -66,8 +66,8 @@ module MetadataSupport
"#{name}_updated_at".to_sym
end
- def as_json
- @table.as_json
+ def as_json *args
+ @table.as_json *args
end
def method_missing(mid, *args)
diff --git a/app/views/stop_areas/_filters.html.slim b/app/views/stop_areas/_filters.html.slim
index caa264d5e..cca48bb17 100644
--- a/app/views/stop_areas/_filters.html.slim
+++ b/app/views/stop_areas/_filters.html.slim
@@ -1,7 +1,9 @@
= search_form_for @q, url: stop_area_referential_stop_areas_path(@stop_area_referential), html: {method: :get}, class: 'form form-filter' do |f|
.ffg-row
.input-group.search_bar class=filter_item_class(params[:q], :name_or_objectid_cont)
- = f.search_field :name_or_objectid_cont, placeholder: t('.name_or_objectid'), class: 'form-control'
+ = f.search_field :name_or_objectid_or_registration_number_cont,
+ placeholder: t('.name_or_objectid'),
+ class: 'form-control'
span.input-group-btn
button.btn.btn-default#search-btn type='submit'
span.fa.fa-search
diff --git a/spec/controllers/stop_areas_controller_spec.rb b/spec/controllers/stop_areas_controller_spec.rb
index f39ac5776..fbad2649c 100644
--- a/spec/controllers/stop_areas_controller_spec.rb
+++ b/spec/controllers/stop_areas_controller_spec.rb
@@ -4,6 +4,41 @@ RSpec.describe StopAreasController, :type => :controller do
let(:stop_area_referential) { create :stop_area_referential, member: @user.organisation }
let(:stop_area) { create :stop_area, stop_area_referential: stop_area_referential }
+ describe "GET index" do
+ it "filters by registration number" do
+ registration_number = 'E34'
+
+ matched = create(
+ :stop_area,
+ stop_area_referential: stop_area_referential,
+ registration_number: registration_number
+ )
+ create(
+ :stop_area,
+ stop_area_referential: stop_area_referential,
+ registration_number: "doesn't match"
+ )
+
+ get :index,
+ stop_area_referential_id: stop_area_referential.id,
+ q: {
+ name_or_objectid_or_registration_number_cont: registration_number
+ }
+
+ expect(assigns(:stop_areas)).to eq([matched])
+ end
+
+ it "doesn't filter when the name filter is empty" do
+ get :index,
+ stop_area_referential_id: stop_area_referential.id,
+ q: {
+ name_or_objectid_or_registration_number_cont: ''
+ }
+
+ expect(assigns(:stop_areas)).to eq([stop_area])
+ end
+ end
+
describe 'PUT deactivate' do
let(:request){ put :deactivate, id: stop_area.id, stop_area_referential_id: stop_area_referential.id }
diff --git a/spec/features/stop_areas_spec.rb b/spec/features/stop_areas_spec.rb
index 17aee2cc0..52040f070 100644
--- a/spec/features/stop_areas_spec.rb
+++ b/spec/features/stop_areas_spec.rb
@@ -18,14 +18,16 @@ describe "StopAreas", :type => :feature do
context 'filtering' do
it 'supports filtering by name' do
- fill_in 'q[name_or_objectid_cont]', with: stop_areas.first.name
+ fill_in 'q[name_or_objectid_or_registration_number_cont]',
+ with: stop_areas.first.name
click_button 'search-btn'
expect(page).to have_content(stop_areas.first.name)
expect(page).not_to have_content(stop_areas.last.name)
end
it 'supports filtering by objectid' do
- fill_in 'q[name_or_objectid_cont]', with: stop_areas.first.objectid
+ fill_in 'q[name_or_objectid_or_registration_number_cont]',
+ with: stop_areas.first.objectid
click_button 'search-btn'
expect(page).to have_content(stop_areas.first.name)
expect(page).not_to have_content(stop_areas.last.name)
diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb
index 9cc695c3c..ce93588b0 100644
--- a/spec/models/chouette/vehicle_journey_spec.rb
+++ b/spec/models/chouette/vehicle_journey_spec.rb
@@ -966,5 +966,25 @@ describe Chouette::VehicleJourney, :type => :model do
expect(@target_3.departure_time).to eq @target_3.arrival_time
expect(@target_4.departure_time).to eq @target_3.arrival_time
end
+
+ context "with a day offset" do
+ before do
+ @end.update arrival_time: @middle.departure_time - 4.hours, departure_time: @middle.departure_time - 4.hours, departure_day_offset: 1, arrival_day_offset: 1
+ end
+
+ it "should compute passing time" do
+ @journey.reload.fill_passing_time_at_borders
+ expect(@target.reload.arrival_time.to_i).to eq (@start.reload.departure_time + 1.0/3 * (@middle.reload.arrival_time - @start.departure_time)).to_i
+ expect(@target_2.reload.arrival_time).to eq @target.arrival_time
+ expect(@target.departure_time).to eq @target.arrival_time
+ expect(@target_2.departure_time).to eq @target.arrival_time
+ expect(@target_3.reload.arrival_time.to_i).to eq (@middle.reload.departure_time - 14.hours).to_i
+ expect(@target_3.arrival_day_offset).to eq 1
+ expect(@target_3.departure_day_offset).to eq 1
+ expect(@target_4.reload.arrival_time).to eq @target_3.arrival_time
+ expect(@target_3.departure_time).to eq @target_3.arrival_time
+ expect(@target_4.departure_time).to eq @target_3.arrival_time
+ end
+ end
end
end