diff options
| author | Robert | 2017-04-27 16:19:32 +0200 |
|---|---|---|
| committer | Robert | 2017-04-27 16:19:32 +0200 |
| commit | bae7cdb28a0e249f26e3873801e0a1e86c3e227d (patch) | |
| tree | 18296836c7430784cd726235bd37f1668f12b7cc | |
| parent | 7b4b07b5aac7423b9894d48f995d2084db7b2f89 (diff) | |
| parent | b7651ff972af8e0e2729d99baa8db51dc5ec25dc (diff) | |
| download | chouette-core-bae7cdb28a0e249f26e3873801e0a1e86c3e227d.tar.bz2 | |
Merge branch 'master' of github.com:af83/stif-boiv
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/components/Metas.js | 5 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js | 8 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/containers/Metas.js | 2 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/index.js | 1 | ||||
| -rw-r--r-- | app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js | 1 | ||||
| -rw-r--r-- | app/assets/stylesheets/components/_forms.sass | 8 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 7 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 28 | ||||
| -rw-r--r-- | app/models/netex_import.rb | 7 | ||||
| -rw-r--r-- | app/views/time_tables/_form.html.slim | 10 | ||||
| -rw-r--r-- | app/views/time_tables/new.html.slim | 9 | ||||
| -rw-r--r-- | config/deploy.rb | 1 | ||||
| -rw-r--r-- | spec/models/chouette/time_table_spec.rb | 65 |
13 files changed, 137 insertions, 15 deletions
diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/Metas.js b/app/assets/javascripts/es6_browserified/time_tables/components/Metas.js index 7add0ddfd..792d75520 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/Metas.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/Metas.js @@ -71,18 +71,17 @@ const Metas = ({metas, onUpdateDayTypes, onUpdateComment, onUpdateColor, onSelec </div> {/* tags */} - {/* <div className="form-group"> + <div className="form-group"> <label htmlFor="" className="control-label col-sm-4">Etiquettes</label> <div className="col-sm-8"> <TagsSelect2 + initialTags={metas.initial_tags} tags={metas.tags} onSelect2Tags={(e) => onSelect2Tags(e)} onUnselect2Tags={(e) => onUnselect2Tags(e)} /> - <input type="text" value='ton papa' className='form-control'/> </div> </div> - */} {/* calendar */} <div className="form-group"> diff --git a/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js b/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js index 16ebc250a..f1b999cff 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js +++ b/app/assets/javascripts/es6_browserified/time_tables/components/TagsSelect2.js @@ -25,16 +25,20 @@ class TagsSelect2 extends React.Component{ return ( <Select2 value={(this.props.tags.length) ? _.map(this.props.tags, 'id') : undefined} - data={(this.props.tags.length) ? this.mapKeys(this.props.tags) : undefined} + data={(this.props.initialTags.length) ? this.mapKeys(this.props.initialTags) : undefined} onSelect={(e) => this.props.onSelect2Tags(e)} onUnselect={(e) => setTimeout( () => this.props.onUnselect2Tags(e, 150))} multiple={true} ref='tags_id' options={{ + tags:true, + createTag: function(params) { + return {name: params.term, text: params.term, id: params.term} + }, allowClear: true, theme: 'bootstrap', width: '100%', - placeholder: 'Cherchez un tag...', + placeholder: 'Ajoutez ou cherchez une étiquette...', ajax: { url: origin + path + '/tags.json', dataType: 'json', diff --git a/app/assets/javascripts/es6_browserified/time_tables/containers/Metas.js b/app/assets/javascripts/es6_browserified/time_tables/containers/Metas.js index 514ed2347..a8639d89f 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/containers/Metas.js +++ b/app/assets/javascripts/es6_browserified/time_tables/containers/Metas.js @@ -20,9 +20,11 @@ const mapDispatchToProps = (dispatch) => { dispatch(actions.updateColor(color)) }, onSelect2Tags: (e) => { + e.preventDefault() dispatch(actions.select2Tags(e.params.data)) }, onUnselect2Tags: (e) => { + e.preventDefault() dispatch(actions.unselect2Tags(e.params.data)) } } diff --git a/app/assets/javascripts/es6_browserified/time_tables/index.js b/app/assets/javascripts/es6_browserified/time_tables/index.js index 174cede5c..3bf5a3b99 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/index.js +++ b/app/assets/javascripts/es6_browserified/time_tables/index.js @@ -28,6 +28,7 @@ var initialState = { comment: '', day_types: [], tags: [], + initial_tags: [], color: '', calendar: {} }, 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 365026cfa..dd6b484f3 100644 --- a/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js +++ b/app/assets/javascripts/es6_browserified/time_tables/reducers/metas.js @@ -8,6 +8,7 @@ const metas = (state = {}, action) => { comment: action.json.comment, day_types: actions.strToArrayDayTypes(action.json.day_types), tags: action.json.tags, + initial_tags: action.json.tags, color: action.json.color, calendar: action.json.calendar ? action.json.calendar : {name : 'Aucun'} }) diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index 8419c2345..96adb56cf 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -16,6 +16,10 @@ input color: rgba($grey, 0.65) font-style: italic + + .help-block.small + margin-bottom: 0 + font-style: italic + .control-label.required abbr[title], abbr[data-original-title] border: none @@ -95,6 +99,10 @@ input + [class*='col-sm-'] float: right + &.string + top: 17px + + // Colors dropdown .dropdown.color_selector .btn.btn-default diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 487c14e9f..3b8e390b6 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -46,7 +46,11 @@ class TimeTablesController < ChouetteController @time_table.periods << Chouette::TimeTablePeriod.new(period_start: date_range.begin, period_end: date_range.end, position: i) end end - create! + + create! do |success, failure| + success.html { redirect_to edit_referential_time_table_path(@referential, @time_table) } + failure.html { render :new } + end end def edit @@ -58,6 +62,7 @@ class TimeTablesController < ChouetteController def update state = JSON.parse request.raw_post + resource.state_update state respond_to do |format| format.json { render json: state, status: state['errors'] ? :unprocessable_entity : :ok } end diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index acce96681..7285e9716 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -34,12 +34,39 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord def state_update state update_attributes(self.class.state_permited_attributes(state)) + self.tag_list = state['tags'].collect{|t| t['name']}.join(', ') 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']) + + 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 + + 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}) + end + end self.save end @@ -62,6 +89,7 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord (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, diff --git a/app/models/netex_import.rb b/app/models/netex_import.rb index 0da008d2e..595f7f82b 100644 --- a/app/models/netex_import.rb +++ b/app/models/netex_import.rb @@ -5,9 +5,10 @@ class NetexImport < Import def launch_java_import logger.warn "Call iev get #{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}" begin - Net::HTTP.get(Rails.configuration.iev_url, "/boiv_iev/referentials/importer/new?id=#{id}") - rescue - logger.error("IEV server error") + Net::HTTP.get(URI("#{Rails.configuration.iev_url}/boiv_iev/referentials/importer/new?id=#{id}")) + rescue Exception => e + logger.error "IEV server error : e.message" + logger.error e.backtrace.inspect end end end diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim new file mode 100644 index 000000000..8152e7f94 --- /dev/null +++ b/app/views/time_tables/_form.html.slim @@ -0,0 +1,10 @@ += simple_form_for [@referential, @time_table], html: {class: 'form-horizontal', id: 'timetable_form'}, wrapper: :horizontal_form do |form| + + .row + .col-lg-12 + = form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")} + + - if @time_table.new_record? + = form.input :calendar, as: :select, collection: current_organisation.calendars + + = form.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'timetable_form' diff --git a/app/views/time_tables/new.html.slim b/app/views/time_tables/new.html.slim index 6a0faade8..8d72f49b6 100644 --- a/app/views/time_tables/new.html.slim +++ b/app/views/time_tables/new.html.slim @@ -7,9 +7,6 @@ / PageContent .page_content .container-fluid - #periods - -= javascript_tag do - | window.actionType = "#{params[:action]}" - -= javascript_include_tag 'es6_browserified/time_tables/index.js' + .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/config/deploy.rb b/config/deploy.rb index e3bc9a121..78def7de7 100644 --- a/config/deploy.rb +++ b/config/deploy.rb @@ -62,6 +62,7 @@ namespace :deploy do run "ln -nfs #{shared_path}/config/secrets.yml #{release_path}/config/" run "ln -nfs #{shared_path}/config/newrelic.yml #{release_path}/config/" + run "rm -rf #{release_path}/public/uploads" run "ln -nfs #{shared_path}/public/uploads #{release_path}/public/uploads" run "ln -nfs #{shared_path}/tmp/uploads #{release_path}/tmp/uploads" end diff --git a/spec/models/chouette/time_table_spec.rb b/spec/models/chouette/time_table_spec.rb index fd9f70740..96f91aa03 100644 --- a/spec/models/chouette/time_table_spec.rb +++ b/spec/models/chouette/time_table_spec.rb @@ -11,10 +11,30 @@ describe Chouette::TimeTable, :type => :model do def time_table_to_state time_table time_table.slice('id', 'comment').tap do |item| item['day_types'] = "Di,Lu,Ma,Me,Je,Ve,Sa" + item['current_month'] = time_table.month_inspect(Date.today.beginning_of_month) + item['current_periode_range'] = Date.today.beginning_of_month.to_s + item['tags'] = time_table.tags.map{ |tag| {id: tag.id, name: tag.name}} end end let(:state) { time_table_to_state subject } + it 'should save new tags' do + subject.tag_list = "awesome, great" + subject.save + state['tags'] << {'id' => false, 'name' => 'new_tag'} + + subject.state_update state + expect(subject.reload.tags.map(&:name)).to include('new_tag') + end + + it 'should remove removed tags' do + subject.tag_list = "awesome, great" + subject.save + state['tags'] = [] + + subject.state_update state + expect(subject.reload.tags).to be_empty + end it 'should update comment' do state['comment'] = "Edited timetable name" @@ -28,6 +48,51 @@ describe Chouette::TimeTable, :type => :model do expect(subject.reload.valid_days).to include(7, 1, 4, 2) expect(subject.reload.valid_days).not_to include(3, 5, 6) end + + it 'should delete date if date is set to neither include or excluded date' do + updated = state['current_month'].map do |day| + day['include_date'] = false if day['include_date'] + end + + expect { + subject.state_update state + }.to change {subject.dates.count}.by(-updated.compact.count) + end + + it 'should update date if date is set to excluded date' do + updated = state['current_month'].map do |day| + next unless day['include_date'] + day['include_date'] = false + day['excluded_date'] = true + end + + subject.state_update state + expect(subject.reload.excluded_days.count).to eq (updated.compact.count) + end + + it 'should create new include date' do + day = state['current_month'].first + date = Date.parse(day['date']) + day['include_date'] = true + expect(subject.included_days).not_to include(date) + + expect { + subject.state_update state + }.to change {subject.dates.count}.by(1) + expect(subject.reload.included_days).to include(date) + end + + it 'should create new exclude date' do + day = state['current_month'].first + date = Date.parse(day['date']) + day['excluded_date'] = true + expect(subject.excluded_days).not_to include(date) + + expect { + subject.state_update state + }.to change {subject.dates.count}.by(1) + expect(subject.reload.excluded_days).to include(date) + end end describe "#periods_max_date" do |
