diff options
| author | Luc Donnet | 2017-12-15 10:11:17 +0100 | 
|---|---|---|
| committer | Luc Donnet | 2017-12-21 13:54:07 +0100 | 
| commit | 0cf1d52d1dfc83fe304c7f3b7f7e1114ade28c11 (patch) | |
| tree | 07cc76b653c49c28d9a3aed19619d728f22fa560 | |
| parent | 8af4523f211519035d47e003c0eee4291dd2459d (diff) | |
| download | chouette-core-0cf1d52d1dfc83fe304c7f3b7f7e1114ade28c11.tar.bz2 | |
Fix migrations, locales, view and exclude calendar timetable in concern Refs #5301
| -rw-r--r-- | app/controllers/business_calendars_controller.rb | 4 | ||||
| -rw-r--r-- | app/models/calendar.rb | 4 | ||||
| -rw-r--r-- | app/models/concerns/calendar_support.rb | 9 | ||||
| -rw-r--r-- | app/views/business_calendars/_date_value_fields.html.slim | 13 | ||||
| -rw-r--r-- | app/views/business_calendars/_form.html.slim | 20 | ||||
| -rw-r--r-- | app/views/business_calendars/_period_fields.html.slim | 15 | ||||
| -rw-r--r-- | config/locales/business_calendars.fr.yml | 76 | ||||
| -rw-r--r-- | config/locales/businnes_calendars.en.yml | 76 | ||||
| -rw-r--r-- | db/migrate/20171214131755_create_business_calendars.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 13 | 
10 files changed, 211 insertions, 24 deletions
| diff --git a/app/controllers/business_calendars_controller.rb b/app/controllers/business_calendars_controller.rb index ee990dfba..617a07855 100644 --- a/app/controllers/business_calendars_controller.rb +++ b/app/controllers/business_calendars_controller.rb @@ -21,7 +21,7 @@ class BusinessCalendarsController < ChouetteController    private    def business_calendar_params -    permitted_params = [:id, :name, :short_name, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]] +    permitted_params = [:id, :name, :short_name, :color, periods_attributes: [:id, :begin, :end, :_destroy], date_values_attributes: [:id, :value, :_destroy]]      params.require(:business_calendar).permit(*permitted_params)    end @@ -30,4 +30,4 @@ class BusinessCalendarsController < ChouetteController        business_calendars,        with: BusinessCalendarDecorator)    end -end
\ No newline at end of file +end diff --git a/app/models/calendar.rb b/app/models/calendar.rb index 4e8cd0977..5df2bb1da 100644 --- a/app/models/calendar.rb +++ b/app/models/calendar.rb @@ -4,7 +4,9 @@ require_relative 'calendar/period'  class Calendar < ActiveRecord::Base    include CalendarSupport -   + +  has_many :time_tables +    scope :contains_date, ->(date) { where('date ? = any (dates) OR date ? <@ any (date_ranges)', date, date) }    def self.ransackable_scopes(auth_object = nil) diff --git a/app/models/concerns/calendar_support.rb b/app/models/concerns/calendar_support.rb index 9d27f4c0d..73bb201ec 100644 --- a/app/models/concerns/calendar_support.rb +++ b/app/models/concerns/calendar_support.rb @@ -1,16 +1,15 @@  module CalendarSupport    extend ActiveSupport::Concern -   +    included do      has_paper_trail      belongs_to :organisation -    has_many :time_tables      validates_presence_of :name, :short_name, :organisation      validates_uniqueness_of :short_name      after_initialize :init_dates_and_date_ranges -     -     + +      def init_dates_and_date_ranges        self.dates ||= []        self.date_ranges ||= [] @@ -154,4 +153,4 @@ module CalendarSupport      private :clear_date_values    end -end
\ No newline at end of file +end diff --git a/app/views/business_calendars/_date_value_fields.html.slim b/app/views/business_calendars/_date_value_fields.html.slim new file mode 100644 index 000000000..7bde06a94 --- /dev/null +++ b/app/views/business_calendars/_date_value_fields.html.slim @@ -0,0 +1,13 @@ +.nested-fields +  - if f.object.errors.has_key? :base +    .row +      .col-lg-12 +        .alert.alert-danger +          - f.object.errors[:base].each do |message| +            p.small = message + +  .wrapper +    div +      = f.input :value, as: :date, label: false, wrapper_html: { class: 'date smart_date' } +    div +      = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete') diff --git a/app/views/business_calendars/_form.html.slim b/app/views/business_calendars/_form.html.slim index c2c9fb3a1..a7c0d8c4a 100644 --- a/app/views/business_calendars/_form.html.slim +++ b/app/views/business_calendars/_form.html.slim @@ -2,9 +2,11 @@    .row      .col-lg-12        = f.input :name +      = f.input :short_name +      = f.input :color    .separator -   +    .row      .col-lg-12        .subform @@ -13,17 +15,17 @@              div                .form-group                  label.control-label -                  = BusinessCalendar.human_attribute_name(:date) +                  = Calendar.human_attribute_name(:date)              div          = f.simple_fields_for :date_values do |date_value| -          = render 'calendars/date_fields', f: date_value +          = render 'date_value_fields', f: date_value          .links.nested-linker -          = link_to_add_association t('simple_form.labels.calendar.add_a_date'), f, :dates, class: 'btn btn-outline-primary' -   +          = link_to_add_association t('simple_form.labels.business_calendar.add_a_date'), f, :date_values, class: 'btn btn-outline-primary' +    .separator -   +    .row      .col-lg-12        .subform @@ -32,16 +34,16 @@              div                .form-group                  label.control-label -                  = t('simple_form.labels.calendar.ranges.begin') +                  = t('simple_form.labels.business_calendar.ranges.begin')              div                .form-group                  label.control-label -                  = t('simple_form.labels.calendar.ranges.end') +                  = t('simple_form.labels.business_calendar.ranges.end')              div          = f.simple_fields_for :periods do |period|            = render 'period_fields', f: period          .links.nested-linker -          = link_to_add_association t('simple_form.labels.calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary' +          = link_to_add_association t('simple_form.labels.business_calendar.add_a_date_range'), f, :periods, class: 'btn btn-outline-primary'    = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'business_calendar_form' diff --git a/app/views/business_calendars/_period_fields.html.slim b/app/views/business_calendars/_period_fields.html.slim new file mode 100644 index 000000000..95e204554 --- /dev/null +++ b/app/views/business_calendars/_period_fields.html.slim @@ -0,0 +1,15 @@ +.nested-fields +  - if f.object.errors.has_key? :base +    .row +      .col-lg-12 +        .alert.alert-danger +          - f.object.errors[:base].each do |message| +            p.small = message + +  .wrapper +    div +      = f.input :begin, as: :date, label: false, wrapper_html: { class: 'date smart_date' } +    div +      = f.input :end, as: :date, label: false, wrapper_html: { class: 'date smart_date' } +    div +      = link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete') diff --git a/config/locales/business_calendars.fr.yml b/config/locales/business_calendars.fr.yml new file mode 100644 index 000000000..a67864384 --- /dev/null +++ b/config/locales/business_calendars.fr.yml @@ -0,0 +1,76 @@ +fr: +  business_calendars: +    search_no_results: 'Aucun calendrier commercial ne correspond à votre recherche' +    days: +      monday: L +      tuesday: Ma +      wednesday: Me +      thursday: J +      friday: V +      saturday: S +      sunday: D +    months: +      1: Janvier +      2: Février +      3: Mars +      4: Avril +      5: Mai +      6: Juin +      7: Juillet +      8: Août +      9: Septembre +      10: Octobre +      11: Novembre +      12: Décembre +    standard_calendars: Calendriers standards +    standard_calendar: Calendrier standard +    actions: +      new: Ajouter un calendrier commercial +      edit: Editer cet calendrier commercial +      destroy: Supprimer ce calendrier commercial +      destroy_confirm: Etes vous sûr de supprimer cet calendrier commercial ? +    errors: +      overlapped_periods: Une autre période chevauche cette période +      short_period: Une période doit être d'un duréé de deux jours minimum +    index: +      title: Calendriers commerciaux +      all: Tous +      shared: Partagées +      not_shared: Non partagées +      search_no_results: Aucun calendrier commercial ne correspond à votre recherche +      date: Date +    new: +      title: Ajouter un calendrier commercial +    edit: +      title: Editer le calendrier comercial %{name} +    show: +      title: Calendrier commercial %{name} +  simple_form: +    labels: +      calendar: +        date_value: Date +        add_a_date: Ajouter une date +        add_a_date_range: Ajouter un intervalle de dates +        ranges: +          begin: Début +          end: Fin +  activerecord: +    models: +      one: "calendrier commercial" +      other: "calendriers commerciaux" +    attributes: +      business_calendar: +        name: Nom +        short_name: Nom court +        date_ranges: Intervalles de dates +        dates: Dates +        organisation: Organisation +        color: Couleur +    errors: +      models: +        business_calendar: +          attributes: +            dates: +              date_in_date_ranges: Une même date ne peut pas être incluse à la fois dans la liste et dans les intervalles de dates. +              date_in_dates: Une même date ne peut pas être incluse plusieurs fois dans la liste. +              illegal_date: La date %{date} n'existe pas. diff --git a/config/locales/businnes_calendars.en.yml b/config/locales/businnes_calendars.en.yml new file mode 100644 index 000000000..6232adc43 --- /dev/null +++ b/config/locales/businnes_calendars.en.yml @@ -0,0 +1,76 @@ +en: +  business_calendars: +    search_no_results: 'No business calendar matching your query' +    days: +      monday: M +      tuesday: Tu +      wednesday: W +      thursday: Th +      friday: F +      saturday: Sa +      sunday: Su +    months: +      1: January +      2: February +      3: March +      4: April +      5: May +      6: June +      7: July +      8: August +      9: September +      10: October +      11: November +      12: December +    standard_calendars: Standard calendars +    standard_calendar: Standard calendar +    actions: +      new: Add a new business calendar +      edit: Edit this business calendar +      destroy: Remove this business calendar +      destroy_confirm: Are you sure you want destroy this business calendar? +    errors: +      overlapped_periods: Another period is overlapped with this period +      short_period: A period needs to last at least two days +    index: +      title: Business calendars +      all: All +      shared: Shared +      not_shared: Not shared +      search_no_results: No business calendar matching your query +      date: Date +    new: +      title: Add a new business calendar +    edit: +      title: Update business calendar %{name} +    show: +      title: Business calendar %{name} +  simple_form: +    labels: +      business_calendar: +        date_value: Date +        add_a_date: Add a date +        add_a_date_range: Add a date range +        ranges: +          begin: Beginning +          end: End +  activerecord: +    models: +      one: business calendar +      other: business calendars +    attributes: +      business_calendar: +        name: Name +        short_name: Short name +        date_ranges: Date ranges +        dates: Dates +        organisation: Organisation +        color: Color +    errors: +      models: +        business_calendar: +          attributes: +            dates: +              date_in_date_ranges: A date can not be in Dates and in Date ranges. +              date_in_dates: A date can appear only once in the list of dates. +              illegal_date: The date %{date} does not exist. diff --git a/db/migrate/20171214131755_create_business_calendars.rb b/db/migrate/20171214131755_create_business_calendars.rb index 5bb3db9d3..aa7c1ab12 100644 --- a/db/migrate/20171214131755_create_business_calendars.rb +++ b/db/migrate/20171214131755_create_business_calendars.rb @@ -4,8 +4,9 @@ class CreateBusinessCalendars < ActiveRecord::Migration        t.string :name        t.string :short_name        t.string :color -      t.date :dates -      t.daterange :date_ranges +      t.daterange :date_ranges, array: true +      t.date :dates, array: true +      t.belongs_to :organisation, index: true        t.timestamps null: false      end diff --git a/db/schema.rb b/db/schema.rb index a51a3bb42..36128807a 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -85,12 +85,15 @@ ActiveRecord::Schema.define(version: 20171214130636) do      t.string    "name"      t.string    "short_name"      t.string    "color" -    t.date      "dates" -    t.daterange "date_ranges" -    t.datetime  "created_at",  null: false -    t.datetime  "updated_at",  null: false +    t.daterange "date_ranges",                  array: true +    t.date      "dates",                        array: true +    t.integer   "organisation_id" +    t.datetime  "created_at",      null: false +    t.datetime  "updated_at",      null: false    end +  add_index "business_calendars", ["organisation_id"], name: "index_business_calendars_on_organisation_id", using: :btree +    create_table "calendars", id: :bigserial, force: :cascade do |t|      t.string    "name"      t.string    "short_name" @@ -413,9 +416,9 @@ ActiveRecord::Schema.define(version: 20171214130636) do      t.string   "type"      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 | 
