aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers/application_helper.rb
blob: 702ca0ffc5ac74ed951ceb886dc100f5e673178d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
module ApplicationHelper

  include NewapplicationHelper

  def array_to_html_list items
    content_tag :ul do
      items.each do |item|
        concat content_tag :li, item
      end
    end
  end

  def page_header_title(object)
    # Unwrap from decorator, we want to know the object model name
    object = object.object if object.try(:object)

    if Referential === object
      return object.full_name
    end

    local = "#{object.model_name.name.underscore.pluralize}.#{params[:action]}.title"

    arg = object.organisation.name if Workbench === object

    if object.try(:name)
      t(local, name: arg || object.name || object.id)
    else
      t(local)
    end
  end

  def page_header_meta(object)
    out = ""
    display = true
    display = policy(object).synchronize? if policy(object).respond_to?(:synchronize?) rescue false
    if display
      info = t('last_update', time: l(object.updated_at, format: :short))
      if object.has_metadata?
        author = object.metadata.modifier_username || t('default_whodunnit')
        info   = "#{info} <br/> #{t('whodunnit', author: author)}"
      end
      out += content_tag :div, info.html_safe, class: 'small last-update'
    end
    out.html_safe
  end

  def page_header_content_for(object)
    content_for :page_header_title, page_header_title(object)
    content_for :page_header_meta, page_header_meta(object)
  end

  def font_awesome_classic_tag(name)
    name = "fa-file-text-o" if name == "fa-file-csv-o"
    name = "fa-file-code-o" if name == "fa-file-xml-o"
    content_tag(:i, nil, {class: "fa #{name}"})
  end

  def stop_area_picture_url(stop_area)
    image_path("map/#{(stop_area.area_type || 'zdep').underscore}.png")
  end

  def selected_referential?
    @referential.present? and not @referential.new_record?
  end

  def format_restriction_for_locales(referential)
    if !referential.respond_to?(:data_format) or referential.data_format.blank?
      ""
    else
      "."+referential.data_format
    end
  end

  def polymorphic_path_patch( source)
    relative_url_root = Rails.application.config.relative_url_root
    relative_url_root && !source.starts_with?("#{relative_url_root}/") ? "#{relative_url_root}#{source}" : source
  end

  def assets_path_patch( source)
    relative_url_root = Rails.application.config.relative_url_root
    return "/assets/#{source}" unless relative_url_root
    "#{relative_url_root}/assets/#{source}"
  end


  def help_page?
    controller_name == "help"
  end

  def help_path
    path = request.env['PATH_INFO']
    target = case
    when path.include?("/help")
      ""
    when path.include?("/networks")
      "networks"
    when path.include?("/companies")
      "companies"
    when path.include?("/group_of_lines")
      "group_of_lines"
    when path.include?("/vehicle_journeys")
      "vehicle_journeys"
    when path.include?("/vehicle_journey_frequencies")
      "vehicle_journeys"
    when path.include?("/journey_patterns")
      "journey_patterns"
    when path.include?("/routes")
      "routes"
    when path.include?("/lines")
      "lines"
    when path.include?("/access_points")
      "access_points_links"
    when path.include?("/access_links")
      "access_points_links"
    when path.include?("/stop_areas")
      "stop_areas"
    when path.include?("/connection_links")
      "connection_links"
    when path.include?("/time_tables")
      "time_tables"
    when path.include?("/timebands")
      "timebands"
    when path.include?("/import_tasks")
      "imports"
    when path.include?("/exports")
      "exports"
    when path.include?("/compliance_check_tasks")
      "validations"
    when path.include?("/referentials")
      "dataspaces"
    else
      ""
    end

    url_for(:controller => "/help", :action => "show") + '/' + target
  end

  def permitted_custom_fields_params custom_fields
    [{
      custom_field_values: custom_fields.map(&:code)
    }]
  end
end