diff options
| -rw-r--r-- | app/assets/stylesheets/main/time_tables.sass | 5 | ||||
| -rw-r--r-- | app/controllers/time_tables_controller.rb | 30 | ||||
| -rw-r--r-- | app/models/calendar.rb | 1 | ||||
| -rw-r--r-- | app/models/chouette/time_table.rb | 2 | ||||
| -rw-r--r-- | app/views/time_tables/_form.html.slim | 14 | ||||
| -rw-r--r-- | app/views/time_tables/_show_time_table.html.slim | 9 | ||||
| -rw-r--r-- | config/locales/calendars.en.yml | 1 | ||||
| -rw-r--r-- | config/locales/calendars.fr.yml | 1 | ||||
| -rw-r--r-- | config/locales/time_tables.fr.yml | 3 | ||||
| -rw-r--r-- | db/migrate/20170106135000_add_calendar_ref_to_time_tables.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 4 | ||||
| -rw-r--r-- | spec/factories/chouette_time_table.rb | 15 | 
12 files changed, 70 insertions, 20 deletions
| diff --git a/app/assets/stylesheets/main/time_tables.sass b/app/assets/stylesheets/main/time_tables.sass index b24a02c27..de2ae8253 100644 --- a/app/assets/stylesheets/main/time_tables.sass +++ b/app/assets/stylesheets/main/time_tables.sass @@ -61,6 +61,9 @@    .actions      float: right +  #associated_calendars +    padding-top: 15px +  #workspace.time_tables.edit,  #workspace.time_tables.new,  #workspace.time_tables.create, @@ -129,4 +132,4 @@      background: url(image-path('icons/remove.png')) no-repeat 0% 50%    .actions -    margin-top: 20px
\ No newline at end of file +    margin-top: 20px diff --git a/app/controllers/time_tables_controller.rb b/app/controllers/time_tables_controller.rb index 5ebd3c5c3..10e1e76dc 100644 --- a/app/controllers/time_tables_controller.rb +++ b/app/controllers/time_tables_controller.rb @@ -9,7 +9,6 @@ class TimeTablesController < ChouetteController    belongs_to :referential    def show -      @year = params[:year] ? params[:year].to_i : Date.today.cwyear      @time_table_combination = TimeTableCombination.new      show! do @@ -24,6 +23,25 @@ class TimeTablesController < ChouetteController      end    end +  def create +    tt_params = time_table_params +    if tt_params[:calendar_id] +      %i(monday tuesday wednesday thursday friday saturday sunday).map { |d| tt_params[d] = true } +      calendar = current_organisation.calendars.find_by_id(tt_params[:calendar_id]) +      tt_params[:calendar_id] = nil if tt_params.has_key?(:dates_attributes) || tt_params.has_key?(:periods_attributes) +    end +    @time_table = Chouette::TimeTable.new(tt_params) +    if calendar +      calendar.dates.each_with_index do |date, i| +        @time_table.dates << Chouette::TimeTableDate.new(date: date, position: i) +      end +      calendar.date_ranges.each_with_index do |date_range, i| +        @time_table.periods << Chouette::TimeTablePeriod.new(period_start: date_range.begin, period_end: date_range.end, position: i) +      end +    end +    create! +  end +    def edit      edit! do        build_breadcrumb :edit @@ -31,6 +49,12 @@ class TimeTablesController < ChouetteController      end    end +  def update +    @time_table = Chouette::TimeTable.find_by_id(params[:id]) +    @time_table.calendar_id = nil +    update! +  end +    def index      request.format.kml? ? @per_page = nil : @per_page = 12 @@ -89,8 +113,8 @@ class TimeTablesController < ChouetteController    end    private -   +    def time_table_params -    params.require(:time_table).permit( :objectid, :object_version, :creation_time, :creator_id, :version, :comment, :int_day_types, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, :tag_list, :tag_search ) +    params.require(:time_table).permit( :objectid, :object_version, :creation_time, :creator_id, :calendar_id, :version, :comment, :int_day_types, :monday, :tuesday, :wednesday, :thursday, :friday, :saturday, :sunday, :start_date, :end_date, { :dates_attributes => [:date, :in_out, :id, :_destroy] }, { :periods_attributes => [:period_start, :period_end, :_destroy, :id] }, :tag_list, :tag_search )    end  end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 54237e9cc..641f97302 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -1,5 +1,6 @@  class Calendar < ActiveRecord::Base    belongs_to :organisation +  has_many :time_tables    validates_presence_of :name, :short_name, :organisation    validates_uniqueness_of :short_name diff --git a/app/models/chouette/time_table.rb b/app/models/chouette/time_table.rb index abe6186a7..7afdc4529 100644 --- a/app/models/chouette/time_table.rb +++ b/app/models/chouette/time_table.rb @@ -17,6 +17,8 @@ class Chouette::TimeTable < Chouette::TridentActiveRecord    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 +    after_save :save_shortcuts    def self.object_id_key diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim index 7194ce363..8652f7cb5 100644 --- a/app/views/time_tables/_form.html.slim +++ b/app/views/time_tables/_form.html.slim @@ -5,9 +5,11 @@      = form.input :tag_search, as: :tags, :input_html => { :id => "tag_search",:placeholder => t("formtastic.placeholders.time_table.tag_search") }      = form.input :tag_list, as: :hidden, :input_html => { :id => "tag_list" }      = form.input :objectid, :required => !@time_table.new_record?, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.objectid")} -   +    - if @time_table.new_record? +      = form.input :calendar, as: :select, collection: current_organisation.calendars +    h3.time_table_periods = @time_table.human_attribute_name("periods") -   +    #periods_content      = form.inputs class: 'day_type' do        label.day_type_label = @time_table.human_attribute_name("day_types") @@ -24,7 +26,7 @@          == render "period_fields",  :f => p      = link_to_add_association t("time_tables.actions.add_period"), form, :periods , :"data-association-insertion-method" => "append", :"data-association-insertion-node" => "div#periods" -   +    h3.time_table_dates = @time_table.human_attribute_name("dates")    #dates_content @@ -53,9 +55,9 @@ javascript:    $("#tag_search").tagsManager({      prefilled: items,      output: '#tag_list', -    tagsContainer: '#tagsContainer'  +    tagsContainer: '#tagsContainer'    }); -   +    var time_tables_tag_list = new Bloodhound({      datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),      queryTokenizer: Bloodhound.tokenizers.whitespace, @@ -68,4 +70,4 @@ javascript:      name: 'time_tables_tag_list',      displayKey: 'name',      source: time_tables_tag_list.ttAdapter() -  });
\ No newline at end of file +  }); diff --git a/app/views/time_tables/_show_time_table.html.slim b/app/views/time_tables/_show_time_table.html.slim index ccdc4187f..419d13c96 100644 --- a/app/views/time_tables/_show_time_table.html.slim +++ b/app/views/time_tables/_show_time_table.html.slim @@ -24,6 +24,13 @@    #my-tab-content.tab-content      #time_tables.tab-pane.active +      #associated_calendar +        => "#{t('calendars.standard_calendar')} : " +        - if @time_table.calendar +          = link_to @time_table.calendar.name, @time_table.calendar +        - else +          = '--' +        .well.legend          span.title = t(".legend")          span.label.excluded_date X @@ -84,4 +91,4 @@        - if @time_table.dates.where("in_out = false").present?          h3.time_table_dates = @time_table.human_attribute_name("excluded_dates")          .excluded_dates.content -          == render "time_tables/excluded_dates"
\ No newline at end of file +          == render "time_tables/excluded_dates" diff --git a/config/locales/calendars.en.yml b/config/locales/calendars.en.yml index 97109a812..cb63afde5 100644 --- a/config/locales/calendars.en.yml +++ b/config/locales/calendars.en.yml @@ -1,6 +1,7 @@  en:    calendars:      standard_calendars: Standard calendars +    standard_calendar: Standard calendar      actions:        new: Add a new calendar        edit: Edit this calendar diff --git a/config/locales/calendars.fr.yml b/config/locales/calendars.fr.yml index 6abfb0f4a..fbcc3c8cd 100644 --- a/config/locales/calendars.fr.yml +++ b/config/locales/calendars.fr.yml @@ -1,6 +1,7 @@  fr:    calendars:      standard_calendars: Calendriers standards +    standard_calendar: Calendrier standard      actions:        new: Ajouter un calendrier        edit: Modifier cet calendrier diff --git a/config/locales/time_tables.fr.yml b/config/locales/time_tables.fr.yml index d2d693c93..46f243580 100644 --- a/config/locales/time_tables.fr.yml +++ b/config/locales/time_tables.fr.yml @@ -42,7 +42,7 @@ fr:        selected_date: "Date incluse directement"        selected_period: "Date incluse par période"      properties_show: -      resume: "Validité comprise du %{start_date} au %{end_date}"  +      resume: "Validité comprise du %{start_date} au %{end_date}"        resume_empty: "Calendrier vide"      index:        comment: "Recherche par nom" @@ -88,6 +88,7 @@ fr:          period_end: "au"          tag_search: "Etiquettes"          tag_list: "Etiquettes" +        calendar: Calendrier    formtastic:      titles:        time_table: diff --git a/db/migrate/20170106135000_add_calendar_ref_to_time_tables.rb b/db/migrate/20170106135000_add_calendar_ref_to_time_tables.rb new file mode 100644 index 000000000..9c7b8b578 --- /dev/null +++ b/db/migrate/20170106135000_add_calendar_ref_to_time_tables.rb @@ -0,0 +1,5 @@ +class AddCalendarRefToTimeTables < ActiveRecord::Migration +  def change +    add_reference :time_tables, :calendar, index: true +  end +end diff --git a/db/schema.rb b/db/schema.rb index 562bf2ab6..ab58b696f 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: 20161228092957) do +ActiveRecord::Schema.define(version: 20170106135000) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" @@ -644,8 +644,10 @@ ActiveRecord::Schema.define(version: 20161228092957) do      t.integer  "int_day_types",  default: 0      t.date     "start_date"      t.date     "end_date" +    t.integer  "calendar_id"    end +  add_index "time_tables", ["calendar_id"], :name => "index_time_tables_on_calendar_id"    add_index "time_tables", ["objectid"], :name => "time_tables_objectid_key", :unique => true    create_table "time_tables_vehicle_journeys", id: false, force: true do |t| diff --git a/spec/factories/chouette_time_table.rb b/spec/factories/chouette_time_table.rb index 722c977b2..f462349cf 100644 --- a/spec/factories/chouette_time_table.rb +++ b/spec/factories/chouette_time_table.rb @@ -2,29 +2,30 @@ FactoryGirl.define do    factory :time_table_date, :class => Chouette::TimeTableDate do    end -   +    factory :time_table_period, :class => Chouette::TimeTablePeriod do    end -   +    factory :time_table, :class => Chouette::TimeTable do      sequence(:comment) { |n| "Timetable #{n}" }      sequence(:objectid) { |n| "test:Timetable:#{n}" }      sequence(:int_day_types) { (1..7).to_a.map{ |n| 2**(n+1)}.sum } +    calendar nil      transient do        dates_count 4        periods_count 4      end -     +      after(:create) do |time_table, evaluator| -       +        0.upto(4) do |i|          time_table.dates  << create(:time_table_date, :time_table => time_table, :date => i.days.since.to_date, :in_out => true)        end -       +        start_date = Date.today        end_date = start_date + 10 -       +        0.upto(4) do |i|          time_table.periods << create(:time_table_period, :time_table => time_table, :period_start => start_date, :period_end => end_date)          start_date = start_date + 20 @@ -33,5 +34,5 @@ FactoryGirl.define do        time_table.save_shortcuts      end    end -   +  end | 
