diff options
| -rw-r--r-- | app/assets/stylesheets/components/_forms.sass | 8 | ||||
| -rw-r--r-- | app/javascript/helpers/master_slave.coffee | 18 | ||||
| -rw-r--r-- | app/javascript/packs/stop_areas/new.js | 3 | ||||
| -rw-r--r-- | app/models/chouette/area_type.rb | 25 | ||||
| -rw-r--r-- | app/models/chouette/stop_area.rb | 9 | ||||
| -rw-r--r-- | app/views/stop_areas/_form.html.slim | 10 | ||||
| -rw-r--r-- | app/views/stop_areas/show.html.slim | 8 | ||||
| -rw-r--r-- | config/locales/area_types.en.yml | 6 | ||||
| -rw-r--r-- | config/locales/area_types.fr.yml | 6 | ||||
| -rw-r--r-- | db/migrate/20180126134944_add_kind_to_stop_areas.rb | 5 | ||||
| -rw-r--r-- | db/schema.rb | 9 | ||||
| -rw-r--r-- | spec/models/chouette/area_type_spec.rb | 4 | 
12 files changed, 94 insertions, 17 deletions
| diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index b7f720963..214795b8b 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -85,9 +85,15 @@ input  // BS horizontal form label positionning fix  .form-horizontal +  input[type="radio"].form-control +    height: auto +    width: auto    .form-group      position: relative - +    .radio-inline +      padding-top: 4px +      &:first-child +        padding-left: 0      > .control-label        &[class*='col-sm-']          float: none diff --git a/app/javascript/helpers/master_slave.coffee b/app/javascript/helpers/master_slave.coffee new file mode 100644 index 000000000..11f6bca7e --- /dev/null +++ b/app/javascript/helpers/master_slave.coffee @@ -0,0 +1,18 @@ +class MasterSlave +  constructor: (selector)-> +    $(selector).find('[data-master]').each (i, slave)-> +      $slave = $(slave) +      master = $($slave.data().master) +      console.log $slave.data().master +      console.log master +      toggle = -> +        val = master.filter(":checked").val() if master.filter("[type=radio]").length > 0 +        val ||= master.val() +        selected = val == $slave.data().value +        $slave.toggle selected +        $slave.find("input, select").attr "disabled", !selected +      master.change toggle +      toggle() +      # $slave.toggle master.val() == $slave.data().value + +export default MasterSlave diff --git a/app/javascript/packs/stop_areas/new.js b/app/javascript/packs/stop_areas/new.js new file mode 100644 index 000000000..ffe702cdb --- /dev/null +++ b/app/javascript/packs/stop_areas/new.js @@ -0,0 +1,3 @@ +import MasterSlave from "../../helpers/master_slave" + +new MasterSlave("form") diff --git a/app/models/chouette/area_type.rb b/app/models/chouette/area_type.rb index 4703ea646..e17d2ee8d 100644 --- a/app/models/chouette/area_type.rb +++ b/app/models/chouette/area_type.rb @@ -1,13 +1,22 @@  class Chouette::AreaType    include Comparable -  ALL = %i(zdep zder zdlp zdlr lda gdl).freeze +  COMMERCIAL = %i(zdep zder zdlp zdlr lda gdl).freeze +  NON_COMMERCIAL = %i(deposit border service_area relief other).freeze +  ALL = COMMERCIAL + NON_COMMERCIAL +  @@commercial = COMMERCIAL +  @@non_commercial = NON_COMMERCIAL    @@all = ALL -  mattr_accessor :all +  mattr_accessor :all, :commercial, :non_commercial -  def self.all=(values) -    @@all = ALL & values +  def self.commercial=(values) +    @@commercial = COMMERCIAL & values +    reset_caches! +  end + +  def self.non_commercial=(values) +    @@non_commercial = NON_COMMERCIAL & values      reset_caches!    end @@ -20,12 +29,14 @@ class Chouette::AreaType    end    def self.reset_caches! +    @@all = @@commercial + @@non_commercial      @@instances = {} -    @@options = nil +    @@options = {}    end -  def self.options -    @@options ||= all.map { |c| find(c) }.map { |t| [ t.label, t.code ] } +  def self.options(kind=:all) +    @@options ||= {} +    @@options[kind] ||= self.send(kind).map { |c| find(c) }.map { |t| [ t.label, t.code ] }    end    attr_reader :code diff --git a/app/models/chouette/stop_area.rb b/app/models/chouette/stop_area.rb index ea1855ea8..d270a8696 100644 --- a/app/models/chouette/stop_area.rb +++ b/app/models/chouette/stop_area.rb @@ -10,6 +10,7 @@ module Chouette      extend Enumerize      enumerize :area_type, in: Chouette::AreaType::ALL +    enumerize :kind, in: %i(commercial non_commercial)      with_options dependent: :destroy do |assoc|        assoc.has_many :stop_points @@ -96,6 +97,10 @@ module Chouette        end      end +    def local_id +      id.to_s +    end +      def children_in_depth        return [] if self.children.empty? @@ -374,5 +379,9 @@ module Chouette        return nil unless time_zone.present?        ActiveSupport::TimeZone[time_zone]&.formatted_offset      end + +    def commercial? +      kind == "commercial" +    end    end  end diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index b2322f73a..699381d50 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -7,9 +7,13 @@          = f.input :id, as: :hidden          = f.input :name, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.name")} -        = f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}} +        = f.input :kind, as: :radio_buttons, :input_html => {:disabled => !@stop_area.new_record?}, :include_blank => false, item_wrapper_class: 'radio-inline', wrapper: :horizontal_form, item_class: "fooo" -        = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options, :include_blank => false +        .slave data-master="[name='stop_area[kind]']" data-value="commercial" +          = f.input :parent_id, as: :select, :collection => [f.object.parent_id], input_html: { data: { select2_ajax: 'true', url: autocomplete_stop_area_referential_stop_areas_path(@stop_area_referential), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:full_name)}}} +        - %i(commercial non_commercial).each do |kind| +          .slave data-master="[name='stop_area[kind]']" data-value=kind +            = f.input :area_type, as: :select, :input_html => {:disabled => !@stop_area.new_record?}, :collection => Chouette::AreaType.options(kind), :include_blank => false          .location_info            h3 = t("stop_areas.stop_area.localisation") @@ -49,3 +53,5 @@    .separator    = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'stop_area_form' + += javascript_pack_tag "stop_areas/new" diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index b5ec8ac00..b0896c1e0 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -6,11 +6,11 @@    .container-fluid      .row        .col-lg-6.col-md-6.col-sm-12.col-xs-12 -        - attributes = { t('id_reflex') => @stop_area.get_objectid.short_id, -            @stop_area.human_attribute_name(:parent) => @stop_area.parent ? link_to(@stop_area.parent.name, stop_area_referential_stop_area_path(@stop_area_referential, @stop_area.parent)) : "-", -            @stop_area.human_attribute_name(:stop_area_type) => Chouette::AreaType.find(@stop_area.area_type).try(:label), +        - attributes = { t('id_reflex') => @stop_area.get_objectid.short_id } +        - attributes.merge!({ @stop_area.human_attribute_name(:parent) => @stop_area.parent ? link_to(@stop_area.parent.name, stop_area_referential_stop_area_path(@stop_area_referential, @stop_area.parent)) : "-" }) if @stop_area.commercial? +        - attributes.merge!({ @stop_area.human_attribute_name(:stop_area_type) => Chouette::AreaType.find(@stop_area.area_type).try(:label),              @stop_area.human_attribute_name(:registration_number) => @stop_area.registration_number, -            } +            })          - attributes.merge!(@stop_area.human_attribute_name(:waiting_time) => @stop_area.waiting_time_text) if has_feature?(:stop_area_waiting_time)          - attributes.merge!({ "Coordonnées" => geo_data(@stop_area, @stop_area_referential),              @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code, diff --git a/config/locales/area_types.en.yml b/config/locales/area_types.en.yml index 34ec3243d..5d23a6665 100644 --- a/config/locales/area_types.en.yml +++ b/config/locales/area_types.en.yml @@ -6,3 +6,9 @@ en:        zdlp: ZDLp        zdlr: ZDLr        lda: LDA +      gdl: GDL +      deposit: Deposit +      border: Border +      service_area: Service Area +      relief: Relief point +      other: Other diff --git a/config/locales/area_types.fr.yml b/config/locales/area_types.fr.yml index fd4e1e741..bb249c235 100644 --- a/config/locales/area_types.fr.yml +++ b/config/locales/area_types.fr.yml @@ -6,3 +6,9 @@ fr:        zdlp: ZDLp        zdlr: ZDLr        lda: LDA +      gdl: GDL +      deposit: Dépôt +      border: Frontière +      service_area: Aire de service / Pause +      relief: Point de releve +      other: Autre diff --git a/db/migrate/20180126134944_add_kind_to_stop_areas.rb b/db/migrate/20180126134944_add_kind_to_stop_areas.rb new file mode 100644 index 000000000..3a4f0a0c8 --- /dev/null +++ b/db/migrate/20180126134944_add_kind_to_stop_areas.rb @@ -0,0 +1,5 @@ +class AddKindToStopAreas < ActiveRecord::Migration +  def change +    add_column :stop_areas, :kind, :string +  end +end diff --git a/db/schema.rb b/db/schema.rb index 2c5520110..b2063539b 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,13 +11,14 @@  #  # It's strongly recommended that you check this file into your version control system. -ActiveRecord::Schema.define(version: 20180111200406) do +ActiveRecord::Schema.define(version: 20180126134944) do    # These are extensions that must be enabled in order to support this database    enable_extension "plpgsql" -  enable_extension "postgis"    enable_extension "hstore" +  enable_extension "postgis"    enable_extension "unaccent" +  enable_extension "objectid"    create_table "access_links", id: :bigserial, force: :cascade do |t|      t.integer  "access_point_id",                        limit: 8 @@ -90,6 +91,8 @@ ActiveRecord::Schema.define(version: 20180111200406) do      t.integer   "organisation_id", limit: 8      t.datetime  "created_at"      t.datetime  "updated_at" +    t.integer   "int_day_types" +    t.date      "excluded_dates",                            array: true    end    add_index "calendars", ["organisation_id"], name: "index_calendars_on_organisation_id", using: :btree @@ -115,6 +118,7 @@ ActiveRecord::Schema.define(version: 20180111200406) do      t.datetime "updated_at"      t.date     "end_date"      t.string   "date_type" +    t.string   "mode"    end    add_index "clean_ups", ["referential_id"], name: "index_clean_ups_on_referential_id", using: :btree @@ -786,6 +790,7 @@ ActiveRecord::Schema.define(version: 20180111200406) do      t.datetime "updated_at"      t.string   "stif_type"      t.integer  "waiting_time" +    t.string   "kind"    end    add_index "stop_areas", ["name"], name: "index_stop_areas_on_name", using: :btree diff --git a/spec/models/chouette/area_type_spec.rb b/spec/models/chouette/area_type_spec.rb index 67d218df8..28325dd0a 100644 --- a/spec/models/chouette/area_type_spec.rb +++ b/spec/models/chouette/area_type_spec.rb @@ -4,7 +4,9 @@ RSpec.describe Chouette::AreaType do    describe "::ALL" do      it "includes all supported types" do -      expect(Chouette::AreaType::ALL).to match_array( %i(zdep zder zdlp zdlr lda gdl) ) +      expect(Chouette::AreaType::ALL).to match_array( %i(zdep zder zdlp zdlr lda gdl deposit border service_area relief other) ) +      expect(Chouette::AreaType::COMMERCIAL).to match_array( %i(zdep zder zdlp zdlr lda gdl) ) +      expect(Chouette::AreaType::NON_COMMERCIAL).to match_array( %i( deposit border service_area relief other) )      end    end | 
