diff options
| author | Luc Donnet | 2017-11-30 22:33:17 +0100 |
|---|---|---|
| committer | Luc Donnet | 2017-11-30 22:33:17 +0100 |
| commit | 4d9611d4cf1c9625536b63ea7942d9f8bf5147ae (patch) | |
| tree | 040ea7f70a71a163721a15fe7dbaf41246cd55f3 | |
| parent | d69312d870880bde378d50d329fe2dbb523f84e6 (diff) | |
| parent | 8e80415f70e0c181643e522976b1cf8bf9f9abfd (diff) | |
| download | chouette-core-4d9611d4cf1c9625536b63ea7942d9f8bf5147ae.tar.bz2 | |
Merge branch 'master' into staging
392 files changed, 3710 insertions, 3839 deletions
diff --git a/.gitignore b/.gitignore index cfcbf47a5..03a39be90 100644 --- a/.gitignore +++ b/.gitignore @@ -40,6 +40,8 @@ coverage /public/packs /public/packs-test +/bin + # Every machine shall create its binstubs /bin/rake /bin/rails @@ -33,8 +33,14 @@ gem 'spring', group: :development # ActiveRecord associations on top of PostgreSQL arrays gem 'has_array_of', af83: 'has_array_of' +# Track changes to your models' data. Good for auditing or versioning. +gem 'paper_trail' + gem 'rails-observers' +# Use SeedBank for spliting seeds +gem 'seedbank' + # Use ActiveModel has_secure_password # gem 'bcrypt', '~> 3.1.7' diff --git a/Gemfile.lock b/Gemfile.lock index 48a8b638a..f9682dff1 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -321,6 +321,10 @@ GEM mini_portile2 (~> 2.3.0) open4 (1.3.4) orm_adapter (0.5.0) + paper_trail (4.1.0) + activerecord (>= 3.0, < 6.0) + activesupport (>= 3.0, < 6.0) + request_store (~> 1.1) parser (2.4.0.0) ast (~> 2.2) pg (0.20.0) @@ -458,6 +462,7 @@ GEM sdoc (0.4.2) json (~> 1.7, >= 1.7.7) rdoc (~> 4.0) + seedbank (0.4.0) select2-rails (4.0.3) thor (~> 0.14) sequel (4.47.0) @@ -620,6 +625,7 @@ DEPENDENCIES map_layers (= 0.0.4) mimemagic newrelic_rpm + paper_trail pg phantomjs poltergeist @@ -652,6 +658,7 @@ DEPENDENCIES sass-rails (~> 4.0.3) sawyer (~> 0.6.0) sdoc (~> 0.4.0) + seedbank select2-rails (~> 4.0, >= 4.0.3) sequel shoulda-matchers (~> 3.1) diff --git a/app/assets/stylesheets/components/_device.sass b/app/assets/stylesheets/components/_device.sass new file mode 100644 index 000000000..0e773c29c --- /dev/null +++ b/app/assets/stylesheets/components/_device.sass @@ -0,0 +1,9 @@ +#sessions_new + li + list-style: none + .login + .checkbox + width: 100% + .panel-body + padding-left: 35px !important + padding-right: 35px !important
\ No newline at end of file diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index 2b715d669..9a363ab97 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -531,6 +531,12 @@ table, .table &.open > .control-label + * display: block + &.search + width: 30% + > .search_bar + padding: 0 15px + > .input-group-btn + right: 5% > .filter_menu margin: 0 diff --git a/app/assets/stylesheets/typography/_sboiv.sass b/app/assets/stylesheets/typography/_sboiv.sass index e37f89f2d..1345fbac6 100644 --- a/app/assets/stylesheets/typography/_sboiv.sass +++ b/app/assets/stylesheets/typography/_sboiv.sass @@ -62,25 +62,25 @@ .sb-ZDEP:before content: '\e906' -.sb-transporteur:before +.sb-company:before content: '\e907' .sb-trace:before content: '\e908' -.sb-tableau-de-bord:before +.sb-dashboard:before content: '\e909' -.sb-synchro-ilico:before +.sb-line_referential:before content: '\e90a' -.sb-synchro-icar:before +.sb-stop_area_referential:before content: '\e90b' -.sb-reseau:before +.sb-network:before content: '\e90c' -.sb-rapport-de-controle:before +.sb-compliance-check-set:before content: '\e90d' .sb-OAT:before @@ -89,7 +89,7 @@ .sb-OAS:before content: '\e90f' -.sb-modele-calendrier:before +.sb-calendar:before content: '\e910' .sb-mission:before @@ -104,28 +104,28 @@ .sb-LDA:before content: '\e914' -.sb-jeux-de-donnees:before +.sb-referential:before content: '\e915' -.sb-jeux-de-controle:before +.sb-compliance_control_set:before content: '\e916' -.sb-itl:before +.sb-routing_constraint_zone:before content: '\e917' -.sb-itineraire:before +.sb-route:before content: '\e918' -.sb-importer:before +.sb-import:before content: '\e919' -.sb-horaires-des-courses:before +.sb-vehicle_journey:before content: '\e91a' -.sb-calendrier-application:before +.sb-time_table:before content: '\e91b' -.sb-arret:before +.sb-stop_area:before content: '\e91c' .sb-Acces:before @@ -143,5 +143,5 @@ .sb-update-vj:before content: '\e900' -.sb-ligne:before +.sb-line:before content: '\e91e' diff --git a/app/controllers/access_links_controller.rb b/app/controllers/access_links_controller.rb index 936b8ea5e..19b3eb742 100644 --- a/app/controllers/access_links_controller.rb +++ b/app/controllers/access_links_controller.rb @@ -1,4 +1,5 @@ class AccessLinksController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::AccessLink belongs_to :referential do @@ -83,7 +84,7 @@ class AccessLinksController < ChouetteController private def access_link_params - params.require(:access_link).permit(:access_link_type,:access_point_id, :stop_area_id, :objectid, :object_version, :creator_id, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :link_orientation, :link_orientation_type, :stop_area ) + params.require(:access_link).permit(:access_link_type,:access_point_id, :stop_area_id, :objectid, :object_version, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :link_orientation, :link_orientation_type, :stop_area ) end end diff --git a/app/controllers/access_points_controller.rb b/app/controllers/access_points_controller.rb index 477875cc9..112a13a86 100644 --- a/app/controllers/access_points_controller.rb +++ b/app/controllers/access_points_controller.rb @@ -1,4 +1,5 @@ class AccessPointsController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::AccessPoint belongs_to :referential do @@ -63,7 +64,7 @@ class AccessPointsController < ChouetteController private def access_point_params - params.require(:access_point).permit( :objectid, :object_version, :creator_id, :name, :comment, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :openning_time, :closing_time, :access_type, :access_point_type, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :stop_area_id, :coordinates ) + params.require(:access_point).permit( :objectid, :object_version, :name, :comment, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :zip_code, :city_name, :openning_time, :closing_time, :access_type, :access_point_type, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :stop_area_id, :coordinates ) end end diff --git a/app/controllers/api_keys_controller.rb b/app/controllers/api_keys_controller.rb index eebad5e7b..9706c5961 100644 --- a/app/controllers/api_keys_controller.rb +++ b/app/controllers/api_keys_controller.rb @@ -1,4 +1,4 @@ -class ApiKeysController < InheritedResources::Base +class ApiKeysController < ChouetteController defaults resource_class: Api::V1::ApiKey include PolicyChecker diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 853c2f715..97f5548ae 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -1,5 +1,7 @@ class ApplicationController < ActionController::Base + include PaperTrailSupport include Pundit + rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized # TODO : Delete hack to authorize Cross Request for js and json get request from javascript @@ -48,7 +50,6 @@ class ApplicationController < ActionController::Base current_organisation end - # Overwriting the sign_out redirect path method def after_sign_out_path_for(resource_or_scope) new_user_session_path diff --git a/app/controllers/autocomplete_stop_areas_controller.rb b/app/controllers/autocomplete_stop_areas_controller.rb index e35a545ae..233012028 100644 --- a/app/controllers/autocomplete_stop_areas_controller.rb +++ b/app/controllers/autocomplete_stop_areas_controller.rb @@ -1,4 +1,4 @@ -class AutocompleteStopAreasController < InheritedResources::Base +class AutocompleteStopAreasController < ChouetteController respond_to :json, :only => [:index, :children, :parent, :physicals] include ReferentialSupport diff --git a/app/controllers/autocomplete_time_tables_controller.rb b/app/controllers/autocomplete_time_tables_controller.rb index f65f5b9f6..0a9f51ced 100644 --- a/app/controllers/autocomplete_time_tables_controller.rb +++ b/app/controllers/autocomplete_time_tables_controller.rb @@ -1,4 +1,4 @@ -class AutocompleteTimeTablesController < InheritedResources::Base +class AutocompleteTimeTablesController < ChouetteController respond_to :json, :only => [:index] before_action :switch_referential diff --git a/app/controllers/autocomplete_timebands_controller.rb b/app/controllers/autocomplete_timebands_controller.rb index 4922e214c..af041c33e 100644 --- a/app/controllers/autocomplete_timebands_controller.rb +++ b/app/controllers/autocomplete_timebands_controller.rb @@ -1,4 +1,4 @@ -class AutocompleteTimebandsController < InheritedResources::Base +class AutocompleteTimebandsController < ChouetteController respond_to :json, :only => [:index] include ReferentialSupport diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb index e9ee7579a..2ed10a111 100644 --- a/app/controllers/calendars_controller.rb +++ b/app/controllers/calendars_controller.rb @@ -1,4 +1,4 @@ -class CalendarsController < InheritedResources::Base +class CalendarsController < ChouetteController include PolicyChecker defaults resource_class: Calendar before_action :ransack_contains_date, only: [:index] diff --git a/app/controllers/chouette_controller.rb b/app/controllers/chouette_controller.rb index 1313aa7cc..3e4f3af27 100644 --- a/app/controllers/chouette_controller.rb +++ b/app/controllers/chouette_controller.rb @@ -1,5 +1,4 @@ class ChouetteController < InheritedResources::Base - + include PaperTrailSupport include ApplicationHelper - include ReferentialSupport end diff --git a/app/controllers/clean_ups_controller.rb b/app/controllers/clean_ups_controller.rb index b9ff225b3..ec28aa0fc 100644 --- a/app/controllers/clean_ups_controller.rb +++ b/app/controllers/clean_ups_controller.rb @@ -1,4 +1,5 @@ class CleanUpsController < ChouetteController + include ReferentialSupport respond_to :html, :only => [:create] belongs_to :referential diff --git a/app/controllers/companies_controller.rb b/app/controllers/companies_controller.rb index bc5bedd7f..931d846c5 100644 --- a/app/controllers/companies_controller.rb +++ b/app/controllers/companies_controller.rb @@ -1,4 +1,4 @@ -class CompaniesController < InheritedResources::Base +class CompaniesController < ChouetteController include ApplicationHelper include PolicyChecker defaults :resource_class => Chouette::Company @@ -62,7 +62,7 @@ class CompaniesController < InheritedResources::Base helper_method :current_referential def company_params - params.require(:company).permit( :objectid, :object_version, :creator_id, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone ) + 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 private diff --git a/app/controllers/compliance_check_sets_controller.rb b/app/controllers/compliance_check_sets_controller.rb index 175c22191..03b920030 100644 --- a/app/controllers/compliance_check_sets_controller.rb +++ b/app/controllers/compliance_check_sets_controller.rb @@ -1,4 +1,4 @@ -class ComplianceCheckSetsController < InheritedResources::Base +class ComplianceCheckSetsController < ChouetteController defaults resource_class: ComplianceCheckSet include RansackDateFilter before_action only: [:index] { set_date_time_params("created_at", DateTime) } @@ -19,11 +19,19 @@ class ComplianceCheckSetsController < InheritedResources::Base end end + def show + show! do + @compliance_check_set = @compliance_check_set.decorate(context: { + compliance_check_set: @compliance_check_set + }) + end + end + def executed - show! do |format| + show! do |format| # But now nobody is aware anymore that `format.html` passes a parameter into the block format.html { executed_for_html } - end + end end diff --git a/app/controllers/compliance_control_blocks_controller.rb b/app/controllers/compliance_control_blocks_controller.rb index f53a1e04a..9eee8dfaf 100644 --- a/app/controllers/compliance_control_blocks_controller.rb +++ b/app/controllers/compliance_control_blocks_controller.rb @@ -1,4 +1,4 @@ -class ComplianceControlBlocksController < InheritedResources::Base +class ComplianceControlBlocksController < ChouetteController include PolicyChecker defaults resource_class: ComplianceControlBlock belongs_to :compliance_control_set diff --git a/app/controllers/compliance_control_sets_controller.rb b/app/controllers/compliance_control_sets_controller.rb index 83a345c6f..2d3d03ad0 100644 --- a/app/controllers/compliance_control_sets_controller.rb +++ b/app/controllers/compliance_control_sets_controller.rb @@ -1,4 +1,4 @@ -class ComplianceControlSetsController < InheritedResources::Base +class ComplianceControlSetsController < ChouetteController include PolicyChecker defaults resource_class: ComplianceControlSet include RansackDateFilter diff --git a/app/controllers/compliance_controls_controller.rb b/app/controllers/compliance_controls_controller.rb index 5a9c0b671..dfbecaa71 100644 --- a/app/controllers/compliance_controls_controller.rb +++ b/app/controllers/compliance_controls_controller.rb @@ -1,4 +1,4 @@ -class ComplianceControlsController < InheritedResources::Base +class ComplianceControlsController < ChouetteController include PolicyChecker defaults resource_class: ComplianceControl belongs_to :compliance_control_set diff --git a/app/controllers/concerns/paper_trail_support.rb b/app/controllers/concerns/paper_trail_support.rb new file mode 100644 index 000000000..4b0b1a7c7 --- /dev/null +++ b/app/controllers/concerns/paper_trail_support.rb @@ -0,0 +1,11 @@ +module PaperTrailSupport + extend ActiveSupport::Concern + + included do + before_action :set_paper_trail_whodunnit + + def user_for_paper_trail + current_user ? current_user.name : '' + end + end +end diff --git a/app/controllers/connection_link_areas_controller.rb b/app/controllers/connection_link_areas_controller.rb index eceb1b0fc..981a7639e 100644 --- a/app/controllers/connection_link_areas_controller.rb +++ b/app/controllers/connection_link_areas_controller.rb @@ -1,16 +1,17 @@ class ConnectionLinkAreasController < ChouetteController + include ReferentialSupport respond_to :json, :only => :index def index - respond_to do |format| - format.json { render :json => areas_maps } - end + respond_to do |format| + format.json { render :json => areas_maps } + end end def areas_maps areas.collect do |area| - { :id => area.id.to_s, + { :id => area.id.to_s, :name => area.name, :country_code => area.country_code, :zip_code => area.zip_code || "", @@ -20,8 +21,8 @@ class ConnectionLinkAreasController < ChouetteController end end - def areas - referential.connection_links.find(params[:connection_link_id]).possible_areas.select{ |p| p.name =~ /#{params[:q]}/i } + def areas + referential.connection_links.find(params[:connection_link_id]).possible_areas.select{ |p| p.name =~ /#{params[:q]}/i } end end diff --git a/app/controllers/connection_links_controller.rb b/app/controllers/connection_links_controller.rb index b56450291..f14868776 100644 --- a/app/controllers/connection_links_controller.rb +++ b/app/controllers/connection_links_controller.rb @@ -1,4 +1,5 @@ class ConnectionLinksController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::ConnectionLink belongs_to :referential do @@ -53,7 +54,7 @@ class ConnectionLinksController < ChouetteController private def connection_link_params - params.require(:connection_link).permit( :connection_link_type,:departure_id, :arrival_id, :objectid, :object_version, :creator_id, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs ) + params.require(:connection_link).permit( :connection_link_type,:departure_id, :arrival_id, :objectid, :object_version, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs ) end end diff --git a/app/controllers/dashboards_controller.rb b/app/controllers/dashboards_controller.rb index 1c7876c58..c90d0c296 100644 --- a/app/controllers/dashboards_controller.rb +++ b/app/controllers/dashboards_controller.rb @@ -3,8 +3,9 @@ # this controller will use a custom partial like # custom/dashboards/_dashboard.html.slim for Custom::Dashboard # -class DashboardsController < InheritedResources::Base +class DashboardsController < ChouetteController respond_to :html, only: [:show] + defaults :resource_class => Dashboard def show @dashboard = Dashboard.create self diff --git a/app/controllers/export_tasks_controller.rb b/app/controllers/export_tasks_controller.rb index 2b30a5605..b889c1882 100644 --- a/app/controllers/export_tasks_controller.rb +++ b/app/controllers/export_tasks_controller.rb @@ -1,6 +1,7 @@ class ExportTasksController < ChouetteController + include ReferentialSupport defaults :resource_class => ExportTask - + respond_to :html, :only => [:new, :create] respond_to :js, :only => [:new, :create] belongs_to :referential @@ -15,10 +16,10 @@ class ExportTasksController < ChouetteController redirect_to referential_path(@referential) end end - + def create @available_exports = available_exports - begin + begin create! do |success, failure| success.html { redirect_to referential_exports_path(@referential) } end @@ -62,7 +63,7 @@ class ExportTasksController < ChouetteController end end - def build_resource + def build_resource @export_task ||= if params[:export_task].present? export_task_parameters = params[:export_task] case export_task_parameters[:data_format] @@ -80,7 +81,7 @@ class ExportTasksController < ChouetteController else NeptuneExport.new end - + end - + end diff --git a/app/controllers/exports_controller.rb b/app/controllers/exports_controller.rb index ad88c6dae..ccc163e34 100644 --- a/app/controllers/exports_controller.rb +++ b/app/controllers/exports_controller.rb @@ -2,6 +2,7 @@ require 'will_paginate/array' require 'open-uri' class ExportsController < ChouetteController + include ReferentialSupport defaults :resource_class => Export respond_to :html, :only => [:show, :index, :destroy, :exported_file] diff --git a/app/controllers/group_of_lines_controller.rb b/app/controllers/group_of_lines_controller.rb index 1a59d39f7..5762108dc 100644 --- a/app/controllers/group_of_lines_controller.rb +++ b/app/controllers/group_of_lines_controller.rb @@ -1,4 +1,4 @@ -class GroupOfLinesController < InheritedResources::Base +class GroupOfLinesController < ChouetteController include ApplicationHelper include PolicyChecker defaults :resource_class => Chouette::GroupOfLine @@ -73,7 +73,7 @@ class GroupOfLinesController < InheritedResources::Base private def group_of_line_params - params.require(:group_of_line).permit( :objectid, :object_version, :creator_id, :name, :comment, :lines, :registration_number, :line_tokens) + params.require(:group_of_line).permit( :objectid, :object_version, :name, :comment, :lines, :registration_number, :line_tokens) end end diff --git a/app/controllers/import_messages_controller.rb b/app/controllers/import_messages_controller.rb index c3c6b46b5..6546b25f8 100644 --- a/app/controllers/import_messages_controller.rb +++ b/app/controllers/import_messages_controller.rb @@ -1,4 +1,4 @@ -class ImportMessagesController < InheritedResources::Base +class ImportMessagesController < ChouetteController defaults resource_class: ImportMessage, collection_name: 'import_messages', instance_name: 'import_message' respond_to :csv belongs_to :import, :parent_class => Import do diff --git a/app/controllers/import_resources_controller.rb b/app/controllers/import_resources_controller.rb index 3e52233f2..c83721310 100644 --- a/app/controllers/import_resources_controller.rb +++ b/app/controllers/import_resources_controller.rb @@ -1,4 +1,4 @@ -class ImportResourcesController < InheritedResources::Base +class ImportResourcesController < ChouetteController defaults resource_class: ImportResource, collection_name: 'import_resources', instance_name: 'import_resource' respond_to :html belongs_to :import diff --git a/app/controllers/import_tasks_controller.rb b/app/controllers/import_tasks_controller.rb index cb377ec5a..1a349087d 100644 --- a/app/controllers/import_tasks_controller.rb +++ b/app/controllers/import_tasks_controller.rb @@ -1,6 +1,7 @@ class ImportTasksController < ChouetteController + include ReferentialSupport defaults :resource_class => ImportTask - + respond_to :html, :only => [:new, :create] respond_to :js, :only => [:new, :create] belongs_to :referential @@ -15,10 +16,10 @@ class ImportTasksController < ChouetteController redirect_to referential_path(@referential) end end - + def create @available_imports = available_imports - begin + begin create! do |success, failure| success.html { redirect_to referential_imports_path(@referential) } end @@ -33,14 +34,14 @@ class ImportTasksController < ChouetteController def available_imports import_task_parameters = params[:import_task] - + if import_task_parameters.present? @available_imports = [ import_task_parameters[:data_format] == "neptune" ? build_resource : NeptuneImport.new(:referential_id => @referential.id ), import_task_parameters[:data_format] == "netex" ? build_resource : NetexImport.new(:referential_id => @referential.id ), import_task_parameters[:data_format] == "gtfs" ? build_resource : GtfsImport.new(:referential_id => @referential.id ) ] - else + else @available_imports = [ NeptuneImport.new(:referential_id => @referential.id ), NetexImport.new(:referential_id => @referential.id ), @@ -48,7 +49,7 @@ class ImportTasksController < ChouetteController ] end end - + def build_resource @import_task ||= if params[:import_task].present? import_task_parameters = params[:import_task] @@ -64,5 +65,5 @@ class ImportTasksController < ChouetteController @import_task = NeptuneImport.new end end - + end diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 6c9d81d82..5e23a1795 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,4 +1,4 @@ -class ImportsController < InheritedResources::Base +class ImportsController < ChouetteController include PolicyChecker include RansackDateFilter before_action only: [:index] { set_date_time_params("started_at", DateTime) } diff --git a/app/controllers/journey_pattern_stop_points_controller.rb b/app/controllers/journey_pattern_stop_points_controller.rb index c4fc9b08f..65e41af3b 100644 --- a/app/controllers/journey_pattern_stop_points_controller.rb +++ b/app/controllers/journey_pattern_stop_points_controller.rb @@ -1,4 +1,5 @@ class JourneyPatternStopPointsController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::JourneyPattern respond_to :html diff --git a/app/controllers/journey_patterns_collections_controller.rb b/app/controllers/journey_patterns_collections_controller.rb index 546158fa8..736fb1441 100644 --- a/app/controllers/journey_patterns_collections_controller.rb +++ b/app/controllers/journey_patterns_collections_controller.rb @@ -1,4 +1,5 @@ class JourneyPatternsCollectionsController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::JourneyPattern before_action :user_permissions, only: :show diff --git a/app/controllers/journey_patterns_controller.rb b/app/controllers/journey_patterns_controller.rb index a72e7da7f..881ab6630 100644 --- a/app/controllers/journey_patterns_controller.rb +++ b/app/controllers/journey_patterns_controller.rb @@ -1,4 +1,5 @@ class JourneyPatternsController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::JourneyPattern respond_to :html @@ -54,7 +55,7 @@ class JourneyPatternsController < ChouetteController private def journey_pattern_params - params.require(:journey_pattern).permit(:route_id, :objectid, :object_version, :creator_id, :name, :comment, :registration_number, :published_name, :departure_stop_point_id, :arrival_stop_point_id, {:stop_point_ids => []}) + params.require(:journey_pattern).permit(:route_id, :objectid, :object_version, :name, :comment, :registration_number, :published_name, :departure_stop_point_id, :arrival_stop_point_id, {:stop_point_ids => []}) end end diff --git a/app/controllers/line_footnotes_controller.rb b/app/controllers/line_footnotes_controller.rb index 2d4d10064..1fe677a39 100644 --- a/app/controllers/line_footnotes_controller.rb +++ b/app/controllers/line_footnotes_controller.rb @@ -1,4 +1,5 @@ class LineFootnotesController < ChouetteController + include ReferentialSupport defaults resource_class: Chouette::Line, collection_name: 'lines', instance_name: 'line' belongs_to :referential diff --git a/app/controllers/line_referentials_controller.rb b/app/controllers/line_referentials_controller.rb index f70ddef41..39c2cdb89 100644 --- a/app/controllers/line_referentials_controller.rb +++ b/app/controllers/line_referentials_controller.rb @@ -1,4 +1,4 @@ -class LineReferentialsController < InheritedResources::Base +class LineReferentialsController < ChouetteController defaults :resource_class => LineReferential diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb index cf2908500..2f0ef1542 100644 --- a/app/controllers/lines_controller.rb +++ b/app/controllers/lines_controller.rb @@ -1,4 +1,4 @@ -class LinesController < InheritedResources::Base +class LinesController < ChouetteController include ApplicationHelper include PolicyChecker defaults :resource_class => Chouette::Line @@ -119,7 +119,6 @@ class LinesController < InheritedResources::Base :company_id, :objectid, :object_version, - :creator_id, :name, :number, :published_name, diff --git a/app/controllers/networks_controller.rb b/app/controllers/networks_controller.rb index 98c840777..494d1e69f 100644 --- a/app/controllers/networks_controller.rb +++ b/app/controllers/networks_controller.rb @@ -1,4 +1,4 @@ -class NetworksController < InheritedResources::Base +class NetworksController < ChouetteController include ApplicationHelper include PolicyChecker defaults :resource_class => Chouette::Network @@ -22,10 +22,12 @@ class NetworksController < InheritedResources::Base def new authorize resource_class + new! end def create authorize resource_class + create! end def index @@ -70,7 +72,7 @@ class NetworksController < InheritedResources::Base helper_method :current_referential def network_params - params.require(:network).permit(:objectid, :object_version, :creator_id, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) + params.require(:network).permit(:objectid, :object_version, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) end private diff --git a/app/controllers/organisations_controller.rb b/app/controllers/organisations_controller.rb index d80541800..fa521faaf 100644 --- a/app/controllers/organisations_controller.rb +++ b/app/controllers/organisations_controller.rb @@ -1,4 +1,4 @@ -class OrganisationsController < InheritedResources::Base +class OrganisationsController < ChouetteController defaults :resource_class => Organisation respond_to :html, :only => [:edit, :show, :update] diff --git a/app/controllers/referential_companies_controller.rb b/app/controllers/referential_companies_controller.rb index fdbd83dc9..ca1ff67db 100644 --- a/app/controllers/referential_companies_controller.rb +++ b/app/controllers/referential_companies_controller.rb @@ -1,4 +1,5 @@ class ReferentialCompaniesController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::Company, :collection_name => 'companies', :instance_name => 'company' respond_to :html respond_to :xml @@ -55,7 +56,7 @@ class ReferentialCompaniesController < ChouetteController end def company_params - params.require(:company).permit( :objectid, :object_version, :creator_id, :name, :short_name, :organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :registration_number, :url, :time_zone ) + 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 private diff --git a/app/controllers/referential_group_of_lines_controller.rb b/app/controllers/referential_group_of_lines_controller.rb index d88daab84..1294fc5d5 100644 --- a/app/controllers/referential_group_of_lines_controller.rb +++ b/app/controllers/referential_group_of_lines_controller.rb @@ -1,4 +1,5 @@ class ReferentialGroupOfLinesController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::GroupOfLine, :collection_name => 'group_of_lines', :instance_name => 'group_of_line' respond_to :html @@ -68,7 +69,7 @@ class ReferentialGroupOfLinesController < ChouetteController private def group_of_line_params - params.require(:group_of_line).permit( :objectid, :object_version, :creator_id, :name, :comment, :lines, :registration_number, :line_tokens) + params.require(:group_of_line).permit( :objectid, :object_version, :name, :comment, :lines, :registration_number, :line_tokens) end end diff --git a/app/controllers/referential_lines_controller.rb b/app/controllers/referential_lines_controller.rb index b9f8c0050..9e8f5c512 100644 --- a/app/controllers/referential_lines_controller.rb +++ b/app/controllers/referential_lines_controller.rb @@ -1,4 +1,5 @@ class ReferentialLinesController < ChouetteController + include ReferentialSupport include PolicyChecker defaults :resource_class => Chouette::Line, :collection_name => 'lines', :instance_name => 'line' @@ -127,7 +128,6 @@ class ReferentialLinesController < ChouetteController :company_id, :objectid, :object_version, - :creator_id, :name, :number, :published_name, :transport_mode, diff --git a/app/controllers/referential_networks_controller.rb b/app/controllers/referential_networks_controller.rb index 2131b8e57..b2d83f953 100644 --- a/app/controllers/referential_networks_controller.rb +++ b/app/controllers/referential_networks_controller.rb @@ -1,4 +1,5 @@ class ReferentialNetworksController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::Network, :collection_name => 'networks', :instance_name => 'network' respond_to :html respond_to :xml @@ -64,7 +65,7 @@ class ReferentialNetworksController < ChouetteController end def network_params - params.require(:network).permit(:objectid, :object_version, :creator_id, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) + params.require(:network).permit(:objectid, :object_version, :version_date, :description, :name, :registration_number, :source_name, :source_type_name, :source_identifier, :comment ) end private diff --git a/app/controllers/referential_stop_areas_controller.rb b/app/controllers/referential_stop_areas_controller.rb index 78dcd6dd9..0ed330180 100644 --- a/app/controllers/referential_stop_areas_controller.rb +++ b/app/controllers/referential_stop_areas_controller.rb @@ -1,5 +1,6 @@ # -*- coding: utf-8 -*- class ReferentialStopAreasController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::StopArea, :collection_name => 'stop_areas', :instance_name => 'stop_area' belongs_to :referential do @@ -144,7 +145,7 @@ class ReferentialStopAreasController < ChouetteController end 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, :creator_id, :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( :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 ) end end diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb index b63741ef6..ee1236912 100644 --- a/app/controllers/referentials_controller.rb +++ b/app/controllers/referentials_controller.rb @@ -1,4 +1,4 @@ -class ReferentialsController < InheritedResources::Base +class ReferentialsController < ChouetteController defaults :resource_class => Referential include PolicyChecker diff --git a/app/controllers/route_stop_points_controller.rb b/app/controllers/route_stop_points_controller.rb index 730bd08a9..36e1cbc4f 100644 --- a/app/controllers/route_stop_points_controller.rb +++ b/app/controllers/route_stop_points_controller.rb @@ -1,4 +1,5 @@ class RouteStopPointsController < ChouetteController + include ReferentialSupport defaults resource_class: Chouette::StopPoint actions :index respond_to :json, only: :index diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 1a6c82484..79f49143a 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -1,4 +1,5 @@ class RoutesController < ChouetteController + include ReferentialSupport include PolicyChecker defaults :resource_class => Chouette::Route @@ -110,7 +111,6 @@ class RoutesController < ChouetteController :line_id, :objectid, :object_version, - :creator_id, :name, :comment, :opposite_route_id, diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb index 6c3da5980..a72b288b8 100644 --- a/app/controllers/routing_constraint_zones_controller.rb +++ b/app/controllers/routing_constraint_zones_controller.rb @@ -1,4 +1,5 @@ class RoutingConstraintZonesController < ChouetteController + include ReferentialSupport include PolicyChecker defaults resource_class: Chouette::RoutingConstraintZone @@ -96,7 +97,6 @@ class RoutingConstraintZonesController < ChouetteController :route_id, :objectid, :object_version, - :creator_id ) end diff --git a/app/controllers/stop_area_copies_controller.rb b/app/controllers/stop_area_copies_controller.rb index fb429595e..992a2bb08 100644 --- a/app/controllers/stop_area_copies_controller.rb +++ b/app/controllers/stop_area_copies_controller.rb @@ -1,13 +1,14 @@ class StopAreaCopiesController < ChouetteController + include ReferentialSupport defaults :resource_class => StopAreaCopy belongs_to :referential do - belongs_to :stop_area, :parent_class => Chouette::StopArea + belongs_to :stop_area, :parent_class => Chouette::StopArea end - + actions :new, :create respond_to :html, :only => :new - - def new + + def new @stop_area_copy = StopAreaCopy.new(:hierarchy => params[:hierarchy], :source => parent) new! do build_breadcrumb :new @@ -25,6 +26,6 @@ class StopAreaCopiesController < ChouetteController end end - protected + protected end diff --git a/app/controllers/stop_area_referentials_controller.rb b/app/controllers/stop_area_referentials_controller.rb index e2815e5fb..85541230d 100644 --- a/app/controllers/stop_area_referentials_controller.rb +++ b/app/controllers/stop_area_referentials_controller.rb @@ -1,4 +1,4 @@ -class StopAreaReferentialsController < InheritedResources::Base +class StopAreaReferentialsController < ChouetteController defaults :resource_class => StopAreaReferential def sync diff --git a/app/controllers/stop_area_routing_lines_controller.rb b/app/controllers/stop_area_routing_lines_controller.rb index 9ba6fb40c..cba0a369c 100644 --- a/app/controllers/stop_area_routing_lines_controller.rb +++ b/app/controllers/stop_area_routing_lines_controller.rb @@ -1,11 +1,12 @@ class StopAreaRoutingLinesController < ChouetteController + include ReferentialSupport respond_to :json, :only => :index def index - respond_to do |format| - format.json { render :json => routing_lines_maps } - end + respond_to do |format| + format.json { render :json => routing_lines_maps } + end end def routing_lines_maps @@ -14,8 +15,8 @@ class StopAreaRoutingLinesController < ChouetteController end end - def routing_lines - referential.lines.all.select{ |p| p.name =~ /#{params[:q]}/i || p.number =~ /#{params[:q]}/i } + def routing_lines + referential.lines.all.select{ |p| p.name =~ /#{params[:q]}/i || p.number =~ /#{params[:q]}/i } end end diff --git a/app/controllers/stop_areas_controller.rb b/app/controllers/stop_areas_controller.rb index 1d6f88068..133518324 100644 --- a/app/controllers/stop_areas_controller.rb +++ b/app/controllers/stop_areas_controller.rb @@ -1,4 +1,4 @@ -class StopAreasController < InheritedResources::Base +class StopAreasController < ChouetteController include ApplicationHelper defaults :resource_class => Chouette::StopArea @@ -64,22 +64,22 @@ class StopAreasController < InheritedResources::Base def new authorize resource_class - @map = StopAreaMap.new( Chouette::StopArea.new).with_helpers(self) - @map.editable = true + # @map = StopAreaMap.new( Chouette::StopArea.new).with_helpers(self) + # @map.editable = true new! end def create authorize resource_class - @map = StopAreaMap.new( Chouette::StopArea.new).with_helpers(self) - @map.editable = true + # @map = StopAreaMap.new( Chouette::StopArea.new).with_helpers(self) + # @map.editable = true create! end def show - map.editable = false - @access_points = @stop_area.access_points + # map.editable = false + # @access_points = @stop_area.access_points show! do |format| unless stop_area.position or params[:default] or params[:routing] format.kml { @@ -171,7 +171,7 @@ class StopAreasController < InheritedResources::Base 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, :creator_id, :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( :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 ) end end diff --git a/app/controllers/time_table_combinations_controller.rb b/app/controllers/time_table_combinations_controller.rb index ba61a2ea4..26cd425b3 100644 --- a/app/controllers/time_table_combinations_controller.rb +++ b/app/controllers/time_table_combinations_controller.rb @@ -1,4 +1,5 @@ class TimeTableCombinationsController < ChouetteController + include ReferentialSupport belongs_to :referential do belongs_to :time_table, :parent_class => Chouette::TimeTable end diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 0c1769ad7..a0fa168f0 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -1,4 +1,5 @@ class TimeTablesController < ChouetteController + include ReferentialSupport include TimeTablesHelper include RansackDateFilter before_action only: [:index] { set_date_time_params("bounding_dates", Date) } @@ -179,7 +180,6 @@ class TimeTablesController < ChouetteController params.require(:time_table).permit( :objectid, :object_version, - :creator_id, :calendar_id, :version, :comment, :color, :int_day_types, diff --git a/app/controllers/timebands_controller.rb b/app/controllers/timebands_controller.rb index 765557193..937283b0e 100644 --- a/app/controllers/timebands_controller.rb +++ b/app/controllers/timebands_controller.rb @@ -1,4 +1,5 @@ class TimebandsController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::Timeband diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 2452a2796..6343320a4 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1,4 +1,4 @@ -class UsersController < InheritedResources::Base +class UsersController < ChouetteController defaults :resource_class => User diff --git a/app/controllers/vehicle_journey_exports_controller.rb b/app/controllers/vehicle_journey_exports_controller.rb index 0cc30f23a..2ce47e51f 100644 --- a/app/controllers/vehicle_journey_exports_controller.rb +++ b/app/controllers/vehicle_journey_exports_controller.rb @@ -1,22 +1,23 @@ class VehicleJourneyExportsController < ChouetteController + include ReferentialSupport belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line do belongs_to :route, :parent_class => Chouette::Route end end - + respond_to :csv, :only => [:index] respond_to :zip, :only => [:index] #respond_to :xls, :only => [:index] def index - index! do |format| + index! do |format| format.csv { send_data VehicleJourneyExport.new(:route => route, :vehicle_journeys => vehicle_journeys).to_csv(:col_sep => ";") , :filename => t("vehicle_journey_exports.new.basename")+"_#{route.id}.csv" } format.zip do begin temp_file = Tempfile.new("vehicle_journey_export") VehicleJourneyExport.new(:route => route, :vehicle_journeys => vehicle_journeys).to_zip(temp_file,:col_sep => ";") - send_data File.read(temp_file.path), :filename => t("vehicle_journey_exports.new.basename")+"_#{route.id}.zip" + send_data File.read(temp_file.path), :filename => t("vehicle_journey_exports.new.basename")+"_#{route.id}.zip" ensure temp_file.close temp_file.unlink @@ -25,15 +26,15 @@ class VehicleJourneyExportsController < ChouetteController #format.xls end end - + protected - - + + alias_method :route, :parent - + def collection @vehicle_journeys ||= route.vehicle_journeys.includes(:vehicle_journey_at_stops).order("vehicle_journey_at_stops.departure_time") end alias_method :vehicle_journeys, :collection - + end diff --git a/app/controllers/vehicle_journey_imports_controller.rb b/app/controllers/vehicle_journey_imports_controller.rb index 58f8816aa..aec90f7ec 100644 --- a/app/controllers/vehicle_journey_imports_controller.rb +++ b/app/controllers/vehicle_journey_imports_controller.rb @@ -1,4 +1,5 @@ class VehicleJourneyImportsController < ChouetteController + include ReferentialSupport defaults :resource_class => VehicleJourneyImport belongs_to :referential do diff --git a/app/controllers/vehicle_journeys_collections_controller.rb b/app/controllers/vehicle_journeys_collections_controller.rb index caaa2258e..712bcc154 100644 --- a/app/controllers/vehicle_journeys_collections_controller.rb +++ b/app/controllers/vehicle_journeys_collections_controller.rb @@ -1,4 +1,5 @@ class VehicleJourneysCollectionsController < ChouetteController + include ReferentialSupport respond_to :json belongs_to :referential do belongs_to :line, :parent_class => Chouette::Line do diff --git a/app/controllers/vehicle_journeys_controller.rb b/app/controllers/vehicle_journeys_controller.rb index 050f2f219..c941aeae4 100644 --- a/app/controllers/vehicle_journeys_controller.rb +++ b/app/controllers/vehicle_journeys_controller.rb @@ -1,4 +1,5 @@ class VehicleJourneysController < ChouetteController + include ReferentialSupport defaults :resource_class => Chouette::VehicleJourney before_action :user_permissions, only: :index diff --git a/app/controllers/vehicle_translations_controller.rb b/app/controllers/vehicle_translations_controller.rb index 65a0db7fe..5b6b392ac 100644 --- a/app/controllers/vehicle_translations_controller.rb +++ b/app/controllers/vehicle_translations_controller.rb @@ -1,4 +1,5 @@ class VehicleTranslationsController < ChouetteController + include ReferentialSupport respond_to :js, :only => [:new, :create] belongs_to :referential do diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb index 9b4f0d6c4..b2dac9e67 100644 --- a/app/controllers/workbenches_controller.rb +++ b/app/controllers/workbenches_controller.rb @@ -1,4 +1,4 @@ -class WorkbenchesController < InheritedResources::Base +class WorkbenchesController < ChouetteController before_action :query_params, only: [:show] include RansackDateFilter before_action only: [:show] { set_date_time_params("validity_period", Date) } diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index 764cce3a0..9416c73ae 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -49,5 +49,4 @@ class CompanyDecorator < Draper::Decorator links end - end diff --git a/app/decorators/compliance_check_set_decorator.rb b/app/decorators/compliance_check_set_decorator.rb index 5f3821cbe..096596b19 100644 --- a/app/decorators/compliance_check_set_decorator.rb +++ b/app/decorators/compliance_check_set_decorator.rb @@ -3,6 +3,23 @@ class ComplianceCheckSetDecorator < Draper::Decorator def action_links links = [] + + links << Link.new( + content: h.destroy_link_content, + href: h.workbench_compliance_check_sets_path(object.id), + method: :delete, + data: {confirm: h.t('imports.actions.destroy_confirm')} + ) + + links + end + + def lines_status + object.compliance_check_resources.where(status: :OK, resource_type: :line).count + end + + def lines_in_compliance_check_set + object.compliance_check_resources.where(resource_type: :line).count end end diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index f351103b2..ede670cbd 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -22,9 +22,19 @@ class LineDecorator < Draper::Decorator ) if h.policy(Chouette::Line).create? && - context[:line_referential].organisations.include?( - context[:current_organisation] - ) + context[:line_referential].organisations.include?( + context[:current_organisation] + ) + links << Link.new( + content: h.t('lines.actions.edit'), + href: h.edit_line_referential_line_path(context[:line_referential], object.id) + ) + end + + if h.policy(Chouette::Line).create? && + context[:line_referential].organisations.include?( + context[:current_organisation] + ) links << Link.new( content: h.t('lines.actions.new'), href: h.new_line_referential_line_path(context[:line_referential]) @@ -33,10 +43,10 @@ class LineDecorator < Draper::Decorator if h.policy(object).destroy? links << Link.new( - content: h.destroy_link_content('lines.actions.destroy_confirm'), + content: h.destroy_link_content('lines.actions.destroy'), href: h.line_referential_line_path(context[:line_referential], object), method: :delete, - data: { confirm: h.t('lines.actions.destroy_confirm') } + data: {confirm: h.t('lines.actions.destroy_confirm')} ) end diff --git a/app/decorators/referential_network_decorator.rb b/app/decorators/referential_network_decorator.rb index 9eb94c8d2..1260a38cb 100644 --- a/app/decorators/referential_network_decorator.rb +++ b/app/decorators/referential_network_decorator.rb @@ -3,36 +3,36 @@ class ReferentialNetworkDecorator < Draper::Decorator delegate_all - # Requires: - # context: { - # referential: , - # } - def action_links - links = [] +# Requires: +# context: { +# referential: , +# } +def action_links + links = [] - if h.policy(Chouette::Network).create? - links << Link.new( - content: h.t('networks.actions.new'), - href: h.new_referential_network_path(context[:referential]) - ) - end + if h.policy(Chouette::Network).create? + links << Link.new( + content: h.t('networks.actions.new'), + href: h.new_referential_network_path(context[:referential]) + ) + end - if h.policy(object).update? - links << Link.new( - content: h.t('networks.actions.edit'), - href: h.edit_referential_network_path(context[:referential], object) - ) - end + if h.policy(object).update? + links << Link.new( + content: h.t('networks.actions.edit'), + href: h.edit_referential_network_path(context[:referential], object) + ) + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('networks.actions.destroy'), - href: h.referential_network_path(context[:referential], object), - method: :delete, - data: { confirm: t('networks.actions.destroy_confirm') } - ) - end + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('networks.actions.destroy'), + href: h.referential_network_path(context[:referential], object), + method: :delete, + data: { confirm: t('networks.actions.destroy_confirm') } + ) + end links end -end +end
\ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 0a7b0fb75..2ce1de497 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -1,7 +1,33 @@ + module ApplicationHelper include NewapplicationHelper + def page_header_title(object) + # Unwrap from decorator, we want to know the object model name + object = object.object if object.try(:object) + local = "#{object.model_name.name.underscore.pluralize}.#{params[:action]}.title" + if object.try(:name) + t(local, name: object.name) + else + t(local) + end + end + + def page_header_meta(object) + info = t('last_update', time: l(object.updated_at, format: :short)) + if object.try(:versions) + author = object.versions.try(:last).try(:whodunnit) || t('default_whodunnit') + info = "#{info} #{t('whodunnit', author: author)}" + end + content_tag :div, info.html_safe, class: 'small' + end + + def page_header_content_for(object) + content_for :page_header_title, page_header_title(object) + content_for :page_header_meta, page_header_meta(object) + end + def font_awesome_classic_tag(name) name = "fa-file-text-o" if name == "fa-file-csv-o" name = "fa-file-code-o" if name == "fa-file-xml-o" diff --git a/app/helpers/compliance_check_sets_helper.rb b/app/helpers/compliance_check_sets_helper.rb index fc7165fed..b255aee63 100644 --- a/app/helpers/compliance_check_sets_helper.rb +++ b/app/helpers/compliance_check_sets_helper.rb @@ -13,4 +13,18 @@ module ComplianceCheckSetsHelper compliance_check.compliance_check_set, compliance_check) end + + # Import statuses helper + def compliance_check_set_status(status) + if %w[new running pending].include? status + content_tag :span, '', class: "fa fa-clock-o" + else + cls ='' + cls = 'success' if status == 'OK' + cls = 'warning' if status == 'WARNING' + cls = 'danger' if %w[ERROR IGNORED].include? status + + content_tag :span, '', class: "fa fa-circle text-#{cls}" + end + end end diff --git a/app/helpers/custom_view_helper.rb b/app/helpers/custom_view_helper.rb new file mode 100644 index 000000000..7e7291c81 --- /dev/null +++ b/app/helpers/custom_view_helper.rb @@ -0,0 +1,9 @@ +module CustomViewHelper + + def render_custom_view(view) + view_name = [view, current_organisation.try(:custom_view)].compact.join('_') + Rails.logger.debug "Render custom view #{view_name}" + render partial: view_name + end + +end diff --git a/app/helpers/import_resources_helper.rb b/app/helpers/import_resources_helper.rb index 3ee96eb9b..1d870f68e 100644 --- a/app/helpers/import_resources_helper.rb +++ b/app/helpers/import_resources_helper.rb @@ -12,4 +12,8 @@ module ImportResourcesHelper content_tag :span, '', class: "fa fa-circle text-#{cls}" end + def import_resoruce_metrics(metrics) + metrics.delete_if {|k,v| !k.include?("count")}.deep_symbolize_keys + end + end diff --git a/app/helpers/networks_helper.rb b/app/helpers/networks_helper.rb deleted file mode 100644 index b881ce078..000000000 --- a/app/helpers/networks_helper.rb +++ /dev/null @@ -1,7 +0,0 @@ -module NetworksHelper - - def source_type_name_label_pairs - Chouette::Network.source_type_names - .zip_map { |source_type_name| t("source_types.label.#{source_type_name}") } - end -end diff --git a/app/javascript/journey_patterns/actions/index.js b/app/javascript/journey_patterns/actions/index.js index 8bea5a990..4ff3f77ea 100644 --- a/app/javascript/journey_patterns/actions/index.js +++ b/app/javascript/journey_patterns/actions/index.js @@ -90,10 +90,6 @@ const actions = { resetValidation: (target) => { $(target).parent().removeClass('has-error').children('.help-block').remove() }, - humanOID : (oid) => { - let shortOId = oid.split(':')[2].split("-").pop() - return shortOId.length > 10 ? `${shortOId.slice(0, 10)}...` : shortOId - }, validateFields : (fields) => { const test = [] @@ -201,6 +197,7 @@ const actions = { journeyPatterns.push({ name: val.name, object_id: val.object_id, + short_id: val.short_id, published_name: val.published_name, registration_number: val.registration_number, stop_points: val.route_short_description.stop_points, diff --git a/app/javascript/journey_patterns/components/JourneyPattern.js b/app/javascript/journey_patterns/components/JourneyPattern.js index 34d102c5d..d4c9816ec 100644 --- a/app/javascript/journey_patterns/components/JourneyPattern.js +++ b/app/javascript/journey_patterns/components/JourneyPattern.js @@ -68,7 +68,7 @@ export default class JourneyPattern extends Component{ {/* this.props.value.errors ? this.getErrors(this.props.value.errors) : '' */} <div className='th'> - <div className='strong mb-xs'>{this.props.value.object_id ? actions.humanOID(this.props.value.object_id) : '-'}</div> + <div className='strong mb-xs'>{this.props.value.object_id ? this.props.value.short_id : '-'}</div> <div>{this.props.value.registration_number}</div> <div>{actions.getChecked(this.props.value.stop_points).length} arrêt(s)</div> diff --git a/app/javascript/vehicle_journeys/actions/index.js b/app/javascript/vehicle_journeys/actions/index.js index 95c739893..ddb54d615 100644 --- a/app/javascript/vehicle_journeys/actions/index.js +++ b/app/javascript/vehicle_journeys/actions/index.js @@ -269,10 +269,6 @@ const actions = { type: 'RECEIVE_TOTAL_COUNT', total }), - humanOID: (oid) => { - let shortOId = oid.split(':')[2].split("-").pop() - return shortOId.length > 10 ? `${shortOId.slice(0, 10)}...` : shortOId - }, fetchVehicleJourneys : (dispatch, currentPage, nextPage, queryString) => { if(currentPage == undefined){ currentPage = 1 @@ -334,6 +330,7 @@ const actions = { journey_pattern: val.journey_pattern, published_journey_name: val.published_journey_name, objectid: val.objectid, + short_id: val.short_id, footnotes: val.footnotes, time_tables: timeTables, vehicle_journey_at_stops: vjasWithDelta, diff --git a/app/javascript/vehicle_journeys/components/VehicleJourney.js b/app/javascript/vehicle_journeys/components/VehicleJourney.js index 13f8eced2..8fb4b8a7e 100644 --- a/app/javascript/vehicle_journeys/components/VehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/VehicleJourney.js @@ -49,8 +49,8 @@ export default class VehicleJourney extends Component { return ( <div className={'t2e-item' + (this.props.value.deletable ? ' disabled' : '') + (this.props.value.errors ? ' has-error': '')}> <div className='th'> - <div className='strong mb-xs'>{this.props.value.objectid ? actions.humanOID(this.props.value.objectid) : '-'}</div> - <div>{actions.humanOID(this.props.value.journey_pattern.objectid)}</div> + <div className='strong mb-xs'>{this.props.value.objectid ? this.props.value.short_id : '-'}</div> + <div>{this.props.value.journey_pattern.short_id}</div> <div> {time_tables.slice(0,3).map((tt, i)=> <span key={i} className='vj_tt'>{this.timeTableURL(tt)}</span> diff --git a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js index 7ad3cf510..7d91896eb 100644 --- a/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/EditVehicleJourney.js @@ -72,7 +72,7 @@ export default class EditVehicleJourney extends Component { <input type='text' className='form-control' - value={actions.humanOID(this.props.modal.modalProps.vehicleJourney.journey_pattern.objectid) + ' - ' + (this.props.modal.modalProps.vehicleJourney.journey_pattern.name)} + value={this.props.modal.modalProps.vehicleJourney.journey_pattern.short_id + ' - ' + (this.props.modal.modalProps.vehicleJourney.journey_pattern.name)} disabled={true} /> </div> diff --git a/app/javascript/vehicle_journeys/components/tools/ShiftVehicleJourney.js b/app/javascript/vehicle_journeys/components/tools/ShiftVehicleJourney.js index ebfbed9eb..a54e40502 100644 --- a/app/javascript/vehicle_journeys/components/tools/ShiftVehicleJourney.js +++ b/app/javascript/vehicle_journeys/components/tools/ShiftVehicleJourney.js @@ -49,7 +49,7 @@ export default class ShiftVehicleJourney extends Component { <div className='modal-header'> <h4 className='modal-title'>Mettre à jour une course</h4> {(this.props.modal.type == 'shift') && ( - <em>Mettre à jour les horaires de la course {actions.humanOID(actions.getSelected(this.props.vehicleJourneys)[0].objectid)}</em> + <em>Mettre à jour les horaires de la course {actions.getSelected(this.props.vehicleJourneys)[0].short_id}</em> )} <span type="button" className="close modal-close" data-dismiss="modal">×</span> </div> diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js index 6069bf089..5b4ae564c 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/MissionSelect2.js @@ -42,7 +42,7 @@ export default class BSelect4 extends Component { item => _.assign( {}, item, - { text: "<strong>" + item.published_name + " - " + actions.humanOID(item.object_id) + "</strong><br/><small>" + item.registration_number + "</small>" } + { text: "<strong>" + item.published_name + " - " + item.short_id + "</strong><br/><small>" + item.registration_number + "</small>" } ) ) }; diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js index 60c3eab83..a90a9f7b8 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/TimetableSelect2.js @@ -44,7 +44,7 @@ export default class BSelect4 extends Component { item => _.assign( {}, item, - {text: '<strong>' + "<span class='fa fa-circle' style='color:" + (item.color ? item.color : '#4B4B4B') + "'></span> " + item.comment + ' - ' + actions.humanOID(item.objectid) + '</strong><br/><small>' + (item.day_types ? item.day_types.match(/[A-Z]?[a-z]+/g).join(', ') : "") + '</small>'} + {text: '<strong>' + "<span class='fa fa-circle' style='color:" + (item.color ? item.color : '#4B4B4B') + "'></span> " + item.comment + ' - ' + item.short_id + '</strong><br/><small>' + (item.day_types ? item.day_types.match(/[A-Z]?[a-z]+/g).join(', ') : "") + '</small>'} ) ) }; diff --git a/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js b/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js index 7cccbbc05..37628fce0 100644 --- a/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js +++ b/app/javascript/vehicle_journeys/components/tools/select2s/VJSelect2.js @@ -42,7 +42,7 @@ export default class BSelect4b extends Component { item => _.assign( {}, item, - { id: item.objectid, text: actions.humanOID(item.objectid) } + { id: item.objectid, text: item.short_id } ) ) }; diff --git a/app/models/api/v1/api_key.rb b/app/models/api/v1/api_key.rb index 767e65f3a..09c6f77ac 100644 --- a/app/models/api/v1/api_key.rb +++ b/app/models/api/v1/api_key.rb @@ -1,6 +1,7 @@ module Api module V1 class ApiKey < ::ActiveRecord::Base + has_paper_trail before_create :generate_access_token belongs_to :referential, :class_name => '::Referential' belongs_to :organisation, :class_name => '::Organisation' diff --git a/app/models/calendar.rb b/app/models/calendar.rb index bb38e74df..b2e73929f 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -3,7 +3,7 @@ require_relative 'calendar/date_value' require_relative 'calendar/period' class Calendar < ActiveRecord::Base - + has_paper_trail belongs_to :organisation has_many :time_tables diff --git a/app/models/chouette/access_link.rb b/app/models/chouette/access_link.rb index b43dcfb7f..4b99ab5ba 100644 --- a/app/models/chouette/access_link.rb +++ b/app/models/chouette/access_link.rb @@ -1,5 +1,7 @@ module Chouette - class AccessLink < TridentActiveRecord + class AccessLink < Chouette::TridentActiveRecord + has_paper_trail + include ObjectidSupport # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" @@ -49,11 +51,11 @@ module Chouette def link_key Chouette::AccessLink.build_link_key(access_point,stop_area,link_orientation_type) end - + def self.build_link_key(access_point,stop_area,link_orientation_type) if link_orientation_type == "access_point_to_stop_area" "A_#{access_point.id}-S_#{stop_area.id}" - else + else "S_#{stop_area.id}-A_#{access_point.id}" end end diff --git a/app/models/chouette/access_point.rb b/app/models/chouette/access_point.rb index 4a1ae8a0e..7428db1ea 100644 --- a/app/models/chouette/access_point.rb +++ b/app/models/chouette/access_point.rb @@ -1,173 +1,172 @@ require 'geokit' require 'geo_ruby' -class Chouette::AccessPoint < Chouette::ActiveRecord - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - include StifReflexAttributesSupport - include Geokit::Mappable - include ProjectionFields +module Chouette + class AccessPoint < Chouette::ActiveRecord + has_paper_trail + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - has_many :access_links, :dependent => :destroy - belongs_to :stop_area + include Geokit::Mappable + include ProjectionFields + include ObjectidSupport - attr_accessor :access_point_type - attr_writer :coordinates + has_many :access_links, :dependent => :destroy + belongs_to :stop_area - validates_presence_of :name - validates_presence_of :access_type + attr_accessor :access_point_type + attr_writer :coordinates - validates_presence_of :latitude, :if => :longitude - validates_presence_of :longitude, :if => :latitude - validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true - validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true - - validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true - before_save :coordinates_to_lat_lng - def self.nullable_attributes - [:street_name, :country_code, :comment, :long_lat_type, :zip_code, :city_name] - end + validates_presence_of :name + validates_presence_of :access_type + validates_presence_of :latitude, :if => :longitude + validates_presence_of :longitude, :if => :latitude + validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true + validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true - def referential - @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! - end + validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true + before_save :coordinates_to_lat_lng + def self.nullable_attributes + [:street_name, :country_code, :comment, :long_lat_type, :zip_code, :city_name] + end - def referential - @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! - end + def referential + @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! + end - def combine_lat_lng - if self.latitude.nil? || self.longitude.nil? - "" - else - self.latitude.to_s+","+self.longitude.to_s + def combine_lat_lng + if self.latitude.nil? || self.longitude.nil? + "" + else + self.latitude.to_s+","+self.longitude.to_s + end end - end - def coordinates - @coordinates || combine_lat_lng - end + def coordinates + @coordinates || combine_lat_lng + end - def coordinates_to_lat_lng - if ! @coordinates.nil? - if @coordinates.empty? - self.latitude = nil - self.longitude = nil - else - self.latitude = BigDecimal.new(@coordinates.split(",").first) - self.longitude = BigDecimal.new(@coordinates.split(",").last) + def coordinates_to_lat_lng + if ! @coordinates.nil? + if @coordinates.empty? + self.latitude = nil + self.longitude = nil + else + self.latitude = BigDecimal.new(@coordinates.split(",").first) + self.longitude = BigDecimal.new(@coordinates.split(",").last) + end + @coordinates = nil end - @coordinates = nil end - end - def to_lat_lng - Geokit::LatLng.new(latitude, longitude) if latitude and longitude - end + def to_lat_lng + Geokit::LatLng.new(latitude, longitude) if latitude and longitude + end - def geometry - GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude - end + def geometry + GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude + end - def geometry=(geometry) - geometry = geometry.to_wgs84 - self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" - end + def geometry=(geometry) + geometry = geometry.to_wgs84 + self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" + end - def position - geometry - end + def position + geometry + end - def position=(position) - position = nil if String === position && position == "" - position = Geokit::LatLng.normalize(position), 4326 if String === position - self.latitude = position.lat - self.longitude = position.lng - end + def position=(position) + position = nil if String === position && position == "" + position = Geokit::LatLng.normalize(position), 4326 if String === position + self.latitude = position.lat + self.longitude = position.lng + end - def default_position - stop_area.geometry or stop_area.default_position - end + def default_position + stop_area.geometry or stop_area.default_position + end - def access_point_type - access_type && Chouette::AccessPointType.new(access_type.underscore) - end + def access_point_type + access_type && Chouette::AccessPointType.new(access_type.underscore) + end - def access_point_type=(access_point_type) - self.access_type = (access_point_type ? access_point_type.camelcase : nil) - end + def access_point_type=(access_point_type) + self.access_type = (access_point_type ? access_point_type.camelcase : nil) + end - @@access_point_types = nil - def self.access_point_types - @@access_point_types ||= Chouette::AccessPointType.all.select do |access_point_type| - access_point_type.to_i >= 0 + @@access_point_types = nil + def self.access_point_types + @@access_point_types ||= Chouette::AccessPointType.all.select do |access_point_type| + access_point_type.to_i >= 0 + end end - end - def generic_access_link_matrix - matrix = Array.new - hash = Hash.new - access_links.each do |link| - hash[link.link_key] = link - end - key=Chouette::AccessLink.build_link_key(self,stop_area,"access_point_to_stop_area") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = stop_area - link.link_orientation_type = "access_point_to_stop_area" - matrix << link - end - key=Chouette::AccessLink.build_link_key(self,stop_area,"stop_area_to_access_point") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = stop_area - link.link_orientation_type = "stop_area_to_access_point" - matrix << link - end - matrix - end + def generic_access_link_matrix + matrix = Array.new + hash = Hash.new + access_links.each do |link| + hash[link.link_key] = link + end + key=Chouette::AccessLink.build_link_key(self,stop_area,"access_point_to_stop_area") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = stop_area + link.link_orientation_type = "access_point_to_stop_area" + matrix << link + end + key=Chouette::AccessLink.build_link_key(self,stop_area,"stop_area_to_access_point") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = stop_area + link.link_orientation_type = "stop_area_to_access_point" + matrix << link + end + matrix + end - def detail_access_link_matrix - matrix = Array.new - hash = Hash.new - access_links.each do |link| - hash[link.link_key] = link - end - stop_area.children_at_base.each do |child| - key=Chouette::AccessLink.build_link_key(self,child,"access_point_to_stop_area") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = child - link.link_orientation_type = "access_point_to_stop_area" - matrix << link - end - key=Chouette::AccessLink.build_link_key(self,child,"stop_area_to_access_point") - if hash.has_key?(key) - matrix << hash[key] - else - link = Chouette::AccessLink.new - link.access_point = self - link.stop_area = child - link.link_orientation_type = "stop_area_to_access_point" - matrix << link - end - end - matrix - end + def detail_access_link_matrix + matrix = Array.new + hash = Hash.new + access_links.each do |link| + hash[link.link_key] = link + end + stop_area.children_at_base.each do |child| + key=Chouette::AccessLink.build_link_key(self,child,"access_point_to_stop_area") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = child + link.link_orientation_type = "access_point_to_stop_area" + matrix << link + end + key=Chouette::AccessLink.build_link_key(self,child,"stop_area_to_access_point") + if hash.has_key?(key) + matrix << hash[key] + else + link = Chouette::AccessLink.new + link.access_point = self + link.stop_area = child + link.link_orientation_type = "stop_area_to_access_point" + matrix << link + end + end + matrix + end - def geometry_presenter - Chouette::Geometry::AccessPointPresenter.new self + def geometry_presenter + Chouette::Geometry::AccessPointPresenter.new self + end end end diff --git a/app/models/chouette/access_point_type.rb b/app/models/chouette/access_point_type.rb index 94d28e5ae..f7439a428 100644 --- a/app/models/chouette/access_point_type.rb +++ b/app/models/chouette/access_point_type.rb @@ -1,50 +1,52 @@ -class Chouette::AccessPointType < ActiveSupport::StringInquirer +module Chouette + class AccessPointType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - def to_i - @numerical_code - end + def to_i + @numerical_code + end - def inspect - "#{to_s}/#{to_i}" - end + def inspect + "#{to_s}/#{to_i}" + end - def name - camelize - end + def name + camelize + end - @@definitions = [ - ["in", 0], - ["out", 1], - ["in_out", 2] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@definitions = [ + ["in", 0], + ["out", 1], + ["in_out", 2] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/active_record.rb b/app/models/chouette/active_record.rb index e12f30266..c2aab9d50 100644 --- a/app/models/chouette/active_record.rb +++ b/app/models/chouette/active_record.rb @@ -24,6 +24,10 @@ module Chouette end end + def self.model_name + ActiveModel::Name.new self, Chouette, self.name.demodulize + end + # TODO: Can we remove this? # class << self # alias_method :create_reflection_without_chouette_naming, :create_reflection diff --git a/app/models/chouette/command.rb b/app/models/chouette/command.rb index d2995a000..b735747bf 100644 --- a/app/models/chouette/command.rb +++ b/app/models/chouette/command.rb @@ -10,85 +10,85 @@ require 'tmpdir' end #end -class Chouette::Command +module Chouette + class Command - include Chouette::CommandLineSupport + include Chouette::CommandLineSupport - @@command = "chouette" - cattr_accessor :command + @@command = "chouette" + cattr_accessor :command - attr_accessor :database, :schema, :host, :user, :password, :port + attr_accessor :database, :schema, :host, :user, :password, :port - def initialize(options = {}) - database_options_from_active_record.merge(options).each do |k,v| - send "#{k}=", v + def initialize(options = {}) + database_options_from_active_record.merge(options).each do |k,v| + send "#{k}=", v + end end - end - def database_options_from_active_record - config = Chouette::ActiveRecord.connection_pool.spec.config - { - :database => config[:database], - :user => config[:username], - :password => config[:password], - :port => config[:port], - :host => (config[:host] or "localhost") - } - end + def database_options_from_active_record + config = Chouette::ActiveRecord.connection_pool.spec.config + { + :database => config[:database], + :user => config[:username], + :password => config[:password], + :port => config[:port], + :host => (config[:host] or "localhost") + } + end - def run!(options = {}) - Dir.mktmpdir do |config_dir| - chouette_properties = File.join(config_dir, "chouette.properties") - open(chouette_properties, "w") do |f| - f.puts "database.name = #{database}" - f.puts "database.schema = #{schema}" - #f.puts "database.showsql = true" - f.puts "hibernate.username = #{user}" - f.puts "hibernate.password = #{password}" - f.puts "jdbc.url=jdbc:postgresql://#{host}:#{port}/#{database}" - f.puts "jdbc.username = #{user}" - f.puts "jdbc.password = #{password}" - #f.puts "database.hbm2ddl.auto=update" - end + def run!(options = {}) + Dir.mktmpdir do |config_dir| + chouette_properties = File.join(config_dir, "chouette.properties") + open(chouette_properties, "w") do |f| + f.puts "database.name = #{database}" + f.puts "database.schema = #{schema}" + #f.puts "database.showsql = true" + f.puts "hibernate.username = #{user}" + f.puts "hibernate.password = #{password}" + f.puts "jdbc.url=jdbc:postgresql://#{host}:#{port}/#{database}" + f.puts "jdbc.username = #{user}" + f.puts "jdbc.password = #{password}" + #f.puts "database.hbm2ddl.auto=update" + end - logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}" + logger.debug "Chouette properties: #{File.readlines(chouette_properties).collect(&:strip).join(', ')}" - command_line = "#{command} -classpath #{config_dir} #{command_options(options)}" - logger.debug "Execute '#{command_line}'" + command_line = "#{command} -classpath #{config_dir} #{command_options(options)}" + logger.debug "Execute '#{command_line}'" - execute! command_line + execute! command_line + end end - end - class Option + class Option - attr_accessor :key, :value + attr_accessor :key, :value - def initialize(key, value) - @key, @value = key.to_s, value - end + def initialize(key, value) + @key, @value = key.to_s, value + end - def command_key - key.camelize(:lower) - end + def command_key + key.camelize(:lower) + end - def to_s - unless value == true - "-#{command_key} #{value}" - else - "-#{command_key}" + def to_s + unless value == true + "-#{command_key} #{value}" + else + "-#{command_key}" + end end + end - end + def command_options(options) + options.collect do |key, value| + Option.new(key, value) + end.sort_by(&:key).join(' ') + end - def command_options(options) - options.collect do |key, value| - Option.new(key, value) - end.sort_by(&:key).join(' ') end - - - -end +end
\ No newline at end of file diff --git a/app/models/chouette/company.rb b/app/models/chouette/company.rb index a472020e1..12b21e347 100644 --- a/app/models/chouette/company.rb +++ b/app/models/chouette/company.rb @@ -1,18 +1,20 @@ -class Chouette::Company < Chouette::ActiveRecord - include CompanyRestrictions - include StifCodifligneAttributesSupport - include LineReferentialSupport +module Chouette + class Company < Chouette::ActiveRecord + include CompanyRestrictions + include LineReferentialSupport + include ObjectidSupport + has_paper_trail - has_many :lines + has_many :lines - validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true - validates_presence_of :name - validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true + validates_presence_of :name + validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true - def self.nullable_attributes - [:organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :url, :time_zone] - end + def self.nullable_attributes + [:organizational_unit, :operating_department_name, :code, :phone, :fax, :email, :url, :time_zone] + end + end end - diff --git a/app/models/chouette/connection_link.rb b/app/models/chouette/connection_link.rb index e225c2fae..d5ddc606a 100644 --- a/app/models/chouette/connection_link.rb +++ b/app/models/chouette/connection_link.rb @@ -1,48 +1,51 @@ -class Chouette::ConnectionLink < Chouette::TridentActiveRecord - include ConnectionLinkRestrictions - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" +module Chouette + class ConnectionLink < Chouette::TridentActiveRecord + has_paper_trail + include ObjectidSupport + include ConnectionLinkRestrictions + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - attr_accessor :connection_link_type + attr_accessor :connection_link_type - belongs_to :departure, :class_name => 'Chouette::StopArea' - belongs_to :arrival, :class_name => 'Chouette::StopArea' + belongs_to :departure, :class_name => 'Chouette::StopArea' + belongs_to :arrival, :class_name => 'Chouette::StopArea' - validates_presence_of :name + validates_presence_of :name - def self.nullable_attributes - [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, - :mobility_restricted_traveller_duration, :link_type] - end + def self.nullable_attributes + [:link_distance, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, + :mobility_restricted_traveller_duration, :link_type] + end - def connection_link_type - link_type && Chouette::ConnectionLinkType.new( link_type.underscore) - end + def connection_link_type + link_type && Chouette::ConnectionLinkType.new( link_type.underscore) + end - def connection_link_type=(connection_link_type) - self.link_type = (connection_link_type ? connection_link_type.camelcase : nil) - end + def connection_link_type=(connection_link_type) + self.link_type = (connection_link_type ? connection_link_type.camelcase : nil) + end - @@connection_link_types = nil - def self.connection_link_types - @@connection_link_types ||= Chouette::ConnectionLinkType.all - end + @@connection_link_types = nil + def self.connection_link_types + @@connection_link_types ||= Chouette::ConnectionLinkType.all + end - def possible_areas - Chouette::StopArea.where("area_type != 'ITL'") - end + def possible_areas + Chouette::StopArea.where("area_type != 'ITL'") + end - def stop_areas - Chouette::StopArea.where(:id => [self.departure_id,self.arrival_id]) - end + def stop_areas + Chouette::StopArea.where(:id => [self.departure_id,self.arrival_id]) + end - def geometry - GeoRuby::SimpleFeatures::LineString.from_points( [ departure.geometry, arrival.geometry], 4326) if departure.geometry and arrival.geometry - end + def geometry + GeoRuby::SimpleFeatures::LineString.from_points( [ departure.geometry, arrival.geometry], 4326) if departure.geometry and arrival.geometry + end - def geometry_presenter - Chouette::Geometry::ConnectionLinkPresenter.new self - end + def geometry_presenter + Chouette::Geometry::ConnectionLinkPresenter.new self + end + end end - diff --git a/app/models/chouette/connection_link_type.rb b/app/models/chouette/connection_link_type.rb index 41635f48c..516395ed9 100644 --- a/app/models/chouette/connection_link_type.rb +++ b/app/models/chouette/connection_link_type.rb @@ -1,51 +1,50 @@ -class Chouette::ConnectionLinkType < ActiveSupport::StringInquirer - - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end +module Chouette + class ConnectionLinkType < ActiveSupport::StringInquirer + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - - def to_i - @numerical_code - end - def inspect - "#{to_s}/#{to_i}" - end + def to_i + @numerical_code + end - def name - camelize - end + def inspect + "#{to_s}/#{to_i}" + end - @@definitions = [ - ["underground", 0], - ["mixed", 1], - ["overground", 2] - ] - cattr_reader :definitions + def name + camelize + end - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@definitions = [ + ["underground", 0], + ["mixed", 1], + ["overground", 2] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end end - -end - +end
\ No newline at end of file diff --git a/app/models/chouette/direction.rb b/app/models/chouette/direction.rb index 93bc1318b..2d3fea10a 100644 --- a/app/models/chouette/direction.rb +++ b/app/models/chouette/direction.rb @@ -1,60 +1,59 @@ -class Chouette::Direction < ActiveSupport::StringInquirer - - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end +module Chouette + class Direction < ActiveSupport::StringInquirer + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - - def to_i - @numerical_code - end - def inspect - "#{to_s}/#{to_i}" - end + def to_i + @numerical_code + end - def name - to_s - end + def inspect + "#{to_s}/#{to_i}" + end - @@definitions = [ - ["straight_forward", 0], - ["backward", 1], - ["clock_wise", 2], - ["counter_clock_wise", 3], - ["north", 4], - ["north_west", 5], - ["west", 6], - ["south_west", 7], - ["south", 8], - ["south_east", 9], - ["east", 10], - ["north_east", 11] - ] - cattr_reader :definitions + def name + to_s + end - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@definitions = [ + ["straight_forward", 0], + ["backward", 1], + ["clock_wise", 2], + ["counter_clock_wise", 3], + ["north", 4], + ["north_west", 5], + ["west", 6], + ["south_west", 7], + ["south", 8], + ["south_east", 9], + ["east", 10], + ["north_east", 11] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end end - -end - +end
\ No newline at end of file diff --git a/app/models/chouette/exporter.rb b/app/models/chouette/exporter.rb index df85a9dde..98cab7269 100644 --- a/app/models/chouette/exporter.rb +++ b/app/models/chouette/exporter.rb @@ -1,32 +1,34 @@ -class Chouette::Exporter +module Chouette + class Exporter - attr_reader :schema + attr_reader :schema - def initialize(schema) - @schema = schema - end + def initialize(schema) + @schema = schema + end - def chouette_command - @chouette_command ||= Chouette::Command.new(:schema => schema) - end + def chouette_command + @chouette_command ||= Chouette::Command.new(:schema => schema) + end - def export(file, options = {}) - options = { - :format => :neptune - }.merge(options) - - command_options = { - :c => "export", - :o => "line", - :format => options.delete(:format).to_s.upcase, - :output_file => File.expand_path(file), - :optimize_memory => true - }.merge(options) - - logger.info "Export #{file} in schema #{schema}" - chouette_command.run! command_options - end + def export(file, options = {}) + options = { + :format => :neptune + }.merge(options) - include Chouette::CommandLineSupport + command_options = { + :c => "export", + :o => "line", + :format => options.delete(:format).to_s.upcase, + :output_file => File.expand_path(file), + :optimize_memory => true + }.merge(options) -end + logger.info "Export #{file} in schema #{schema}" + chouette_command.run! command_options + end + + include Chouette::CommandLineSupport + + end +end
\ No newline at end of file diff --git a/app/models/chouette/file_validator.rb b/app/models/chouette/file_validator.rb index 513648a62..98453c71c 100644 --- a/app/models/chouette/file_validator.rb +++ b/app/models/chouette/file_validator.rb @@ -1,47 +1,49 @@ -class Chouette::FileValidator +module Chouette + class FileValidator - attr_reader :schema, :database, :user, :password, :host + attr_reader :schema, :database, :user, :password, :host - def initialize(schema) - @schema = schema + def initialize(schema) + @schema = schema - Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| - @database = config[:database] - @user = config[:username] - @password = config[:password] - @host = (config[:host] or "localhost") + Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| + @database = config[:database] + @user = config[:username] + @password = config[:password] + @host = (config[:host] or "localhost") + end end - end - def self.chouette_command=(command) - Chouette::Command.command = command - end + def self.chouette_command=(command) + Chouette::Command.command = command + end - class << self - deprecate :chouette_command= => "Use Chouette::Command.command =" - end + class << self + deprecate :chouette_command= => "Use Chouette::Command.command =" + end - def chouette_command - @chouette_command ||= Chouette::Command.new(:schema => schema) - end + def chouette_command + @chouette_command ||= Chouette::Command.new(:schema => schema) + end - def validate(file, options = {}) - options = { - :format => :neptune - }.merge(options) + def validate(file, options = {}) + options = { + :format => :neptune + }.merge(options) - command_options = { - :c => "validate", - :o => "line", - :input_file => File.expand_path(file), - :optimize_memory => true - }.merge(options) + command_options = { + :c => "validate", + :o => "line", + :input_file => File.expand_path(file), + :optimize_memory => true + }.merge(options) - logger.info "Validate #{file}" - chouette_command.run! command_options - end + logger.info "Validate #{file}" + chouette_command.run! command_options + end - include Chouette::CommandLineSupport + include Chouette::CommandLineSupport -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/footnote.rb b/app/models/chouette/footnote.rb index 1664faf23..051027cea 100644 --- a/app/models/chouette/footnote.rb +++ b/app/models/chouette/footnote.rb @@ -1,13 +1,15 @@ -class Chouette::Footnote < Chouette::ActiveRecord - include ChecksumSupport +module Chouette + class Footnote < Chouette::ActiveRecord + include ChecksumSupport - belongs_to :line, inverse_of: :footnotes - has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' + belongs_to :line, inverse_of: :footnotes + has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' - validates_presence_of :line + validates_presence_of :line - def checksum_attributes - attrs = ['code', 'label'] - self.slice(*attrs).values + def checksum_attributes + attrs = ['code', 'label'] + self.slice(*attrs).values + end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/group_of_line.rb b/app/models/chouette/group_of_line.rb index a987d6311..75ee1ce73 100644 --- a/app/models/chouette/group_of_line.rb +++ b/app/models/chouette/group_of_line.rb @@ -1,31 +1,34 @@ -class Chouette::GroupOfLine < Chouette::ActiveRecord - include StifCodifligneAttributesSupport - include GroupOfLineRestrictions - include LineReferentialSupport +module Chouette + class GroupOfLine < Chouette::ActiveRecord + has_paper_trail + include ObjectidSupport + include GroupOfLineRestrictions + include LineReferentialSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - has_and_belongs_to_many :lines, :class_name => 'Chouette::Line', :order => 'lines.name' + has_and_belongs_to_many :lines, :class_name => 'Chouette::Line', :order => 'lines.name' - validates_presence_of :name + validates_presence_of :name - attr_reader :line_tokens + attr_reader :line_tokens - def self.nullable_attributes - [:comment] - end + def self.nullable_attributes + [:comment] + end - def commercial_stop_areas - Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :group_of_lines] ] ]).where(:group_of_lines => {:id => self.id}).uniq - end + def commercial_stop_areas + Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :group_of_lines] ] ]).where(:group_of_lines => {:id => self.id}).uniq + end - def stop_areas - Chouette::StopArea.joins(:stop_points => [:route => [:line => :group_of_lines] ]).where(:group_of_lines => {:id => self.id}) - end + def stop_areas + Chouette::StopArea.joins(:stop_points => [:route => [:line => :group_of_lines] ]).where(:group_of_lines => {:id => self.id}) + end - def line_tokens=(ids) - self.line_ids = ids.split(",") - end + def line_tokens=(ids) + self.line_ids = ids.split(",") + end + end end diff --git a/app/models/chouette/journey_frequency.rb b/app/models/chouette/journey_frequency.rb index 45b8aea8c..1b4efe96e 100644 --- a/app/models/chouette/journey_frequency.rb +++ b/app/models/chouette/journey_frequency.rb @@ -1,5 +1,4 @@ module Chouette - class JourneyFrequencyValidator < ActiveModel::Validator def validate(record) timeband = record.timeband @@ -31,6 +30,6 @@ module Chouette validates :first_departure_time, presence: true validates :last_departure_time, presence: true validates :scheduled_headway_interval, presence: true - validates_with JourneyFrequencyValidator + validates_with Chouette::JourneyFrequencyValidator end -end +end
\ No newline at end of file diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index 1104c6035..a62da6353 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -1,144 +1,149 @@ -class Chouette::JourneyPattern < Chouette::TridentActiveRecord - include ChecksumSupport - include JourneyPatternRestrictions - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - belongs_to :route - has_many :vehicle_journeys, :dependent => :destroy - has_many :vehicle_journey_at_stops, :through => :vehicle_journeys - has_and_belongs_to_many :stop_points, -> { order("stop_points.position") }, :before_add => :vjas_add, :before_remove => :vjas_remove, :after_add => :shortcuts_update_for_add, :after_remove => :shortcuts_update_for_remove - has_many :stop_areas, through: :stop_points - - validates_presence_of :route - validates_presence_of :name - - #validates :stop_points, length: { minimum: 2, too_short: :minimum }, on: :update - enum section_status: { todo: 0, completed: 1, control: 2 } - - attr_accessor :control_checked - def local_id - "IBOO-#{self.referential.id}-#{self.try(:route).try(:line).try(:objectid).try(:local_id)}-#{self.id}" - end +module Chouette + class JourneyPattern < Chouette::TridentActiveRecord + has_paper_trail + include ChecksumSupport + include JourneyPatternRestrictions + include ObjectidSupport + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + + belongs_to :route + has_many :vehicle_journeys, :dependent => :destroy + has_many :vehicle_journey_at_stops, :through => :vehicle_journeys + has_and_belongs_to_many :stop_points, -> { order("stop_points.position") }, :before_add => :vjas_add, :before_remove => :vjas_remove, :after_add => :shortcuts_update_for_add, :after_remove => :shortcuts_update_for_remove + has_many :stop_areas, through: :stop_points + + validates_presence_of :route + validates_presence_of :name + + #validates :stop_points, length: { minimum: 2, too_short: :minimum }, on: :update + enum section_status: { todo: 0, completed: 1, control: 2 } + + attr_accessor :control_checked + + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.id}" + end - def checksum_attributes - values = self.slice(*['name', 'published_name', 'registration_number']).values - values << self.stop_points.map(&:stop_area).map(&:user_objectid) - values.flatten - end + def checksum_attributes + values = self.slice(*['name', 'published_name', 'registration_number']).values + values << self.stop_points.map(&:stop_area).map(&:user_objectid) + values.flatten + end - def self.state_update route, state - transaction do - state.each do |item| - item.delete('errors') - jp = find_by(objectid: item['object_id']) || state_create_instance(route, item) - next if item['deletable'] && jp.persisted? && jp.destroy - # Update attributes and stop_points associations - jp.update_attributes(state_permited_attributes(item)) unless item['new_record'] - jp.state_stop_points_update(item) if !jp.errors.any? && jp.persisted? - item['errors'] = jp.errors if jp.errors.any? + def self.state_update route, state + transaction do + state.each do |item| + item.delete('errors') + jp = find_by(objectid: item['object_id']) || state_create_instance(route, item) + next if item['deletable'] && jp.persisted? && jp.destroy + # Update attributes and stop_points associations + jp.update_attributes(state_permited_attributes(item)) unless item['new_record'] + jp.state_stop_points_update(item) if !jp.errors.any? && jp.persisted? + item['errors'] = jp.errors if jp.errors.any? + end + + if state.any? {|item| item['errors']} + state.map {|item| item.delete('object_id') if item['new_record']} + raise ::ActiveRecord::Rollback + end end - if state.any? {|item| item['errors']} - state.map {|item| item.delete('object_id') if item['new_record']} - raise ActiveRecord::Rollback - end + state.map {|item| item.delete('new_record')} + state.delete_if {|item| item['deletable']} end - state.map {|item| item.delete('new_record')} - state.delete_if {|item| item['deletable']} - end - - def self.state_permited_attributes item - { - name: item['name'], - published_name: item['published_name'], - registration_number: item['registration_number'] - } - end - - def self.state_create_instance route, item - # Flag new record, so we can unset object_id if transaction rollback - jp = route.journey_patterns.create(state_permited_attributes(item)) + def self.state_permited_attributes item + { + name: item['name'], + published_name: item['published_name'], + registration_number: item['registration_number'] + } + end - # FIXME - # DefaultAttributesSupport will trigger some weird validation on after save - # wich will call to valid?, wich will populate errors - # In this case, we mark jp to be valid if persisted? return true - jp.errors.clear if jp.persisted? + def self.state_create_instance route, item + # Flag new record, so we can unset object_id if transaction rollback + jp = route.journey_patterns.create(state_permited_attributes(item)) - item['object_id'] = jp.objectid - item['new_record'] = true - jp - end + # FIXME + # DefaultAttributesSupport will trigger some weird validation on after save + # wich will call to valid?, wich will populate errors + # In this case, we mark jp to be valid if persisted? return true + jp.errors.clear if jp.persisted? - def state_stop_points_update item - item['stop_points'].each do |sp| - exist = stop_area_ids.include?(sp['id']) - next if exist && sp['checked'] + item['object_id'] = jp.objectid + item['new_record'] = true + jp + end - stop_point = route.stop_points.find_by(stop_area_id: sp['id']) - if !exist && sp['checked'] - stop_points << stop_point - end - if exist && !sp['checked'] - stop_points.delete(stop_point) + def state_stop_points_update item + item['stop_points'].each do |sp| + exist = stop_area_ids.include?(sp['id']) + next if exist && sp['checked'] + + stop_point = route.stop_points.find_by(stop_area_id: sp['id']) + if !exist && sp['checked'] + stop_points << stop_point + end + if exist && !sp['checked'] + stop_points.delete(stop_point) + end end end - end - # TODO: this a workarround - # otherwise, we loose the first stop_point - # when creating a new journey_pattern - def special_update - bck_sp = self.stop_points.map {|s| s} - self.update_attributes :stop_points => [] - self.update_attributes :stop_points => bck_sp - end + # TODO: this a workarround + # otherwise, we loose the first stop_point + # when creating a new journey_pattern + def special_update + bck_sp = self.stop_points.map {|s| s} + self.update_attributes :stop_points => [] + self.update_attributes :stop_points => bck_sp + end - def departure_stop_point - return unless departure_stop_point_id - Chouette::StopPoint.find( departure_stop_point_id) - end + def departure_stop_point + return unless departure_stop_point_id + Chouette::StopPoint.find( departure_stop_point_id) + end - def arrival_stop_point - return unless arrival_stop_point_id - Chouette::StopPoint.find( arrival_stop_point_id) - end + def arrival_stop_point + return unless arrival_stop_point_id + Chouette::StopPoint.find( arrival_stop_point_id) + end - def shortcuts_update_for_add( stop_point) - stop_points << stop_point unless stop_points.include?( stop_point) + def shortcuts_update_for_add( stop_point) + stop_points << stop_point unless stop_points.include?( stop_point) - ordered_stop_points = stop_points - ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? + ordered_stop_points = stop_points + ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? - self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), - :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) - end + self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), + :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) + end - def shortcuts_update_for_remove( stop_point) - stop_points.delete( stop_point) if stop_points.include?( stop_point) + def shortcuts_update_for_remove( stop_point) + stop_points.delete( stop_point) if stop_points.include?( stop_point) - ordered_stop_points = stop_points - ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? + ordered_stop_points = stop_points + ordered_stop_points = ordered_stop_points.sort { |a,b| a.position <=> b.position} unless ordered_stop_points.empty? - self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), - :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) - end + self.update_attributes( :departure_stop_point_id => (ordered_stop_points.first && ordered_stop_points.first.id), + :arrival_stop_point_id => (ordered_stop_points.last && ordered_stop_points.last.id)) + end - def vjas_add( stop_point) - return if new_record? + def vjas_add( stop_point) + return if new_record? - vehicle_journeys.each do |vj| - vjas = vj.vehicle_journey_at_stops.create :stop_point_id => stop_point.id + vehicle_journeys.each do |vj| + vjas = vj.vehicle_journey_at_stops.create :stop_point_id => stop_point.id + end end - end - def vjas_remove( stop_point) - return if new_record? + def vjas_remove( stop_point) + return if new_record? - vehicle_journey_at_stops.where( :stop_point_id => stop_point.id).each do |vjas| - vjas.destroy + vehicle_journey_at_stops.where( :stop_point_id => stop_point.id).each do |vjas| + vjas.destroy + end end end end diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb index 6f87a5d08..784e3f5b9 100644 --- a/app/models/chouette/line.rb +++ b/app/models/chouette/line.rb @@ -1,81 +1,83 @@ -class Chouette::Line < Chouette::ActiveRecord - include StifCodifligneAttributesSupport - include LineRestrictions - include LineReferentialSupport - include StifTransportModeEnumerations - include StifTransportSubmodeEnumerations +module Chouette + class Line < Chouette::ActiveRecord + has_paper_trail + include LineRestrictions + include LineReferentialSupport + include ObjectidSupport + include StifTransportModeEnumerations + include StifTransportSubmodeEnumerations + extend ActiveModel::Naming - extend ActiveModel::Naming + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + belongs_to :company + belongs_to :network + belongs_to :line_referential - belongs_to :company - belongs_to :network - belongs_to :line_referential + has_array_of :secondary_companies, class_name: 'Chouette::Company' - has_array_of :secondary_companies, class_name: 'Chouette::Company' + has_many :routes, :dependent => :destroy + has_many :journey_patterns, :through => :routes + has_many :vehicle_journeys, :through => :journey_patterns + has_many :routing_constraint_zones, through: :routes - has_many :routes, :dependent => :destroy - has_many :journey_patterns, :through => :routes - has_many :vehicle_journeys, :through => :journey_patterns - has_many :routing_constraint_zones, through: :routes + has_and_belongs_to_many :group_of_lines, :class_name => 'Chouette::GroupOfLine', :order => 'group_of_lines.name' - has_and_belongs_to_many :group_of_lines, :class_name => 'Chouette::GroupOfLine', :order => 'group_of_lines.name' + has_many :footnotes, :inverse_of => :line, :validate => :true, :dependent => :destroy + accepts_nested_attributes_for :footnotes, :reject_if => :all_blank, :allow_destroy => true - has_many :footnotes, :inverse_of => :line, :validate => :true, :dependent => :destroy - accepts_nested_attributes_for :footnotes, :reject_if => :all_blank, :allow_destroy => true + attr_reader :group_of_line_tokens - attr_reader :group_of_line_tokens + # validates_presence_of :network + # validates_presence_of :company - # validates_presence_of :network - # validates_presence_of :company + validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :stable_id, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :text_color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :stable_id, :with => %r{\A[\d\w_\-]+\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :text_color, :with => %r{\A[0-9a-fA-F]{6}\Z}, :allow_nil => true, :allow_blank => true + validates_presence_of :name - validates_presence_of :name + scope :by_text, ->(text) { where('lower(name) LIKE :t or lower(published_name) LIKE :t or lower(objectid) LIKE :t or lower(comment) LIKE :t or lower(number) LIKE :t', + t: "%#{text.downcase}%") } - scope :by_text, ->(text) { where('lower(name) LIKE :t or lower(published_name) LIKE :t or lower(objectid) LIKE :t or lower(comment) LIKE :t or lower(number) LIKE :t', - t: "%#{text.downcase}%") } + def self.nullable_attributes + [:published_name, :number, :comment, :url, :color, :text_color, :stable_id] + end - def self.nullable_attributes - [:published_name, :number, :comment, :url, :color, :text_color, :stable_id] - end + def geometry_presenter + Chouette::Geometry::LinePresenter.new self + end - def geometry_presenter - Chouette::Geometry::LinePresenter.new self - end + def commercial_stop_areas + Chouette::StopArea.joins(:children => [:stop_points => [:route => :line] ]).where(:lines => {:id => self.id}).uniq + end - def commercial_stop_areas - Chouette::StopArea.joins(:children => [:stop_points => [:route => :line] ]).where(:lines => {:id => self.id}).uniq - end + def stop_areas + Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}) + end - def stop_areas - Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}) - end + def stop_areas_last_parents + Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}).collect(&:root).flatten.uniq + end - def stop_areas_last_parents - Chouette::StopArea.joins(:stop_points => [:route => :line]).where(:lines => {:id => self.id}).collect(&:root).flatten.uniq - end + def group_of_line_tokens=(ids) + self.group_of_line_ids = ids.split(",") + end - def group_of_line_tokens=(ids) - self.group_of_line_ids = ids.split(",") - end + def vehicle_journey_frequencies? + self.vehicle_journeys.unscoped.where(journey_category: 1).count > 0 + end - def vehicle_journey_frequencies? - self.vehicle_journeys.unscoped.where(journey_category: 1).count > 0 - end + def display_name + [self.get_objectid.local_id, number, name, company.try(:name)].compact.join(' - ') + end - def display_name - [objectid.local_id, number, name, company.try(:name)].compact.join(' - ') - end + def companies + line_referential.companies.where(id: ([company_id] + Array(secondary_company_ids)).compact) + end - def companies - line_referential.companies.where(id: ([company_id] + Array(secondary_company_ids)).compact) end - end diff --git a/app/models/chouette/link_orientation_type.rb b/app/models/chouette/link_orientation_type.rb index ec279aba3..c3addf4b4 100644 --- a/app/models/chouette/link_orientation_type.rb +++ b/app/models/chouette/link_orientation_type.rb @@ -1,49 +1,51 @@ -class Chouette::LinkOrientationType < ActiveSupport::StringInquirer +module Chouette + class LinkOrientationType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - def to_i - @numerical_code - end + def to_i + @numerical_code + end - def inspect - "#{to_s}/#{to_i}" - end + def inspect + "#{to_s}/#{to_i}" + end - def name - camelize - end + def name + camelize + end - @@definitions = [ - ["access_point_to_stop_area", 0], - ["stop_area_to_access_point", 1] - ] - cattr_reader :definitions + @@definitions = [ + ["access_point_to_stop_area", 0], + ["stop_area_to_access_point", 1] + ] + cattr_reader :definitions - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/loader.rb b/app/models/chouette/loader.rb index 40a2be4ee..7ab696dab 100644 --- a/app/models/chouette/loader.rb +++ b/app/models/chouette/loader.rb @@ -1,110 +1,112 @@ -class Chouette::Loader +module Chouette + class Loader - attr_reader :schema, :database, :user, :password, :host + attr_reader :schema, :database, :user, :password, :host - def initialize(schema) - @schema = schema + def initialize(schema) + @schema = schema - Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| - @database = config[:database] - @user = config[:username] - @password = config[:password] - @host = (config[:host] or "localhost") + Chouette::ActiveRecord.connection_pool.spec.config.tap do |config| + @database = config[:database] + @user = config[:username] + @password = config[:password] + @host = (config[:host] or "localhost") + end end - end - # Load dump where datas are in schema 'chouette' - def load_dump(file) - logger.info "Load #{file} in schema #{schema}" - with_pg_password do - execute!("sed -e 's/ chouette/ \"#{schema}\"/' -e 's/ OWNER TO .*;/ OWNER TO #{user};/' #{file} | psql #{pg_options} --set ON_ERROR_ROLLBACK=1 --set ON_ERROR_STOP=1") + # Load dump where datas are in schema 'chouette' + def load_dump(file) + logger.info "Load #{file} in schema #{schema}" + with_pg_password do + execute!("sed -e 's/ chouette/ \"#{schema}\"/' -e 's/ OWNER TO .*;/ OWNER TO #{user};/' #{file} | psql #{pg_options} --set ON_ERROR_ROLLBACK=1 --set ON_ERROR_STOP=1") + end + self end - self - end - def self.chouette_command=(command) - Chouette::Command.command = command - end + def self.chouette_command=(command) + Chouette::Command.command = command + end - class << self - deprecate :chouette_command= => "Use Chouette::Command.command =" - end + class << self + deprecate :chouette_command= => "Use Chouette::Command.command =" + end - def chouette_command - @chouette_command ||= Chouette::Command.new(:schema => schema) - end + def chouette_command + @chouette_command ||= Chouette::Command.new(:schema => schema) + end - def import(file, options = {}) - options = { - :format => :neptune - }.merge(options) - - command_options = { - :c => "import", - :o => "line", - :format => options.delete(:format).to_s.upcase, - :input_file => File.expand_path(file), - :optimize_memory => true - }.merge(options) - - logger.info "Import #{file} in schema #{schema}" - chouette_command.run! command_options - end + def import(file, options = {}) + options = { + :format => :neptune + }.merge(options) + + command_options = { + :c => "import", + :o => "line", + :format => options.delete(:format).to_s.upcase, + :input_file => File.expand_path(file), + :optimize_memory => true + }.merge(options) + + logger.info "Import #{file} in schema #{schema}" + chouette_command.run! command_options + end - def backup(file) - logger.info "Backup schema #{schema} in #{file}" + def backup(file) + logger.info "Backup schema #{schema} in #{file}" - with_pg_password do - execute!("pg_dump -n #{schema} -f #{file} #{pg_options}") - end + with_pg_password do + execute!("pg_dump -n #{schema} -f #{file} #{pg_options}") + end - self - end + self + end - def pg_options - [].tap do |options| - options << "-U #{user}" if user - options << "-h #{host}" if host - options << database - end.join(" ") - end + def pg_options + [].tap do |options| + options << "-U #{user}" if user + options << "-h #{host}" if host + options << database + end.join(" ") + end - def create - logger.info "Create schema #{schema}" - with_pg_password do - execute!("psql -c 'CREATE SCHEMA \"#{schema}\";' #{pg_options}") + def create + logger.info "Create schema #{schema}" + with_pg_password do + execute!("psql -c 'CREATE SCHEMA \"#{schema}\";' #{pg_options}") + end + self end - self - end - def drop - logger.info "Drop schema #{schema}" - with_pg_password do - execute!("psql -c 'DROP SCHEMA \"#{schema}\" CASCADE;' #{pg_options}") + def drop + logger.info "Drop schema #{schema}" + with_pg_password do + execute!("psql -c 'DROP SCHEMA \"#{schema}\" CASCADE;' #{pg_options}") + end + self end - self - end - def with_pg_password(&block) - ENV['PGPASSWORD'] = password.to_s if password - begin - yield - ensure - ENV['PGPASSWORD'] = nil + def with_pg_password(&block) + ENV['PGPASSWORD'] = password.to_s if password + begin + yield + ensure + ENV['PGPASSWORD'] = nil + end end - end - @@binarisation_command = "binarisation" - cattr_accessor :binarisation_command + @@binarisation_command = "binarisation" + cattr_accessor :binarisation_command - def binarize(period, target_directory) - # TODO check these computed daybefore/dayafter - day_before = Date.today - period.begin - day_after = period.end - period.begin + def binarize(period, target_directory) + # TODO check these computed daybefore/dayafter + day_before = Date.today - period.begin + day_after = period.end - period.begin - execute! "#{binarisation_command} --host=#{host} --dbname=#{database} --user=#{user} --password=#{password} --schema=#{schema} --daybefore=#{day_before} --dayafter=#{day_after} --targetdirectory=#{target_directory}" - end + execute! "#{binarisation_command} --host=#{host} --dbname=#{database} --user=#{user} --password=#{password} --schema=#{schema} --daybefore=#{day_before} --dayafter=#{day_after} --targetdirectory=#{target_directory}" + end - include Chouette::CommandLineSupport + include Chouette::CommandLineSupport -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/netex_object_id.rb b/app/models/chouette/netex_object_id.rb deleted file mode 100644 index 441004c1e..000000000 --- a/app/models/chouette/netex_object_id.rb +++ /dev/null @@ -1,40 +0,0 @@ -class Chouette::NetexObjectId < String - - def valid? - parts.present? - end - alias_method :objectid?, :valid? - - @@format = /^([A-Za-z_]+):([0-9A-Za-z_]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def provider_id - parts.try(:first) - end - - def system_id - parts.try(:second) - end - - def object_type - parts.try(:third) - end - - def local_id - parts.try(:fourth) - end - - def self.create(provider_id, system_id, object_type, local_id) - new [provider_id, system_id, object_type, local_id].join(":") - end - - def self.new(string) - string ||= "" - self === string ? string : super - end - -end diff --git a/app/models/chouette/network.rb b/app/models/chouette/network.rb index 8df205789..9b3f2fe29 100644 --- a/app/models/chouette/network.rb +++ b/app/models/chouette/network.rb @@ -1,49 +1,61 @@ -class Chouette::Network < Chouette::ActiveRecord - include StifCodifligneAttributesSupport - include NetworkRestrictions - include LineReferentialSupport - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - has_many :lines - - attr_accessor :source_type_name - - validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true - validates_presence_of :name - - def self.object_id_key - "PTNetwork" - end +module Chouette + class Network < Chouette::ActiveRecord + has_paper_trail + include NetworkRestrictions + include LineReferentialSupport + include ObjectidSupport + extend Enumerize + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + has_many :lines + + attr_accessor :source_type_name + + enumerize :source_type_name, in: %w(public_and_private_utilities + road_authorities + transit_operator + public_transport + passenger_transport_coordinating_authority + travel_information_service_provider + travel_agency + individual_subject_of_travel_itinerary + other_information) + + validates_format_of :registration_number, :with => %r{\A[0-9A-Za-z_-]+\Z}, :allow_nil => true, :allow_blank => true + validates_presence_of :name + + def self.object_id_key + "PTNetwork" + end - def self.nullable_attributes - [:source_name, :source_type, :source_identifier, :comment] - end + def self.nullable_attributes + [:source_name, :source_type, :source_identifier, :comment] + end - def commercial_stop_areas - Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :network] ] ]).where(:networks => {:id => self.id}).uniq - end + def commercial_stop_areas + Chouette::StopArea.joins(:children => [:stop_points => [:route => [:line => :network] ] ]).where(:networks => {:id => self.id}).uniq + end - def stop_areas - Chouette::StopArea.joins(:stop_points => [:route => [:line => :network] ]).where(:networks => {:id => self.id}) - end + def stop_areas + Chouette::StopArea.joins(:stop_points => [:route => [:line => :network] ]).where(:networks => {:id => self.id}) + end - def source_type_name - # return nil if source_type is nil - source_type && Chouette::SourceType.new( source_type.underscore) - end + def source_type_name + # return nil if source_type is nil + source_type && Chouette::SourceType.new( source_type.underscore) + end - def source_type_name=(source_type_name) - self.source_type = (source_type_name ? source_type_name.camelcase : nil) - end + def source_type_name=(source_type_name) + self.source_type = (source_type_name ? source_type_name.camelcase : nil) + end - @@source_type_names = nil - def self.source_type_names - @@source_type_names ||= Chouette::SourceType.all.select do |source_type_name| - source_type_name.to_i > 0 + @@source_type_names = nil + def self.source_type_names + @@source_type_names ||= Chouette::SourceType.all.select do |source_type_name| + source_type_name.to_i > 0 + end end - end + end end - diff --git a/app/models/chouette/object_id.rb b/app/models/chouette/object_id.rb deleted file mode 100644 index 0b122c91b..000000000 --- a/app/models/chouette/object_id.rb +++ /dev/null @@ -1,36 +0,0 @@ -class Chouette::ObjectId < String - - def valid? - parts.present? - end - alias_method :objectid?, :valid? - - @@format = /^([0-9A-Za-z_]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def system_id - parts.try(:first) - end - - def object_type - parts.try(:second) - end - - def local_id - parts.try(:third) - end - - def self.create(system_id, object_type, local_id) - new [system_id, object_type, local_id].join(":") - end - - def self.new(string) - string ||= "" - self === string ? string : super - end - -end diff --git a/app/models/chouette/objectid/netex.rb b/app/models/chouette/objectid/netex.rb new file mode 100644 index 000000000..5d27abb1f --- /dev/null +++ b/app/models/chouette/objectid/netex.rb @@ -0,0 +1,33 @@ +module Chouette + module Objectid + class Netex + include ActiveModel::Model + + attr_accessor :provider_id, :object_type, :local_id, :creation_id + validates_presence_of :provider_id, :object_type, :local_id, :creation_id + validate :must_respect_format + + def initialize(**attributes) + @provider_id = attributes[:provider_id] || 'chouette' + @object_type = attributes[:object_type] + @local_id = attributes[:local_id] + @creation_id = attributes[:creation_id] || 'LOC' + end + + @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ + cattr_reader :format + + def to_s + "#{self.provider_id}:#{self.object_type}:#{self.local_id}:#{self.creation_id}" + end + + def must_respect_format + self.to_s.match(self.class.format) + end + + def short_id + local_id.try(:split, "-").try(:first) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_codifligne.rb b/app/models/chouette/objectid/stif_codifligne.rb new file mode 100644 index 000000000..903ebc2dc --- /dev/null +++ b/app/models/chouette/objectid/stif_codifligne.rb @@ -0,0 +1,28 @@ +module Chouette + module Objectid + class StifCodifligne < Chouette::Objectid::Netex + + attr_accessor :sync_id + validates_presence_of :sync_id + validates :creation_id, presence: false + + @@format = /^([A-Za-z_]+):([A-Za-z]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ + + def initialize(**attributes) + @provider_id = attributes[:provider_id] + @object_type = attributes[:object_type] + @local_id = attributes[:local_id] + @sync_id = attributes[:sync_id] + super + end + + def to_s + "#{self.provider_id}:#{self.sync_id}:#{self.object_type}:#{self.local_id}" + end + + def short_id + local_id + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_netex.rb b/app/models/chouette/objectid/stif_netex.rb new file mode 100644 index 000000000..19fd42702 --- /dev/null +++ b/app/models/chouette/objectid/stif_netex.rb @@ -0,0 +1,17 @@ +module Chouette + module Objectid + class StifNetex < Chouette::Objectid::Netex + + @@format = Chouette::Objectid::Netex.format + + def initialize(**attributes) + @provider_id = attributes[:provider_id] ||= 'stif' + super + end + + def short_id + local_id.try(:split, "-").try(:last) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid/stif_reflex.rb b/app/models/chouette/objectid/stif_reflex.rb new file mode 100644 index 000000000..770f3c433 --- /dev/null +++ b/app/models/chouette/objectid/stif_reflex.rb @@ -0,0 +1,27 @@ +module Chouette + module Objectid + class StifReflex < Chouette::Objectid::Netex + + attr_accessor :country_code, :zip_code + validates_presence_of :country_code, :zip_code + validates :creation_id, presence: false + + @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ + + def initialize(**attributes) + @provider_id = attributes[:provider_id] + @country_code = attributes[:country_code] + @zip_code = attributes[:zip_code] + super + end + + def to_s + "#{self.country_code}:#{self.zip_code}:#{self.object_type}:#{self.local_id}:#{self.provider_id}" + end + + def short_id + local_id + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/netex.rb b/app/models/chouette/objectid_formatter/netex.rb new file mode 100644 index 000000000..00c539553 --- /dev/null +++ b/app/models/chouette/objectid_formatter/netex.rb @@ -0,0 +1,19 @@ +module Chouette + module ObjectidFormatter + class Netex + def before_validation(model) + oid = Chouette::Objectid::Netex.new(local_id: SecureRandom.uuid, object_type: model.class.name.gsub('Chouette::','')) + model.update(objectid: oid.to_s) if oid.valid? + end + + def after_commit(model) + # unused method in this context + end + + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::Netex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/stif_codifligne.rb b/app/models/chouette/objectid_formatter/stif_codifligne.rb new file mode 100644 index 000000000..eafd2a090 --- /dev/null +++ b/app/models/chouette/objectid_formatter/stif_codifligne.rb @@ -0,0 +1,18 @@ +module Chouette + module ObjectidFormatter + class StifCodifligne + def before_validation(model) + # unused method in this context + end + + def after_commit(model) + # unused method in this context + end + + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::StifCodifligne.new(provider_id: parts[0], sync_id: parts[1], object_type: parts[2], local_id: parts[3]) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/stif_netex.rb b/app/models/chouette/objectid_formatter/stif_netex.rb new file mode 100644 index 000000000..01ddfc528 --- /dev/null +++ b/app/models/chouette/objectid_formatter/stif_netex.rb @@ -0,0 +1,19 @@ +module Chouette + module ObjectidFormatter + class StifNetex + def before_validation(model) + model.attributes = {objectid: "__pending_id__#{SecureRandom.uuid}"} + end + + def after_commit(model) + oid = Chouette::Objectid::StifNetex.new(provider_id: "stif", object_type: model.class.name.gsub('Chouette::',''), local_id: model.local_id) + model.update(objectid: oid.to_s) if oid.valid? + end + + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::StifNetex.new(provider_id: parts[0], object_type: parts[1], local_id: parts[2], creation_id: parts[3]) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/objectid_formatter/stif_reflex.rb b/app/models/chouette/objectid_formatter/stif_reflex.rb new file mode 100644 index 000000000..5bfb21ecd --- /dev/null +++ b/app/models/chouette/objectid_formatter/stif_reflex.rb @@ -0,0 +1,18 @@ +module Chouette + module ObjectidFormatter + class StifReflex + def before_validation(model) + # unused method in this context + end + + def after_commit(model) + # unused method in this context + end + + def get_objectid(definition) + parts = definition.try(:split, ":") + Chouette::Objectid::StifReflex.new(country_code: parts[0], zip_code: parts[1], object_type: parts[2], local_id: parts[3], provider_id: parts[4]) + end + end + end +end
\ No newline at end of file diff --git a/app/models/chouette/pt_link.rb b/app/models/chouette/pt_link.rb index 8a4e368ea..d14d5f29c 100644 --- a/app/models/chouette/pt_link.rb +++ b/app/models/chouette/pt_link.rb @@ -1,37 +1,37 @@ require 'geokit' -class Chouette::PtLink < Chouette::ActiveRecord - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - include Geokit::Mappable - - def geometry - the_geom - end +module Chouette + class PtLink < Chouette::ActiveRecord + has_paper_trail + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + include Geokit::Mappable + + def geometry + the_geom + end - def self.import_csv - csv_file = Rails.root + "chouette_pt_links.csv" - if File.exists?( csv_file) - csv = CSV::Reader.parse(File.read(csv_file)) + def self.import_csv + csv_file = Rails.root + "chouette_pt_links.csv" + if File.exists?( csv_file) + csv = CSV::Reader.parse(File.read(csv_file)) - slug = csv.shift.first + slug = csv.shift.first - Network::Base.find_by_slug( slug).tune_connection + Network::Base.find_by_slug( slug).tune_connection - csv.each do |row| - origin = Chouette::StopArea.find_by_objectid( row[0]) - destination = Chouette::StopArea.find_by_objectid( row[1]) + csv.each do |row| + origin = Chouette::StopArea.find_by_objectid( row[0]) + destination = Chouette::StopArea.find_by_objectid( row[1]) - raise "unknown origin #{row[0]}" unless origin - raise "unknown destination #{row[1]}" unless destination + raise "unknown origin #{row[0]}" unless origin + raise "unknown destination #{row[1]}" unless destination - Chouette::PtLink.create( :departure_id => origin.id, - :arrival_id => destination.id, - :the_geom => GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb( row[2])) + Chouette::PtLink.create( :departure_id => origin.id, + :arrival_id => destination.id, + :the_geom => GeoRuby::SimpleFeatures::Geometry.from_hex_ewkb( row[2])) + end end end - end - end diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 1a05d43d9..5c0ad24a1 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -1,78 +1,82 @@ -class Chouette::Route < Chouette::TridentActiveRecord - include RouteRestrictions - include ChecksumSupport - extend Enumerize - extend ActiveModel::Naming +module Chouette + class Route < Chouette::TridentActiveRecord + has_paper_trail + include RouteRestrictions + include ChecksumSupport + include ObjectidSupport - enumerize :direction, in: %i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east) - enumerize :wayback, in: %i(outbound inbound), default: :outbound + extend Enumerize + extend ActiveModel::Naming - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" + enumerize :direction, in: %i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east) + enumerize :wayback, in: %i(outbound inbound), default: :outbound - def self.nullable_attributes - [:published_name, :comment, :number, :name, :direction, :wayback] - end + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + + def self.nullable_attributes + [:published_name, :comment, :number, :name, :direction, :wayback] + end - belongs_to :line - belongs_to :opposite_route, :class_name => 'Chouette::Route', :foreign_key => :opposite_route_id + belongs_to :line + belongs_to :opposite_route, :class_name => 'Chouette::Route', :foreign_key => :opposite_route_id - has_many :routing_constraint_zones - has_many :journey_patterns, :dependent => :destroy - has_many :vehicle_journeys, :dependent => :destroy do - def timeless - Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + has_many :routing_constraint_zones + has_many :journey_patterns, :dependent => :destroy + has_many :vehicle_journeys, :dependent => :destroy do + def timeless + Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + end end - end - has_many :vehicle_journey_frequencies, :dependent => :destroy do - # Todo : I think there is a better way to do this. - def timeless - Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + has_many :vehicle_journey_frequencies, :dependent => :destroy do + # Todo : I think there is a better way to do this. + def timeless + Chouette::Route.vehicle_journeys_timeless(proxy_association.owner.journey_patterns.pluck( :departure_stop_point_id)) + end end - end - has_many :stop_points, -> { order("position") }, :dependent => :destroy do - def find_by_stop_area(stop_area) - stop_area_ids = Integer === stop_area ? [stop_area] : (stop_area.children_in_depth + [stop_area]).map(&:id) - where( :stop_area_id => stop_area_ids).first or - raise ActiveRecord::RecordNotFound.new("Can't find a StopArea #{stop_area.inspect} in Route #{proxy_owner.id.inspect}'s StopPoints") - end - - def between(departure, arrival) - between_positions = [departure, arrival].collect do |endpoint| - case endpoint - when Chouette::StopArea - find_by_stop_area(endpoint).position - when Chouette::StopPoint - endpoint.position - when Integer - endpoint - else - raise ActiveRecord::RecordNotFound.new("Can't determine position in route #{proxy_owner.id} with #{departure.inspect}") + has_many :stop_points, -> { order("position") }, :dependent => :destroy do + def find_by_stop_area(stop_area) + stop_area_ids = Integer === stop_area ? [stop_area] : (stop_area.children_in_depth + [stop_area]).map(&:id) + where( :stop_area_id => stop_area_ids).first or + raise ActiveRecord::RecordNotFound.new("Can't find a StopArea #{stop_area.inspect} in Route #{proxy_owner.id.inspect}'s StopPoints") + end + + def between(departure, arrival) + between_positions = [departure, arrival].collect do |endpoint| + case endpoint + when Chouette::StopArea + find_by_stop_area(endpoint).position + when Chouette::StopPoint + endpoint.position + when Integer + endpoint + else + raise ActiveRecord::RecordNotFound.new("Can't determine position in route #{proxy_owner.id} with #{departure.inspect}") + end end + where(" position between ? and ? ", between_positions.first, between_positions.last) end - where(" position between ? and ? ", between_positions.first, between_positions.last) end - end - has_many :stop_areas, -> { order('stop_points.position ASC') }, :through => :stop_points do - def between(departure, arrival) - departure, arrival = [departure, arrival].map do |endpoint| - String === endpoint ? Chouette::StopArea.find_by_objectid(endpoint) : endpoint + has_many :stop_areas, -> { order('stop_points.position ASC') }, :through => :stop_points do + def between(departure, arrival) + departure, arrival = [departure, arrival].map do |endpoint| + String === endpoint ? Chouette::StopArea.find_by_objectid(endpoint) : endpoint + end + proxy_owner.stop_points.between(departure, arrival).includes(:stop_area).collect(&:stop_area) end - proxy_owner.stop_points.between(departure, arrival).includes(:stop_area).collect(&:stop_area) end - end - accepts_nested_attributes_for :stop_points, :allow_destroy => :true + accepts_nested_attributes_for :stop_points, :allow_destroy => :true - validates_presence_of :name - validates_presence_of :published_name - validates_presence_of :line + validates_presence_of :name + validates_presence_of :published_name + validates_presence_of :line - # validates_presence_of :direction - # validates_presence_of :wayback + # validates_presence_of :direction + # validates_presence_of :wayback - validates :wayback, inclusion: { in: self.wayback.values } + validates :wayback, inclusion: { in: self.wayback.values } def duplicate overrides = { @@ -88,103 +92,104 @@ class Chouette::Route < Chouette::TridentActiveRecord new_route end - def duplicate_stop_points(for_route:) - stop_points.each(&duplicate_stop_point(for_route: for_route)) - end - def duplicate_stop_point(for_route:) - -> stop_point do - stop_point.duplicate(for_route: for_route) + def duplicate_stop_points(for_route:) + stop_points.each(&duplicate_stop_point(for_route: for_route)) + end + def duplicate_stop_point(for_route:) + -> stop_point do + stop_point.duplicate(for_route: for_route) + end end - end - def local_id - "IBOO-#{self.referential.id}-#{self.line.objectid.local_id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.line.get_objectid.local_id}-#{self.id}" + end - def geometry_presenter - Chouette::Geometry::RoutePresenter.new self - end + def geometry_presenter + Chouette::Geometry::RoutePresenter.new self + end - @@opposite_waybacks = { outbound: :inbound, inbound: :outbound} - def opposite_wayback - @@opposite_waybacks[wayback.to_sym] - end + @@opposite_waybacks = { outbound: :inbound, inbound: :outbound} + def opposite_wayback + @@opposite_waybacks[wayback.to_sym] + end - def opposite_route_candidates - if opposite_wayback - line.routes.where(opposite_route: [nil, self], wayback: opposite_wayback) - else - self.class.none + def opposite_route_candidates + if opposite_wayback + line.routes.where(opposite_route: [nil, self], wayback: opposite_wayback) + else + self.class.none + end end - end - validate :check_opposite_route - def check_opposite_route - return unless opposite_route && opposite_wayback - unless opposite_route_candidates.include?(opposite_route) - errors.add(:opposite_route_id, :invalid) + validate :check_opposite_route + def check_opposite_route + return unless opposite_route && opposite_wayback + unless opposite_route_candidates.include?(opposite_route) + errors.add(:opposite_route_id, :invalid) + end end - end - def checksum_attributes - values = self.slice(*['name', 'published_name', 'wayback']).values - values.tap do |attrs| - attrs << self.stop_points.map{|sp| "#{sp.stop_area.user_objectid}#{sp.for_boarding}#{sp.for_alighting}" }.join - attrs << self.routing_constraint_zones.map(&:checksum) + def checksum_attributes + values = self.slice(*['name', 'published_name', 'wayback']).values + values.tap do |attrs| + attrs << self.stop_points.map{|sp| "#{sp.stop_area.user_objectid}#{sp.for_boarding}#{sp.for_alighting}" }.join + attrs << self.routing_constraint_zones.map(&:checksum) + end end - end - def geometry - points = stop_areas.map(&:to_lat_lng).compact.map do |loc| - [loc.lng, loc.lat] + def geometry + points = stop_areas.map(&:to_lat_lng).compact.map do |loc| + [loc.lng, loc.lat] + end + GeoRuby::SimpleFeatures::LineString.from_coordinates( points, 4326) end - GeoRuby::SimpleFeatures::LineString.from_coordinates( points, 4326) - end - def time_tables - vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq - end + def time_tables + vehicle_journeys.joins(:time_tables).map(&:"time_tables").flatten.uniq + end - def sorted_vehicle_journeys(journey_category_model) - send(journey_category_model) - .joins(:journey_pattern, :vehicle_journey_at_stops) - .joins('LEFT JOIN "time_tables_vehicle_journeys" ON "time_tables_vehicle_journeys"."vehicle_journey_id" = "vehicle_journeys"."id" LEFT JOIN "time_tables" ON "time_tables"."id" = "time_tables_vehicle_journeys"."time_table_id"') - .where("vehicle_journey_at_stops.stop_point_id=journey_patterns.departure_stop_point_id") - .order("vehicle_journey_at_stops.departure_time") - end + def sorted_vehicle_journeys(journey_category_model) + send(journey_category_model) + .joins(:journey_pattern, :vehicle_journey_at_stops) + .joins('LEFT JOIN "time_tables_vehicle_journeys" ON "time_tables_vehicle_journeys"."vehicle_journey_id" = "vehicle_journeys"."id" LEFT JOIN "time_tables" ON "time_tables"."id" = "time_tables_vehicle_journeys"."time_table_id"') + .where("vehicle_journey_at_stops.stop_point_id=journey_patterns.departure_stop_point_id") + .order("vehicle_journey_at_stops.departure_time") + end - def stop_point_permutation?( stop_point_ids) - stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort - end + def stop_point_permutation?( stop_point_ids) + stop_points.map(&:id).map(&:to_s).sort == stop_point_ids.map(&:to_s).sort + end - def reorder!( stop_point_ids) - return false unless stop_point_permutation?( stop_point_ids) + def reorder!( stop_point_ids) + return false unless stop_point_permutation?( stop_point_ids) - stop_area_id_by_stop_point_id = {} - stop_points.each do |sp| - stop_area_id_by_stop_point_id.merge!( sp.id => sp.stop_area_id) - end + stop_area_id_by_stop_point_id = {} + stop_points.each do |sp| + stop_area_id_by_stop_point_id.merge!( sp.id => sp.stop_area_id) + end - reordered_stop_area_ids = [] - stop_point_ids.each do |stop_point_id| - reordered_stop_area_ids << stop_area_id_by_stop_point_id[ stop_point_id.to_i] - end + reordered_stop_area_ids = [] + stop_point_ids.each do |stop_point_id| + reordered_stop_area_ids << stop_area_id_by_stop_point_id[ stop_point_id.to_i] + end - stop_points.each_with_index do |sp, index| - if sp.stop_area_id.to_s != reordered_stop_area_ids[ index].to_s - #result = sp.update_attributes( :stop_area_id => reordered_stop_area_ids[ index]) - sp.stop_area_id = reordered_stop_area_ids[ index] - result = sp.save! + stop_points.each_with_index do |sp, index| + if sp.stop_area_id.to_s != reordered_stop_area_ids[ index].to_s + #result = sp.update_attributes( :stop_area_id => reordered_stop_area_ids[ index]) + sp.stop_area_id = reordered_stop_area_ids[ index] + result = sp.save! + end end + + return true end - return true - end + protected - protected + def self.vehicle_journeys_timeless(stop_point_id) + all( :conditions => ['vehicle_journeys.id NOT IN (?)', Chouette::VehicleJourneyAtStop.where(stop_point_id: stop_point_id).pluck(:vehicle_journey_id)] ) + end - def self.vehicle_journeys_timeless(stop_point_id) - all( :conditions => ['vehicle_journeys.id NOT IN (?)', Chouette::VehicleJourneyAtStop.where(stop_point_id: stop_point_id).pluck(:vehicle_journey_id)] ) end - end diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index efe1b7237..fcf47f154 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -1,43 +1,47 @@ -class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord - include ChecksumSupport - - belongs_to :route - has_array_of :stop_points, class_name: 'Chouette::StopPoint' - - validates_presence_of :name, :stop_points, :route - # validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') } - validate :stop_points_belong_to_route, :not_all_stop_points_selected - - def local_id - "IBOO-#{self.referential.id}-#{self.route.line.objectid.local_id}-#{self.route.objectid.local_id}-#{self.id}" - end - - scope :order_by_stop_points_count, ->(direction) do - order("array_length(stop_point_ids, 1) #{direction}") - end - - scope :order_by_route_name, ->(direction) do - joins(:route) - .order("routes.name #{direction}") - end - - def checksum_attributes - self.stop_points.map(&:stop_area).map(&:user_objectid) - end - - def stop_points_belong_to_route - errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp } - end - - def not_all_stop_points_selected - errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.all_stop_points_selected')) if stop_points.length == route.stop_points.length - end - - def stop_points_count - stop_points.count - end - - def route_name - route.name +module Chouette + class RoutingConstraintZone < Chouette::TridentActiveRecord + has_paper_trail + include ChecksumSupport + include ObjectidSupport + + belongs_to :route + has_array_of :stop_points, class_name: 'Chouette::StopPoint' + + validates_presence_of :name, :stop_points, :route + # validates :stop_point_ids, length: { minimum: 2, too_short: I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.not_enough_stop_points') } + validate :stop_points_belong_to_route, :not_all_stop_points_selected + + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.route.id}-#{self.id}" + end + + scope :order_by_stop_points_count, ->(direction) do + order("array_length(stop_point_ids, 1) #{direction}") + end + + scope :order_by_route_name, ->(direction) do + joins(:route) + .order("routes.name #{direction}") + end + + def checksum_attributes + self.stop_points.map(&:stop_area).map(&:user_objectid) + end + + def stop_points_belong_to_route + errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.stop_points_not_from_route')) unless stop_points.all? { |sp| route.stop_points.include? sp } + end + + def not_all_stop_points_selected + errors.add(:stop_point_ids, I18n.t('activerecord.errors.models.routing_constraint_zone.attributes.stop_points.all_stop_points_selected')) if stop_points.length == route.stop_points.length + end + + def stop_points_count + stop_points.count + end + + def route_name + route.name + end end end diff --git a/app/models/chouette/source_type.rb b/app/models/chouette/source_type.rb index 124a6c433..1554d846b 100644 --- a/app/models/chouette/source_type.rb +++ b/app/models/chouette/source_type.rb @@ -1,56 +1,58 @@ -class Chouette::SourceType < ActiveSupport::StringInquirer +module Chouette + class SourceType < ActiveSupport::StringInquirer - def initialize(text_code, numerical_code) - super text_code.to_s - @numerical_code = numerical_code - end + def initialize(text_code, numerical_code) + super text_code.to_s + @numerical_code = numerical_code + end - def self.new(text_code, numerical_code = nil) - if text_code and numerical_code - super - elsif self === text_code - text_code - else - if Fixnum === text_code - text_code, numerical_code = definitions.rassoc(text_code) + def self.new(text_code, numerical_code = nil) + if text_code and numerical_code + super + elsif self === text_code + text_code else - text_code, numerical_code = definitions.assoc(text_code.to_s) - end + if Fixnum === text_code + text_code, numerical_code = definitions.rassoc(text_code) + else + text_code, numerical_code = definitions.assoc(text_code.to_s) + end - super text_code, numerical_code + super text_code, numerical_code + end end - end - def to_i - @numerical_code - end + def to_i + @numerical_code + end - def inspect - "#{to_s}/#{to_i}" - end + def inspect + "#{to_s}/#{to_i}" + end - def name - camelize - end + def name + camelize + end - @@definitions = [ - ["public_and_private_utilities", 0], - ["road_authorities", 1], - ["transit_operator", 2], - ["public_transport", 3], - ["passenger_transport_coordinating_authority", 4], - ["travel_information_service_provider", 5], - ["travel_agency", 6], - ["individual_subject_of_travel_itinerary", 7], - ["other_information", 8] - ] - cattr_reader :definitions - - @@all = nil - def self.all - @@all ||= definitions.collect do |text_code, numerical_code| - new(text_code, numerical_code) + @@definitions = [ + ["public_and_private_utilities", 0], + ["road_authorities", 1], + ["transit_operator", 2], + ["public_transport", 3], + ["passenger_transport_coordinating_authority", 4], + ["travel_information_service_provider", 5], + ["travel_agency", 6], + ["individual_subject_of_travel_itinerary", 7], + ["other_information", 8] + ] + cattr_reader :definitions + + @@all = nil + def self.all + @@all ||= definitions.collect do |text_code, numerical_code| + new(text_code, numerical_code) + end end - end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/stif_codifligne_objectid.rb b/app/models/chouette/stif_codifligne_objectid.rb deleted file mode 100644 index 46109e24f..000000000 --- a/app/models/chouette/stif_codifligne_objectid.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Chouette::StifCodifligneObjectid < String - - @@format = /^([A-Za-z_]+):([A-Za-z]+):([A-Za-z]+):([0-9A-Za-z_-]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def object_type - parts.try(:third) - end - - def local_id - parts.try(:fourth) - end - -end diff --git a/app/models/chouette/stif_netex_objectid.rb b/app/models/chouette/stif_netex_objectid.rb deleted file mode 100644 index 93e7a1e85..000000000 --- a/app/models/chouette/stif_netex_objectid.rb +++ /dev/null @@ -1,42 +0,0 @@ -class Chouette::StifNetexObjectid < String - def valid? - parts.present? - end - - @@format = /^([A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def provider_id - parts.try(:first) - end - - def object_type - parts.try(:second) - end - - def local_id - parts.try(:third) - end - - def boiv_id - parts.try(:fourth) - end - - def short_id - local_id.try(:split, "-").try(:[], -1) - end - - def self.create(provider_id, object_type, local_id, boiv_id) - new [provider_id, object_type, local_id, boiv_id].join(":") - end - - def self.new(string) - string ||= "" - self === string ? string : super - end - -end diff --git a/app/models/chouette/stif_reflex_objectid.rb b/app/models/chouette/stif_reflex_objectid.rb deleted file mode 100644 index c41a9325a..000000000 --- a/app/models/chouette/stif_reflex_objectid.rb +++ /dev/null @@ -1,18 +0,0 @@ -class Chouette::StifReflexObjectid < String - - @@format = /^([A-Za-z_]+):([0-9A-Za-z_-]+):([A-Za-z]+):([0-9A-Za-z_-]+):([A-Za-z]+)$/ - cattr_reader :format - - def parts - match(format).try(:captures) - end - - def object_type - parts.try(:third) - end - - def local_id - parts.try(:fourth) - end - -end diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index 43bc82f7f..cc7170728 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -1,333 +1,328 @@ require 'geokit' require 'geo_ruby' +module Chouette + class StopArea < Chouette::ActiveRecord + has_paper_trail + include ProjectionFields + include StopAreaRestrictions + include StopAreaReferentialSupport + include ObjectidSupport + + extend Enumerize + enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) + + with_options dependent: :destroy do |assoc| + assoc.has_many :stop_points + assoc.has_many :access_points + assoc.has_many :access_links + end -class Chouette::StopArea < Chouette::ActiveRecord - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - include Geokit::Mappable - include StifReflexAttributesSupport - include ProjectionFields - include StopAreaRestrictions - include StopAreaReferentialSupport - - extend Enumerize - enumerize :area_type, in: %i(zdep zder zdlp zdlr lda) - - with_options dependent: :destroy do |assoc| - assoc.has_many :stop_points - assoc.has_many :access_points - assoc.has_many :access_links - end - - has_and_belongs_to_many :routing_lines, :class_name => 'Chouette::Line', :foreign_key => "stop_area_id", :association_foreign_key => "line_id", :join_table => "routing_constraints_lines", :order => "lines.number" - has_and_belongs_to_many :routing_stops, :class_name => 'Chouette::StopArea', :foreign_key => "parent_id", :association_foreign_key => "child_id", :join_table => "stop_areas_stop_areas", :order => "stop_areas.name" + has_and_belongs_to_many :routing_lines, :class_name => 'Chouette::Line', :foreign_key => "stop_area_id", :association_foreign_key => "line_id", :join_table => "routing_constraints_lines", :order => "lines.number" + has_and_belongs_to_many :routing_stops, :class_name => 'Chouette::StopArea', :foreign_key => "parent_id", :association_foreign_key => "child_id", :join_table => "stop_areas_stop_areas", :order => "stop_areas.name" - belongs_to :stop_area_referential - validates_presence_of :stop_area_referential_id + acts_as_tree :foreign_key => 'parent_id', :order => "name" - acts_as_tree :foreign_key => 'parent_id', :order => "name" + attr_accessor :stop_area_type + attr_accessor :children_ids + attr_writer :coordinates - attr_accessor :stop_area_type - attr_accessor :children_ids - attr_writer :coordinates + after_update :journey_patterns_control_route_sections, + if: Proc.new { |stop_area| ['boarding_position', 'quay'].include? stop_area.stop_area_type } - after_update :journey_patterns_control_route_sections, - if: Proc.new { |stop_area| ['boarding_position', 'quay'].include? stop_area.stop_area_type } + validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_blank => true + validates_presence_of :name + validates_presence_of :latitude, :if => :longitude + validates_presence_of :longitude, :if => :latitude + validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true + validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true - validates_format_of :registration_number, :with => %r{\A[\d\w_\-]+\Z}, :allow_blank => true - validates_presence_of :name - validates_presence_of :latitude, :if => :longitude - validates_presence_of :longitude, :if => :latitude - validates_numericality_of :latitude, :less_than_or_equal_to => 90, :greater_than_or_equal_to => -90, :allow_nil => true - validates_numericality_of :longitude, :less_than_or_equal_to => 180, :greater_than_or_equal_to => -180, :allow_nil => true + validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true + validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :coordinates, :with => %r{\A *-?(0?[0-9](\.[0-9]*)?|[0-8][0-9](\.[0-9]*)?|90(\.[0]*)?) *\, *-?(0?[0-9]?[0-9](\.[0-9]*)?|1[0-7][0-9](\.[0-9]*)?|180(\.[0]*)?) *\Z}, :allow_nil => true, :allow_blank => true - validates_format_of :url, :with => %r{\Ahttps?:\/\/([\da-z\.-]+)\.([a-z\.]{2,6})([\/\w \.-]*)*\/?\Z}, :allow_nil => true, :allow_blank => true + def self.nullable_attributes + [:registration_number, :street_name, :country_code, :fare_code, + :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] + end - def self.nullable_attributes - [:registration_number, :street_name, :country_code, :fare_code, - :nearest_topic_name, :comment, :long_lat_type, :zip_code, :city_name, :url, :time_zone] - end + after_update :clean_invalid_access_links + before_save :coordinates_to_lat_lng - after_update :clean_invalid_access_links - before_save :coordinates_to_lat_lng + def combine_lat_lng + if self.latitude.nil? || self.longitude.nil? + "" + else + self.latitude.to_s+","+self.longitude.to_s + end + end - def combine_lat_lng - if self.latitude.nil? || self.longitude.nil? - "" - else - self.latitude.to_s+","+self.longitude.to_s + def coordinates + @coordinates || combine_lat_lng end - end - def coordinates - @coordinates || combine_lat_lng - end + def coordinates_to_lat_lng + if ! @coordinates.nil? + if @coordinates.empty? + self.latitude = nil + self.longitude = nil + else + self.latitude = BigDecimal.new(@coordinates.split(",").first) + self.longitude = BigDecimal.new(@coordinates.split(",").last) + end + @coordinates = nil + end + end - def coordinates_to_lat_lng - if ! @coordinates.nil? - if @coordinates.empty? - self.latitude = nil - self.longitude = nil + def user_objectid + if objectid =~ /^.*:([0-9A-Za-z_-]+):STIF$/ + $1 else - self.latitude = BigDecimal.new(@coordinates.split(",").first) - self.longitude = BigDecimal.new(@coordinates.split(",").last) + id.to_s end - @coordinates = nil end - end - def user_objectid - if objectid =~ /^.*:([0-9A-Za-z_-]+):STIF$/ - $1 - else - id.to_s - end - end + def children_in_depth + return [] if self.children.empty? - def children_in_depth - return [] if self.children.empty? + self.children + self.children.map do |child| + child.children_in_depth + end.flatten.compact + end - self.children + self.children.map do |child| - child.children_in_depth - end.flatten.compact - end + def possible_children + case area_type + when "BoardingPosition" then [] + when "Quay" then [] + when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) - [self] + when "StopPlace" then Chouette::StopArea.where(:area_type => ['StopPlace', 'CommercialStopPoint']) - [self] + end - def possible_children - case area_type - when "BoardingPosition" then [] - when "Quay" then [] - when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) - [self] - when "StopPlace" then Chouette::StopArea.where(:area_type => ['StopPlace', 'CommercialStopPoint']) - [self] end - end - - def possible_parents - case area_type - when "BoardingPosition" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] - when "Quay" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] - when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] - when "StopPlace" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] + def possible_parents + case area_type + when "BoardingPosition" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] + when "Quay" then Chouette::StopArea.where(:area_type => "CommercialStopPoint") - [self] + when "CommercialStopPoint" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] + when "StopPlace" then Chouette::StopArea.where(:area_type => "StopPlace") - [self] + end end - end - def geometry_presenter - Chouette::Geometry::StopAreaPresenter.new self - end + def geometry_presenter + Chouette::Geometry::StopAreaPresenter.new self + end - def lines - [] - end + def lines + [] + end - def routes - [] - end + def routes + [] + end - def self.commercial - where :area_type => "CommercialStopPoint" - end + def self.commercial + where :area_type => "CommercialStopPoint" + end - def self.stop_place - where :area_type => "StopPlace" - end + def self.stop_place + where :area_type => "StopPlace" + end - def self.physical - where :area_type => [ "BoardingPosition", "Quay" ] - end + def self.physical + where :area_type => [ "BoardingPosition", "Quay" ] + end - def to_lat_lng - Geokit::LatLng.new(latitude, longitude) if latitude and longitude - end + def to_lat_lng + Geokit::LatLng.new(latitude, longitude) if latitude and longitude + end - def geometry - GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude - end + def geometry + GeoRuby::SimpleFeatures::Point.from_lon_lat(longitude, latitude, 4326) if latitude and longitude + end - def geometry=(geometry) - geometry = geometry.to_wgs84 - self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" - end + def geometry=(geometry) + geometry = geometry.to_wgs84 + self.latitude, self.longitude, self.long_lat_type = geometry.lat, geometry.lng, "WGS84" + end - def position - geometry - end + def position + geometry + end - def position=(position) - position = nil if String === position && position == "" - position = Geokit::LatLng.normalize(position), 4326 if String === position - if position - self.latitude = position.lat - self.longitude = position.lng + def position=(position) + position = nil if String === position && position == "" + position = Geokit::LatLng.normalize(position), 4326 if String === position + if position + self.latitude = position.lat + self.longitude = position.lng + end end - end - def default_position - # for first StopArea ... the bounds is nil :( - Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : nil # FIXME #821 stop_area_referential.envelope.center - end + def default_position + # for first StopArea ... the bounds is nil :( + Chouette::StopArea.bounds ? Chouette::StopArea.bounds.center : nil # FIXME #821 stop_area_referential.envelope.center + end - def around(scope, distance) - db = "ST_GeomFromEWKB(ST_MakePoint(longitude, latitude, 4326))" - from = "ST_GeomFromText('POINT(#{self.longitude} #{self.latitude})', 4326)" - scope.where("ST_DWithin(#{db}, #{from}, ?, false)", distance) - end + def around(scope, distance) + db = "ST_GeomFromEWKB(ST_MakePoint(longitude, latitude, 4326))" + from = "ST_GeomFromText('POINT(#{self.longitude} #{self.latitude})', 4326)" + scope.where("ST_DWithin(#{db}, #{from}, ?, false)", distance) + end - def self.near(origin, distance = 0.3) - origin = origin.to_lat_lng + def self.near(origin, distance = 0.3) + origin = origin.to_lat_lng - lat_degree_units = units_per_latitude_degree(:kms) - lng_degree_units = units_per_longitude_degree(origin.lat, :kms) + lat_degree_units = units_per_latitude_degree(:kms) + lng_degree_units = units_per_longitude_degree(origin.lat, :kms) - where "SQRT(POW(#{lat_degree_units}*(#{origin.lat}-latitude),2)+POW(#{lng_degree_units}*(#{origin.lng}-longitude),2)) <= #{distance}" - end + where "SQRT(POW(#{lat_degree_units}*(#{origin.lat}-latitude),2)+POW(#{lng_degree_units}*(#{origin.lng}-longitude),2)) <= #{distance}" + end - def self.bounds - # Give something like : - # [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]] - min_and_max = connection.select_rows("select min(longitude) as min_lon, min(latitude) as min_lat, max(longitude) as max_lon, max(latitude) as max_lat from #{table_name} where latitude is not null and longitude is not null").first - return nil unless min_and_max + def self.bounds + # Give something like : + # [["113.5292500000000000", "22.1127580000000000", "113.5819330000000000", "22.2157050000000000"]] + min_and_max = connection.select_rows("select min(longitude) as min_lon, min(latitude) as min_lat, max(longitude) as max_lon, max(latitude) as max_lat from #{table_name} where latitude is not null and longitude is not null").first + return nil unless min_and_max - # Ignore [nil, nil, nil, nil] - min_and_max.compact! - return nil unless min_and_max.size == 4 + # Ignore [nil, nil, nil, nil] + min_and_max.compact! + return nil unless min_and_max.size == 4 - min_and_max.collect! { |n| n.to_f } + min_and_max.collect! { |n| n.to_f } - # We need something like : - # [[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]] - coordinates = min_and_max.each_slice(2).to_a - GeoRuby::SimpleFeatures::Envelope.from_coordinates coordinates - end + # We need something like : + # [[113.5292500000000000, 22.1127580000000000], [113.5819330000000000, 22.2157050000000000]] + coordinates = min_and_max.each_slice(2).to_a + GeoRuby::SimpleFeatures::Envelope.from_coordinates coordinates + end - def stop_area_type - area_type ? area_type : " " - end + def stop_area_type + area_type ? area_type : " " + end - def stop_area_type=(stop_area_type) - self.area_type = (stop_area_type ? stop_area_type.camelcase : nil) - end + def stop_area_type=(stop_area_type) + self.area_type = (stop_area_type ? stop_area_type.camelcase : nil) + end - def children_ids=(children_ids) - children = children_ids.split(',').uniq - # remove unset children - self.children.each do |child| - if (! children.include? child.id) - child.update_attribute :parent_id, nil + def children_ids=(children_ids) + children = children_ids.split(',').uniq + # remove unset children + self.children.each do |child| + if (! children.include? child.id) + child.update_attribute :parent_id, nil + end + end + # add new children + Chouette::StopArea.find(children).each do |child| + child.update_attribute :parent_id, self.id end end - # add new children - Chouette::StopArea.find(children).each do |child| - child.update_attribute :parent_id, self.id - end - end - def routing_stop_ids=(routing_stop_ids) - stops = routing_stop_ids.split(',').uniq - self.routing_stops.clear - Chouette::StopArea.find(stops).each do |stop| - self.routing_stops << stop + def routing_stop_ids=(routing_stop_ids) + stops = routing_stop_ids.split(',').uniq + self.routing_stops.clear + Chouette::StopArea.find(stops).each do |stop| + self.routing_stops << stop + end end - end - def routing_line_ids=(routing_line_ids) - lines = routing_line_ids.split(',').uniq - self.routing_lines.clear - Chouette::Line.find(lines).each do |line| - self.routing_lines << line + def routing_line_ids=(routing_line_ids) + lines = routing_line_ids.split(',').uniq + self.routing_lines.clear + Chouette::Line.find(lines).each do |line| + self.routing_lines << line + end end - end - def self.without_geometry - where("latitude is null or longitude is null") - end + def self.without_geometry + where("latitude is null or longitude is null") + end - def self.with_geometry - where("latitude is not null and longitude is not null") - end + def self.with_geometry + where("latitude is not null and longitude is not null") + end - def self.default_geometry! - count = 0 - where(nil).find_each do |stop_area| - Chouette::StopArea.unscoped do - count += 1 if stop_area.default_geometry! + def self.default_geometry! + count = 0 + where(nil).find_each do |stop_area| + Chouette::StopArea.unscoped do + count += 1 if stop_area.default_geometry! + end end + count end - count - end - - def default_geometry! - new_geometry = default_geometry - update_attribute :geometry, new_geometry if new_geometry - end - def default_geometry - children_geometries = children.with_geometry.map(&:geometry).uniq - GeoRuby::SimpleFeatures::Point.centroid children_geometries if children_geometries.present? - end + def default_geometry! + new_geometry = default_geometry + update_attribute :geometry, new_geometry if new_geometry + end - def generic_access_link_matrix - matrix = Array.new - access_points.each do |access_point| - matrix += access_point.generic_access_link_matrix - end - matrix - end + def default_geometry + children_geometries = children.with_geometry.map(&:geometry).uniq + GeoRuby::SimpleFeatures::Point.centroid children_geometries if children_geometries.present? + end - def detail_access_link_matrix - matrix = Array.new - access_points.each do |access_point| - matrix += access_point.detail_access_link_matrix - end - matrix - end + def generic_access_link_matrix + matrix = Array.new + access_points.each do |access_point| + matrix += access_point.generic_access_link_matrix + end + matrix + end - def children_at_base - list = Array.new - children_in_depth.each do |child| - if child.area_type == 'Quay' || child.area_type == 'BoardingPosition' - list << child + def detail_access_link_matrix + matrix = Array.new + access_points.each do |access_point| + matrix += access_point.detail_access_link_matrix end + matrix end - list - end - def parents - list = Array.new - if !parent.nil? - list << parent - list += parent.parents + def children_at_base + list = Array.new + children_in_depth.each do |child| + if child.area_type == 'Quay' || child.area_type == 'BoardingPosition' + list << child + end + end + list end - list - end - def clean_invalid_access_links - stop_parents = parents - access_links.each do |link| - unless stop_parents.include? link.access_point.stop_area - link.delete + def parents + list = Array.new + if !parent.nil? + list << parent + list += parent.parents end + list end - children.each do |child| - child.clean_invalid_access_links + + def clean_invalid_access_links + stop_parents = parents + access_links.each do |link| + unless stop_parents.include? link.access_point.stop_area + link.delete + end + end + children.each do |child| + child.clean_invalid_access_links + end end - end - def duplicate - sa = self.deep_clone :except => [:object_version, :parent_id, :registration_number] - sa.uniq_objectid - sa.name = I18n.t("activerecord.copy", :name => self.name) - sa - end + def duplicate + sa = self.deep_clone :except => [:object_version, :parent_id, :registration_number] + sa.uniq_objectid + sa.name = I18n.t("activerecord.copy", :name => self.name) + sa + end - def journey_patterns_control_route_sections - if self.changed_attributes['latitude'] || self.changed_attributes['longitude'] - self.stop_points.each do |stop_point| - stop_point.route.journey_patterns.completed.map{ |jp| jp.control! } + def journey_patterns_control_route_sections + if self.changed_attributes['latitude'] || self.changed_attributes['longitude'] + self.stop_points.each do |stop_point| + stop_point.route.journey_patterns.completed.map{ |jp| jp.control! } + end end end - end + end end diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb index 89c492b91..3b9eaa2f6 100644 --- a/app/models/chouette/stop_point.rb +++ b/app/models/chouette/stop_point.rb @@ -1,12 +1,13 @@ module Chouette - class StopPoint < TridentActiveRecord - + class StopPoint < Chouette::TridentActiveRecord + has_paper_trail def self.policy_class RoutePolicy end include ForBoardingEnumerations include ForAlightingEnumerations + include ObjectidSupport # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" @@ -18,6 +19,7 @@ module Chouette acts_as_list :scope => :route, top_of_list: 0 + validates_presence_of :stop_area validate :stop_area_id_validation def stop_area_id_validation @@ -47,9 +49,12 @@ module Chouette self.class.create!(atts_for_create) end + def local_id + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.route.id}-#{self.id}" + end + def self.area_candidates Chouette::StopArea.where(:area_type => ['Quay', 'BoardingPosition']) end - end end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index 72496273e..74c20f061 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -1,570 +1,573 @@ -class Chouette::TimeTable < Chouette::TridentActiveRecord - include ChecksumSupport - include TimeTableRestrictions - # FIXME http://jira.codehaus.org/browse/JRUBY-6358 - self.primary_key = "id" - - acts_as_taggable - - attr_accessor :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday - attr_accessor :tag_search - - def self.ransackable_attributes auth_object = nil - (column_names + ['tag_search']) + _ransackers.keys - end +module Chouette + class TimeTable < Chouette::TridentActiveRecord + has_paper_trail + include ChecksumSupport + include TimeTableRestrictions + include ObjectidSupport + # FIXME http://jira.codehaus.org/browse/JRUBY-6358 + self.primary_key = "id" + acts_as_taggable + + attr_accessor :monday,:tuesday,:wednesday,:thursday,:friday,:saturday,:sunday + attr_accessor :tag_search + + def self.ransackable_attributes auth_object = nil + (column_names + ['tag_search']) + _ransackers.keys + end - has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' + has_and_belongs_to_many :vehicle_journeys, :class_name => 'Chouette::VehicleJourney' - has_many :dates, -> {order(:date)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTableDate", :dependent => :destroy - has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy + has_many :dates, -> {order(:date)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTableDate", :dependent => :destroy + has_many :periods, -> {order(:period_start)}, inverse_of: :time_table, :validate => :true, :class_name => "Chouette::TimeTablePeriod", :dependent => :destroy - belongs_to :calendar - belongs_to :created_from, class_name: 'Chouette::TimeTable' + belongs_to :calendar + belongs_to :created_from, class_name: 'Chouette::TimeTable' - scope :overlapping, -> (period_range) do - joins(" - LEFT JOIN time_table_periods ON time_tables.id = time_table_periods.time_table_id - LEFT JOIN time_table_dates ON time_tables.id = time_table_dates.time_table_id - ") - .where("(time_table_periods.period_start <= :end AND time_table_periods.period_end >= :begin) OR (time_table_dates.date BETWEEN :begin AND :end)", {begin: period_range.begin, end: period_range.end}) - end + scope :overlapping, -> (period_range) do + joins(" + LEFT JOIN time_table_periods ON time_tables.id = time_table_periods.time_table_id + LEFT JOIN time_table_dates ON time_tables.id = time_table_dates.time_table_id + ") + .where("(time_table_periods.period_start <= :end AND time_table_periods.period_end >= :begin) OR (time_table_dates.date BETWEEN :begin AND :end)", {begin: period_range.begin, end: period_range.end}) + end - after_save :save_shortcuts + after_save :save_shortcuts - def local_id - "IBOO-#{self.referential.id}-#{self.id}" - end + def local_id + "IBOO-#{self.referential.id}-#{self.id}" + end - def checksum_attributes - [].tap do |attrs| - attrs << self.int_day_types - attrs << self.dates.map(&:checksum).map(&:to_s).sort - attrs << self.periods.map(&:checksum).map(&:to_s).sort + def checksum_attributes + [].tap do |attrs| + attrs << self.int_day_types + attrs << self.dates.map(&:checksum).map(&:to_s).sort + attrs << self.periods.map(&:checksum).map(&:to_s).sort + end end - end - def self.object_id_key - "Timetable" - end + def self.object_id_key + "Timetable" + end - accepts_nested_attributes_for :dates, :allow_destroy => :true - accepts_nested_attributes_for :periods, :allow_destroy => :true - - validates_presence_of :comment - validates_associated :dates - validates_associated :periods - - def continuous_dates - in_days = self.dates.where(in_out: true).sort_by(&:date) - chunk = {} - group = nil - in_days.each_with_index do |date, index| - group ||= index - group = (date.date == in_days[index - 1].date + 1.day) ? group : group + 1 - chunk[group] ||= [] - chunk[group] << date - end - # Remove less than 2 continuous day chunk - chunk.values.delete_if {|dates| dates.count < 2} - end + accepts_nested_attributes_for :dates, :allow_destroy => :true + accepts_nested_attributes_for :periods, :allow_destroy => :true + + validates_presence_of :comment + validates_associated :dates + validates_associated :periods + + def continuous_dates + in_days = self.dates.where(in_out: true).sort_by(&:date) + chunk = {} + group = nil + in_days.each_with_index do |date, index| + group ||= index + group = (date.date == in_days[index - 1].date + 1.day) ? group : group + 1 + chunk[group] ||= [] + chunk[group] << date + end + # Remove less than 2 continuous day chunk + chunk.values.delete_if {|dates| dates.count < 2} + end - def convert_continuous_dates_to_periods - chunks = self.continuous_dates + def convert_continuous_dates_to_periods + chunks = self.continuous_dates - transaction do - chunks.each do |chunk| - self.periods.create!(period_start: chunk.first.date, period_end: chunk.last.date) - self.dates.delete(chunk) + transaction do + chunks.each do |chunk| + self.periods.create!(period_start: chunk.first.date, period_end: chunk.last.date) + self.dates.delete(chunk) + end end end - end - def state_update state - update_attributes(self.class.state_permited_attributes(state)) - self.tag_list = state['tags'].collect{|t| t['name']}.join(', ') - self.calendar_id = nil unless state['calendar'] + def state_update state + update_attributes(self.class.state_permited_attributes(state)) + self.tag_list = state['tags'].collect{|t| t['name']}.join(', ') + self.calendar_id = nil unless state['calendar'] - days = state['day_types'].split(',') - Date::DAYNAMES.map(&:underscore).each do |name| - prefix = human_attribute_name(name).first(2) - send("#{name}=", days.include?(prefix)) - end + days = state['day_types'].split(',') + Date::DAYNAMES.map(&:underscore).each do |name| + prefix = human_attribute_name(name).first(2) + send("#{name}=", days.include?(prefix)) + end - saved_dates = Hash[self.dates.collect{ |d| [d.id, d.date]}] - cmonth = Date.parse(state['current_periode_range']) + saved_dates = Hash[self.dates.collect{ |d| [d.id, d.date]}] + cmonth = Date.parse(state['current_periode_range']) - state['current_month'].each do |d| - date = Date.parse(d['date']) - checked = d['include_date'] || d['excluded_date'] - in_out = d['include_date'] ? true : false + state['current_month'].each do |d| + date = Date.parse(d['date']) + checked = d['include_date'] || d['excluded_date'] + in_out = d['include_date'] ? true : false - date_id = saved_dates.key(date) - time_table_date = self.dates.find(date_id) if date_id + date_id = saved_dates.key(date) + time_table_date = self.dates.find(date_id) if date_id - next if !checked && !time_table_date - # Destroy date if no longer checked - next if !checked && time_table_date.destroy + next if !checked && !time_table_date + # Destroy date if no longer checked + next if !checked && time_table_date.destroy - # Create new date - unless time_table_date - time_table_date = self.dates.create({in_out: in_out, date: date}) - end - # Update in_out - if in_out != time_table_date.in_out - time_table_date.update_attributes({in_out: in_out}) + # Create new date + unless time_table_date + time_table_date = self.dates.create({in_out: in_out, date: date}) + end + # Update in_out + if in_out != time_table_date.in_out + time_table_date.update_attributes({in_out: in_out}) + end end - end - self.state_update_periods state['time_table_periods'] - self.save - end + self.state_update_periods state['time_table_periods'] + self.save + end - def state_update_periods state_periods - state_periods.each do |item| - period = self.periods.find(item['id']) if item['id'] - next if period && item['deleted'] && period.destroy - period ||= self.periods.build + def state_update_periods state_periods + state_periods.each do |item| + period = self.periods.find(item['id']) if item['id'] + next if period && item['deleted'] && period.destroy + period ||= self.periods.build - period.period_start = Date.parse(item['period_start']) - period.period_end = Date.parse(item['period_end']) + period.period_start = Date.parse(item['period_start']) + period.period_end = Date.parse(item['period_end']) - if period.changed? - period.save - item['id'] = period.id + if period.changed? + period.save + item['id'] = period.id + end end + + state_periods.delete_if {|item| item['deleted']} end - state_periods.delete_if {|item| item['deleted']} - end + def self.state_permited_attributes item + item.slice('comment', 'color').to_hash + end - def self.state_permited_attributes item - item.slice('comment', 'color').to_hash - end + def presenter + @presenter ||= ::TimeTablePresenter.new( self) + end - def presenter - @presenter ||= ::TimeTablePresenter.new( self) - end + def self.start_validity_period + [Chouette::TimeTable.minimum(:start_date)].compact.min + end + def self.end_validity_period + [Chouette::TimeTable.maximum(:end_date)].compact.max + end - def self.start_validity_period - [Chouette::TimeTable.minimum(:start_date)].compact.min - end - def self.end_validity_period - [Chouette::TimeTable.maximum(:end_date)].compact.max - end + def add_exclude_date(in_out, date) + self.dates.create!({in_out: in_out, date: date}) + end - def add_exclude_date(in_out, date) - self.dates.create!({in_out: in_out, date: date}) - end + def actualize + self.dates.clear + self.periods.clear + from = self.calendar.convert_to_time_table + self.dates = from.dates + self.periods = from.periods + self.save + end - def actualize - self.dates.clear - self.periods.clear - from = self.calendar.convert_to_time_table - self.dates = from.dates - self.periods = from.periods - self.save - end + def month_inspect(date) + (date.beginning_of_month..date.end_of_month).map do |d| + { + day: I18n.l(d, format: '%A'), + date: d.to_s, + wday: d.wday, + wnumber: d.strftime("%W").to_s, + mday: d.mday, + include_date: include_in_dates?(d), + excluded_date: excluded_date?(d) + } + end + end - def month_inspect(date) - (date.beginning_of_month..date.end_of_month).map do |d| - { - day: I18n.l(d, format: '%A'), - date: d.to_s, - wday: d.wday, - wnumber: d.strftime("%W").to_s, - mday: d.mday, - include_date: include_in_dates?(d), - excluded_date: excluded_date?(d) - } + def save_shortcuts + shortcuts_update + self.update_column(:start_date, start_date) + self.update_column(:end_date, end_date) end - end - def save_shortcuts - shortcuts_update - self.update_column(:start_date, start_date) - self.update_column(:end_date, end_date) - end + def shortcuts_update(date=nil) + dates_array = bounding_dates + #if new_record? + if dates_array.empty? + self.start_date=nil + self.end_date=nil + else + self.start_date=dates_array.min + self.end_date=dates_array.max + end + #else + # if dates_array.empty? + # update_attributes :start_date => nil, :end_date => nil + # else + # update_attributes :start_date => dates_array.min, :end_date => dates_array.max + # end + #end + end - def shortcuts_update(date=nil) - dates_array = bounding_dates - #if new_record? - if dates_array.empty? - self.start_date=nil - self.end_date=nil + def validity_out_from_on?(expected_date) + return false unless self.end_date + self.end_date <= expected_date + end + + def validity_out_between?(starting_date, ending_date) + return false unless self.start_date + starting_date < self.end_date && + self.end_date <= ending_date + end + def self.validity_out_from_on?(expected_date,limit=0) + if limit==0 + Chouette::TimeTable.where("end_date <= ?", expected_date) else - self.start_date=dates_array.min - self.end_date=dates_array.max + Chouette::TimeTable.where("end_date <= ?", expected_date).limit( limit) end - #else - # if dates_array.empty? - # update_attributes :start_date => nil, :end_date => nil - # else - # update_attributes :start_date => dates_array.min, :end_date => dates_array.max - # end - #end - end - - def validity_out_from_on?(expected_date) - return false unless self.end_date - self.end_date <= expected_date - end - - def validity_out_between?(starting_date, ending_date) - return false unless self.start_date - starting_date < self.end_date && - self.end_date <= ending_date - end - def self.validity_out_from_on?(expected_date,limit=0) - if limit==0 - Chouette::TimeTable.where("end_date <= ?", expected_date) - else - Chouette::TimeTable.where("end_date <= ?", expected_date).limit( limit) end - end - def self.validity_out_between?(start_date, end_date,limit=0) - if limit==0 - Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date) - else - Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date).limit( limit) + def self.validity_out_between?(start_date, end_date,limit=0) + if limit==0 + Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date) + else + Chouette::TimeTable.where( "? < end_date", start_date).where( "end_date <= ?", end_date).limit( limit) + end end - end - # Return days which intersects with the time table dates and periods - def intersects(days) - [].tap do |intersect_days| - days.each do |day| - intersect_days << day if include_day?(day) + # Return days which intersects with the time table dates and periods + def intersects(days) + [].tap do |intersect_days| + days.each do |day| + intersect_days << day if include_day?(day) + end end end - end - def include_day?(day) - include_in_dates?(day) || include_in_periods?(day) - end + def include_day?(day) + include_in_dates?(day) || include_in_periods?(day) + end - def include_in_dates?(day) - self.dates.any?{ |d| d.date === day && d.in_out == true } - end + def include_in_dates?(day) + self.dates.any?{ |d| d.date === day && d.in_out == true } + end - def excluded_date?(day) - self.dates.any?{ |d| d.date === day && d.in_out == false } - end + def excluded_date?(day) + self.dates.any?{ |d| d.date === day && d.in_out == false } + end - def include_in_periods?(day) - self.periods.any?{ |period| period.period_start <= day && - day <= period.period_end && - valid_days.include?(day.cwday) && - ! excluded_date?(day) } - end + def include_in_periods?(day) + self.periods.any?{ |period| period.period_start <= day && + day <= period.period_end && + valid_days.include?(day.cwday) && + ! excluded_date?(day) } + end - def include_in_overlap_dates?(day) - return false if self.excluded_date?(day) + def include_in_overlap_dates?(day) + return false if self.excluded_date?(day) - counter = self.dates.select{ |d| d.date === day}.size + self.periods.select{ |period| period.period_start <= day && day <= period.period_end && valid_days.include?(day.cwday) }.size - counter <= 1 ? false : true - end + counter = self.dates.select{ |d| d.date === day}.size + self.periods.select{ |period| period.period_start <= day && day <= period.period_end && valid_days.include?(day.cwday) }.size + counter <= 1 ? false : true + end - def periods_max_date - return nil if self.periods.empty? + def periods_max_date + return nil if self.periods.empty? - min_start = self.periods.map(&:period_start).compact.min - max_end = self.periods.map(&:period_end).compact.max - result = nil + min_start = self.periods.map(&:period_start).compact.min + max_end = self.periods.map(&:period_end).compact.max + result = nil - if max_end && min_start - max_end.downto( min_start) do |date| - if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) - result = date - break + if max_end && min_start + max_end.downto( min_start) do |date| + if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) + result = date + break + end end end + result end - result - end - def periods_min_date - return nil if self.periods.empty? - - min_start = self.periods.map(&:period_start).compact.min - max_end = self.periods.map(&:period_end).compact.max - result = nil - - if max_end && min_start - min_start.upto(max_end) do |date| - if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) - result = date - break + def periods_min_date + return nil if self.periods.empty? + + min_start = self.periods.map(&:period_start).compact.min + max_end = self.periods.map(&:period_end).compact.max + result = nil + + if max_end && min_start + min_start.upto(max_end) do |date| + if self.valid_days.include?(date.cwday) && !self.excluded_date?(date) + result = date + break + end end end + result end - result - end - def bounding_dates - bounding_min = self.dates.select{|d| d.in_out}.map(&:date).compact.min - bounding_max = self.dates.select{|d| d.in_out}.map(&:date).compact.max + def bounding_dates + bounding_min = self.dates.select{|d| d.in_out}.map(&:date).compact.min + bounding_max = self.dates.select{|d| d.in_out}.map(&:date).compact.max - unless self.periods.empty? - bounding_min = periods_min_date if periods_min_date && - (bounding_min.nil? || (periods_min_date < bounding_min)) + unless self.periods.empty? + bounding_min = periods_min_date if periods_min_date && + (bounding_min.nil? || (periods_min_date < bounding_min)) - bounding_max = periods_max_date if periods_max_date && - (bounding_max.nil? || (bounding_max < periods_max_date)) - end + bounding_max = periods_max_date if periods_max_date && + (bounding_max.nil? || (bounding_max < periods_max_date)) + end - [bounding_min, bounding_max].compact - end + [bounding_min, bounding_max].compact + end - def display_day_types - %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| self.send(d) }.map{ |d| self.human_attribute_name(d).first(2)}.join(', ') - end + def display_day_types + %w(monday tuesday wednesday thursday friday saturday sunday).select{ |d| self.send(d) }.map{ |d| self.human_attribute_name(d).first(2)}.join(', ') + end - def day_by_mask(flag) - int_day_types & flag == flag - end + def day_by_mask(flag) + int_day_types & flag == flag + end - def self.day_by_mask(int_day_types,flag) - int_day_types & flag == flag - end + def self.day_by_mask(int_day_types,flag) + int_day_types & flag == flag + end - def valid_days - # Build an array with day of calendar week (1-7, Monday is 1). - [].tap do |valid_days| - valid_days << 1 if monday - valid_days << 2 if tuesday - valid_days << 3 if wednesday - valid_days << 4 if thursday - valid_days << 5 if friday - valid_days << 6 if saturday - valid_days << 7 if sunday + def valid_days + # Build an array with day of calendar week (1-7, Monday is 1). + [].tap do |valid_days| + valid_days << 1 if monday + valid_days << 2 if tuesday + valid_days << 3 if wednesday + valid_days << 4 if thursday + valid_days << 5 if friday + valid_days << 6 if saturday + valid_days << 7 if sunday + end end - end - def self.valid_days(int_day_types) - # Build an array with day of calendar week (1-7, Monday is 1). - [].tap do |valid_days| - valid_days << 1 if day_by_mask(int_day_types,4) - valid_days << 2 if day_by_mask(int_day_types,8) - valid_days << 3 if day_by_mask(int_day_types,16) - valid_days << 4 if day_by_mask(int_day_types,32) - valid_days << 5 if day_by_mask(int_day_types,64) - valid_days << 6 if day_by_mask(int_day_types,128) - valid_days << 7 if day_by_mask(int_day_types,256) + def self.valid_days(int_day_types) + # Build an array with day of calendar week (1-7, Monday is 1). + [].tap do |valid_days| + valid_days << 1 if day_by_mask(int_day_types,4) + valid_days << 2 if day_by_mask(int_day_types,8) + valid_days << 3 if day_by_mask(int_day_types,16) + valid_days << 4 if day_by_mask(int_day_types,32) + valid_days << 5 if day_by_mask(int_day_types,64) + valid_days << 6 if day_by_mask(int_day_types,128) + valid_days << 7 if day_by_mask(int_day_types,256) + end end - end - def monday - day_by_mask(4) - end - def tuesday - day_by_mask(8) - end - def wednesday - day_by_mask(16) - end - def thursday - day_by_mask(32) - end - def friday - day_by_mask(64) - end - def saturday - day_by_mask(128) - end - def sunday - day_by_mask(256) - end + def monday + day_by_mask(4) + end + def tuesday + day_by_mask(8) + end + def wednesday + day_by_mask(16) + end + def thursday + day_by_mask(32) + end + def friday + day_by_mask(64) + end + def saturday + day_by_mask(128) + end + def sunday + day_by_mask(256) + end - def set_day(day,flag) - if day == '1' || day == true - self.int_day_types |= flag - else - self.int_day_types &= ~flag + def set_day(day,flag) + if day == '1' || day == true + self.int_day_types |= flag + else + self.int_day_types &= ~flag + end + shortcuts_update end - shortcuts_update - end - def monday=(day) - set_day(day,4) - end - def tuesday=(day) - set_day(day,8) - end - def wednesday=(day) - set_day(day,16) - end - def thursday=(day) - set_day(day,32) - end - def friday=(day) - set_day(day,64) - end - def saturday=(day) - set_day(day,128) - end - def sunday=(day) - set_day(day,256) - end + def monday=(day) + set_day(day,4) + end + def tuesday=(day) + set_day(day,8) + end + def wednesday=(day) + set_day(day,16) + end + def thursday=(day) + set_day(day,32) + end + def friday=(day) + set_day(day,64) + end + def saturday=(day) + set_day(day,128) + end + def sunday=(day) + set_day(day,256) + end - def effective_days_of_period(period,valid_days=self.valid_days) - days = [] - period.period_start.upto(period.period_end) do |date| - if valid_days.include?(date.cwday) && !self.excluded_date?(date) - days << date + def effective_days_of_period(period,valid_days=self.valid_days) + days = [] + period.period_start.upto(period.period_end) do |date| + if valid_days.include?(date.cwday) && !self.excluded_date?(date) + days << date + end end - end - days - end + days + end - def effective_days(valid_days=self.valid_days) - days=self.effective_days_of_periods(valid_days) - self.dates.each do |d| - days |= [d.date] if d.in_out + def effective_days(valid_days=self.valid_days) + days=self.effective_days_of_periods(valid_days) + self.dates.each do |d| + days |= [d.date] if d.in_out + end + days.sort end - days.sort - end - def effective_days_of_periods(valid_days=self.valid_days) - days = [] - self.periods.each { |p| days |= self.effective_days_of_period(p,valid_days)} - days.sort - end + def effective_days_of_periods(valid_days=self.valid_days) + days = [] + self.periods.each { |p| days |= self.effective_days_of_period(p,valid_days)} + days.sort + end - def clone_periods - periods = [] - self.periods.each { |p| periods << p.copy} - periods.sort_by(&:period_start) - end + def clone_periods + periods = [] + self.periods.each { |p| periods << p.copy} + periods.sort_by(&:period_start) + end - def included_days - days = [] - self.dates.each do |d| - days |= [d.date] if d.in_out + def included_days + days = [] + self.dates.each do |d| + days |= [d.date] if d.in_out + end + days.sort end - days.sort - end - def excluded_days - days = [] - self.dates.each do |d| - days |= [d.date] unless d.in_out + def excluded_days + days = [] + self.dates.each do |d| + days |= [d.date] unless d.in_out + end + days.sort end - days.sort - end - # produce a copy of periods without anyone overlapping or including another - def optimize_overlapping_periods - periods = self.clone_periods - optimized = [] - i=0 - while i < periods.length - p1 = periods[i] - optimized << p1 - j= i+1 - while j < periods.length - p2 = periods[j] - if p1.contains? p2 - periods.delete p2 - elsif p1.overlap? p2 - p1.period_start = [p1.period_start,p2.period_start].min - p1.period_end = [p1.period_end,p2.period_end].max - periods.delete p2 - else - j += 1 + # produce a copy of periods without anyone overlapping or including another + def optimize_overlapping_periods + periods = self.clone_periods + optimized = [] + i=0 + while i < periods.length + p1 = periods[i] + optimized << p1 + j= i+1 + while j < periods.length + p2 = periods[j] + if p1.contains? p2 + periods.delete p2 + elsif p1.overlap? p2 + p1.period_start = [p1.period_start,p2.period_start].min + p1.period_end = [p1.period_end,p2.period_end].max + periods.delete p2 + else + j += 1 + end end + i+= 1 end - i+= 1 + optimized.sort { |a,b| a.period_start <=> b.period_start} end - optimized.sort { |a,b| a.period_start <=> b.period_start} - end - # add a peculiar day or switch it from excluded to included - def add_included_day(d) - if self.excluded_date?(d) - self.dates.each do |date| - if date.date === d - date.in_out = true - end - end - elsif !self.include_in_dates?(d) - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + # add a peculiar day or switch it from excluded to included + def add_included_day(d) + if self.excluded_date?(d) + self.dates.each do |date| + if date.date === d + date.in_out = true + end + end + elsif !self.include_in_dates?(d) + self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + end end - end - # merge effective days from another timetable - def merge!(another_tt) - transaction do - days = [].tap do |array| - array.push(*self.effective_days, *another_tt.effective_days) - array.uniq! - end + # merge effective days from another timetable + def merge!(another_tt) + transaction do + days = [].tap do |array| + array.push(*self.effective_days, *another_tt.effective_days) + array.uniq! + end - self.dates.clear - self.periods.clear + self.dates.clear + self.periods.clear - days.each do |day| - self.dates << Chouette::TimeTableDate.new(date: day, in_out: true) + days.each do |day| + self.dates << Chouette::TimeTableDate.new(date: day, in_out: true) + end + self.save! end - self.save! + self.convert_continuous_dates_to_periods end - self.convert_continuous_dates_to_periods - end - def included_days_in_dates_and_periods - in_day = self.dates.select {|d| d.in_out }.map(&:date) - out_day = self.dates.select {|d| !d.in_out }.map(&:date) + def included_days_in_dates_and_periods + in_day = self.dates.select {|d| d.in_out }.map(&:date) + out_day = self.dates.select {|d| !d.in_out }.map(&:date) - in_periods = self.periods.map{|p| (p.period_start..p.period_end).to_a }.flatten - days = in_periods + in_day - days -= out_day - days - end + in_periods = self.periods.map{|p| (p.period_start..p.period_end).to_a }.flatten + days = in_periods + in_day + days -= out_day + days + end - # keep common dates with another_tt - def intersect!(another_tt) - transaction do - days = [].tap do |array| - array.push(*self.effective_days) - array.delete_if {|day| !another_tt.effective_days.include?(day) } - array.uniq! - end + # keep common dates with another_tt + def intersect!(another_tt) + transaction do + days = [].tap do |array| + array.push(*self.effective_days) + array.delete_if {|day| !another_tt.effective_days.include?(day) } + array.uniq! + end - self.dates.clear - self.periods.clear + self.dates.clear + self.periods.clear - days.sort.each do |d| - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + days.sort.each do |d| + self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + end + self.save! end - self.save! + self.convert_continuous_dates_to_periods end - self.convert_continuous_dates_to_periods - end - # remove common dates with another_tt - def disjoin!(another_tt) - transaction do - days = [].tap do |array| - array.push(*self.effective_days) - array.delete_if {|day| another_tt.effective_days.include?(day) } - array.uniq! - end + # remove common dates with another_tt + def disjoin!(another_tt) + transaction do + days = [].tap do |array| + array.push(*self.effective_days) + array.delete_if {|day| another_tt.effective_days.include?(day) } + array.uniq! + end - self.dates.clear - self.periods.clear + self.dates.clear + self.periods.clear - days.sort.each do |d| - self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + days.sort.each do |d| + self.dates << Chouette::TimeTableDate.new(:date => d, :in_out => true) + end + self.save! end - self.save! + self.convert_continuous_dates_to_periods end - self.convert_continuous_dates_to_periods - end - def duplicate - tt = self.deep_clone :include => [:periods, :dates], :except => [:object_version, :objectid] - tt.tag_list.add(*self.tag_list) unless self.tag_list.empty? - tt.created_from = self - tt.comment = I18n.t("activerecord.copy", :name => self.comment) - tt + def duplicate + tt = self.deep_clone :include => [:periods, :dates], :except => [:object_version, :objectid] + tt.tag_list.add(*self.tag_list) unless self.tag_list.empty? + tt.created_from = self + tt.comment = I18n.t("activerecord.copy", :name => self.comment) + tt + end end end diff --git a/app/models/chouette/time_table_date.rb b/app/models/chouette/time_table_date.rb index 1893eae91..b3b2fd561 100644 --- a/app/models/chouette/time_table_date.rb +++ b/app/models/chouette/time_table_date.rb @@ -1,22 +1,23 @@ -class Chouette::TimeTableDate < Chouette::ActiveRecord - include ChecksumSupport +module Chouette + class TimeTableDate < Chouette::ActiveRecord + include ChecksumSupport - self.primary_key = "id" - belongs_to :time_table, inverse_of: :dates - acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 + self.primary_key = "id" + belongs_to :time_table, inverse_of: :dates + acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 - validates_presence_of :date - validates_uniqueness_of :date, :scope => :time_table_id + validates_presence_of :date + validates_uniqueness_of :date, :scope => :time_table_id - scope :in_dates, -> { where(in_out: true) } + scope :in_dates, -> { where(in_out: true) } - def self.model_name - ActiveModel::Name.new Chouette::TimeTableDate, Chouette, "TimeTableDate" - end + def self.model_name + ActiveModel::Name.new Chouette::TimeTableDate, Chouette, "TimeTableDate" + end - def checksum_attributes - attrs = ['date', 'in_out'] - self.slice(*attrs).values + def checksum_attributes + attrs = ['date', 'in_out'] + self.slice(*attrs).values + end end -end - +end
\ No newline at end of file diff --git a/app/models/chouette/time_table_period.rb b/app/models/chouette/time_table_period.rb index ed136f3b9..ab3e79d7e 100644 --- a/app/models/chouette/time_table_period.rb +++ b/app/models/chouette/time_table_period.rb @@ -1,45 +1,46 @@ -class Chouette::TimeTablePeriod < Chouette::ActiveRecord - include ChecksumSupport +module Chouette + class TimeTablePeriod < Chouette::ActiveRecord + include ChecksumSupport - self.primary_key = "id" - belongs_to :time_table, inverse_of: :periods - acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 + self.primary_key = "id" + belongs_to :time_table, inverse_of: :periods + acts_as_list :scope => 'time_table_id = #{time_table_id}',:top_of_list => 0 - validates_presence_of :period_start, :period_end + validates_presence_of :period_start, :period_end - validate :start_must_be_before_end + validate :start_must_be_before_end - def checksum_attributes - attrs = ['period_start', 'period_end'] - self.slice(*attrs).values - end - - def self.model_name - ActiveModel::Name.new Chouette::TimeTablePeriod, Chouette, "TimeTablePeriod" - end + def checksum_attributes + attrs = ['period_start', 'period_end'] + self.slice(*attrs).values + end - def start_must_be_before_end - # security against nil values - if period_end.nil? || period_start.nil? - return + def self.model_name + ActiveModel::Name.new Chouette::TimeTablePeriod, Chouette, "TimeTablePeriod" end - if period_end <= period_start - errors.add(:period_end,I18n.t("activerecord.errors.models.time_table_period.start_must_be_before_end")) + + def start_must_be_before_end + # security against nil values + if period_end.nil? || period_start.nil? + return + end + if period_end <= period_start + errors.add(:period_end,I18n.t("activerecord.errors.models.time_table_period.start_must_be_before_end")) + end end - end - def copy - Chouette::TimeTablePeriod.new(:period_start => self.period_start,:period_end => self.period_end) - end + def copy + Chouette::TimeTablePeriod.new(:period_start => self.period_start,:period_end => self.period_end) + end - # Test to see if a period overlap this period - def overlap?(p) - (p.period_start >= self.period_start && p.period_start <= self.period_end) || (p.period_end >= self.period_start && p.period_end <= self.period_end) - end + # Test to see if a period overlap this period + def overlap?(p) + (p.period_start >= self.period_start && p.period_start <= self.period_end) || (p.period_end >= self.period_start && p.period_end <= self.period_end) + end - # Test to see if a period is included in this period - def contains?(p) - (p.period_start >= self.period_start && p.period_end <= self.period_end) + # Test to see if a period is included in this period + def contains?(p) + (p.period_start >= self.period_start && p.period_end <= self.period_end) + end end - -end +end
\ No newline at end of file diff --git a/app/models/chouette/timeband.rb b/app/models/chouette/timeband.rb index 9844dd1b1..6155ffc77 100644 --- a/app/models/chouette/timeband.rb +++ b/app/models/chouette/timeband.rb @@ -1,5 +1,4 @@ module Chouette - class TimebandValidator < ActiveModel::Validator def validate(record) if record.end_time <= record.start_time @@ -9,10 +8,12 @@ module Chouette end class Timeband < Chouette::TridentActiveRecord + include ObjectidSupport + has_paper_trail self.primary_key = "id" validates :start_time, :end_time, presence: true - validates_with TimebandValidator + validates_with Chouette::TimebandValidator default_scope { order(:start_time) } @@ -24,7 +25,5 @@ module Chouette fullname = "#{I18n.l(self.start_time, format: :hour)}-#{I18n.l(self.end_time, format: :hour)}" "#{self.name} (#{fullname})" if self.name end - end - end diff --git a/app/models/chouette/trident_active_record.rb b/app/models/chouette/trident_active_record.rb index e8223e3d6..18b7bbf9b 100644 --- a/app/models/chouette/trident_active_record.rb +++ b/app/models/chouette/trident_active_record.rb @@ -1,18 +1,19 @@ -class Chouette::TridentActiveRecord < Chouette::ActiveRecord - include StifNetexAttributesSupport +module Chouette + class TridentActiveRecord < Chouette::ActiveRecord - self.abstract_class = true + self.abstract_class = true - def referential - @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! - end + def referential + @referential ||= Referential.where(:slug => Apartment::Tenant.current).first! + end - def hub_restricted? - referential.data_format == "hub" - end + def hub_restricted? + referential.data_format == "hub" + end - def prefix - referential.prefix - end + def prefix + referential.prefix + end -end + end +end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index f574afc93..247c30668 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -1,7 +1,9 @@ module Chouette - class VehicleJourney < TridentActiveRecord + class VehicleJourney < Chouette::TridentActiveRecord + has_paper_trail include ChecksumSupport include VehicleJourneyRestrictions + include ObjectidSupport include StifTransportModeEnumerations # FIXME http://jira.codehaus.org/browse/JRUBY-6358 self.primary_key = "id" @@ -57,14 +59,14 @@ module Chouette end def local_id - "IBOO-#{self.referential.id}-#{self.route.line.objectid.local_id}-#{self.id}" + "IBOO-#{self.referential.id}-#{self.route.line.get_objectid.local_id}-#{self.id}" end def checksum_attributes [].tap do |attrs| attrs << self.published_journey_name attrs << self.published_journey_identifier - attrs << self.try(:company).try(:objectid).try(:local_id) + attrs << self.try(:company).try(:get_objectid).try(:local_id) attrs << self.footnotes.map(&:checksum).sort attrs << self.vehicle_journey_at_stops.map(&:checksum).sort end @@ -302,6 +304,5 @@ module Chouette ') .where('"time_tables_vehicle_journeys"."vehicle_journey_id" IS NULL') end - end end diff --git a/app/models/chouette/vehicle_journey_at_stop.rb b/app/models/chouette/vehicle_journey_at_stop.rb index a4a4a02c8..6f0119e74 100644 --- a/app/models/chouette/vehicle_journey_at_stop.rb +++ b/app/models/chouette/vehicle_journey_at_stop.rb @@ -1,7 +1,7 @@ module Chouette class VehicleJourneyAtStop < ActiveRecord - include ForBoardingEnumerations - include ForAlightingEnumerations + include Chouette::ForBoardingEnumerations + include Chouette::ForAlightingEnumerations include ChecksumSupport DAY_OFFSET_MAX = 1 @@ -41,7 +41,7 @@ module Chouette :arrival_day_offset, I18n.t( 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', - short_id: vehicle_journey.objectid.short_id, + short_id: vehicle_journey.get_objectid.short_id, max: DAY_OFFSET_MAX + 1 ) ) @@ -52,7 +52,7 @@ module Chouette :departure_day_offset, I18n.t( 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', - short_id: vehicle_journey.objectid.short_id, + short_id: vehicle_journey.get_objectid.short_id, max: DAY_OFFSET_MAX + 1 ) ) @@ -76,4 +76,4 @@ module Chouette end end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb index 95f0cdc3e..db48a6108 100644 --- a/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb +++ b/app/models/chouette/vehicle_journey_at_stops_are_in_increasing_time_order_validator.rb @@ -1,6 +1,6 @@ + module Chouette - class VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator < - ActiveModel::EachValidator + class VehicleJourneyAtStopsAreInIncreasingTimeOrderValidator < ActiveModel::EachValidator def validate_each(vehicle_journey, attribute, value) previous_at_stop = nil @@ -47,4 +47,4 @@ module Chouette valid end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb index 9f577dded..b2cb90d11 100644 --- a/app/models/chouette/vehicle_journey_at_stops_day_offset.rb +++ b/app/models/chouette/vehicle_journey_at_stops_day_offset.rb @@ -39,4 +39,4 @@ module Chouette save end end -end +end
\ No newline at end of file diff --git a/app/models/chouette/vehicle_journey_frequency.rb b/app/models/chouette/vehicle_journey_frequency.rb index 41ba49082..53e85121f 100644 --- a/app/models/chouette/vehicle_journey_frequency.rb +++ b/app/models/chouette/vehicle_journey_frequency.rb @@ -1,5 +1,5 @@ module Chouette - class VehicleJourneyFrequency < VehicleJourney + class VehicleJourneyFrequency < Chouette::VehicleJourney after_initialize :fill_journey_category @@ -66,4 +66,4 @@ module Chouette errors.add(:base, I18n.t('vehicle_journey_frequency.require_at_least_one_frequency')) unless journey_frequencies.size > 0 end end -end +end
\ No newline at end of file diff --git a/app/models/compliance_check_set.rb b/app/models/compliance_check_set.rb index 80e499b74..d734e5f5a 100644 --- a/app/models/compliance_check_set.rb +++ b/app/models/compliance_check_set.rb @@ -1,16 +1,17 @@ class ComplianceCheckSet < ActiveRecord::Base extend Enumerize + has_paper_trail belongs_to :referential belongs_to :compliance_control_set belongs_to :workbench belongs_to :parent, polymorphic: true - has_many :compliance_check_blocks - has_many :compliance_checks + has_many :compliance_check_blocks, dependent: :destroy + has_many :compliance_checks, dependent: :destroy - has_many :compliance_check_resources - has_many :compliance_check_messages + has_many :compliance_check_resources, dependent: :destroy + has_many :compliance_check_messages, dependent: :destroy enumerize :status, in: %w[new pending successful warning failed running aborted canceled] diff --git a/app/models/compliance_control.rb b/app/models/compliance_control.rb index 146c4e838..65e22643d 100644 --- a/app/models/compliance_control.rb +++ b/app/models/compliance_control.rb @@ -83,7 +83,7 @@ require_dependency 'route_control/omnibus_journey_pattern' require_dependency 'route_control/opposite_route_terminus' require_dependency 'route_control/opposite_route' require_dependency 'route_control/stop_points_in_journey_pattern' -require_dependency 'route_control/unactivated_stop_points' +require_dependency 'route_control/unactivated_stop_point' require_dependency 'route_control/zdl_stop_area' require_dependency 'routing_constraint_zone_control/maximum_length' require_dependency 'routing_constraint_zone_control/minimum_length' diff --git a/app/models/compliance_control_set.rb b/app/models/compliance_control_set.rb index deb46f5a1..41076fefc 100644 --- a/app/models/compliance_control_set.rb +++ b/app/models/compliance_control_set.rb @@ -1,4 +1,5 @@ class ComplianceControlSet < ActiveRecord::Base + has_paper_trail belongs_to :organisation has_many :compliance_control_blocks, dependent: :destroy has_many :compliance_controls, dependent: :destroy diff --git a/app/models/concerns/default_attributes_support.rb b/app/models/concerns/default_attributes_support.rb index e85a59160..2ef9149cb 100644 --- a/app/models/concerns/default_attributes_support.rb +++ b/app/models/concerns/default_attributes_support.rb @@ -47,7 +47,6 @@ module DefaultAttributesSupport else self.object_version += 1 end - self.creator_id = 'chouette' end def reset_auto_columns diff --git a/app/models/concerns/default_netex_attributes_support.rb b/app/models/concerns/default_netex_attributes_support.rb deleted file mode 100644 index 4cf77ea65..000000000 --- a/app/models/concerns/default_netex_attributes_support.rb +++ /dev/null @@ -1,72 +0,0 @@ -module DefaultNetexAttributesSupport - extend ActiveSupport::Concern - - included do - before_validation :prepare_auto_columns - - validates_presence_of :objectid - validates_uniqueness_of :objectid - validates_numericality_of :object_version - validate :objectid_format_compliance - - before_validation :default_values, :on => :create - end - - module ClassMethods - def object_id_key - model_name - end - - def model_name - ActiveModel::Name.new self, Chouette, self.name.demodulize - end - end - - def objectid - Chouette::NetexObjectId.new read_attribute(:objectid) - end - - def prepare_auto_columns - if object_version.nil? - self.object_version = 1 - else - self.object_version += 1 - end - self.creator_id = 'chouette' - end - - def fix_uniq_objectid - base_objectid = objectid.rpartition(":").first - self.objectid = "#{base_objectid}:#{id}" - if !valid? - base_objectid="#{objectid}_" - cnt=1 - while !valid? - self.objectid = "#{base_objectid}#{cnt}" - cnt += 1 - end - end - - end - - def objectid_format_compliance - if !objectid.valid? - errors.add :objectid, I18n.t("activerecord.errors.models.trident.invalid_object_id", type: self.class.object_id_key) - end - end - - def uniq_objectid - # OPTIMIZEME - i = 0 - baseobjectid = objectid - while self.class.exists?(:objectid => objectid) - i += 1 - self.objectid = baseobjectid+"_"+i.to_s - end - end - - def default_values - self.object_version ||= 1 - end - -end diff --git a/app/models/concerns/line_referential_support.rb b/app/models/concerns/line_referential_support.rb index 406730ddb..5eade3557 100644 --- a/app/models/concerns/line_referential_support.rb +++ b/app/models/concerns/line_referential_support.rb @@ -3,6 +3,7 @@ module LineReferentialSupport included do belongs_to :line_referential + validates_presence_of :line_referential alias_method :referential, :line_referential end diff --git a/app/models/concerns/object_id_format.rb b/app/models/concerns/object_id_format.rb new file mode 100644 index 000000000..55b93ec81 --- /dev/null +++ b/app/models/concerns/object_id_format.rb @@ -0,0 +1,5 @@ +module ObjectIdFormat + def object_id_format + self.referential.object_id_format + end +end diff --git a/app/models/concerns/objectid_formatter_support.rb b/app/models/concerns/objectid_formatter_support.rb new file mode 100644 index 000000000..34a51740f --- /dev/null +++ b/app/models/concerns/objectid_formatter_support.rb @@ -0,0 +1,17 @@ +module ObjectidFormatterSupport + extend ActiveSupport::Concern + + included do + extend Enumerize + enumerize :objectid_format, in: %w(netex stif_netex stif_reflex stif_codifligne), default: 'netex' + validates_presence_of :objectid_format + + def objectid_formatter + objectid_formatter_class.new + end + + def objectid_formatter_class + "Chouette::ObjectidFormatter::#{read_attribute(:objectid_format).camelcase}".constantize if read_attribute(:objectid_format) + end + end +end diff --git a/app/models/concerns/objectid_support.rb b/app/models/concerns/objectid_support.rb new file mode 100644 index 000000000..cec36678e --- /dev/null +++ b/app/models/concerns/objectid_support.rb @@ -0,0 +1,30 @@ +module ObjectidSupport + extend ActiveSupport::Concern + + included do + before_validation :before_validation_objectid, unless: Proc.new {|model| model.read_attribute(:objectid)} + after_commit :after_commit_objectid, on: :create, if: Proc.new {|model| model.read_attribute(:objectid).try(:include?, '__pending_id__')} + validates_presence_of :objectid + validates_uniqueness_of :objectid, skip_validation: Proc.new {|model| model.read_attribute(:objectid).nil?} + + def before_validation_objectid + self.referential.objectid_formatter.before_validation self + end + + def after_commit_objectid + self.referential.objectid_formatter.after_commit self + end + + def get_objectid + self.referential.objectid_formatter.get_objectid read_attribute(:objectid) if self.referential.objectid_format && read_attribute(:objectid) + end + + def objectid + get_objectid.try(:to_s) + end + + def objectid_class + get_objectid.try(:class) + end + end +end diff --git a/app/models/concerns/stif_codifligne_attributes_support.rb b/app/models/concerns/stif_codifligne_attributes_support.rb deleted file mode 100644 index 0cd2cccc4..000000000 --- a/app/models/concerns/stif_codifligne_attributes_support.rb +++ /dev/null @@ -1,21 +0,0 @@ -module StifCodifligneAttributesSupport - extend ActiveSupport::Concern - - included do - validates_presence_of :objectid - end - - module ClassMethods - def object_id_key - model_name - end - - def model_name - ActiveModel::Name.new self, Chouette, self.name.demodulize - end - end - - def objectid - Chouette::StifCodifligneObjectid.new read_attribute(:objectid) - end -end diff --git a/app/models/concerns/stif_netex_attributes_support.rb b/app/models/concerns/stif_netex_attributes_support.rb deleted file mode 100644 index 076acf491..000000000 --- a/app/models/concerns/stif_netex_attributes_support.rb +++ /dev/null @@ -1,58 +0,0 @@ -module StifNetexAttributesSupport - extend ActiveSupport::Concern - - included do - validates_numericality_of :object_version - validates :objectid, uniqueness: true, presence: true - validate :objectid_format_compliance - - after_save :build_objectid - before_validation :default_values, on: :create - end - - module ClassMethods - def object_id_key - model_name - end - - def model_name - ActiveModel::Name.new self, Chouette, self.name.demodulize - end - end - - def objectid_format_compliance - errors.add :objectid, I18n.t("activerecord.errors.models.trident.invalid_object_id") if !objectid.valid? - end - - def local_id - "IBOO-#{self.referential.id}-#{self.id}" - end - - def build_objectid - if objectid.include? ':__pending_id__' - self.objectid = Chouette::StifNetexObjectid.create(self.provider_id, self.model_name, self.local_id, self.boiv_id) - self.save - end - end - - def default_values - self.object_version ||= 1 - - if self.objectid.to_s.empty? - local_id = "__pending_id__#{rand(50)+ rand(50)}" - self.objectid = Chouette::StifNetexObjectid.create(self.provider_id, self.model_name, local_id, self.boiv_id) - end - end - - def objectid - Chouette::StifNetexObjectid.new read_attribute(:objectid) - end - - def provider_id - self.referential.workbench.organisation.code.underscore.parameterize - end - - def boiv_id - 'LOC' - end -end diff --git a/app/models/concerns/stif_reflex_attributes_support.rb b/app/models/concerns/stif_reflex_attributes_support.rb deleted file mode 100644 index 9dfd21f94..000000000 --- a/app/models/concerns/stif_reflex_attributes_support.rb +++ /dev/null @@ -1,21 +0,0 @@ -module StifReflexAttributesSupport - extend ActiveSupport::Concern - - included do - validates_presence_of :objectid - end - - module ClassMethods - def object_id_key - model_name - end - - def model_name - ActiveModel::Name.new self, Chouette, self.name.demodulize - end - end - - def objectid - Chouette::StifReflexObjectid.new read_attribute(:objectid) - end -end diff --git a/app/models/concerns/stop_area_referential_support.rb b/app/models/concerns/stop_area_referential_support.rb index aa59cbd35..f29397b3a 100644 --- a/app/models/concerns/stop_area_referential_support.rb +++ b/app/models/concerns/stop_area_referential_support.rb @@ -3,6 +3,7 @@ module StopAreaReferentialSupport included do belongs_to :stop_area_referential + validates_presence_of :stop_area_referential alias_method :referential, :stop_area_referential end diff --git a/app/models/dashboard.rb b/app/models/dashboard.rb index a53267db5..46c621266 100644 --- a/app/models/dashboard.rb +++ b/app/models/dashboard.rb @@ -11,8 +11,11 @@ class Dashboard @@default_class = self mattr_accessor :default_class - attr_reader :context + def self.model_name + ActiveModel::Name.new Dashboard, Dashboard, "Dashboard" + end + attr_reader :context def initialize(context) @context = context end diff --git a/app/models/line_referential.rb b/app/models/line_referential.rb index 7ab892b53..15b2f6276 100644 --- a/app/models/line_referential.rb +++ b/app/models/line_referential.rb @@ -1,5 +1,6 @@ class LineReferential < ActiveRecord::Base - include StifTransportModeEnumerations + include ObjectidFormatterSupport + extend StifTransportModeEnumerations has_many :line_referential_memberships has_many :organisations, through: :line_referential_memberships diff --git a/app/models/referential.rb b/app/models/referential.rb index fad91fa7f..ee74bd9f5 100644 --- a/app/models/referential.rb +++ b/app/models/referential.rb @@ -1,5 +1,6 @@ class Referential < ActiveRecord::Base include DataFormatEnumerations + include ObjectidFormatterSupport validates_presence_of :name validates_presence_of :slug @@ -11,8 +12,6 @@ class Referential < ActiveRecord::Base validates_uniqueness_of :slug - validates_presence_of :line_referential - validates_presence_of :stop_area_referential validates_format_of :slug, :with => %r{\A[a-z][0-9a-z_]+\Z} validates_format_of :prefix, :with => %r{\A[0-9a-zA-Z_]+\Z} validates_format_of :upper_corner, :with => %r{\A-?[0-9]+\.?[0-9]*\,-?[0-9]+\.?[0-9]*\Z} @@ -55,6 +54,7 @@ class Referential < ActiveRecord::Base belongs_to :referential_suite + scope :ready, -> { where(ready: true) } scope :in_periode, ->(periode) { where(id: referential_ids_in_periode(periode)) } scope :include_metadatas_lines, ->(line_ids) { where('referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids) } diff --git a/app/models/route_control/unactivated_stop_points.rb b/app/models/route_control/unactivated_stop_point.rb index a903fff53..3066bb523 100644 --- a/app/models/route_control/unactivated_stop_points.rb +++ b/app/models/route_control/unactivated_stop_point.rb @@ -1,5 +1,5 @@ module RouteControl - class UnactivatedStopPoints < ComplianceControl + class UnactivatedStopPoint < ComplianceControl def self.default_code; "3-Route-10" end end diff --git a/app/models/stop_area_referential.rb b/app/models/stop_area_referential.rb index dd206f9e9..54e895cd0 100644 --- a/app/models/stop_area_referential.rb +++ b/app/models/stop_area_referential.rb @@ -1,4 +1,5 @@ class StopAreaReferential < ActiveRecord::Base + include ObjectidFormatterSupport has_many :stop_area_referential_memberships has_many :organisations, through: :stop_area_referential_memberships diff --git a/app/models/workbench.rb b/app/models/workbench.rb index c304e8ba9..e36589210 100644 --- a/app/models/workbench.rb +++ b/app/models/workbench.rb @@ -1,4 +1,5 @@ class Workbench < ActiveRecord::Base + include ObjectidFormatterSupport belongs_to :organisation belongs_to :line_referential belongs_to :stop_area_referential diff --git a/app/policies/company_policy.rb b/app/policies/company_policy.rb index 6106798be..b08dcec53 100644 --- a/app/policies/company_policy.rb +++ b/app/policies/company_policy.rb @@ -4,4 +4,16 @@ class CompanyPolicy < ApplicationPolicy scope end end + + def create? + user.has_permission?('companies.create') + end + + def destroy? + user.has_permission?('companies.destroy') + end + + def update? + user.has_permission?('companies.update') + end end diff --git a/app/policies/compliance_check_set_policy.rb b/app/policies/compliance_check_set_policy.rb index 3f715649e..90323d7c3 100644 --- a/app/policies/compliance_check_set_policy.rb +++ b/app/policies/compliance_check_set_policy.rb @@ -3,5 +3,6 @@ class ComplianceCheckSetPolicy < ApplicationPolicy def resolve scope end + end end diff --git a/app/policies/import_policy.rb b/app/policies/import_policy.rb index b12dcc167..512bfc8ac 100644 --- a/app/policies/import_policy.rb +++ b/app/policies/import_policy.rb @@ -6,14 +6,10 @@ class ImportPolicy < ApplicationPolicy end def create? - !archived? && user.has_permission?('imports.create') - end - - def destroy? - !archived? && user.has_permission?('imports.destroy') + user.has_permission?('imports.create') end def update? - !archived? && user.has_permission?('imports.update') + user.has_permission?('imports.update') end end diff --git a/app/policies/journey_pattern_policy.rb b/app/policies/journey_pattern_policy.rb index 507a364b6..12bcced17 100644 --- a/app/policies/journey_pattern_policy.rb +++ b/app/policies/journey_pattern_policy.rb @@ -18,4 +18,3 @@ class JourneyPatternPolicy < ApplicationPolicy !archived? && organisation_match? && user.has_permission?('journey_patterns.update') end end - diff --git a/app/policies/line_policy.rb b/app/policies/line_policy.rb index acb0d79e7..67ea0b611 100644 --- a/app/policies/line_policy.rb +++ b/app/policies/line_policy.rb @@ -1,11 +1,23 @@ class LinePolicy < ApplicationPolicy - class Scope < Scope def resolve scope end end + def create? + Rails.logger.debug "LinePolicy.create?" + user.has_permission?('lines.create') + end + + def destroy? + user.has_permission?('lines.destroy') + end + + def update? + user.has_permission?('lines.update') + end + def create_footnote? !archived? && organisation_match? && user.has_permission?('footnotes.create') end diff --git a/app/policies/stop_area_policy.rb b/app/policies/stop_area_policy.rb index de8ecda8d..faeebbc2a 100644 --- a/app/policies/stop_area_policy.rb +++ b/app/policies/stop_area_policy.rb @@ -4,4 +4,16 @@ class StopAreaPolicy < ApplicationPolicy scope end end + + def create? + user.has_permission?('stop_areas.create') + end + + def destroy? + user.has_permission?('stop_areas.destroy') + end + + def update? + user.has_permission?('stop_areas.update') + end end diff --git a/app/views/api/kml/access_links/index.kml.slim b/app/views/api/kml/access_links/index.kml.slim index 1bcfdacf1..06db8bf9d 100644 --- a/app/views/api/kml/access_links/index.kml.slim +++ b/app/views/api/kml/access_links/index.kml.slim @@ -8,7 +8,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{access_link.objectid}" name = h(access_link.name) extendeddata - - [ :access_link_type, :objectid, :object_version, :created_at, :updated_at, :creator_id, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :link_orientation].each do |prop| + - [ :access_link_type, :objectid, :object_version, :created_at, :updated_at, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs, :link_orientation].each do |prop| data name="#{prop.to_s}" value = h(access_link.send( prop)) diff --git a/app/views/api/kml/access_points/index.kml.slim b/app/views/api/kml/access_points/index.kml.slim index 1a162f7ed..c6f6b7797 100644 --- a/app/views/api/kml/access_points/index.kml.slim +++ b/app/views/api/kml/access_points/index.kml.slim @@ -9,7 +9,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{access_point.objectid}" name = h(access_point.name) extendeddata - - [ :objectid, :object_version, :creator_id, :created_at, :updated_at, :name, :comment, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :openning_time, :closing_time, :access_type, :access_point_type, :mobility_restricted_suitability, :stairs_availability, :lift_availability].each do |prop| + - [ :objectid, :object_version, :created_at, :updated_at, :name, :comment, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :openning_time, :closing_time, :access_type, :access_point_type, :mobility_restricted_suitability, :stairs_availability, :lift_availability].each do |prop| data name="#{prop.to_s}" value = h(access_point.send( prop)) diff --git a/app/views/api/kml/connection_links/index.kml.slim b/app/views/api/kml/connection_links/index.kml.slim index 7305fbc78..0acdeaafe 100644 --- a/app/views/api/kml/connection_links/index.kml.slim +++ b/app/views/api/kml/connection_links/index.kml.slim @@ -8,7 +8,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{connection_link.objectid}" name = h(connection_link.name) extendeddata - - [ :connection_link_type, :objectid, :object_version, :creator_id, :created_at, :updated_at, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs].each do |prop| + - [ :connection_link_type, :objectid, :object_version, :created_at, :updated_at, :name, :comment, :link_distance, :link_type, :default_duration, :frequent_traveller_duration, :occasional_traveller_duration, :mobility_restricted_traveller_duration, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs].each do |prop| data name="#{prop.to_s}" value = h(connection_link.send( prop)) diff --git a/app/views/api/kml/journey_patterns/show.kml.slim b/app/views/api/kml/journey_patterns/show.kml.slim index 15fb96daa..347d358cc 100644 --- a/app/views/api/kml/journey_patterns/show.kml.slim +++ b/app/views/api/kml/journey_patterns/show.kml.slim @@ -4,7 +4,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" document name = "#{h(Chouette::JourneyPattern.model_name.human)} : #{h(@journey_pattern.name)}" extendeddata - - [:objectid, :object_version, :creator_id, :created_at, :updated_at, :name, :comment, :registration_number, :published_name].each do |prop| + - [:objectid, :object_version, :created_at, :updated_at, :name, :comment, :registration_number, :published_name].each do |prop| data name="#{prop.to_s}" value = h(@journey_pattern.send( prop)) @@ -17,7 +17,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{stop_area.objectid}" name = h(stop_area.name) extendeddata - - [ :objectid, :object_version, :creator_id, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs].each do |prop| + - [ :objectid, :object_version, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs].each do |prop| data name="#{prop.to_s}" value = h(stop_area.send( prop)) diff --git a/app/views/api/kml/lines/show.kml.slim b/app/views/api/kml/lines/show.kml.slim index d1e48323d..1163c98d3 100644 --- a/app/views/api/kml/lines/show.kml.slim +++ b/app/views/api/kml/lines/show.kml.slim @@ -7,7 +7,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{@line.objectid}" name = h(@line.name) extendeddata - - [ :transport_mode, :objectid, :created_at, :updated_at, :object_version, :creator_id, :name, :number, :published_name, :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs].each do |prop| + - [ :transport_mode, :objectid, :created_at, :updated_at, :object_version, :name, :number, :published_name, :registration_number, :comment, :mobility_restricted_suitability, :int_user_needs].each do |prop| data name="#{prop.to_s}" value = h(@line.send( prop)) diff --git a/app/views/api/kml/routes/show.kml.slim b/app/views/api/kml/routes/show.kml.slim index 8a2843bc0..fdf73754d 100644 --- a/app/views/api/kml/routes/show.kml.slim +++ b/app/views/api/kml/routes/show.kml.slim @@ -6,7 +6,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{@route.objectid}" name = h(@route.name) extendeddata - - [:direction, :wayback, :objectid, :object_version, :creator_id, :created_at, :updated_at, :name, :comment, :published_name, :number, :direction_text, :wayback_text].each do |prop| + - [:direction, :wayback, :objectid, :object_version, :created_at, :updated_at, :name, :comment, :published_name, :number, :direction_text, :wayback_text].each do |prop| data name="#{prop.to_s}" value = h(@route.send( prop)) diff --git a/app/views/api/kml/stop_areas/index.kml.slim b/app/views/api/kml/stop_areas/index.kml.slim index a08dbf963..284bd3e34 100644 --- a/app/views/api/kml/stop_areas/index.kml.slim +++ b/app/views/api/kml/stop_areas/index.kml.slim @@ -8,7 +8,7 @@ kml xmlns="http://www.opengis.net/kml/2.2" placemark id="#{stop_area.objectid}" name = h(stop_area.name) extendeddata - - [:objectid, :object_version, :creator_id, :created_at, :updated_at, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs].each do |prop| + - [:objectid, :object_version, :created_at, :updated_at, :name, :comment, :area_type, :registration_number, :nearest_topic_name, :fare_code, :longitude, :latitude, :long_lat_type, :country_code, :street_name, :mobility_restricted_suitability, :stairs_availability, :lift_availability, :int_user_needs].each do |prop| data name="#{prop.to_s}" value = h(stop_area.send( prop)) diff --git a/app/views/api/v1/compliance_check_sets/validated.rabl b/app/views/api/v1/compliance_check_sets/validated.rabl index 1368a8014..4dfa9e420 100644 --- a/app/views/api/v1/compliance_check_sets/validated.rabl +++ b/app/views/api/v1/compliance_check_sets/validated.rabl @@ -4,7 +4,6 @@ attributes( :id, :referential_id, :name, - :creator, :status, :started_at, :ended_at diff --git a/app/views/api/v1/group_of_lines/short_description.rabl b/app/views/api/v1/group_of_lines/short_description.rabl index 770b334ec..15465874c 100644 --- a/app/views/api/v1/group_of_lines/short_description.rabl +++ b/app/views/api/v1/group_of_lines/short_description.rabl @@ -1,6 +1,6 @@ object @group_of_line extends "api/v1/trident_objects/short_description" -[ :creator_id, :name].each do |attr| +[:name].each do |attr| attributes attr, :unless => lambda { |m| m.send( attr).nil?} end diff --git a/app/views/api/v1/group_of_lines/show.rabl b/app/views/api/v1/group_of_lines/show.rabl index 96e4bfc58..d02247da9 100644 --- a/app/views/api/v1/group_of_lines/show.rabl +++ b/app/views/api/v1/group_of_lines/show.rabl @@ -1,6 +1,6 @@ object @group_of_line extends "api/v1/trident_objects/show" -[ :creator_id, :name].each do |attr| +[:name].each do |attr| attributes attr, :unless => lambda { |m| m.send( attr).nil?} end diff --git a/app/views/api/v1/journey_patterns/show.rabl b/app/views/api/v1/journey_patterns/show.rabl index 7c3af52fc..3ea1bb6ff 100644 --- a/app/views/api/v1/journey_patterns/show.rabl +++ b/app/views/api/v1/journey_patterns/show.rabl @@ -5,13 +5,6 @@ extends "api/v1/trident_objects/show" attributes attr, :unless => lambda { |m| m.send( attr).nil?} end -node do |jp| - { - short_id: jp.objectid.parts.try(:third) - } - -end - node(:route_short_description) do |journey_pattern| partial("api/v1/routes/short_description", :object => journey_pattern.route) end diff --git a/app/views/api/v1/trident_objects/show.rabl b/app/views/api/v1/trident_objects/show.rabl index e53a791ef..9722594e1 100644 --- a/app/views/api/v1/trident_objects/show.rabl +++ b/app/views/api/v1/trident_objects/show.rabl @@ -1,5 +1,6 @@ attributes :objectid => :object_id -[ :object_version, :created_at, :updated_at, :creator_id].each do |attr| +[ :object_version, :created_at, :updated_at].each do |attr| attributes attr, :unless => lambda { |m| m.send( attr).nil?} end +node { |model| {short_id: model.get_objectid.short_id} }
\ No newline at end of file diff --git a/app/views/api_keys/edit.html.slim b/app/views/api_keys/edit.html.slim index 9d7d1fdb7..50808b5a4 100644 --- a/app/views/api_keys/edit.html.slim +++ b/app/views/api_keys/edit.html.slim @@ -1,16 +1,10 @@ -/ PageHeader -= pageheader 'Clé d\'API', - t('api_keys.edit.title'), - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@api_key.updated_at, format: :short)), - '' - - / Below are secondary actions & optional content (filters, ...) +- page_header_content_for @api_key +- content_for :page_header_content do + - if policy(@api_key).destroy? .row.mb-sm .col-lg-12.text-right - = ( policy(@api_key).destroy? ? link_to(t('actions.destroy'), api_key_path(@api_key), :method => :delete, class: 'btn btn-default') : '' ) + = link_to(t('actions.destroy'), api_key_path(@api_key), :method => :delete, class: 'btn btn-default') -/ PageContent .page_content .container-fluid .row diff --git a/app/views/api_keys/new.html.slim b/app/views/api_keys/new.html.slim index 9acb08a94..2bed9f912 100644 --- a/app/views/api_keys/new.html.slim +++ b/app/views/api_keys/new.html.slim @@ -1,10 +1,3 @@ -/ PageHeader -= pageheader 'Clé d\'API', - t('api_keys.new.title'), - 'Lorem ipsum dolor sit amet', - '' - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/autocomplete_time_tables/index.rabl b/app/views/autocomplete_time_tables/index.rabl index 7aafdca16..b17411684 100644 --- a/app/views/autocomplete_time_tables/index.rabl +++ b/app/views/autocomplete_time_tables/index.rabl @@ -10,7 +10,7 @@ node do |time_table| :tags => time_table.tags.join(','), :color => time_table.color, :day_types => time_table.display_day_types, - :short_id => time_table.objectid.parts.try(:third), - :text => "<strong><span class='fa fa-circle' style='color:" + (time_table.color ? time_table.color : '#4b4b4b') + "'></span> " + time_table.comment + " - " + time_table.objectid.parts.try(:third) + "</strong><br/><small>" + time_table.display_day_types + "</small>" + :short_id => time_table.get_objectid.short_id, + :text => "<strong><span class='fa fa-circle' style='color:" + (time_table.color ? time_table.color : '#4b4b4b') + "'></span> " + time_table.comment + " - " + time_table.get_objectid.short_id + "</strong><br/><small>" + time_table.display_day_types + "</small>" } end diff --git a/app/views/calendars/edit.html.slim b/app/views/calendars/edit.html.slim index 3463bd05c..e806fc94b 100644 --- a/app/views/calendars/edit.html.slim +++ b/app/views/calendars/edit.html.slim @@ -1,11 +1,5 @@ - breadcrumb :calendar, @calendar -/ PageHeader -= pageheader 'modele-calendrier', - t('.title', calendar: @calendar.name), - '', - t('last_update', time: l(@calendar.updated_at, format: :short)) - -/ PageContent +- page_header_content_for @calendar .page_content .container-fluid .row diff --git a/app/views/calendars/index.html.slim b/app/views/calendars/index.html.slim index a95d54428..77478a624 100644 --- a/app/views/calendars/index.html.slim +++ b/app/views/calendars/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :calendars -/ PageHeader -- header_params = ['modele-calendrier', - t('.title'), - ''] -- header_params << link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default') if policy(Calendar).create? -= pageheader(*header_params) do +- content_for :page_header_actions do + - if policy(Calendar).create? + = link_to(t('actions.add'), new_calendar_path, class: 'btn btn-default') -/ PageContent .page_content .container-fluid - if params[:q].present? or @calendars.any? diff --git a/app/views/calendars/new.html.slim b/app/views/calendars/new.html.slim index 146173d35..ce8b6a036 100644 --- a/app/views/calendars/new.html.slim +++ b/app/views/calendars/new.html.slim @@ -1,11 +1,4 @@ - breadcrumb :calendars -/ PageHeader -= pageheader 'modele-calendrier', - t('.title'), - '', - '' - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim index b2ace0ccc..da4afa3e6 100644 --- a/app/views/calendars/show.html.slim +++ b/app/views/calendars/show.html.slim @@ -1,12 +1,6 @@ - breadcrumb :calendar, @calendar -/ PageHeader -= pageheader 'modele-calendrier', - @calendar.name, - '', - t('last_update', time: l(@calendar.updated_at, format: :short)), - (policy(@calendar).edit? ? link_to(t('actions.edit'), edit_calendar_path(@calendar), class: 'btn btn-default') : '') do - - / Below is secondary actions & optional contents (filters, ...) +- page_header_content_for @calendar +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - @calendar.action_links.each do |link| @@ -15,8 +9,10 @@ data: link.data, class: 'btn btn-primary' do = link.content +- if policy(@calendar).edit? + - content_for :page_header_actions do + = link_to(t('actions.edit'), edit_calendar_path(@calendar), class: 'btn btn-default') -/ PageContent .page_content .container-fluid .row diff --git a/app/views/companies/_form.html.slim b/app/views/companies/_form.html.slim index caf75bd8b..3979c5800 100644 --- a/app/views/companies/_form.html.slim +++ b/app/views/companies/_form.html.slim @@ -1,18 +1,18 @@ -= semantic_form_for [@line_referential, @company] do |form| - = form.inputs do - = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.name") } - = form.input :short_name - = form.input :organizational_unit - = form.input :operating_department_name - = form.input :code - = form.input :phone, as: :phone - = form.input :fax, as: :phone - = form.input :email, as: :email - = form.input :time_zone, include_blank: true - = form.input :url - = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number") } - = form.input :objectid, :required => !@company.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.company.objectid") } += simple_form_for [@line_referential, @company], html: {class: 'form-horizontal', id: 'company_form'}, wrapper: :horizontal_form do |f| + .row + .col-lg-12 + = f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.name")} + = f.input :short_name + = f.input :organizational_unit + = f.input :operating_department_name + = f.input :code + = f.input :phone + = f.input :fax + = f.input :email, as: :email + = f.input :time_zone, include_blank: true + = f.input :url + = f.input :registration_number, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.registration_number")} - = form.actions do - = form.action :submit, as: :button - = form.action :cancel, as: :link
\ No newline at end of file + .separator + + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'company_form' diff --git a/app/views/companies/edit.html.slim b/app/views/companies/edit.html.slim index 2f4c559b9..faa88f829 100644 --- a/app/views/companies/edit.html.slim +++ b/app/views/companies/edit.html.slim @@ -1,4 +1,3 @@ - breadcrumb :company, @company - -= title_tag t('companies.edit.title', company: @company.name) -= render 'form' +- page_header_content_for @company += render 'form'
\ No newline at end of file diff --git a/app/views/companies/index.html.slim b/app/views/companies/index.html.slim index ba061f505..5d746642f 100644 --- a/app/views/companies/index.html.slim +++ b/app/views/companies/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :companies, @line_referential -/ PageHeader -= pageheader 'transporteur', - t('companies.index.title'), - 'Lorem ipsum dolor sit amet', - '', - (policy(Chouette::Company).create? ? link_to(t('companies.actions.new'), new_line_referential_company_path(@line_referential), class: 'btn btn-primary') : '') +- content_for :page_header_actions do + - if policy(Chouette::Company).create? + = link_to(t('companies.actions.new'), new_line_referential_company_path(@line_referential), class: 'btn btn-primary') -/ PageContent .page_content .container-fluid - if params[:q].present? or @companies.any? @@ -27,7 +23,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'Oid', \ - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ + attribute: Proc.new { |n| n.try(:get_objectid).try(:short_id) }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/companies/new.html.slim b/app/views/companies/new.html.slim index 68c0f76c3..cc085ffe2 100644 --- a/app/views/companies/new.html.slim +++ b/app/views/companies/new.html.slim @@ -1,2 +1,6 @@ -= title_tag t('companies.new.title') -= render 'form' +- breadcrumb :lines, @line_referential +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form'
\ No newline at end of file diff --git a/app/views/companies/show.html.slim b/app/views/companies/show.html.slim index 668226938..0d6b4aae3 100644 --- a/app/views/companies/show.html.slim +++ b/app/views/companies/show.html.slim @@ -1,11 +1,6 @@ - breadcrumb :company, @company -/ PageHeader -= pageheader 'transporteur', - @company.name, - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@company.updated_at, format: :short)) do - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - if policy(Chouette::Company).create? @@ -16,14 +11,15 @@ = link_to line_referential_company_path(@line_referential, @company), method: :delete, data: {confirm: t('companies.actions.destroy_confirm')}, class: 'btn btn-primary' do span.fa.fa-trash span = t('companies.actions.destroy') +- page_header_content_for @company + -/ PageContent .page_content .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { 'ID Codif' => @company.try(:objectid).try(:local_id), + { 'ID Codif' => @company.try(:get_objectid).try(:short_id), Chouette::Company.human_attribute_name(:phone) => @company.phone, Chouette::Company.human_attribute_name(:email) => @company.email, Chouette::Company.human_attribute_name(:url) => @company.url } diff --git a/app/views/compliance_check_sets/_filters.html.slim b/app/views/compliance_check_sets/_filters.html.slim index 3051bda64..bf929bc08 100644 --- a/app/views/compliance_check_sets/_filters.html.slim +++ b/app/views/compliance_check_sets/_filters.html.slim @@ -10,14 +10,18 @@ .form-group.togglable = f.label t('activerecord.attributes.compliance_check_set.assigned_to'), required: false, class: 'control-label' = f.input :parent_type_eq_any, collection: ComplianceCheckSet.order('parent_type'), as: :check_boxes, label: false, label_method: lambda {|w| ("<span>#{w}</span>").html_safe}, required: false, wrapper_html: {class: 'checkbox_list'} - .form-group.togglable = f.label Import.human_attribute_name(:created_at), required: false, class: 'control-label' .filter_menu = f.simple_fields_for :created_at do |p| = p.input :start_date, as: :date, label: false, wrapper_html: {class: 'date smart_date filter_menu-item'}, default: @begin_range, include_blank: @begin_range ? false : true = p.input :end_date, as: :date, label: false, wrapper_html: {class: 'date smart_date filter_menu-item'}, default: @end_range, include_blank: @end_range ? false : true - + .form-group.search + .input-group.search_bar + = f.search_field :compliance_control_set_name_cont, class: 'form-control', placeholder: t('compliance_check_sets.filters.name_compliance_control_set') + span.input-group-btn + button.btn.btn-default type='submit' + span.fa.fa-search .actions = link_to t('actions.erase'), @compliance_checks_sets, class: 'btn btn-link' = f.submit t('actions.filter'), class: 'btn btn-default', id: 'compliance_check_set_filter_btn' diff --git a/app/views/compliance_check_sets/executed.html.slim b/app/views/compliance_check_sets/executed.html.slim index bb055272d..da8a2a3de 100644 --- a/app/views/compliance_check_sets/executed.html.slim +++ b/app/views/compliance_check_sets/executed.html.slim @@ -1,8 +1,6 @@ - breadcrumb :compliance_check_set, @workbench, @compliance_check_set -/ PageHeader -= pageheader 'jeux-de-donnees', - t('compliance_check_sets.executed.title', name: @compliance_check_set.name) -/ PageContent +- page_header_content_for @compliance_check_set + .page_content .container-fluid .row @@ -47,7 +45,7 @@ sortable: true, cls: 'table has-filter has-search', model: ComplianceCheck - + - @blocks_to_compliance_checks_map.each do |block, compliance_checks| - if compliance_checks.try(:any?) diff --git a/app/views/compliance_check_sets/index.html.slim b/app/views/compliance_check_sets/index.html.slim index 4ca5a2ee7..f5d1bd777 100644 --- a/app/views/compliance_check_sets/index.html.slim +++ b/app/views/compliance_check_sets/index.html.slim @@ -1,15 +1,5 @@ - breadcrumb :compliance_check_sets, @workbench -/ PageHeader -- header_params = ['jeux-de-donnees', - t('compliance_check_sets.index.title'), - ''] -= pageheader(*header_params) do - / Below is secundary actions & optional contents (filters, ...) - .row.mb-sm - .col-lg-12.text-right - -/ PageContent .page_content .container-fluid .row @@ -22,7 +12,7 @@ [ \ TableBuilderHelper::Column.new( \ key: :ref, \ - attribute: 'referential_id' \ + attribute: 'compliance_check_set_id' \ ), \ TableBuilderHelper::Column.new( \ key: :creation_date, \ @@ -31,8 +21,8 @@ TableBuilderHelper::Column.new( \ key: :associated_object, \ attribute: Proc.new{|n| n.referential.name}, \ - link_to: lambda do |referential| \ - referential_path(referential, current_workbench_id: params[:id]) \ + link_to: lambda do |compliance_check_set| \ + referential_path(compliance_check_set.referential_id) \ end \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/compliance_check_sets/show.html.slim b/app/views/compliance_check_sets/show.html.slim new file mode 100644 index 000000000..c9d0583a5 --- /dev/null +++ b/app/views/compliance_check_sets/show.html.slim @@ -0,0 +1,47 @@ +- breadcrumb :compliance_check_sets, @workbench, @compliance_check_set +/ PageHeader += pageheader 'jeux-de-donnees', + @compliance_check_set.name, + '', + t('last_update', time: l(@compliance_check_set.updated_at, format: :short)) do + + / Below is secundary actions & optional contents (filters, ...) + .row + .col-lg-12.text-right.mb-sm + - @compliance_check_set.action_links.each do |link| + = link_to link.href, + method: link.method, + data: link.data, + class: 'btn btn-primary' do + = link.content + +/ PageContent +.page_content.import_messages + .container-fluid + .row + .col-lg-12 + h1 + span.status_icon = compliance_check_set_status(@compliance_check_set.status) + span = t('compliance_check_sets.show.table_state', lines_status: @compliance_check_set.lines_status , lines_in_compliance_check_set: @compliance_check_set.lines_in_compliance_check_set ) + .col-lg-12 + = t('compliance_check_sets.show.table_explanation') + .row + .col-lg-12 + = table_builder_2 @compliance_check_set.compliance_check_resources, + [ \ + TableBuilderHelper::Column.new( \ + key: :name, \ + attribute: 'name' \ + ), \ + TableBuilderHelper::Column.new( \ + key: :status, \ + attribute: Proc.new { |n| compliance_check_set_status(n.status) } \ + ), \ + TableBuilderHelper::Column.new( \ + key: :metrics, \ + attribute: Proc.new { |n| I18n.t('compliance_check_sets.show.metrics', n.metrics.deep_symbolize_keys) } \ + ) \ + ], + sortable: false, \ + links: [], + cls: 'table' diff --git a/app/views/compliance_control_blocks/edit.html.slim b/app/views/compliance_control_blocks/edit.html.slim index 637bb7311..49aee7705 100644 --- a/app/views/compliance_control_blocks/edit.html.slim +++ b/app/views/compliance_control_blocks/edit.html.slim @@ -1,11 +1,7 @@ -/ PageHeader -= pageheader 'jeux-de-controle', - t('compliance_control_blocks.edit.title', compliance_control_block: @compliance_control_block.id) +- page_header_content_for @compliance_control_block - -/ PageContent .page_content .container-fluid .row .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 - = render 'form'
\ No newline at end of file + = render 'form' diff --git a/app/views/compliance_control_blocks/new.html.slim b/app/views/compliance_control_blocks/new.html.slim index 49404c552..7d2551311 100644 --- a/app/views/compliance_control_blocks/new.html.slim +++ b/app/views/compliance_control_blocks/new.html.slim @@ -1,11 +1,5 @@ -/ PageHeader -= pageheader 'jeux-de-controle', - t('compliance_control_blocks.new.title') - - -/ PageContent .page_content .container-fluid .row .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 - = render 'form'
\ No newline at end of file + = render 'form' diff --git a/app/views/compliance_control_sets/edit.html.slim b/app/views/compliance_control_sets/edit.html.slim index dbe537c93..fd68f0abb 100644 --- a/app/views/compliance_control_sets/edit.html.slim +++ b/app/views/compliance_control_sets/edit.html.slim @@ -1,9 +1,6 @@ - breadcrumb :compliance_control_set, @compliance_control_set -/ PageHeader -= pageheader 'jeux-de-controle', - t('compliance_control_sets.edit.title', name: @compliance_control_set.name) +- page_header_content_for @compliance_control_set -/ PageContent .page_content .container-fluid .row diff --git a/app/views/compliance_control_sets/index.html.slim b/app/views/compliance_control_sets/index.html.slim index 69bff4725..2a5651280 100644 --- a/app/views/compliance_control_sets/index.html.slim +++ b/app/views/compliance_control_sets/index.html.slim @@ -1,16 +1,8 @@ - breadcrumb :compliance_control_sets -/ PageHeader -- header_params = ['jeux-de-controle', - t('compliance_control_sets.index.title'), - ''] -- header_params << link_to(t('compliance_control_sets.actions.new'), new_compliance_control_set_path, class: 'btn btn-default') if policy(Calendar).create? -= pageheader(*header_params) do +- content_for :page_header_actions do + - if policy(ComplianceControlSet).create? + = link_to(t('compliance_control_sets.actions.new'), new_compliance_control_set_path, class: 'btn btn-default') - / Below is secundary actions & optional contents (filters, ...) - .row.mb-sm - .col-lg-12.text-right - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/compliance_control_sets/new.html.slim b/app/views/compliance_control_sets/new.html.slim index d543a6395..ada0de5bf 100644 --- a/app/views/compliance_control_sets/new.html.slim +++ b/app/views/compliance_control_sets/new.html.slim @@ -1,10 +1,5 @@ - breadcrumb :compliance_control_sets -/ PageHeader -= pageheader 'jeux-de-controle', - t('compliance_control_sets.index.new') - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/compliance_control_sets/show.html.slim b/app/views/compliance_control_sets/show.html.slim index a6e2c192a..2291eda06 100644 --- a/app/views/compliance_control_sets/show.html.slim +++ b/app/views/compliance_control_sets/show.html.slim @@ -1,9 +1,6 @@ - breadcrumb :compliance_control_set, @compliance_control_set -/ PageHeader -= pageheader 'jeux-de-controle', - t('compliance_control_sets.show.title', name: @compliance_control_set.name) - - / Below is secondary actions & optional contents (filters, ...) +- page_header_content_for @compliance_control_set +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - @compliance_control_set.action_links.each do |link| @@ -16,7 +13,6 @@ class: 'btn btn-primary' do = link.content -/ PageContent .page_content .container-fluid .row diff --git a/app/views/compliance_controls/_form.html.slim b/app/views/compliance_controls/_form.html.slim index d342f120a..1bcfc093e 100644 --- a/app/views/compliance_controls/_form.html.slim +++ b/app/views/compliance_controls/_form.html.slim @@ -6,7 +6,7 @@ = f.input :compliance_control_set_id, as: :hidden, input_html: { value: @compliance_control_set.id } = f.input :code = f.input :criticity - = f.association :compliance_control_block, collection: @compliance_control_set.compliance_control_blocks, label_method: lambda { |block| transport_mode(block.transport_mode, block.transport_submode) } + = f.association :compliance_control_block, collection: @compliance_control_set.compliance_control_blocks, label_method: lambda { |block| transport_mode_text(block) } = f.input :comment - f.object.class.dynamic_attributes.each do |attribute| - if attribute == :target diff --git a/app/views/compliance_controls/edit.html.slim b/app/views/compliance_controls/edit.html.slim index 192e3521f..00456410c 100644 --- a/app/views/compliance_controls/edit.html.slim +++ b/app/views/compliance_controls/edit.html.slim @@ -1,8 +1,5 @@ - breadcrumb :compliance_control, @compliance_control - -= pageheader 'jeux-de-controle', - t('compliance_controls.edit.title') - +- page_header_content_for @compliance_control .page_content .container-fluid diff --git a/app/views/compliance_controls/new.html.slim b/app/views/compliance_controls/new.html.slim index bd2db230b..f7f47fba3 100644 --- a/app/views/compliance_controls/new.html.slim +++ b/app/views/compliance_controls/new.html.slim @@ -1,11 +1,4 @@ - breadcrumb :compliance_control_set, parent -/ PageHeader -- header_params = ['jeux-de-controle', - t('compliance_controls.new.title'), - ''] -= pageheader(*header_params) do - - .page_content .container-fluid .row @@ -14,4 +7,4 @@ = definition_list t('metadatas'), I18n.t('activerecord.attributes.compliance_control.predicate') => @compliance_control.class.predicate, - I18n.t('activerecord.attributes.compliance_control.prerequisite') => @compliance_control.class.prerequisite
\ No newline at end of file + I18n.t('activerecord.attributes.compliance_control.prerequisite') => @compliance_control.class.prerequisite diff --git a/app/views/compliance_controls/select_type.html.slim b/app/views/compliance_controls/select_type.html.slim index ec1c360cb..d1c518ecf 100644 --- a/app/views/compliance_controls/select_type.html.slim +++ b/app/views/compliance_controls/select_type.html.slim @@ -1,11 +1,4 @@ - breadcrumb :compliance_control_set, parent -/ PageHeader -- header_params = ['jeux-de-controle', - t('compliance_controls.select_type.title'), - ''] -= pageheader(*header_params) do - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/compliance_controls/show.html.slim b/app/views/compliance_controls/show.html.slim index f7ec118b0..54b07abf1 100644 --- a/app/views/compliance_controls/show.html.slim +++ b/app/views/compliance_controls/show.html.slim @@ -1,11 +1,9 @@ - breadcrumb :compliance_control, @compliance_control -/ PageHeader -= pageheader 'jeux-de-controle', - t('compliance_controls.show.title'), - '', - link_to(t('actions.edit'), edit_compliance_control_set_compliance_control_path(params[:compliance_control_set_id], params[:id]), class: 'btn btn-default') do +- content_for :page_header_actions do + = link_to(t('actions.edit'), edit_compliance_control_set_compliance_control_path(params[:compliance_control_set_id], params[:id]), class: 'btn btn-default') +- page_header_content_for @compliance_control + -/ PageContent .page_content .container-fluid .row @@ -29,4 +27,4 @@ - if @compliance_control.compliance_control_block = definition_list t('compliance_controls.show.metadatas.compliance_control_block'), I18n.t('activerecord.attributes.compliance_control_blocks.transport_mode') => I18n.t("enumerize.transport_mode.#{@compliance_control.compliance_control_block.transport_mode}"), - I18n.t('activerecord.attributes.compliance_control_blocks.transport_submode') => I18n.t("enumerize.transport_submode.#{@compliance_control.compliance_control_block.transport_submode}")
\ No newline at end of file + I18n.t('activerecord.attributes.compliance_control_blocks.transport_submode') => I18n.t("enumerize.transport_submode.#{@compliance_control.compliance_control_block.transport_submode}") diff --git a/app/views/connection_links/_connection_link.slim b/app/views/connection_links/_connection_link.slim index 2ece8ed44..44ed5093f 100644 --- a/app/views/connection_links/_connection_link.slim +++ b/app/views/connection_links/_connection_link.slim @@ -11,7 +11,7 @@ span.fa.fa-trash-o h5 - = link_to([@referential, connection_link], class: 'preview', title: "#{Chouette::ConnectionLink.model_name.human.capitalize} #{connection_link.name}") do + = link_to referential_connection_link_path(@referential, connection_link), class: 'preview', title: "#{Chouette::ConnectionLink.model_name.human.capitalize} #{connection_link.name}" do span.name = truncate(connection_link.name, :length => 20) diff --git a/app/views/dashboards/_dashboard.html.slim b/app/views/dashboards/_dashboard.html.slim new file mode 100644 index 000000000..f03301e23 --- /dev/null +++ b/app/views/dashboards/_dashboard.html.slim @@ -0,0 +1,51 @@ +.row + .col-lg-6.col-md-6.col-sm-6.col-xs-12 + - @dashboard.current_organisation.workbenches.each do |workbench| + .panel.panel-default + .panel-heading + h3.panel-title.with_actions + div + = workbench.name + span.badge.ml-xs = workbench.referentials.count if workbench.referentials.present? + + div + = link_to '', workbench_path(workbench), class: ' fa fa-chevron-right pull-right', title: t('.offers.see') + + - if workbench.referentials.present? + .list-group + - workbench.referentials.limit(5).each do |referential| + = link_to referential.name, referential_path(referential, workbench_id: referential.workbench_id, current_workbench_id: workbench.id), class: 'list-group-item' + - else + .panel-body + em.small.text-muted = t('.offers.no_content') + + .panel.panel-default + .panel-heading + h3.panel-title.with_actions + = "Modèles de calendrier" + div + = link_to '', calendars_path, class: ' fa fa-chevron-right pull-right' + - if @dashboard.current_organisation.calendars.present? + .list-group + - @dashboard.current_organisation.calendars.order("updated_at desc").limit(5).each do |calendar| + = link_to calendar.name, calendar_path(calendar), class: 'list-group-item' + - else + .panel-body + em.small.text-muted Aucun modèle de calendrier défini + + .col-lg-6.col-md-6.col-sm-6.col-xs-12 + .panel.panel-default + .panel-heading + h3.panel-title + = "Référentiels d'arrêts" + .list-group + - @dashboard.current_organisation.stop_area_referentials.each do |referential| + = link_to referential.name, stop_area_referential_stop_areas_path(referential), class: 'list-group-item' + + .panel.panel-default + .panel-heading + h3.panel-title + = "Référentiels de lignes" + .list-group + - @dashboard.current_organisation.line_referentials.all.each do |referential| + = link_to referential.name, line_referential_lines_path(referential), class: 'list-group-item' diff --git a/app/views/dashboards/show.html.slim b/app/views/dashboards/show.html.slim index e86af55a6..8df880f89 100644 --- a/app/views/dashboards/show.html.slim +++ b/app/views/dashboards/show.html.slim @@ -1,16 +1,11 @@ - breadcrumb :root -/ PageHeader -= pageheader 'tableau-de-bord', - t('.title', organisation: current_organisation.name) - - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_title, t('.title', organisation: current_organisation.name) +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - if policy(Api::V1::ApiKey).create? = link_to t('actions.create_api_key'), new_api_key_path, class: 'btn btn-primary' - -/ PageContent .page_content .container-fluid = render partial: @dashboard diff --git a/app/views/errors/forbidden.html.slim b/app/views/errors/forbidden.html.slim index 4ca3a6dbf..23ea67eff 100644 --- a/app/views/errors/forbidden.html.slim +++ b/app/views/errors/forbidden.html.slim @@ -1,7 +1,4 @@ -/ PageHeader -= pageheader 'bug', - 'Erreur 403', - '' +- content_for :page_header_title, 'Erreur 403' .page_content .container-fluid diff --git a/app/views/errors/not_found.html.slim b/app/views/errors/not_found.html.slim index 6348ea1be..8821e9ec3 100644 --- a/app/views/errors/not_found.html.slim +++ b/app/views/errors/not_found.html.slim @@ -1,7 +1,4 @@ -/ PageHeader -= pageheader 'bug', - 'Erreur 404', - '' +- content_for :page_header_title, 'Erreur 404' .page_content .container-fluid @@ -11,11 +8,11 @@ - if I18n.locale == :fr p strong = "Désolé, la page demandée n'existe pas." - + p = "Vous pouvez néanmoins continuer à utiliser l'application IBOO." - + - else p strong = "The page you were looking for doesn't exist." - + p = "You can still continue the use the IBOO application. Thank you for understanding." diff --git a/app/views/errors/server_error.html.slim b/app/views/errors/server_error.html.slim index 09884dc29..189a48760 100644 --- a/app/views/errors/server_error.html.slim +++ b/app/views/errors/server_error.html.slim @@ -1,7 +1,4 @@ -/ PageHeader -= pageheader 'bug', - 'Erreur serveur', - '' +- content_for :page_header_title, 'Erreur serveur' .page_content .container-fluid @@ -11,11 +8,11 @@ - if I18n.locale == :fr p strong = "Désolé, une erreur est survenue." - + p = "Vous pouvez néanmoins continuer à utiliser l'application IBOO." - + - else p strong = "We're sorry, but something went wrong." - + p = "You can still continue the use the IBOO application. Thank you for understanding." diff --git a/app/views/import_resources/index.html.slim b/app/views/import_resources/index.html.slim index 849ed6d8d..565dd04e4 100644 --- a/app/views/import_resources/index.html.slim +++ b/app/views/import_resources/index.html.slim @@ -1,11 +1,4 @@ -/ PageHeader -= pageheader 'importer', - t('.title'), - '', - '', - '' -/ PageContent .page_content.import_messages .container-fluid .row @@ -38,7 +31,7 @@ ), \ TableBuilderHelper::Column.new( \ name: 'Résultat des tests' , \ - attribute: Proc.new { |n| I18n.t('import_resources.index.metrics', n.metrics.deep_symbolize_keys) }, \ + attribute: Proc.new { |n| I18n.t('import_resources.index.metrics', import_resoruce_metrics(n.metrics) }, \ sortable: false, \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/imports/index.html.slim b/app/views/imports/index.html.slim index 35cd666b1..79452bbfc 100644 --- a/app/views/imports/index.html.slim +++ b/app/views/imports/index.html.slim @@ -1,12 +1,7 @@ - breadcrumb :imports, @workbench -/ PageHeader -= pageheader 'importer', - t('.title'), - '', - '', - link_to(t('imports.actions.new'), new_workbench_import_path(workbench_id: @workbench), class: 'btn btn-primary') +- content_for :page_header_actions do + = link_to(t('imports.actions.new'), new_workbench_import_path(workbench_id: @workbench), class: 'btn btn-primary') -/ PageContent .page_content .container-fluid - if params[:q].present? or @imports.any? diff --git a/app/views/imports/new.html.slim b/app/views/imports/new.html.slim index b74d8eaf2..3e35028f7 100644 --- a/app/views/imports/new.html.slim +++ b/app/views/imports/new.html.slim @@ -1,9 +1,5 @@ - breadcrumb :imports, @workbench -/ PageHeader -= pageheader 'importer', - t('.title') -/ PageContent .page_content .container-fluid .row diff --git a/app/views/imports/show.html.slim b/app/views/imports/show.html.slim index 69ee44f9f..5e22e03e0 100644 --- a/app/views/imports/show.html.slim +++ b/app/views/imports/show.html.slim @@ -1,11 +1,5 @@ - breadcrumb :import, @workbench, @import -/ PageHeader -= pageheader 'importer', - @import.name, - '', - t('last_update', time: l(@import.updated_at, format: :short)) do - - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @import.action_links.each do |link| @@ -15,7 +9,8 @@ class: 'btn btn-primary' do = link.content -/ PageContent +- page_header_content_for @import + .page_content .container-fluid .row @@ -58,7 +53,7 @@ overhead: [ \ {}, \ { \ - title: "#{@import.children_succeedeed} jeu de données validé sur #{@import.children.count} présents dans l'archive", \ + title: "#{@import.children_succeedeed} jeu de données validé sur #{@import.children.count} présent(s) dans l'archive", \ width: 1, \ cls: "#{@import.import_status_css_class} full-border" \ }, { \ diff --git a/app/views/journey_patterns_collections/show.html.slim b/app/views/journey_patterns_collections/show.html.slim index 7c62b69ee..d53403ff3 100644 --- a/app/views/journey_patterns_collections/show.html.slim +++ b/app/views/journey_patterns_collections/show.html.slim @@ -1,9 +1,6 @@ - breadcrumb :journey_patterns, @referential, @route -/ pageheader -= pageheader 'mission', - "Missions de #{@route.try(:stop_points).first.try(:stop_area).name} vers #{@route.try(:stop_points).last.try(:stop_area).name}", - 'Lorem ipsum dolor sit amet', - '' +- page_header_content_for @route + - @journey_patterns.each do |jp| - jp.errors.each do |error_message| = error_message diff --git a/app/views/layouts/application.html.slim b/app/views/layouts/application.html.slim index 8c731007d..567e14ef0 100644 --- a/app/views/layouts/application.html.slim +++ b/app/views/layouts/application.html.slim @@ -17,6 +17,7 @@ html lang=I18n.locale body = render 'layouts/navigation/main_nav' = render 'layouts/flash_messages', flash: flash + = render 'layouts/navigation/page_header' = yield #sidebar = yield :sidebar diff --git a/app/views/layouts/navigation/_main_nav_left.html.slim b/app/views/layouts/navigation/_main_nav_left.html.slim index 837b9cb73..b63c2dd1c 100644 --- a/app/views/layouts/navigation/_main_nav_left.html.slim +++ b/app/views/layouts/navigation/_main_nav_left.html.slim @@ -1,5 +1,3 @@ -- @localizationUrl = "#{params[:controller]}##{params[:action]}" - .nav-menu#menu_left .openMenu title='Ouvrir le menu' @@ -7,108 +5,4 @@ .closeMenu title='Fermer le menu' .brandname = t('brandname') - #menu-items.panel-group - .menu-item.panel - .panel-heading - h4.panel-title - = link_to '#miOne', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do - |Offres courantes - - #miOne.panel-collapse.collapse - .list-group - = link_to root_path, class: "list-group-item #{(@localizationUrl == 'workbenches#index') ? 'active' : ''}" do - span Tableau de bord - = link_to '#', class: 'list-group-item' do - span Offre de mon organisation - = link_to '#', class: 'list-group-item' do - span Offre IDF - - .menu-item.panel - .panel-heading - h4.panel-title - = link_to '#miTwo', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do - |Espace de travail - - #miTwo.panel-collapse.collapse - .list-group - - if current_user - = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do - span Jeux de données - = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do - span Import - = link_to calendars_path, class: 'list-group-item' do - span Modèles de calendrier - = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do - span Rapport de contrôle - = link_to compliance_control_sets_path, class: 'list-group-item' do - span Jeux de contrôle - - .menu-item.panel - .panel-heading - h4.panel-title - = link_to '#miThree', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do - |Données - - #miThree.panel-collapse.collapse - - if @referential.try(:id) && respond_to?(:current_referential) - .list-group - .list-group-item - = (current_referential.name).upcase - .list-group - = link_to referential_networks_path(current_referential), class: 'list-group-item' do - span = t('networks.index.title') - - = link_to referential_companies_path(current_referential), class: 'list-group-item' do - span = t('companies.index.title') - - = link_to '#', class: 'list-group-item disabled' do - span Tracés - - = link_to referential_time_tables_path(current_referential), class: 'list-group-item' do - span = t('time_tables.index.title') - - - else - .panel-body - em.text-muted - = "Sélectionnez un jeu de données pour accéder à plus de fonctionnalités" - - .menu-item.panel - .panel-heading - h4.panel-title - = link_to '#miFour', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do - |Synchronisation - - #miFour.panel-collapse.collapse - .list-group - = link_to line_referential_path(1), class: "list-group-item #{(@localizationUrl == 'line_referentials#show') ? 'active' : ''}" do - span Synchronisation iLICO - = link_to stop_area_referential_path(1), class: "list-group-item #{(@localizationUrl == 'stop_area_referentials#show') ? 'active' : ''}" do - span Synchronisation iCAR - - .menu-item.panel - .panel-heading - h4.panel-title - = link_to '#miFive', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do - |Outils - - #miFive.panel-collapse.collapse - .list-group - = link_to Rails.application.config.try(:portal_url), target: '_blank', class: 'list-group-item' do - span - span.fa.fa-2x.fa-circle - |Portail (POSTIF) - - = link_to Rails.application.config.try(:codifligne_url), target: '_blank', class: 'list-group-item' do - span - span.fa.fa-2x.fa-circle - |iLICO - - = link_to Rails.application.config.try(:reflex_url), target: '_blank', class: 'list-group-item' do - span - span.fa.fa-2x.fa-circle - |iCAR - - = link_to '#', target: '_blank', class: 'list-group-item' do - span - span.fa.fa-2x.fa-circle - |Support + = render_custom_view 'layouts/navigation/main_nav_left_content' diff --git a/app/views/layouts/navigation/_main_nav_left_content.html.slim b/app/views/layouts/navigation/_main_nav_left_content.html.slim new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/app/views/layouts/navigation/_main_nav_left_content.html.slim diff --git a/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim new file mode 100644 index 000000000..3963d4cd4 --- /dev/null +++ b/app/views/layouts/navigation/_main_nav_left_content_stif.html.slim @@ -0,0 +1,107 @@ +- @localizationUrl = "#{params[:controller]}##{params[:action]}" + +#menu-items.panel-group + .menu-item.panel + .panel-heading + h4.panel-title + = link_to '#miOne', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do + |Offres courantes + + #miOne.panel-collapse.collapse + .list-group + = link_to root_path, class: "list-group-item #{(@localizationUrl == 'workbenches#index') ? 'active' : ''}" do + span Tableau de bord + = link_to '#', class: 'list-group-item' do + span Offre de mon organisation + = link_to '#', class: 'list-group-item' do + span Offre IDF + + .menu-item.panel + .panel-heading + h4.panel-title + = link_to '#miTwo', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do + |Espace de travail + + #miTwo.panel-collapse.collapse + .list-group + - if current_user + = link_to workbench_path(current_offer_workbench), class: "list-group-item #{params[:controller] == 'workbenches' ? 'active' : ''}" do + span Jeux de données + = link_to workbench_imports_path(current_offer_workbench), class: "list-group-item #{(params[:controller] == 'imports') ? 'active' : ''}" do + span Import + = link_to calendars_path, class: 'list-group-item' do + span Modèles de calendrier + = link_to workbench_compliance_check_sets_path(current_offer_workbench), class: 'list-group-item' do + span Rapport de contrôle + = link_to compliance_control_sets_path, class: 'list-group-item' do + span Jeux de contrôle + + .menu-item.panel + .panel-heading + h4.panel-title + = link_to '#miThree', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do + |Données + + #miThree.panel-collapse.collapse + - if @referential.try(:id) && respond_to?(:current_referential) + .list-group + .list-group-item + = (current_referential.name).upcase + .list-group + = link_to referential_networks_path(current_referential), class: 'list-group-item' do + span = t('networks.index.title') + + = link_to referential_companies_path(current_referential), class: 'list-group-item' do + span = t('companies.index.title') + + = link_to '#', class: 'list-group-item disabled' do + span Tracés + + = link_to referential_time_tables_path(current_referential), class: 'list-group-item' do + span = t('time_tables.index.title') + + - else + .panel-body + em.text-muted + = "Sélectionnez un jeu de données pour accéder à plus de fonctionnalités" + + .menu-item.panel + .panel-heading + h4.panel-title + = link_to '#miFour', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do + |Synchronisation + + #miFour.panel-collapse.collapse + .list-group + = link_to line_referential_path(1), class: "list-group-item #{(@localizationUrl == 'line_referentials#show') ? 'active' : ''}" do + span Synchronisation iLICO + = link_to stop_area_referential_path(1), class: "list-group-item #{(@localizationUrl == 'stop_area_referentials#show') ? 'active' : ''}" do + span Synchronisation iCAR + + .menu-item.panel + .panel-heading + h4.panel-title + = link_to '#miFive', data: {toggle: 'collapse', parent: '#menu-items'}, 'aria-expanded' => 'false' do + |Outils + + #miFive.panel-collapse.collapse + .list-group + = link_to Rails.application.config.try(:portal_url), target: '_blank', class: 'list-group-item' do + span + span.fa.fa-2x.fa-circle + |Portail (POSTIF) + + = link_to Rails.application.config.try(:codifligne_url), target: '_blank', class: 'list-group-item' do + span + span.fa.fa-2x.fa-circle + |iLICO + + = link_to Rails.application.config.try(:reflex_url), target: '_blank', class: 'list-group-item' do + span + span.fa.fa-2x.fa-circle + |iCAR + + = link_to '#', target: '_blank', class: 'list-group-item' do + span + span.fa.fa-2x.fa-circle + |Support diff --git a/app/views/layouts/navigation/_page_header.html.slim b/app/views/layouts/navigation/_page_header.html.slim new file mode 100644 index 000000000..2548ddd81 --- /dev/null +++ b/app/views/layouts/navigation/_page_header.html.slim @@ -0,0 +1,24 @@ +div.page_header + div.container-fluid + div.row + div.col-lg-9.col-md-8.col-sm-7.col-xs-7 + - if defined?(resource_class) + div.page-icon + span.sb class="sb-#{resource_class.model_name.name.underscore}" + div.page-title + - if content_for? :page_header_title + h1 = yield :page_header_title + - elsif defined?(resource_class) + h1 = t("#{resource_class.model_name.name.underscore.pluralize}.#{params[:action]}.title") + + div.col-lg-3.col-md-4.col-sm-5.col-xs-5.text-right + div.page-meta + - if content_for? :page_header_meta + div.small = yield :page_header_meta + + div.page-action + - if content_for? :page_header_actions + div.small = yield :page_header_actions + + - if content_for? :page_header_content + = yield :page_header_content diff --git a/app/views/line_footnotes/edit.html.slim b/app/views/line_footnotes/edit.html.slim index 4a0fbb931..203bdab94 100644 --- a/app/views/line_footnotes/edit.html.slim +++ b/app/views/line_footnotes/edit.html.slim @@ -1,10 +1,5 @@ -/ PageHeader -= pageheader 'ligne', - "Notes sur la ligne #{@line.name}", - 'Lorem ipsum dolor sit amet', - (@line.footnotes.any? ? t('last_update', time: l(@line.footnotes.last.updated_at, format: :short)) : '') +- page_header_content_for @line -/ PageContent .page_content .container-fluid .row diff --git a/app/views/line_footnotes/show.html.slim b/app/views/line_footnotes/show.html.slim index 0ed1d2958..e4f2a1d42 100644 --- a/app/views/line_footnotes/show.html.slim +++ b/app/views/line_footnotes/show.html.slim @@ -1,12 +1,11 @@ - breadcrumb :line_footnotes, @referential, @line -/ PageHeader -= pageheader 'ligne', - "Notes sur la ligne #{@line.name}", - 'Lorem ipsum dolor sit amet', - '', - (policy(@line).update_footnote? ? link_to(t('actions.edit'), edit_referential_line_footnotes_path(@referential, @line), class: 'btn btn-primary') : '') -/ PageContent +- content_for :page_header_actions do + - if policy(@line).update_footnote? + = link_to(t('actions.edit'), edit_referential_line_footnotes_path(@referential, @line), class: 'btn btn-primary') + +- page_header_content_for @line + .page_content .container-fluid .row diff --git a/app/views/line_referentials/edit.html.slim b/app/views/line_referentials/edit.html.slim index 820b788e5..374d34ed3 100644 --- a/app/views/line_referentials/edit.html.slim +++ b/app/views/line_referentials/edit.html.slim @@ -1,3 +1,2 @@ -= title_tag t('line_referentials.edit.title', line_referential: @line_referential.name) - -= render 'form'
\ No newline at end of file +- page_header_content_for @line_referential += render 'form' diff --git a/app/views/line_referentials/show.html.slim b/app/views/line_referentials/show.html.slim index b98e9d5bb..b4b32bc52 100644 --- a/app/views/line_referentials/show.html.slim +++ b/app/views/line_referentials/show.html.slim @@ -1,12 +1,9 @@ - breadcrumb :line_referential, @line_referential -/ PageHeader -= pageheader 'synchro-ilico', - t('.title'), - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@line_referential.updated_at, format: :short)), - link_to(t('actions.sync'), sync_line_referential_path(@line_referential), method: :post, class: 'btn btn-default') do +- page_header_content_for @line_referential +- content_for :page_header_actions do + = link_to(t('actions.sync'), sync_line_referential_path(@line_referential), method: :post, class: 'btn btn-default') - / Below is secundary actions & opt. contents +- content_for :page_header_content do .row.mb-md .col-lg-12.text-right = link_to line_referential_companies_path(@line_referential), class: 'btn btn-primary' do @@ -19,7 +16,6 @@ = Referential.human_attribute_name(:lines) em.small = " (#{@line_referential.lines.size})" -/ PageContent .page_content .container-fluid .row diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim index 58f8f2431..e3674656a 100644 --- a/app/views/lines/_filters.html.slim +++ b/app/views/lines/_filters.html.slim @@ -8,11 +8,11 @@ .ffg-row .form-group.togglable - = f.label Chouette::Line.human_attribute_name(:network), required: false, class: 'control-label' + = f.label Chouette::Line.human_attribute_name(:network_id), required: false, class: 'control-label' = f.input :network_id_eq_any, collection: @line_referential.networks.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} .form-group.togglable - = f.label Chouette::Line.human_attribute_name(:company), required: false, class: 'control-label' + = f.label Chouette::Line.human_attribute_name(:company_id), required: false, class: 'control-label' = f.input :company_id_eq_any, collection: @line_referential.companies.order(name: :asc), as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + l.name + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'} .form-group.togglable diff --git a/app/views/lines/_form.html.slim b/app/views/lines/_form.html.slim index d7b5a65ed..4952b72ff 100644 --- a/app/views/lines/_form.html.slim +++ b/app/views/lines/_form.html.slim @@ -1,45 +1,22 @@ -= semantic_form_for [@line_referential, @line] do |form| - = form.inputs do - / = form.input :network, as: :select, :collection => Chouette::Network.all, include_blank: false - / = form.input :company, as: :select, :collection => Chouette::Company.all, include_blank: false - / = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.name") } - / = form.input :published_name - / = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.registration_number")} - / = form.input :number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.number") } - / = form.input :transport_mode, include_blank: false - / = form.input :color, as: :string - / = form.input :text_color - / = form.input :stable_id - / = form.input :url - / = form.input :mobility_restricted_suitability, as: :select, :collection => [[@line.human_attribute_name("accessible"), true], [@line.human_attribute_name("not_accessible"), false]], :include_blank => true - / = form.input :flexible_service, as: :select, :collection => [[@line.human_attribute_name("on_demaond_fs"), true], [@line.human_attribute_name("regular_fs"), false]], :include_blank => true - / = form.input :comment - / = form.input :objectid, :required => !@line.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.line.objectid")} - / = form.input :group_of_line_tokens, :label => t('.group_of_lines'), as: :text, :input_html => { :"data-pre" => ( @line.group_of_lines.map { |group_of_line| { :id => group_of_line.id, :name => group_of_line.name } } ).to_json } += simple_form_for [@line_referential, @line], html: {class: 'form-horizontal', id: 'lines_form'}, wrapper: :horizontal_form do |f| + .row + .col-lg-12 + = f.input :name + = f.input :network_id, as: :select, :collection => @line_referential.networks, include_blank: false + = f.input :company_id, as: :select, :collection => @line_referential.companies, include_blank: false + = f.input :published_name + = f.input :registration_number + = f.input :number + = f.input :transport_mode, as: :select, collection: Chouette::Line.sorted_transport_modes, label: t('activerecord.attributes.compliance_control_blocks.transport_mode'), label_method: lambda {|t| ("<span>" + t("enumerize.transport_mode.#{t}") + "</span>").html_safe}, required: true, :include_blank => false + = f.input :transport_submode, as: :select, collection: Chouette::Line.sorted_transport_submodes, label: t('activerecord.attributes.compliance_control_blocks.transport_submode'), label_method: lambda {|t| ("<span>" + t("enumerize.transport_submode.#{t}") + "</span>").html_safe}, :include_blank => true + = f.input :color, as: :string + = f.input :text_color + = f.input :stable_id + = f.input :url + = f.input :mobility_restricted_suitability, as: :select, :collection => [[@line.human_attribute_name("accessible"), true], [@line.human_attribute_name("not_accessible"), false]], :include_blank => true + = f.input :flexible_service, as: :select, :collection => [[@line.human_attribute_name("on_demaond_fs"), true], [@line.human_attribute_name("regular_fs"), false]], :include_blank => true + = f.input :comment + .separator - .footnotes_block - h3 = t("footnotes.index.title") + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'lines_form' - #footnotes - = form.semantic_fields_for :footnotes do |f| - = render "footnotes/footnote_fields", :f => f - - .add_footnote - = link_to_add_association t("footnotes.actions.add_footnote"), form, :footnotes , :partial => "footnotes/footnote_fields", :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "div#footnotes", class: 'add' - - = form.actions do - = form.action :submit, as: :button - = form.action :cancel, as: :link - -javascript: - $(function() { - $("#line_group_of_line_tokens").tokenInput("#{name_filter_referential_group_of_lines_path(@line_referential, format: :json)}", { - crossDomain: false, - prePopulate: $('#group_of_line_tokens').data('pre'), - minChars: 3, - preventDuplicates: true, - hintText: "#{I18n.t('search_hint')}", - noResultsText: "#{I18n.t('no_result_text')}", - searchingText: "#{I18n.t('searching_term')}" - }); - }); diff --git a/app/views/lines/edit.html.slim b/app/views/lines/edit.html.slim index 3c2eee03f..efe674ba4 100644 --- a/app/views/lines/edit.html.slim +++ b/app/views/lines/edit.html.slim @@ -1,5 +1,8 @@ - breadcrumb :line, @line +- page_header_content_for @line -= title_tag t('lines.edit.title', line: @line.name) - -= render 'form' +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim index 7e3e1cc85..8b035b477 100644 --- a/app/views/lines/index.html.slim +++ b/app/views/lines/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :lines, @line_referential -/ PageHeader -= pageheader 'ligne', - t('lines.index.title'), - 'Lorem ipsum dolor sit amet', - '', - ((policy(Chouette::Line).create? && @line_referential.organisations.include?(current_organisation)) ? link_to(t('lines.actions.new'), new_line_referential_line_path(@line_referential), class: 'btn btn-primary') : '') +- content_for :page_header_actions do + - if (policy(Chouette::Line).create? && @line_referential.organisations.include?(current_organisation)) + = link_to(t('lines.actions.new'), new_line_referential_line_path(@line_referential), class: 'btn btn-primary') -/ PageContent .page_content .container-fluid - if params[:q].present? or @lines.any? @@ -20,8 +16,8 @@ = table_builder_2 @lines, [ \ TableBuilderHelper::Column.new( \ - name: 'ID Codifligne', \ - attribute: Proc.new { |n| n.objectid.local_id }, \ + name: t('id_codif'), \ + attribute: Proc.new { |n| n.get_objectid.short_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/lines/new.html.slim b/app/views/lines/new.html.slim index f09a4b4aa..6eecf1e7d 100644 --- a/app/views/lines/new.html.slim +++ b/app/views/lines/new.html.slim @@ -1,5 +1,6 @@ - breadcrumb :lines, @line_referential - -= title_tag t('lines.new.title') - -= render 'form' +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' diff --git a/app/views/lines/show.html.slim b/app/views/lines/show.html.slim index d8f236ecc..4969ca3cd 100644 --- a/app/views/lines/show.html.slim +++ b/app/views/lines/show.html.slim @@ -1,11 +1,5 @@ - breadcrumb :line, @line -/ PageHeader -= pageheader 'ligne', - @line.name, - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@line.updated_at, format: :short)) do - - / Below is secundary actions & optional contents +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @line.action_links.each do |link| @@ -15,16 +9,17 @@ class: 'btn btn-primary' do = link.content -/ PageContent +- page_header_content_for @line + .page_content .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { 'ID Codif' => @line.objectid.local_id, + { 'ID Codif' => @line.get_objectid.short_id, 'Activé' => (@line.deactivated? ? t('false') : t('true')), - @line.human_attribute_name(:network) => (@line.network.nil? ? t('lines.index.unset') : @line.network.name), - @line.human_attribute_name(:company) => (@line.company.nil? ? t('lines.index.unset') : @line.company.name), + @line.human_attribute_name(:network_id) => (@line.network.nil? ? t('lines.index.unset') : @line.network.name), + @line.human_attribute_name(:company_id) => (@line.company.nil? ? t('lines.index.unset') : @line.company.name), 'Transporteur(s) secondaire(s)' => (@line.secondary_companies.nil? ? t('lines.index.unset') : @line.secondary_companies.collect(&:name).join(', ')), 'Nom court' => @line.number, 'Code public' => (@line.registration_number ? @line.registration_number : '-'), diff --git a/app/views/networks/_form.html.slim b/app/views/networks/_form.html.slim index 7b048edc9..362584f97 100644 --- a/app/views/networks/_form.html.slim +++ b/app/views/networks/_form.html.slim @@ -1,15 +1,14 @@ -= semantic_form_for [@line_referential, @network] do |form| - = form.inputs do - = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.network.name")} - = form.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.network.registration_number")} - = form.input :comment - = form.input :version_date, as: :date_picker - = form.input :description - = form.input :source_name - = form.input :source_type_name, as: :select, :collection => source_type_name_label_pairs, :include_blank => true - = form.input :source_identifier - = form.input :objectid, :required => !@network.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.network.objectid")} += simple_form_for [@line_referential, @network], html: {class: 'form-horizontal', id: 'network_form'}, wrapper: :horizontal_form do |f| + .row + .col-lg-12 + = f.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.network.name")} + = f.input :registration_number, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.network.registration_number")} + = f.input :comment + = f.input :version_date, :label_html => { :class => 'string optional col-sm-4 col-xs-5 control-label' }, :wrapper => :multi_select_inline + = f.input :description + = f.input :source_name + = f.input :source_type_name, as: :select, :collection => Chouette::Network.source_type_name.options, :include_blank => true + = f.input :source_identifier + .separator - = form.actions do - = form.action :submit, as: :button - = form.action :cancel, as: :link + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'network_form' diff --git a/app/views/networks/edit.html.slim b/app/views/networks/edit.html.slim index 2d511e15d..64513d250 100644 --- a/app/views/networks/edit.html.slim +++ b/app/views/networks/edit.html.slim @@ -1,4 +1,7 @@ - breadcrumb :network, @network -= title_tag t('networks.edit.title', network: @network.name) - -= render 'form' +- page_header_content_for @network +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form'
\ No newline at end of file diff --git a/app/views/networks/index.html.slim b/app/views/networks/index.html.slim index e498ea35f..b13c73e9e 100644 --- a/app/views/networks/index.html.slim +++ b/app/views/networks/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :networks, @line_referential -/ PageHeader -= pageheader 'reseau', - t('networks.index.title'), - 'Lorem ipsum dolor sit amet', - '', - (policy(Chouette::Network).create? ? link_to(t('networks.actions.new'), new_line_referential_network_path(@line_referential), class: 'btn btn-primary') : '') +- content_for :page_header_actions do + - if policy(Chouette::Network).create? + = link_to(t('networks.actions.new'), new_line_referential_network_path(@line_referential), class: 'btn btn-primary') -/ PageContent .page_content .container-fluid - if params[:q].present? or @networks.any? @@ -27,7 +23,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'Oid', \ - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ + attribute: Proc.new { |n| n.try(:get_objectid).try(:short_id) }, \ sortable: false \ ), TableBuilderHelper::Column.new( \ diff --git a/app/views/networks/new.html.slim b/app/views/networks/new.html.slim index cf04ab03f..590d2b409 100644 --- a/app/views/networks/new.html.slim +++ b/app/views/networks/new.html.slim @@ -1,4 +1,6 @@ - breadcrumb :networks, @line_referential -= title_tag t('networks.new.title') - -= render 'form' +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form'
\ No newline at end of file diff --git a/app/views/networks/show.html.slim b/app/views/networks/show.html.slim index 9b2a0dbf8..f7d40a049 100644 --- a/app/views/networks/show.html.slim +++ b/app/views/networks/show.html.slim @@ -1,11 +1,6 @@ - breadcrumb :network, @network -/ PageHeader -= pageheader 'reseau', - @network.name, - '', - t('last_update', time: l(@network.updated_at, format: :short)) do - - / Below is secundary actions & optional contents (filters, ...) +- page_header_content_for @network +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @network.action_links.each do |link| @@ -14,11 +9,9 @@ data: link.data, class: 'btn btn-primary' do = link.content - -/ PageContent .page_content .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { 'ID Codif' => @network.try(:objectid).try(:local_id) } + { 'ID Codif' => @network.try(:get_objectid).try(:short_id) } diff --git a/app/views/referential_companies/edit.html.slim b/app/views/referential_companies/edit.html.slim index d191d2a37..b3fcf6cd8 100644 --- a/app/views/referential_companies/edit.html.slim +++ b/app/views/referential_companies/edit.html.slim @@ -1,4 +1,3 @@ - breadcrumb :referential_company, @referential, @company - -= title_tag t('companies.edit.title', company: @company.name) +- page_header_content_for @company = render 'form' diff --git a/app/views/referential_companies/index.html.slim b/app/views/referential_companies/index.html.slim index 9f5cd5d62..de0f7de69 100644 --- a/app/views/referential_companies/index.html.slim +++ b/app/views/referential_companies/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :referential_companies, @referential -/ PageHeader -= pageheader 'transporteur', - t('companies.index.title'), - '', - '', - (policy(Chouette::Company).create? ? link_to(t('companies.actions.new'), new_referential_company_path(@referential), class: 'btn btn-default') : '') +- content_for :page_header_actions do + - if policy(Chouette::Company).create? + = link_to(t('companies.actions.new'), new_referential_company_path(@referential), class: 'btn btn-default') -/ PageContent .page_content .container-fluid - if params[:q].present? or @companies.any? @@ -26,7 +22,7 @@ = table_builder_2 @companies, [ \ TableBuilderHelper::Column.new( \ - name: 'ID Codifligne', \ + name: t('id_codif'), \ attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ sortable: false \ ), \ diff --git a/app/views/referential_companies/new.html.slim b/app/views/referential_companies/new.html.slim index 1c7fc7297..5e59db139 100644 --- a/app/views/referential_companies/new.html.slim +++ b/app/views/referential_companies/new.html.slim @@ -1,3 +1,2 @@ - breadcrumb :referential_companies, @referential -= title_tag t('companies.new.title') = render 'form' diff --git a/app/views/referential_companies/show.html.slim b/app/views/referential_companies/show.html.slim index 0dbc3cdd0..1599145be 100644 --- a/app/views/referential_companies/show.html.slim +++ b/app/views/referential_companies/show.html.slim @@ -1,11 +1,5 @@ - breadcrumb :referential_company, @referential, @company -/ PageHeader -= pageheader 'transporteur', - @company.name, - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@company.updated_at, format: :short)) do - - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - if policy(Chouette::Company).create? @@ -17,7 +11,8 @@ span.fa.fa-trash span = t('companies.actions.destroy') -/ PageContent +- page_header_content_for @company + .page_content .container-fluid .row diff --git a/app/views/referential_lines/edit.html.slim b/app/views/referential_lines/edit.html.slim index 8c51715ba..45f26a05c 100644 --- a/app/views/referential_lines/edit.html.slim +++ b/app/views/referential_lines/edit.html.slim @@ -1,4 +1,3 @@ -- breadcrumb :referential_line, @line, @referential -= title_tag t('lines.edit.title', line: @line.name) - +- breadcrumb :referential_line, @referential, @line +- page_header_content_for @line = render 'form' diff --git a/app/views/referential_lines/new.html.slim b/app/views/referential_lines/new.html.slim index 56da24d7c..bcc583279 100644 --- a/app/views/referential_lines/new.html.slim +++ b/app/views/referential_lines/new.html.slim @@ -1,3 +1 @@ -= title_tag t('lines.new.title') - -= render 'form'
\ No newline at end of file += render 'form' diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index 0ef548e89..cb4791855 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -1,27 +1,21 @@ - breadcrumb :referential_line, @referential, @line -/ PageHeader -= pageheader 'ligne', - t('lines.index.line', line: @line.name), - '', - t('last_update', time: l(@line.updated_at, format: :short)) do +- content_for :page_header_content do +.row + .col-lg-12.text-right.mb-sm + - @line.action_links.each do |link| + = link_to link.href, + method: link.method, + data: link.data, + class: 'btn btn-primary' do + = link.content +- page_header_content_for @line - / Below is secundary actions & optional contents - .row - .col-lg-12.text-right.mb-sm - - @line.action_links.each do |link| - = link_to link.href, - method: link.method, - data: link.data, - class: 'btn btn-primary' do - = link.content - -/ PageContent .page_content .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { t('id_codif') => @line.objectid.local_id, + { t('id_codif') => @line.get_objectid.short_id, 'Activé' => (@line.deactivated? ? t('false') : t('true')), @line.human_attribute_name(:network) => (@line.network.nil? ? t('lines.index.unset') : link_to(@line.network.name, [@referential, @line.network]) ), @line.human_attribute_name(:company) => (@line.company.nil? ? t('lines.index.unset') : link_to(@line.company.name, [@referential, @line.company]) ), @@ -47,8 +41,8 @@ = table_builder_2 @routes, [ \ TableBuilderHelper::Column.new( \ - name: 'ID', \ - attribute: Proc.new { |n| n.objectid.short_id }, \ + name: 'Oid', \ + attribute: Proc.new { |n| n.get_objectid.short_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/referential_networks/edit.html.slim b/app/views/referential_networks/edit.html.slim index dded4b176..a77d2db34 100644 --- a/app/views/referential_networks/edit.html.slim +++ b/app/views/referential_networks/edit.html.slim @@ -1,4 +1,3 @@ - breadcrumb :referential_network, @referential, @network -= title_tag t('networks.edit.title', network: @network.name) - +- page_header_content_for @network = render 'form' diff --git a/app/views/referential_networks/index.html.slim b/app/views/referential_networks/index.html.slim index 57d3e7f1f..d556e7e5e 100644 --- a/app/views/referential_networks/index.html.slim +++ b/app/views/referential_networks/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :referential_networks, @referential -/ PageHeader -= pageheader 'reseau', - t('networks.index.title'), - 'Lorem ipsum dolor sit amet', - '', - (policy(Chouette::Network).create? ? link_to(t('networks.actions.new'), new_referential_network_path(@referential), class: 'btn btn-default') : '') +- if policy(Chouette::Network).create? + - content_for :page_header_actions do + = link_to(t('networks.actions.new'), new_referential_network_path(@referential), class: 'btn btn-default') -/PageContent .page_content .container-fluid - if params[:q].present? or @networks.any? @@ -26,8 +22,8 @@ = table_builder_2 @networks, [ \ TableBuilderHelper::Column.new( \ - name: 'ID Codifligne', \ - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ + name: t('id_codif'), \ + attribute: Proc.new { |n| n.get_objectid.try(:short_id) }, \ sortable: false \ ), TableBuilderHelper::Column.new( \ diff --git a/app/views/referential_networks/new.html.slim b/app/views/referential_networks/new.html.slim index 4a737d9f7..9c2020eb3 100644 --- a/app/views/referential_networks/new.html.slim +++ b/app/views/referential_networks/new.html.slim @@ -1,5 +1,2 @@ - breadcrumb :referential_networks, @referential - -= title_tag t('networks.new.title') - = render 'form' diff --git a/app/views/referential_networks/show.html.slim b/app/views/referential_networks/show.html.slim index eab0cd51a..7de304671 100644 --- a/app/views/referential_networks/show.html.slim +++ b/app/views/referential_networks/show.html.slim @@ -1,11 +1,6 @@ - breadcrumb :referential_network, @referential, @network -/ PageHeader -= pageheader 'reseau', - @network.name, - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@network.updated_at, format: :short)) do - - / Below is secundary actions & optional contents (filters, ...) +- page_header_content_for @network +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @network.action_links.each do |link| @@ -21,4 +16,4 @@ .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { t('id_codif') => @network.try(:objectid).try(:local_id) } + { t('id_codif') => @network.try(:get_objectid).try(:local_id) } diff --git a/app/views/referential_stop_areas/edit.html.slim b/app/views/referential_stop_areas/edit.html.slim index fc7220095..d88230b58 100644 --- a/app/views/referential_stop_areas/edit.html.slim +++ b/app/views/referential_stop_areas/edit.html.slim @@ -1,4 +1,3 @@ - breadcrumb :referential_stop_area, @referential, @stop_area -= title_tag t('stop_areas.edit.title', stop_area: @stop_area.name) - +- page_header_content_for @stop_area = render 'form' diff --git a/app/views/referential_stop_areas/index.html.slim b/app/views/referential_stop_areas/index.html.slim index 718cbb472..ad04fb02e 100644 --- a/app/views/referential_stop_areas/index.html.slim +++ b/app/views/referential_stop_areas/index.html.slim @@ -1,5 +1,4 @@ - breadcrumb :referential_stop_areas, @referential -= title_tag t('stop_areas.index.title') = search_form_for @q, :url => referential_stop_areas_path(@referential), remote: true, :html => {:method => :get, class: "form-inline", :id => "search", role: "form"} do |f| .panel.panel-default diff --git a/app/views/referential_stop_areas/new.html.slim b/app/views/referential_stop_areas/new.html.slim index 87ba9b657..9342b673b 100644 --- a/app/views/referential_stop_areas/new.html.slim +++ b/app/views/referential_stop_areas/new.html.slim @@ -1,4 +1,2 @@ - breadcrumb :referential_stop_areas, @referential -= title_tag t('stop_areas.new.title') - = render 'form' diff --git a/app/views/referential_stop_areas/show.html.slim b/app/views/referential_stop_areas/show.html.slim index b9a1c9899..0470b4654 100644 --- a/app/views/referential_stop_areas/show.html.slim +++ b/app/views/referential_stop_areas/show.html.slim @@ -1,9 +1,6 @@ - breadcrumb :referential_stop_area, @referential, @stop_area -/ PageHeader -= pageheader 'arret', - @stop_area.name, - 'Lorem ipsum dolor sit amet' - +- page_header_content_for @stop_area +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @stop_area.action_links.each do |link| @@ -13,13 +10,12 @@ class: 'btn btn-primary' do = link.content -/ PageContent .page_content .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { 'ID Reflex' => @stop_area.try(:user_objectid), + { t('id_reflex') => @stop_area.try(:user_objectid), 'Activé' => (@stop_area.deleted_at ? t('false') : t('true')), @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment), @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"), diff --git a/app/views/referentials/edit.html.slim b/app/views/referentials/edit.html.slim index 1fac626e6..904dc5439 100644 --- a/app/views/referentials/edit.html.slim +++ b/app/views/referentials/edit.html.slim @@ -1,10 +1,6 @@ -/ PageHeader -= pageheader 'jeux-de-donnees', - t('.title'), - '', - t('last_update', time: l(@referential.updated_at, format: :short)) +- breadcrumb @referential +- page_header_content_for @referential -/ PageContent .page_content .container-fluid .row diff --git a/app/views/referentials/new.html.slim b/app/views/referentials/new.html.slim index f4a7e4707..2bed9f912 100644 --- a/app/views/referentials/new.html.slim +++ b/app/views/referentials/new.html.slim @@ -1,12 +1,3 @@ -/ PageHeader -- if @referential.created_from.present? - = pageheader 'jeux-de-donnees', - t('.duplicated.title') -- else - = pageheader 'jeux-de-donnees', - t('.title') - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/referentials/select_compliance_control_set.html.slim b/app/views/referentials/select_compliance_control_set.html.slim index 2d3f2344c..87a888c0a 100644 --- a/app/views/referentials/select_compliance_control_set.html.slim +++ b/app/views/referentials/select_compliance_control_set.html.slim @@ -1,10 +1,3 @@ -/ PageHeader -- header_params = ['jeux-de-controle', - t('referentials.select_compliance_control_set.title'), - ''] -= pageheader(*header_params) do - -/ PageContent .page_content .container-fluid .row @@ -17,4 +10,4 @@ .col-sm-8.col-xs-7 = select_tag :compliance_control_set, options_from_collection_for_select(@compliance_control_sets, "id", "name"), class: 'select optional form-control' .separator - = button_tag t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'select_compliance_control_set'
\ No newline at end of file + = button_tag t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'select_compliance_control_set' diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim index b03fb9f53..9852fb0a3 100644 --- a/app/views/referentials/show.html.slim +++ b/app/views/referentials/show.html.slim @@ -1,12 +1,10 @@ - breadcrumb @referential -/ PageHeader -= pageheader 'jeux-de-donnees', - @referential.name, - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@referential.updated_at, format: :short)), - ((@referential.archived? || !policy(@referential).edit?) ? '' : link_to(t('actions.edit'), edit_referential_path(@referential), class: 'btn btn-default')) do +- page_header_content_for @referential +- content_for :page_header_actions do + - unless (@referential.archived? || !policy(@referential).edit?) + = link_to(t('actions.edit'), edit_referential_path(@referential), class: 'btn btn-default') - / Below is secondary actions & optional contents (filters, ...) +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - @referential.action_links.each do |link| @@ -19,7 +17,6 @@ class: 'btn btn-primary' do = link.content -/ PageContent .page_content .container-fluid .row @@ -43,7 +40,7 @@ [ \ TableBuilderHelper::Column.new( \ name: t('id_codif'), \ - attribute: Proc.new { |n| n.objectid.local_id }, \ + attribute: Proc.new { |n| n.get_objectid.short_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/routes/edit.html.slim b/app/views/routes/edit.html.slim index a69c5aeff..78f9a2e85 100644 --- a/app/views/routes/edit.html.slim +++ b/app/views/routes/edit.html.slim @@ -1,11 +1,6 @@ - breadcrumb :route, @referential, @route -/ PageHeader -= pageheader 'itineraire', - @route.name, - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@route.updated_at, format: :short)) +- page_header_content_for @route -/ PageContent .page_content .container-fluid .row diff --git a/app/views/routes/new.html.slim b/app/views/routes/new.html.slim index 3a8ceb963..9d5ca2e23 100644 --- a/app/views/routes/new.html.slim +++ b/app/views/routes/new.html.slim @@ -1,10 +1,4 @@ - breadcrumb :referential_line, @referential, @line -/ PageHeader -= pageheader 'itineraire', - t('routes.new.title'), - '' - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/routes/show.html.slim b/app/views/routes/show.html.slim index 1411a5502..3adf3e2f6 100644 --- a/app/views/routes/show.html.slim +++ b/app/views/routes/show.html.slim @@ -1,12 +1,10 @@ - breadcrumb :route, @referential, @route -/ PageHeader -= pageheader 'itineraire', - t('routes.index.title', route: @route.name), - '', - t('last_update', time: l(@route.updated_at, format: :short)), - (policy(@route).edit? ? link_to(t('actions.edit'), edit_referential_line_route_path(@referential, @line, @route), class: 'btn btn-default') : '') do +- page_header_content_for @route +- content_for :page_header_actions do + - if policy(@route).edit? + = link_to(t('actions.edit'), edit_referential_line_route_path(@referential, @line, @route), class: 'btn btn-default') - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - @route.action_links.each do |link| @@ -16,13 +14,12 @@ class: 'btn btn-primary' do = link.content -/ PageContent .page_content .container-fluid .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { t('objectid') => @route.objectid.short_id, + { t('objectid') => @route.get_objectid.short_id, t('activerecord.attributes.route.published_name') => (@route.published_name ? @route.published_name : '-'), @route.human_attribute_name(:wayback) => (@route.wayback ? @route.wayback_text : '-' ), @route.human_attribute_name(:opposite_route) => (@route.opposite_route ? @route.opposite_route.name : '-') } @@ -38,7 +35,7 @@ = table_builder_2 @route_sp, [ \ TableBuilderHelper::Column.new( \ - name: 'ID Reflex', \ + name: t('id_reflex'), \ attribute: Proc.new { |s| s.try(:stop_area).try(:user_objectid) } \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim index c9b9b0c41..e971ee5dd 100644 --- a/app/views/routing_constraint_zones/edit.html.slim +++ b/app/views/routing_constraint_zones/edit.html.slim @@ -1,11 +1,6 @@ - breadcrumb :routing_constraint_zone, @referential, @line, @routing_constraint_zone -/ PageHeader -= pageheader 'itl', - t('.title', routing_constraint_zone: @routing_constraint_zone.name), - '', - t('last_update', time: l(@routing_constraint_zone.updated_at, format: :short)) +- page_header_content_for @routing_constraint_zone -/ PageContent .page_content .container-fluid .row diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim index ddad7723e..7c54fca68 100644 --- a/app/views/routing_constraint_zones/index.html.slim +++ b/app/views/routing_constraint_zones/index.html.slim @@ -1,12 +1,8 @@ - breadcrumb :routing_constraint_zones, @referential, @line -/ PageHeader -= pageheader 'itl', - t('routing_constraint_zones.index.title'), - '', - '', - ((policy(Chouette::RoutingConstraintZone).create? && @referential.organisation == current_organisation) ? link_to(t('actions.new'), new_referential_line_routing_constraint_zone_path(@referential, @line), class: 'btn btn-primary') : '') +- content_for :page_header_actions do + - if (policy(Chouette::RoutingConstraintZone).create? && @referential.organisation == current_organisation) + = link_to(t('actions.new'), new_referential_line_routing_constraint_zone_path(@referential, @line), class: 'btn btn-primary') -/ PageContent .page_content .container-fluid - if params[:q].present? or @routing_constraint_zones.any? @@ -21,7 +17,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'ID', \ - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, \ + attribute: Proc.new { |n| n.get_objectid.local_id }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/routing_constraint_zones/new.html.slim b/app/views/routing_constraint_zones/new.html.slim index d15de13a4..62ecf5e95 100644 --- a/app/views/routing_constraint_zones/new.html.slim +++ b/app/views/routing_constraint_zones/new.html.slim @@ -1,9 +1,5 @@ - breadcrumb :routing_constraint_zones, @referential, @line -/ PageHeader -= pageheader 'itl', - t('.title') -/ PageContent .page_content .container-fluid .row diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim index d0c0619c3..6235ade68 100644 --- a/app/views/routing_constraint_zones/show.html.slim +++ b/app/views/routing_constraint_zones/show.html.slim @@ -1,11 +1,6 @@ - breadcrumb :routing_constraint_zone, @referential, @line, @routing_constraint_zone -/ PageHeader -= pageheader 'itl', - @routing_constraint_zone.name, - '', - t('last_update', time: l(@routing_constraint_zone.updated_at, format: :short)) do - - / Below is secundary actions & optional contents +- page_header_content_for @routing_constraint_zone +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @routing_constraint_zone.action_links.each do |link| @@ -15,7 +10,6 @@ class: 'btn btn-primary' do = link.content -/ PageContent .page_content .container-fluid .row diff --git a/app/views/stop_area_referentials/show.html.slim b/app/views/stop_area_referentials/show.html.slim index 896ce756e..d43333fd9 100644 --- a/app/views/stop_area_referentials/show.html.slim +++ b/app/views/stop_area_referentials/show.html.slim @@ -1,18 +1,15 @@ - breadcrumb :stop_area_referential, @stop_area_referential -/ PageHeader -= pageheader 'synchro-icar', - t('.title'), - 'Lorem ipsum dolor sit amet', - t('last_update', time: l(@stop_area_referential.updated_at, format: :short)), - link_to(t('actions.sync'), sync_stop_area_referential_path(@stop_area_referential), method: :post, class: 'btn btn-default') do +- content_for :page_header_actions do + = link_to(t('actions.sync'), sync_stop_area_referential_path(@stop_area_referential), method: :post, class: 'btn btn-default') +- content_for :page_header_content do .row.mb-md .col-lg-12.text-right = link_to stop_area_referential_stop_areas_path(@stop_area_referential), class: 'btn btn-primary' do = Referential.human_attribute_name(:stop_areas) em.small = " (#{@stop_area_referential.stop_areas.size})" +- page_header_content_for @stop_area_referential -/ PageContent .page_content .container-fluid .row diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index 546143393..20c7c0468 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -1,153 +1,45 @@ -= semantic_form_for [@stop_area_referential, @stop_area] do |form| += simple_form_for [@stop_area_referential, @stop_area], html: {class: 'form-horizontal', id: 'stop_area_form'}, wrapper: :horizontal_form do |f| .row - .container-fluid - - if !manage_itl && @map - = @map.to_html - - = form.inputs do - = form.input :id, as: :hidden - = form.input :name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")} - = form.input :stop_area_type, as: :select, :input_html => { :disabled => !@stop_area.new_record? }, :collection => Chouette::StopArea.area_type.options, :include_blank => false + .col-lg-12 + /- if !manage_itl && @map + - if !manage_itl + /= @map.to_html + = f.input :id, as: :hidden + = f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")} + = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::StopArea.area_type.options, :include_blank => false .location_info h3 = t("stop_areas.stop_area.localisation") - #prefetch label = t('.geolocalize') input.typeahead.form-control.input-lg maxlength="255" type="text" placeholder="#{t('.address')}" - unless @stop_area.projection.blank? or @stop_area.projection_type_label.empty? - = form.input :projection_xy, :label => t("activerecord.attributes.stop_area.projection_xy", :projection => @referential.projection_type_label), :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.projection_xy")} - - = form.input :coordinates, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.coordinates")} - = form.input :street_name - = form.input :country_code, required: format_restriction_for_locales(@referential) == '.hub' - = form.input :zip_code, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.zip_code")} - = form.input :city_name, required: format_restriction_for_locales(@referential) == '.hub', :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.city_name")} - - .stop_areas.stop_area.general_info - h3 = t("stop_areas.stop_area.general") - - = form.inputs do - = form.input :objectid, :required => !@stop_area.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.objectid")} - = form.input :registration_number, required: format_restriction_for_locales(@referential) == '.hub', :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.registration_number")} - = form.input :fare_code, as: :number - = form.input :nearest_topic_name, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.nearest_topic_name")} - = form.input :comment, as: :text, :input_html => { :rows => 5, :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.comment") } - = form.input :time_zone, :include_blank => true - = form.input :url - - .pmr_info - h3 = t("stop_areas.stop_area.accessibility") - = form.inputs do - - if !manage_itl - = form.input :mobility_restricted_suitability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true - = form.input :stairs_availability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true - = form.input :lift_availability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true - - = form.actions do - = form.action :submit, as: :button - = form.action :cancel, as: :link - -javascript: - $(document).ready(function() { - var address_display = function( address ) { - var name = ""; - if ( address.house_number) { - name += address.house_number+" "; - } - name += address.road+", "; - if ( address.suburb) { - name += address.suburb+", "; - } - if ( address.postcode) { - name += address.postcode+" "; - } - if ( address.city) { - name += address.city; - } else if ( address.village) { - name += address.village; - } else if ( address.town) { - name += address.town; - } else if ( address.county ) { - name += address.county; - } else if ( address.country ) { - name += address.country; - } - - - return name; - }; - var filtering = function(list) { - // update map view - removeAddress(); - - var selection = $.grep( list, function(item) { - return (item.type == "house" || item.type == "residential" || - item.type == "tertiary" || item.type == "primary" || - item.type == "secondary") && item.address.road ; - }); - return $.map( selection, function( d) { - var city = ""; - if ( d.address.city) { - city = d.address.city; - } else if ( d.address.town) { - city = d.address.town; - } else if ( d.address.village) { - city = d.address.village; - } - return { postcode: d.address.postcode, - road: d.address.road, - lon: d.lon, lat: d.lat, - suburb: d.address.suburb, - city: city, - postcode: d.address.postcode, - the_key: address_display( d.address)}; - }); - }; - - var addressesEngine = new Bloodhound({ - datumTokenizer: function(d) { - return Bloodhound.tokenizers.whitespace(d.id+" : "+d.road); - }, - queryTokenizer: function(d) { - return Bloodhound.tokenizers.whitespace(d.id+" :: "+d.road); - }, - limit: 10, - remote: { - url: 'http://nominatim.openstreetmap.org/search?q=%QUERY&format=json&addressdetails=1&bounded=1&viewbox='+ - // FIXME #821 - //= @stop_area_referential.viewbox_left_top_right_bottom - filter: filtering, - } - }); - - // kicks off the loading/processing of `local` and `prefetch` - var promise = addressesEngine.initialize(); - - // passing in `null` for the `options` arguments will result in the default - // options being used - $('#prefetch .typeahead').typeahead( - { - hint: true, - highlight: true, - minLength: 1 - }, - { - name: 'addresses', - displayKey: 'the_key', - source: addressesEngine.ttAdapter(), - } - ); - - $('.typeahead').on('typeahead:selected', function($e, datum) { - // update map view - addAddress( datum.lon, datum.lat, datum.road); - // update form fields - <% if @stop_area.new_record? %> - $('input[name="stop_area[street_name]"]').val(datum.road); - $('input[name="stop_area[zip_code]"]').val(datum.postcode); - $('input[name="stop_area[city_name]"]').val(datum.city); - <% end %> - }) - }); + = f.input :projection_xy, :label => t("activerecord.attributes.stop_area.projection_xy", :projection => @referential.projection_type_label), :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.projection_xy")} + + = f.input :coordinates, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.coordinates")}, required: true + = f.input :street_name + /= f.input :country_code, required: format_restriction_for_locales(@referential) == '.hub' + = f.input :zip_code, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.zip_code")} + = f.input :city_name, required: format_restriction_for_locales(@referential) == '.hub', :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.city_name")} + + .stop_areas.stop_area.general_info + h3 = t("stop_areas.stop_area.general") + + = f.input :registration_number, required: format_restriction_for_locales(@referential) == '.hub', :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.registration_number")} + = f.input :fare_code + = f.input :nearest_topic_name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.nearest_topic_name")} + = f.input :comment, as: :text, :input_html => {:rows => 5, :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.comment")} + = f.input :time_zone, :include_blank => true + = f.input :url + + .pmr_info + h3 = t("stop_areas.stop_area.accessibility") + - if !manage_itl + = f.input :mobility_restricted_suitability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true + = f.input :stairs_availability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true + = f.input :lift_availability, as: :select, :collection => [[t("true"), true], [t("false"), false]], :include_blank => true + + .separator + + = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'stop_area_form' diff --git a/app/views/stop_areas/edit.html.slim b/app/views/stop_areas/edit.html.slim index 8005f5a08..4f2b3f4de 100644 --- a/app/views/stop_areas/edit.html.slim +++ b/app/views/stop_areas/edit.html.slim @@ -1,4 +1,8 @@ - breadcrumb :stop_area, @stop_area_referential, @stop_area -= title_tag t('stop_areas.edit.title', stop_area: @stop_area.name ) +- page_header_content_for @stop_area -== render 'form' +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' diff --git a/app/views/stop_areas/index.html.slim b/app/views/stop_areas/index.html.slim index 4e880f7a3..c4d880081 100644 --- a/app/views/stop_areas/index.html.slim +++ b/app/views/stop_areas/index.html.slim @@ -1,18 +1,14 @@ - breadcrumb :stop_areas, @stop_area_referential -/ PageHeader -= pageheader 'arret', - t('stop_areas.index.title'), - '', - '', - (policy(Chouette::StopArea).create? ? link_to(t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), class: 'btn btn-primary') : '') +- content_for :page_header_actions do + - if policy(Chouette::StopArea).create? + = link_to(t('stop_areas.actions.new'), new_stop_area_referential_stop_area_path(@stop_area_referential), class: 'btn btn-primary') -/ PageContent .page_content .container-fluid - if params[:q].present? or @stop_areas.any? .row .col-lg-12 - = render 'filters' + = render 'filters' - if @stop_areas.any? .row @@ -20,8 +16,8 @@ = table_builder_2 @stop_areas, [ \ TableBuilderHelper::Column.new( \ - name: 'ID Reflex', \ - attribute: Proc.new { |n| n.try(:user_objectid) }, \ + name: t('id_reflex'), \ + attribute: Proc.new { |n| n.get_objectid.try(:short_id) }, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/stop_areas/new.html.slim b/app/views/stop_areas/new.html.slim index e0c5b7a61..69d78c533 100644 --- a/app/views/stop_areas/new.html.slim +++ b/app/views/stop_areas/new.html.slim @@ -1,4 +1,7 @@ - breadcrumb :stop_areas, @stop_area_referential -= title_tag t('stop_areas.new.title') -== render 'form' +.page_content + .container-fluid + .row + .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 + = render 'form' diff --git a/app/views/stop_areas/select_parent.html.slim b/app/views/stop_areas/select_parent.html.slim index 1289eafef..e387e83b8 100644 --- a/app/views/stop_areas/select_parent.html.slim +++ b/app/views/stop_areas/select_parent.html.slim @@ -1,5 +1,3 @@ -= title_tag t('stop_areas.select_parent.title', stop_area: @stop_area.name ) - = semantic_form_for [@referential, @stop_area] do |form| div = form.inputs do @@ -10,4 +8,4 @@ = form.action :cancel, as: :link - content_for :sidebar do - ul.actions
\ No newline at end of file + ul.actions diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index bc9cc2ac0..af673bb25 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -1,9 +1,6 @@ - breadcrumb :stop_area, @stop_area_referential, @stop_area -/ PageHeader -= pageheader 'arret', - @stop_area.name, - 'Lorem ipsum dolor sit amet' - +- page_header_content_for @stop_area +- content_for :page_header_content do .row .col-lg-12.text-right.mb-sm - @stop_area.action_links.each do |link| @@ -19,9 +16,9 @@ .row .col-lg-6.col-md-6.col-sm-12.col-xs-12 = definition_list t('metadatas'), - { @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"), + { t('id_reflex') => @stop_area.get_objectid.short_id, + @stop_area.human_attribute_name(:stop_area_type) => t("area_types.label.#{@stop_area.stop_area_type}"), @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number, - t('id_reflex') => @stop_area.user_objectid, 'Coordonnées' => geo_data(@stop_area, @stop_area_referential), @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code, @stop_area.human_attribute_name(:city_name) => @stop_area.city_name, diff --git a/app/views/time_table_combinations/new.html.slim b/app/views/time_table_combinations/new.html.slim index e49a10bc6..f18553081 100644 --- a/app/views/time_table_combinations/new.html.slim +++ b/app/views/time_table_combinations/new.html.slim @@ -1,10 +1,4 @@ -/ PageHeader -= pageheader 'map-marker', - t('time_tables.show.combine_form'), - '', - '' -/ PageContent .page_content .container-fluid .row diff --git a/app/views/time_tables/edit.html.slim b/app/views/time_tables/edit.html.slim index a1ebb2c72..6ad572906 100644 --- a/app/views/time_tables/edit.html.slim +++ b/app/views/time_tables/edit.html.slim @@ -1,11 +1,6 @@ - breadcrumb :time_table, @referential, @time_table -/ PageHeader -= pageheader 'calendrier-application', - @time_table.comment, - '', - '' +- page_header_content_for @time_table -/ PageContent .page_content .container-fluid #periods diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim index b0f4e84c5..b684b0bcb 100644 --- a/app/views/time_tables/index.html.slim +++ b/app/views/time_tables/index.html.slim @@ -1,11 +1,8 @@ - breadcrumb :time_tables, @referential -/ PageHeader -= pageheader 'calendrier-application', - t('time_tables.index.title'), - '', - ((policy(Chouette::TimeTable).create? && @referential.organisation == current_organisation) ? link_to(t('actions.add'), new_referential_time_table_path(@referential), class: 'btn btn-default') : '') +- content_for :page_header_actions do + - if (policy(Chouette::TimeTable).create? && @referential.organisation == current_organisation) + = link_to(t('actions.add'), new_referential_time_table_path(@referential), class: 'btn btn-default') -/ PageContent .page_content .container-fluid .row @@ -19,7 +16,7 @@ [ \ TableBuilderHelper::Column.new( \ name: 'ID', \ - attribute: Proc.new { |n| n.objectid.short_id}, \ + attribute: Proc.new { |n| n.get_objectid.short_id}, \ sortable: false \ ), \ TableBuilderHelper::Column.new( \ diff --git a/app/views/time_tables/new.html.slim b/app/views/time_tables/new.html.slim index c8c2658ba..ddb34e0b7 100644 --- a/app/views/time_tables/new.html.slim +++ b/app/views/time_tables/new.html.slim @@ -1,11 +1,4 @@ - breadcrumb :time_tables, @referential -/ PageHeader -= pageheader 'calendrier-application', - t("time_tables.#{params[:action]}.title"), - '', - '' - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/time_tables/show.html.slim b/app/views/time_tables/show.html.slim index 85de7f8ec..8326a4d05 100644 --- a/app/views/time_tables/show.html.slim +++ b/app/views/time_tables/show.html.slim @@ -1,14 +1,12 @@ - require 'calendar_helper' - breadcrumb :time_table, @referential, @time_table -/ PageHeader +- page_header_content_for @time_table -= pageheader 'calendrier-application', - @time_table.comment, - '', - t('last_update', time: l(@time_table.updated_at, format: :short)), - (policy(@time_table).edit? ? link_to(t('actions.edit'), edit_referential_time_table_path(@referential, @time_table), class: 'btn btn-default') : '') +- content_for :page_header_actions do + - if policy(@time_table).edit? + = link_to(t('actions.edit'), edit_referential_time_table_path(@referential, @time_table), class: 'btn btn-default') - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - @time_table.action_links.each do |link| @@ -18,7 +16,7 @@ class: 'btn btn-primary' do = link.content -/ PageContent + .page_content .container-fluid .row diff --git a/app/views/time_tables/show.rabl b/app/views/time_tables/show.rabl index 53c9daec0..55744bf8c 100644 --- a/app/views/time_tables/show.rabl +++ b/app/views/time_tables/show.rabl @@ -10,7 +10,7 @@ node do |tt| periode_range: month_periode_enum(3), current_periode_range: Date.today.beginning_of_month, color: tt.color ? tt.color : '', - short_id: tt.objectid.parts.try(:third) + short_id: tt.get_objectid.short_id } end diff --git a/app/views/vehicle_journeys/index.html.slim b/app/views/vehicle_journeys/index.html.slim index 2046ecca6..ef9b5a780 100644 --- a/app/views/vehicle_journeys/index.html.slim +++ b/app/views/vehicle_journeys/index.html.slim @@ -1,11 +1,4 @@ - breadcrumb :vehicle_journeys, @referential, @route -/ PageHeader -= pageheader 'horaires-des-courses', - t('vehicle_journeys.index.title', route: @route.name ), - 'Lorem ipsum dolor sit amet', - '' do - -/ PageContent .page_content .container-fluid .row diff --git a/app/views/vehicle_journeys/show.html.slim b/app/views/vehicle_journeys/show.html.slim index 8ff4b188d..c67632864 100644 --- a/app/views/vehicle_journeys/show.html.slim +++ b/app/views/vehicle_journeys/show.html.slim @@ -1,2 +1,3 @@ +- page_header_content_for @vehicle_journey == render 'show_details', vehicle_journey: @vehicle_journey -== render 'show_sidebar'
\ No newline at end of file +== render 'show_sidebar' diff --git a/app/views/vehicle_journeys/show.rabl b/app/views/vehicle_journeys/show.rabl index fce16dfb3..830dee8bd 100644 --- a/app/views/vehicle_journeys/show.rabl +++ b/app/views/vehicle_journeys/show.rabl @@ -4,6 +4,8 @@ object @vehicle_journey attributes attr, :unless => lambda { |m| m.send( attr).nil?} end +node { |vj| {short_id: vj.get_objectid.short_id} } + child(:company) do |company| attributes :id, :objectid, :name end @@ -16,6 +18,7 @@ end child(:journey_pattern) do |journey_pattern| attributes :id, :objectid, :name, :published_name + node(:short_id) {journey_pattern.get_objectid.short_id} end child(:time_tables, :object_root => false) do |time_tables| diff --git a/app/views/workbenches/index.html.slim b/app/views/workbenches/index.html.slim index d35ed8121..14fc79222 100644 --- a/app/views/workbenches/index.html.slim +++ b/app/views/workbenches/index.html.slim @@ -1,8 +1,5 @@ -/ PageHeader -= pageheader 'tableau-de-bord', - t('.title', organisation: current_organisation.name) - / Below is secundary actions & optional contents (filters, ...) +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - if policy(Api::V1::ApiKey).create? diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim index 66eedb68d..22869b2d7 100644 --- a/app/views/workbenches/show.html.slim +++ b/app/views/workbenches/show.html.slim @@ -1,17 +1,12 @@ - breadcrumb @workbench -/ PageHeader -= pageheader 'jeux-de-donnees', - t('referentials.index.title'), - '', - '' do - / Below is secundary actions & optional contents (filters, ...) +- page_header_content_for @workbench +- content_for :page_header_content do .row.mb-sm .col-lg-12.text-right - if policy(Referential).create? = link_to t('actions.import'), workbench_imports_path(@workbench), class: 'btn btn-primary' = link_to t('actions.add'), new_referential_path(workbench_id: @workbench), class: 'btn btn-primary' -/ PageContent .page_content .container-fluid - if params[:q].present? or @wbench_refs.any? diff --git a/bin/bundle b/bin/bundle deleted file mode 100755 index 66e9889e8..000000000 --- a/bin/bundle +++ /dev/null @@ -1,3 +0,0 @@ -#!/usr/bin/env ruby -ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) -load Gem.bin_path('bundler', 'bundle') diff --git a/bin/setup b/bin/setup deleted file mode 100755 index acdb2c138..000000000 --- a/bin/setup +++ /dev/null @@ -1,29 +0,0 @@ -#!/usr/bin/env ruby -require 'pathname' - -# path to your application root. -APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) - -Dir.chdir APP_ROOT do - # This script is a starting point to setup your application. - # Add necessary setup steps to this file: - - puts "== Installing dependencies ==" - system "gem install bundler --conservative" - system "bundle check || bundle install" - - # puts "\n== Copying sample files ==" - # unless File.exist?("config/database.yml") - # system "cp config/database.yml.sample config/database.yml" - # end - - puts "\n== Preparing database ==" - system "bin/rake db:setup" - - puts "\n== Removing old logs and tempfiles ==" - system "rm -f log/*" - system "rm -rf tmp/cache" - - puts "\n== Restarting application server ==" - system "touch tmp/restart.txt" -end diff --git a/config/deploy.rb b/config/deploy.rb index 5fff31a4a..a8d44d3e5 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -55,6 +55,12 @@ namespace :deploy do end after "bundle:install", "deploy:bundle_link" + desc "Run yarn install" + task :yarn do + run "cd #{release_path} && yarn --production --no-progress install" + end + after "bundle:install", "deploy:yarn" + desc "Symlinks shared configs and folders on each release" task :symlink_shared, :except => { :no_release => true } do run "ln -nfs #{shared_path}/config/database.yml #{release_path}/config/" diff --git a/config/initializers/apartment.rb b/config/initializers/apartment.rb index 87bca0b45..69204a5d7 100644 --- a/config/initializers/apartment.rb +++ b/config/initializers/apartment.rb @@ -61,7 +61,7 @@ Apartment.configure do |config| 'RouteControl::OppositeRouteTerminus', 'RouteControl::OppositeRoute', 'RouteControl::StopPointsInJourneyPattern', - 'RouteControl::UnactivatedStopPoints', + 'RouteControl::UnactivatedStopPoint', 'RouteControl::ZDLStopArea', 'RoutingConstraintZoneControl::MaximumLength', 'RoutingConstraintZoneControl::MinimumLength', diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb index d90ea6398..4b9bd320d 100644 --- a/config/initializers/simple_form_bootstrap.rb +++ b/config/initializers/simple_form_bootstrap.rb @@ -132,6 +132,17 @@ SimpleForm.setup do |config| ba.use :hint, wrap_with: { tag: 'p', class: 'help-block small' } end end + + config.wrappers :multi_select_inline, tag: 'div', class: 'form-group', error_class: 'has-error' do |b| + b.use :html5 + b.optional :readonly + b.use :label, class: 'control-label' + b.wrapper tag: 'div', class: 'form-inline col-sm-8 col-xs-7' do |ba| + ba.use :input, class: 'form-control' + ba.use :error, wrap_with: {tag: 'span', class: 'help-block small'} + ba.use :hint, wrap_with: {tag: 'p', class: 'help-block small'} + end + end # Wrappers for forms and inputs using the Bootstrap toolkit. # Check the Bootstrap docs (http://getbootstrap.com) # to learn about the different styles for forms and inputs, diff --git a/config/initializers/stif.rb b/config/initializers/stif.rb index f20429575..eb918131b 100644 --- a/config/initializers/stif.rb +++ b/config/initializers/stif.rb @@ -6,6 +6,7 @@ Rails.application.config.to_prepare do organisation.workbenches.find_or_create_by(name: "Gestion de l'offre") do |workbench| workbench.line_referential = line_referential workbench.stop_area_referential = stop_area_referential + workbench.objectid_format = Workbench.objectid_format.stif_netex Rails.logger.debug "Create Workbench for #{organisation.name}" end @@ -13,5 +14,11 @@ Rails.application.config.to_prepare do end unless Rails.env.test? Rails.application.config.to_prepare do + Organisation.before_validation(on: :create) do |organisation| + organisation.custom_view = "stif" + end +end + +Rails.application.config.to_prepare do Dashboard.default_class = Stif::Dashboard end diff --git a/config/locales/calendars.en.yml b/config/locales/calendars.en.yml index 3b015ff08..0076e5207 100644 --- a/config/locales/calendars.en.yml +++ b/config/locales/calendars.en.yml @@ -42,9 +42,9 @@ en: new: title: Add a new calendar edit: - title: Update calendar %{calendar} + title: Update calendar %{name} show: - title: Calendar %{calendar} + title: Calendar %{name} simple_form: labels: calendar: diff --git a/config/locales/calendars.fr.yml b/config/locales/calendars.fr.yml index 55ec9c620..fddb47d64 100644 --- a/config/locales/calendars.fr.yml +++ b/config/locales/calendars.fr.yml @@ -42,9 +42,9 @@ fr: new: title: Ajouter un calendrier edit: - title: Editer le calendrier %{calendar} + title: Editer le calendrier %{name} show: - title: Calendrier %{calendar} + title: Calendrier %{name} simple_form: labels: calendar: diff --git a/config/locales/companies.en.yml b/config/locales/companies.en.yml index 301f4d68d..a3cd520cb 100644 --- a/config/locales/companies.en.yml +++ b/config/locales/companies.en.yml @@ -9,9 +9,9 @@ en: new: title: "Add a new company" edit: - title: "Update company %{company}" + title: "Update company %{name}" show: - title: "Company %{company}" + title: "Company %{name}" index: title: "Companies" name: "Search by name..." diff --git a/config/locales/companies.fr.yml b/config/locales/companies.fr.yml index 58fcc2ed7..0cf729c35 100644 --- a/config/locales/companies.fr.yml +++ b/config/locales/companies.fr.yml @@ -9,9 +9,9 @@ fr: new: title: "Ajouter un transporteur" edit: - title: "Editer le transporteur %{company}" + title: "Editer le transporteur %{name}" show: - title: "Transporteur %{company}" + title: "Transporteur %{name}" index: title: "Transporteurs" name: "Recherche par nom..." diff --git a/config/locales/compliance_check_sets.en.yml b/config/locales/compliance_check_sets.en.yml index 5aa6f9740..87d9abef0 100644 --- a/config/locales/compliance_check_sets.en.yml +++ b/config/locales/compliance_check_sets.en.yml @@ -7,6 +7,7 @@ en: destroy_confirm: Are you sure you want to delete this control report? filters: name: Specify a control report name... + name_compliance_control_set: Specify a compliance control set name... error_period_filter: End date must be greater than or equal to begin date index: title: Compliance control set @@ -17,6 +18,10 @@ en: search_no_results: No control reports match your search executed: title: Executed control report %{name} + show: + table_state: "%{lines_status} lines imported on %{lines_in_compliance_check_set} in the archive" + table_explanation: "These controls apply to all imported data and condition the construction of your organization's offer." + metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" activerecord: attributes: compliance_check_set: @@ -26,6 +31,11 @@ en: assigned_to: Assigned to compliance_control_set: Compliance control set name: Name + compliance_check_resources: + name: Name of the line + status: Status + metrics: Test results + download: Download models: compliance_check_block: one: compliance_control_set diff --git a/config/locales/compliance_check_sets.fr.yml b/config/locales/compliance_check_sets.fr.yml index 8ad5af904..84db8b934 100644 --- a/config/locales/compliance_check_sets.fr.yml +++ b/config/locales/compliance_check_sets.fr.yml @@ -7,12 +7,17 @@ fr: destroy_confirm: Etes vous sûr de supprimer ce rapport de contrôle ? filters: name: Indiquez un nom d'un objet associé... + name_compliance_control_set: Indiquez le nom d'un jeu de contrôle error_period_filter: La date de fin doit être supérieure ou égale à la date de début0 index: title: "Liste des jeux de contrôles" search_no_results: Aucun rapport de contrôle ne correspond à votre recherche executed: title: Jeu de contrôles exécutés %{name} + show: + table_state: "%{lines_status} lignes importées sur %{lines_in_compliance_check_set} présentes dans l'archive" + table_explanation: Ces contrôles s’appliquent pour toutes les données importées et conditionnent la construction de l’offre de votre organisation + metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" activerecord: attributes: compliance_check_set: @@ -22,6 +27,11 @@ fr: assigned_to: Affectation compliance_control_set: jeu de contrôle name: Nom + compliance_check_resource: + name: Nom de la ligne + status: État + metrics: Résultat des tests + download: Télécharger models: compliance_check_block: zero: "Groupe de contrôle" diff --git a/config/locales/compliance_controls.en.yml b/config/locales/compliance_controls.en.yml index 9615bbf69..0c476a46d 100644 --- a/config/locales/compliance_controls.en.yml +++ b/config/locales/compliance_controls.en.yml @@ -160,7 +160,7 @@ en: one: "A route must have at least 2 stop points" route_control/omnibus_journey_pattern: one: "A journey pattern of a route should connect all of a route's stop points" - route_control/unactivated_stop_points: + route_control/unactivated_stop_point: one: "Route and unactivated stop point" route_control/stop_points_in_journey_pattern: one: "The stop points of a route must be used by at least one journey pattern" diff --git a/config/locales/compliance_controls.fr.yml b/config/locales/compliance_controls.fr.yml index e23f879f5..70227b01f 100644 --- a/config/locales/compliance_controls.fr.yml +++ b/config/locales/compliance_controls.fr.yml @@ -106,7 +106,7 @@ fr: 3_vehiclejourney_5_1: "La course %{source_objectid} a un horaire d'arrivé %{error_value} supérieur à l'horaire de départ %{reference_value} à l'arrêt %{target_0_label} (%{target_0_objectid})" 3_vehiclejourney_5_2: "La course %{source_objectid} a un horaire de départ %{error_value} à l'arrêt %{target_0_label} (%{target_0_objectid}) supérieur à l'horaire d'arrivé % à l'arrêt suivant" description: "L'horaire d'arrivée à un arrêt doit être antérieur à l'horaire de départ de cet arrêt ET les horaires de départ aux arrêts doivent être dans l'ordre chronologique croissant." - routing_constraint_zone_control/vehicle_journey_at_stops: + routing_constraint_zone_control/unactivated_stop_point: messages: 3_routingconstraint_1: "L'ITL %{source_objectid} référence un arrêt (ZDEp) désactivé %{target_0_label} (%{target_0_objectid})" description: "Les arrêts d'une ITL ne doivent pas être désactivés" @@ -159,7 +159,7 @@ fr: one: "Un itinéraire doit contenir au moins 2 arrêts" route_control/omnibus_journey_pattern: one: "Existence d’une mission passant par tous les arrêts de l'itinéraire" - route_control/unactivated_stop_points: + route_control/unactivated_stop_point: one: "Itinéraire & arrêt désactivé" route_control/stop_points_in_journey_pattern: one: "Utilisation des arrêts par les missions" diff --git a/config/locales/en.yml b/config/locales/en.yml index b65484bc2..4834ceef4 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -48,6 +48,8 @@ en: format: "%{message}" last_update: 'Last update on<br>%{time}' + whodunnit: 'By %{author}' + default_whodunnit: 'web service' last_sync: 'Last sync on %{time}' validity_range: '%{debut} > %{end}' bounding_dates: '%{debut} > %{end}' diff --git a/config/locales/enumerize.en.yml b/config/locales/enumerize.en.yml index f5e51171b..bfd7b8c22 100644 --- a/config/locales/enumerize.en.yml +++ b/config/locales/enumerize.en.yml @@ -244,3 +244,15 @@ en: streetCableCar: 'Street cable car' allFunicularServices: 'All funicular services' undefinedFunicular: 'Undefined funicular' + source_type_name: + name: "Source types" + public_and_private_utilities: "Public and private utilities" + road_authorities: "Road authorities" + transit_operator: "Transit operator" + public_transport: "Public transport" + passenger_transport_coordinating_authority: "Passenger transport coordinating authority" + travel_information_service_provider: "Travel information service provider" + travel_agency: "Travel_agency" + individual_subject_of_travel_itinerary: "Individual subject of travel itinerary" + other_information: "Other information" + diff --git a/config/locales/enumerize.fr.yml b/config/locales/enumerize.fr.yml index a5845971b..b2eab665d 100644 --- a/config/locales/enumerize.fr.yml +++ b/config/locales/enumerize.fr.yml @@ -242,3 +242,14 @@ fr: streetCableCar: 'Tramway (2)' allFunicularServices: 'Tous services de funiculaire' undefinedFunicular: 'Funiculaire non défini' + source_type_name: + name: "Type de source" + public_and_private_utilities: "Service public ou privé" + road_authorities: "Autorité routière" + transit_operator: "Exploitant de transport public" + public_transport: "Transport public" + passenger_transport_coordinating_authority: "Autorité organisatrice de transport public" + travel_information_service_provider: "Opérateur de voyage (voyagiste/tour operator ...)" + travel_agency: "Agence de voyage" + individual_subject_of_travel_itinerary: "Voyageur individuel" + other_information: "Autre source d'information" diff --git a/config/locales/fr.yml b/config/locales/fr.yml index 49e41a570..24482166c 100644 --- a/config/locales/fr.yml +++ b/config/locales/fr.yml @@ -48,6 +48,8 @@ fr: format: "%{message}" last_update: 'Dernière mise à jour<br>le %{time}' + whodunnit: 'Par %{author}' + default_whodunnit: 'web service' last_sync: 'Dernière mise à jour le %{time}' validity_range: '%{debut} > %{end}' bounding_dates: '%{debut} > %{end}' diff --git a/config/locales/import_messages.en.yml b/config/locales/import_messages.en.yml index bf6b45020..42d180abd 100644 --- a/config/locales/import_messages.en.yml +++ b/config/locales/import_messages.en.yml @@ -3,7 +3,7 @@ en: compliance_check_messages: corrupt_zip_file: "The zip file %{source_filename} is corrupted and cannot be read" inconsistent_zip_file: "The zip file %{source_filename} contains unexpected directories: %{spurious_dirs}, which are ignored" - referential_creation: "Le référentiel n'a pas pu être créé car un référentiel existe déjà sur les même périodes et lignes" + referential_creation: "Le référentiel n'a pas pu être créé car un référentiel existe déjà sur les mêmes périodes et lignes" 1_netexstif_2: "Le fichier %{source_filename} ne respecte pas la syntaxe XML ou la XSD NeTEx : erreur '%{error_value}' rencontré" 1_netexstif_5: "%{source_filename}-Ligne %{source_line_number}-Colonne %{source_column_number} : l'objet %{source_label} d'identifiant %{source_objectid} a une date de mise à jour dans le futur" 2_netexstif_1_1: "Le fichier commun.xml ne contient pas de frame nommée NETEX_COMMUN" diff --git a/config/locales/import_messages.fr.yml b/config/locales/import_messages.fr.yml index 7d3bbf23b..e29da05f9 100644 --- a/config/locales/import_messages.fr.yml +++ b/config/locales/import_messages.fr.yml @@ -3,7 +3,7 @@ fr: compliance_check_messages: corrupt_zip_file: "Le fichier zip %{source_filename} est corrompu, et ne peut être lu" inconsistent_zip_file: "Le fichier zip %{source_filename} contient des repertoires non prévus : %{spurious_dirs} qui seront ignorés" - referential_creation: "Le référentiel n'a pas pu être créé car un référentiel existe déjà sur les même périodes et lignes" + referential_creation: "Le référentiel n'a pas pu être créé car un référentiel existe déjà sur les mêmes périodes et lignes" 1_netexstif_2: "Le fichier %{source_filename} ne respecte pas la syntaxe XML ou la XSD NeTEx : erreur '%{error_value}' rencontré" 1_netexstif_5: "%{source_filename}-Ligne %{source_line_number}-Colonne %{source_column_number} : l'objet %{source_label} d'identifiant %{source_objectid} a une date de mise à jour dans le futur" 2_netexstif_1_1: "Le fichier commun.xml ne contient pas de frame nommée NETEX_COMMUN" diff --git a/config/locales/import_resources.en.yml b/config/locales/import_resources.en.yml index d98b3eacf..5f0f3213e 100644 --- a/config/locales/import_resources.en.yml +++ b/config/locales/import_resources.en.yml @@ -2,7 +2,7 @@ en: import_resources: index: title: "NeTEx conformity" - table_state: "%{lines_imported} lines imported on %{lines_in_zipfile} presents in zipfile" + table_state: "%{lines_imported} line(s) imported on %{lines_in_zipfile} presents in zipfile" table_title: "Satus of anlyzed files" table_explanation: "When calendriers.xml and/or commun.xml are not imported, then all lines file are not processed." metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" diff --git a/config/locales/import_resources.fr.yml b/config/locales/import_resources.fr.yml index 86c8d8e73..a271ae1ca 100644 --- a/config/locales/import_resources.fr.yml +++ b/config/locales/import_resources.fr.yml @@ -2,7 +2,7 @@ fr: import_resources: index: title: "Rapport de conformité NeTEx" - table_state: "%{lines_imported} lignes importées sur %{lines_in_zipfile} présentes dans l'archive" + table_state: "%{lines_imported} ligne(s) importée(s) sur %{lines_in_zipfile} présente(s) dans l'archive" table_title: "Etat des fichiers analysés" table_explanation: "Dans le cas ou le(s) fichiers calendriers.xml et/ou commun.xml sont dans un état non importé, alors tous les fichiers lignes sont automatiquement dans un état non traité." metrics: "%{ok_count} ok, %{error_count} errors, %{warning_count} warnings, %{uncheck_count} n/a" diff --git a/config/locales/line_referentials.en.yml b/config/locales/line_referentials.en.yml index c6e498b50..5663ed691 100644 --- a/config/locales/line_referentials.en.yml +++ b/config/locales/line_referentials.en.yml @@ -5,7 +5,7 @@ en: sync: "Launch a new codifligne synchronization" cancel_sync: "Cancel codifligne synchronization" edit: - title: "Edit %{line_referential} referential" + title: "Edit %{name} referential" show: title: "iLICO synchronization" synchronized: Synchronized diff --git a/config/locales/line_referentials.fr.yml b/config/locales/line_referentials.fr.yml index 1711fdf9c..630a3e170 100644 --- a/config/locales/line_referentials.fr.yml +++ b/config/locales/line_referentials.fr.yml @@ -5,7 +5,7 @@ fr: sync: "Lancer une synchronisation Codifligne" cancel_sync: "Annuler la synchronisation Codifligne" edit: - title: "Editer le référentiel %{line_referential}" + title: "Editer le référentiel %{name}" show: title: 'Synchronisation iLICO' synchronized: Synchronisé diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml index 15e08290d..a69c3b0ba 100644 --- a/config/locales/lines.en.yml +++ b/config/locales/lines.en.yml @@ -18,9 +18,9 @@ en: new: title: "Add a new line" edit: - title: "Update line %{line}" + title: "Update line %{name}" show: - title: "Line %{line}" + title: "Line %{name}" routes: title: "Routes list" group_of_lines: "Groups of lines" @@ -62,10 +62,10 @@ en: attributes: line: id: "ID" - network: "Network" + network_id: "Network" networks: name: "Network" - company: "Company" + company_id: "Company" companies: name: "Company" registration_number: "Registration number" diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml index c459eb51b..160cc4ab4 100644 --- a/config/locales/lines.fr.yml +++ b/config/locales/lines.fr.yml @@ -18,9 +18,9 @@ fr: new: title: "Ajouter une ligne" edit: - title: "Editer la ligne %{line}" + title: "Editer la ligne %{name}" show: - title: "Ligne %{line}" + title: "Ligne %{name}" routes: title: "Liste des Itinéraires" itineraries: "Liste des séquences d'arrêts de la ligne" @@ -63,10 +63,10 @@ fr: attributes: line: id: "ID" - network: "Réseau" + network_id: "Réseau" networks: name: "Réseau" - company: "Transporteur principal" + company_id: "Transporteur principal" companies: name: "Transporteur principal" registration_number: "Nom court" diff --git a/config/locales/networks.en.yml b/config/locales/networks.en.yml index 86be535e4..94a8d9df0 100644 --- a/config/locales/networks.en.yml +++ b/config/locales/networks.en.yml @@ -9,7 +9,7 @@ en: new: title: "Add a new network" edit: - title: "Update network %{network}" + title: "Update network %{name}" show: title: "Network" index: diff --git a/config/locales/networks.fr.yml b/config/locales/networks.fr.yml index 30d061968..48c32e7c1 100644 --- a/config/locales/networks.fr.yml +++ b/config/locales/networks.fr.yml @@ -9,9 +9,9 @@ fr: new: title: "Ajouter un réseau" edit: - title: "Editer le réseau %{network}" + title: "Editer le réseau %{name}" show: - title: "Réseau %{network}" + title: "Réseau %{name}" index: title: "Réseaux" name: "Recherche par nom..." diff --git a/config/locales/routes.en.yml b/config/locales/routes.en.yml index ba4f76daa..d82ba98dd 100644 --- a/config/locales/routes.en.yml +++ b/config/locales/routes.en.yml @@ -16,7 +16,7 @@ en: new: title: "Add a new route" edit: - title: "Update route %{route}" + title: "Update route %{name}" select2: placeholder: "Select a stop point..." map: @@ -37,7 +37,7 @@ en: normal: Normal alighting forbidden: Forbidden alighting show: - title: "Route %{route}" + title: "Route %{name}" stop_points: "Stop point on route list" stop_areas: title: "Stop area list" @@ -45,7 +45,7 @@ en: no_opposite_route: "No reversed route associated" undefined: "Undefined" index: - title: "Routes %{route}" + title: "Routes" selection: "Selection" selection_all: "All" edit_boarding_alighting: diff --git a/config/locales/routes.fr.yml b/config/locales/routes.fr.yml index 3bcc33320..457345ae8 100644 --- a/config/locales/routes.fr.yml +++ b/config/locales/routes.fr.yml @@ -16,7 +16,7 @@ fr: new: title: "Ajouter un itinéraire" edit: - title: "Editer l'itinéraire %{route}" + title: "Editer l'itinéraire %{name}" select2: placeholder: "Sélectionnez un arrêt existant..." map: @@ -37,7 +37,7 @@ fr: normal: Descente autorisée forbidden: Descente interdite show: - title: "Itinéraire %{route} de la ligne %{line}" + title: "Itinéraire %{name}" stop_points: "Liste des arrêts de l'itinéraire" stop_areas: title: "Liste des arrêts" @@ -45,7 +45,7 @@ fr: no_opposite_route: "Aucun itinéraire associé" undefined: "Non défini" index: - title: "Itinéraire %{route}" + title: "Itinéraire" selection: "Sélection" selection_all: "Tous" edit_boarding_alighting: diff --git a/config/locales/routing_constraint_zones.en.yml b/config/locales/routing_constraint_zones.en.yml index cc0a15e0c..34a10ac67 100644 --- a/config/locales/routing_constraint_zones.en.yml +++ b/config/locales/routing_constraint_zones.en.yml @@ -31,8 +31,8 @@ en: new: title: Add a new routings constraint zone edit: - title: "Update routing constraint zone %{routing_constraint_zone}" + title: "Update routing constraint zone %{name}" show: - title: "Routing constraint zone %{routing_constraint_zone}" + title: "Routing constraint zone %{name}" index: title: "Interdictions of local trafficous" diff --git a/config/locales/routing_constraint_zones.fr.yml b/config/locales/routing_constraint_zones.fr.yml index 10c6d37f7..80bbad8cf 100644 --- a/config/locales/routing_constraint_zones.fr.yml +++ b/config/locales/routing_constraint_zones.fr.yml @@ -31,8 +31,8 @@ fr: new: title: Créer une ITL edit: - title: "Editer l'ITL : %{routing_constraint_zone}" + title: "Editer l'ITL : %{name}" show: - title: "Zone de contrainte %{routing_constraint_zone}" + title: "Zone de contrainte %{name}" index: title: "Interdictions de trafic local" diff --git a/config/locales/source_types.en.yml b/config/locales/source_types.en.yml deleted file mode 100644 index 1cea5ed2c..000000000 --- a/config/locales/source_types.en.yml +++ /dev/null @@ -1,13 +0,0 @@ -en: - source_types: - name: "Source type" - label: - public_and_private_utilities: "public and private utilities" - road_authorities: "road authorities" - transit_operator: "transit operator" - public_transport: "public transport" - passenger_transport_coordinating_authority: "passenger transport coordinating authority" - travel_information_service_provider: "travel information service provider" - travel_agency: "travel_agency" - individual_subject_of_travel_itinerary: "individual subject of travel itinerary" - other_information: "other information" diff --git a/config/locales/source_types.fr.yml b/config/locales/source_types.fr.yml deleted file mode 100644 index 6979a14b7..000000000 --- a/config/locales/source_types.fr.yml +++ /dev/null @@ -1,13 +0,0 @@ -fr: - source_types: - name: "Type de source" - label: - public_and_private_utilities: "Service public ou privé" - road_authorities: "Autorité routière" - transit_operator: "Exploitant de transport public" - public_transport: "Transport public" - passenger_transport_coordinating_authority: "Autorité organisatrice de transport public" - travel_information_service_provider: "Opérateur de voyage (voyagiste/tour operator ...)" - travel_agency: "Agence de voyage" - individual_subject_of_travel_itinerary: "Voyageur individuel" - other_information: "Autre source d'information" diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml index 216516e5b..bf4dd832f 100644 --- a/config/locales/stop_areas.fr.yml +++ b/config/locales/stop_areas.fr.yml @@ -44,9 +44,9 @@ fr: address: "246 Boulevard Saint-Germain, 75007 Paris" geolocalize: "Géolocalisez " edit: - title: "Editer l'arrêt %{stop_area}" + title: "Editer l'arrêt %{name}" show: - title: "Arrêt %{stop_area}" + title: "Arrêt %{name}" geographic_data: "Données géographiques" no_geographic_data: "Aucune" itl_managment: "Gestion des liens de l'ITL" diff --git a/db/migrate/20171001100320_add_custom_view_to_organisations.rb b/db/migrate/20171001100320_add_custom_view_to_organisations.rb new file mode 100644 index 000000000..bd8da50fc --- /dev/null +++ b/db/migrate/20171001100320_add_custom_view_to_organisations.rb @@ -0,0 +1,5 @@ +class AddCustomViewToOrganisations < ActiveRecord::Migration + def change + add_column :organisations, :custom_view, :string + end +end diff --git a/db/migrate/20171001100642_stif_define_custom_view_for_organisations.rb b/db/migrate/20171001100642_stif_define_custom_view_for_organisations.rb new file mode 100644 index 000000000..304c90a1a --- /dev/null +++ b/db/migrate/20171001100642_stif_define_custom_view_for_organisations.rb @@ -0,0 +1,5 @@ +class StifDefineCustomViewForOrganisations < ActiveRecord::Migration + def change + Organisation.update_all custom_view: "stif" + end +end diff --git a/db/migrate/20171109100955_add_object_id_format_to_workbenches.rb b/db/migrate/20171109100955_add_object_id_format_to_workbenches.rb new file mode 100644 index 000000000..0e5e57643 --- /dev/null +++ b/db/migrate/20171109100955_add_object_id_format_to_workbenches.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToWorkbenches < ActiveRecord::Migration + def change + add_column :workbenches, :objectid_format, :string + end +end diff --git a/db/migrate/20171109101523_add_object_id_format_to_referential.rb b/db/migrate/20171109101523_add_object_id_format_to_referential.rb new file mode 100644 index 000000000..fed630b75 --- /dev/null +++ b/db/migrate/20171109101523_add_object_id_format_to_referential.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToReferential < ActiveRecord::Migration + def change + add_column :referentials, :objectid_format, :string + end +end diff --git a/db/migrate/20171109101545_add_object_id_format_to_line_referential.rb b/db/migrate/20171109101545_add_object_id_format_to_line_referential.rb new file mode 100644 index 000000000..5d2fc9f4f --- /dev/null +++ b/db/migrate/20171109101545_add_object_id_format_to_line_referential.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToLineReferential < ActiveRecord::Migration + def change + add_column :line_referentials, :objectid_format, :string + end +end diff --git a/db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb b/db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb new file mode 100644 index 000000000..ffa77e2ed --- /dev/null +++ b/db/migrate/20171109101605_add_object_id_format_to_stop_area_referential.rb @@ -0,0 +1,5 @@ +class AddObjectIdFormatToStopAreaReferential < ActiveRecord::Migration + def change + add_column :stop_area_referentials, :objectid_format, :string + end +end diff --git a/db/migrate/20171121142536_create_versions.rb b/db/migrate/20171121142536_create_versions.rb new file mode 100644 index 000000000..ff794f9e1 --- /dev/null +++ b/db/migrate/20171121142536_create_versions.rb @@ -0,0 +1,34 @@ +class CreateVersions < ActiveRecord::Migration + + # The largest text column available in all supported RDBMS is + # 1024^3 - 1 bytes, roughly one gibibyte. We specify a size + # so that MySQL will use `longtext` instead of `text`. Otherwise, + # when serializing very large objects, `text` might not be big enough. + TEXT_BYTES = 1_073_741_823 + + def change + create_table :versions do |t| + t.string :item_type, :null => false + t.integer :item_id, :null => false + t.string :event, :null => false + t.string :whodunnit + t.text :object, :limit => TEXT_BYTES + + # Known issue in MySQL: fractional second precision + # ------------------------------------------------- + # + # MySQL timestamp columns do not support fractional seconds unless + # defined with "fractional seconds precision". MySQL users should manually + # add fractional seconds precision to this migration, specifically, to + # the `created_at` column. + # (https://dev.mysql.com/doc/refman/5.6/en/fractional-seconds.html) + # + # MySQL users should also upgrade to rails 4.2, which is the first + # version of ActiveRecord with support for fractional seconds in MySQL. + # (https://github.com/rails/rails/pull/14359) + # + t.datetime :created_at + end + add_index :versions, [:item_type, :item_id] + end +end diff --git a/db/migrate/20171121153506_remove_creator_id.rb b/db/migrate/20171121153506_remove_creator_id.rb new file mode 100644 index 000000000..520941841 --- /dev/null +++ b/db/migrate/20171121153506_remove_creator_id.rb @@ -0,0 +1,11 @@ +class RemoveCreatorId < ActiveRecord::Migration + def change + [ + 'companies', 'connection_links', 'facilities', 'group_of_lines', + 'journey_patterns', 'lines', 'networks', 'pt_links', 'routes', 'routing_constraint_zones', + 'stop_areas', 'stop_points', 'time_tables', 'timebands', 'vehicle_journeys', 'access_links', 'access_points' + ].each do |table_name| + remove_column table_name, :creator_id, :string + end + end +end diff --git a/db/migrate/20171121163631_remove_creator_from_compliance_check_sets.rb b/db/migrate/20171121163631_remove_creator_from_compliance_check_sets.rb new file mode 100644 index 000000000..0798b2040 --- /dev/null +++ b/db/migrate/20171121163631_remove_creator_from_compliance_check_sets.rb @@ -0,0 +1,5 @@ +class RemoveCreatorFromComplianceCheckSets < ActiveRecord::Migration + def change + remove_column :compliance_check_sets, :creator, :string + end +end diff --git a/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb b/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb new file mode 100644 index 000000000..c85a63b6e --- /dev/null +++ b/db/migrate/20171123110204_update_objectid_format_value_to_referentials.rb @@ -0,0 +1,14 @@ +class UpdateObjectidFormatValueToReferentials < ActiveRecord::Migration + # Migration in the context of the STIF + # Not a definitive choice since it cannot be used for Chouette + def up + Workbench.update_all(objectid_format: 'stif_netex') + Referential.update_all(objectid_format: 'stif_netex') + LineReferential.update_all(objectid_format: 'stif_codifligne') + StopAreaReferential.update_all(objectid_format: 'stif_reflex') + end + + def down + raise ActiveRecord::IrreversibleMigration + end +end diff --git a/db/migrate/20171128112629_delete_referential_foreign_key_for_compliance_check_set.rb b/db/migrate/20171128112629_delete_referential_foreign_key_for_compliance_check_set.rb new file mode 100644 index 000000000..724bdbb61 --- /dev/null +++ b/db/migrate/20171128112629_delete_referential_foreign_key_for_compliance_check_set.rb @@ -0,0 +1,9 @@ +class DeleteReferentialForeignKeyForComplianceCheckSet < ActiveRecord::Migration + def up + remove_foreign_key :compliance_check_sets, :referentials + end + + def down + add_foreign_key :compliance_check_sets, :referentials + end +end diff --git a/db/migrate/20171130172926_delete_compliance_control_set_foreign_key_for_compliance_check_set.rb b/db/migrate/20171130172926_delete_compliance_control_set_foreign_key_for_compliance_check_set.rb new file mode 100644 index 000000000..ea94a01c1 --- /dev/null +++ b/db/migrate/20171130172926_delete_compliance_control_set_foreign_key_for_compliance_check_set.rb @@ -0,0 +1,10 @@ +class DeleteComplianceControlSetForeignKeyForComplianceCheckSet < ActiveRecord::Migration + + def up + remove_foreign_key :compliance_check_sets, :compliance_control_sets + end + + def down + add_foreign_key :compliance_check_sets, :compliance_control_sets + end +end diff --git a/db/migrate/20171130180144_change_item_id_in_versions_to_bigint.rb b/db/migrate/20171130180144_change_item_id_in_versions_to_bigint.rb new file mode 100644 index 000000000..b1e6ca0a6 --- /dev/null +++ b/db/migrate/20171130180144_change_item_id_in_versions_to_bigint.rb @@ -0,0 +1,8 @@ +class ChangeItemIdInVersionsToBigint < ActiveRecord::Migration + def up + change_column :versions, :item_id, :integer, limit: 8, null: false + end + def down + change_column :versions, :item_id, :integer, null: false + end +end diff --git a/db/schema.rb b/db/schema.rb index 21aa73cd8..4650d8812 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20171114102438) do +ActiveRecord::Schema.define(version: 20171128112629) do # These are extensions that must be enabled in order to support this database enable_extension "plpgsql" @@ -23,7 +23,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "stop_area_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.decimal "link_distance", precision: 19, scale: 2 @@ -46,7 +45,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do create_table "access_points", id: :bigserial, force: :cascade do |t| t.string "objectid" t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.decimal "longitude", precision: 19, scale: 16 @@ -123,7 +121,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do create_table "companies", id: :bigserial, force: :cascade do |t| t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "short_name" t.string "organizational_unit" @@ -188,7 +185,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "referential_id", limit: 8 t.integer "compliance_control_set_id", limit: 8 t.integer "workbench_id", limit: 8 - t.string "creator" t.string "status" t.integer "parent_id", limit: 8 t.string "parent_type" @@ -265,7 +261,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "arrival_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.decimal "link_distance", precision: 19, scale: 2 @@ -284,6 +279,22 @@ ActiveRecord::Schema.define(version: 20171114102438) do add_index "connection_links", ["objectid"], name: "connection_links_objectid_key", unique: true, using: :btree + create_table "delayed_jobs", id: :bigserial, force: :cascade do |t| + t.integer "priority", default: 0 + t.integer "attempts", default: 0 + t.text "handler" + t.text "last_error" + t.datetime "run_at" + t.datetime "locked_at" + t.datetime "failed_at" + t.string "locked_by", limit: 255 + t.string "queue", limit: 255 + t.datetime "created_at" + t.datetime "updated_at" + end + + add_index "delayed_jobs", ["priority", "run_at"], name: "delayed_jobs_priority", using: :btree + create_table "exports", id: :bigserial, force: :cascade do |t| t.integer "referential_id", limit: 8 t.string "status" @@ -305,7 +316,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.string "objectid", null: false t.integer "object_version", limit: 8 t.datetime "creation_time" - t.string "creator_id" t.string "name" t.string "comment" t.string "description" @@ -347,7 +357,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do create_table "group_of_lines", id: :bigserial, force: :cascade do |t| t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.string "registration_number" @@ -405,12 +414,12 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.datetime "started_at" t.datetime "ended_at" t.string "token_download" - t.string "type" + t.string "type", limit: 255 t.integer "parent_id", limit: 8 t.string "parent_type" + t.datetime "notified_parent_at" t.integer "current_step", default: 0 t.integer "total_steps", default: 0 - t.datetime "notified_parent_at" t.string "creator" end @@ -435,7 +444,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "route_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.string "registration_number" @@ -500,7 +508,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "company_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "number" t.string "published_name" @@ -532,7 +539,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do create_table "networks", id: :bigserial, force: :cascade do |t| t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.date "version_date" t.string "description" t.string "name" @@ -551,6 +557,11 @@ ActiveRecord::Schema.define(version: 20171114102438) do add_index "networks", ["objectid"], name: "networks_objectid_key", unique: true, using: :btree add_index "networks", ["registration_number"], name: "networks_registration_number_key", using: :btree + create_table "object_id_factories", id: :bigserial, force: :cascade do |t| + t.datetime "created_at", null: false + t.datetime "updated_at", null: false + end + create_table "organisations", id: :bigserial, force: :cascade do |t| t.string "name" t.datetime "created_at" @@ -559,6 +570,7 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.string "code" t.datetime "synced_at" t.hstore "sso_attributes" + t.string "custom_view" end add_index "organisations", ["code"], name: "index_organisations_on_code", unique: true, using: :btree @@ -569,7 +581,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "route_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.decimal "link_distance", precision: 19, scale: 2 @@ -646,7 +657,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "line_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.integer "opposite_route_id", limit: 8 @@ -669,7 +679,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.datetime "updated_at" t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.integer "route_id", limit: 8 t.integer "stop_point_ids", limit: 8, array: true t.string "checksum" @@ -719,17 +728,16 @@ ActiveRecord::Schema.define(version: 20171114102438) do create_table "stop_areas", id: :bigserial, force: :cascade do |t| t.integer "parent_id", limit: 8 - t.string "objectid", null: false + t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.string "comment" t.string "area_type" t.string "registration_number" t.string "nearest_topic_name" t.integer "fare_code" - t.decimal "longitude", precision: 19, scale: 16 - t.decimal "latitude", precision: 19, scale: 16 + t.decimal "longitude", precision: 19, scale: 16 + t.decimal "latitude", precision: 19, scale: 16 t.string "long_lat_type" t.string "country_code" t.string "street_name" @@ -747,7 +755,7 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.datetime "deleted_at" t.datetime "created_at" t.datetime "updated_at" - t.string "stif_type" + t.string "stif_type", limit: 255 end add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree @@ -765,7 +773,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "stop_area_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.integer "position" t.string "for_boarding" t.string "for_alighting" @@ -818,18 +825,17 @@ ActiveRecord::Schema.define(version: 20171114102438) do add_index "time_table_periods", ["time_table_id"], name: "index_time_table_periods_on_time_table_id", using: :btree create_table "time_tables", id: :bigserial, force: :cascade do |t| - t.string "objectid", null: false - t.integer "object_version", limit: 8, default: 1 - t.string "creator_id" + t.string "objectid", null: false + t.integer "object_version", limit: 8, default: 1 t.string "version" t.string "comment" - t.integer "int_day_types", default: 0 + t.integer "int_day_types", default: 0 t.date "start_date" t.date "end_date" t.integer "calendar_id", limit: 8 t.datetime "created_at" t.datetime "updated_at" - t.string "color" + t.string "color", limit: 255 t.integer "created_from_id", limit: 8 t.string "checksum" t.text "checksum_source" @@ -851,7 +857,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do create_table "timebands", id: :bigserial, force: :cascade do |t| t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "name" t.time "start_time", null: false t.time "end_time", null: false @@ -923,7 +928,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do t.integer "company_id", limit: 8 t.string "objectid", null: false t.integer "object_version", limit: 8 - t.string "creator_id" t.string "comment" t.string "status_value" t.string "transport_mode" @@ -945,6 +949,17 @@ ActiveRecord::Schema.define(version: 20171114102438) do add_index "vehicle_journeys", ["objectid"], name: "vehicle_journeys_objectid_key", unique: true, using: :btree add_index "vehicle_journeys", ["route_id"], name: "index_vehicle_journeys_on_route_id", using: :btree + create_table "versions", id: :bigserial, force: :cascade do |t| + t.string "item_type", null: false + t.integer "item_id", limit: 8, null: false + t.string "event", null: false + t.string "whodunnit" + t.text "object" + t.datetime "created_at" + end + + add_index "versions", ["item_type", "item_id"], name: "index_versions_on_item_type_and_item_id", using: :btree + create_table "workbenches", id: :bigserial, force: :cascade do |t| t.string "name" t.integer "organisation_id", limit: 8 @@ -967,8 +982,6 @@ ActiveRecord::Schema.define(version: 20171114102438) do add_foreign_key "compliance_check_messages", "compliance_check_sets" add_foreign_key "compliance_check_messages", "compliance_checks" add_foreign_key "compliance_check_resources", "compliance_check_sets" - add_foreign_key "compliance_check_sets", "compliance_control_sets" - add_foreign_key "compliance_check_sets", "referentials" add_foreign_key "compliance_check_sets", "workbenches" add_foreign_key "compliance_checks", "compliance_check_blocks" add_foreign_key "compliance_checks", "compliance_check_sets" @@ -977,7 +990,9 @@ ActiveRecord::Schema.define(version: 20171114102438) do add_foreign_key "compliance_controls", "compliance_control_blocks" add_foreign_key "compliance_controls", "compliance_control_sets" add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", on_delete: :cascade + add_foreign_key "journey_frequencies", "timebands", name: "journey_frequencies_timeband_id_fk", on_delete: :nullify add_foreign_key "journey_frequencies", "timebands", on_delete: :nullify + add_foreign_key "journey_frequencies", "vehicle_journeys", name: "journey_frequencies_vehicle_journey_id_fk", on_delete: :nullify add_foreign_key "journey_frequencies", "vehicle_journeys", on_delete: :nullify add_foreign_key "journey_patterns", "routes", name: "jp_route_fkey", on_delete: :cascade add_foreign_key "journey_patterns", "stop_points", column: "arrival_stop_point_id", name: "arrival_point_fkey", on_delete: :nullify diff --git a/db/seeds.rb b/db/seeds.rb index d31a35cfc..b7db25411 100644 --- a/db/seeds.rb +++ b/db/seeds.rb @@ -1,38 +1 @@ -# coding: utf-8 -# This file should contain all the record creation needed to seed the database with its default values. -# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). - -stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex") -line_referential = LineReferential.find_or_create_by!(name: "CodifLigne") - -# Organisations -stif = Organisation.find_or_create_by!(code: "STIF") do |org| - org.name = 'STIF' -end -operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation| - organisation.name = "Transporteur A" -end - -# Member -line_referential.add_member stif, owner: true -line_referential.add_member operator - -stop_area_referential.add_member stif, owner: true -stop_area_referential.add_member operator - -# Users -stif.users.find_or_create_by!(username: "admin") do |user| - user.email = 'stif-boiv@af83.com' - user.password = "secret" - user.name = "STIF Administrateur" -end - -operator.users.find_or_create_by!(username: "transporteur") do |user| - user.email = 'stif-boiv+transporteur@af83.com' - user.password = "secret" - user.name = "Martin Lejeune" -end - -# Include all Lines in organisation functional_scope -stif.update sso_attributes: { functional_scope: line_referential.lines.pluck(:objectid) } -operator.update sso_attributes: { functional_scope: line_referential.lines.limit(3).pluck(:objectid) } +# Empty diff --git a/db/seeds/stif.seeds.rb b/db/seeds/stif.seeds.rb new file mode 100644 index 000000000..464601557 --- /dev/null +++ b/db/seeds/stif.seeds.rb @@ -0,0 +1,38 @@ +# coding: utf-8 +# This file should contain all the record creation needed to seed the database with its default values. +# The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). + +stop_area_referential = StopAreaReferential.find_or_create_by!(name: "Reflex", objectid_format: "stif_netex") +line_referential = LineReferential.find_or_create_by!(name: "CodifLigne", objectid_format: "stif_netex") + +# Organisations +stif = Organisation.find_or_create_by!(code: "STIF") do |org| + org.name = 'STIF' +end +operator = Organisation.find_or_create_by!(code: 'transporteur-a') do |organisation| + organisation.name = "Transporteur A" +end + +# Member +line_referential.add_member stif, owner: true +line_referential.add_member operator + +stop_area_referential.add_member stif, owner: true +stop_area_referential.add_member operator + +# Users +stif.users.find_or_create_by!(username: "admin") do |user| + user.email = 'stif-boiv@af83.com' + user.password = "secret" + user.name = "STIF Administrateur" +end + +operator.users.find_or_create_by!(username: "transporteur") do |user| + user.email = 'stif-boiv+transporteur@af83.com' + user.password = "secret" + user.name = "Martin Lejeune" +end + +# Include all Lines in organisation functional_scope +stif.update sso_attributes: { functional_scope: line_referential.lines.pluck(:objectid) } +operator.update sso_attributes: { functional_scope: line_referential.lines.limit(3).pluck(:objectid) } diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index a3bf3957e..39a92bd1f 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -150,9 +150,8 @@ module Stif end def create_or_update_stop_area entry - stop = Chouette::StopArea.find_or_create_by(objectid: entry['id']) + stop = Chouette::StopArea.find_or_create_by(objectid: entry['id'], stop_area_referential: self.defaut_referential ) stop.deleted_at = nil - stop.stop_area_referential = self.defaut_referential { :comment => 'Description', :name => 'Name', diff --git a/spec/controllers/devise/cas_sessions_controller_spec.rb b/spec/controllers/devise/cas_sessions_controller_spec.rb index e4436f6c1..934bc1da2 100644 --- a/spec/controllers/devise/cas_sessions_controller_spec.rb +++ b/spec/controllers/devise/cas_sessions_controller_spec.rb @@ -22,7 +22,7 @@ RSpec.describe Devise::CasSessionsController, type: :controller do it 'cannot login and will be redirected to the login page, with a corresponding message' do get :service - expect(controller).to set_flash[:alert].to(%r{IBOO}) + expect(controller).to set_flash[:alert].to(%r{Vous ne pouvez pas vous connecter car vous n'avez pas les permissions}) expect(response).to redirect_to "http://stif-portail-dev.af83.priv/sessions/logout?service=http%3A%2F%2Ftest.host%2Fusers%2Fservice" end end diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb index fb29c8d73..f8e8697ec 100644 --- a/spec/controllers/routes_controller_spec.rb +++ b/spec/controllers/routes_controller_spec.rb @@ -1,5 +1,3 @@ -Route = Chouette::Route - RSpec.describe RoutesController, type: :controller do login_user @@ -87,10 +85,10 @@ RSpec.describe RoutesController, type: :controller do referential_id: route.line.line_referential_id, line_id: route.line_id, id: route.id - end.to change { Route.count }.by(1) + end.to change { Chouette::Route.count }.by(1) - expect(Route.last.name).to eq( I18n.t('activerecord.copy', name: route.name)) - expect(Route.last.published_name).to eq(route.published_name) + expect(Chouette::Route.last.name).to eq(I18n.t('activerecord.copy', name: route.name)) + expect(Chouette::Route.last.published_name).to eq(route.published_name) end end end diff --git a/spec/db/schema_spec.rb b/spec/db/schema_spec.rb index a7fe0a162..585636124 100644 --- a/spec/db/schema_spec.rb +++ b/spec/db/schema_spec.rb @@ -44,6 +44,6 @@ Diff: #{diff} def diff RSpec::Support::Differ.new( color: RSpec::Matchers.configuration.color? - ).diff_as_string(@original, @expected) + ).diff_as_string(@expected, @original) end end diff --git a/spec/decorators/company_decorator_spec.rb b/spec/decorators/company_decorator_spec.rb index a1df03449..557d98da1 100644 --- a/spec/decorators/company_decorator_spec.rb +++ b/spec/decorators/company_decorator_spec.rb @@ -1,2 +1,2 @@ -describe CompanyDecorator do +describe Chouette::CompanyDecorator do end diff --git a/spec/fabricators/user_fabricator.rb b/spec/fabricators/user_fabricator.rb index 04c1c6279..62eb82d51 100644 --- a/spec/fabricators/user_fabricator.rb +++ b/spec/fabricators/user_fabricator.rb @@ -5,4 +5,4 @@ Fabricator :user do password { 'password' } username { "#{FFaker::Name.first_name.parameterize}.#{FFaker::Name.last_name.parameterize}" } -end
\ No newline at end of file +end diff --git a/spec/factories/chouette_lines.rb b/spec/factories/chouette_lines.rb index 423ab99f2..95f760174 100644 --- a/spec/factories/chouette_lines.rb +++ b/spec/factories/chouette_lines.rb @@ -8,7 +8,7 @@ FactoryGirl.define do association :network, :factory => :network association :company, :factory => :company - + before(:create) do |line| line.line_referential ||= LineReferential.find_by! name: "first" end @@ -44,6 +44,11 @@ FactoryGirl.define do end + factory :line_with_after_commit do |line| + line.run_callbacks(:commit) + + end + end end diff --git a/spec/factories/chouette_routes.rb b/spec/factories/chouette_routes.rb index 4986ab70e..4e20059fe 100644 --- a/spec/factories/chouette_routes.rb +++ b/spec/factories/chouette_routes.rb @@ -33,6 +33,13 @@ FactoryGirl.define do end end + factory :route_with_after_commit do + sequence(:objectid) {nil} + after(:create) do |route| + route.run_callbacks(:commit) + end + end + end end diff --git a/spec/factories/compliance_controls/route_control_factories.rb b/spec/factories/compliance_controls/route_control_factories.rb index 1462ca635..35d8f481f 100644 --- a/spec/factories/compliance_controls/route_control_factories.rb +++ b/spec/factories/compliance_controls/route_control_factories.rb @@ -28,7 +28,7 @@ FactoryGirl.define do association :compliance_control_set end - factory :route_control_unactivated_stop_points, class: 'RouteControl::UnactivatedStopPoints' do + factory :route_control_unactivated_stop_point, class: 'RouteControl::UnactivatedStopPoint' do association :compliance_control_set end diff --git a/spec/factories/line_referentials.rb b/spec/factories/line_referentials.rb index cfce1399f..e9e6dce5a 100644 --- a/spec/factories/line_referentials.rb +++ b/spec/factories/line_referentials.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :line_referential do sequence(:name) { |n| "Line Referential #{n}" } + objectid_format 'stif_codifligne' end end diff --git a/spec/factories/referentials.rb b/spec/factories/referentials.rb index a4155d181..0276a47be 100644 --- a/spec/factories/referentials.rb +++ b/spec/factories/referentials.rb @@ -8,6 +8,7 @@ FactoryGirl.define do association :organisation time_zone "Europe/Paris" ready { true } + objectid_format "stif_netex" factory :workbench_referential do association :workbench diff --git a/spec/factories/stop_area_referentials.rb b/spec/factories/stop_area_referentials.rb index c88819010..fcba996e4 100644 --- a/spec/factories/stop_area_referentials.rb +++ b/spec/factories/stop_area_referentials.rb @@ -1,5 +1,6 @@ FactoryGirl.define do factory :stop_area_referential, :class => StopAreaReferential do sequence(:name) { |n| "StopArea Referential #{n}" } + objectid_format 'stif_reflex' end end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index 57bef2203..0f26559d8 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -1,6 +1,7 @@ FactoryGirl.define do factory :workbench do name "Gestion de l'offre" + objectid_format 'stif_netex' association :organisation association :line_referential diff --git a/spec/features/api_keys/edit_api_key_feature_spec.rb b/spec/features/api_keys/edit_api_key_feature_spec.rb index 256c4218b..9248e2b17 100644 --- a/spec/features/api_keys/edit_api_key_feature_spec.rb +++ b/spec/features/api_keys/edit_api_key_feature_spec.rb @@ -12,6 +12,8 @@ RSpec.describe 'Edit API Key', type: :feature do let( :unique_name ){ SecureRandom.uuid } it 'complete workflow' do + skip "Specific to STIF Dashboard" if Dashboard.default_class != Stif::Dashboard + visit dashboard_path # api_key's new name does not exist yet expect( page ).not_to have_content(unique_name) diff --git a/spec/features/api_keys/new_api_key_feature_spec.rb b/spec/features/api_keys/new_api_key_feature_spec.rb index 988690f3c..fc5497788 100644 --- a/spec/features/api_keys/new_api_key_feature_spec.rb +++ b/spec/features/api_keys/new_api_key_feature_spec.rb @@ -13,6 +13,8 @@ RSpec.describe 'New API Key', type: :feature do it 'complete workflow' do + skip "Specific to STIF Dashboard" if Dashboard.default_class != Stif::Dashboard + # /workbenches visit dashboard_path expect(page).to have_link(create_label, href: new_api_key_path) diff --git a/spec/helpers/table_builder_helper_spec.rb b/spec/helpers/table_builder_helper_spec.rb index a8854bf97..3b0a18379 100644 --- a/spec/helpers/table_builder_helper_spec.rb +++ b/spec/helpers/table_builder_helper_spec.rb @@ -214,7 +214,7 @@ describe TableBuilderHelper, type: :helper do </thead> <tbody> <tr> - <td>#{company.objectid.local_id}</td> + <td>#{company.get_objectid.local_id}</td> <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td> <td></td> <td></td> @@ -237,7 +237,7 @@ describe TableBuilderHelper, type: :helper do [ TableBuilderHelper::Column.new( name: 'ID Codif', - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) }, + attribute: Proc.new { |n| n.try(:get_objectid).try(:local_id) }, sortable: false ), TableBuilderHelper::Column.new( @@ -327,7 +327,7 @@ describe TableBuilderHelper, type: :helper do </thead> <tbody> <tr> - <td>#{company.objectid.local_id}</td> + <td>#{company.get_objectid.local_id}</td> <td title="Voir"><a href="/referentials/#{referential.id}/companies/#{company.id}">#{company.name}</a></td> <td></td> <td></td> @@ -350,7 +350,7 @@ describe TableBuilderHelper, type: :helper do [ TableBuilderHelper::Column.new( name: 'ID Codif', - attribute: Proc.new { |n| n.try(:objectid).try(:local_id) } + attribute: Proc.new { |n| n.try(:get_objectid).try(:local_id) } ), TableBuilderHelper::Column.new( key: :name, diff --git a/spec/models/api/v1/api_key_spec.rb b/spec/models/api/v1/api_key_spec.rb index b700429d3..cc483a118 100644 --- a/spec/models/api/v1/api_key_spec.rb +++ b/spec/models/api/v1/api_key_spec.rb @@ -4,6 +4,7 @@ RSpec.describe Api::V1::ApiKey, type: :model do subject { create(:api_key) } it { should validate_presence_of :organisation } + it { is_expected.to be_versioned } it 'should have a valid factory' do expect(build(:api_key)).to be_valid diff --git a/spec/models/calendar_spec.rb b/spec/models/calendar_spec.rb index f5020ebf8..e71c2b081 100644 --- a/spec/models/calendar_spec.rb +++ b/spec/models/calendar_spec.rb @@ -6,6 +6,7 @@ RSpec.describe Calendar, :type => :model do it { is_expected.to validate_presence_of(:name) } it { is_expected.to validate_presence_of(:short_name) } it { is_expected.to validate_uniqueness_of(:short_name) } + it { is_expected.to be_versioned } describe '#to_time_table' do let(:calendar) { create(:calendar, date_ranges: [Date.today...(Date.today + 1.month)]) } @@ -29,7 +30,6 @@ RSpec.describe Calendar, :type => :model do end end - describe 'before_validation' do let(:calendar) { create(:calendar, date_ranges: []) } diff --git a/spec/models/chouette/access_link_spec.rb b/spec/models/chouette/access_link_spec.rb index 5a31b8f0c..ced99eb1d 100644 --- a/spec/models/chouette/access_link_spec.rb +++ b/spec/models/chouette/access_link_spec.rb @@ -4,10 +4,11 @@ describe Chouette::AccessLink, :type => :model do subject { create(:access_link) } it { is_expected.to validate_uniqueness_of :objectid } + it { is_expected.to be_versioned } - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } + describe '#get_objectid' do + subject { super().get_objectid } + it {is_expected.to be_kind_of(Chouette::Objectid::StifNetex)} end it { is_expected.to validate_presence_of :name } diff --git a/spec/models/chouette/access_point_spec.rb b/spec/models/chouette/access_point_spec.rb index e0f4b1501..c734ecedf 100644 --- a/spec/models/chouette/access_point_spec.rb +++ b/spec/models/chouette/access_point_spec.rb @@ -4,13 +4,15 @@ describe Chouette::AccessPoint, :type => :model do subject { create(:access_point) } describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifReflexObjectid) } + it "should have the same class as stop_area objectid" do + expect(subject.objectid.class).to eq(subject.stop_area.objectid.class) + end end it { is_expected.to validate_presence_of :name } it { is_expected.to validate_numericality_of :latitude } it { is_expected.to validate_numericality_of :longitude } + it { is_expected.to be_versioned } describe ".latitude" do it "should accept -90 value" do diff --git a/spec/models/chouette/company_spec.rb b/spec/models/chouette/company_spec.rb index a3101d79c..34b19eeda 100644 --- a/spec/models/chouette/company_spec.rb +++ b/spec/models/chouette/company_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Chouette::Company, :type => :model do subject { create(:company) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe "#nullables empty" do it "should set null empty nullable attributes" do diff --git a/spec/models/chouette/connection_link_spec.rb b/spec/models/chouette/connection_link_spec.rb index 57eb7d66c..4ab67d007 100644 --- a/spec/models/chouette/connection_link_spec.rb +++ b/spec/models/chouette/connection_link_spec.rb @@ -8,10 +8,11 @@ describe Chouette::ConnectionLink, :type => :model do subject { create(:connection_link) } it { is_expected.to validate_uniqueness_of :objectid } + it { is_expected.to be_versioned } - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } + describe '#get_objectid' do + subject { super().get_objectid } + it {is_expected.to be_kind_of(Chouette::Objectid::StifNetex)} end it { is_expected.to validate_presence_of :name } diff --git a/spec/models/chouette/group_of_line_spec.rb b/spec/models/chouette/group_of_line_spec.rb index 29b4433c5..d43d75374 100644 --- a/spec/models/chouette/group_of_line_spec.rb +++ b/spec/models/chouette/group_of_line_spec.rb @@ -4,6 +4,7 @@ describe Chouette::GroupOfLine, :type => :model do subject { create(:group_of_line) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe "#stop_areas" do let!(:line){create(:line, :group_of_lines => [subject])} diff --git a/spec/models/chouette/journey_pattern_spec.rb b/spec/models/chouette/journey_pattern_spec.rb index 047022ade..ea7c2a2e9 100644 --- a/spec/models/chouette/journey_pattern_spec.rb +++ b/spec/models/chouette/journey_pattern_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Chouette::JourneyPattern, :type => :model do + it { is_expected.to be_versioned } + describe 'checksum' do it_behaves_like 'checksum support', :journey_pattern end diff --git a/spec/models/chouette/line_spec.rb b/spec/models/chouette/line_spec.rb index 2e5882012..056d5da9e 100644 --- a/spec/models/chouette/line_spec.rb +++ b/spec/models/chouette/line_spec.rb @@ -7,19 +7,15 @@ describe Chouette::Line, :type => :model do # it { is_expected.to validate_presence_of :network } # it { is_expected.to validate_presence_of :company } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe '#display_name' do it 'should display local_id, number, name and company name' do - display_name = "#{subject.objectid.local_id} - #{subject.number} - #{subject.name} - #{subject.company.try(:name)}" + display_name = "#{subject.get_objectid.local_id} - #{subject.number} - #{subject.name} - #{subject.company.try(:name)}" expect(subject.display_name).to eq(display_name) end end - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifCodifligneObjectid) } - end - # it { should validate_numericality_of :objectversion } # describe ".last_stop_areas_parents" do diff --git a/spec/models/chouette/network_spec.rb b/spec/models/chouette/network_spec.rb index 32bacc512..78a4150df 100644 --- a/spec/models/chouette/network_spec.rb +++ b/spec/models/chouette/network_spec.rb @@ -3,6 +3,7 @@ require 'spec_helper' describe Chouette::Network, :type => :model do subject { create(:network) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } describe "#stop_areas" do let!(:line){create(:line, :network => subject)} diff --git a/spec/models/chouette/object_id_spec.rb b/spec/models/chouette/object_id_spec.rb deleted file mode 100644 index dd8b66388..000000000 --- a/spec/models/chouette/object_id_spec.rb +++ /dev/null @@ -1,149 +0,0 @@ -require 'spec_helper' - -describe Chouette::ObjectId, :type => :model do - - def objectid(value = "abc:StopArea:abc123") - Chouette::ObjectId.new value - end - - subject { objectid } - - context "when invalid" do - - subject { objectid("abc") } - - it { is_expected.not_to be_valid } - - describe '#parts' do - subject { super().parts } - it { is_expected.to be_nil } - end - - describe '#system_id' do - subject { super().system_id } - it { is_expected.to be_nil } - end - - end - - context "when with spaces in last part" do - - subject { objectid("abc:Line:Aze toto") } - - it { is_expected.not_to be_valid } - - - end - - context "when with spaces in first part" do - - subject { objectid("ae abc:Line:Aze") } - - it { is_expected.not_to be_valid } - - - end - - context "when with spaces in middle part" do - - subject { objectid("aeabc:Li ne:Aze") } - - it { is_expected.not_to be_valid } - - - end - - context "when invalid in first part" do - - subject { objectid("Abc_+19:Line:Abc") } - - it { is_expected.not_to be_valid } - end - - context "when invalid in middle part" do - - subject { objectid("Abc_19:Li56ne:Abc") } - - it { is_expected.not_to be_valid } - end - - context "when invalid in last part" do - - subject { objectid("Abc_19:Line:Ab+c") } - - it { is_expected.not_to be_valid } - end - context "when valid" do - - subject { objectid("Abc_19:Line:Abc_12-") } - - it { is_expected.to be_valid } - end - - describe "#parts" do - - it "should be the 3 parts of the ObjectId" do - expect(objectid("abc:StopArea:abc123").parts).to eq(%w{abc StopArea abc123}) - end - - end - - describe "#system_id" do - - it "should be the first ObjectId parts" do - expect(objectid("first:second:third").system_id).to eq("first") - end - - end - - describe "#object_type" do - - it "should be the second ObjectId parts" do - expect(objectid("first:second:third").object_type).to eq("second") - end - - end - - describe "#local_id" do - - it "should be the third ObjectId parts" do - expect(objectid("first:second:third").local_id).to eq("third") - end - - end - - it "should be valid when parts are found" do - allow(subject).to receive_messages :parts => "dummy" - expect(subject).to be_valid - end - - describe ".create" do - - let(:given_system_id) { "systemId" } - let(:given_object_type) { "objectType" } - let(:given_local_id) { "localId" } - - subject { Chouette::ObjectId.create(given_system_id, given_object_type, given_local_id) } - - it "should return ObjectId attributes" do - expect(subject.send(:system_id)).to eq(given_system_id) - expect(subject.send(:object_type)).to eq(given_object_type) - expect(subject.send(:local_id)).to eq(given_local_id) - end - - end - - describe ".new" do - - it "should return an existing ObjectId" do - expect(Chouette::ObjectId.new(objectid)).to eq(objectid) - end - - it "should create an empty ObjectId with nil" do - expect(Chouette::ObjectId.new(nil)).to be_empty - end - - end - - -end diff --git a/spec/models/chouette/objectid/netex_spec.rb b/spec/models/chouette/objectid/netex_spec.rb new file mode 100644 index 000000000..3aee13624 --- /dev/null +++ b/spec/models/chouette/objectid/netex_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Chouette::Objectid::Netex, :type => :model do + subject { Chouette::Objectid::Netex.new(object_type: 'Route', local_id: SecureRandom.uuid) } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :creation_id } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/objectid/stif_codifligne_spec.rb b/spec/models/chouette/objectid/stif_codifligne_spec.rb new file mode 100644 index 000000000..533af3556 --- /dev/null +++ b/spec/models/chouette/objectid/stif_codifligne_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Chouette::Objectid::StifCodifligne, :type => :model do + subject { Chouette::Objectid::StifCodifligne.new(object_type: 'Line', local_id: 'C02008', sync_id: 'CODIFLIGNE', provider_id: 'STIF') } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :sync_id } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/objectid/stif_netex_spec.rb b/spec/models/chouette/objectid/stif_netex_spec.rb new file mode 100644 index 000000000..1d361ca86 --- /dev/null +++ b/spec/models/chouette/objectid/stif_netex_spec.rb @@ -0,0 +1,10 @@ +require 'spec_helper' + +describe Chouette::Objectid::StifNetex, :type => :model do + subject { Chouette::Objectid::StifNetex.new(object_type: 'Route', local_id: '13') } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :creation_id } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/objectid/stif_reflex_spec.rb b/spec/models/chouette/objectid/stif_reflex_spec.rb new file mode 100644 index 000000000..0846f27fa --- /dev/null +++ b/spec/models/chouette/objectid/stif_reflex_spec.rb @@ -0,0 +1,11 @@ +require 'spec_helper' + +describe Chouette::Objectid::StifReflex, :type => :model do + subject { Chouette::Objectid::StifReflex.new(country_code: 'FR', zip_code: '78517', object_type: 'ZDL', local_id: '50015386', provider_id: 'STIF') } + it { should validate_presence_of :provider_id } + it { should validate_presence_of :object_type } + it { should validate_presence_of :local_id } + it { should validate_presence_of :country_code } + it { should validate_presence_of :zip_code } + it { is_expected.to be_valid } +end
\ No newline at end of file diff --git a/spec/models/chouette/route/route_base_spec.rb b/spec/models/chouette/route/route_base_spec.rb index cac2880e8..26f57eae5 100644 --- a/spec/models/chouette/route/route_base_spec.rb +++ b/spec/models/chouette/route/route_base_spec.rb @@ -5,11 +5,6 @@ RSpec.describe Chouette::Route, :type => :model do it_behaves_like 'checksum support', :route end - describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } - end - it { is_expected.to enumerize(:direction).in(:straight_forward, :backward, :clockwise, :counter_clockwise, :north, :north_west, :west, :south_west, :south, :south_east, :east, :north_east) } it { is_expected.to enumerize(:wayback).in(:outbound, :inbound) } @@ -20,6 +15,7 @@ RSpec.describe Chouette::Route, :type => :model do #it { is_expected.to validate_presence_of :direction_code } it { is_expected.to validate_inclusion_of(:direction).in_array(%i(straight_forward backward clockwise counter_clockwise north north_west west south_west south south_east east north_east)) } it { is_expected.to validate_inclusion_of(:wayback).in_array(%i(outbound inbound)) } + it { is_expected.to be_versioned } context "reordering methods" do let(:bad_stop_point_ids){subject.stop_points.map { |sp| sp.id + 1}} diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb index 5bcd13fc8..ee45b5005 100644 --- a/spec/models/chouette/route/route_duplication_spec.rb +++ b/spec/models/chouette/route/route_duplication_spec.rb @@ -1,9 +1,4 @@ -# From Chouette import what we need ™ -Route = Chouette::Route -StopArea = Chouette::StopArea -StopPoint = Chouette::StopPoint - -RSpec.describe Route do +RSpec.describe Chouette::Route do let!( :route ){ create :route } @@ -11,7 +6,7 @@ RSpec.describe Route do describe 'properties' do it 'same attribute values' do route.duplicate - expect( values_for_create(Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) ) + expect( values_for_create(Chouette::Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) ) end it 'and others cannot' do expect{ route.duplicate name: 'YAN', line_id: 42 }.to raise_error(ArgumentError) @@ -23,13 +18,13 @@ RSpec.describe Route do describe 'side_effects' do it { - expect{ route.duplicate }.to change{Route.count}.by(1) + expect{ route.duplicate }.to change{Chouette::Route.count}.by(1) } it 'duplicates its stop points' do - expect{ route.duplicate }.to change{StopPoint.count}.by(route.stop_points.count) + expect{ route.duplicate }.to change{Chouette::StopPoint.count}.by(route.stop_points.count) end it 'does bot duplicate the stop areas' do - expect{ route.duplicate }.not_to change{StopArea.count} + expect{ route.duplicate }.not_to change{Chouette::StopArea.count} end end diff --git a/spec/models/chouette/routing_constraint_zone_spec.rb b/spec/models/chouette/routing_constraint_zone_spec.rb index c344642e6..8ebd8695c 100644 --- a/spec/models/chouette/routing_constraint_zone_spec.rb +++ b/spec/models/chouette/routing_constraint_zone_spec.rb @@ -7,6 +7,7 @@ describe Chouette::RoutingConstraintZone, type: :model do it { is_expected.to validate_presence_of :name } # shoulda matcher to validate length of array ? xit { is_expected.to validate_length_of(:stop_point_ids).is_at_least(2) } + it { is_expected.to be_versioned } describe 'checksum' do it_behaves_like 'checksum support', :routing_constraint_zone diff --git a/spec/models/chouette/stop_area_spec.rb b/spec/models/chouette/stop_area_spec.rb index a3a398bfb..c6aeafaf8 100644 --- a/spec/models/chouette/stop_area_spec.rb +++ b/spec/models/chouette/stop_area_spec.rb @@ -7,15 +7,11 @@ describe Chouette::StopArea, :type => :model do let!(:commercial_stop_point) { create :stop_area, :area_type => "lda" } let!(:stop_place) { create :stop_area, :area_type => "zdlp" } - describe '#objectid' do - subject { super().objectid } - it { should be_kind_of(Chouette::StifReflexObjectid) } - end - it { should belong_to(:stop_area_referential) } it { should validate_presence_of :name } it { should validate_numericality_of :latitude } it { should validate_numericality_of :longitude } + it { is_expected.to be_versioned } # describe ".latitude" do # it "should accept -90 value" do diff --git a/spec/models/chouette/stop_point_spec.rb b/spec/models/chouette/stop_point_spec.rb index 329e76a75..6b9e7727f 100644 --- a/spec/models/chouette/stop_point_spec.rb +++ b/spec/models/chouette/stop_point_spec.rb @@ -1,16 +1,14 @@ -# From Chouette import what we need ™ -StopPoint = Chouette::StopPoint - -describe StopPoint, :type => :model do +describe Chouette::StopPoint, :type => :model do let!(:vehicle_journey) { create(:vehicle_journey)} subject { Chouette::Route.find( vehicle_journey.route_id).stop_points.first } it { is_expected.to validate_uniqueness_of :objectid } it { is_expected.to validate_presence_of :stop_area } + it { is_expected.to be_versioned } describe '#objectid' do - subject { super().objectid } - it { is_expected.to be_kind_of(Chouette::StifNetexObjectid) } + subject { super().get_objectid } + it { is_expected.to be_kind_of(Chouette::Objectid::StifNetex) } end describe "#destroy" do @@ -44,7 +42,7 @@ describe StopPoint, :type => :model do let!( :new_route ){ create :route } it 'creates a new instance' do - expect{ subject.duplicate(for_route: new_route) }.to change{ StopPoint.count }.by(1) + expect{ subject.duplicate(for_route: new_route) }.to change{ Chouette::StopPoint.count }.by(1) end it 'new instance has a new route' do expect(subject.duplicate(for_route: new_route).route).to eq(new_route) diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index 761c39e5b..677308fc8 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -6,6 +6,7 @@ describe Chouette::TimeTable, :type => :model do it { is_expected.to validate_presence_of :comment } it { is_expected.to validate_uniqueness_of :objectid } + it { is_expected.to be_versioned } def create_time_table_periode time_table, start_date, end_date create(:time_table_period, time_table: time_table, :period_start => start_date, :period_end => end_date) diff --git a/spec/models/chouette/timeband_spec.rb b/spec/models/chouette/timeband_spec.rb index 1f812a6e2..b960c203f 100644 --- a/spec/models/chouette/timeband_spec.rb +++ b/spec/models/chouette/timeband_spec.rb @@ -1,6 +1,7 @@ require 'spec_helper' describe Chouette::Timeband, :type => :model do + it { is_expected.to be_versioned } describe '#create' do context 'when valid' do diff --git a/spec/models/chouette/trident_active_record_spec.rb b/spec/models/chouette/trident_active_record_spec.rb deleted file mode 100644 index d5e30594d..000000000 --- a/spec/models/chouette/trident_active_record_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -require 'spec_helper' - -describe Chouette::TridentActiveRecord, :type => :model do - subject { create(:time_table) } - - it { should validate_presence_of :objectid } - it { should validate_uniqueness_of :objectid } - - describe "#default_values" do - let(:object) { build(:time_table, objectid: nil) } - - it 'should fill __pending_id__' do - object.default_values - expect(object.objectid.include?('__pending_id__')).to be_truthy - end - end - - describe "#objectid" do - let(:object) { build(:time_table, objectid: nil) } - - it 'should build objectid on create' do - object.save - id = "#{object.provider_id}:#{object.model_name}:#{object.local_id}:#{object.boiv_id}" - expect(object.objectid).to eq(id) - end - - it 'should call build_objectid on after save' do - expect(object).to receive(:build_objectid) - object.save - end - - it 'should not build new objectid is already set' do - id = "first:TimeTable:1-1:LOC" - object.objectid = id - object.save - expect(object.objectid).to eq(id) - end - - it 'should call default_values on create' do - expect(object).to receive(:default_values) - object.save - end - - it 'should not call default_values on update' do - object = create(:time_table) - expect(object).to_not receive(:default_values) - object.touch - end - - it 'should create a new objectid when cleared' do - object.save - object.objectid = nil - object.save - expect(object.objectid).to be_truthy - end - end -end diff --git a/spec/models/chouette/vehicle_journey_at_stop_spec.rb b/spec/models/chouette/vehicle_journey_at_stop_spec.rb index 03e6fcb7d..df8a630fe 100644 --- a/spec/models/chouette/vehicle_journey_at_stop_spec.rb +++ b/spec/models/chouette/vehicle_journey_at_stop_spec.rb @@ -51,7 +51,7 @@ RSpec.describe Chouette::VehicleJourneyAtStop, type: :model do ) error_message = I18n.t( 'vehicle_journey_at_stops.errors.day_offset_must_not_exceed_max', - short_id: at_stop.vehicle_journey.objectid.short_id, + short_id: at_stop.vehicle_journey.get_objectid.short_id, max: bad_offset ) diff --git a/spec/models/chouette/vehicle_journey_spec.rb b/spec/models/chouette/vehicle_journey_spec.rb index 52f2ab42d..ac9b21ceb 100644 --- a/spec/models/chouette/vehicle_journey_spec.rb +++ b/spec/models/chouette/vehicle_journey_spec.rb @@ -1,6 +1,8 @@ require 'spec_helper' describe Chouette::VehicleJourney, :type => :model do + it { is_expected.to be_versioned } + it "must be valid with an at-stop day offset of 1" do vehicle_journey = create( :vehicle_journey, @@ -94,10 +96,13 @@ describe Chouette::VehicleJourney, :type => :model do expect { Chouette::VehicleJourney.state_update(route, collection) }.to change {Chouette::VehicleJourney.count}.by(1) + expect(collection.last['objectid']).not_to be_nil - vj = Chouette::VehicleJourney.find_by(objectid: collection.last['objectid']) - expect(vj.published_journey_name).to eq 'dummy' + obj = Chouette::VehicleJourney.last + obj.run_callbacks(:commit) + + expect(obj.published_journey_name).to eq 'dummy' end it 'should save vehicle_journey_at_stops of newly created vj' do diff --git a/spec/models/compliance_check_set_spec.rb b/spec/models/compliance_check_set_spec.rb index 0159d1c6b..b981a68bb 100644 --- a/spec/models/compliance_check_set_spec.rb +++ b/spec/models/compliance_check_set_spec.rb @@ -12,6 +12,7 @@ RSpec.describe ComplianceCheckSet, type: :model do it { should have_many :compliance_checks } it { should have_many :compliance_check_blocks } + it { is_expected.to be_versioned } describe "#update_status" do it "updates :status to successful when all resources are OK" do @@ -89,4 +90,13 @@ RSpec.describe ComplianceCheckSet, type: :model do expect(check_set.update_status).to be true end end + + describe 'possibility to delete the associated compliance_control_set' do + let!(:compliance_check_set) { create :compliance_check_set } + + it do + expect{ compliance_check_set.compliance_control_set.delete } + .to change{ ComplianceControlSet.count }.by(-1) + end + end end diff --git a/spec/models/compliance_check_spec.rb b/spec/models/compliance_check_spec.rb index bd797ab09..f83d78c29 100644 --- a/spec/models/compliance_check_spec.rb +++ b/spec/models/compliance_check_spec.rb @@ -1,4 +1,5 @@ RSpec.describe ComplianceCheck, type: :model do + it 'should have a valid factory' do expect(FactoryGirl.build(:compliance_check)).to be_valid end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_point_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_point_cccld_spec.rb new file mode 100644 index 000000000..e9c335dea --- /dev/null +++ b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_point_cccld_spec.rb @@ -0,0 +1,7 @@ + +RSpec.describe RouteControl::UnactivatedStopPoint, type: :model do + let( :default_code ){ "3-Route-10" } + let( :factory ){ :route_control_unactivated_stop_point } + + it_behaves_like 'ComplianceControl Class Level Defaults' +end diff --git a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb b/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb deleted file mode 100644 index bf725d743..000000000 --- a/spec/models/compliance_control_class_level_defaults/route_control/unactivated_stop_points_cccld_spec.rb +++ /dev/null @@ -1,7 +0,0 @@ - -RSpec.describe RouteControl::UnactivatedStopPoints, type: :model do - let( :default_code ){ "3-Route-10" } - let( :factory ){ :route_control_unactivated_stop_points } - - it_behaves_like 'ComplianceControl Class Level Defaults' -end diff --git a/spec/models/compliance_control_set_spec.rb b/spec/models/compliance_control_set_spec.rb index 04d1c418c..c157dcaf3 100644 --- a/spec/models/compliance_control_set_spec.rb +++ b/spec/models/compliance_control_set_spec.rb @@ -10,4 +10,5 @@ RSpec.describe ComplianceControlSet, type: :model do it { should have_many(:compliance_control_blocks).dependent(:destroy) } it { should validate_presence_of :name } + it { is_expected.to be_versioned } end diff --git a/spec/models/concerns/objectid_support_spec.rb b/spec/models/concerns/objectid_support_spec.rb new file mode 100644 index 000000000..fabeeec11 --- /dev/null +++ b/spec/models/concerns/objectid_support_spec.rb @@ -0,0 +1,138 @@ +RSpec.describe ObjectidSupport do + + context 'when referential has an objectid format of stif_netex' do + let(:object) { create(:time_table, objectid: nil) } + + context "#objectid_format" do + it "should be stif_netex" do + expect(object.referential.objectid_format).to eq('stif_netex') + end + end + + it 'should fill __pending_id__' do + expect(object.objectid.include?('__pending_id__')).to be_truthy + end + + context "#get_objectid" do + + before(:each) do + object.run_callbacks(:commit) + end + + it "should be valid" do + expect(object.get_objectid).to be_valid + end + + it "should have the same local id than the object" do + expect(object.get_objectid.local_id).to eq(object.local_id) + end + + it "should be a Chouette::Objectid::StifNetex" do + expect(object.get_objectid).to be_kind_of(Chouette::Objectid::StifNetex) + end + + context "#to_s" do + it "should return a string" do + expect(object.get_objectid.to_s).to be_kind_of(String) + end + + it "should be the same as the db attribute" do + expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid)) + expect(object.get_objectid.to_s).to eq(object.objectid) + end + + context "#objectid" do + + it 'should build objectid on create' do + object.save + object.run_callbacks(:commit) + objectid = object.get_objectid + id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" + expect(object.read_attribute(:objectid)).to eq(id) + end + + it 'should not build new objectid is already set' do + id = "first:TimeTable:1-1:LOC" + object.attributes = {objectid: id} + object.save + expect(object.objectid).to eq(id) + end + + it 'should create a new objectid when cleared' do + object.save + object.attributes = { objectid: nil} + object.save + expect(object.objectid).to be_truthy + end + end + end + end + end + + context 'when referential has an objectid format of netex' do + before(:all) do + Referential.first.update(objectid_format: 'netex') + end + + let(:object) { create(:time_table, objectid: nil) } + + + context "#objectid_format" do + it "should be netex" do + expect(object.referential.objectid_format).to eq('netex') + end + end + + context "#get_objectid" do + + it "should be valid" do + expect(object.get_objectid).to be_valid + end + + it "should have the same local id than the object" do + expect(object.get_objectid.local_id).to match(/\w+-\w+-\w+-\w+-\w+/) + end + + it "should be a Chouette::Objectid::StifNetex" do + expect(object.get_objectid).to be_kind_of(Chouette::Objectid::Netex) + end + + context "#to_s" do + it "should return a string" do + expect(object.get_objectid.to_s).to be_kind_of(String) + end + + it "should be the same as the db attribute" do + expect(object.get_objectid.to_s).to eq(object.read_attribute(:objectid)) + expect(object.get_objectid.to_s).to eq(object.objectid) + end + + context "#objectid" do + + it 'should build objectid on create' do + object.save + object.run_callbacks(:commit) + objectid = object.get_objectid + id = "#{objectid.provider_id}:#{objectid.object_type}:#{objectid.local_id}:#{objectid.creation_id}" + expect(object.read_attribute(:objectid)).to eq(id) + end + + it 'should not build new objectid is already set' do + id = "first:TimeTable:1-1:LOC" + object.attributes = {objectid: id} + object.save + expect(object.objectid).to eq(id) + end + + it 'should create a new objectid when cleared' do + object.save + object.attributes = { objectid: nil} + object.save + expect(object.objectid).to be_truthy + end + end + end + end + end + +end
\ No newline at end of file diff --git a/spec/models/line_referential_spec.rb b/spec/models/line_referential_spec.rb index 8f8714f8f..46434a7ab 100644 --- a/spec/models/line_referential_spec.rb +++ b/spec/models/line_referential_spec.rb @@ -7,5 +7,6 @@ RSpec.describe LineReferential, type: :model do it { is_expected.to have_many(:line_referential_syncs) } it { is_expected.to have_many(:workbenches) } it { should validate_presence_of(:sync_interval) } + it { should validate_presence_of(:objectid_format) } end diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb index ad9c43010..d0b1d6447 100644 --- a/spec/models/referential_spec.rb +++ b/spec/models/referential_spec.rb @@ -12,6 +12,12 @@ describe Referential, :type => :model do it { should belong_to(:workbench) } it { should belong_to(:referential_suite) } + context "validation" do + subject { build_stubbed(:referential) } + + it { should validate_presence_of(:objectid_format) } + end + context ".referential_ids_in_periode" do it 'should retrieve referential id in periode range' do range = ref.metadatas.first.periodes.sample diff --git a/spec/models/stop_area_referential_spec.rb b/spec/models/stop_area_referential_spec.rb index 271badff8..dd2bdce20 100644 --- a/spec/models/stop_area_referential_spec.rb +++ b/spec/models/stop_area_referential_spec.rb @@ -7,4 +7,5 @@ RSpec.describe StopAreaReferential, :type => :model do it { is_expected.to have_many(:stop_area_referential_syncs) } it { is_expected.to have_many(:workbenches) } + it { should validate_presence_of(:objectid_format) } end diff --git a/spec/models/workbench_spec.rb b/spec/models/workbench_spec.rb index 037537b60..3b9ed6b07 100644 --- a/spec/models/workbench_spec.rb +++ b/spec/models/workbench_spec.rb @@ -7,6 +7,7 @@ RSpec.describe Workbench, :type => :model do it { should validate_presence_of(:name) } it { should validate_presence_of(:organisation) } + it { should validate_presence_of(:objectid_format) } it { should belong_to(:organisation) } it { should belong_to(:line_referential) } diff --git a/spec/policies/company_policy_spec.rb b/spec/policies/company_policy_spec.rb index 2d249a2be..e018902ca 100644 --- a/spec/policies/company_policy_spec.rb +++ b/spec/policies/company_policy_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe CompanyPolicy, type: :policy do let( :record ){ build_stubbed :company } @@ -24,19 +25,19 @@ RSpec.describe CompanyPolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'always forbidden', 'companies.create', archived: true + it_behaves_like 'permitted policy', 'companies.create' end permissions :destroy? do - it_behaves_like 'always forbidden', 'companies.destroy', archived: true + it_behaves_like 'permitted policy', 'companies.destroy' end permissions :edit? do - it_behaves_like 'always forbidden', 'companies.update', archived: true + it_behaves_like 'permitted policy', 'companies.update' end permissions :new? do - it_behaves_like 'always forbidden', 'companies.create', archived: true + it_behaves_like 'permitted policy', 'companies.create' end permissions :update? do - it_behaves_like 'always forbidden', 'companies.update', archived: true + it_behaves_like 'permitted policy', 'companies.update' end end end diff --git a/spec/policies/import_policy_spec.rb b/spec/policies/import_policy_spec.rb index fd9f3172c..9c7fca8a5 100644 --- a/spec/policies/import_policy_spec.rb +++ b/spec/policies/import_policy_spec.rb @@ -9,10 +9,10 @@ RSpec.describe ImportPolicy, type: :policy do context 'Non Destructive actions →' do permissions :index? do - it_behaves_like 'always allowed', 'anything', archived: true + it_behaves_like 'always allowed', 'anything' end permissions :show? do - it_behaves_like 'always allowed', 'anything', archived: true + it_behaves_like 'always allowed', 'anything' end end @@ -23,19 +23,19 @@ RSpec.describe ImportPolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'permitted policy', 'imports.create', archived: true + it_behaves_like 'permitted policy', 'imports.create' end permissions :destroy? do - it_behaves_like 'permitted policy', 'imports.destroy', archived: true + it_behaves_like 'always forbidden', 'imports.destroy' end permissions :edit? do - it_behaves_like 'permitted policy', 'imports.update', archived: true + it_behaves_like 'permitted policy', 'imports.update' end permissions :new? do - it_behaves_like 'permitted policy', 'imports.create', archived: true + it_behaves_like 'permitted policy', 'imports.create' end permissions :update? do - it_behaves_like 'permitted policy', 'imports.update', archived: true + it_behaves_like 'permitted policy', 'imports.update' end end end diff --git a/spec/policies/line_policy_spec.rb b/spec/policies/line_policy_spec.rb index 334073506..452606bcf 100644 --- a/spec/policies/line_policy_spec.rb +++ b/spec/policies/line_policy_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe LinePolicy, type: :policy do let( :record ){ build_stubbed :line } @@ -24,19 +25,19 @@ RSpec.describe LinePolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'always forbidden', 'lines.create', archived: true + it_behaves_like 'permitted policy', 'lines.create' end permissions :destroy? do - it_behaves_like 'always forbidden', 'lines.destroy', archived: true + it_behaves_like 'permitted policy', 'lines.destroy' end permissions :edit? do - it_behaves_like 'always forbidden', 'lines.update', archived: true + it_behaves_like 'permitted policy', 'lines.update' end permissions :new? do - it_behaves_like 'always forbidden', 'lines.create', archived: true + it_behaves_like 'permitted policy', 'lines.create' end permissions :update? do - it_behaves_like 'always forbidden', 'lines.update', archived: true + it_behaves_like 'permitted policy', 'lines.update' end end diff --git a/spec/policies/network_policy_spec.rb b/spec/policies/network_policy_spec.rb index ae4ffa03a..c09546c22 100644 --- a/spec/policies/network_policy_spec.rb +++ b/spec/policies/network_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe NetworkPolicy, type: :policy do +RSpec.describe Chouette::NetworkPolicy, type: :policy do let( :record ){ build_stubbed :network } before { stub_policy_scope(record) } diff --git a/spec/policies/route_policy_spec.rb b/spec/policies/route_policy_spec.rb index d7edceaef..df2e41a89 100644 --- a/spec/policies/route_policy_spec.rb +++ b/spec/policies/route_policy_spec.rb @@ -1,4 +1,4 @@ -RSpec.describe RoutePolicy, type: :policy do +RSpec.describe Chouette::RoutePolicy, type: :policy do let( :record ){ build_stubbed :route } diff --git a/spec/policies/stop_area_policy_spec.rb b/spec/policies/stop_area_policy_spec.rb index 8fe59c8e3..90835d1d8 100644 --- a/spec/policies/stop_area_policy_spec.rb +++ b/spec/policies/stop_area_policy_spec.rb @@ -1,3 +1,4 @@ +# coding: utf-8 RSpec.describe StopAreaPolicy, type: :policy do let( :record ){ build_stubbed :stop_area } @@ -24,19 +25,19 @@ RSpec.describe StopAreaPolicy, type: :policy do context 'Destructive actions →' do permissions :create? do - it_behaves_like 'always forbidden', 'stop_areas.create', archived: true + it_behaves_like 'permitted policy', 'stop_areas.create' end permissions :destroy? do - it_behaves_like 'always forbidden', 'stop_areas.destroy', archived: true + it_behaves_like 'permitted policy', 'stop_areas.destroy' end permissions :edit? do - it_behaves_like 'always forbidden', 'stop_areas.update', archived: true + it_behaves_like 'permitted policy', 'stop_areas.update' end permissions :new? do - it_behaves_like 'always forbidden', 'stop_areas.create', archived: true + it_behaves_like 'permitted policy', 'stop_areas.create' end permissions :update? do - it_behaves_like 'always forbidden', 'stop_areas.update', archived: true + it_behaves_like 'permitted policy', 'stop_areas.update' end end end diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 6d9f4a4a2..47578405e 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -3,6 +3,7 @@ ENV["RAILS_ENV"] ||= 'test' require 'spec_helper' require File.expand_path("../../config/environment", __FILE__) require 'rspec/rails' + # Add additional requires below this line. Rails is not loaded until this point! # Requires supporting ruby files with custom matchers and macros, etc, in diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 6b37b9fa8..9679952df 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -34,6 +34,7 @@ require 'webmock/rspec' require 'simplecov' require 'sidekiq/testing' Sidekiq::Testing.fake! +require 'paper_trail/frameworks/rspec' # Requires supporting ruby files with custom matchers and macros, etc, in # spec/support/ and its subdirectories. Files matching `spec/**/*_spec.rb` are diff --git a/spec/support/referential.rb b/spec/support/referential.rb index 6f60bd86b..b615491da 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -46,9 +46,11 @@ RSpec.configure do |config| organisation = Organisation.create!(code: "first", name: "first") line_referential = LineReferential.find_or_create_by(name: "first") do |referential| + referential.objectid_format = "stif_codifligne" referential.add_member organisation, owner: true end stop_area_referential = StopAreaReferential.find_or_create_by(name: "first") do |referential| + referential.objectid_format = "stif_reflex" referential.add_member organisation, owner: true end @@ -65,7 +67,8 @@ RSpec.configure do |config| name: "first", slug: "first", organisation: organisation, - workbench: workbench + workbench: workbench, + objectid_format: "stif_netex" ) end diff --git a/spec/views/companies/edit.html.erb_spec.rb b/spec/views/companies/edit.html.erb_spec.rb index 4566ed64c..8aaf705ab 100644 --- a/spec/views/companies/edit.html.erb_spec.rb +++ b/spec/views/companies/edit.html.erb_spec.rb @@ -6,13 +6,6 @@ describe "/companies/edit", :type => :view do let!(:companies) { Array.new(2) { create(:company) } } let!(:line_referential) { assign :line_referential, company.line_referential } - describe "test" do - it "should render h2 with the company name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(company.name)) - end - end - describe "form" do it "should render input for name" do render @@ -21,5 +14,4 @@ describe "/companies/edit", :type => :view do end end end - end diff --git a/spec/views/companies/show.html.erb_spec.rb b/spec/views/companies/show.html.erb_spec.rb index dbc544f63..aeb93aebb 100644 --- a/spec/views/companies/show.html.erb_spec.rb +++ b/spec/views/companies/show.html.erb_spec.rb @@ -5,24 +5,8 @@ describe "/companies/show", :type => :view do let!(:company) { assign(:company, create(:company)) } let!(:line_referential) { assign :line_referential, company.line_referential } - it "should render h1 with the company name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(company.name)) - end - # it "should display a map with class 'company'" do # render # expect(rendered).to have_selector("#map", :class => 'company') # end - - it "should render a link to edit the company" do - render - expect(rendered).to have_selector("a[href='#{view.edit_line_referential_company_path(line_referential, company)}']") - end - - it "should render a link to remove the company" do - render - expect(rendered).to have_selector("a[href='#{view.line_referential_company_path(line_referential, company)}']") - end - end diff --git a/spec/views/lines/edit.html.erb_spec.rb b/spec/views/lines/edit.html.erb_spec.rb index 6cd2940f5..2af4df10a 100644 --- a/spec/views/lines/edit.html.erb_spec.rb +++ b/spec/views/lines/edit.html.erb_spec.rb @@ -8,13 +8,6 @@ describe "/lines/edit", :type => :view do let!(:lines) { Array.new(2) { create(:line, :network => network, :company => company) } } let!(:line_referential) { assign :line_referential, line.line_referential } - describe "test" do - it "should render h2 with the group name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(line.name)) - end - end - describe "form" do it "should render input for name" do render diff --git a/spec/views/lines/show.html.erb_spec.rb b/spec/views/lines/show.html.erb_spec.rb index 7bc120f1a..9649d9c8e 100644 --- a/spec/views/lines/show.html.erb_spec.rb +++ b/spec/views/lines/show.html.erb_spec.rb @@ -17,25 +17,4 @@ describe "/lines/show", :type => :view do before do allow(view).to receive_messages(current_organisation: referential.organisation) end - - it "should render h1 with the line name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(line.name)) - end - - # it "should display a map with class 'line'" do - # render - # expect(rendered).to have_selector("#map", :class => 'line') - # end - # FIXME #2018 - xit "should render a link to edit the line" do - render - expect(rendered).to have_selector("a[href='#{view.edit_line_referential_line_path(line_referential, line)}']") - end - - it "should render a link to remove the line" do - render - expect(rendered).to have_selector("a[href='#{view.line_referential_line_path(line_referential, line)}']") - end - end diff --git a/spec/views/networks/edit.html.erb_spec.rb b/spec/views/networks/edit.html.erb_spec.rb index f77459837..aac6d4d28 100644 --- a/spec/views/networks/edit.html.erb_spec.rb +++ b/spec/views/networks/edit.html.erb_spec.rb @@ -5,13 +5,6 @@ describe "/networks/edit", :type => :view do let!(:network) { assign(:network, create(:network) ) } let!(:line_referential) { assign :line_referential, network.line_referential } - describe "test" do - it "should render h2 with the group name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(network.name)) - end - end - describe "form" do it "should render input for name" do render diff --git a/spec/views/networks/show.html.erb_spec.rb b/spec/views/networks/show.html.erb_spec.rb index 72605fb46..3926ead14 100644 --- a/spec/views/networks/show.html.erb_spec.rb +++ b/spec/views/networks/show.html.erb_spec.rb @@ -11,24 +11,8 @@ describe "/networks/show", :type => :view do let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } let!(:line_referential) { assign :line_referential, network.line_referential } - it "should render h1 with the network name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(network.name)) - end - # it "should display a map with class 'network'" do # render # expect(rendered).to have_selector("#map") # end - - it "should render a link to edit the network" do - render - expect(rendered).to have_selector("a[href='#{view.edit_line_referential_network_path(line_referential, network)}']") - end - - it "should render a link to remove the network" do - render - expect(rendered).to have_selector("a[href='#{view.line_referential_network_path(line_referential, network)}']") - end - end diff --git a/spec/views/routes/show.html.erb_spec.rb b/spec/views/routes/show.html.erb_spec.rb index dae8c9ed3..3bbfaa799 100644 --- a/spec/views/routes/show.html.erb_spec.rb +++ b/spec/views/routes/show.html.erb_spec.rb @@ -22,20 +22,4 @@ RSpec.describe "/routes/show", type: :view do referential )) end - - it "should render h1 with the route name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(route.name)) - end - - it "should render a link to edit the route" do - render - expect(rendered).to have_selector("a[href='#{view.edit_referential_line_route_path(referential, line, route)}']") - end - - it "should render a link to remove the route" do - render - expect(rendered).to have_selector("a[href='#{view.referential_line_route_path(referential, line, route)}']") - end - end diff --git a/spec/views/stop_areas/edit.html.erb_spec.rb b/spec/views/stop_areas/edit.html.erb_spec.rb index 664225203..5105bff4b 100644 --- a/spec/views/stop_areas/edit.html.erb_spec.rb +++ b/spec/views/stop_areas/edit.html.erb_spec.rb @@ -6,13 +6,6 @@ describe "/stop_areas/edit", :type => :view do let!(:stop_area) { assign(:stop_area, create(:stop_area)) } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } - describe "test" do - it "should render h2 with the group name" do - render - expect(rendered).to have_selector("h2", :text => Regexp.new(stop_area.name)) - end - end - describe "form" do it "should render input for name" do render diff --git a/spec/views/stop_areas/show.html.erb_spec.rb b/spec/views/stop_areas/show.html.erb_spec.rb index 6fd416128..693d9cf1f 100644 --- a/spec/views/stop_areas/show.html.erb_spec.rb +++ b/spec/views/stop_areas/show.html.erb_spec.rb @@ -7,24 +7,8 @@ describe "/stop_areas/show", :type => :view do let!(:access_points) { assign :access_points, [] } let!(:map) { assign(:map, double(:to_html => '<div id="map"/>'.html_safe)) } - it "should render h1 with the stop_area name" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(stop_area.name)) - end - # it "should display a map with class 'stop_area'" do # render # expect(rendered).to have_selector("#map", :class => 'stop_area') # end - - it "should render a link to edit the stop_area" do - render - expect(rendered).to have_selector("a[href='#{view.edit_stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']") - end - - it "should render a link to remove the stop_area" do - render - expect(rendered).to have_selector("a[href='#{view.stop_area_referential_stop_area_path(stop_area_referential, stop_area)}']") - end - end diff --git a/spec/views/time_tables/edit.html.erb_spec.rb b/spec/views/time_tables/edit.html.erb_spec.rb index c84c5eb74..f431eab7b 100644 --- a/spec/views/time_tables/edit.html.erb_spec.rb +++ b/spec/views/time_tables/edit.html.erb_spec.rb @@ -3,13 +3,5 @@ require 'spec_helper' describe "/time_tables/edit", :type => :view do assign_referential let!(:time_table) { assign(:time_table, create(:time_table) ) } - - describe "test" do - it "should render h1 with the group comment" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(time_table.comment)) - end - end - # No more test for the form, as it is now managed by React/Redux. end diff --git a/spec/views/time_tables/show.html.erb_spec.rb b/spec/views/time_tables/show.html.erb_spec.rb index edfb3f3cc..100c74b90 100644 --- a/spec/views/time_tables/show.html.erb_spec.rb +++ b/spec/views/time_tables/show.html.erb_spec.rb @@ -17,20 +17,4 @@ describe "/time_tables/show", :type => :view do before do allow(view).to receive_messages(current_organisation: referential.organisation) end - - it "should render h2 with the time_table comment" do - render - expect(rendered).to have_selector("h1", :text => Regexp.new(time_table.comment)) - end - - it "should render a link to edit the time_table" do - render - expect(rendered).to have_selector(" a[href='#{view.edit_referential_time_table_path(referential, time_table)}']") - end - - it "should render a link to remove the time_table" do - render - expect(rendered).to have_selector(" a[href='#{view.referential_time_table_path(referential, time_table)}']") - end - end |
