aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-06-09 17:53:29 +0200
committerRobert2017-06-09 17:53:29 +0200
commitf9b43e0c29276da72a1db1d0715d191b3015a115 (patch)
tree83042b5e6f1ceb2d2bd443f0f7120c7323f60a42
parent63a893c22feca2c26cd8eecef2e6deb8ff97bd26 (diff)
parent63a1f4c60a465f8f57dc9ea406ddd52e37cbfeaf (diff)
downloadchouette-core-f9b43e0c29276da72a1db1d0715d191b3015a115.tar.bz2
Merge branch 'master' into 3604_clonage_missing_data
-rw-r--r--app/assets/javascripts/es6_browserified/journey_patterns/components/CreateModal.js151
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/actions/index.js4
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/components/ConfirmModal.js4
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/containers/ConfirmModal.js5
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js3
-rw-r--r--app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js7
-rw-r--r--app/assets/javascripts/es6_browserified/vehicle_journeys/index.js14
-rw-r--r--app/assets/stylesheets/components/_tables.sass60
-rw-r--r--app/controllers/routing_constraint_zones_controller.rb46
-rw-r--r--app/helpers/newapplication_helper.rb2
-rw-r--r--app/models/chouette/time_table.rb4
-rw-r--r--app/models/chouette/time_table_date.rb2
-rw-r--r--app/models/clean_up.rb101
-rw-r--r--app/views/referential_lines/index.js.slim1
-rw-r--r--app/views/referential_lines/show.html.slim13
-rw-r--r--app/views/routing_constraint_zones/_filters.html.slim16
-rw-r--r--app/views/routing_constraint_zones/_form.html.slim25
-rw-r--r--app/views/routing_constraint_zones/edit.html.slim15
-rw-r--r--app/views/routing_constraint_zones/index.html.slim37
-rw-r--r--app/views/routing_constraint_zones/new.html.slim13
-rw-r--r--app/views/routing_constraint_zones/show.html.slim44
-rw-r--r--app/views/time_tables/index.html.slim2
-rw-r--r--app/views/time_tables/show.html.slim1
-rw-r--r--config/locales/actions.en.yml1
-rw-r--r--config/locales/actions.fr.yml1
-rw-r--r--config/locales/routing_constraint_zones.en.yml6
-rw-r--r--config/locales/routing_constraint_zones.fr.yml12
-rw-r--r--db/migrate/20170607141031_change_begin_date_from_clean_ups.rb9
-rw-r--r--db/migrate/20170607141317_change_end_date_from_clean_ups.rb9
-rw-r--r--db/schema.rb10
-rw-r--r--spec/factories/chouette_time_table.rb1
-rw-r--r--spec/factories/clean_ups.rb13
-rw-r--r--spec/features/routing_constraint_zones_spec.rb4
-rw-r--r--spec/javascripts/time_table/reducers/pagination_spec.js7
-rw-r--r--spec/models/clean_up_spec.rb224
35 files changed, 663 insertions, 204 deletions
diff --git a/app/assets/javascripts/es6_browserified/journey_patterns/components/CreateModal.js b/app/assets/javascripts/es6_browserified/journey_patterns/components/CreateModal.js
index aa2d208df..0ed8660d5 100644
--- a/app/assets/javascripts/es6_browserified/journey_patterns/components/CreateModal.js
+++ b/app/assets/javascripts/es6_browserified/journey_patterns/components/CreateModal.js
@@ -22,90 +22,91 @@ class CreateModal extends Component {
}
if(this.props.status.fetchSuccess == true) {
return (
- <div className='row mt-md'>
- <div className='col-lg-12 text-right'>
- <button
- type='button'
- className='btn btn-outline-primary'
- data-toggle='modal'
- data-target='#NewJourneyPatternModal'
- onClick={this.props.onOpenCreateModal}
- >
- Ajouter une mission
- </button>
+ <div className="select_toolbox">
+ <ul>
+ <li className='st_action'>
+ <button
+ type='button'
+ data-toggle='modal'
+ data-target='#NewJourneyPatternModal'
+ onClick={this.props.onOpenCreateModal}
+ >
+ <span className="fa fa-plus"></span>
+ </button>
- <div className={ 'modal fade ' + ((this.props.modal.type == 'create') ? 'in' : '') } id='NewJourneyPatternModal'>
- <div className='modal-container'>
- <div className='modal-dialog'>
- <div className='modal-content'>
- <div className='modal-header'>
- <h4 className='modal-title'>Ajouter une mission</h4>
- </div>
+ <div className={ 'modal fade ' + ((this.props.modal.type == 'create') ? 'in' : '') } id='NewJourneyPatternModal'>
+ <div className='modal-container'>
+ <div className='modal-dialog'>
+ <div className='modal-content'>
+ <div className='modal-header'>
+ <h4 className='modal-title'>Ajouter une mission</h4>
+ </div>
- {(this.props.modal.type == 'create') && (
- <form>
- <div className='modal-body'>
- <div className='form-group'>
- <label className='control-label is-required'>Nom</label>
- <input
- type='text'
- ref='name'
- className='form-control'
- onKeyDown={(e) => actions.resetValidation(e.currentTarget)}
- required
- />
- </div>
- <div className='row'>
- <div className='col-lg-6 col-md-6 col-sm-6 col-xs-6'>
- <div className='form-group'>
- <label className='control-label is-required'>Nom public</label>
- <input
- type='text'
- ref='published_name'
- className='form-control'
- onKeyDown={(e) => actions.resetValidation(e.currentTarget)}
- required
- />
- </div>
+ {(this.props.modal.type == 'create') && (
+ <form>
+ <div className='modal-body'>
+ <div className='form-group'>
+ <label className='control-label is-required'>Nom</label>
+ <input
+ type='text'
+ ref='name'
+ className='form-control'
+ onKeyDown={(e) => actions.resetValidation(e.currentTarget)}
+ required
+ />
</div>
- <div className='col-lg-6 col-md-6 col-sm-6 col-xs-6'>
- <div className='form-group'>
- <label className='control-label is-required'>Code mission</label>
- <input
- type='text'
- ref='registration_number'
- className='form-control'
- onKeyDown={(e) => actions.resetValidation(e.currentTarget)}
- required
- />
+ <div className='row'>
+ <div className='col-lg-6 col-md-6 col-sm-6 col-xs-6'>
+ <div className='form-group'>
+ <label className='control-label is-required'>Nom public</label>
+ <input
+ type='text'
+ ref='published_name'
+ className='form-control'
+ onKeyDown={(e) => actions.resetValidation(e.currentTarget)}
+ required
+ />
+ </div>
+ </div>
+ <div className='col-lg-6 col-md-6 col-sm-6 col-xs-6'>
+ <div className='form-group'>
+ <label className='control-label is-required'>Code mission</label>
+ <input
+ type='text'
+ ref='registration_number'
+ className='form-control'
+ onKeyDown={(e) => actions.resetValidation(e.currentTarget)}
+ required
+ />
+ </div>
</div>
</div>
</div>
- </div>
- <div className='modal-footer'>
- <button
- className='btn btn-link'
- data-dismiss='modal'
- type='button'
- onClick={this.props.onModalClose}
- >
- Annuler
- </button>
- <button
- className='btn btn-primary'
- type='button'
- onClick={this.handleSubmit.bind(this)}
- >
- Valider
- </button>
- </div>
- </form>
- )}
+ <div className='modal-footer'>
+ <button
+ className='btn btn-link'
+ data-dismiss='modal'
+ type='button'
+ onClick={this.props.onModalClose}
+ >
+ Annuler
+ </button>
+ <button
+ className='btn btn-primary'
+ type='button'
+ onClick={this.handleSubmit.bind(this)}
+ >
+ Valider
+ </button>
+ </div>
+ </form>
+ )}
+ </div>
</div>
</div>
</div>
- </div>
- </div>
+ </li>
+ </ul>
</div>
)
} else {
diff --git a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
index 41d247b21..0a6e7e1dc 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/actions/index.js
@@ -201,8 +201,8 @@ const actions = {
start = new Date(start)
end = new Date(end)
_.each(periods, (period, i) => {
- if(index != i && !period.deleted){
- if((new Date(period.period_start) <= start && new Date(period.period_end) >= start) || (new Date(period.period_start) <= end && new Date(period.period_end) >= end))
+ if(index !== i && !period.deleted){
+ if((new Date(period.period_start) <= start && new Date(period.period_end) >= start) || (new Date(period.period_start) <= end && new Date(period.period_end) >= end) || (start >= new Date(period.period_start) && end <= new Date(period.period_end)) || (start <= new Date(period.period_start) && end >= new Date(period.period_end)))
error = 'Les périodes ne peuvent pas se chevaucher'
}
})
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/ConfirmModal.js b/app/assets/javascripts/es6_browserified/time_tables/components/ConfirmModal.js
index c2229d991..40ae0eccf 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/components/ConfirmModal.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/components/ConfirmModal.js
@@ -2,7 +2,7 @@ var React = require('react')
var Component = require('react').Component
var PropTypes = require('react').PropTypes
-const ConfirmModal = ({dispatch, modal, onModalAccept, onModalCancel, journeyPatterns}) => (
+const ConfirmModal = ({dispatch, modal, onModalAccept, onModalCancel, timetable, metas}) => (
<div className={ 'modal fade ' + ((modal.type == 'confirm') ? 'in' : '') } id='ConfirmModal'>
<div className='modal-container'>
<div className='modal-dialog'>
@@ -28,7 +28,7 @@ const ConfirmModal = ({dispatch, modal, onModalAccept, onModalCancel, journeyPat
className='btn btn-primary'
data-dismiss='modal'
type='button'
- onClick = {() => {onModalAccept(modal.confirmModal.callback, journeyPatterns)}}
+ onClick = {() => {onModalAccept(modal.confirmModal.callback, timetable, metas)}}
>
Valider
</button>
diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/ConfirmModal.js b/app/assets/javascripts/es6_browserified/time_tables/containers/ConfirmModal.js
index 8095e1e7c..6282c1d1d 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/containers/ConfirmModal.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/containers/ConfirmModal.js
@@ -5,13 +5,14 @@ var ConfirmModal = require('../components/ConfirmModal')
const mapStateToProps = (state) => {
return {
modal: state.modal,
- journeyPatterns: state.journeyPatterns
+ timetable: state.timetable,
+ metas: state.metas
}
}
const mapDispatchToProps = (dispatch) => {
return {
- onModalAccept: (next, timetable, metas, state) =>{
+ onModalAccept: (next, timetable, metas) =>{
dispatch(actions.fetchingApi())
actions.submitTimetable(dispatch, timetable, metas, next)
},
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js
index 4f1e7a528..2ce084efd 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js
@@ -12,6 +12,9 @@ const metas = (state = {}, action) => {
color: action.json.color,
calendar: action.json.calendar ? action.json.calendar : null
})
+ case 'RECEIVE_MONTH':
+ let dt = (typeof state.day_types === 'string') ? actions.strToArrayDayTypes(state.day_types) : state.day_types
+ return _.assign({}, state, {day_types: dt})
case 'INCLUDE_DATE_IN_PERIOD':
case 'EXCLUDE_DATE_FROM_PERIOD':
case 'DELETE_PERIOD':
diff --git a/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js b/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
index 660484c58..3d96fb7b7 100644
--- a/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
+++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/pagination.js
@@ -5,8 +5,12 @@ const pagination = (state = {}, action) => {
case 'RECEIVE_TIME_TABLES':
return _.assign({}, state, {
currentPage: action.json.current_periode_range,
- periode_range: action.json.periode_range
+ periode_range: action.json.periode_range,
+ stateChanged: false
})
+ case 'RECEIVE_MONTH':
+ case 'RECEIVE_ERRORS':
+ return _.assign({}, state, {stateChanged: false})
case 'GO_TO_PREVIOUS_PAGE':
case 'GO_TO_NEXT_PAGE':
let nextPage = action.nextPage ? 1 : -1
@@ -22,7 +26,6 @@ const pagination = (state = {}, action) => {
case 'VALIDATE_PERIOD_FORM':
case 'UPDATE_COMMENT':
case 'UPDATE_COLOR':
- case 'UPDATE_DAY_TYPES':
toggleOnConfirmModal('modal')
return _.assign({}, state, {stateChanged: true})
default:
diff --git a/app/assets/javascripts/es6_browserified/vehicle_journeys/index.js b/app/assets/javascripts/es6_browserified/vehicle_journeys/index.js
index ba27ca72c..97aa60526 100644
--- a/app/assets/javascripts/es6_browserified/vehicle_journeys/index.js
+++ b/app/assets/javascripts/es6_browserified/vehicle_journeys/index.js
@@ -8,10 +8,10 @@ var actions = require("./actions")
var enableBatching = require('./batch').enableBatching
// logger, DO NOT REMOVE
-var applyMiddleware = require('redux').applyMiddleware
-var createLogger = require('redux-logger')
-var thunkMiddleware = require('redux-thunk').default
-var promise = require('redux-promise')
+// var applyMiddleware = require('redux').applyMiddleware
+// var createLogger = require('redux-logger')
+// var thunkMiddleware = require('redux-thunk').default
+// var promise = require('redux-promise')
var selectedJP = []
@@ -85,12 +85,12 @@ if (window.jpOrigin){
initialState.filters.queryString = actions.encodeParams(params)
}
-const loggerMiddleware = createLogger()
+// const loggerMiddleware = createLogger()
let store = createStore(
enableBatching(vehicleJourneysApp),
- initialState,
- applyMiddleware(thunkMiddleware, promise, loggerMiddleware)
+ initialState
+ // applyMiddleware(thunkMiddleware, promise, loggerMiddleware)
)
render(
diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass
index 0cd91a1a8..e3a33e131 100644
--- a/app/assets/stylesheets/components/_tables.sass
+++ b/app/assets/stylesheets/components/_tables.sass
@@ -82,6 +82,66 @@
border-top: 2px solid $darkgrey
margin-top: 15px
+ // Specific for tables displaying stop points
+ &.has-stoppoints
+ tbody
+ > tr > td:first-child
+ position: relative
+ padding-left: 25px
+
+ &:before
+ content: ''
+ display: block
+ width: 10px
+ height: 10px
+ background-color: #fff
+ border: 2px solid $blue
+ border-radius: 50%
+ position: absolute
+ z-index: 5
+ left: 5px
+ top: 50%
+ margin-top: -5px
+
+ &:after
+ content: ''
+ display: block
+ width: 4px
+ margin: 0 3px
+ background-color: rgba($grey, 0.5)
+ position: absolute
+ z-index: 3
+ top: 0
+ left: 5px
+ bottom: 0
+
+ > tr:first-child > td:first-child
+ &:after
+ content: ''
+ top: 50%
+
+ > tr:last-child > td:first-child
+ &:after
+ content: ''
+ bottom: 50%
+
+ > tr:first-child > td:first-child, > tr:last-child > td:first-child
+ &:before
+ content: '•'
+ color: $blue
+ text-align: center
+ font-size: 28px
+ letter-spacing: 0
+ text-indent: -0.01em
+ line-height: 12px
+ width: 15px
+ height: 15px
+ left: 2px
+ top: 50%
+ margin-top: -8px
+
+
+
// select_toolbox
.select_toolbox
padding: 10px
diff --git a/app/controllers/routing_constraint_zones_controller.rb b/app/controllers/routing_constraint_zones_controller.rb
index f2f74e801..b5072f401 100644
--- a/app/controllers/routing_constraint_zones_controller.rb
+++ b/app/controllers/routing_constraint_zones_controller.rb
@@ -1,6 +1,7 @@
class RoutingConstraintZonesController < ChouetteController
- defaults resource_class: Chouette::RoutingConstraintZone
+ include PolicyChecker
+ defaults resource_class: Chouette::RoutingConstraintZone
respond_to :html, :xml, :json
before_action :remove_empty_stop_point, only: [:create, :update]
@@ -9,11 +10,50 @@ class RoutingConstraintZonesController < ChouetteController
belongs_to :line, parent_class: Chouette::Line
end
- include PolicyChecker
+ def index
+ @routing_constraint_zones = collection
+ end
+
+ def show
+ @routing_constraint_zone = collection.find(params[:id])
+ end
+
+ protected
+
+ def collection
+ @q = resource.routing_constraint_zones.search(params[:q])
+
+ if sort_column && sort_direction
+ @routing_constraint_zones ||= @q.result(distinct: true).order(sort_column + ' ' + sort_direction)
+ else
+ @routing_constraint_zones ||= @q.result(distinct: true).order(:name)
+ end
+ @routing_constraint_zones = @routing_constraint_zones.paginate(page: params[:page], per_page: 10)
+ end
private
+ def sort_column
+ (Chouette::RoutingConstraintZone.column_names).include?(params[:sort]) ? params[:sort] : 'name'
+ end
+ def sort_direction
+ %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
+ end
+
+ def resource
+ @referential = Referential.find params[:referential_id]
+ @line = @referential.lines.find params[:line_id]
+ end
+
def routing_constraint_zone_params
- params.require(:routing_constraint_zone).permit(:name, { stop_point_ids: [] }, :line_id, :route_id, :objectid, :object_version, :creator_id)
+ params.require(:routing_constraint_zone).permit(
+ :name,
+ { stop_point_ids: [] },
+ :line_id,
+ :route_id,
+ :objectid,
+ :object_version,
+ :creator_id
+ )
end
def remove_empty_stop_point
diff --git a/app/helpers/newapplication_helper.rb b/app/helpers/newapplication_helper.rb
index f03228d73..3d43e9fc7 100644
--- a/app/helpers/newapplication_helper.rb
+++ b/app/helpers/newapplication_helper.rb
@@ -16,7 +16,7 @@ module NewapplicationHelper
end
columns.map do |k, v|
- if ["ID Codif", "Oid", "OiD", "ID Reflex", "Arrêt de départ", "Arrêt d'arrivée", "Période de validité englobante", "Période englobante", "Nombre de courses associées", "Journées d'application"].include? k
+ if ["ID Codif", "Oid", "OiD", "ID Reflex", "Arrêt de départ", "Arrêt d'arrivée", "Période de validité englobante", "Période englobante", "Nombre de courses associées", "Journées d'application", "Arrêts de l'itinéraire", "Arrêts inclus dans l'ITL"].include? k
hcont << content_tag(:th, k)
else
hcont << content_tag(:th, sortable_columns(collection, k))
diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb
index 2d329bcc6..151570f20 100644
--- a/app/models/chouette/time_table.rb
+++ b/app/models/chouette/time_table.rb
@@ -135,6 +135,10 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord
[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 actualize
self.dates.clear
self.periods.clear
diff --git a/app/models/chouette/time_table_date.rb b/app/models/chouette/time_table_date.rb
index 4624ae88e..b881c9a5d 100644
--- a/app/models/chouette/time_table_date.rb
+++ b/app/models/chouette/time_table_date.rb
@@ -6,6 +6,8 @@ class Chouette::TimeTableDate < Chouette::ActiveRecord
validates_presence_of :date
validates_uniqueness_of :date, :scope => :time_table_id
+ scope :in_dates, -> { where(in_out: true) }
+
def self.model_name
ActiveModel::Name.new Chouette::TimeTableDate, Chouette, "TimeTableDate"
end
diff --git a/app/models/clean_up.rb b/app/models/clean_up.rb
index 457e90b65..a2b150ecc 100644
--- a/app/models/clean_up.rb
+++ b/app/models/clean_up.rb
@@ -15,25 +15,96 @@ class CleanUp < ActiveRecord::Base
end
def clean
- result = {}
- result['time_table_count'] = self.clean_time_tables
- result['vehicle_journey_count'] = self.clean_vehicle_journeys
- result['journey_pattern_count'] = self.clean_journey_patterns
- result
+ {}.tap do |result|
+ result['time_table'] = send("destroy_time_tables_#{self.date_type}").try(:count)
+ result['time_table_date'] = send("destroy_time_tables_dates_#{self.date_type}").try(:count)
+ result['time_table_period'] = send("destroy_time_tables_periods_#{self.date_type}").try(:count)
+ self.overlapping_periods.each do |period|
+ exclude_dates_in_overlapping_period(period)
+ end
+ end
+ end
+
+ def destroy_time_tables_between
+ time_tables = Chouette::TimeTable.where('end_date <= ? AND start_date >= ?', self.end_date, self.begin_date)
+ self.destroy_time_tables(time_tables)
+ end
+
+ def destroy_time_tables_before
+ time_tables = Chouette::TimeTable.where('end_date <= ?', self.begin_date)
+ self.destroy_time_tables(time_tables)
+ end
+
+ def destroy_time_tables_after
+ time_tables = Chouette::TimeTable.where('start_date >= ?', self.begin_date)
+ self.destroy_time_tables(time_tables)
+ end
+
+ def destroy_time_table_dates_before
+ Chouette::TimeTableDate.in_dates.where('date <= ?', self.begin_date).destroy_all
+ end
+
+ def destroy_time_tables_dates_after
+ Chouette::TimeTableDate.in_dates.where('date >= ?', self.begin_date).destroy_all
+ end
+
+ def destroy_time_tables_dates_between
+ Chouette::TimeTableDate.in_dates.where('date >= ? AND date <= ?', self.begin_date, self.end_date).destroy_all
end
- def clean_time_tables
- Chouette::TimeTable.validity_out_between?(begin_date, end_date).delete_all
+ def destroy_time_tables_periods_before
+ Chouette::TimeTablePeriod.where('period_end <= ?', self.begin_date).destroy_all
end
- def clean_vehicle_journeys
- ids = Chouette::VehicleJourney.includes(:time_tables).where(:time_tables => {id: nil}).pluck(:id)
- Chouette::VehicleJourney.where(id: ids).delete_all
+ def destroy_time_tables_periods_after
+ Chouette::TimeTablePeriod.where('period_start >= ?', self.begin_date).destroy_all
end
- def clean_journey_patterns
- ids = Chouette::JourneyPattern.includes(:vehicle_journeys).where(:vehicle_journeys => {id: nil}).pluck(:id)
- Chouette::JourneyPattern.where(id: ids).delete_all
+ def destroy_time_tables_periods_between
+ Chouette::TimeTablePeriod.where('period_start >= ? AND period_end <= ?', self.begin_date, self.end_date).destroy_all
+ end
+
+ def overlapping_periods
+ self.end_date = self.begin_date if self.date_type != 'between'
+ Chouette::TimeTablePeriod.where('(period_start, period_end) OVERLAPS (?, ?)', self.begin_date, self.end_date)
+ end
+
+ def exclude_dates_in_overlapping_period(period)
+ days_in_period = period.period_start..period.period_end
+ day_out = period.time_table.dates.where(in_out: false).map(&:date)
+ # check if day is greater or less then cleanup date
+ if date_type != 'between'
+ operator = date_type == 'after' ? '>' : '<'
+ to_exclude_days = days_in_period.map do |day|
+ day if day.public_send(operator, self.begin_date)
+ end
+ else
+ days_in_cleanup_periode = (self.begin_date..self.end_date)
+ to_exclude_days = days_in_period & days_in_cleanup_periode
+ end
+
+ to_exclude_days.to_a.compact.each do |day|
+ # we ensure day is not already an exclude date
+ if !day_out.include?(day)
+ self.add_exclude_date(period.time_table, day)
+ end
+ end
+ end
+
+ def add_exclude_date(time_table, day)
+ day_in = time_table.dates.where(in_out: true).map(&:date)
+ unless day_in.include?(day)
+ time_table.add_exclude_date(false, day)
+ else
+ time_table.dates.where(date: day).take.update_attribute(:in_out, false)
+ end
+ end
+
+ def destroy_time_tables(time_tables)
+ time_tables.each do |time_table|
+ time_table.vehicle_journeys.map(&:destroy)
+ end
+ time_tables.destroy_all
end
aasm column: :status do
@@ -61,11 +132,11 @@ class CleanUp < ActiveRecord::Base
def log_successful message_attributs
update_attribute(:ended_at, Time.now)
- CleanUpResult.create(clean_up: self, message_key: :successfull, message_attributs: message_attributs)
+ CleanUpResult.create(destroy_up: self, message_key: :successfull, message_attributs: message_attributs)
end
def log_failed message_attributs
update_attribute(:ended_at, Time.now)
- CleanUpResult.create(clean_up: self, message_key: :failed, message_attributs: message_attributs)
+ CleanUpResult.create(destroy_up: self, message_key: :failed, message_attributs: message_attributs)
end
end
diff --git a/app/views/referential_lines/index.js.slim b/app/views/referential_lines/index.js.slim
deleted file mode 100644
index 0165fb077..000000000
--- a/app/views/referential_lines/index.js.slim
+++ /dev/null
@@ -1 +0,0 @@
-| $('#lines').html("#{escape_javascript(render('lines'))}"); \ No newline at end of file
diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim
index 1e24f0f15..db99381d3 100644
--- a/app/views/referential_lines/show.html.slim
+++ b/app/views/referential_lines/show.html.slim
@@ -1,26 +1,23 @@
/ PageHeader
= pageheader 'map-marker',
@line.name,
- 'Lorem ipsum dolor sit amet',
+ '',
t('last_update', time: l(@line.updated_at, format: :short)) do
/ Below is secundary actions & optional contents
.row
.col-lg-12.text-right.mb-sm
- / = link_to t('lines.actions.show_network'), [@referential, @line.network], class: 'btn btn-primary'
- / = link_to t('lines.actions.show_company'), [@referential, @line.company], class: 'btn btn-primary'
-
= link_to @line.human_attribute_name(:footnotes), referential_line_footnotes_path(@referential, @line), class: 'btn btn-primary'
- = link_to Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr), referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-primary disabled'
+ = link_to t('routing_constraint_zones.index.title'), referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-primary'
- if policy(Chouette::Line).create? && @referential.organisation == current_organisation
- = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'btn btn-primary'
+ = link_to t('actions.new'), new_referential_line_path(@referential), class: 'btn btn-primary'
- if policy(@line).update?
- = link_to t('lines.actions.edit'), edit_referential_line_path(@referential, @line), class: 'btn btn-primary'
+ = link_to t('actions.edit'), edit_referential_line_path(@referential, @line), class: 'btn btn-primary'
- if policy(@line).destroy?
= link_to referential_line_path(@referential, @line), method: :delete, data: {confirm: t('lines.actions.destroy_confirm')}, class: 'btn btn-primary' do
span.fa.fa-trash
- span = t('lines.actions.destroy')
+ span = t('actions.destroy')
- if !@line.hub_restricted? || (@line.hub_restricted? && @line.routes.size < 2)
- if policy(Chouette::Route).create? && @referential.organisation == current_organisation
diff --git a/app/views/routing_constraint_zones/_filters.html.slim b/app/views/routing_constraint_zones/_filters.html.slim
new file mode 100644
index 000000000..18ef40d61
--- /dev/null
+++ b/app/views/routing_constraint_zones/_filters.html.slim
@@ -0,0 +1,16 @@
+= search_form_for @q, url: referential_line_routing_constraint_zones_path(@referential, @line), class: 'form form-filter' do |f|
+ .ffg-row
+ .input-group.search_bar
+ = f.search_field :name_or_objectid_cont, class: 'form-control', placeholder: "Indiquez un nom d'ITL ou un OiD..."
+ span.input-group-btn
+ button.btn.btn-default#search-btn type='submit'
+ span.fa.fa-search
+
+ .ffg-row
+ .form-group
+ = f.label 'Itinéraire associé', required: false, class: 'control-label'
+ = f.input :route_id, as: :select, collection: @line.routing_constraint_zones.pluck(:route_id), label: false, label_method: lambda {|r| @line.routing_constraint_zones.find_by(route_id: r).route_name}, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Indiquez un itinéraire...' }, wrapper_html: { class: 'select2ed'}
+
+ .actions
+ = link_to 'Effacer', referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-link'
+ = f.submit 'Filtrer', class: 'btn btn-default'
diff --git a/app/views/routing_constraint_zones/_form.html.slim b/app/views/routing_constraint_zones/_form.html.slim
index b1c77a44b..082e8f7f8 100644
--- a/app/views/routing_constraint_zones/_form.html.slim
+++ b/app/views/routing_constraint_zones/_form.html.slim
@@ -1,19 +1,14 @@
-= simple_form_for [@referential, @line, @routing_constraint_zone] do |f|
- .row
- .col-lg-6.col-sm-12
- = f.input :name
- .row
- .col-lg-6.col-sm-12
- = f.input :route_id, collection: @line.routes.select { |route| route.stop_points.count > 2 }, include_blank: false
- .row
- .col-lg-6.col-sm-12
- - stop_points_collection = @routing_constraint_zone.persisted? ? @routing_constraint_zone.route.stop_points : []
- = f.input :stop_point_ids, as: :select, collection: stop_points_collection, selected: @routing_constraint_zone.stop_point_ids, label: Chouette::StopPoint.model_name.human.pluralize.capitalize, label_method: :name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection des arrêts sur séquence d\'arrêts', 'multiple': 'multiple', style: 'width: 100%' }
+= simple_form_for [@referential, @line, @routing_constraint_zone], html: {class: 'form-horizontal', id: 'itl_form'}, wrapper: :horizontal_form do |form|
.row
- .col-lg-12.text-right
- = link_to 'Annuler', :back, class: 'btn btn-link'
- = f.button :submit, class: 'btn btn-danger'
+ .col-lg-12
+ = form.input :name
+
+ = form.input :route_id, collection: @line.routes.select { |route| route.stop_points.count > 2 }, include_blank: false
+
+ - stop_points_collection = @routing_constraint_zone.persisted? ? @routing_constraint_zone.route.stop_points : []
+ = form.input :stop_point_ids, as: :select, collection: stop_points_collection, selected: @routing_constraint_zone.stop_point_ids, label: Chouette::StopPoint.model_name.human.pluralize.capitalize, label_method: :name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection des arrêts sur séquence d\'arrêts', 'multiple': 'multiple', style: 'width: 100%' }
+ = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'itl_form'
-= hidden_field_tag 'stop_point_ids', @routing_constraint_zone.stop_point_ids.to_s, id: 'stop_point_ids'
+ = hidden_field_tag 'stop_point_ids', @routing_constraint_zone.stop_point_ids.to_s, id: 'stop_point_ids'
diff --git a/app/views/routing_constraint_zones/edit.html.slim b/app/views/routing_constraint_zones/edit.html.slim
index fcb0d08a8..d81a347e0 100644
--- a/app/views/routing_constraint_zones/edit.html.slim
+++ b/app/views/routing_constraint_zones/edit.html.slim
@@ -1,5 +1,12 @@
-= title_tag t('.title', routing_constraint_zone: @routing_constraint_zone.name)
+/ PageHeader
+= pageheader 'map-marker',
+ t('.title'),
+ '',
+ t('last_update', time: l(@routing_constraint_zone.updated_at, format: :short))
-.row
- .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2
- == render 'form'
+/ 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'
diff --git a/app/views/routing_constraint_zones/index.html.slim b/app/views/routing_constraint_zones/index.html.slim
index 620b0f7db..248efedb4 100644
--- a/app/views/routing_constraint_zones/index.html.slim
+++ b/app/views/routing_constraint_zones/index.html.slim
@@ -1,11 +1,30 @@
-= title_tag Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr)
+/ PageHeader
+= pageheader 'map-marker',
+ 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') : '')
-- if policy(Chouette::RoutingConstraintZone).create? && @referential.organisation == current_organisation
- = link_to t('routing_constraint_zones.actions.new'), new_referential_line_routing_constraint_zone_path(@referential, @line)
+/ PageContent
+.page_content
+ .container-fluid
+ - if params[:q].present? or @routing_constraint_zones.any?
+ .row
+ .col-lg-12
+ = render 'filters'
-- if @routing_constraint_zones.any?
- = table_builder @routing_constraint_zones,
- { objectid: 'objectid', name: 'name', route: 'route_name', stop_points_count: 'stop_points_count' },
- [:show, :edit, :delete],
- [],
- 'table table-bordered'
+ - if @routing_constraint_zones.any?
+ .row
+ .col-lg-12
+ = table_builder @routing_constraint_zones,
+ { 'Oid' => Proc.new { |n| n.try(:objectid).try(:local_id) },
+ :name => 'name', :stop_points_count => 'stop_points_count',
+ :route => 'route_name' },
+ [:show, :edit, :delete],
+ [],
+ 'table has-filter has-search'
+
+ - unless @routing_constraint_zones.any?
+ .row.mt-xs
+ .col-lg-12
+ = replacement_msg t('routing_constraint_zones.search_no_results')
diff --git a/app/views/routing_constraint_zones/new.html.slim b/app/views/routing_constraint_zones/new.html.slim
index fcb0d08a8..f6ae62825 100644
--- a/app/views/routing_constraint_zones/new.html.slim
+++ b/app/views/routing_constraint_zones/new.html.slim
@@ -1,5 +1,10 @@
-= title_tag t('.title', routing_constraint_zone: @routing_constraint_zone.name)
+/ PageHeader
+= pageheader 'map-marker',
+ t('.title')
-.row
- .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2
- == render 'form'
+/ 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'
diff --git a/app/views/routing_constraint_zones/show.html.slim b/app/views/routing_constraint_zones/show.html.slim
index 351784ecc..f0c244387 100644
--- a/app/views/routing_constraint_zones/show.html.slim
+++ b/app/views/routing_constraint_zones/show.html.slim
@@ -1,17 +1,35 @@
-= title_tag @routing_constraint_zone.name
+/ PageHeader
+= pageheader 'map-marker',
+ @routing_constraint_zone.name,
+ '',
+ t('last_update', time: l(@routing_constraint_zone.updated_at, format: :short)) do
-p
- label => "#{@routing_constraint_zone.human_attribute_name(:name)} : "
- = @routing_constraint_zone.name
+ / Below is secundary actions & optional contents
+ .row
+ .col-lg-12.text-right.mb-sm
+ - if policy(@routing_constraint_zone).update?
+ = link_to t('actions.edit'), edit_referential_line_routing_constraint_zone_path(@referential, @line, @routing_constraint_zone), class: 'btn btn-primary'
-p
- label => "#{Chouette::Route.model_name.human.capitalize} : "
- = link_to @routing_constraint_zone.route.name, referential_line_route_path(@referential, @line, @routing_constraint_zone.route)
+ - if policy(@routing_constraint_zone).destroy?
+ = link_to referential_line_routing_constraint_zone_path(@referential, @line, @routing_constraint_zone), method: :delete, data: {confirm: t('routing_constraint_zones.actions.destroy_confirm')}, class: 'btn btn-primary' do
+ span.fa.fa-trash
+ span = t('actions.destroy')
-p
- label => "#{Chouette::StopPoint.model_name.human.pluralize.capitalize} : "
- br
- - @routing_constraint_zone.stop_points.each do |stop_point|
- = link_to stop_point.name, referential_stop_area_path(@referential, stop_point.stop_area)
- br
+/ PageContent
+.page_content
+ .container-fluid
+ .row
+ .col-lg-6.col-md-6.col-sm-12.col-xs-12
+ = definition_list t('metadatas'),
+ { @routing_constraint_zone.human_attribute_name(:name) => @routing_constraint_zone.try(:name),
+ @routing_constraint_zone.human_attribute_name(:route) => link_to(@routing_constraint_zone.try(:route_name), [@referential, @line, @routing_constraint_zone.route]),
+ @routing_constraint_zone.human_attribute_name(:line) => link_to(@line.name, [@referential, @line])}
+ .row
+ .col-lg-12
+ = table_builder @routing_constraint_zone.route.stop_points,
+ { "Arrêts de l'itinéraire" => 'name',
+ "Arrêts inclus dans l'ITL" => Proc.new{ |rsp| (@routing_constraint_zone.stop_points.collect{|c| c.name}.include? rsp.name) ? 'Oui' : 'Non' } },
+ [],
+ [],
+ 'table has-stoppoints'
diff --git a/app/views/time_tables/index.html.slim b/app/views/time_tables/index.html.slim
index c17f96c85..402b09b98 100644
--- a/app/views/time_tables/index.html.slim
+++ b/app/views/time_tables/index.html.slim
@@ -20,7 +20,7 @@
"Nombre de courses associées" => Proc.new{ |tt| tt.vehicle_journeys.count },
"Journées d'application" => Proc.new{ |tt| (%w(monday tuesday wednesday thursday friday saturday sunday).collect{|d| tt.send(d) ? t("calendars.days.#{d}") : '' }).reject{|a| a.empty?}.join(', ').html_safe },
:calendar => Proc.new{ |tt| tt.calendar ? tt.calendar.try(:name) : '-' }, :updated_at => Proc.new {|tt| l(tt.updated_at, format: :short)} },
- [:show, :edit, :duplicate, :delete],
+ [:show, :edit, :duplicate, :actualize, :delete],
[],
'table has-search'
diff --git a/app/views/time_tables/show.html.slim b/app/views/time_tables/show.html.slim
index 1c5984a7d..2e71ebb9e 100644
--- a/app/views/time_tables/show.html.slim
+++ b/app/views/time_tables/show.html.slim
@@ -4,6 +4,7 @@
= pageheader 'map-marker',
@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') : '')
/ Below is secundary actions & optional contents (filters, ...)
diff --git a/config/locales/actions.en.yml b/config/locales/actions.en.yml
index 6e2dd3aa2..fe4d3d4e5 100644
--- a/config/locales/actions.en.yml
+++ b/config/locales/actions.en.yml
@@ -5,6 +5,7 @@ en:
delete: "Delete"
search: "Search"
add: "Add new"
+ new: "Add new"
show: "See"
archive: "Archive"
unarchive: "Unarchive"
diff --git a/config/locales/actions.fr.yml b/config/locales/actions.fr.yml
index 8f2fc90f8..ae0537ebb 100644
--- a/config/locales/actions.fr.yml
+++ b/config/locales/actions.fr.yml
@@ -6,6 +6,7 @@ fr:
search: "Chercher"
submit: "Valider"
add: 'Ajouter'
+ new: 'Ajouter'
show: 'Consulter'
archive: 'Conserver'
unarchive: 'Déconserver'
diff --git a/config/locales/routing_constraint_zones.en.yml b/config/locales/routing_constraint_zones.en.yml
index 2d4412dba..8e9dbfb02 100644
--- a/config/locales/routing_constraint_zones.en.yml
+++ b/config/locales/routing_constraint_zones.en.yml
@@ -11,7 +11,7 @@ en:
updated_at: Updated at
objectid: Object ID
stop_points_count: Number of stop points
- route: Route
+ route: Associated route
errors:
models:
routing_constraint_zone:
@@ -21,6 +21,7 @@ en:
stop_points_not_from_route: 'Stop point does not belong to the Route of this Routing constraint zone.'
all_stop_points_selected: 'All stop points from route cannot be selected.'
routing_constraint_zones:
+ search_no_results: "No ITL matches your query"
actions:
new: New routing constraint zone
edit: Edit this routing constraint zone
@@ -32,4 +33,5 @@ en:
title: "Update routing constraint zone %{routing_constraint_zone}"
show:
title: "Routing constraint zone %{routing_constraint_zone}"
-
+ 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 36dcf9301..3e207fac0 100644
--- a/config/locales/routing_constraint_zones.fr.yml
+++ b/config/locales/routing_constraint_zones.fr.yml
@@ -6,12 +6,12 @@ fr:
routing_constraint_zone:
name: Nom
stop_areas: Arrêts
- line: Ligne
+ line: Ligne associée
created_at: "Créé le"
updated_at: "Edité le"
objectid: Object ID
stop_points_count: Nombre d'arrêts
- route: Itinéraire
+ route: Itinéraire associé
errors:
models:
routing_constraint_zone:
@@ -21,14 +21,14 @@ fr:
stop_points_not_from_route: "Arrêt sur séquence d'arrêts n'appartient pas à la Route de cette Zone de contrainte."
all_stop_points_selected: "Une zone de contrainte ne peut pas couvrir tous les arrêts d'une ligne."
routing_constraint_zones:
+ search_no_results: "Aucune ITL ne correspond à votre recherche"
actions:
- new: Ajouter une zone de contrainte
- edit: Editer cette zone de contrainte
- destroy: Supprimer cette zone de contrainte
destroy_confirm: Etes vous sûr de supprimer cette zone de contrainte ?
new:
- title: Ajouter une zone de contrainte
+ title: Ajouter un ITL
edit:
title: "Editer la zone de contrainte %{routing_constraint_zone}"
show:
title: "Zone de contrainte %{routing_constraint_zone}"
+ index:
+ title: "Interdictions de traffic local"
diff --git a/db/migrate/20170607141031_change_begin_date_from_clean_ups.rb b/db/migrate/20170607141031_change_begin_date_from_clean_ups.rb
new file mode 100644
index 000000000..850616b18
--- /dev/null
+++ b/db/migrate/20170607141031_change_begin_date_from_clean_ups.rb
@@ -0,0 +1,9 @@
+class ChangeBeginDateFromCleanUps < ActiveRecord::Migration
+ def up
+ change_column :clean_ups, :begin_date, :date
+ end
+
+ def down
+ change_column :clean_ups, :begin_date, :datetime
+ end
+end
diff --git a/db/migrate/20170607141317_change_end_date_from_clean_ups.rb b/db/migrate/20170607141317_change_end_date_from_clean_ups.rb
new file mode 100644
index 000000000..e47197ff1
--- /dev/null
+++ b/db/migrate/20170607141317_change_end_date_from_clean_ups.rb
@@ -0,0 +1,9 @@
+class ChangeEndDateFromCleanUps < ActiveRecord::Migration
+ def up
+ change_column :clean_ups, :end_date, :date
+ end
+
+ def down
+ change_column :clean_ups, :end_date, :datetime
+ end
+end
diff --git a/db/schema.rb b/db/schema.rb
index 1aa092fa8..d9a4fc5f8 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: 20170605135126) do
+ActiveRecord::Schema.define(version: 20170607141317) do
# These are extensions that must be enabled in order to support this database
enable_extension "plpgsql"
@@ -108,10 +108,10 @@ ActiveRecord::Schema.define(version: 20170605135126) do
t.datetime "started_at"
t.datetime "ended_at"
t.integer "referential_id", limit: 8
- t.datetime "begin_date"
+ t.date "begin_date"
t.datetime "created_at"
t.datetime "updated_at"
- t.datetime "end_date"
+ t.date "end_date"
t.string "date_type"
end
@@ -829,6 +829,10 @@ ActiveRecord::Schema.define(version: 20170605135126) do
add_index "workbenches", ["organisation_id"], name: "index_workbenches_on_organisation_id", using: :btree
add_index "workbenches", ["stop_area_referential_id"], name: "index_workbenches_on_stop_area_referential_id", using: :btree
+ create_table "yyy", id: false, force: :cascade do |t|
+ t.text "value"
+ end
+
add_foreign_key "access_links", "access_points", name: "aclk_acpt_fkey"
add_foreign_key "group_of_lines_lines", "group_of_lines", name: "groupofline_group_fkey", on_delete: :cascade
add_foreign_key "journey_frequencies", "timebands", on_delete: :nullify
diff --git a/spec/factories/chouette_time_table.rb b/spec/factories/chouette_time_table.rb
index f462349cf..6480df79d 100644
--- a/spec/factories/chouette_time_table.rb
+++ b/spec/factories/chouette_time_table.rb
@@ -1,6 +1,7 @@
FactoryGirl.define do
factory :time_table_date, :class => Chouette::TimeTableDate do
+ association :time_table, :factory => :time_table
end
factory :time_table_period, :class => Chouette::TimeTablePeriod do
diff --git a/spec/factories/clean_ups.rb b/spec/factories/clean_ups.rb
index 41165ac16..d3746c3b2 100644
--- a/spec/factories/clean_ups.rb
+++ b/spec/factories/clean_ups.rb
@@ -1,15 +1,6 @@
FactoryGirl.define do
factory :clean_up do
- status "MyString"
-started_at "2016-11-14 14:45:18"
-ended_at "2016-11-14 14:45:18"
-referential nil
-keep_lines false
-keep_stops false
-keep_companies false
-keep_networks false
-keep_group_of_lines false
-expected_date "2016-11-14 14:45:18"
+ begin_date { Date.today}
+ end_date { Date.today + 1.month }
end
-
end
diff --git a/spec/features/routing_constraint_zones_spec.rb b/spec/features/routing_constraint_zones_spec.rb
index 9e8c7dad4..b116b38bd 100644
--- a/spec/features/routing_constraint_zones_spec.rb
+++ b/spec/features/routing_constraint_zones_spec.rb
@@ -20,7 +20,7 @@ describe 'RoutingConstraintZones', type: :feature do
context 'user has permission to create routing_constraint_zones' do
it 'shows a create link for routing_constraint_zones' do
- expect(page).to have_content(I18n.t('routing_constraint_zones.actions.new'))
+ expect(page).to have_content(I18n.t('actions.new'))
end
end
@@ -28,7 +28,7 @@ describe 'RoutingConstraintZones', type: :feature do
it 'does not show a create link for routing_constraint_zones' do
@user.update_attribute(:permissions, [])
visit referential_line_routing_constraint_zones_path(referential, line)
- expect(page).not_to have_content(I18n.t('routing_constraint_zones.actions.new'))
+ expect(page).not_to have_content(I18n.t('actions.new'))
end
end
diff --git a/spec/javascripts/time_table/reducers/pagination_spec.js b/spec/javascripts/time_table/reducers/pagination_spec.js
index 740ded3ac..5da58427e 100644
--- a/spec/javascripts/time_table/reducers/pagination_spec.js
+++ b/spec/javascripts/time_table/reducers/pagination_spec.js
@@ -118,11 +118,4 @@ describe('pagination reducer', () => {
})
).toEqual(Object.assign({}, state, {stateChanged: true}))
})
- it('should handle UPDATE_DAY_TYPES', () => {
- expect(
- paginationReducer(state, {
- type: 'UPDATE_DAY_TYPES'
- })
- ).toEqual(Object.assign({}, state, {stateChanged: true}))
- })
})
diff --git a/spec/models/clean_up_spec.rb b/spec/models/clean_up_spec.rb
index c22d32eaa..b4cf5e1af 100644
--- a/spec/models/clean_up_spec.rb
+++ b/spec/models/clean_up_spec.rb
@@ -1,21 +1,227 @@
require 'rails_helper'
RSpec.describe CleanUp, :type => :model do
- let(:cleaner) { CleanUp.new }
it { should validate_presence_of(:begin_date) }
it { should validate_presence_of(:date_type) }
it { should belong_to(:referential) }
- it 'should delete vehiclejourneys without timetables' do
- create_list(:vehicle_journey, 2)
- create_list(:vehicle_journey, 2, time_tables:[create(:time_table)])
- expect(cleaner.clean_vehicle_journeys).to eq 2
+ context '#exclude_dates_in_overlapping_period with :before date_type' do
+ let(:time_table) { create(:time_table) }
+ let(:period) { time_table.periods[0] }
+ let(:cleaner) { create(:clean_up, date_type: :before) }
+
+ it 'should add exclude date into period for overlapping period' do
+ days_in_period = (period.period_start..period.period_end).count
+ cleaner.begin_date = period.period_end
+
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {
+ time_table.dates.where(in_out: false).count
+ }.by(days_in_period - 1)
+ end
+
+ it 'should not add exclude date if no overlapping found' do
+ cleaner.begin_date = period.period_start
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to_not change {
+ time_table.dates.where(in_out: false).count
+ }
+ end
+ end
+
+ context '#exclude_dates_in_overlapping_period with :after date_type' do
+ let(:time_table) { create(:time_table) }
+ let(:period) { time_table.periods[0] }
+ let(:cleaner) { create(:clean_up, date_type: :after) }
+
+ it 'should add exclude date into period for overlapping period' do
+ days_in_period = (period.period_start..period.period_end).count
+ cleaner.begin_date = period.period_start + 1.day
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {
+ time_table.dates.where(in_out: false).count
+ }.by(days_in_period - 2)
+ end
+
+ it 'should not add exclude date if no overlapping found' do
+ cleaner.begin_date = period.period_end
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to_not change {
+ time_table.dates.where(in_out: false).count
+ }
+ end
+ end
+
+ context '#exclude_dates_in_overlapping_period with :between date_type' do
+ let(:time_table) { create(:time_table) }
+ let(:period) { time_table.periods[0] }
+ let(:cleaner) { create(:clean_up, date_type: :between, begin_date: period.period_start + 3.day, end_date: period.period_end) }
+
+ it 'should add exclude date into period for overlapping period' do
+ expected_day_out = (cleaner.begin_date..cleaner.end_date).count
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to change {
+ time_table.dates.where(in_out: false).count
+ }.by(expected_day_out)
+ end
+
+ it 'should not add exclude date if no overlapping found' do
+ cleaner.begin_date = period.period_end + 1.day
+ cleaner.end_date = cleaner.begin_date + 1.day
+
+ expect { cleaner.exclude_dates_in_overlapping_period(period) }.to_not change {
+ time_table.dates.where(in_out: false).count
+ }
+ end
+ end
+
+ context '#overlapping_periods' do
+ let(:cleaner) { create(:clean_up, date_type: :before, end_date: nil) }
+ let(:time_table) { create(:time_table) }
+
+ it 'should detect overlapping periods' do
+ cleaner.begin_date = time_table.periods[0].period_start
+ expect(cleaner.overlapping_periods).to include(time_table.periods[0])
+ end
+
+ it 'should not return none overlapping periods' do
+ cleaner.begin_date = time_table.periods[0].period_start - 1.day
+ expect(cleaner.overlapping_periods).to_not include(time_table.periods[0])
+ end
+ end
+
+ context '#clean' do
+ let(:cleaner) { create(:clean_up, date_type: :before) }
+
+ it 'should call destroy_time_tables_before' do
+ cleaner.date_type = :before
+ expect(cleaner).to receive(:destroy_time_tables_before)
+ expect(cleaner).to receive(:destroy_time_tables_dates_before)
+ expect(cleaner).to receive(:destroy_time_tables_periods_before)
+ cleaner.clean
+ end
+
+ it 'should call destroy_time_tables_after' do
+ cleaner.date_type = :after
+ expect(cleaner).to receive(:destroy_time_tables_after)
+ expect(cleaner).to receive(:destroy_time_tables_dates_after)
+ expect(cleaner).to receive(:destroy_time_tables_periods_after)
+ cleaner.clean
+ end
+
+ it 'should call destroy_time_tables_between' do
+ cleaner.date_type = :between
+ expect(cleaner).to receive(:destroy_time_tables_between)
+ expect(cleaner).to receive(:destroy_time_tables_dates_between)
+ expect(cleaner).to receive(:destroy_time_tables_periods_between)
+ cleaner.clean
+ end
+ end
+
+ context '#destroy_time_tables_dates_between' do
+ let!(:time_table) { create(:time_table) }
+ let(:cleaner) { create(:clean_up, date_type: :between) }
+
+ before do
+ time_table.periods.clear
+ time_table.save
+ cleaner.begin_date = time_table.start_date
+ cleaner.end_date = time_table.end_date
+ end
+
+ it 'should destroy record' do
+ expect{ cleaner.destroy_time_tables_dates_between }.to change {
+ Chouette::TimeTableDate.count
+ }.by(-time_table.dates.count)
+ end
+
+ it 'should not destroy record not in range' do
+ cleaner.begin_date = time_table.end_date + 1.day
+ cleaner.end_date = cleaner.begin_date + 1.day
+
+ expect{ cleaner.destroy_time_tables_dates_between }.to_not change {
+ Chouette::TimeTableDate.count
+ }
+ end
+ end
+
+ context '#destroy_time_tables_dates_after' do
+ let!(:time_table_date) { create(:time_table_date, date: Date.yesterday, in_out: true) }
+ let(:cleaner) { create(:clean_up, date_type: :after, begin_date: time_table_date.date) }
+
+ it 'should destroy record' do
+ count = Chouette::TimeTableDate.where('date >= ?', cleaner.begin_date).count
+ expect{ cleaner.destroy_time_tables_dates_after }.to change {
+ Chouette::TimeTableDate.count
+ }.by(-count)
+ end
+ end
+
+ context '#destroy_time_tables_between' do
+ let!(:time_table) { create(:time_table ) }
+ let(:cleaner) { create(:clean_up, date_type: :after, begin_date: time_table.start_date, end_date: time_table.end_date) }
+
+ it 'should destroy time_tables with validity period in purge range' do
+ expect{ cleaner.destroy_time_tables_between }.to change {
+ Chouette::TimeTable.count
+ }.by(-1)
+ end
+
+ it 'should not destroy time_tables if not totaly inside purge range' do
+ cleaner.begin_date = time_table.start_date + 1.day
+ expect{ cleaner.destroy_time_tables_between }.to_not change {
+ Chouette::TimeTable.count
+ }
+ end
+ end
+
+ context '#destroy_time_tables_after' do
+ let!(:time_table) { create(:time_table ) }
+ let(:cleaner) { create(:clean_up, date_type: :after, begin_date: time_table.start_date) }
+
+ it 'should destroy time_tables with start_date >= purge begin_date' do
+ expect{ cleaner.destroy_time_tables_after }.to change {
+ Chouette::TimeTable.count
+ }.by(-1)
+ end
+
+ it 'should not destroy time_tables with start_date < purge begin date' do
+ cleaner.begin_date = time_table.end_date
+ expect{ cleaner.destroy_time_tables_after }.to_not change {
+ Chouette::TimeTable.count
+ }
+ end
end
- it 'should delete journeypatterns without vehicle journeys' do
- create_list(:journey_pattern, 2)
- create_list(:vehicle_journey, 2, journey_pattern: create(:journey_pattern))
- expect(cleaner.clean_journey_patterns).to eq 2
+ context '#destroy_time_tables' do
+ let!(:time_table) { create(:time_table) }
+ let(:cleaner) { create(:clean_up, date_type: :before) }
+
+ it 'should destroy all time_tables' do
+ expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change {
+ Chouette::TimeTable.count
+ }.by(-1)
+ end
+
+ it 'should destroy associated vehicle_journeys' do
+ create(:vehicle_journey, time_tables: [time_table])
+ expect{cleaner.destroy_time_tables(Chouette::TimeTable.all)}.to change {
+ Chouette::VehicleJourney.count
+ }.by(-1)
+ end
+ end
+
+ context '#destroy_time_tables_before' do
+ let!(:time_table) { create(:time_table ) }
+ let(:cleaner) { create(:clean_up, date_type: :before, begin_date: time_table.end_date) }
+
+ it 'should destroy time_tables with end_date <= purge begin_date' do
+ expect{ cleaner.destroy_time_tables_before }.to change {
+ Chouette::TimeTable.count
+ }.by(-1)
+ end
+
+ it 'should not destroy time_tables with end_date > purge begin date' do
+ cleaner.begin_date = Date.today
+ expect{ cleaner.destroy_time_tables_before }.to_not change {
+ Chouette::TimeTable.count
+ }
+ end
end
end