aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers
diff options
context:
space:
mode:
Diffstat (limited to 'app/controllers')
-rw-r--r--app/controllers/api_keys_controller.rb7
-rw-r--r--app/controllers/application_controller.rb19
-rw-r--r--app/controllers/autocomplete_purchase_windows_controller.rb12
-rw-r--r--app/controllers/autocomplete_stop_areas_controller.rb11
-rw-r--r--app/controllers/calendars_controller.rb75
-rw-r--r--app/controllers/companies_controller.rb10
-rw-r--r--app/controllers/compliance_check_messages_controller.rb34
-rw-r--r--app/controllers/compliance_check_sets_controller.rb22
-rw-r--r--app/controllers/compliance_control_sets_controller.rb50
-rw-r--r--app/controllers/compliance_controls_controller.rb6
-rw-r--r--app/controllers/concerns/activatable.rb11
-rw-r--r--app/controllers/concerns/feature_checker.rb42
-rw-r--r--app/controllers/concerns/ransack_date_filter.rb28
-rw-r--r--app/controllers/development_toolbar_controller.rb11
-rw-r--r--app/controllers/group_of_lines_controller.rb5
-rw-r--r--app/controllers/import_messages_controller.rb2
-rw-r--r--app/controllers/import_resources_controller.rb8
-rw-r--r--app/controllers/imports_controller.rb3
-rw-r--r--app/controllers/journey_patterns_collections_controller.rb67
-rw-r--r--app/controllers/line_referentials_controller.rb1
-rw-r--r--app/controllers/lines_controller.rb10
-rw-r--r--app/controllers/merges_controller.rb40
-rw-r--r--app/controllers/networks_controller.rb7
-rw-r--r--app/controllers/purchase_windows_controller.rb74
-rw-r--r--app/controllers/referential_companies_controller.rb10
-rw-r--r--app/controllers/referential_lines_controller.rb3
-rw-r--r--app/controllers/referential_networks_controller.rb7
-rw-r--r--app/controllers/referential_vehicle_journeys_controller.rb30
-rw-r--r--app/controllers/referentials_controller.rb29
-rw-r--r--app/controllers/routes_controller.rb5
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb3
-rw-r--r--app/controllers/snapshots_controller.rb14
-rw-r--r--app/controllers/statuses_controller.rb20
-rw-r--r--app/controllers/stop_area_referentials_controller.rb1
-rw-r--r--app/controllers/stop_areas_controller.rb56
-rw-r--r--app/controllers/time_tables_controller.rb5
-rw-r--r--app/controllers/vehicle_journeys_controller.rb129
-rw-r--r--app/controllers/workbench_outputs_controller.rb9
-rw-r--r--app/controllers/workbenches_controller.rb3
39 files changed, 694 insertions, 185 deletions
diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb
index 9706c5961..a03a67481 100644
--- a/app/controllers/api_keys_controller.rb
+++ b/app/controllers/api_keys_controller.rb
@@ -31,11 +31,4 @@ class ApiKeysController < ChouetteController
def api_key_params
params.require(:api_key).permit(:name, :referential_id)
end
-
- def decorate_api_keys(api_keys)
- ModelDecorator.decorate(
- api_keys,
- with: ApiKeyDecorator,
- )
- end
end
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 97f5548ae..8bd3da2f9 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -1,6 +1,7 @@
class ApplicationController < ActionController::Base
include PaperTrailSupport
include Pundit
+ include FeatureChecker
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
@@ -40,12 +41,30 @@ class ApplicationController < ActionController::Base
end
helper_method :current_offer_workbench
+ def current_workgroup
+ current_offer_workbench.workgroup
+ end
+ helper_method :current_workgroup
+
def current_functional_scope
functional_scope = current_organisation.sso_attributes.try(:[], "functional_scope") if current_organisation
JSON.parse(functional_scope) if functional_scope
end
helper_method :current_functional_scope
+ def collection_name
+ self.class.name.split("::").last.gsub('Controller', '').underscore
+ end
+
+ def decorated_collection
+ if instance_variable_defined?("@#{collection_name}")
+ instance_variable_get("@#{collection_name}")
+ else
+ nil
+ end
+ end
+ helper_method :decorated_collection
+
def begin_of_association_chain
current_organisation
end
diff --git a/app/controllers/autocomplete_purchase_windows_controller.rb b/app/controllers/autocomplete_purchase_windows_controller.rb
new file mode 100644
index 000000000..70dc5a346
--- /dev/null
+++ b/app/controllers/autocomplete_purchase_windows_controller.rb
@@ -0,0 +1,12 @@
+class AutocompletePurchaseWindowsController < ChouetteController
+ respond_to :json, :only => [:index]
+
+ requires_feature :purchase_windows
+
+ include ReferentialSupport
+
+ protected
+ def collection
+ @purchase_windows = referential.purchase_windows.search(params[:q]).result.paginate(page: params[:page])
+ end
+end
diff --git a/app/controllers/autocomplete_stop_areas_controller.rb b/app/controllers/autocomplete_stop_areas_controller.rb
index 233012028..79154a6e0 100644
--- a/app/controllers/autocomplete_stop_areas_controller.rb
+++ b/app/controllers/autocomplete_stop_areas_controller.rb
@@ -17,13 +17,20 @@ class AutocompleteStopAreasController < ChouetteController
scope = scope.possible_parents if relation_parent?
scope = scope.possible_parents if relation_children?
end
+ if search_scope.present?
+ scope = StopAreaPolicy::Scope.new(current_user, scope).search_scope(search_scope)
+ end
args = [].tap{|arg| 4.times{arg << "%#{params[:q]}%"}}
- @stop_areas = scope.where("name ILIKE ? OR city_name ILIKE ? OR registration_number ILIKE ? OR objectid ILIKE ?", *args).limit(50)
+ @stop_areas = scope.where("unaccent(stop_areas.name) ILIKE unaccent(?) OR unaccent(stop_areas.city_name) ILIKE unaccent(?) OR stop_areas.registration_number ILIKE ? OR stop_areas.objectid ILIKE ?", *args).limit(50)
@stop_areas
end
def target_type?
- params.has_key?( :target_type)
+ params.has_key?(:target_type)
+ end
+
+ def search_scope
+ params[:scope]
end
def relation_parent?
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 2ed10a111..75d4cbd09 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -1,25 +1,69 @@
class CalendarsController < ChouetteController
include PolicyChecker
+ include TimeTablesHelper
+
defaults resource_class: Calendar
before_action :ransack_contains_date, only: [:index]
respond_to :html
+ respond_to :json, only: :show
respond_to :js, only: :index
+ belongs_to :workgroup
+
def index
index! do
- @calendars = ModelDecorator.decorate(@calendars, with: CalendarDecorator)
+ @calendars = decorate_calendars(@calendars)
end
end
def show
show! do
- @calendar = @calendar.decorate
+ @year = params[:year] ? params[:year].to_i : Date.today.cwyear
+ @calendar = @calendar.decorate(context: {
+ workgroup: workgroup
+ })
+ end
+ end
+
+ def month
+ @date = params['date'] ? Date.parse(params['date']) : Date.today
+ @calendar = resource
+ end
+
+ def create
+ create! do
+ if @calendar.valid? && has_feature?('application_days_on_calendars')
+ redirect_to([:edit, @calendar])
+ return
+ end
+ end
+ end
+
+ def update
+ if params[:calendar]
+ super
+ else
+ state = JSON.parse request.raw_post
+ resource.state_update state
+ respond_to do |format|
+ format.json { render json: state, status: state['errors'] ? :unprocessable_entity : :ok }
+ end
end
end
private
+
+ def decorate_calendars(calendars)
+ CalendarDecorator.decorate(
+ calendars,
+ context: {
+ workgroup: workgroup
+ }
+ )
+ end
+
def calendar_params
- permitted_params = [:id, :name, :short_name, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]
+ permitted_params = [:id, :name, :short_name, :shared, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]
permitted_params << :shared if policy(Calendar).share?
params.require(:calendar).permit(*permitted_params)
end
@@ -33,25 +77,30 @@ class CalendarsController < ChouetteController
end
protected
+
+ alias_method :workgroup, :parent
+ helper_method :workgroup
+
def resource
- @calendar = Calendar.where('organisation_id = ? OR shared = true', current_organisation.id).find_by_id(params[:id])
+ @calendar ||= workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true).find_by_id(params[:id])
end
def build_resource
super.tap do |calendar|
+ calendar.workgroup = workgroup
calendar.organisation = current_organisation
end
end
def collection
- return @calendars if @calendars
- scope = Calendar.where('organisation_id = ? OR shared = ?', current_organisation.id, true)
- scope = shared_scope(scope)
- @q = scope.ransack(params[:q])
-
- calendars = @q.result
- calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
- @calendars = calendars.paginate(page: params[:page])
+ @calendars ||= begin
+ scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true)
+ scope = shared_scope(scope)
+ @q = scope.ransack(params[:q])
+ calendars = @q.result
+ calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ calendars = calendars.paginate(page: params[:page])
+ end
end
def ransack_contains_date
@@ -76,4 +125,4 @@ class CalendarsController < ChouetteController
scope
end
-end
+end \ No newline at end of file
diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb
index 931d846c5..4afd12be1 100644
--- a/app/controllers/companies_controller.rb
+++ b/app/controllers/companies_controller.rb
@@ -47,6 +47,9 @@ class CompaniesController < ChouetteController
end
end
+ def resource
+ super.decorate(context: { referential: line_referential })
+ end
def resource_url(company = nil)
line_referential_company_path(line_referential, company || resource)
@@ -61,6 +64,10 @@ class CompaniesController < ChouetteController
alias_method :current_referential, :line_referential
helper_method :current_referential
+ def begin_of_association_chain
+ current_organisation
+ end
+
def company_params
params.require(:company).permit( :objectid, :object_version, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone )
end
@@ -75,9 +82,8 @@ class CompaniesController < ChouetteController
end
def decorate_companies(companies)
- ModelDecorator.decorate(
+ CompanyDecorator.decorate(
companies,
- with: CompanyDecorator,
context: {
referential: line_referential
}
diff --git a/app/controllers/compliance_check_messages_controller.rb b/app/controllers/compliance_check_messages_controller.rb
new file mode 100644
index 000000000..7c416584e
--- /dev/null
+++ b/app/controllers/compliance_check_messages_controller.rb
@@ -0,0 +1,34 @@
+class ComplianceCheckMessagesController < ChouetteController
+ defaults resource_class: ComplianceCheckMessage, collection_name: 'compliance_check_messages', instance_name: 'compliance_check_message'
+ respond_to :csv
+ belongs_to :compliance_check_set, :parent_class => ComplianceCheckSet
+
+
+ def index
+ index! do |format|
+ format.csv {
+ send_data ComplianceCheckMessageExport.new(compliance_check_messages: collection).to_csv(:col_sep => "\;", :quote_char=>'"', force_quotes: true, server_url: request.base_url) , :filename => "compliance_check_set_errors_#{line_code}_#{Time.now.to_i}.csv"
+ }
+ end
+ end
+
+ protected
+ def collection
+ parent.compliance_check_messages.where(compliance_check_resource_id: params[:compliance_check_resource_id])
+ end
+
+ def parent
+ @compliance_check_set ||= ComplianceCheckSet.find(params[:compliance_check_set_id])
+ end
+
+ def compliance_check_resource
+ ComplianceCheckResource.find(params[:compliance_check_resource_id])
+ end
+
+ private
+
+ def line_code
+ Chouette::Line.find_by_objectid("#{compliance_check_resource.reference}").get_objectid.local_id
+ end
+
+end
diff --git a/app/controllers/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb
index 600c69126..271598428 100644
--- a/app/controllers/compliance_check_sets_controller.rb
+++ b/app/controllers/compliance_check_sets_controller.rb
@@ -11,9 +11,8 @@ class ComplianceCheckSetsController < ChouetteController
scope = self.ransack_period_range(scope: @compliance_check_sets, error_message: t('compliance_check_sets.filters.error_period_filter'), query: :where_created_at_between)
@q_for_form = scope.ransack(params[:q])
format.html {
- @compliance_check_sets = ModelDecorator.decorate(
- @q_for_form.result.order(created_at: :desc),
- with: ComplianceCheckSetDecorator
+ @compliance_check_sets = ComplianceCheckSetDecorator.decorate(
+ @q_for_form.result.order(created_at: :desc)
)
}
end
@@ -21,9 +20,7 @@ class ComplianceCheckSetsController < ChouetteController
def show
show! do
- @compliance_check_set = @compliance_check_set.decorate(context: {
- compliance_check_set: @compliance_check_set
- })
+ @compliance_check_set = @compliance_check_set.decorate
end
end
@@ -43,18 +40,9 @@ class ComplianceCheckSetsController < ChouetteController
def executed_for_html
@q_checks_form = @compliance_check_set.compliance_checks.ransack(params[:q])
@compliance_check_set = @compliance_check_set.decorate
- compliance_checks =
- decorate_compliance_checks( @q_checks_form.result)
- .group_by(&:compliance_check_block)
+ compliance_checks = @q_checks_form.result
+ .group_by(&:compliance_check_block)
@direct_compliance_checks = compliance_checks.delete nil
@blocks_to_compliance_checks_map = compliance_checks
end
-
- # Decoration
- # ----------
- def decorate_compliance_checks(compliance_checks)
- ModelDecorator.decorate(
- compliance_checks,
- with: ComplianceCheckDecorator)
- end
end
diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb
index 2d3d03ad0..8f9251155 100644
--- a/app/controllers/compliance_control_sets_controller.rb
+++ b/app/controllers/compliance_control_sets_controller.rb
@@ -7,10 +7,8 @@ class ComplianceControlSetsController < ChouetteController
def index
index! do |format|
- scope = self.ransack_period_range(scope: @compliance_control_sets, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between)
- @q_for_form = scope.ransack(params[:q])
format.html {
- @compliance_control_sets = decorate_compliance_control_sets(@q_for_form.result.paginate(page: params[:page], per_page: 30))
+ @compliance_control_sets = decorate_compliance_control_sets(@compliance_control_sets)
}
end
end
@@ -37,18 +35,20 @@ class ComplianceControlSetsController < ChouetteController
private
+ def collection
+ scope = self.ransack_period_range(scope: ComplianceControlSet.all, error_message: t('imports.filters.error_period_filter'), query: :where_updated_at_between)
+ @q_for_form = scope.ransack(params[:q])
+ compliance_control_sets = @q_for_form.result
+ compliance_control_sets = joins_with_associated_objects(compliance_control_sets).order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ @compliance_control_sets = compliance_control_sets.paginate(page: params[:page], per_page: 30)
+ end
+
def decorate_compliance_control_sets(compliance_control_sets)
- ModelDecorator.decorate(
- compliance_control_sets,
- with: ComplianceControlSetDecorator
- )
+ ComplianceControlSetDecorator.decorate(compliance_control_sets)
end
def decorate_compliance_controls(compliance_controls)
- ModelDecorator.decorate(
- compliance_controls,
- with: ComplianceControlDecorator,
- )
+ ComplianceControlDecorator.decorate(compliance_controls)
end
def compliance_control_set_params
@@ -64,4 +64,32 @@ class ComplianceControlSetsController < ChouetteController
@direct_compliance_controls = compliance_controls.delete nil
@blocks_to_compliance_controls_map = compliance_controls
end
+
+ def sort_column
+ case params[:sort]
+ when 'name' then 'lower(compliance_control_sets.name)'
+ when 'owner_jdc' then 'lower(organisations.name)'
+ when 'control_numbers' then 'COUNT(compliance_controls.id)'
+ else
+ ComplianceControlSet.column_names.include?(params[:sort]) ? params[:sort] : 'lower(compliance_control_sets.name)'
+ end
+ end
+
+ def joins_with_associated_objects(collection)
+
+ # dont know if this is the right way to do it but since we need to join table deoending of the params
+ # it was to avoid loading associated objects if we don't need them
+ case params[:sort]
+ when 'owner_jdc'
+ collection.joins("LEFT JOIN organisations ON compliance_control_sets.organisation_id = organisations.id")
+ when 'control_numbers'
+ collection.joins("LEFT JOIN compliance_controls ON compliance_controls.compliance_control_set_id = compliance_control_sets.id").group(:id)
+ else
+ collection
+ end
+ end
+
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
+ end
end
diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb
index dfbecaa71..73dc18f59 100644
--- a/app/controllers/compliance_controls_controller.rb
+++ b/app/controllers/compliance_controls_controller.rb
@@ -8,6 +8,12 @@ class ComplianceControlsController < ChouetteController
@sti_subclasses = ComplianceControl.subclasses
end
+ def show
+ show! do
+ @compliance_control = @compliance_control.decorate
+ end
+ end
+
def new
if params[:sti_class].blank?
flash[:notice] = I18n.t("compliance_controls.errors.mandatory_control_type")
diff --git a/app/controllers/concerns/activatable.rb b/app/controllers/concerns/activatable.rb
new file mode 100644
index 000000000..1a34551a9
--- /dev/null
+++ b/app/controllers/concerns/activatable.rb
@@ -0,0 +1,11 @@
+module Activatable
+ extend ActiveSupport::Concern
+
+ %w(activate deactivate).each do |action|
+ define_method action do
+ authorize resource, "#{action}?"
+ resource.send "#{action}!"
+ redirect_to request.referer || [current_referential, resource]
+ end
+ end
+end
diff --git a/app/controllers/concerns/feature_checker.rb b/app/controllers/concerns/feature_checker.rb
new file mode 100644
index 000000000..9ca5ed0a7
--- /dev/null
+++ b/app/controllers/concerns/feature_checker.rb
@@ -0,0 +1,42 @@
+# Check availability of optional features
+#
+# In your controller, use :
+#
+# requires_feature :test
+# requires_feature :test, only: [:show]
+#
+# In your view, use :
+#
+# has_feature? :test
+#
+module FeatureChecker
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ def requires_feature(feature, options = {})
+ before_action options do
+ check_feature! feature
+ end
+ end
+ end
+
+ included do
+ helper_method :has_feature?
+ end
+
+ protected
+
+ def has_feature?(*features)
+ features.all? do |feature|
+ current_organisation.has_feature? feature
+ end
+ end
+
+ def check_feature!(*features)
+ unless has_feature?(*features)
+ raise NotAuthorizedError, "Feature not autorized"
+ end
+ end
+
+ class NotAuthorizedError < StandardError; end
+end
diff --git a/app/controllers/concerns/ransack_date_filter.rb b/app/controllers/concerns/ransack_date_filter.rb
index 0fbde91d3..055c01130 100644
--- a/app/controllers/concerns/ransack_date_filter.rb
+++ b/app/controllers/concerns/ransack_date_filter.rb
@@ -3,7 +3,15 @@ module RansackDateFilter
included do
- def set_date_time_params(param_name, klass)
+ def begin_range_var prefix
+ "@#{[prefix, "begin_range"].compact.join('_')}"
+ end
+
+ def end_range_var prefix
+ "@#{[prefix, "end_range"].compact.join('_')}"
+ end
+
+ def set_date_time_params(param_name, klass, prefix: nil)
start_date = []
end_date = []
@@ -16,26 +24,28 @@ module RansackDateFilter
params[:q].delete([param_name])
if klass == DateTime
- @begin_range = klass.new(*start_date,0,0,0) rescue nil
- @end_range = klass.new(*end_date,23,59,59) rescue nil
+ instance_variable_set begin_range_var(prefix), klass.new(*start_date,0,0,0) rescue nil
+ instance_variable_set end_range_var(prefix), klass.new(*end_date,23,59,59) rescue nil
else
- @begin_range = klass.new(*start_date) rescue nil
- @end_range = klass.new(*end_date) rescue nil
+ instance_variable_set begin_range_var(prefix), klass.new(*start_date) rescue nil
+ instance_variable_set end_range_var(prefix), klass.new(*end_date) rescue nil
end
end
end
# Fake ransack filter
def ransack_period_range **options
- return options[:scope] unless !!@begin_range && !!@end_range
+ prefix = options[:prefix]
+ return options[:scope] unless !!instance_variable_get(begin_range_var(prefix)) && !!instance_variable_get(end_range_var(prefix))
- if @begin_range > @end_range
+ scope = options[:scope]
+ if instance_variable_get(begin_range_var(prefix)) > instance_variable_get(end_range_var(prefix))
flash.now[:error] = options[:error_message]
else
- scope = options[:scope].send options[:query], @begin_range..@end_range
+ scope = scope.send options[:query], instance_variable_get(begin_range_var(prefix))..instance_variable_get(end_range_var(prefix))
end
scope
end
end
-end \ No newline at end of file
+end
diff --git a/app/controllers/development_toolbar_controller.rb b/app/controllers/development_toolbar_controller.rb
new file mode 100644
index 000000000..20349f7b8
--- /dev/null
+++ b/app/controllers/development_toolbar_controller.rb
@@ -0,0 +1,11 @@
+class DevelopmentToolbarController < ApplicationController
+ def update_settings
+ return unless Rails.application.config.development_toolbar.present?
+ organisation = current_user.organisation
+ organisation.features = params[:features].keys.select{|k| params[:features][k] == "true"}
+ organisation.save
+ current_user.permissions = params[:permissions].keys.select{|k| params[:permissions][k] == "true"}
+ current_user.save
+ redirect_to request.referrer || "/"
+ end
+end
diff --git a/app/controllers/group_of_lines_controller.rb b/app/controllers/group_of_lines_controller.rb
index 5762108dc..46d9d077f 100644
--- a/app/controllers/group_of_lines_controller.rb
+++ b/app/controllers/group_of_lines_controller.rb
@@ -42,7 +42,6 @@ class GroupOfLinesController < ChouetteController
end
end
-
protected
def filtered_group_of_lines_maps
@@ -70,6 +69,10 @@ class GroupOfLinesController < ChouetteController
alias_method :line_referential, :parent
+ def begin_of_association_chain
+ current_organisation
+ end
+
private
def group_of_line_params
diff --git a/app/controllers/import_messages_controller.rb b/app/controllers/import_messages_controller.rb
index 6546b25f8..286bb0ce8 100644
--- a/app/controllers/import_messages_controller.rb
+++ b/app/controllers/import_messages_controller.rb
@@ -9,7 +9,7 @@ class ImportMessagesController < ChouetteController
def index
index! do |format|
format.csv {
- send_data ImportMessageExport.new(:import_messages => @import_messages).to_csv(:col_sep => ";") , :filename => "#{File.basename(@import_resource.name)}_#{Time.now.to_i}.csv"
+ send_data ImportMessageExport.new(:import_messages => @import_messages).to_csv(:col_sep => "\;", :quote_char=>'"', force_quotes: true) , :filename => "import_errors_#{@import_resource.name.gsub('.xml', '')}_#{Time.now.to_i}.csv"
}
end
end
diff --git a/app/controllers/import_resources_controller.rb b/app/controllers/import_resources_controller.rb
index c83721310..ea78394a1 100644
--- a/app/controllers/import_resources_controller.rb
+++ b/app/controllers/import_resources_controller.rb
@@ -27,12 +27,6 @@ class ImportResourcesController < ChouetteController
private
def decorate_import_resources(import_resources)
- ImportResourcesDecorator.decorate(
- import_resources,
- with: ImportResourceDecorator,
- context: {
- import: @import
- }
- )
+ ImportResourcesDecorator.decorate(import_resources)
end
end
diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb
index 46d34efda..7a999d657 100644
--- a/app/controllers/imports_controller.rb
+++ b/app/controllers/imports_controller.rb
@@ -84,9 +84,8 @@ class ImportsController < ChouetteController
end
def decorate_imports(imports)
- ModelDecorator.decorate(
+ ImportDecorator.decorate(
imports,
- with: ImportDecorator,
context: {
workbench: @workbench
}
diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb
index 736fb1441..da567779e 100644
--- a/app/controllers/journey_patterns_collections_controller.rb
+++ b/app/controllers/journey_patterns_collections_controller.rb
@@ -17,38 +17,53 @@ class JourneyPatternsCollectionsController < ChouetteController
alias_method :vehicle_journey, :resource
def show
- @q = route.journey_patterns.search(params[:q]).result(distinct: true).includes(:stop_points)
+ @q = route.journey_patterns
+ if params[:q].present?
+ ids = @q.search(params[:q]).result(distinct: true).pluck(:id)
+ @q = @q.where(id: ids)
+ end
+ @q = @q.includes(:stop_points)
@ppage = 10
@journey_patterns ||= @q.paginate(page: params[:page], per_page: @ppage).order(:name)
-
- @stop_points_list = []
- route.stop_points.each do |sp|
- @stop_points_list << {
- :id => sp.stop_area.id,
- :route_id => sp.try(:route_id),
- :object_id => sp.try(:objectid),
- :position => sp.try(:position),
- :for_boarding => sp.try(:for_boarding),
- :for_alighting => sp.try(:for_alighting),
- :name => sp.stop_area.try(:name),
- :zip_code => sp.stop_area.try(:zip_code),
- :city_name => sp.stop_area.try(:city_name),
- :comment => sp.stop_area.try(:comment),
- :area_type => sp.stop_area.try(:area_type),
- :registration_number => sp.stop_area.try(:registration_number),
- :nearest_topic_name => sp.stop_area.try(:nearest_topic_name),
- :fare_code => sp.stop_area.try(:fare_code),
- :longitude => sp.stop_area.try(:longitude),
- :latitude => sp.stop_area.try(:latitude),
- :long_lat_type => sp.stop_area.try(:long_lat_type),
- :country_code => sp.stop_area.try(:country_code),
- :street_name => sp.stop_area.try(:street_name)
- }
+ respond_to do |format|
+ format.json do
+ @journey_patterns = @journey_patterns.includes(stop_points: {stop_area: :stop_area_referential})
+ end
+ format.html do
+ @stop_points_list = []
+ route.stop_points.includes(:stop_area).each do |sp|
+ @stop_points_list << {
+ :id => sp.stop_area.id,
+ :route_id => sp.try(:route_id),
+ :object_id => sp.try(:objectid),
+ :stop_area_object_id => sp.stop_area.try(:objectid),
+ :position => sp.try(:position),
+ :for_boarding => sp.try(:for_boarding),
+ :for_alighting => sp.try(:for_alighting),
+ :name => sp.stop_area.try(:name),
+ :zip_code => sp.stop_area.try(:zip_code),
+ :city_name => sp.stop_area.try(:city_name),
+ :country_name => sp.stop_area.try(:country_name),
+ :time_zone_formatted_offset => sp.stop_area.try(:time_zone_formatted_offset),
+ :comment => sp.stop_area.try(:comment),
+ :area_type => sp.stop_area.try(:area_type),
+ :registration_number => sp.stop_area.try(:registration_number),
+ :nearest_topic_name => sp.stop_area.try(:nearest_topic_name),
+ :fare_code => sp.stop_area.try(:fare_code),
+ :longitude => sp.stop_area.try(:longitude),
+ :latitude => sp.stop_area.try(:latitude),
+ :long_lat_type => sp.stop_area.try(:long_lat_type),
+ :country_code => sp.stop_area.try(:country_code),
+ :street_name => sp.stop_area.try(:street_name)
+ }
+ end
+ @stop_points_list = @stop_points_list.sort_by {|a| a[:position] }
+ end
end
- @stop_points_list = @stop_points_list.sort_by {|a| a[:position] }
end
def user_permissions
+ @features = Hash[*current_organisation.features.map{|f| [f, true]}.flatten].to_json
policy = policy(:journey_pattern)
@perms =
%w{create destroy update}.inject({}) do | permissions, action |
diff --git a/app/controllers/line_referentials_controller.rb b/app/controllers/line_referentials_controller.rb
index 39c2cdb89..03dab3f8f 100644
--- a/app/controllers/line_referentials_controller.rb
+++ b/app/controllers/line_referentials_controller.rb
@@ -3,6 +3,7 @@ class LineReferentialsController < ChouetteController
defaults :resource_class => LineReferential
def sync
+ authorize resource, :synchronize?
@sync = resource.line_referential_syncs.build
if @sync.save
flash[:notice] = t('notice.line_referential_sync.created')
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 571c73f4a..27a9bf9be 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -1,6 +1,8 @@
class LinesController < ChouetteController
include ApplicationHelper
+ include Activatable
include PolicyChecker
+
defaults :resource_class => Chouette::Line
respond_to :html
respond_to :xml
@@ -13,9 +15,8 @@ class LinesController < ChouetteController
def index
@hide_group_of_line = line_referential.group_of_lines.empty?
index! do |format|
- @lines = ModelDecorator.decorate(
+ @lines = LineDecorator.decorate(
@lines,
- with: LineDecorator,
context: {
line_referential: @line_referential,
current_organisation: current_organisation
@@ -67,7 +68,6 @@ class LinesController < ChouetteController
respond_to do |format|
format.json { render :json => filtered_lines_maps}
end
-
end
protected
@@ -112,6 +112,10 @@ class LinesController < ChouetteController
alias_method :current_referential, :line_referential
helper_method :current_referential
+ def begin_of_association_chain
+ current_organisation
+ end
+
def line_params
params.require(:line).permit(
:transport_mode,
diff --git a/app/controllers/merges_controller.rb b/app/controllers/merges_controller.rb
new file mode 100644
index 000000000..1ce64ed58
--- /dev/null
+++ b/app/controllers/merges_controller.rb
@@ -0,0 +1,40 @@
+class MergesController < ChouetteController
+ # include PolicyChecker
+
+ defaults resource_class: Merge
+ belongs_to :workbench
+
+ respond_to :html
+
+ before_action :set_mergeable_controllers, only: [:new]
+
+ private
+
+ def set_mergeable_controllers
+ @mergeable_referentials ||= parent.referentials.mergeable
+ Rails.logger.debug "Mergeables: #{@mergeable_referentials.inspect}"
+ end
+
+ def build_resource
+ super.tap do |merge|
+ merge.creator = current_user.name
+ end
+ end
+
+ # def build_resource
+ # @import ||= WorkbenchImport.new(*resource_params) do |import|
+ # import.workbench = parent
+ # import.creator = current_user.name
+ # end
+ # end
+
+ def merge_params
+ params.require(:merge).permit(
+ referentials: []
+ # :name,
+ # :file,
+ # :type,
+ # :referential_id
+ )
+ end
+end
diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb
index 494d1e69f..1c69b1240 100644
--- a/app/controllers/networks_controller.rb
+++ b/app/controllers/networks_controller.rb
@@ -71,6 +71,10 @@ class NetworksController < ChouetteController
alias_method :current_referential, :line_referential
helper_method :current_referential
+ def begin_of_association_chain
+ current_organisation
+ end
+
def network_params
params.require(:network).permit(:objectid, :object_version, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment )
end
@@ -85,9 +89,8 @@ class NetworksController < ChouetteController
end
def decorate_networks(networks)
- ModelDecorator.decorate(
+ NetworkDecorator.decorate(
networks,
- with: NetworkDecorator,
context: {
line_referential: line_referential
}
diff --git a/app/controllers/purchase_windows_controller.rb b/app/controllers/purchase_windows_controller.rb
new file mode 100644
index 000000000..293a7d8e4
--- /dev/null
+++ b/app/controllers/purchase_windows_controller.rb
@@ -0,0 +1,74 @@
+class PurchaseWindowsController < ChouetteController
+ include ReferentialSupport
+ include RansackDateFilter
+ include PolicyChecker
+ before_action :ransack_contains_date, only: [:index]
+ defaults :resource_class => Chouette::PurchaseWindow, collection_name: 'purchase_windows', instance_name: 'purchase_window'
+ belongs_to :referential
+
+ requires_feature :purchase_windows
+
+ def index
+ index! do
+ @purchase_windows = decorate_purchase_windows(@purchase_windows)
+ end
+ end
+
+ def show
+ show! do
+ @purchase_window = @purchase_window.decorate(context: {
+ referential: @referential
+ })
+ end
+ end
+
+ protected
+
+ def create_resource(purchase_window)
+ purchase_window.referential = @referential
+ super
+ end
+
+ private
+
+ def purchase_window_params
+ params.require(:purchase_window).permit(:id, :name, :color, :referential_id, periods_attributes: [:id, :begin, :end, :_destroy])
+ end
+
+ def decorate_purchase_windows(purchase_windows)
+ PurchaseWindowDecorator.decorate(
+ purchase_windows,
+ context: {
+ referential: @referential
+ }
+ )
+ end
+
+ def sort_column
+ Chouette::PurchaseWindow.column_names.include?(params[:sort]) ? params[:sort] : 'name'
+ end
+
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
+ end
+
+ def collection
+ return @purchase_windows if @purchase_windows
+ @q = Chouette::PurchaseWindow.ransack(params[:q])
+
+ purchase_windows = @q.result
+ purchase_windows = purchase_windows.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ @purchase_windows = purchase_windows.paginate(page: params[:page])
+ end
+
+ def ransack_contains_date
+ date =[]
+ if params[:q] && params[:q]['contains_date(1i)'].present?
+ ['contains_date(1i)', 'contains_date(2i)', 'contains_date(3i)'].each do |key|
+ date << params[:q][key].to_i
+ params[:q].delete(key)
+ end
+ params[:q]['contains_date'] = @date = Date.new(*date) rescue nil
+ end
+ end
+end
diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb
index ca1ff67db..806a70c8f 100644
--- a/app/controllers/referential_companies_controller.rb
+++ b/app/controllers/referential_companies_controller.rb
@@ -35,7 +35,8 @@ class ReferentialCompaniesController < ChouetteController
def collection
scope = referential.line_referential.companies
if params[:line_id]
- scope = referential.line_referential.lines.find(params[:line_id]).companies
+ line_scope = referential.line_referential.lines.find(params[:line_id]).companies
+ scope = line_scope if line_scope.exists?
end
@q = scope.search(params[:q])
@@ -68,10 +69,13 @@ class ReferentialCompaniesController < ChouetteController
%w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
end
+ def collection_name
+ "companies"
+ end
+
def decorate_companies(companies)
- ModelDecorator.decorate(
+ CompanyDecorator.decorate(
companies,
- with: CompanyDecorator,
context: {
referential: referential
}
diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb
index 9e8f5c512..37051faeb 100644
--- a/app/controllers/referential_lines_controller.rb
+++ b/app/controllers/referential_lines_controller.rb
@@ -28,9 +28,8 @@ class ReferentialLinesController < ChouetteController
@routes = @routes.paginate(page: params[:page], per_page: 10)
- @routes = ModelDecorator.decorate(
+ @routes = RouteDecorator.decorate(
@routes,
- with: RouteDecorator,
context: {
referential: referential,
line: @line
diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb
index b2d83f953..fe00a99df 100644
--- a/app/controllers/referential_networks_controller.rb
+++ b/app/controllers/referential_networks_controller.rb
@@ -56,6 +56,10 @@ class ReferentialNetworksController < ChouetteController
end
end
+ def collection_name
+ 'networks'
+ end
+
def resource_url(network = nil)
referential_network_path(referential, network || resource)
end
@@ -78,9 +82,8 @@ class ReferentialNetworksController < ChouetteController
end
def decorate_networks(networks)
- ModelDecorator.decorate(
+ ReferentialNetworkDecorator.decorate(
networks,
- with: ReferentialNetworkDecorator,
context: {
referential: referential
}
diff --git a/app/controllers/referential_vehicle_journeys_controller.rb b/app/controllers/referential_vehicle_journeys_controller.rb
new file mode 100644
index 000000000..2ce28a5cc
--- /dev/null
+++ b/app/controllers/referential_vehicle_journeys_controller.rb
@@ -0,0 +1,30 @@
+#
+# Browse all VehicleJourneys of the Referential
+#
+class ReferentialVehicleJourneysController < ChouetteController
+ include ReferentialSupport
+ include RansackDateFilter
+
+ before_action only: [:index] { set_date_time_params("purchase_window", Date, prefix: :purchase_window) }
+ before_action only: [:index] { set_date_time_params("time_table", Date, prefix: :time_table) }
+
+ defaults :resource_class => Chouette::VehicleJourney, collection_name: :vehicle_journeys
+
+ requires_feature :referential_vehicle_journeys
+
+ private
+
+ def collection
+ @q ||= end_of_association_chain
+ @q = @q.with_stop_area_ids(params[:q][:stop_area_ids]) if params[:q] && params[:q][:stop_area_ids]
+ @q = ransack_period_range(scope: @q, error_message: t('vehicle_journeys.errors.purchase_window'), query: :in_purchase_window, prefix: :purchase_window)
+ @q = ransack_period_range(scope: @q, error_message: t('vehicle_journeys.errors.time_table'), query: :with_matching_timetable, prefix: :time_table)
+ @q = @q.ransack(params[:q])
+ @vehicle_journeys ||= @q.result.order(:published_journey_name).includes(:vehicle_journey_at_stops).paginate page: params[:page], per_page: params[:per_page] || 10
+ @all_companies = Chouette::Company.where("id IN (#{@referential.vehicle_journeys.select(:company_id).to_sql})").distinct
+ @all_stop_areas = Chouette::StopArea.where("id IN (#{@referential.vehicle_journeys.joins(:stop_areas).select("stop_areas.id").to_sql})").distinct
+ stop_area_ids = params[:q].try(:[], :stop_area_ids).try(:select, &:present?)
+ @filters_stop_areas = Chouette::StopArea.find(stop_area_ids) if stop_area_ids.present? && stop_area_ids.size <= 2
+ end
+
+end
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index ee1236912..0ed3f75dd 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -8,16 +8,21 @@ class ReferentialsController < ChouetteController
def new
new! do
- build_referenial
+ build_referential
end
end
def create
- create! do |format|
- build_referenial
-
- if !!@referential.created_from_id
- format.html { redirect_to workbench_path(@referential.workbench) }
+ create! do |success, failure|
+ success.html do
+ if @referential.created_from_id.present?
+ flash[:notice] = t('notice.referentials.duplicate')
+ end
+ redirect_to workbench_path(@referential.workbench)
+ end
+ failure.html do
+ Rails.logger.info "Can't create Referential : #{@referential.errors.inspect}"
+ render :new
end
end
end
@@ -27,9 +32,8 @@ class ReferentialsController < ChouetteController
show! do |format|
@referential = @referential.decorate(context: { current_workbench_id: params[:current_workbench_id] } )
@reflines = lines_collection.paginate(page: params[:page], per_page: 10)
- @reflines = ModelDecorator.decorate(
+ @reflines = ReferentialLineDecorator.decorate(
@reflines,
- with: ReferentialLineDecorator,
context: {
referential: referential,
current_organisation: current_organisation
@@ -60,8 +64,8 @@ class ReferentialsController < ChouetteController
def validate
ComplianceControlSetCopyWorker.perform_async(params[:compliance_control_set], params[:id])
- flash[:notice] = I18n.t("referentials.operation_in_progress")
- redirect_to(referential_path)
+ flash[:notice] = t('notice.referentials.validate')
+ redirect_to workbench_compliance_check_sets_path(referential.workbench_id)
end
def destroy
@@ -75,6 +79,7 @@ class ReferentialsController < ChouetteController
referential.archive!
redirect_to workbench_path(referential.workbench_id), notice: t('notice.referential.archived')
end
+
def unarchive
if referential.unarchive!
flash[:notice] = t('notice.referential.unarchived')
@@ -92,7 +97,7 @@ class ReferentialsController < ChouetteController
helper_method :current_referential
def resource
- @referential ||= current_organisation.find_referential(params[:id])
+ @referential ||= current_organisation.find_referential(params[:id]).decorate
end
def collection
@@ -132,7 +137,7 @@ class ReferentialsController < ChouetteController
super
end
- def build_referenial
+ def build_referential
if params[:from]
source_referential = Referential.find(params[:from])
@referential = Referential.new_from(source_referential, current_functional_scope)
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index 79f49143a..af5a9a91b 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -47,10 +47,7 @@ class RoutesController < ChouetteController
line: @line
})
- @route_sp = ModelDecorator.decorate(
- @route_sp,
- with: StopPointDecorator
- )
+ @route_sp = StopPointDecorator.decorate(@route_sp)
end
end
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index a72b288b8..47df211d0 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -13,9 +13,8 @@ class RoutingConstraintZonesController < ChouetteController
def index
index! do |format|
- @routing_constraint_zones = ModelDecorator.decorate(
+ @routing_constraint_zones = RoutingConstraintZoneDecorator.decorate(
@routing_constraint_zones,
- with: RoutingConstraintZoneDecorator,
context: {
referential: referential,
line: parent
diff --git a/app/controllers/snapshots_controller.rb b/app/controllers/snapshots_controller.rb
new file mode 100644
index 000000000..e453b4965
--- /dev/null
+++ b/app/controllers/snapshots_controller.rb
@@ -0,0 +1,14 @@
+class SnapshotsController < ApplicationController
+ if Rails.env.development? || Rails.env.test?
+ layout :which_layout
+ def show
+ tpl = params[:snap]
+ tpl = tpl.gsub Rails.root.to_s, ''
+ render file: tpl
+ end
+
+ def which_layout
+ "snapshots/#{params[:layout] || "default"}"
+ end
+ end
+end
diff --git a/app/controllers/statuses_controller.rb b/app/controllers/statuses_controller.rb
new file mode 100644
index 000000000..e38a92982
--- /dev/null
+++ b/app/controllers/statuses_controller.rb
@@ -0,0 +1,20 @@
+class StatusesController < ChouetteController
+ respond_to :json
+
+ def index
+
+ status = {
+ referentials_blocked: Referential.blocked.count,
+ imports_blocked: Import.blocked.count,
+ compliance_check_sets_blocked: ComplianceCheckSet.blocked.count
+ }
+ status[:status] = global_status status
+ render json: status.to_json
+ end
+
+ private
+
+ def global_status status
+ status.values.all?(&:zero?) ? 'ok' : 'ko'
+ end
+end
diff --git a/app/controllers/stop_area_referentials_controller.rb b/app/controllers/stop_area_referentials_controller.rb
index 85541230d..f2d375e49 100644
--- a/app/controllers/stop_area_referentials_controller.rb
+++ b/app/controllers/stop_area_referentials_controller.rb
@@ -2,6 +2,7 @@ class StopAreaReferentialsController < ChouetteController
defaults :resource_class => StopAreaReferential
def sync
+ authorize resource, :synchronize?
@sync = resource.stop_area_referential_syncs.build
if @sync.save
flash[:notice] = t('notice.stop_area_referential_sync.created')
diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb
index 133518324..41a1a8c6d 100644
--- a/app/controllers/stop_areas_controller.rb
+++ b/app/controllers/stop_areas_controller.rb
@@ -1,5 +1,6 @@
class StopAreasController < ChouetteController
include ApplicationHelper
+ include Activatable
defaults :resource_class => Chouette::StopArea
@@ -13,10 +14,12 @@ class StopAreasController < ChouetteController
respond_to :html, :kml, :xml, :json
respond_to :js, :only => :index
- # def complete
- # @stop_areas = line.stop_areas
- # render :layout => false
- # end
+ def autocomplete
+ scope = stop_area_referential.stop_areas.where(deleted_at: nil)
+ args = [].tap{|arg| 4.times{arg << "%#{params[:q]}%"}}
+ @stop_areas = scope.where("unaccent(name) ILIKE unaccent(?) OR unaccent(city_name) ILIKE unaccent(?) OR registration_number ILIKE ? OR objectid ILIKE ?", *args).limit(50)
+ @stop_areas
+ end
def select_parent
@stop_area = stop_area
@@ -54,10 +57,7 @@ class StopAreasController < ChouetteController
redirect_to params.merge(:page => 1)
end
- @stop_areas = ModelDecorator.decorate(
- @stop_areas,
- with: StopAreaDecorator
- )
+ @stop_areas = StopAreaDecorator.decorate(@stop_areas)
}
end
end
@@ -95,9 +95,8 @@ class StopAreasController < ChouetteController
def edit
authorize stop_area
edit! do
- stop_area.position ||= stop_area.default_position
map.editable = true
- end
+ end
end
def destroy
@@ -107,7 +106,6 @@ class StopAreasController < ChouetteController
def update
authorize stop_area
- stop_area.position ||= stop_area.default_position
map.editable = true
update!
@@ -154,6 +152,10 @@ class StopAreasController < ChouetteController
end
end
+ def begin_of_association_chain
+ current_organisation
+ end
+
private
def sort_column
@@ -171,7 +173,37 @@ class StopAreasController < ChouetteController
helper_method :current_referential
def stop_area_params
- params.require(:stop_area).permit( :routing_stop_ids, :routing_line_ids, :children_ids, :stop_area_type, :parent_id, :objectid, :object_version, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :coordinates, :url, :time_zone )
+ params.require(:stop_area).permit(
+ :area_type,
+ :children_ids,
+ :city_name,
+ :comment,
+ :coordinates,
+ :country_code,
+ :fare_code,
+ :int_user_needs,
+ :latitude,
+ :lift_availability,
+ :long_lat_type,
+ :longitude,
+ :mobility_restricted_suitability,
+ :name,
+ :nearest_topic_name,
+ :object_version,
+ :objectid,
+ :parent_id,
+ :registration_number,
+ :routing_line_ids,
+ :routing_stop_ids,
+ :stairs_availability,
+ :street_name,
+ :time_zone,
+ :url,
+ :waiting_time,
+ :zip_code,
+ :kind,
+ localized_names: Chouette::StopArea::AVAILABLE_LOCALIZATIONS
+ )
end
end
diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb
index a0fa168f0..0dcadad1e 100644
--- a/app/controllers/time_tables_controller.rb
+++ b/app/controllers/time_tables_controller.rb
@@ -36,7 +36,6 @@ class TimeTablesController < ChouetteController
def create
tt_params = time_table_params
if tt_params[:calendar_id] && tt_params[:calendar_id] != ""
- %i(monday tuesday wednesday thursday friday saturday sunday).map { |d| tt_params[d] = true }
calendar = Calendar.find(tt_params[:calendar_id])
tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes)
end
@@ -45,6 +44,7 @@ class TimeTablesController < ChouetteController
@time_table = created_from ? created_from.duplicate : Chouette::TimeTable.new(tt_params)
if calendar
+ @time_table.int_day_types = calendar.int_day_types
calendar.dates.each_with_index do |date, i|
@time_table.dates << Chouette::TimeTableDate.new(date: date, position: i, in_out: true)
end
@@ -167,9 +167,8 @@ class TimeTablesController < ChouetteController
end
def decorate_time_tables(time_tables)
- ModelDecorator.decorate(
+ TimeTableDecorator.decorate(
time_tables,
- with: TimeTableDecorator,
context: {
referential: @referential
}
diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb
index c941aeae4..e031e4952 100644
--- a/app/controllers/vehicle_journeys_controller.rb
+++ b/app/controllers/vehicle_journeys_controller.rb
@@ -40,43 +40,26 @@ class VehicleJourneysController < ChouetteController
end
def index
- @stop_points_list = []
- route.stop_points.each do |sp|
- @stop_points_list << {
- :id => sp.stop_area.id,
- :route_id => sp.try(:route_id),
- :object_id => sp.try(:objectid),
- :position => sp.try(:position),
- :for_boarding => sp.try(:for_boarding),
- :for_alighting => sp.try(:for_alighting),
- :name => sp.stop_area.try(:name),
- :zip_code => sp.stop_area.try(:zip_code),
- :city_name => sp.stop_area.try(:city_name),
- :comment => sp.stop_area.try(:comment),
- :area_type => sp.stop_area.try(:area_type),
- :registration_number => sp.stop_area.try(:registration_number),
- :nearest_topic_name => sp.stop_area.try(:nearest_topic_name),
- :fare_code => sp.stop_area.try(:fare_code),
- :longitude => sp.stop_area.try(:longitude),
- :latitude => sp.stop_area.try(:latitude),
- :long_lat_type => sp.stop_area.try(:long_lat_type),
- :country_code => sp.stop_area.try(:country_code),
- :street_name => sp.stop_area.try(:street_name)
- }
- end
-
- @transport_mode = route.line['transport_mode']
- @transport_submode = route.line['transport_submode']
-
- if params[:jp]
- @jp_origin = Chouette::JourneyPattern.find_by(objectid: params[:jp])
- @jp_origin_stop_points = @jp_origin.stop_points
- end
-
- index! do
+ index! do |format|
if collection.out_of_bounds?
redirect_to params.merge(:page => 1)
end
+ format.json do
+ @vehicle_journeys = @vehicle_journeys.includes({stop_points: :stop_area})
+ end
+ format.html do
+ load_missions
+ load_custom_fields
+ @stop_points_list = map_stop_points(route.stop_points)
+ @return_stop_points_list = map_stop_points(route.opposite_route&.stop_points) if has_feature?(:vehicle_journeys_return_route)
+ @transport_mode = route.line['transport_mode']
+ @transport_submode = route.line['transport_submode']
+
+ if params[:jp]
+ @jp_origin = Chouette::JourneyPattern.find_by(objectid: params[:jp])
+ @jp_origin_stop_points = @jp_origin.stop_points
+ end
+ end
end
end
@@ -92,13 +75,15 @@ class VehicleJourneysController < ChouetteController
scope = maybe_filter_by_departure_time(scope)
scope = maybe_filter_out_journeys_with_time_tables(scope)
- @q = scope.search filtered_ransack_params
+ @vehicle_journeys ||= begin
+ @q = scope.search filtered_ransack_params
- @ppage = 20
- @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
+ @ppage = 20
+ 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
+ end
end
def maybe_filter_by_departure_time(scope)
@@ -159,6 +144,7 @@ class VehicleJourneysController < ChouetteController
end
def user_permissions
+ @features = Hash[*current_organisation.features.map{|f| [f, true]}.flatten].to_json
policy = policy(:vehicle_journey)
@perms =
%w{create destroy update}.inject({}) do | permissions, action |
@@ -167,6 +153,69 @@ class VehicleJourneysController < ChouetteController
end
private
+ def load_custom_fields
+ @custom_fields = current_workgroup.custom_fields_definitions
+ end
+
+ def map_stop_points points
+ (points&.includes(:stop_area) || []).map do |sp|
+ {
+ :id => sp.stop_area.id,
+ :route_id => sp.try(:route_id),
+ :object_id => sp.try(:objectid),
+ :area_object_id => sp.stop_area.try(:objectid),
+ :position => sp.try(:position),
+ :for_boarding => sp.try(:for_boarding),
+ :for_alighting => sp.try(:for_alighting),
+ :name => sp.stop_area.try(:name),
+ :time_zone_offset => sp.stop_area.try(:time_zone_offset),
+ :time_zone_formatted_offset => sp.stop_area.try(:time_zone_formatted_offset),
+ :zip_code => sp.stop_area.try(:zip_code),
+ :city_name => sp.stop_area.try(:city_name),
+ :comment => sp.stop_area.try(:comment),
+ :area_type => sp.stop_area.try(:area_type),
+ :area_type_i18n => I18n.t(sp.stop_area.try(:area_type), scope: 'area_types.label'),
+ :area_kind => sp.stop_area.try(:kind),
+ :stop_area_id => sp.stop_area_id,
+ :registration_number => sp.stop_area.try(:registration_number),
+ :nearest_topic_name => sp.stop_area.try(:nearest_topic_name),
+ :fare_code => sp.stop_area.try(:fare_code),
+ :longitude => sp.stop_area.try(:longitude),
+ :latitude => sp.stop_area.try(:latitude),
+ :long_lat_type => sp.stop_area.try(:long_lat_type),
+ :country_code => sp.stop_area.try(:country_code),
+ :country_name => sp.stop_area.try(:country_name),
+ :street_name => sp.stop_area.try(:street_name)
+ }
+ end
+ end
+
+ def load_missions
+ @all_missions = route.journey_patterns.count > 10 ? [] : route.journey_patterns.map do |item|
+ {
+ id: item.id,
+ "data-item": {
+ id: item.id,
+ name: item.name,
+ published_name: item.published_name,
+ object_id: item.objectid,
+ short_id: item.get_objectid.short_id,
+ full_schedule: item.full_schedule?,
+ costs: item.costs,
+ stop_area_short_descriptions: item.stop_areas.map do |stop|
+ {
+ stop_area_short_description: {
+ id: stop.id,
+ name: stop.name,
+ object_id: item.objectid
+ }
+ }
+ end
+ }.to_json,
+ text: "<strong>#{item.published_name} - #{item.get_objectid.short_id}</strong><br/><small>#{item.registration_number}</small>"
+ }
+ end
+ end
def vehicle_journey_params
params.require(:vehicle_journey).permit(
{ footnote_ids: [] },
diff --git a/app/controllers/workbench_outputs_controller.rb b/app/controllers/workbench_outputs_controller.rb
new file mode 100644
index 000000000..67ed7569e
--- /dev/null
+++ b/app/controllers/workbench_outputs_controller.rb
@@ -0,0 +1,9 @@
+class WorkbenchOutputsController < ChouetteController
+ respond_to :html, only: [:show]
+ defaults resource_class: Workbench
+
+ def show
+ @workbench = current_organisation.workbenches.find params[:workbench_id]
+ @workbench_merges = @workbench.merges.order("created_at desc").paginate(page: params[:page], per_page: 10)
+ end
+end
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index b2dac9e67..2a71fe811 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -18,9 +18,8 @@ class WorkbenchesController < ChouetteController
@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 = ReferentialDecorator.decorate(
@wbench_refs,
- with: ReferentialDecorator,
context: {
current_workbench_id: params[:id]
}