diff options
| author | Florent Peyraud | 2017-07-06 12:42:53 +0200 |
|---|---|---|
| committer | Florent Peyraud | 2017-07-06 12:42:53 +0200 |
| commit | e3f7a67d922614363fe798992af4f656b77f0eb5 (patch) | |
| tree | 81c00cf3094d724c91f428035ea9e540c377a7bf /app/controllers | |
| parent | 3c39ff76da22a410f1c81acabad626f15a63d800 (diff) | |
| parent | 74e94da83d6ea64dcb1e70e69c2fef046453e4a1 (diff) | |
| download | chouette-core-e3f7a67d922614363fe798992af4f656b77f0eb5.tar.bz2 | |
Merge branch 'master' of github.com:AF83/stif-boiv
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/autocomplete_calendars_controller.rb | 3 | ||||
| -rw-r--r-- | app/controllers/lines_controller.rb | 9 | ||||
| -rw-r--r-- | app/controllers/routing_constraint_zones_controller.rb | 41 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 4 | ||||
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 88 |
5 files changed, 75 insertions, 70 deletions
diff --git a/app/controllers/autocomplete_calendars_controller.rb b/app/controllers/autocomplete_calendars_controller.rb index 2b85fcff3..533b5503a 100644 --- a/app/controllers/autocomplete_calendars_controller.rb +++ b/app/controllers/autocomplete_calendars_controller.rb @@ -2,6 +2,7 @@ class AutocompleteCalendarsController < ApplicationController respond_to :json, :only => [:autocomplete] def autocomplete - @calendars = current_organisation.calendars.search(params[:q]).result.paginate(page: params[:page]) + scope = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id) + @calendars = scope.search(params[:q]).result.paginate(page: params[:page]) end end diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index 1e2056aad..4b6448ce8 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -13,6 +13,15 @@ class LinesController < BreadcrumbController def index @hide_group_of_line = line_referential.group_of_lines.empty? index! do |format| + @lines = ModelDecorator.decorate( + @lines, + with: LineDecorator, + context: { + line_referential: @line_referential, + current_organisation: current_organisation + } + ) + format.html { if collection.out_of_bounds? redirect_to params.merge(:page => 1) diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index 6fb5348f0..1eb2ddf28 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -4,14 +4,33 @@ class RoutingConstraintZonesController < ChouetteController defaults resource_class: Chouette::RoutingConstraintZone respond_to :html, :xml, :json - before_action :check_stoppoint_param, only: [:create, :update] + # before_action :check_stoppoint_param, only: [:create, :update] belongs_to :referential do belongs_to :line, parent_class: Chouette::Line end + def show + show! do |format| + @routing_constraint_zone = @routing_constraint_zone.decorate(context: { + referential: current_referential, + line: parent.id + }) + end + end + + def new + new! do |format| + format.html + @route = @line.routes.find params[:route_id] if params[:route_id] + format.js + end + end + protected + alias_method :routing_constraint_zone, :resource + def collection @q = current_referential.routing_constraint_zones.search(params[:q]) @@ -25,26 +44,6 @@ class RoutingConstraintZonesController < ChouetteController end end - def resource - @routing_constraint_zone ||= begin - routing_constraint_zone = current_referential.routing_constraint_zones.find(params[:id]) - routing_constraint_zone = routing_constraint_zone.decorate(context: { - referential: current_referential, - line: parent.id - }) - end - end - - def build_resource - @routing_constraint_zone ||= begin - routing_constraint_zone = current_referential.routing_constraint_zones.new - routing_constraint_zone = routing_constraint_zone.decorate(context: { - referential: current_referential, - line: parent.id - }) - end - end - private def sort_column (Chouette::RoutingConstraintZone.column_names).include?(params[:sort]) ? params[:sort] : 'name' diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 3704f2885..6d2639981 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -49,8 +49,8 @@ class TimeTablesController < ChouetteController calendar.dates.each_with_index do |date, i| @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i, in_out: true) end - calendar.date_ranges.each_with_index do |date_range, i| - @time_table.periods << Chouette::TimeTablePeriod.new(period_start: date_range.begin, period_end: date_range.end, position: i) + calendar.periods.each_with_index do |period, i| + @time_table.periods << Chouette::TimeTablePeriod.new(period_start: period.begin, period_end: period.end, position: i) end end diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index d03841356..22a71863a 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -7,21 +7,13 @@ class WorkbenchesController < BreadcrumbController def show scope = resource.all_referentials scope = ransack_associated_lines(scope) - scope = ransack_periode(scope) + scope = ransack_period(scope) scope = ransack_status(scope) - # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope - # We clone params[:q] so we can delete fake ransack filter arguments before calling search method, - # which will allow us to preserve params[:q] for sorting - ransack_params = params[:q].merge(archived_at_not_null: nil, archived_at_null: nil).clone - ransack_params.delete('associated_lines_id_eq') - - @q = scope.ransack(ransack_params) - @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30) - @wbench_refs = ModelDecorator.decorate( - @wbench_refs, - with: ReferentialDecorator - ) + @q_for_form = scope.ransack(params[:q]) + @q_for_result = scope.ransack(ransack_params) + @wbench_refs = sort_result(@q_for_result.result).paginate(page: params[:page], per_page: 30) + @wbench_refs = ModelDecorator.decorate(@wbench_refs, with: ReferentialDecorator) show! do build_breadcrumb :show @@ -55,29 +47,34 @@ class WorkbenchesController < BreadcrumbController end def query_params - if params[:q].present? - params[:q].delete_if { |query, value| value.blank? } - else - params[:q] = { "archived_at_not_null"=>"1", "archived_at_null"=>"1" } - end + params[:q] ||= {} + params[:q].delete_if { |query, value| value.blank? } end # Fake ransack filter def ransack_associated_lines scope - if params[:q] && params[:q]['associated_lines_id_eq'] + if params[:q]['associated_lines_id_eq'] scope = scope.include_metadatas_lines([params[:q]['associated_lines_id_eq']]) end scope end # Fake ransack filter - def ransack_periode scope - return scope unless params[:q] && params[:q]['validity_period'] - periode = params[:q]['validity_period'] - return scope if periode['end_lteq(1i)'].blank? || periode['begin_gteq(1i)'].blank? - - begin_range = Date.civil(periode["begin_gteq(1i)"].to_i, periode["begin_gteq(2i)"].to_i, periode["begin_gteq(3i)"].to_i) - end_range = Date.civil(periode["end_lteq(1i)"].to_i, periode["end_lteq(2i)"].to_i, periode["end_lteq(3i)"].to_i) + def ransack_period scope + period = params[:q]['validity_period'] + return scope unless period + + begin + if period['begin_gteq'].kind_of?(Array) + begin_range = Date.new(*period['begin_gteq'].map(&:to_i)) + end_range = Date.new(*period['end_lteq'].map(&:to_i)) + else + begin_range = Date.new(period["begin_gteq(1i)"].to_i, period["begin_gteq(2i)"].to_i, period["begin_gteq(3i)"].to_i) + end_range = Date.new(period["end_lteq(1i)"].to_i, period["end_lteq(2i)"].to_i, period["end_lteq(3i)"].to_i) + end + rescue Exception => e + return scope + end if begin_range > end_range flash.now[:error] = t('referentials.errors.validity_period') @@ -89,29 +86,28 @@ class WorkbenchesController < BreadcrumbController scope end - # Fake (again) ransack filter + # Fake ransack filter def ransack_status scope - return scope unless params[:q] - - archived_at_not_null = params[:q]['archived_at_not_null'] == '1' - archived_at_null = params[:q]['archived_at_null'] == '1' - - if !archived_at_not_null and !archived_at_null - return scope.none - end + archived = !params[:q]['archived_at_not_null'].to_i.zero? + unarchived = !params[:q]['archived_at_null'].to_i.zero? - if archived_at_not_null and archived_at_null - return scope - end - - if archived_at_null - return scope.where(archived_at: nil) - end - - if archived_at_not_null - return scope.where("archived_at is not null") - end + # Both status checked, means no filter + return scope unless archived || unarchived + return scope if archived && unarchived + scope = scope.where(archived_at: nil) if unarchived + scope = scope.where("archived_at is not null") if archived scope end + + # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope + # We clone params[:q] so we can delete fake ransack filter arguments before calling search method, + # which will allow us to preserve params[:q] for sorting + def ransack_params + copy_params = params[:q].clone + copy_params.delete('associated_lines_id_eq') + copy_params.delete('archived_at_not_null') + copy_params.delete('archived_at_null') + copy_params + end end |
