aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorZog2018-01-31 11:39:39 +0100
committerZog2018-01-31 11:39:39 +0100
commitfe7915ffac359db41c7737a3847f31a728f502e6 (patch)
treee733b44018321cc8eec28b147813cb279db40b7a /app
parent4023ea52097a47458ac2fcad36d343aba0c8e68b (diff)
downloadchouette-core-fe7915ffac359db41c7737a3847f31a728f502e6.tar.bz2
Refs #5683 @2H; Fix specs and refactor action_links
Note: Did not fix the missing workgroup in the calendar mailer
Diffstat (limited to 'app')
-rw-r--r--app/controllers/calendars_controller.rb21
-rw-r--r--app/decorators/calendar_decorator.rb2
-rw-r--r--app/decorators/company_decorator.rb19
-rw-r--r--app/decorators/compliance_control_decorator.rb18
-rw-r--r--app/decorators/import_decorator.rb7
-rw-r--r--app/decorators/line_decorator.rb10
-rw-r--r--app/decorators/network_decorator.rb14
-rw-r--r--app/decorators/purchase_window_decorator.rb18
-rw-r--r--app/decorators/referential_line_decorator.rb10
-rw-r--r--app/decorators/referential_network_decorator.rb21
-rw-r--r--app/decorators/route_decorator.rb29
-rw-r--r--app/decorators/routing_constraint_zone_decorator.rb39
-rw-r--r--app/decorators/stop_area_decorator.rb22
-rw-r--r--app/helpers/table_builder_helper.rb1
14 files changed, 50 insertions, 181 deletions
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index 193680342..6f1522428 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -4,7 +4,7 @@ class CalendarsController < ChouetteController
before_action :ransack_contains_date, only: [:index]
respond_to :html
respond_to :js, only: :index
-
+
belongs_to :workgroup
def index
@@ -24,9 +24,8 @@ class CalendarsController < ChouetteController
private
def decorate_calendars(calendars)
- ModelDecorator.decorate(
+ CalendarDecorator.decorate(
calendars,
- with: CalendarDecorator,
context: {
workgroup: workgroup
}
@@ -65,13 +64,13 @@ class CalendarsController < ChouetteController
def collection
@calendars ||= begin
- scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true)
- scope = shared_scope(scope)
- @q = scope.ransack(params[:q])
- calendars = @q.result
- calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
- calendars = calendars.paginate(page: params[:page])
- end
+ scope = workgroup.calendars.where('(organisation_id = ? OR shared = ?)', current_organisation.id, true)
+ scope = shared_scope(scope)
+ @q = scope.ransack(params[:q])
+ calendars = @q.result
+ calendars = calendars.order(sort_column + ' ' + sort_direction) if sort_column && sort_direction
+ calendars = calendars.paginate(page: params[:page])
+ end
end
def ransack_contains_date
@@ -96,4 +95,4 @@ class CalendarsController < ChouetteController
scope
end
-end \ No newline at end of file
+end
diff --git a/app/decorators/calendar_decorator.rb b/app/decorators/calendar_decorator.rb
index be1f9e3bf..0a7cbc312 100644
--- a/app/decorators/calendar_decorator.rb
+++ b/app/decorators/calendar_decorator.rb
@@ -1,6 +1,8 @@
class CalendarDecorator < AF83::Decorator
decorates Calendar
+ set_scope { context[:workgroup] }
+
create_action_link
with_instance_decorator do |instance_decorator|
diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb
index aadce68bb..5580e0d4a 100644
--- a/app/decorators/company_decorator.rb
+++ b/app/decorators/company_decorator.rb
@@ -1,34 +1,21 @@
class CompanyDecorator < AF83::Decorator
decorates Chouette::Company
+ set_scope { context[:referential] }
+
create_action_link do |l|
l.content { h.t('companies.actions.new') }
- l.href { [:new, context[:referential], :company] }
end
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href { [context[:referential], object] }
- end
+ instance_decorator.show_action_link
instance_decorator.edit_action_link do |l|
l.content {|l| l.action == "show" ? h.t('actions.edit') : h.t('companies.actions.edit') }
- l.href {
- h.edit_line_referential_company_path(
- context[:referential],
- object
- )
- }
end
instance_decorator.destroy_action_link do |l|
l.content { h.destroy_link_content('companies.actions.destroy') }
- l.href {
- h.edit_line_referential_company_path(
- context[:referential],
- object
- )
- }
l.data {{ confirm: h.t('companies.actions.destroy_confirm') }}
end
end
diff --git a/app/decorators/compliance_control_decorator.rb b/app/decorators/compliance_control_decorator.rb
index c57a7ccc7..fd2dbd9ce 100644
--- a/app/decorators/compliance_control_decorator.rb
+++ b/app/decorators/compliance_control_decorator.rb
@@ -1,6 +1,8 @@
class ComplianceControlDecorator < AF83::Decorator
decorates ComplianceControl
+ set_scope { object.compliance_control_set }
+
with_instance_decorator do |instance_decorator|
instance_decorator.show_action_link do |l|
l.content h.t('compliance_control_sets.actions.show')
@@ -12,23 +14,9 @@ class ComplianceControlDecorator < AF83::Decorator
end
end
- instance_decorator.edit_action_link do |l|
- l.href do
- h.edit_compliance_control_set_compliance_control_path(
- object.compliance_control_set_id,
- object.id
- )
- end
- end
+ instance_decorator.edit_action_link
instance_decorator.destroy_action_link do |l|
- l.content h.destroy_link_content
- l.href do
- h.compliance_control_set_compliance_control_path(
- object.compliance_control_set.id,
- object.id
- )
- end
l.data confirm: h.t('compliance_controls.actions.destroy_confirm')
end
end
diff --git a/app/decorators/import_decorator.rb b/app/decorators/import_decorator.rb
index c6b1f2349..1964365ae 100644
--- a/app/decorators/import_decorator.rb
+++ b/app/decorators/import_decorator.rb
@@ -1,6 +1,8 @@
class ImportDecorator < AF83::Decorator
decorates Import
+ set_scope { context[:workbench] }
+
define_instance_method :import_status_css_class do
cls =''
cls = 'overheaded-success' if object.status == 'successful'
@@ -11,13 +13,10 @@ class ImportDecorator < AF83::Decorator
create_action_link do |l|
l.content t('imports.actions.new')
- l.href { h.new_workbench_import_path(workbench_id: context[:workbench]) }
end
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href { h.workbench_import_path(context[:workbench], object) }
- end
+ instance_decorator.show_action_link
instance_decorator.action_link secondary: :show do |l|
l.content t('imports.actions.download')
diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb
index 9171a6310..039ad90a3 100644
--- a/app/decorators/line_decorator.rb
+++ b/app/decorators/line_decorator.rb
@@ -1,9 +1,10 @@
class LineDecorator < AF83::Decorator
decorates Chouette::Line
+ set_scope { context[:line_referential] }
+
create_action_link do |l|
l.content t('lines.actions.new')
- l.href { h.new_line_referential_line_path(context[:line_referential]) }
end
with_instance_decorator do |instance_decorator|
@@ -14,17 +15,16 @@ class LineDecorator < AF83::Decorator
instance_decorator.show_action_link do |l|
l.content t('lines.actions.show')
- l.href { [context[:line_referential], object] }
end
instance_decorator.action_link secondary: :show do |l|
l.content t('lines.actions.show_network')
- l.href { [context[:line_referential], object.network] }
+ l.href { [scope, object.network] }
end
instance_decorator.action_link secondary: :show do |l|
l.content t('lines.actions.show_company')
- l.href { [context[:line_referential], object.company] }
+ l.href { [scope, object.company] }
l.disabled { object.company.nil? }
end
@@ -33,7 +33,6 @@ class LineDecorator < AF83::Decorator
instance_decorator.with_condition can_edit_line do
edit_action_link do |l|
l.content {|l| l.primary? ? h.t('actions.edit') : h.t('lines.actions.edit') }
- l.href { h.edit_line_referential_line_path(context[:line_referential], object.id) }
end
action_link on: :index, secondary: :index do |l|
@@ -63,7 +62,6 @@ class LineDecorator < AF83::Decorator
instance_decorator.destroy_action_link do |l|
l.content { h.destroy_link_content('lines.actions.destroy') }
- l.href { h.line_referential_line_path(context[:line_referential], object) }
l.data confirm: h.t('lines.actions.destroy_confirm')
l.add_class "delete-action"
end
diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb
index 90f0d0e82..ea0f73dc2 100644
--- a/app/decorators/network_decorator.rb
+++ b/app/decorators/network_decorator.rb
@@ -1,6 +1,7 @@
class NetworkDecorator < AF83::Decorator
decorates Chouette::Network
+ set_scope { context[:line_referential] }
# Action links require:
# context: {
# line_referential: ,
@@ -8,15 +9,10 @@ class NetworkDecorator < AF83::Decorator
create_action_link do |l|
l.content t('networks.actions.new')
- l.href { h.new_line_referential_network_path(context[:line_referential]) }
end
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href do
- h.line_referential_network_path(context[:line_referential], object)
- end
- end
+ instance_decorator.show_action_link
instance_decorator.action_link secondary: true, policy: :edit do |l|
l.content t('networks.actions.edit')
@@ -30,12 +26,6 @@ class NetworkDecorator < AF83::Decorator
instance_decorator.destroy_action_link do |l|
l.content h.destroy_link_content('networks.actions.destroy')
- l.href do
- h.line_referential_network_path(
- context[:line_referential],
- object
- )
- end
l.data confirm: h.t('networks.actions.destroy_confirm')
end
end
diff --git a/app/decorators/purchase_window_decorator.rb b/app/decorators/purchase_window_decorator.rb
index 54b241173..9b58577b2 100644
--- a/app/decorators/purchase_window_decorator.rb
+++ b/app/decorators/purchase_window_decorator.rb
@@ -1,32 +1,20 @@
class PurchaseWindowDecorator < AF83::Decorator
decorates Chouette::PurchaseWindow
+ set_scope { context[:referential] }
+
create_action_link do |l|
l.content t('purchase_windows.actions.new')
- l.href { h.new_referential_purchase_window_path(context[:referential]) }
end
with_instance_decorator do |instance_decorator|
instance_decorator.show_action_link do |l|
l.content t('purchase_windows.actions.show')
- l.href do
- h.referential_purchase_window_path(
- context[:referential],
- object
- )
- end
end
- instance_decorator.edit_action_link do |l|
- l.href do
- h.edit_referential_purchase_window_path(context[:referential].id, object)
- end
- end
+ instance_decorator.edit_action_link
instance_decorator.destroy_action_link do |l|
- l.href do
- h.referential_purchase_window_path(context[:referential].id, object)
- end
l.data confirm: h.t('purchase_windows.actions.destroy_confirm')
end
end
diff --git a/app/decorators/referential_line_decorator.rb b/app/decorators/referential_line_decorator.rb
index 8f884a8e0..3ac846d76 100644
--- a/app/decorators/referential_line_decorator.rb
+++ b/app/decorators/referential_line_decorator.rb
@@ -1,6 +1,8 @@
class ReferentialLineDecorator < AF83::Decorator
decorates Chouette::Line
+ set_scope { context[:referential] }
+
# Action links require:
# context: {
# referential: ,
@@ -8,9 +10,7 @@ class ReferentialLineDecorator < AF83::Decorator
# }
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href { h.referential_line_path(context[:referential], object) }
- end
+ instance_decorator.show_action_link
instance_decorator.action_link secondary: true do |l|
l.content Chouette::Line.human_attribute_name(:footnotes)
@@ -21,7 +21,7 @@ class ReferentialLineDecorator < AF83::Decorator
l.content h.t('routing_constraint_zones.index.title')
l.href do
h.referential_line_routing_constraint_zones_path(
- context[:referential],
+ scope,
object
)
end
@@ -37,7 +37,7 @@ class ReferentialLineDecorator < AF83::Decorator
secondary: true
) do |l|
l.content h.t('routes.actions.new')
- l.href { h.new_referential_line_route_path(context[:referential], object) }
+ l.href { h.new_referential_line_route_path(scope, object) }
end
end
end
diff --git a/app/decorators/referential_network_decorator.rb b/app/decorators/referential_network_decorator.rb
index ff3467188..c508452c0 100644
--- a/app/decorators/referential_network_decorator.rb
+++ b/app/decorators/referential_network_decorator.rb
@@ -1,6 +1,8 @@
class ReferentialNetworkDecorator < AF83::Decorator
decorates Chouette::Network
+ set_scope { context[:referential] }
+
# Action links require:
# context: {
# referential: ,
@@ -8,33 +10,18 @@ class ReferentialNetworkDecorator < AF83::Decorator
create_action_link do |l|
l.content t('networks.actions.new')
- l.href { h.new_referential_network_path(context[:referential]) }
end
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href { h.referential_network_path(context[:referential], object) }
- end
+ instance_decorator.show_action_link
instance_decorator.edit_action_link do |l|
l.content t('networks.actions.edit')
- l.href do
- h.edit_referential_network_path(
- context[:referential],
- object
- )
- end
end
instance_decorator.destroy_action_link do |l|
l.content h.destroy_link_content('networks.actions.destroy')
- l.href do
- h.referential_network_path(
- context[:referential],
- object
- )
- end
l.data confirm: h.t('networks.actions.destroy_confirm')
end
end
-end \ No newline at end of file
+end
diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb
index 7e3ea889f..75ef20d63 100644
--- a/app/decorators/route_decorator.rb
+++ b/app/decorators/route_decorator.rb
@@ -7,26 +7,12 @@ class RouteDecorator < AF83::Decorator
# line:
# }
+ set_scope { [context[:referential], context[:line]] }
+
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href do
- h.referential_line_route_path(
- context[:referential],
- context[:line],
- object
- )
- end
- end
+ instance_decorator.show_action_link
- instance_decorator.edit_action_link do |l|
- l.href do
- h.edit_referential_line_route_path(
- context[:referential],
- context[:line],
- object
- )
- end
- end
+ instance_decorator.edit_action_link
instance_decorator.action_link(
if: ->() { object.stop_points.any? },
@@ -85,13 +71,6 @@ class RouteDecorator < AF83::Decorator
end
instance_decorator.destroy_action_link do |l|
- l.href do
- h.referential_line_route_path(
- context[:referential],
- context[:line],
- object
- )
- end
l.data confirm: h.t('routes.actions.destroy_confirm')
end
end
diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb
index 962625fa7..de73068be 100644
--- a/app/decorators/routing_constraint_zone_decorator.rb
+++ b/app/decorators/routing_constraint_zone_decorator.rb
@@ -1,6 +1,8 @@
class RoutingConstraintZoneDecorator < AF83::Decorator
decorates Chouette::RoutingConstraintZone
+ set_scope { [context[:referential], context[:line]] }
+
# Action links require:
# context: {
# referential: ,
@@ -12,44 +14,13 @@ class RoutingConstraintZoneDecorator < AF83::Decorator
h.policy(Chouette::RoutingConstraintZone).create? &&
context[:referential].organisation == h.current_organisation
}
- ) do |l|
- l.href do
- h.new_referential_line_routing_constraint_zone_path(
- context[:referential],
- context[:line]
- )
- end
- end
+ )
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href do
- h.referential_line_routing_constraint_zone_path(
- context[:referential],
- context[:line],
- object
- )
- end
- end
-
- instance_decorator.edit_action_link do |l|
- l.href do
- h.edit_referential_line_routing_constraint_zone_path(
- context[:referential],
- context[:line],
- object
- )
- end
- end
+ instance_decorator.show_action_link
+ instance_decorator.edit_action_link
instance_decorator.destroy_action_link do |l|
- l.href do
- h.referential_line_routing_constraint_zone_path(
- context[:referential],
- context[:line],
- object
- )
- end
l.data confirm: h.t('routing_constraint_zones.actions.destroy_confirm')
end
end
diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb
index 2e57da0e4..525681971 100644
--- a/app/decorators/stop_area_decorator.rb
+++ b/app/decorators/stop_area_decorator.rb
@@ -7,23 +7,11 @@ class StopAreaDecorator < AF83::Decorator
end
with_instance_decorator do |instance_decorator|
- instance_decorator.show_action_link do |l|
- l.href do
- h.stop_area_referential_stop_area_path(
- object.stop_area_referential,
- object
- )
- end
- end
+ set_scope { object.stop_area_referential }
+ instance_decorator.show_action_link
instance_decorator.edit_action_link do |l|
l.content h.t('stop_areas.actions.edit')
- l.href do
- h.edit_stop_area_referential_stop_area_path(
- object.stop_area_referential,
- object
- )
- end
end
instance_decorator.action_link policy: :deactivate, secondary: true do |l|
@@ -54,12 +42,6 @@ class StopAreaDecorator < AF83::Decorator
instance_decorator.destroy_action_link do |l|
l.content h.destroy_link_content('stop_areas.actions.destroy')
- l.href do
- h.stop_area_referential_stop_area_path(
- object.stop_area_referential,
- object
- )
- end
l.data confirm: h.t('stop_areas.actions.destroy_confirm')
end
end
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index f48075ed9..2068dd23c 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -395,7 +395,6 @@ module TableBuilderHelper
klass << link.extra_class if link.extra_class
klass << 'delete-action' if link.method == :delete
klass << 'disabled' if link.disabled
-
content_tag(
:li,
link_to(