diff options
| author | Thomas Haddad | 2017-01-04 11:10:15 +0100 |
|---|---|---|
| committer | Thomas Haddad | 2017-01-04 11:10:15 +0100 |
| commit | 9c08e8f9f42906f9be17a8fbce7fcd83dbd51179 (patch) | |
| tree | 65e132910ffadab7534f4b5ad2257539f06b309b /app/controllers | |
| parent | 9560056852d1d48767c5ed150bce4e3abffcca00 (diff) | |
| parent | 66dc68487a6e8a826ec4d4ffcee2f34456488dea (diff) | |
| download | chouette-core-9c08e8f9f42906f9be17a8fbce7fcd83dbd51179.tar.bz2 | |
Merge branch 'mission_redux'
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/journey_patterns_collections_controller.rb | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb new file mode 100644 index 000000000..39355932e --- /dev/null +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -0,0 +1,51 @@ +class JourneyPatternsCollectionsController < ChouetteController + respond_to :html + respond_to :json + + belongs_to :referential do + belongs_to :line, :parent_class => Chouette::Line do + belongs_to :route, :parent_class => Chouette::Route + end + end + alias_method :route, :parent + + def show + journey_patterns_state + end + + def update + state = JSON.parse request.raw_post + state.each do |item| + journey_pattern = journey_pattern_by_objectid(item['object_id']) + journey_pattern_update_stop_points(journey_pattern, item['stop_points']) if journey_pattern + end + + journey_patterns_state + end + + protected + + def journey_pattern_update_stop_points journey_pattern, stop_points + stop_points.each do |sp| + stop_id = sp['id'] + exist = journey_pattern.stop_area_ids.include?(stop_id) + next if exist && sp['checked'] + + stop_point = route.stop_points.find_by(stop_area_id: stop_id) + if sp['checked'] && !exist + journey_pattern.stop_points << stop_point + else + journey_pattern.stop_points.delete(stop_point) + end + end + end + + def journey_patterns_state + @q = route.journey_patterns.includes(:stop_points) + @journey_patterns ||= @q.paginate(:page => params[:page]).order(:name) + end + + def journey_pattern_by_objectid objectid + Chouette::JourneyPattern.find_by(objectid: objectid) + end +end |
