diff options
| author | cedricnjanga | 2017-11-24 12:32:09 +0100 |
|---|---|---|
| committer | cedricnjanga | 2017-11-24 12:32:09 +0100 |
| commit | 4ee768d80cc5374c84ed0b06a43eb4f4bda0f825 (patch) | |
| tree | deea0d202e15a781fba98a5949bd84e879cc533e /app/decorators | |
| parent | 5b9351272ec0f02c2c76fd8b3168cbbc6acdedff (diff) | |
| download | chouette-core-4ee768d80cc5374c84ed0b06a43eb4f4bda0f825.tar.bz2 | |
Take into account code review
Diffstat (limited to 'app/decorators')
| -rw-r--r-- | app/decorators/company_decorator.rb | 86 | ||||
| -rw-r--r-- | app/decorators/line_decorator.rb | 70 | ||||
| -rw-r--r-- | app/decorators/network_decorator.rb | 72 | ||||
| -rw-r--r-- | app/decorators/route_decorator.rb | 122 | ||||
| -rw-r--r-- | app/decorators/routing_constraint_zone_decorator.rb | 70 | ||||
| -rw-r--r-- | app/decorators/stop_area_decorator.rb | 68 | ||||
| -rw-r--r-- | app/decorators/stop_point_decorator.rb | 12 | ||||
| -rw-r--r-- | app/decorators/time_table_decorator.rb | 90 |
8 files changed, 295 insertions, 295 deletions
diff --git a/app/decorators/company_decorator.rb b/app/decorators/company_decorator.rb index a95f90128..9416c73ae 100644 --- a/app/decorators/company_decorator.rb +++ b/app/decorators/company_decorator.rb @@ -1,52 +1,52 @@ - class CompanyDecorator < Draper::Decorator - decorates Chouette::Company +class CompanyDecorator < Draper::Decorator + decorates Chouette::Company - delegate_all + delegate_all - def self.collection_decorator_class - PaginatingDecorator - end + def self.collection_decorator_class + PaginatingDecorator + end + + def linecount + object.lines.count + end - def linecount - object.lines.count + # Requires: + # context: { + # referential: + # } + def action_links + links = [] + + if h.policy(Chouette::Company).create? + links << Link.new( + content: h.t('companies.actions.new'), + href: h.new_line_referential_company_path(context[:referential]) + ) end - # Requires: - # context: { - # referential: - # } - def action_links - links = [] - - if h.policy(Chouette::Company).create? - links << Link.new( - content: h.t('companies.actions.new'), - href: h.new_line_referential_company_path(context[:referential]) + if h.policy(object).update? + links << Link.new( + content: h.t('companies.actions.edit'), + href: h.edit_line_referential_company_path( + context[:referential], + object ) - end - - if h.policy(object).update? - links << Link.new( - content: h.t('companies.actions.edit'), - href: h.edit_line_referential_company_path( - context[:referential], - object - ) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: t('companies.actions.destroy'), - href: h.line_referential_company_path( - context[:referential], - object - ), - method: :delete, - data: { confirm: h.t('companies.actions.destroy_confirm') } - ) - end + ) + end - links + if h.policy(object).destroy? + links << Link.new( + content: t('companies.actions.destroy'), + href: h.line_referential_company_path( + context[:referential], + object + ), + method: :delete, + data: { confirm: h.t('companies.actions.destroy_confirm') } + ) end + + links end +end diff --git a/app/decorators/line_decorator.rb b/app/decorators/line_decorator.rb index d465f9321..f351103b2 100644 --- a/app/decorators/line_decorator.rb +++ b/app/decorators/line_decorator.rb @@ -1,45 +1,45 @@ - class LineDecorator < Draper::Decorator - decorates Chouette::Line +class LineDecorator < Draper::Decorator + decorates Chouette::Line - delegate_all + delegate_all - # Requires: - # context: { - # line_referential: , - # current_organisation: - # } - def action_links - links = [] + # Requires: + # context: { + # line_referential: , + # current_organisation: + # } + def action_links + links = [] + links << Link.new( + content: h.t('lines.actions.show_network'), + href: [context[:line_referential], object.network] + ) + + links << Link.new( + content: h.t('lines.actions.show_company'), + href: [context[:line_referential], object.company] + ) + + if h.policy(Chouette::Line).create? && + context[:line_referential].organisations.include?( + context[:current_organisation] + ) links << Link.new( - content: h.t('lines.actions.show_network'), - href: [context[:line_referential], object.network] + content: h.t('lines.actions.new'), + href: h.new_line_referential_line_path(context[:line_referential]) ) + end + if h.policy(object).destroy? links << Link.new( - content: h.t('lines.actions.show_company'), - href: [context[:line_referential], object.company] + content: h.destroy_link_content('lines.actions.destroy_confirm'), + href: h.line_referential_line_path(context[:line_referential], object), + method: :delete, + data: { confirm: h.t('lines.actions.destroy_confirm') } ) - - if h.policy(Chouette::Line).create? && - context[:line_referential].organisations.include?( - context[:current_organisation] - ) - links << Link.new( - content: h.t('lines.actions.new'), - href: h.new_line_referential_line_path(context[:line_referential]) - ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('lines.actions.destroy_confirm'), - href: h.line_referential_line_path(context[:line_referential], object), - method: :delete, - data: { confirm: h.t('lines.actions.destroy_confirm') } - ) - end - - links end + + links end +end diff --git a/app/decorators/network_decorator.rb b/app/decorators/network_decorator.rb index 4f22141e0..1f62fe512 100644 --- a/app/decorators/network_decorator.rb +++ b/app/decorators/network_decorator.rb @@ -1,44 +1,44 @@ - class NetworkDecorator < Draper::Decorator - decorates Chouette::Network +class NetworkDecorator < Draper::Decorator + decorates Chouette::Network - delegate_all + delegate_all - # Requires: - # context: { - # line_referential: , - # } - def action_links - links = [] + # Requires: + # context: { + # line_referential: , + # } + def action_links + links = [] - if h.policy(Chouette::Network).create? - links << Link.new( - content: h.t('networks.actions.new'), - href: h.new_line_referential_network_path(context[:line_referential]) - ) - end - - if h.policy(object).update? - links << Link.new( - content: h.t('networks.actions.edit'), - href: h.edit_line_referential_network_path( - context[:line_referential], - object - ) - ) - end + if h.policy(Chouette::Network).create? + links << Link.new( + content: h.t('networks.actions.new'), + href: h.new_line_referential_network_path(context[:line_referential]) + ) + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content('networks.actions.destroy'), - href: h.line_referential_network_path( - context[:line_referential], - object - ), - method: :delete, - data: { confirm: t('networks.actions.destroy_confirm') } + if h.policy(object).update? + links << Link.new( + content: h.t('networks.actions.edit'), + href: h.edit_line_referential_network_path( + context[:line_referential], + object ) - end + ) + end - links + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content('networks.actions.destroy'), + href: h.line_referential_network_path( + context[:line_referential], + object + ), + method: :delete, + data: { confirm: t('networks.actions.destroy_confirm') } + ) end + + links end +end diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index ca35c2dde..510c941a3 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -1,75 +1,75 @@ - class RouteDecorator < Draper::Decorator - decorates Chouette::Route +class RouteDecorator < Draper::Decorator + decorates Chouette::Route - delegate_all + delegate_all - # Requires: - # context: { - # referential: , - # line: - # } - def action_links - links = [] + # Requires: + # context: { + # referential: , + # line: + # } + def action_links + links = [] - if object.stop_points.any? - links << Link.new( - content: h.t('journey_patterns.index.title'), - href: [ - context[:referential], - context[:line], - object, - :journey_patterns_collection - ] - ) - end - - if object.journey_patterns.present? - links << Link.new( - content: h.t('vehicle_journeys.actions.index'), - href: [ - context[:referential], - context[:line], - object, - :vehicle_journeys - ] - ) - end + if object.stop_points.any? + links << Link.new( + content: h.t('journey_patterns.index.title'), + href: [ + context[:referential], + context[:line], + object, + :journey_patterns_collection + ] + ) + end + if object.journey_patterns.present? links << Link.new( - content: h.t('vehicle_journey_exports.new.title'), - href: h.referential_line_route_vehicle_journey_exports_path( + content: h.t('vehicle_journeys.actions.index'), + href: [ context[:referential], context[:line], object, - format: :zip - ) + :vehicle_journeys + ] ) + end - if h.policy(object).duplicate? - links << Link.new( - content: h.t('routes.duplicate.title'), - href: h.duplicate_referential_line_route_path( - context[:referential], - context[:line], - object - ), - method: :post - ) - end + links << Link.new( + content: h.t('vehicle_journey_exports.new.title'), + href: h.referential_line_route_vehicle_journey_exports_path( + context[:referential], + context[:line], + object, + format: :zip + ) + ) - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_line_route_path( - context[:referential], - context[:line], - object - ), - method: :delete, - data: { confirm: h.t('routes.actions.destroy_confirm') } - ) - end + if h.policy(object).duplicate? + links << Link.new( + content: h.t('routes.duplicate.title'), + href: h.duplicate_referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :post + ) + end - links + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_line_route_path( + context[:referential], + context[:line], + object + ), + method: :delete, + data: { confirm: h.t('routes.actions.destroy_confirm') } + ) end + + links end +end diff --git a/app/decorators/routing_constraint_zone_decorator.rb b/app/decorators/routing_constraint_zone_decorator.rb index 1d12cfc25..0b438a554 100644 --- a/app/decorators/routing_constraint_zone_decorator.rb +++ b/app/decorators/routing_constraint_zone_decorator.rb @@ -1,42 +1,42 @@ - class RoutingConstraintZoneDecorator < Draper::Decorator - decorates Chouette::RoutingConstraintZone +class RoutingConstraintZoneDecorator < Draper::Decorator + decorates Chouette::RoutingConstraintZone - delegate_all + delegate_all - # Requires: - # context: { - # referential: , - # line: - # } - def action_links - links = [] + # Requires: + # context: { + # referential: , + # line: + # } + def action_links + links = [] - if h.policy(object).update? - links << Link.new( - content: h.t('actions.edit'), - href: h.edit_referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ) + if h.policy(object).update? + links << Link.new( + content: h.t('actions.edit'), + href: h.edit_referential_line_routing_constraint_zone_path( + context[:referential], + context[:line], + object ) - end - - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_line_routing_constraint_zone_path( - context[:referential], - context[:line], - object - ), - method: :delete, - data: { - confirm: h.t('routing_constraint_zones.actions.destroy_confirm') - } - ) - end + ) + end - links + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_line_routing_constraint_zone_path( + context[:referential], + context[:line], + object + ), + method: :delete, + data: { + confirm: h.t('routing_constraint_zones.actions.destroy_confirm') + } + ) end + + links end +end diff --git a/app/decorators/stop_area_decorator.rb b/app/decorators/stop_area_decorator.rb index c64ecc9e3..4e777292d 100644 --- a/app/decorators/stop_area_decorator.rb +++ b/app/decorators/stop_area_decorator.rb @@ -1,43 +1,43 @@ - class StopAreaDecorator < Draper::Decorator - decorates Chouette::StopArea +class StopAreaDecorator < Draper::Decorator + decorates Chouette::StopArea - delegate_all + delegate_all - def action_links(stop_area = nil) - links = [] - stop_area ||= object + def action_links(stop_area = nil) + links = [] + stop_area ||= object - if h.policy(Chouette::StopArea).new? - links << Link.new( - content: h.t('stop_areas.actions.new'), - href: h.new_stop_area_referential_stop_area_path( - stop_area.stop_area_referential - ) + if h.policy(Chouette::StopArea).new? + links << Link.new( + content: h.t('stop_areas.actions.new'), + href: h.new_stop_area_referential_stop_area_path( + stop_area.stop_area_referential ) - end - - if h.policy(stop_area).update? - links << Link.new( - content: h.t('stop_areas.actions.edit'), - href: h.edit_stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ) - ) - end + ) + end - if h.policy(stop_area).destroy? - links << Link.new( - content: h.destroy_link_content('stop_areas.actions.destroy'), - href: h.stop_area_referential_stop_area_path( - stop_area.stop_area_referential, - stop_area - ), - method: :delete, - data: { confirm: t('stop_areas.actions.destroy_confirm') } + if h.policy(stop_area).update? + links << Link.new( + content: h.t('stop_areas.actions.edit'), + href: h.edit_stop_area_referential_stop_area_path( + stop_area.stop_area_referential, + stop_area ) - end + ) + end - links + if h.policy(stop_area).destroy? + links << Link.new( + content: h.destroy_link_content('stop_areas.actions.destroy'), + href: h.stop_area_referential_stop_area_path( + stop_area.stop_area_referential, + stop_area + ), + method: :delete, + data: { confirm: t('stop_areas.actions.destroy_confirm') } + ) end + + links end +end diff --git a/app/decorators/stop_point_decorator.rb b/app/decorators/stop_point_decorator.rb index f87db73e8..196d6d490 100644 --- a/app/decorators/stop_point_decorator.rb +++ b/app/decorators/stop_point_decorator.rb @@ -1,9 +1,9 @@ - class StopPointDecorator < StopAreaDecorator - decorates Chouette::StopPoint +class StopPointDecorator < StopAreaDecorator + decorates Chouette::StopPoint - delegate_all + delegate_all - def action_links - super(object.stop_area) - end + def action_links + super(object.stop_area) end +end diff --git a/app/decorators/time_table_decorator.rb b/app/decorators/time_table_decorator.rb index e2a5a7a97..c6eeac176 100644 --- a/app/decorators/time_table_decorator.rb +++ b/app/decorators/time_table_decorator.rb @@ -1,55 +1,55 @@ - class TimeTableDecorator < Draper::Decorator - decorates Chouette::TimeTable +class TimeTableDecorator < Draper::Decorator + decorates Chouette::TimeTable - delegate_all + delegate_all - # Requires: - # context: { - # referential: , - # } - def action_links - links = [] + # Requires: + # context: { + # referential: , + # } + def action_links + links = [] - if object.calendar - links << Link.new( - content: h.t('actions.actualize'), - href: h.actualize_referential_time_table_path( - context[:referential], - object - ), - method: :post - ) - end - - if h.policy(object).edit? - links << Link.new( - content: h.t('actions.combine'), - href: h.new_referential_time_table_time_table_combination_path( - context[:referential], - object - ) - ) - end + if object.calendar + links << Link.new( + content: h.t('actions.actualize'), + href: h.actualize_referential_time_table_path( + context[:referential], + object + ), + method: :post + ) + end - if h.policy(object).duplicate? - links << Link.new( - content: h.t('actions.duplicate'), - href: h.duplicate_referential_time_table_path( - context[:referential], - object - ) + if h.policy(object).edit? + links << Link.new( + content: h.t('actions.combine'), + href: h.new_referential_time_table_time_table_combination_path( + context[:referential], + object ) - end + ) + end - if h.policy(object).destroy? - links << Link.new( - content: h.destroy_link_content, - href: h.referential_time_table_path(context[:referential], object), - method: :delete, - data: { confirm: h.t('time_tables.actions.destroy_confirm') } + if h.policy(object).duplicate? + links << Link.new( + content: h.t('actions.duplicate'), + href: h.duplicate_referential_time_table_path( + context[:referential], + object ) - end + ) + end - links + if h.policy(object).destroy? + links << Link.new( + content: h.destroy_link_content, + href: h.referential_time_table_path(context[:referential], object), + method: :delete, + data: { confirm: h.t('time_tables.actions.destroy_confirm') } + ) end + + links end +end |
