aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2016-11-21 12:37:07 +0100
committerLuc Donnet2016-11-21 12:37:07 +0100
commit53263bf43dd386606204a1aaabc7d02aa282d332 (patch)
tree8e9bb329f7976e7ebae802d783d5a8058d63d7d5
parent61aa1075680b321212326a704d76a5dd60ea3e49 (diff)
parent0c05eb7e70644d5358896c55ed2e993bf379f584 (diff)
downloadchouette-core-53263bf43dd386606204a1aaabc7d02aa282d332.tar.bz2
Merge branch 'master' of github.com:AF83/stif-boiv
-rw-r--r--Gemfile.lock2
-rw-r--r--app/models/chouette/line.rb4
-rw-r--r--app/models/referential.rb8
-rw-r--r--app/models/referential_metadata.rb4
-rw-r--r--app/views/organisations/show.html.slim18
-rw-r--r--app/views/referentials/_form.html.slim26
-rw-r--r--app/views/shared/_lines_search_form.html.slim2
-rw-r--r--app/views/workbenches/show.html.slim14
-rw-r--r--config/environment.rb2
-rw-r--r--config/locales/lines.en.yml2
-rw-r--r--config/locales/lines.fr.yml2
-rw-r--r--config/locales/routes.fr.yml1
-rw-r--r--spec/models/referential_spec.rb17
13 files changed, 58 insertions, 44 deletions
diff --git a/Gemfile.lock b/Gemfile.lock
index 8ae079b8a..abfb75692 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -7,7 +7,7 @@ GIT
GIT
remote: git@github.com:AF83/has_array_of.git
- revision: e00963f9599035ffa11bf412e6923d7ff74a32f8
+ revision: a6439d93291c7a1ca224ea95a8d39ed101e2f05f
specs:
has_array_of (0.0.1)
activerecord (>= 4.0)
diff --git a/app/models/chouette/line.rb b/app/models/chouette/line.rb
index 80b901bd4..3f7a72021 100644
--- a/app/models/chouette/line.rb
+++ b/app/models/chouette/line.rb
@@ -67,4 +67,8 @@ class Chouette::Line < Chouette::ActiveRecord
self.vehicle_journeys.unscoped.where(journey_category: 1).count > 0
end
+ def display_name
+ [name, company.try(:name)].compact.join(' - ')
+ end
+
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 84bc1110d..b75ff3ab9 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -112,7 +112,7 @@ class Referential < ActiveRecord::Base
after_initialize :define_default_attributes
def define_default_attributes
- self.time_zone ||= Time.zone.tzinfo.name
+ self.time_zone ||= Time.zone.name
end
def switch
@@ -206,7 +206,7 @@ class Referential < ActiveRecord::Base
def metadatas_period
# FIXME
if metadatas.present?
- metadatas.first.periodes.first
+ metadatas.first.periodes.try :first
end
end
alias_method :validity_period, :metadatas_period
@@ -220,7 +220,7 @@ class Referential < ActiveRecord::Base
return [] unless metadatas.present?
line_ids = metadatas.first.line_ids
- period = metadatas.first.periodes.first
+ period = metadatas.first.periodes.try :first
return [] unless line_ids.present? && period
@@ -230,7 +230,7 @@ class Referential < ActiveRecord::Base
(SELECT unnest(public.referential_metadata.line_ids) as line, unnest(public.referential_metadata.periodes) as period, public.referential_metadata.referential_id
FROM public.referential_metadata
INNER JOIN public.referentials ON public.referential_metadata.referential_id = public.referentials.id
- WHERE public.referentials.workbench_id = 1 and public.referentials.archived_at is null) as metadatas
+ WHERE public.referentials.workbench_id = #{workbench_id} and public.referentials.archived_at is null) as metadatas
WHERE line in (#{line_ids.join(',')}) and period && '#{ActiveRecord::ConnectionAdapters::PostgreSQLColumn.range_to_string(period)}' #{not_myself};"
self.class.connection.select_values(query).map(&:to_i)
diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb
index 4228d2f7c..a1066e43b 100644
--- a/app/models/referential_metadata.rb
+++ b/app/models/referential_metadata.rb
@@ -7,6 +7,8 @@ class ReferentialMetadata < ActiveRecord::Base
validates :lines, presence: true
validates :periodes, presence: true
+ validates :first_period_begin, :first_period_end, presence: true
+
scope :include_lines, -> (line_ids) { where('line_ids && ARRAY[?]', line_ids) }
scope :include_dateranges, -> (dateranges) { where('periodes && ARRAY[?]', dateranges) }
@@ -18,6 +20,7 @@ class ReferentialMetadata < ActiveRecord::Base
@first_period_begin or first_period.try(:begin)
end
def first_period_begin=(date)
+ date = (Date.parse(date) rescue nil) if String === date
periodes_will_change! unless @first_period_begin == date
@first_period_begin = date
end
@@ -33,6 +36,7 @@ class ReferentialMetadata < ActiveRecord::Base
end
end
def first_period_end=(date)
+ date = (Date.parse(date) rescue nil) if String === date
periodes_will_change! unless @first_period_end == date
@first_period_end = date
end
diff --git a/app/views/organisations/show.html.slim b/app/views/organisations/show.html.slim
index b9259150a..bf9f464dd 100644
--- a/app/views/organisations/show.html.slim
+++ b/app/views/organisations/show.html.slim
@@ -17,18 +17,6 @@
.users.paginated_content
= paginated_content(@organisation.users, "users/user")
-#accordion.panel-group
- .panel.panel-default
- .panel-heading
- h4.panel-title
- a data-toggle="collapse" data-parent="#accordion" href="#rule_parameter_sets"
- = t('.rule_parameter_sets')
-
- #rule_parameter_sets.panel-collapse.collapse
- .panel-body
- .rule_parameter_sets.paginated_content
- = paginated_content(@organisation.rule_parameter_sets, "rule_parameter_sets/rule_parameter_set")
-
- content_for :sidebar do
ul.actions
/ FIXME ref #819
@@ -38,5 +26,7 @@
li
= link_to t('users.actions.new'), new_organisation_user_path, class: 'add'
- li
- = link_to t('rule_parameter_sets.actions.new'), new_organisation_rule_parameter_set_path, class: 'add' \ No newline at end of file
+ / FIXME ref #2007
+ - if false
+ li
+ = link_to t('rule_parameter_sets.actions.new'), new_organisation_rule_parameter_set_path, class: 'add'
diff --git a/app/views/referentials/_form.html.slim b/app/views/referentials/_form.html.slim
index 777c942f4..bce8818f2 100644
--- a/app/views/referentials/_form.html.slim
+++ b/app/views/referentials/_form.html.slim
@@ -2,25 +2,26 @@
.row
.col-lg-8.col-md-8.col-sm-7.col-xs-8
= form.input :name
-
+
- if @referential.new_record?
- if @referential.created_from
.col-lg-2.col-md-2.col-sm-3.col-xs-2
- = form.input :created_from, input_html: { value: @referential.created_from.name}
-
+ = form.input :created_from, disabled: true, input_html: { value: Referential.find(@referential.created_from_id).name }
+ = form.input :created_from_id, as: :hidden
+
.col-lg-2.col-md-2.col-sm-2.col-xs-2
= form.input :slug, :input_html => { title: t("formtastic.titles.referential.slug") }
- else
.col-lg-4.col-md-4.col-sm-5.col-xs-4
= form.input :slug, :input_html => { title: t("formtastic.titles.referential.slug") }
-
+
- else
- if @referential.created_from
.col-lg-2.col-md-2.col-sm-2.col-xs-2
label.control-label = @referential.human_attribute_name('slug')
br
= @referential.slug
-
+
.col-lg-2.col-md-2.col-sm-2.col-xs-2
label.control-label = @referential.human_attribute_name('created_from')
= @referential.created_from.name
@@ -35,11 +36,11 @@
= form.input :prefix, input_html: { title: t("formtastic.titles.referential.prefix") }
.col-lg-7.col-md-7.col-sm-7.col-xs-7
= form.input :projection_type, as: :select, collection: Referential.available_srids
-
+
.row
.col-lg-6.col-md-6.col-sm-6.col-xs-6
= form.input :time_zone
-
+
.row
.col-lg-6.col-md-6.col-sm-6.col-xs-6
= form.input :upper_corner, input_html: {title: t("formtastic.titles.referential.upper_corner")}
@@ -47,9 +48,11 @@
= form.input :lower_corner, input_html: {title: t("formtastic.titles.referential.lower_corner")}
- if @referential.errors.has_key? :metadatas
- ul.errors
- - @referential.errors[:metadatas].each do |message|
- li = message
+ .row
+ .col-lg-12
+ .alert.alert-danger
+ - @referential.errors[:metadatas].each do |message|
+ p.small = "- #{message}"
= form.simple_fields_for :metadatas do |subform|
.row
@@ -57,9 +60,10 @@
= subform.input :first_period_begin, as: :date, html5: true, input_html: { style: 'width: 100%' }
.col-lg-6.col-md-6.col-sm-6.col-xs-6
= subform.input :first_period_end, as: :date, html5: true, input_html: { style: 'width: 100%' }
+
.row
.col-lg-8.col-md-12.col-sm-12.col-xs-12
- = subform.input :lines, as: :select, collection: @referential.workbench.lines, selected: subform.object.line_ids, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection de lignes', 'multiple': 'multiple', style: 'width: 100%' }
+ = subform.input :lines, as: :select, collection: @referential.workbench.lines.includes(:company).order(:name), selected: subform.object.line_ids, label_method: :display_name, input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': 'Sélection de lignes', 'multiple': 'multiple', style: 'width: 100%' }
= form.input :workbench_id, as: :hidden
diff --git a/app/views/shared/_lines_search_form.html.slim b/app/views/shared/_lines_search_form.html.slim
index 4c6af7975..ec355ad8e 100644
--- a/app/views/shared/_lines_search_form.html.slim
+++ b/app/views/shared/_lines_search_form.html.slim
@@ -2,7 +2,7 @@
.panel.panel-default
.panel-heading
.input-group.col-md-9.col-sm-9
- = f.search_field :name_or_number_or_objectid_or_comment_cont, placeholder: t('lines.index.name_or_number_or_objectid_or_comment'), class: 'form-control'
+ = f.search_field :name_or_number_or_objectid_cont, placeholder: t('lines.index.name_or_number_or_objectid'), class: 'form-control'
.input-group-btn
button.btn.btn-primary type='submit'
i.fa.fa-search
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index 2f9937452..a979d85f8 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -55,14 +55,14 @@
li = link_to "Cloner", new_referential_path(from: referential)
- li
- - if referential.archived?
- - if referential.can_unarchive?
- = link_to "Désarchiver", unarchive_referential_path(referential), method: :put
- - else
- = link_to "Désarchiver", "#"
+ - if referential.archived?
+ - if referential.can_unarchive?
+ li = link_to "Désarchiver", unarchive_referential_path(referential), method: :put
- else
- = link_to "Archiver", archive_referential_path(referential), method: :put
+ li.disabled title="L'action est impossible pour ce référentiel"
+ = link_to "Désarchiver", "#"
+ - else
+ li = link_to "Archiver", archive_referential_path(referential), method: :put
li = link_to "Supprimer", referential_path(referential), method: :delete, :data => {:confirm => t('referentials.actions.destroy_confirm')}
diff --git a/config/environment.rb b/config/environment.rb
index 000bf1c03..592eda45a 100644
--- a/config/environment.rb
+++ b/config/environment.rb
@@ -6,4 +6,4 @@ require File.expand_path('../application', __FILE__)
Rails.application.initialize!
# Fix version
-APP_VERSION = 'Itération 5'
+APP_VERSION = 'Itération 7'
diff --git a/config/locales/lines.en.yml b/config/locales/lines.en.yml
index 51ea2a176..33e979a00 100644
--- a/config/locales/lines.en.yml
+++ b/config/locales/lines.en.yml
@@ -23,7 +23,7 @@ en:
deactivated: "Disabled line"
title: "Lines"
name_or_number: "Search by name or number..."
- name_or_number_or_objectid_or_comment: "Search by name, number, objectid or comment..."
+ name_or_number_or_objectid: "Search by name, number or objectid..."
no_networks: "No networks"
no_companies: "No companies"
no_group_of_lines: "No group of lines"
diff --git a/config/locales/lines.fr.yml b/config/locales/lines.fr.yml
index 0ac9e676e..58331b363 100644
--- a/config/locales/lines.fr.yml
+++ b/config/locales/lines.fr.yml
@@ -23,7 +23,7 @@ fr:
deactivated: "Ligne désactivée"
title: "Lignes"
name_or_number: "Recherche par nom ou indice..."
- name_or_number_or_objectid_or_comment: "Recherche par nom, indice, objectid ou commentaire..."
+ name_or_number_or_objectid: "Recherche par nom, indice ou objectid..."
no_networks: "Aucun réseaux"
no_companies: "Aucun transporteurs"
no_group_of_lines: "Aucun groupes de ligne"
diff --git a/config/locales/routes.fr.yml b/config/locales/routes.fr.yml
index 74a07e0c0..183531236 100644
--- a/config/locales/routes.fr.yml
+++ b/config/locales/routes.fr.yml
@@ -59,6 +59,7 @@ fr:
direction: "Direction"
wayback: "Sens"
opposite_route: "Itinéraire associé en sens opposé"
+ opposite_route_id: "Itinéraire associé en sens opposé"
objectid: "Identifiant Neptune"
object_version: "Version"
creation_time: "Créé le"
diff --git a/spec/models/referential_spec.rb b/spec/models/referential_spec.rb
index 4c9338aa6..2086f66d5 100644
--- a/spec/models/referential_spec.rb
+++ b/spec/models/referential_spec.rb
@@ -12,10 +12,21 @@ describe Referential, :type => :model do
it { should belong_to(:workbench) }
context "Cloning referential" do
- let(:cloned) { Referential.new_from(ref).tap(&:save!) }
+ let(:clone) do
+ Referential.new_from(ref)
+ end
+
+ let(:saved_clone) do
+ clone.tap do |clone|
+ clone.metadatas.each do |metadata|
+ metadata.periodes = metadata.periodes.map { |period| Range.new(period.end+1, period.end+10) }
+ end
+ clone.save!
+ end
+ end
it 'should create a ReferentialCloning' do
- expect { cloned }.to change{ReferentialCloning.count}.by(1)
+ expect { saved_clone }.to change{ReferentialCloning.count}.by(1)
end
def metadatas_attributes(referential)
@@ -23,7 +34,7 @@ describe Referential, :type => :model do
end
it 'should clone referential_metadatas' do
- expect(metadatas_attributes(cloned)).to eq(metadatas_attributes(ref))
+ expect(metadatas_attributes(clone)).to eq(metadatas_attributes(ref))
end
end