aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/actions/index.js8
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js118
-rw-r--r--app/assets/javascripts/routing_constraint_zones.coffee7
-rw-r--r--app/controllers/time_tables_controller.rb7
-rw-r--r--app/models/chouette/time_table.rb15
-rw-r--r--lib/tasks/referential.rake33
-rw-r--r--spec/models/chouette/time_table_spec.rb27
7 files changed, 133 insertions, 82 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
index 4a3cfc061..cef9bc75d 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
@@ -7,13 +7,13 @@ const actions = {
},
arrayToStrDayTypes: (arr) => {
let weekDays = ['Di', 'Lu', 'Ma', 'Me', 'Je', 'Ve', 'Sa']
- let str = ''
+ let str = []
arr.map((dayActive, i) => {
if(dayActive){
- str += weekDays[i]
+ str.push(weekDays[i])
}
})
- return str
+ return str.join(',')
},
fetchingApi: () =>({
type: 'FETCH_API'
@@ -237,7 +237,7 @@ const actions = {
let sentState = _.assign({}, timetable, metas)
let urlJSON = window.location.pathname.split('/', 5).join('/')
let hasError = false
- fetch(urlJSON, {
+ fetch(urlJSON + '.json', {
credentials: 'same-origin',
method: 'PATCH',
contentType: 'application/json; charset=utf-8',
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
index 7a33bd63d..1830bfcde 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/Timetable.js
@@ -20,70 +20,78 @@ class Timetable extends Component{
}
render() {
- return (
- <div className="table table-2entries mb-sm">
- <div className="t2e-head w20">
- <div className="th">
- <div className="strong">Synthèse</div>
- </div>
- <div className="td"><span>Journées d'application</span></div>
- <div className="td"><span>Périodes</span></div>
- <div className="td"><span>Exceptions</span></div>
+ if(this.props.status.isFetching == true) {
+ return (
+ <div className="isLoading" style={{marginTop: 80, marginBottom: 80}}>
+ <div className="loader"></div>
</div>
- <div className="t2e-item-list w80">
- <div>
- <div className="t2e-item">
- <div className="th">
- <div className="strong monthName">
- {actions.monthName(this.props.timetable.current_periode_range)}
- </div>
+ )
+ } else {
+ return (
+ <div className="table table-2entries mb-sm">
+ <div className="t2e-head w20">
+ <div className="th">
+ <div className="strong">Synthèse</div>
+ </div>
+ <div className="td"><span>Journées d'application</span></div>
+ <div className="td"><span>Périodes</span></div>
+ <div className="td"><span>Exceptions</span></div>
+ </div>
+ <div className="t2e-item-list w80">
+ <div>
+ <div className="t2e-item">
+ <div className="th">
+ <div className="strong monthName">
+ {actions.monthName(this.props.timetable.current_periode_range)}
+ </div>
- <div className='monthDays'>
- {this.props.timetable.current_month.map((d, i) =>
- <TimeTableDay
- key={i}
- index={i}
- value={d}
- dayTypeActive={this.props.metas.day_types[d.wday]}
- />
- )}
+ <div className='monthDays'>
+ {this.props.timetable.current_month.map((d, i) =>
+ <TimeTableDay
+ key={i}
+ index={i}
+ value={d}
+ dayTypeActive={this.props.metas.day_types[d.wday]}
+ />
+ )}
+ </div>
</div>
- </div>
- {this.props.timetable.current_month.map((d, i) =>
- <div
- key={i}
- className={'td-group' + (this.props.metas.day_types[d.wday] ? '' : ' out_from_daytypes') + (d.wday == 0 ? ' last_wday' : '')}
- >
- {/* day_types */}
- <div className="td"></div>
+ {this.props.timetable.current_month.map((d, i) =>
+ <div
+ key={i}
+ className={'td-group' + (this.props.metas.day_types[d.wday] ? '' : ' out_from_daytypes') + (d.wday == 0 ? ' last_wday' : '')}
+ >
+ {/* day_types */}
+ <div className="td"></div>
- {/* periods */}
- <PeriodsInDay
- index={i}
- value={this.props.timetable.time_table_periods}
- currentDate={this.currentDate(this.props.timetable.current_periode_range, d.mday)}
- onDeletePeriod={this.props.onDeletePeriod}
- onOpenEditPeriodForm={this.props.onOpenEditPeriodForm}
- metas={this.props.metas}
- />
+ {/* periods */}
+ <PeriodsInDay
+ index={i}
+ value={this.props.timetable.time_table_periods}
+ currentDate={this.currentDate(this.props.timetable.current_periode_range, d.mday)}
+ onDeletePeriod={this.props.onDeletePeriod}
+ onOpenEditPeriodForm={this.props.onOpenEditPeriodForm}
+ metas={this.props.metas}
+ />
- {/* exceptions */}
- <ExceptionsInDay
- index={i}
- value={this.props.timetable}
- metas={this.props.metas}
- outFromDaytypes={this.props.metas.day_types[d.wday]}
- onExcludeDateFromPeriod={this.props.onExcludeDateFromPeriod}
- onIncludeDateInPeriod={this.props.onIncludeDateInPeriod}
- />
- </div>
- )}
+ {/* exceptions */}
+ <ExceptionsInDay
+ index={i}
+ value={this.props.timetable}
+ metas={this.props.metas}
+ outFromDaytypes={this.props.metas.day_types[d.wday]}
+ onExcludeDateFromPeriod={this.props.onExcludeDateFromPeriod}
+ onIncludeDateInPeriod={this.props.onIncludeDateInPeriod}
+ />
+ </div>
+ )}
+ </div>
</div>
</div>
</div>
- </div>
- )
+ )
+ }
}
}
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee
index 458189b36..fc032f074 100644
--- a/app/assets/javascripts/routing_constraint_zones.coffee
+++ b/app/assets/javascripts/routing_constraint_zones.coffee
@@ -4,8 +4,10 @@ fill_stop_points_options = ->
referential_id = document.location.pathname.match(/\d+/g)[0]
line_id = document.location.pathname.match(/\d+/g)[1]
route_id = $('#routing_constraint_zone_route_id').val()
+
if errors_on_form()
- stop_point_ids = eval($('#stop_point_ids').val())
+ stop_point_ids = eval($('#stop_point_ids').val())
+
$.ajax
url: "/referentials/#{referential_id}/lines/#{line_id}/routes/#{route_id}/stop_points"
dataType: 'json'
@@ -21,7 +23,6 @@ errors_on_form = ->
document.location.pathname.endsWith('routing_constraint_zones') && $('#new_routing_constraint_zone').length
$(document).on 'turbolinks:load', ->
- if document.location.pathname.endsWith('new') || errors_on_form()
+ if document.location.pathname.endsWith('routing_constraint_zones/new') || errors_on_form()
fill_stop_points_options()
$('#routing_constraint_zone_route_id').change(fill_stop_points_options)
-
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index b23345607..487c14e9f 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -57,9 +57,10 @@ class TimeTablesController < ChouetteController
end
def update
- @time_table = Chouette::TimeTable.find_by_id(params[:id])
- @time_table.calendar_id = nil
- update!
+ state = JSON.parse request.raw_post
+ respond_to do |format|
+ format.json { render json: state, status: state['errors'] ? :unprocessable_entity : :ok }
+ end
end
def index
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index 086e6fa77..acce96681 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -32,6 +32,21 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
validates_associated :dates
validates_associated :periods
+ def state_update state
+ update_attributes(self.class.state_permited_attributes(state))
+
+ days = state['day_types'].split(',')
+ Date::DAYNAMES.map(&:underscore).each do |name|
+ prefix = human_attribute_name(name).first(2)
+ send("#{name}=", days.include?(prefix))
+ end
+ self.save
+ end
+
+ def self.state_permited_attributes item
+ item.slice('comment').to_hash
+ end
+
def presenter
@presenter ||= ::TimeTablePresenter.new( self)
end
diff --git a/lib/tasks/referential.rake b/lib/tasks/referential.rake
index caee2042a..9d98a048b 100644
--- a/lib/tasks/referential.rake
+++ b/lib/tasks/referential.rake
@@ -1,17 +1,22 @@
+# coding: utf-8
# execution example: rake 'referential:create[3, 1896, '01-01-2017', '01-04-2017']'
namespace :referential do
desc 'Create a referential and accompanying data'
task :create, [:workbench_id, :line_id, :start_date, :end_date] => [:environment] do |t, args|
+ args.with_defaults(start_date: Date.today.strftime, end_date: (Date.today + 30).strftime)
+
workbench = Workbench.find_by!(id: args[:workbench_id])
line = workbench.line_referential.lines.find_by!(id: args[:line_id])
name = "Referential #{Faker::Name.unique.name}"
+
referential = workbench.referentials.create!(name: name, slug: name.downcase.parameterize.underscore, organisation: workbench.organisation,
prefix: Faker::Lorem.unique.characters(10))
ReferentialMetadata.create!(referential: referential, line_ids: [args[:line_id]], periodes: [Date.parse(args[:start_date])..Date.parse(args[:end_date])])
referential.switch
- routes = []
+ puts "✓ Created Referential '#{name}' (#{referential.id})"
+
stop_areas = workbench.stop_area_referential.stop_areas.last(10)
4.times do |i|
@@ -28,29 +33,27 @@ namespace :referential do
end
route.save!
- journey_pattern = Chouette::JourneyPattern.create!(route: route, name: "Journey pattern #{Faker::Name.unique.name}")
+ journey_pattern = Chouette::JourneyPattern.create!(route: route, name: "Journey Pattern #{Faker::Name.unique.name}")
journey_pattern.stop_points = stop_areas.inject([]) { |stop_points, stop_area| stop_points += stop_area.stop_points }
+ time_tables = []
+ 2.times do |j|
+ name = "Test #{Faker::Name.unique.name}"
+ time_table = Chouette::TimeTable.create!(comment: name, start_date: Date.parse(args[:start_date]) + j.days,
+ end_date: Date.parse(args[:end_date]) - j.days)
+ time_tables << time_table
+ end
+
25.times do |j|
- vehicle_journey = Chouette::VehicleJourney.create!(journey_pattern: journey_pattern, route: route, number: Faker::Number.unique.number(4))
+ vehicle_journey = Chouette::VehicleJourney.create!(journey_pattern: journey_pattern, route: route, number: Faker::Number.unique.number(4), time_tables: time_tables)
time = Time.current.at_noon + j.minutes
journey_pattern.stop_points.each_with_index do |stop_point, k|
- vjas = Chouette::VehicleJourneyAtStop.create!(stop_point: stop_point, arrival_time: time + k.minutes, departure_time: time + k.minutes + 30.seconds)
+ vehicle_journey.vehicle_journey_at_stops.create!(stop_point: stop_point, arrival_time: time + k.minutes, departure_time: time + k.minutes + 30.seconds)
end
end
- 2.times do |j|
- name = "Calendar #{Faker::Name.unique.name}"
- calendar = Calendar.create!(name: name, short_name: name.parameterize, organisation: workbench.organisation,
- date_ranges: [(Date.parse(args[:start_date]) + j.days)..(Date.parse(args[:end_date]) - j.days)])
- Chouette::TimeTable.create!(comment: Faker::Lorem.sentence(3), calendar: calendar, start_date: Date.parse(args[:start_date]) + j.days,
- end_date: Date.parse(args[:end_date]) - j.days)
- end
end
+ referential.update(ready: true)
end
end
-
-
-
-
diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb
index a3a361e7b..fd9f70740 100644
--- a/spec/models/chouette/time_table_spec.rb
+++ b/spec/models/chouette/time_table_spec.rb
@@ -7,6 +7,29 @@ describe Chouette::TimeTable, :type => :model do
it { is_expected.to validate_presence_of :comment }
it { is_expected.to validate_uniqueness_of :objectid }
+ describe "Update state" do
+ def time_table_to_state time_table
+ time_table.slice('id', 'comment').tap do |item|
+ item['day_types'] = "Di,Lu,Ma,Me,Je,Ve,Sa"
+ end
+ end
+
+ let(:state) { time_table_to_state subject }
+
+ it 'should update comment' do
+ state['comment'] = "Edited timetable name"
+ subject.state_update state
+ expect(subject.reload.comment).to eq state['comment']
+ end
+
+ it 'should update day_types' do
+ state['day_types'] = "Di,Lu,Je,Ma"
+ subject.state_update state
+ expect(subject.reload.valid_days).to include(7, 1, 4, 2)
+ expect(subject.reload.valid_days).not_to include(3, 5, 6)
+ end
+ end
+
describe "#periods_max_date" do
context "when all period extends from 04/10/2013 to 04/15/2013," do
before(:each) do
@@ -1204,8 +1227,8 @@ end
expect(subject.dates[9].date).to eq(Date.new(2014,8,27))
end
end
-
-
+
+
context "with same definition : dsjointed timetable should be empty" do
before do
subject.periods.clear