# coding: utf-8 module BreadcrumbHelper def build_breadcrumb(action) action = action.to_sym case resource_class.to_s when "Chouette::Network" network_breadcrumb action when "Chouette::Company" company_breadcrumb action when "Chouette::GroupOfLine" group_of_line_breadcrumb action when "Chouette::Line" line_breadcrumb action when "Chouette::Route" route_breadcrumb action when "Chouette::JourneyPattern" journey_pattern_breadcrumb action when "Chouette::VehicleJourney" vehicle_journey_breadcrumb action when "Chouette::VehicleJourneyFrequency" vehicle_journey_frequency_breadcrumb action when "VehicleJourneyImport" vehicle_journey_import_breadcrumb action when "Chouette::StopArea" stop_area_breadcrumb action when "Chouette::AccessPoint" access_point_breadcrumb action when "Chouette::AccessLink" access_link_breadcrumb action when "Chouette::ConnectionLink" connection_link_breadcrumb action when "Chouette::TimeTable" time_table_breadcrumb action when "Chouette::RouteSection" route_section_breadcrumb action when "Chouette::Timeband" timeband_breadcrumb action when 'Chouette::RoutingConstraintZone' routing_constraint_zone_breadcrumb action when 'Calendar' calendar_breadcrumb action when "StopAreaCopy" stop_area_copy_breadcrumb action when "Import" import_breadcrumb action when "Export" export_breadcrumb action when "ComplianceCheck" compliance_check_breadcrumb action when "ComplianceCheckTask" compliance_check_task_breadcrumb action when "ComplianceControlSets" compliance_control_sets_breadcrumb action when "RuleParameterSet" rule_parameter_breadcrumb action when "User" user_breadcrumb action when "Referential" referential_breadcrumb action when "LineReferential" line_referential_breadcrumb action when "Organisation" organisation_breadcrumb action when "Api::V1::ApiKey" referential_breadcrumb when "Workbench" workbench_breadcrumb action else Rails.logger.info "---------" Rails.logger.info ">>>>>>> "+resource_class.to_s+" unmapped" Rails.logger.info "---------" organisation_breadcrumb :index end end def calendar_breadcrumb(action) add_breadcrumb I18n.t('breadcrumbs.referentials'), workbenches_path add_breadcrumb I18n.t('calendars.index.title'), calendars_path add_breadcrumb @calendar.name if %i(show edit).include? action end def workbench_breadcrumb(action) add_breadcrumb I18n.t("breadcrumbs.referentials"), workbenches_path add_breadcrumb breadcrumb_label(@workbench), workbench_path(@workbench), :title => breadcrumb_tooltip(@workbench) end def network_breadcrumb(action) if @line_referential line_referential_breadcrumb add_breadcrumb Chouette::Network.model_name.human(:count => 2).capitalize, line_referential_networks_path(@line_referential) unless action == :index add_breadcrumb breadcrumb_label(@network), line_referential_network_path(@line_referential, @network),:title => breadcrumb_tooltip(@network) if action == :edit else referential_breadcrumb add_breadcrumb Chouette::Network.model_name.human(:count => 2).capitalize, referential_networks_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@network), referential_network_path(@referential, @network),:title => breadcrumb_tooltip(@network) if action == :edit end end def group_of_line_breadcrumb(action) if @line_referential line_referential_breadcrumb add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2).capitalize, line_referential_group_of_lines_path(@line_referential) unless action == :index add_breadcrumb breadcrumb_label(@group_of_line), line_referential_group_of_line_path(@line_referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit else referential_breadcrumb add_breadcrumb Chouette::GroupOfLine.model_name.human(:count => 2).capitalize, referential_group_of_lines_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@group_of_line), referential_group_of_line_path(@referential, @group_of_line),:title => breadcrumb_tooltip(@group_of_line) if action == :edit end end def stop_area_breadcrumb(action) referential_breadcrumb add_breadcrumb Chouette::StopArea.model_name.human(:count => 2).capitalize, stop_area_referential_stop_areas_path(@stop_area.stop_area_referential) unless action == :index add_breadcrumb breadcrumb_label(@stop_area), stop_area_referential_stop_area_path(@stop_area.stop_area_referential, @stop_area),:title => breadcrumb_tooltip(@stop_area) if action == :edit end def stop_area_copy_breadcrumb(action) stop_area_breadcrumb :edit end def access_point_breadcrumb(action) stop_area_breadcrumb :edit add_breadcrumb breadcrumb_label(@access_point), referential_stop_area_access_point_path(@referential, @access_point.stop_area,@access_point),:title => breadcrumb_tooltip(@access_point) if action == :edit end def access_link_breadcrumb(action) access_point_breadcrumb :edit add_breadcrumb Chouette::AccessLink.model_name.human(:count => 2).capitalize.capitalize, access_links_referential_stop_area_path(@referential, @stop_area) add_breadcrumb breadcrumb_label(@access_link), referential_access_point_access_link_path(@referential, @access_point,@access_link),:title => breadcrumb_tooltip(@access_link) if action == :edit end def connection_link_breadcrumb(action) referential_breadcrumb add_breadcrumb Chouette::ConnectionLink.model_name.human.pluralize.capitalize, referential_connection_links_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@connection_link), referential_connection_link_path(@referential, @connection_link),:title => breadcrumb_tooltip(@connection_link) if action == :edit end def time_table_breadcrumb(action) referential_breadcrumb add_breadcrumb Chouette::TimeTable.model_name.human(:count => 2).capitalize, referential_time_tables_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@time_table), referential_time_table_path(@referential, @time_table),:title => breadcrumb_tooltip(@time_table) if action == :edit end def route_section_breadcrumb(action) referential_breadcrumb add_breadcrumb Chouette::RouteSection.model_name.human.pluralize, referential_route_sections_path(@referential) add_breadcrumb breadcrumb_label(resource), referential_route_section_path(@referential, resource),:title => breadcrumb_tooltip(resource) if action.in?([:show, :edit]) end def timeband_breadcrumb(action) referential_breadcrumb add_breadcrumb Chouette::Timeband.model_name.human(:count => 2).capitalize, referential_timebands_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@timeband), referential_timeband_path(@referential, @timeband),:title => breadcrumb_tooltip(@timeband) if action == :edit end def line_breadcrumb(action) if @line_referential line_referential_breadcrumb add_breadcrumb Chouette::Line.model_name.human(:count => 2).capitalize, line_referential_lines_path(@line_referential) unless action == :index add_breadcrumb breadcrumb_label(@line), line_referential_line_path(@line_referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit else referential_breadcrumb add_breadcrumb breadcrumb_label(@line), referential_line_path(@referential, @line),:title => breadcrumb_tooltip(@line) if action == :edit end end def route_breadcrumb(action) line_breadcrumb :edit add_breadcrumb breadcrumb_label(@route), referential_line_route_path(@referential, @line,@route),:title => breadcrumb_tooltip(@route) if action == :edit end def routing_constraint_zone_breadcrumb(action) line_breadcrumb :edit add_breadcrumb Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr), referential_line_routing_constraint_zones_path(@referential, @line) unless action == :index add_breadcrumb breadcrumb_label(@routing_constraint_zone), referential_line_routing_constraint_zone_path(@referential, @line, @routing_constraint_zone), title: breadcrumb_tooltip(@routing_constraint_zone) if %i(show edit).include? action end def journey_pattern_breadcrumb(action) route_breadcrumb :edit add_breadcrumb breadcrumb_label(@journey_pattern), referential_line_route_journey_pattern_path(@referential, @line,@route,@journey_pattern),:title => breadcrumb_tooltip(@journey_pattern) if action == :edit end def vehicle_journey_breadcrumb(action) route_breadcrumb :edit add_breadcrumb I18n.t("breadcrumbs.vehicle_journeys"), referential_line_route_vehicle_journeys_path(@referential, @line,@route) unless action == :index add_breadcrumb breadcrumb_label(@vehicle_journey), referential_line_route_vehicle_journey_path(@referential, @line,@route,@vehicle_journey),:title => breadcrumb_tooltip(@vehicle_journey) if action == :edit end def vehicle_journey_frequency_breadcrumb(action) route_breadcrumb :edit add_breadcrumb I18n.t("breadcrumbs.vehicle_journey_frequencies"), referential_line_route_vehicle_journey_frequencies_path(@referential, @line, @route) unless action == :index add_breadcrumb breadcrumb_label(@vehicle_journey_frequency), referential_line_route_vehicle_journey_frequency_path(@referential, @line,@route, @vehicle_journey_frequency),:title => breadcrumb_tooltip(@vehicle_journey_frequency) if action == :edit end def vehicle_journey_import_breadcrumb (action) route_breadcrumb :edit end def line_referential_breadcrumb(action = :edit) organisation_breadcrumb if @line_referential add_breadcrumb breadcrumb_label(@line_referential), line_referential_path(@line_referential), :title => breadcrumb_tooltip(@line_referential) if action == :edit || action == :show || action == :update end end def company_breadcrumb (action) if @line_referential line_referential_breadcrumb add_breadcrumb Chouette::Company.model_name.human(:count => 2).capitalize, line_referential_companies_path(@line_referential) unless action == :index add_breadcrumb breadcrumb_label(@company), line_referential_company_path(@line_referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit else referential_breadcrumb add_breadcrumb Chouette::Company.model_name.human(:count => 2).capitalize, referential_companies_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@company), referential_company_path(@referential, @company),:title => breadcrumb_tooltip(@company) if action == :edit end end def import_breadcrumb (action) add_breadcrumb I18n.t("breadcrumbs.referentials"), workbenches_path add_breadcrumb breadcrumb_label(@workbench), workbench_path(@workbench), :title => breadcrumb_tooltip(@workbench) add_breadcrumb I18n.t("breadcrumbs.imports"), workbench_imports_path(@workbench) end def export_breadcrumb (action) referential_breadcrumb add_breadcrumb Referential.human_attribute_name("exports"), referential_exports_path(@referential) unless action == :index end def compliance_check_breadcrumb (action) referential_breadcrumb add_breadcrumb Referential.human_attribute_name("compliance_checks"), referential_compliance_checks_path(@referential) unless action == :index add_breadcrumb @compliance_check.name, referential_compliance_check_path(@referential, @compliance_check.id) if @compliance_check add_breadcrumb t("compliance_checks.rule_parameter_set"), rule_parameter_set_referential_compliance_check_path(@referential, @rule_parameter_set.compliance_check.id) if action == :rule_parameter_set end def compliance_check_task_breadcrumb (action) referential_breadcrumb add_breadcrumb Referential.human_attribute_name("compliance_check_tasks"), referential_compliance_check_tasks_path(@referential) unless action == :index add_breadcrumb breadcrumb_label(@compliance_check_task), referential_compliance_check_task_path(@referential, @compliance_check_task),:title => breadcrumb_tooltip(@compliance_check_task) if action == :edit end def compliance_control_sets_breadcrumb (action) add_breadcrumb I18n.t("breadcrumbs.referentials"), workbenches_path #add_breadcrumb breadcrumb_label(@workbench), workbench_path(@workbench), :title => breadcrumb_tooltip(@workbench) end def rule_parameter_breadcrumb (action) organisation_breadcrumb add_breadcrumb Referential.human_attribute_name("rule_parameter_sets"), organisation_path unless action == :index add_breadcrumb breadcrumb_label(@rule_parameter_set), organisation_rule_parameter_set_path(@rule_parameter_set),:title => breadcrumb_tooltip(@rule_parameter_set) if action == :edit end def referential_breadcrumb (action = :edit) organisation_breadcrumb if @referential if workbench = @referential.workbench add_breadcrumb breadcrumb_label(workbench), workbench_path(workbench), :title => breadcrumb_tooltip(workbench) end add_breadcrumb breadcrumb_label(@referential), referential_path(@referential),:title => breadcrumb_tooltip(@referential) if action == :edit || action == :show || action == :update end end def organisation_breadcrumb (action = :index) add_breadcrumb I18n.t("breadcrumbs.referentials"), workbenches_path add_breadcrumb breadcrumb_label(@organisation), organisation_path,:title => breadcrumb_tooltip(@organisation) unless action == :index end def user_breadcrumb (action) organisation_breadcrumb add_breadcrumb I18n.t("breadcrumbs.users"), organisation_path unless action == :index add_breadcrumb breadcrumb_label(@user), organisation_user_path(@user),:title => breadcrumb_tooltip(@user) if action == :edit end def breadcrumb_label(obj) label = breadcrumb_name(obj) if label.blank? label = obj.class.model_name.human+" "+obj.id.to_s end if label.length > 20 label[0..16]+"..." else label end end def breadcrumb_tooltip(obj) label = breadcrumb_name(obj) if label.blank? label = obj.class.model_name.human+" ("+obj.id.to_s+")" else label = obj.class.model_name.human+" : "+label end label end def breadcrumb_name(obj) label = "" if obj.respond_to?('name') label = obj.name elsif obj.respond_to?('comment') label = obj.comment end label end end