aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-05-09 16:56:10 +0200
committerRobert2017-05-09 16:56:10 +0200
commitc007b5f1442b903948373337a6cc7d7d42364b41 (patch)
tree5fbcd63e402ff3c136ecad47e06a2891f8ba43ca
parentb5cee945478c17cad2c251f886bd84d9a1f33d7c (diff)
parentfa16b56825592ed584453351e47f771bd580c41f (diff)
downloadchouette-core-c007b5f1442b903948373337a6cc7d7d42364b41.tar.bz2
Merge branch 'master' of github.com:af83/stif-boiv
-rw-r--r--app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js4
-rw-r--r--app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js4
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js4
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js5
-rw-r--r--app/models/chouette/time_table.rb25
-rw-r--r--app/models/time_table_combination.rb40
-rw-r--r--app/views/referentials/show.html.slim4
-rw-r--r--app/views/time_tables/index.html.slim2
-rw-r--r--spec/models/time_table_combination_spec.rb32
9 files changed, 92 insertions, 28 deletions
diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js
index 54d62f999..0ed961f44 100644
--- a/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/journey_patterns/actions/index.js
@@ -84,6 +84,10 @@ const actions = {
resetValidation: (target) => {
$(target).parent().removeClass('has-error').children('.help-block').remove()
},
+ humanOID : (oid) => {
+ var a = oid.split(':')
+ return a[a.length - 1]
+ },
validateFields : (fields) => {
const test = []
diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js
index d9f6d5550..14ddf2b99 100644
--- a/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js
+++ b/app/assets/javascripts/es6_browserified/journey_patterns/components/JourneyPattern.js
@@ -14,7 +14,7 @@ class JourneyPattern extends Component{
let vjURL = routeURL + '/vehicle_journeys?jp=' + jpOid
return (
- <a data-no-turbolink="true" href={vjURL}>Horaires des courses</a>
+ <a data-turbolinks="false" href={vjURL}>Horaires des courses</a>
)
}
@@ -62,7 +62,7 @@ class JourneyPattern extends Component{
)}
<div className='th'>
- <div className='strong mb-xs'>{this.props.value.object_id ? this.props.value.object_id : '-'}</div>
+ <div className='strong mb-xs'>{this.props.value.object_id ? actions.humanOID(this.props.value.object_id) : '-'}</div>
<div>{this.props.value.registration_number}</div>
<div>{actions.getChecked(this.props.value.stop_points).length} arrêt(s)</div>
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js
index ea03694bd..0e6f5ed12 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/actions/index.js
@@ -248,6 +248,10 @@ const actions = {
type: 'RECEIVE_TOTAL_COUNT',
total
}),
+ humanOID : (oid) => {
+ var a = oid.split(':')
+ return a[a.length - 1]
+ },
fetchVehicleJourneys : (dispatch, currentPage, nextPage, queryString) => {
if(currentPage == undefined){
currentPage = 1
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js
index d795d76e3..6f338f747 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/components/VehicleJourney.js
@@ -1,6 +1,7 @@
var React = require('react')
var Component = require('react').Component
var PropTypes = require('react').PropTypes
+var actions = require('../actions')
class VehicleJourney extends Component {
constructor(props) {
@@ -48,8 +49,8 @@ class VehicleJourney extends Component {
return (
<div className={'t2e-item' + (this.props.value.deletable ? ' disabled' : '') + (this.props.value.errors ? ' has-error': '')}>
<div className='th'>
- <div className='strong mb-xs'>{this.props.value.objectid ? this.props.value.objectid : '-'}</div>
- <div>{this.props.value.journey_pattern.objectid}</div>
+ <div className='strong mb-xs'>{this.props.value.objectid ? actions.humanOID(this.props.value.objectid) : '-'}</div>
+ <div>{actions.humanOID(this.props.value.journey_pattern.objectid)}</div>
{this.props.value.time_tables.map((tt, i)=>
<div key={i}>{this.timeTableURL(tt)}</div>
)}
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index 798fa81b4..37f609163 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -33,6 +33,31 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
validates_associated :dates
validates_associated :periods
+ def continuous_dates
+ chunk = {}
+ group = nil
+ self.dates.where(in_out: true).each_with_index do |date, index|
+ group ||= index
+ group = (date.date == dates[index - 1].date + 1.day) ? group : group + 1
+ chunk[group] ||= []
+ chunk[group] << date
+ end
+ chunk.values
+ end
+
+ def convert_continuous_dates_to_periods
+ chunks = self.continuous_dates
+ # Remove less than 3 continuous day chunk
+ chunks.delete_if {|chunk| chunk.count < 3}
+
+ transaction do
+ chunks.each do |chunk|
+ self.periods.create!(period_start: chunk.first.date, period_end: chunk.last.date)
+ chunk.map(&:destroy)
+ end
+ end
+ end
+
def state_update state
update_attributes(self.class.state_permited_attributes(state))
self.tag_list = state['tags'].collect{|t| t['name']}.join(', ')
diff --git a/app/models/time_table_combination.rb b/app/models/time_table_combination.rb
index 783ef53ef..519c02f2b 100644
--- a/app/models/time_table_combination.rb
+++ b/app/models/time_table_combination.rb
@@ -1,33 +1,33 @@
class TimeTableCombination
- include ActiveModel::Validations
- include ActiveModel::Conversion
+ include ActiveModel::Validations
+ include ActiveModel::Conversion
extend ActiveModel::Naming
-
- attr_accessor :source_id, :combined_id, :operation
-
- validates_presence_of :source_id, :combined_id, :operation
+
+ attr_accessor :source_id, :combined_id, :operation
+
+ validates_presence_of :source_id, :combined_id, :operation
validates_inclusion_of :operation, :in => %w( union intersection disjunction), :allow_nil => true
-
+
def clean
self.source_id = nil
self.combined_id = nil
self.operation = nil
self.errors.clear
- end
-
+ end
+
def self.operations
%w( union intersection disjunction)
end
- def initialize(attributes = {})
- attributes.each do |name, value|
- send("#{name}=", value)
- end
- end
-
- def persisted?
- false
- end
+ def initialize(attributes = {})
+ attributes.each do |name, value|
+ send("#{name}=", value)
+ end
+ end
+
+ def persisted?
+ false
+ end
def combine
source = Chouette::TimeTable.find( source_id)
@@ -38,10 +38,10 @@ class TimeTableCombination
source.intersect! combined
elsif operation == "disjunction"
source.disjoin! combined
- else
+ else
raise "unknown operation"
end
source
end
-
+
end
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 45fffe6a1..befa851ab 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -50,8 +50,8 @@
{ 'ID Codif' => Proc.new { |n| n.objectid.local_id },
:number => 'number',
:name => 'name',
- :deactivated => Proc.new{|n| n.deactivated? ? t('false') : t('true')},
- :transport_mode => 'transport_mode',
+ :deactivated => Proc.new{ |n| n.deactivated? ? t('false') : t('true') },
+ :transport_mode => Proc.new{ |n| n.transport_mode ? t("enumerize.line.transport_mode.#{n.transport_mode}") : '' },
'networks.name' => Proc.new { |n| n.try(:network).try(:name) },
'companies.name' => Proc.new { |n| n.try(:company).try(:name) } },
[:show],
diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim
index 01b65653c..c17f96c85 100644
--- a/app/views/time_tables/index.html.slim
+++ b/app/views/time_tables/index.html.slim
@@ -15,7 +15,7 @@
.row
.col-lg-12
= table_builder @time_tables,
- { :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, :comment => 'comment',
+ { 'OiD' => Proc.new { |n| n.objectid.local_id }, :color => Proc.new{|tt| tt.color ? content_tag(:span, '', class: 'fa fa-circle', style: "color:#{tt.color}") : '-' }, :comment => 'comment',
"Période englobante" => Proc.new{ |tt| tt.bounding_dates.empty? ? '-' : t('bounding_dates', debut: l(tt.bounding_dates.min), end: l(tt.bounding_dates.max)) },
"Nombre de courses associées" => Proc.new{ |tt| tt.vehicle_journeys.count },
"Journées d'application" => Proc.new{ |tt| (%w(monday tuesday wednesday thursday friday saturday sunday).collect{|d| tt.send(d) ? t("calendars.days.#{d}") : '' }).reject{|a| a.empty?}.join(', ').html_safe },
diff --git a/spec/models/time_table_combination_spec.rb b/spec/models/time_table_combination_spec.rb
index 46d5f8504..4c99a14fa 100644
--- a/spec/models/time_table_combination_spec.rb
+++ b/spec/models/time_table_combination_spec.rb
@@ -4,7 +4,37 @@ describe TimeTableCombination, :type => :model do
let!(:source){ create(:time_table)}
let!(:combined){create(:time_table)}
subject {build(:time_table_combination)}
-
+
+ describe '#continuous_dates' do
+ it 'should group continuous dates' do
+ dates = source.dates.where(in_out: true)
+ expect(source.continuous_dates[0].count).to eq(dates.count)
+
+ # 6 more continuous date, 1 isolated date
+ (10..15).each do |n|
+ source.dates.create(date: Date.today + n.day, in_out: true)
+ end
+ source.dates.create(date: Date.today + 1.year, in_out: true)
+ expect(source.reload.continuous_dates[1].count).to eq(6)
+ expect(source.reload.continuous_dates[2].count).to eq(1)
+ end
+ end
+
+ describe '#convert_continuous_dates_to_periods' do
+ it 'should convert continuous dates to periods' do
+ (10..12).each do |n|
+ source.dates.create(date: Date.today + n.day, in_out: true)
+ end
+ source.dates.create(date: Date.today + 1.year, in_out: true)
+
+ expect {
+ source.reload.convert_continuous_dates_to_periods
+ }.to change {source.periods.count}.by(2)
+
+ expect(source.reload.dates.where(in_out: true).count).to eq(1)
+ end
+ end
+
describe "#combine" do
context "when operation is union" do
before(:each) do