diff options
| author | RobertDober | 2017-04-06 19:00:24 +0200 |
|---|---|---|
| committer | RobertDober | 2017-04-07 07:07:26 +0200 |
| commit | dc515f5eda324baae5a9583f1be433ac7dcd2915 (patch) | |
| tree | 850f26f59c5f9420bd3a1ed32179c6e5e20676e2 /app/controllers | |
| parent | 2a682f54f583a985809ba9ba1e33a1608f9f63b0 (diff) | |
| parent | 7ac766fb016108429730248f1a8bfd5065e8c31b (diff) | |
| download | chouette-core-dc515f5eda324baae5a9583f1be433ac7dcd2915.tar.bz2 | |
db:schema:dump
Diffstat (limited to 'app/controllers')
| -rw-r--r-- | app/controllers/autocomplete_stop_areas_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/imports_controller.rb | 1 | ||||
| -rw-r--r-- | app/controllers/journey_patterns_collections_controller.rb | 10 | ||||
| -rw-r--r-- | app/controllers/line_footnotes_controller.rb | 7 | ||||
| -rw-r--r-- | app/controllers/lines_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/referentials_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/routes_controller.rb | 26 | ||||
| -rw-r--r-- | app/controllers/routing_constraint_zones_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 22 | ||||
| -rw-r--r-- | app/controllers/workbenches_controller.rb | 45 |
10 files changed, 92 insertions, 27 deletions
diff --git a/app/controllers/autocomplete_stop_areas_controller.rb b/app/controllers/autocomplete_stop_areas_controller.rb index 6daa8a169..e35a545ae 100644 --- a/app/controllers/autocomplete_stop_areas_controller.rb +++ b/app/controllers/autocomplete_stop_areas_controller.rb @@ -10,7 +10,7 @@ class AutocompleteStopAreasController < InheritedResources::Base protected def collection - scope = referential.stop_areas + scope = referential.stop_areas.where(deleted_at: nil) scope = scope.physical if physical_filter? if target_type? scope = scope.where(area_type: params[:target_type]) diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 94fa9d944..70c5c1a0d 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,4 +1,5 @@ class ImportsController < BreadcrumbController + skip_before_action :authenticate_user!, only: [:download] defaults resource_class: Import, collection_name: 'imports', instance_name: 'import' respond_to :html belongs_to :workbench diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb index 51cc48c2a..2963a8ad7 100644 --- a/app/controllers/journey_patterns_collections_controller.rb +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -1,6 +1,7 @@ class JourneyPatternsCollectionsController < ChouetteController respond_to :html respond_to :json + before_action :user_permissions, only: :show belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line do @@ -41,6 +42,15 @@ class JourneyPatternsCollectionsController < ChouetteController @stop_points_list = @stop_points_list.sort_by {|a| a[:position] } end + def user_permissions + @perms = {}.tap do |perm| + ['journey_patterns.create', 'journey_patterns.edit', 'journey_patterns.destroy'].each do |name| + perm[name] = current_user.permissions.include?(name) + end + end + @perms = @perms.to_json + end + def update state = JSON.parse request.raw_post Chouette::JourneyPattern.state_update route, state diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index 8f7a38512..7bc048731 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -1,15 +1,15 @@ -class LineFootnotesController < ChouetteController - defaults :resource_class => Chouette::Line, :instance_name => 'line' +class LineFootnotesController < BreadcrumbController + defaults :resource_class => Chouette::Line include PolicyChecker before_action :check_policy, only: [:edit, :update, :destroy] respond_to :json, :only => :show - belongs_to :referential def show show! do build_breadcrumb :show end + @footnotes = @line.footnotes end def edit @@ -37,7 +37,6 @@ class LineFootnotesController < ChouetteController def resource @referential = Referential.find params[:referential_id] @line = @referential.lines.find params[:line_id] - @footnotes = @line.footnotes end def line_params diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index cce01e334..7eedaeb05 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -92,7 +92,7 @@ class LinesController < BreadcrumbController private def sort_column - line_referential.lines.column_names.include?(params[:sort]) ? params[:sort] : 'number' + (Chouette::Line.column_names + ['companies.name', 'networks.name']).include?(params[:sort]) ? params[:sort] : 'number' end def sort_direction %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc' diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index ed20a6d17..ce875b6ba 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,7 +1,7 @@ class ReferentialsController < BreadcrumbController defaults :resource_class => Referential include PolicyChecker - before_action :check_policy, :only => [:edit, :update] # overrides default + before_action :check_policy, :only => [:edit, :update, :archive, :unarchive] # overrides default respond_to :html respond_to :json, :only => :show diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 6a38b022d..a1aadf883 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -9,8 +9,7 @@ class RoutesController < ChouetteController belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line, :optional => true, :polymorphic => true end - - before_action :define_candidate_opposite_routes, only: [:new, :edit, :create, :update] + before_action :define_candidate_opposite_routes, only: [:new, :edit] def index index! do |format| @@ -66,11 +65,11 @@ class RoutesController < ChouetteController end end -# def update -# update! do |success, failure| -# success.html { redirect_to referential_line_path(@referential,@line) } -# end -# end + # def update + # update! do |success, failure| + # success.html { redirect_to referential_line_path(@referential,@line) } + # end + # end protected alias_method :route, :resource @@ -86,12 +85,13 @@ class RoutesController < ChouetteController end def define_candidate_opposite_routes - @candidate_opposite_routes = - if params[:id] - resource.line.routes.where("id <> ?", resource) - else - parent.routes.select(&:persisted?) - end + scope = if params[:id] + parent.routes.where(opposite_route: [nil, resource]).where('id <> ?', resource.id) + else + parent.routes.where(opposite_route: nil) + end + @forward = scope.where(wayback: :straight_forward) + @backward = scope.where(wayback: :backward) end private diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index c39c50326..bc3dcdfd4 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -11,7 +11,7 @@ class RoutingConstraintZonesController < ChouetteController private def routing_constraint_zone_params - params.require(:routing_constraint_zone).permit(:name, { stop_area_ids: [] }, :line_id, :objectid, :object_version, :creator_id) + params.require(:routing_constraint_zone).permit(:name, { stop_area_ids: [] }, :line_id, :route_id, :objectid, :object_version, :creator_id) end end diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index bdde5d3ab..50c925eac 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -117,6 +117,26 @@ class TimeTablesController < ChouetteController private def time_table_params - params.require(:time_table).permit( :objectid, :object_version, :creator_id, :calendar_id, :version, :comment, :int_day_types, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, :tag_list, :tag_search ) + params.require(:time_table).permit( + :objectid, + :object_version, + :creator_id, + :calendar_id, + :version, :comment, + :int_day_types, + :monday, + :tuesday, + :wednesday, + :thursday, + :friday, + :saturday, + :sunday, + :start_date, + :end_date, + { :dates_attributes => [:date, :in_out, :id, :_destroy] }, + { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, + {tag_list: []}, + :tag_search + ) end end diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index 7f108b266..1424fe03c 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -5,12 +5,17 @@ class WorkbenchesController < BreadcrumbController respond_to :html, only: [:show] def show - scope = params[:q] ? resource.all_referentials : resource.referentials.ready + scope = resource.all_referentials scope = ransack_associated_lines(scope) + scope = ransack_periode(scope) + scope = ransack_status(scope) - @q = ransack_periode(scope).ransack(params[:q]) - @q.organisation_name_eq_any ||= current_organisation.name unless params[:q] - @wbench_refs = sort_result(@q.result).paginate(page: params[:page], per_page: 30) + # Ignore archived_at_not_null/archived_at_null managed by ransack_status scope + q_for_result = + scope.ransack(params[:q].merge(archived_at_not_null: nil, archived_at_null: nil)) + @wbench_refs = sort_result(q_for_result.result).paginate(page: params[:page], per_page: 30) + + @q = scope.ransack(params[:q]) show! do build_breadcrumb :show end @@ -44,6 +49,8 @@ class WorkbenchesController < BreadcrumbController 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 end @@ -68,8 +75,36 @@ class WorkbenchesController < BreadcrumbController if begin_range > end_range flash.now[:error] = t('referentials.errors.validity_period') else - scope = scope.in_periode(begin_range..end_range) + scope = scope.in_periode(begin_range..end_range) + @begin_range = begin_range + @end_range = end_range + end + scope + end + + # Fake (again) 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 + + 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 + scope end end |
