aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-06-16 12:31:41 +0200
committerRobert2017-06-16 12:31:41 +0200
commit42f6791028b56fc3b6210eec3a7d312b03634669 (patch)
tree9acfbe31878923f76c8e5791829ac4571b1a8742
parent7c83232e747ab468eb4d4ff0eb296ac84a8d25e9 (diff)
parentb8659463dfb09742619a964eb095a6b39fcf14a7 (diff)
downloadchouette-core-42f6791028b56fc3b6210eec3a7d312b03634669.tar.bz2
Merge branch 'master' of github.com:af83/stif-boiv
-rw-r--r--app/assets/javascripts/select2.coffee1
-rw-r--r--app/controllers/referentials_controller.rb7
-rw-r--r--app/models/referential.rb17
-rw-r--r--app/views/calendars/_form.html.slim4
-rw-r--r--app/views/referentials/_form.html.slim26
-rw-r--r--app/views/routes/_form.html.slim4
-rw-r--r--app/views/time_table_combinations/_form.html.slim12
-rw-r--r--app/views/time_tables/_form.html.slim2
-rw-r--r--config/initializers/simple_form_bootstrap.rb4
-rw-r--r--spec/features/referentials_spec.rb4
-rw-r--r--spec/features/workbenches_spec.rb2
-rw-r--r--spec/views/referentials/new.html.erb_spec.rb8
12 files changed, 33 insertions, 58 deletions
diff --git a/app/assets/javascripts/select2.coffee b/app/assets/javascripts/select2.coffee
index 5adaabda5..d54ddb811 100644
--- a/app/assets/javascripts/select2.coffee
+++ b/app/assets/javascripts/select2.coffee
@@ -20,6 +20,7 @@ bind_select2_ajax = (el, cfg = {}) ->
delay: 125,
processResults: (data, params) -> results: data
minimumInputLength: 3
+ placeholder: target.data('select2ed-placeholder')
templateResult: (item) ->
item.text
templateSelection: (item) ->
diff --git a/app/controllers/referentials_controller.rb b/app/controllers/referentials_controller.rb
index 437444f29..aa5b359da 100644
--- a/app/controllers/referentials_controller.rb
+++ b/app/controllers/referentials_controller.rb
@@ -74,7 +74,6 @@ class ReferentialsController < BreadcrumbController
alias_method :current_referential, :referential
helper_method :current_referential
-
def resource
@referential ||= current_organisation.find_referential(params[:id])
end
@@ -130,13 +129,7 @@ class ReferentialsController < BreadcrumbController
params.require(:referential).permit(
:id,
:name,
- :slug,
- :prefix,
- :time_zone,
- :upper_corner,
- :lower_corner,
:organisation_id,
- :projection_type,
:data_format,
:archived_at,
:created_from_id,
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 22bfe0d25..0ce325bd6 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -4,9 +4,10 @@ class Referential < ActiveRecord::Base
validates_presence_of :name
validates_presence_of :slug
validates_presence_of :prefix
- validates_presence_of :time_zone
- validates_presence_of :upper_corner
- validates_presence_of :lower_corner
+ # Fixme #3657
+ # validates_presence_of :time_zone
+ # validates_presence_of :upper_corner
+ # validates_presence_of :lower_corner
validates_uniqueness_of :slug
validates_uniqueness_of :name
@@ -179,6 +180,8 @@ class Referential < ActiveRecord::Base
before_validation :assign_line_and_stop_area_referential, :on => :create, if: :workbench, unless: :created_from
before_validation :clone_associations, :on => :create, if: :created_from
+ before_validation :assign_slug, :on => :create
+ before_validation :assign_prefix, :on => :create
before_create :create_schema, unless: :created_from
after_create :clone_schema, if: :created_from
@@ -288,6 +291,14 @@ class Referential < ActiveRecord::Base
Apartment::Tenant.create slug
end
+ def assign_slug
+ self.slug ||= "#{self.name.parameterize.gsub('-', '_')}_#{Time.now.to_i}"
+ end
+
+ def assign_prefix
+ self.prefix = self.organisation.name.parameterize.gsub('-', '_')
+ end
+
def assign_line_and_stop_area_referential
self.line_referential = workbench.line_referential
self.stop_area_referential = workbench.stop_area_referential
diff --git a/app/views/calendars/_form.html.slim b/app/views/calendars/_form.html.slim
index 9aed9f7d8..3c152c61d 100644
--- a/app/views/calendars/_form.html.slim
+++ b/app/views/calendars/_form.html.slim
@@ -6,8 +6,8 @@
- if policy(@calendar).share?
.form-group.has_switch
- = f.label :shared, class: 'col-sm-4 control-label'
- = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8'}
+ = f.label :shared, class: 'col-sm-4 col-xs-5 control-label'
+ = f.input :shared, as: :boolean, checked_value: true, unchecked_value: false, label: content_tag(:span, t("#{@calendar.shared}"), class: 'switch-label', data: {checkedValue: t('true'), uncheckedValue: t('false')}), wrapper_html: { class: 'col-sm-8 col-xs-7'}
.separator
diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim
index f209b278e..31d71bcdc 100644
--- a/app/views/referentials/_form.html.slim
+++ b/app/views/referentials/_form.html.slim
@@ -3,34 +3,16 @@
.row
.col-lg-12
= form.input :name
-
- - if @referential.new_record?
- = form.input :slug, input_html: { title: t('formtastic.titles.referential.slug') }
- - else
- = form.input :slug, disabled: true, input_html: { title: t('formtastic.titles.referential.slug') }
-
- if @referential.new_record?
- if @referential.created_from
= form.input :created_from, disabled: true, input_html: { value: Referential.find(@referential.created_from_id).name }
.hidden = form.input :created_from_id, as: :hidden
-
- = form.input :prefix, input_html: { title: t("formtastic.titles.referential.prefix") }
-
- else
- if @referential.created_from
= form.input :created_from, disabled: true, input_html: { value: Referential.find(@referential.created_from_id).name }
- = form.input :prefix, input_html: { title: t("formtastic.titles.referential.prefix") }
-
- = form.input :projection_type, as: :select, collection: Referential.available_srids
- = form.input :time_zone
-
-
- = form.input :upper_corner, input_html: {title: t("formtastic.titles.referential.upper_corner")}
- = form.input :lower_corner, input_html: {title: t("formtastic.titles.referential.lower_corner")}
-
.separator
-
+
= form.simple_fields_for :metadatas do |subform|
.row
.col-lg-12
@@ -40,7 +22,7 @@
.alert.alert-danger
- @referential.errors[:metadatas].each do |msg|
p.small = "- #{msg}"
-
+
.subform
.nested-head
.wrapper
@@ -55,10 +37,10 @@
= t('simple_form.labels.referential.metadatas.periods.end')
abbr title='requis' *
div
-
+
= subform.simple_fields_for :periods do |period_form|
= render 'period_fields', f: period_form
-
+
.links.nested-linker
= link_to_add_association 'Ajouter une période', subform, :periods, class: 'btn btn-outline-primary'
diff --git a/app/views/routes/_form.html.slim b/app/views/routes/_form.html.slim
index ad389c482..bee86f91e 100644
--- a/app/views/routes/_form.html.slim
+++ b/app/views/routes/_form.html.slim
@@ -6,8 +6,8 @@
= f.input :published_name
.form-group.has_switch
- = f.label :wayback, class: 'col-sm-4 control-label'
- = f.input :wayback, as: :boolean, checked_value: :straight_forward, unchecked_value: :backward, label: content_tag(:span, @route.wayback_text, class: 'switch-label', data: {checkedValue: t('enumerize.route.direction.straight_forward'), uncheckedValue: t('enumerize.route.direction.backward')}), wrapper_html: { class: 'col-sm-8'}
+ = f.label :wayback, class: 'col-sm-4 col-xs-5 control-label'
+ = f.input :wayback, as: :boolean, checked_value: :straight_forward, unchecked_value: :backward, label: content_tag(:span, @route.wayback_text, class: 'switch-label', data: {checkedValue: t('enumerize.route.direction.straight_forward'), uncheckedValue: t('enumerize.route.direction.backward')}), wrapper_html: { class: 'col-sm-8 col-xs-7'}
= f.input :opposite_route_id, collection: @forward, disabled: @route.wayback.straight_forward?, wrapper_html: {class: input_opposite_route_id_css(@route, 'straight_forward')}
diff --git a/app/views/time_table_combinations/_form.html.slim b/app/views/time_table_combinations/_form.html.slim
index d8bebf0c4..b4f818828 100644
--- a/app/views/time_table_combinations/_form.html.slim
+++ b/app/views/time_table_combinations/_form.html.slim
@@ -2,21 +2,21 @@
.row
.col-lg-12
.form-group.has_switch
- = f.label :combined_type, class: 'col-sm-4 control-label required' do
+ = f.label :combined_type, class: 'col-sm-4 col-xs-5 control-label required' do
= 'Type de calendriers '
abbr title='Champ requis' *
- = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8' }
+ = f.input :combined_type, as: :boolean, checked_value: 'time_table', unchecked_value: 'calendar', required: false, label: content_tag(:span, t("time_table_combinations.combined_type.#{@combination.combined_type}"), class: 'switch-label', data: { checkedValue: 'Calendriers', uncheckedValue: 'Modèles de calendriers' }), wrapper_html: { class: 'col-sm-8 col-xs-7' }
- = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', term: 'comment_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}
+ = f.input :time_table_id, as: :select, input_html: {class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un calendrier...', term: 'comment_or_objectid_cont', url: referential_autocomplete_time_tables_path(@referential, format: :json)}}, wrapper_html: {class: @combination.combined_type != 'time_table' ? 'hidden' : ''}
- = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''}
+ = f.input :calendar_id, as: :select, input_html: { class: 'tt_combination_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}, wrapper_html: {class: @combination.combined_type != 'calendar' ? 'hidden' : ''}
.separator
.row
.col-lg-12
- = f.label :operation, class: 'col-sm-4 control-label'
- = f.input :operation, as: :radio_buttons, label: false, collection: TimeTableCombination.operations, label_method: lambda{|o| t("time_table_combinations.operations.#{o}")}, wrapper_html: { class: 'col-sm-8' }
+ = f.label :operation, class: 'col-sm-4 col-xs-5 control-label'
+ = f.input :operation, as: :radio_buttons, label: false, collection: TimeTableCombination.operations, label_method: lambda{|o| t("time_table_combinations.operations.#{o}")}, wrapper_html: { class: 'col-sm-8 col-xs-7' }
= f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'tt_combination_form'
diff --git a/app/views/time_tables/_form.html.slim b/app/views/time_tables/_form.html.slim
index d4e1d838e..d06fdf444 100644
--- a/app/views/time_tables/_form.html.slim
+++ b/app/views/time_tables/_form.html.slim
@@ -5,7 +5,7 @@
= form.input :comment, :input_html => { :title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.time_table.comment")}
- if @time_table.new_record? && !@time_table.created_from
- = form.input :calendar_id, as: :select, collection: current_organisation.calendars
+ = form.input :calendar_id, as: :select, input_html: { class: 'tt_target', style: "width: 100%", data: { 'select2-ajax': 'true', 'select2ed-placeholder': 'Indiquez un modèle de calendrier...', term: 'name_cont', url: autocomplete_calendars_path}}
- if @time_table.created_from
= form.input :created_from, disabled: true, input_html: { value: @time_table.created_from.comment }
diff --git a/config/initializers/simple_form_bootstrap.rb b/config/initializers/simple_form_bootstrap.rb
index 67dfe1ceb..d90ea6398 100644
--- a/config/initializers/simple_form_bootstrap.rb
+++ b/config/initializers/simple_form_bootstrap.rb
@@ -58,9 +58,9 @@ SimpleForm.setup do |config|
b.optional :pattern
b.optional :min_max
b.optional :readonly
- b.use :label, class: 'col-sm-4 control-label'
+ b.use :label, class: 'col-sm-4 col-xs-5 control-label'
- b.wrapper tag: 'div', class: 'col-sm-8' do |ba|
+ b.wrapper tag: 'div', class: 'col-sm-8 col-xs-7' do |ba|
ba.use :input, class: 'form-control'
ba.use :error, wrap_with: { tag: 'span', class: 'help-block small' }
ba.use :hint, wrap_with: { tag: 'p', class: 'help-block small' }
diff --git a/spec/features/referentials_spec.rb b/spec/features/referentials_spec.rb
index 089f818e8..337271fea 100644
--- a/spec/features/referentials_spec.rb
+++ b/spec/features/referentials_spec.rb
@@ -109,13 +109,9 @@ describe "Referentials", :type => :feature do
end
describe "create" do
-
it "should" do
visit new_referential_path
fill_in "Nom", :with => "Test"
- fill_in "Code", :with => "test"
- fill_in "Point haut/droite de l'emprise par défaut", :with => "0.0, 0.0"
- fill_in "Point bas/gauche de l'emprise par défaut", :with => "1.0, 1.0"
click_button "Valider"
expect(Referential.where(:name => "Test")).not_to be_nil
diff --git a/spec/features/workbenches_spec.rb b/spec/features/workbenches_spec.rb
index c11fbd03d..953eb2bf5 100644
--- a/spec/features/workbenches_spec.rb
+++ b/spec/features/workbenches_spec.rb
@@ -46,8 +46,6 @@ describe 'Workbenches', type: :feature do
click_link I18n.t('actions.add')
fill_in "referential[name]", with: "Referential to test creation" # Nom du JDD
- fill_in "referential[slug]", with: "test" # Code
- fill_in "referential[prefix]", with: "test" # Prefix Neptune
select workbench.lines.first.id, from: 'referential[metadatas_attributes][0][lines][]' # Lignes
click_button "Valider"
diff --git a/spec/views/referentials/new.html.erb_spec.rb b/spec/views/referentials/new.html.erb_spec.rb
index 0673b4578..554e71d29 100644
--- a/spec/views/referentials/new.html.erb_spec.rb
+++ b/spec/views/referentials/new.html.erb_spec.rb
@@ -5,15 +5,9 @@ describe "referentials/new", :type => :view do
before(:each) do
assign(:referential, Referential.new)
end
-
+
it "should have a textfield for name" do
render
expect(rendered).to have_field("referential[name]")
end
-
- it "should have a textfield for slug" do
- render
- expect(rendered).to have_field("referential[slug]")
- end
-
end