diff options
| -rw-r--r-- | app/assets/javascripts/filters/import.js | 2 | ||||
| -rw-r--r-- | app/controllers/application_controller.rb | 2 | ||||
| -rw-r--r-- | app/controllers/imports_controller.rb | 38 | ||||
| -rw-r--r-- | app/models/chouette/journey_pattern.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/routing_constraint_zone.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/vehicle_journey.rb | 2 | ||||
| -rw-r--r-- | app/models/import.rb | 8 | ||||
| -rw-r--r-- | app/views/imports/_filters.html.slim | 4 | ||||
| -rw-r--r-- | config/locales/imports.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/imports.fr.yml | 1 | ||||
| -rw-r--r-- | lib/stif/reflex_synchronization.rb | 2 | ||||
| -rw-r--r-- | spec/factories/workbenches.rb | 4 | ||||
| -rw-r--r-- | spec/features/users/user_edit_spec.rb | 1 | ||||
| -rw-r--r-- | spec/features/users/user_index_spec.rb | 1 | ||||
| -rw-r--r-- | spec/features/users/user_show_spec.rb | 2 | ||||
| -rw-r--r-- | spec/support/referential.rb | 2 |
17 files changed, 51 insertions, 25 deletions
diff --git a/app/assets/javascripts/filters/import.js b/app/assets/javascripts/filters/import.js index d0b96da10..bb665d5ad 100644 --- a/app/assets/javascripts/filters/import.js +++ b/app/assets/javascripts/filters/import.js @@ -1,6 +1,6 @@ const DateFilter = require('../helpers/date_filters') $(document).ready(function(){ - const importDF = new DateFilter("#import_filter_btn", "Tous les champs du filtre de date doivent être remplis", "#q_started_on_date_NUMi") + const importDF = new DateFilter("#import_filter_btn", "Tous les champs du filtre de date doivent être remplis", "#q_started_at_begin_NUMi", "#q_started_at_end_NUMi") importDF() }) diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 8cb5726c4..853c2f715 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -34,7 +34,7 @@ class ApplicationController < ActionController::Base helper_method :current_organisation def current_offer_workbench - current_organisation.workbenches.where(name: "Gestion de l'offre") + current_organisation.workbenches.find_by_name("Gestion de l'offre") end helper_method :current_offer_workbench diff --git a/app/controllers/imports_controller.rb b/app/controllers/imports_controller.rb index 97a8f91aa..2bd8cc6f4 100644 --- a/app/controllers/imports_controller.rb +++ b/app/controllers/imports_controller.rb @@ -1,7 +1,7 @@ class ImportsController < BreadcrumbController skip_before_action :authenticate_user!, only: [:download] defaults resource_class: Import, collection_name: 'imports', instance_name: 'import' - before_action :ransack_started_on_date, only: [:index] + before_action :ransack_started_at_params, only: [:index] respond_to :html belongs_to :workbench @@ -45,7 +45,11 @@ class ImportsController < BreadcrumbController protected def collection - @q = parent.imports.where(type: "WorkbenchImport").search(params[:q]) + + scope = parent.imports.where(type: "WorkbenchImport") + scope = ransack_period scope + + @q = scope.search(params[:q].try(:except, :started_at)) if sort_column && sort_direction @imports ||= @q.result(distinct: true).order(sort_column + ' ' + sort_direction).paginate(page: params[:page], per_page: 10) @@ -56,15 +60,31 @@ class ImportsController < BreadcrumbController private - def ransack_started_on_date - date =[] - if params[:q] && !params[:q]['started_on_date(1i)'].empty? - ['started_on_date(1i)', 'started_on_date(2i)', 'started_on_date(3i)'].each do |key| - date << params[:q][key].to_i - params[:q].delete(key) + def ransack_started_at_params + start_date = [] + end_date = [] + + if params[:q] && params[:q][:started_at] && !params[:q][:started_at].has_value?(nil) + [1, 2, 3].each do |key| + start_date << params[:q][:started_at]["begin(#{key}i)"].to_i + end_date << params[:q][:started_at]["end(#{key}i)"].to_i end - params[:q]['started_on_date'] = DateTime.new(*date) rescue nil + params[:q].delete([:started_at]) + @begin_range = DateTime.new(*start_date,0,0,0) rescue nil + @end_range = DateTime.new(*end_date,23,59,59) rescue nil + end + end + + # Fake ransack filter + def ransack_period scope + return scope unless !!@begin_range && !!@end_range + + if @begin_range > @end_range + flash.now[:error] = t('imports.filters.error_period_filter') + else + scope = scope.where_started_at_between(@begin_range, @end_range) end + scope end def build_resource diff --git a/app/models/chouette/journey_pattern.rb b/app/models/chouette/journey_pattern.rb index 2b62d5c7f..fa2a9c8bb 100644 --- a/app/models/chouette/journey_pattern.rb +++ b/app/models/chouette/journey_pattern.rb @@ -23,7 +23,7 @@ class Chouette::JourneyPattern < Chouette::TridentActiveRecord def local_id - "IBOO-#{self.try(:route).try(:line).try(:objectid).try(:local_id)}-#{self.referential.id}-#{self.id}" + "IBOO-#{self.referential.id}-#{self.try(:route).try(:line).try(:objectid).try(:local_id)}-#{self.id}" end def checksum_attributes diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index e361b9e8c..49493d5b5 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -99,7 +99,7 @@ class Chouette::Route < Chouette::TridentActiveRecord end def local_id - "IBOO-#{self.line.objectid.local_id}-#{self.referential.id}-#{self.id}" + "IBOO-#{self.referential.id}-#{self.line.objectid.local_id}-#{self.id}" end def geometry_presenter diff --git a/app/models/chouette/routing_constraint_zone.rb b/app/models/chouette/routing_constraint_zone.rb index 21efa2539..efe1b7237 100644 --- a/app/models/chouette/routing_constraint_zone.rb +++ b/app/models/chouette/routing_constraint_zone.rb @@ -9,7 +9,7 @@ class Chouette::RoutingConstraintZone < Chouette::TridentActiveRecord validate :stop_points_belong_to_route, :not_all_stop_points_selected def local_id - "IBOO-#{self.route.line.objectid.local_id}-#{self.route.objectid.local_id}-#{self.referential.id}-#{self.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 diff --git a/app/models/chouette/vehicle_journey.rb b/app/models/chouette/vehicle_journey.rb index e60afef6e..f574afc93 100644 --- a/app/models/chouette/vehicle_journey.rb +++ b/app/models/chouette/vehicle_journey.rb @@ -57,7 +57,7 @@ module Chouette end def local_id - "IBOO-#{self.route.line.objectid.local_id}-#{self.referential.id}-#{self.id}" + "IBOO-#{self.referential.id}-#{self.route.line.objectid.local_id}-#{self.id}" end def checksum_attributes diff --git a/app/models/import.rb b/app/models/import.rb index 55d74c13c..74f7ef10c 100644 --- a/app/models/import.rb +++ b/app/models/import.rb @@ -9,7 +9,9 @@ class Import < ActiveRecord::Base has_many :resources, class_name: "ImportResource", dependent: :destroy has_many :children, foreign_key: :parent_id, class_name: "Import", dependent: :destroy - scope :started_on_date, ->(date) { where('started_at BETWEEN ? AND ?', date.beginning_of_day, date.end_of_day) } + scope :where_started_at_between, ->(start_date, end_date) do + where('started_at BETWEEN ? AND ?', start_date, end_date) + end extend Enumerize enumerize :status, in: %i(new pending successful warning failed running aborted canceled), scope: true, default: :new @@ -19,10 +21,6 @@ class Import < ActiveRecord::Base before_create :initialize_fields - def self.ransackable_scopes(auth_object = nil) - [:started_on_date] - end - def self.model_name ActiveModel::Name.new Import, Import, "Import" end diff --git a/app/views/imports/_filters.html.slim b/app/views/imports/_filters.html.slim index a216019b6..a5488b275 100644 --- a/app/views/imports/_filters.html.slim +++ b/app/views/imports/_filters.html.slim @@ -14,7 +14,9 @@ .form-group.togglable = f.label Import.human_attribute_name(:started_at), required: false, class: 'control-label' .filter_menu - = f.input :started_on_date, as: :date, label: false, wrapper_html: { class: 'date smart_date filter_menu-item' }, include_blank: true + = f.simple_fields_for :started_at do |p| + = p.input :begin, 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, as: :date, label: false, wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true .actions = link_to t('actions.erase'), workbench_imports_path(@workbench), class: 'btn btn-link' diff --git a/config/locales/imports.en.yml b/config/locales/imports.en.yml index b92b8843f..9bf877c86 100644 --- a/config/locales/imports.en.yml +++ b/config/locales/imports.en.yml @@ -4,6 +4,7 @@ en: filters: referential: "Select data space..." name_or_creator_cont: "Select an import or creator name..." + error_period_filter: "End date must be greater or equal than begin date" actions: new: "New import" show: "Import report" diff --git a/config/locales/imports.fr.yml b/config/locales/imports.fr.yml index f7bf8c178..6998c89d2 100644 --- a/config/locales/imports.fr.yml +++ b/config/locales/imports.fr.yml @@ -4,6 +4,7 @@ fr: filters: referential: "Sélectionnez un jeu de données..." name_or_creator_cont: "Indiquez un nom d'import ou d'opérateur..." + error_period_filter: "La date de fin doit être supérieure ou égale à la date de début" actions: new: "Nouvel import" show: "Rapport d'import" diff --git a/lib/stif/reflex_synchronization.rb b/lib/stif/reflex_synchronization.rb index b3f474221..a3bf3957e 100644 --- a/lib/stif/reflex_synchronization.rb +++ b/lib/stif/reflex_synchronization.rb @@ -38,7 +38,7 @@ module Stif if object.valid? object.save else - Rails.logger.error "Reflex:sync - #{object.class.model_name} with objectid #{object.objectid} and name #{object.name} can't be saved" + Rails.logger.error "Reflex:sync - #{object.class.model_name} with objectid #{object.objectid} can't be saved - errors : #{object.errors.messages}" end end diff --git a/spec/factories/workbenches.rb b/spec/factories/workbenches.rb index f51e7d94c..d55141513 100644 --- a/spec/factories/workbenches.rb +++ b/spec/factories/workbenches.rb @@ -1,8 +1,8 @@ FactoryGirl.define do factory :workbench do - sequence(:name) { |n| "Workbench #{n}" } + name "Gestion de l'offre" - association :organisation, :factory => :organisation + association :organisation association :line_referential association :stop_area_referential end diff --git a/spec/features/users/user_edit_spec.rb b/spec/features/users/user_edit_spec.rb index 4b083a226..14995d8e5 100644 --- a/spec/features/users/user_edit_spec.rb +++ b/spec/features/users/user_edit_spec.rb @@ -36,6 +36,7 @@ feature 'User edit', :devise do # Then I see my own 'edit profile' page scenario "user cannot cannot edit another user's profile", :me do me = FactoryGirl.create(:user) + me.organisation.workbenches << create(:workbench) other = FactoryGirl.create(:user, email: 'other@example.com') login_as(me, :scope => :user) visit edit_user_registration_path(other) diff --git a/spec/features/users/user_index_spec.rb b/spec/features/users/user_index_spec.rb index 2a9199da3..b2dbdbb51 100644 --- a/spec/features/users/user_index_spec.rb +++ b/spec/features/users/user_index_spec.rb @@ -19,6 +19,7 @@ feature 'User index page', :devise do # Then I see my own email address scenario 'user sees own email address' do user = create(:user) + user.organisation.workbenches << create(:workbench) login_as(user, scope: :user) visit organisation_path expect(page).to have_content user.name.truncate(15) diff --git a/spec/features/users/user_show_spec.rb b/spec/features/users/user_show_spec.rb index d840d752c..ae3c25933 100644 --- a/spec/features/users/user_show_spec.rb +++ b/spec/features/users/user_show_spec.rb @@ -19,6 +19,7 @@ feature 'User profile page', :devise do # Then I see my own email address scenario 'user sees own profile' do user = FactoryGirl.create(:user) + user.organisation.workbenches << create(:workbench) login_as(user, :scope => :user) visit organisation_user_path(user) # FIXME ref #819 @@ -32,6 +33,7 @@ feature 'User profile page', :devise do # Then I see an 'access denied' message scenario "user cannot see another user's profile" do me = FactoryGirl.create(:user) + me.organisation.workbenches << create(:workbench) other = FactoryGirl.create(:user, email: 'other@example.com', :organisation => me.organisation) login_as(me, :scope => :user) Capybara.current_session.driver.header 'Referer', authenticated_root_path diff --git a/spec/support/referential.rb b/spec/support/referential.rb index c431856b8..3b74cb639 100644 --- a/spec/support/referential.rb +++ b/spec/support/referential.rb @@ -52,7 +52,7 @@ RSpec.configure do |config| referential.add_member organisation, owner: true end - workbench = Workbench.create!(:name => "first", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential) + workbench = Workbench.create!(:name => "Gestion de l'offre", organisation: organisation, line_referential: line_referential, stop_area_referential: stop_area_referential) referential = Referential.create! prefix: "first", name: "first", slug: "first", organisation: organisation, workbench: workbench end |
