From 9b95304792865eb05305d8fea01c634a5c5d1829 Mon Sep 17 00:00:00 2001 From: Robert Date: Tue, 2 May 2017 12:15:09 +0200 Subject: Refs #3053 passes current_organization down from the controller into Reference.new_from adds joint models *ReferenceMemeberships to excluded Apartment models --- app/controllers/referentials_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index f46cd188d..437444f29 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -8,7 +8,10 @@ class ReferentialsController < BreadcrumbController respond_to :js, :only => :show def new - @referential = Referential.new_from(Referential.find(params[:from])) if params[:from] + if params[:from] + source_referential = Referential.find(params[:from]) + @referential = Referential.new_from(source_referential, organisation: current_organisation) + end new! do @referential.data_format = current_organisation.data_format -- cgit v1.2.3 From e9a07b3d9208e4adba0947fd46c931472244ea9e Mon Sep 17 00:00:00 2001 From: jpl Date: Tue, 2 May 2017 13:04:54 +0200 Subject: RefsĀ #3264: change shared boolean filter by select (to permit join) --- app/controllers/calendars_controller.rb | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index c33aa9373..d18e165d2 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -33,8 +33,12 @@ class CalendarsController < BreadcrumbController def collection return @calendars if @calendars + scope = Calendar.where('organisation_id = ?', current_organisation.id) + + scope = shared_scope(scope) + + @q = scope.ransack(params[:q]) - @q = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).search(params[:q]) calendars = @q.result calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction @calendars = calendars.paginate(page: params[:page]) @@ -51,5 +55,16 @@ class CalendarsController < BreadcrumbController params[:q]['contains_date'] = Date.parse(date.join('-')) end end -end + def shared_scope scope + return scope unless params[:q] + + if params[:q][:shared_true] == params[:q][:shared_false] + params[:q].delete(:shared_true) + params[:q].delete(:shared_false) + end + + scope + end + +end -- cgit v1.2.3 From b6a0ea532f9c75da693ba1a012327807976a3e27 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Tue, 2 May 2017 15:44:25 +0200 Subject: Duplicate TimeTable Refs #3188 --- app/controllers/time_tables_controller.rb | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 3b8e390b6..8436dc020 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -37,7 +37,10 @@ class TimeTablesController < ChouetteController calendar = current_organisation.calendars.find_by_id(tt_params[:calendar_id]) tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes) end - @time_table = Chouette::TimeTable.new(tt_params) + + created_from = duplicate_source + @time_table = created_from ? created_from.duplicate : Chouette::TimeTable.new(tt_params) + if calendar calendar.dates.each_with_index do |date, i| @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i) @@ -48,7 +51,10 @@ class TimeTablesController < ChouetteController end create! do |success, failure| - success.html { redirect_to edit_referential_time_table_path(@referential, @time_table) } + success.html do + path = @time_table.created_from ? 'referential_time_table_path' : 'edit_referential_time_table_path' + redirect_to send(path, @referential, @time_table) + end failure.html { render :new } end end @@ -158,6 +164,11 @@ class TimeTablesController < ChouetteController %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' end + def duplicate_source + from_id = time_table_params['created_from_id'] + Chouette::TimeTable.find(from_id) if from_id + end + def time_table_params params.require(:time_table).permit( :objectid, @@ -175,6 +186,7 @@ class TimeTablesController < ChouetteController :sunday, :start_date, :end_date, + :created_from_id, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, {tag_list: []}, -- cgit v1.2.3 From a75b51bc9b4112d851a38f0e569565ce2c4602c6 Mon Sep 17 00:00:00 2001 From: Robert Date: Thu, 4 May 2017 14:36:25 +0200 Subject: easy change locale for testing and developping translations --- app/controllers/application_controller.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'app/controllers') diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index f2c9b4c6f..42b7c2a25 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -12,7 +12,10 @@ class ApplicationController < ActionController::Base helper LanguageEngine::Engine.helpers def set_locale - I18n.locale = session[:language] || I18n.default_locale + # I18n.locale = session[:language] || I18n.default_locale + # For testing different locales w/o restarting the server + I18n.locale = (params['lang'] || session[:language] || I18n.default_locale).to_sym + logger.info "locale set to #{I18n.locale.inspect}" end def pundit_user -- cgit v1.2.3 From b54ab0a2321bbd0c5c6162a0d313800bb586a98d Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 4 May 2017 15:22:57 +0200 Subject: Fix can't edit or create calendar due to 3 parts date_select Refs #3298 --- app/controllers/calendars_controller.rb | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index d18e165d2..5370d9cbb 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -45,14 +45,13 @@ class CalendarsController < BreadcrumbController end def ransack_contains_date - # 3 parts to date object, in order to use in ransackable_scopes + date =[] if params[:q] && !params[:q]['contains_date(1i)'].empty? - date =[] ['contains_date(1i)', 'contains_date(2i)', 'contains_date(3i)'].each do |key| - date << params[:q][key] + date << params[:q][key].to_i params[:q].delete(key) end - params[:q]['contains_date'] = Date.parse(date.join('-')) + params[:q]['contains_date'] = Date.new(*date) end end -- cgit v1.2.3 From 4c12a6632907d5d24b654791db994bfb830c7e37 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 15:14:44 +0200 Subject: VehicleJourneysCtl#collection: Sort journeys by departure time ascending Correctly sort journeys. They used to be sorted correctly this way, but after d7c6d5ce602219b9bfa47686542dd575f1fe2e50 or c3d207301d17538b65d2a1239ce0acf642942ce9, the sorting got messed up because of the join. Here we leverage `journey_patterns.departure_stop_point_id` in order to get the first stop and sort by that stop's departure time. Query solution thanks to Luc and Alban, who remembered that a reference to the first stop point is stored so we can leverage that for complex things like this. Refs #3268 --- app/controllers/vehicle_journeys_controller.rb | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index c084b592a..f692f3628 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -77,14 +77,22 @@ class VehicleJourneysController < ChouetteController protected def collection - scope = route.vehicle_journeys.joins(:journey_pattern).joins('LEFT JOIN "vehicle_journey_at_stops" ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id"') + scope = route.vehicle_journeys + .joins(:journey_pattern) + .joins(' + LEFT JOIN "vehicle_journey_at_stops" + ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id" + AND "vehicle_journey_at_stops"."stop_point_id" = + "journey_patterns"."departure_stop_point_id" + ') + .order("vehicle_journey_at_stops.departure_time") @q = scope.search filtered_ransack_params grouping = ransack_periode_filter @q.build_grouping(grouping) if grouping @ppage = 20 - @vehicle_journeys = @q.result(distinct: true).paginate(:page => params[:page], :per_page => @ppage) + @vehicle_journeys = @q.result.paginate(:page => params[:page], :per_page => @ppage) @footnotes = route.line.footnotes.to_json @matrix = resource_class.matrix(@vehicle_journeys) @vehicle_journeys -- cgit v1.2.3 From 76abc55ed7aeb07cf65ed2a027ad2cdc694c5751 Mon Sep 17 00:00:00 2001 From: Teddy Wing Date: Thu, 4 May 2017 17:18:05 +0200 Subject: VehicleJourneysCtl#collection: Use VehicleJourney.with_stops Use the class method to get the vehicle journeys in the proper order of departure time ascending. The `.with_stops` method replicates this same SQL sequence of joins and order. Refs #3268 --- app/controllers/vehicle_journeys_controller.rb | 10 +--------- 1 file changed, 1 insertion(+), 9 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index f692f3628..316652ca2 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -77,15 +77,7 @@ class VehicleJourneysController < ChouetteController protected def collection - scope = route.vehicle_journeys - .joins(:journey_pattern) - .joins(' - LEFT JOIN "vehicle_journey_at_stops" - ON "vehicle_journey_at_stops"."vehicle_journey_id" = "vehicle_journeys"."id" - AND "vehicle_journey_at_stops"."stop_point_id" = - "journey_patterns"."departure_stop_point_id" - ') - .order("vehicle_journey_at_stops.departure_time") + scope = route.vehicle_journeys.with_stops @q = scope.search filtered_ransack_params grouping = ransack_periode_filter -- cgit v1.2.3 From 6e925a3a2516aa11682cb178fcb903a7aa169ed0 Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 12:20:43 +0200 Subject: Refs: #3297 removed patch of inherited_resources in RoutesController --- app/controllers/routes_controller.rb | 5 ----- 1 file changed, 5 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index a1aadf883..f914a102b 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,11 +46,6 @@ class RoutesController < ChouetteController end end - # overwrite inherited resources to use delete instead of destroy - # foreign keys will propagate deletion) - def destroy_resource(object) - object.delete - end def destroy destroy! do |success, failure| -- cgit v1.2.3 From 41b9b5decf022e748c6577baf9756bd785149e6f Mon Sep 17 00:00:00 2001 From: Robert Date: Fri, 5 May 2017 16:52:32 +0200 Subject: Refs #3297 Nullification of foreign keys in delete route moved from an `after_destroy' to a `before_destroy' hook. (Motivation: Seemed like a good idea) --- app/controllers/routes_controller.rb | 2 ++ 1 file changed, 2 insertions(+) (limited to 'app/controllers') diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index f914a102b..5a73d397c 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,6 +46,8 @@ class RoutesController < ChouetteController end end + # overwrite inherited resources to use delete instead of destroy + # foreign keys will propagate deletion) def destroy destroy! do |success, failure| -- cgit v1.2.3 From 95776acb5113d3a44044e74c06b1dbf9df0e1ec8 Mon Sep 17 00:00:00 2001 From: Robert Date: Sat, 6 May 2017 06:03:19 +0200 Subject: minor esthetic correction --- app/controllers/routes_controller.rb | 3 --- 1 file changed, 3 deletions(-) (limited to 'app/controllers') diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 5a73d397c..73febc4b9 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -46,9 +46,6 @@ class RoutesController < ChouetteController end end - # overwrite inherited resources to use delete instead of destroy - # foreign keys will propagate deletion) - def destroy destroy! do |success, failure| success.html { redirect_to referential_line_path(@referential,@line) } -- cgit v1.2.3