aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcedricnjanga2018-04-04 14:55:25 -0700
committerGitHub2018-04-04 14:55:25 -0700
commitc327d2ec90851bfe1f81c072ef328bd68ea55f38 (patch)
tree89a52107e5fe4bef33fa273fc32240dcc9901986
parentf04d4420053dc995bad52b5b87ff7f15e302c2b3 (diff)
parent461e1b085e745e819e95649bf3509ca6055ce827 (diff)
downloadchouette-core-c327d2ec90851bfe1f81c072ef328bd68ea55f38.tar.bz2
Merge branch 'master' into 6370-translations-26370-translations-2
-rw-r--r--app/controllers/routes_controller.rb3
-rw-r--r--app/decorators/route_decorator.rb17
-rw-r--r--app/javascript/time_tables/actions/index.js5
-rw-r--r--app/models/chouette/route.rb24
-rw-r--r--app/models/chouette/stop_point.rb3
-rw-r--r--app/policies/route_policy.rb4
-rw-r--r--app/views/calendars/show.html.slim7
-rw-r--r--config/locales/routes.fr.yml4
-rw-r--r--spec/controllers/routes_controller_spec.rb36
-rw-r--r--spec/models/chouette/route/route_duplication_spec.rb3
10 files changed, 86 insertions, 20 deletions
diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb
index 96a23c938..ac243c8eb 100644
--- a/app/controllers/routes_controller.rb
+++ b/app/controllers/routes_controller.rb
@@ -63,7 +63,8 @@ class RoutesController < ChouetteController
end
def duplicate
- route = Chouette::Route.find(params[:id]).duplicate
+ source = Chouette::Route.find(params[:id])
+ route = source.duplicate params[:opposite]
flash[:notice] = t('routes.duplicate.success')
redirect_to referential_line_path(@referential, route.line)
end
diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb
index fa6367924..4a173cbb9 100644
--- a/app/decorators/route_decorator.rb
+++ b/app/decorators/route_decorator.rb
@@ -71,6 +71,23 @@ class RouteDecorator < AF83::Decorator
end
end
+ instance_decorator.action_link(
+ secondary: :show,
+ policy: :create_opposite,
+ if: ->{h.has_feature?(:create_opposite_routes) && object.opposite_route.nil?}
+ ) do |l|
+ l.content h.t('routes.create_opposite.title')
+ l.method :post
+ l.href do
+ h.duplicate_referential_line_route_path(
+ context[:referential],
+ context[:line],
+ object,
+ opposite: true
+ )
+ end
+ end
+
instance_decorator.destroy_action_link do |l|
l.data confirm: h.t('routes.actions.destroy_confirm')
end
diff --git a/app/javascript/time_tables/actions/index.js b/app/javascript/time_tables/actions/index.js
index 3127d11b8..7c79dfe52 100644
--- a/app/javascript/time_tables/actions/index.js
+++ b/app/javascript/time_tables/actions/index.js
@@ -306,10 +306,11 @@ const actions = {
})
},
errorModalKey: (periods, dayTypes) => {
- const withoutPeriodsWithDaysTypes = reject(periods, 'deleted').length == 0 && some(dayTypes) && "withoutPeriodsWithDaysTypes"
+ // const withoutPeriodsWithDaysTypes = reject(periods, 'deleted').length == 0 && some(dayTypes) && "withoutPeriodsWithDaysTypes"
const withPeriodsWithoutDayTypes = reject(periods, 'deleted').length > 0 && every(dayTypes, dt => dt == false) && "withPeriodsWithoutDayTypes"
- return (withoutPeriodsWithDaysTypes || withPeriodsWithoutDayTypes) && (withoutPeriodsWithDaysTypes ? "withoutPeriodsWithDaysTypes" : "withPeriodsWithoutDayTypes")
+ // return (withoutPeriodsWithDaysTypes || withPeriodsWithoutDayTypes) && (withoutPeriodsWithDaysTypes ? "withoutPeriodsWithDaysTypes" : "withPeriodsWithoutDayTypes")
+ return withPeriodsWithoutDayTypes
},
errorModalMessage: (errorKey) => {
diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb
index 13288bc6b..65947c392 100644
--- a/app/models/chouette/route.rb
+++ b/app/models/chouette/route.rb
@@ -68,28 +68,34 @@ module Chouette
validates_presence_of :published_name
validates_presence_of :line
validates :wayback, inclusion: { in: self.wayback.values }
-
after_save :calculate_costs!, if: ->() { TomTom.enabled? }
-
- def duplicate
+
+ def duplicate opposite=false
overrides = {
'opposite_route_id' => nil,
'name' => I18n.t('activerecord.copy', name: self.name)
}
+ keys_for_create = attributes.keys - %w{id objectid created_at updated_at}
atts_for_create = attributes
- .slice!(*%w{id objectid created_at updated_at})
+ .slice(*keys_for_create)
.merge(overrides)
+ if opposite
+ atts_for_create[:wayback] = self.opposite_wayback
+ atts_for_create[:name] = I18n.t('routes.opposite', name: self.name)
+ atts_for_create[:published_name] = atts_for_create[:name]
+ atts_for_create[:opposite_route_id] = self.id
+ end
new_route = self.class.create!(atts_for_create)
- duplicate_stop_points(for_route: new_route)
+ duplicate_stop_points(for_route: new_route, opposite: opposite)
new_route
end
- def duplicate_stop_points(for_route:)
- stop_points.each(&duplicate_stop_point(for_route: for_route))
+ def duplicate_stop_points(for_route:, opposite: false)
+ stop_points.each(&duplicate_stop_point(for_route: for_route, opposite: opposite))
end
- def duplicate_stop_point(for_route:)
+ def duplicate_stop_point(for_route:, opposite: false)
-> stop_point do
- stop_point.duplicate(for_route: for_route)
+ stop_point.duplicate(for_route: for_route, opposite: opposite)
end
end
diff --git a/app/models/chouette/stop_point.rb b/app/models/chouette/stop_point.rb
index 6b363cd93..da2da998a 100644
--- a/app/models/chouette/stop_point.rb
+++ b/app/models/chouette/stop_point.rb
@@ -39,11 +39,12 @@ module Chouette
end
end
- def duplicate(for_route:)
+ def duplicate(for_route:, opposite: false)
keys_for_create = attributes.keys - %w{id objectid created_at updated_at}
atts_for_create = attributes
.slice(*keys_for_create)
.merge('route_id' => for_route.id)
+ atts_for_create["position"] = self.route.stop_points.size - atts_for_create["position"] if opposite
self.class.create!(atts_for_create)
end
diff --git a/app/policies/route_policy.rb b/app/policies/route_policy.rb
index 0337a5300..4fcb6be11 100644
--- a/app/policies/route_policy.rb
+++ b/app/policies/route_policy.rb
@@ -20,4 +20,8 @@ class RoutePolicy < ApplicationPolicy
def duplicate?
create?
end
+
+ def create_opposite?
+ create?
+ end
end
diff --git a/app/views/calendars/show.html.slim b/app/views/calendars/show.html.slim
index 648c98928..880db99f6 100644
--- a/app/views/calendars/show.html.slim
+++ b/app/views/calendars/show.html.slim
@@ -6,8 +6,7 @@
.row
.col-lg-6.col-md-6.col-sm-12.col-xs-12
= definition_list t('metadatas'),
- { Calendar.tmf('short_name') => resource.try(:short_name),
- Calendar.tmf('shared') => t("#{resource.shared}"),
+ { Calendar.tmf('shared') => t("#{resource.shared}"),
Calendar.tmf('organisation') => resource.organisation.name,
Calendar.tmf('dates') => resource.dates.collect{|d| l(d, format: :short)}.join(', ').html_safe,
Calendar.tmf('date_ranges') => resource.periods.map{|d| t('validity_range', debut: l(d.begin, format: :short), end: l(d.end, format: :short))}.join('<br>').html_safe }
@@ -18,7 +17,7 @@
.pagination.pull-right
= @year
.page_links
- = link_to '', calendar_path(@calendar, year: (@year - 1)), class: 'previous_page'
- = link_to '', calendar_path(@calendar, year: (@year + 1)), class: 'next_page'
+ = link_to '', workgroup_calendar_path(@workgroup, @calendar, year: (@year - 1)), class: 'previous_page'
+ = link_to '', workgroup_calendar_path(@workgroup, @calendar, year: (@year + 1)), class: 'next_page'
= render 'time_tables/show_time_table', time_table: @calendar
diff --git a/config/locales/routes.fr.yml b/config/locales/routes.fr.yml
index 01f957496..f4eefa10d 100644
--- a/config/locales/routes.fr.yml
+++ b/config/locales/routes.fr.yml
@@ -16,6 +16,7 @@ fr:
add_stop_point: "Ajouter un arrêt"
new_stop_point: "Créer un arrêt pour l'ajouter"
reversed_vehicle_journey: "Horaires retour"
+ opposite: "%{name} (retour)"
new:
title: "Ajouter un itinéraire"
edit:
@@ -56,6 +57,9 @@ fr:
stop_area_name: "Nom de l'arrêt"
for_boarding: "Montée"
for_alighting: "Descente"
+ create_opposite:
+ title: "Créer retour"
+ success: "itinéraire créé avec succès"
duplicate:
title: "Dupliquer l'itinéraire"
success: "itinéraire dupliqué avec succès"
diff --git a/spec/controllers/routes_controller_spec.rb b/spec/controllers/routes_controller_spec.rb
index e4dc6bc23..a001a942d 100644
--- a/spec/controllers/routes_controller_spec.rb
+++ b/spec/controllers/routes_controller_spec.rb
@@ -83,6 +83,42 @@ RSpec.describe RoutesController, type: :controller do
expect(Chouette::Route.last.name).to eq(I18n.t('activerecord.copy', name: route.name))
expect(Chouette::Route.last.published_name).to eq(route.published_name)
+ expect(Chouette::Route.last.stop_area_ids).to eq route.stop_area_ids
+ end
+
+ context "when opposite = true" do
+ it "creates a new route on the opposite way " do
+ expect do
+ post :duplicate,
+ referential_id: route.line.line_referential_id,
+ line_id: route.line_id,
+ id: route.id,
+ opposite: TRUE
+ end.to change { Chouette::Route.count }.by(1)
+
+ expect(Chouette::Route.last.name).to eq(I18n.t('routes.opposite', name: route.name))
+ expect(Chouette::Route.last.published_name).to eq(Chouette::Route.last.name)
+ expect(Chouette::Route.last.opposite_route).to eq(route)
+ expect(Chouette::Route.last.stop_area_ids).to eq route.stop_area_ids.reverse
+ end
+ end
+
+ context "on a duplicated route" do
+ let!(:duplicated){ route.duplicate }
+ it "creates a new route on the opposite way " do
+ expect do
+ post :duplicate,
+ referential_id: duplicated.line.line_referential_id,
+ line_id: duplicated.line_id,
+ id: duplicated.id,
+ opposite: TRUE
+ end.to change { Chouette::Route.count }.by(1)
+
+ expect(Chouette::Route.last.name).to eq(I18n.t('routes.opposite', name: duplicated.name))
+ expect(Chouette::Route.last.published_name).to eq(Chouette::Route.last.name)
+ expect(Chouette::Route.last.opposite_route).to eq(duplicated)
+ expect(Chouette::Route.last.stop_area_ids).to eq duplicated.stop_area_ids.reverse
+ end
end
end
end
diff --git a/spec/models/chouette/route/route_duplication_spec.rb b/spec/models/chouette/route/route_duplication_spec.rb
index 8b3a948a2..47233b04e 100644
--- a/spec/models/chouette/route/route_duplication_spec.rb
+++ b/spec/models/chouette/route/route_duplication_spec.rb
@@ -8,9 +8,6 @@ RSpec.describe Chouette::Route do
route.duplicate
expect( values_for_create(Chouette::Route.last, except: %w{objectid name checksum checksum_source}) ).to eq( values_for_create( route, except: %w{objectid name checksum checksum_source} ) )
end
- it 'and others cannot' do
- expect{ route.duplicate name: 'YAN', line_id: 42 }.to raise_error(ArgumentError)
- end
it 'same associated stop_areeas' do
expect( route.duplicate.stop_areas.pluck(:id) ).to eq(route.stop_areas.pluck(:id))
end