aboutsummaryrefslogtreecommitdiffstats
path: root/app/helpers
diff options
context:
space:
mode:
authorLuc Donnet2018-01-03 11:57:42 +0100
committerLuc Donnet2018-01-03 11:57:42 +0100
commit7cce4762c11e7d1e78433f6f88d2e12928c398dc (patch)
tree3084d95692a70f9c5d5a842aae6f4ec0ea07a1c3 /app/helpers
parent6497b23e18385121974f6cbf56d48caf897e69b1 (diff)
parent414d0f6c4dd992696354757c4ae700952a7e4dd9 (diff)
downloadchouette-core-7cce4762c11e7d1e78433f6f88d2e12928c398dc.tar.bz2
Merge branch 'master' into 5024-prevent-duplicate-referentials-from-being-created-during-parallel-db-transactions--rb201711271659
Diffstat (limited to 'app/helpers')
-rw-r--r--app/helpers/application_helper.rb26
-rw-r--r--app/helpers/common_helpers.rb26
-rw-r--r--app/helpers/compliance_control_sets_helper.rb91
-rw-r--r--app/helpers/links_helper.rb15
-rw-r--r--app/helpers/multiple_selection_toolbox_helper.rb11
-rw-r--r--app/helpers/table_builder_helper.rb148
-rw-r--r--app/helpers/table_builder_helper/url.rb2
7 files changed, 212 insertions, 107 deletions
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index d2cdaaa20..713542ff4 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -3,24 +3,38 @@ 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)
local = "#{object.model_name.name.underscore.pluralize}.#{params[:action]}.title"
if object.try(:name)
- t(local, name: object.name)
+ t(local, name: object.name || object.id)
else
t(local)
end
end
def page_header_meta(object)
- info = t('last_update', time: l(object.updated_at, format: :short))
- if object.try(:versions)
- author = object.versions.try(:last).try(:whodunnit) || t('default_whodunnit')
- info = "#{info} <br/> #{t('whodunnit', author: author)}"
+ 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.try(:versions)
+ author = object.versions.try(:last).try(:whodunnit) || t('default_whodunnit')
+ info = "#{info} <br/> #{t('whodunnit', author: author)}"
+ end
+ out += content_tag :div, info.html_safe, class: 'small last-update'
end
- content_tag :div, info.html_safe, class: 'small'
+ out.html_safe
end
def page_header_content_for(object)
diff --git a/app/helpers/common_helpers.rb b/app/helpers/common_helpers.rb
deleted file mode 100644
index 29cabddac..000000000
--- a/app/helpers/common_helpers.rb
+++ /dev/null
@@ -1,26 +0,0 @@
-
-module CommonHelpers
- # TODO: Needs refactoring, but does not seem to be under test
- # so let us refactor this **after** test coverage.
- def access_links_pairs(access_links)
- hpairs = Hash.new
- pairs = Array.new
- access_links.each do |link|
- key = pair_key(link)
- pair = nil
- if (hpairs.has_key? key)
- pair = hpairs[key]
- else
- pair = AccessLinkPair.new
- pairs << pair
- hpairs[key] = pair
- end
- if (link.link_orientation_type == "access_point_to_stop_area")
- pair.from_access_point = link
- else
- pair.to_access_point = link
- end
- end
- pairs
- end
-end
diff --git a/app/helpers/compliance_control_sets_helper.rb b/app/helpers/compliance_control_sets_helper.rb
index bb2a72623..57e6d9608 100644
--- a/app/helpers/compliance_control_sets_helper.rb
+++ b/app/helpers/compliance_control_sets_helper.rb
@@ -4,12 +4,12 @@ module ComplianceControlSetsHelper
[current_organisation, Organisation.find_by_name("STIF")].uniq
end
- def flotted_links ccs_id = @compliance_control_set
+ def floating_links ccs_id
links = [new_control(ccs_id), new_block(ccs_id)]
- unless links.all? &:nil?
- content_tag :div, class: 'select_toolbox' do
+ if links.any?
+ content_tag :div, class: 'select_toolbox', id: 'floating-links' do
content_tag :ul do
- links.collect {|link| concat content_tag(:li, link, class: 'st_action with_text') unless link.nil?}
+ links.collect {|link| concat content_tag(:li, link, class: 'st_action with_text') if link}
end
end
end
@@ -21,8 +21,6 @@ module ComplianceControlSetsHelper
concat content_tag :span, nil, class: 'fa fa-plus'
concat content_tag :span, t('compliance_control_sets.actions.add_compliance_control')
end
- else
- nil
end
end
@@ -32,8 +30,83 @@ module ComplianceControlSetsHelper
concat content_tag :span, nil, class: 'fa fa-plus'
concat content_tag :span,t('compliance_control_sets.actions.add_compliance_control_block')
end
- else
- nil
end
end
-end \ No newline at end of file
+
+ def render_compliance_control_block(block=nil)
+ content_tag :div, class: 'row' do
+ content_tag :div, class: 'col-lg-12' do
+ content_tag :h2 do
+ concat transport_mode_text(block)
+ concat dropdown(block) if block
+ end
+ end
+ end
+ end
+
+ def dropdown(block)
+ dropdown_button = content_tag :div, class: 'btn dropdown-toggle', "data-toggle": "dropdown" do
+ content_tag :div, nil, class: 'span fa fa-cog'
+ end
+
+ dropdown_menu = content_tag :ul, class: 'dropdown-menu' do
+ link_1 = content_tag :li do
+ link_to t('compliance_control_sets.actions.edit'), edit_compliance_control_set_compliance_control_block_path(@compliance_control_set.id, block.id)
+ end
+ link_2 = content_tag :li do
+ link_to t('compliance_control_sets.actions.destroy'), compliance_control_set_compliance_control_block_path(@compliance_control_set.id, block.id), :method => :delete, :data => {:confirm => t('compliance_control_sets.actions.destroy_confirm')}
+ end
+ link_1 + link_2
+ end
+
+ content_tag :div, class: 'btn-group' do
+ dropdown_button + dropdown_menu
+ end
+
+ end
+
+ def render_compliance_controls(compliance_controls)
+ content_tag :div, class: 'row' do
+ content_tag :div, class: 'col-lg-12' do
+ compliance_controls.try(:any?) ? render_table_builder(compliance_controls) : render_no_controls
+ end
+ end
+
+ end
+
+ def render_table_builder(compliance_controls)
+ table = content_tag :div, class: 'select_table' do
+ table_builder_2 compliance_controls,
+ [
+ TableBuilderHelper::Column.new(
+ key: :code,
+ attribute: 'code'
+ ),
+ TableBuilderHelper::Column.new(
+ key: :name,
+ attribute: 'name',
+ link_to: lambda do |compliance_control|
+ compliance_control_set_compliance_control_path(@compliance_control_set, compliance_control)
+ end
+ ),
+ TableBuilderHelper::Column.new(
+ key: :criticity,
+ attribute: 'criticity'
+ ),
+ TableBuilderHelper::Column.new(
+ key: :comment,
+ attribute: 'comment'
+ ),
+ ],
+ sortable: true,
+ cls: 'table has-filter has-search',
+ model: ComplianceControl
+ end
+ metas = content_tag :div, I18n.t('compliance_control_blocks.metas.control', count: compliance_controls.count), class: 'pull-right'
+ table + metas
+ end
+
+ def render_no_controls
+ content_tag :div, I18n.t('compliance_control_blocks.metas.control.zero'), class: 'alert alert-warning'
+ end
+end
diff --git a/app/helpers/links_helper.rb b/app/helpers/links_helper.rb
index 4fb7a797d..088415dc3 100644
--- a/app/helpers/links_helper.rb
+++ b/app/helpers/links_helper.rb
@@ -1,5 +1,18 @@
module LinksHelper
+ def custom_link_content(translation_key, klass, extra_class: nil)
+ klass = ["fa", "fa-#{klass}", "mr-xs", extra_class].compact.join(" ")
+ content_tag(:span, nil, class: klass) + t(translation_key)
+ end
+
def destroy_link_content(translation_key = 'actions.destroy')
- content_tag(:span, nil, class: 'fa fa-trash mr-xs') + t(translation_key)
+ custom_link_content translation_key, 'trash'
+ end
+
+ def deactivate_link_content(translation_key = 'actions.deactivate')
+ custom_link_content translation_key, 'power-off', extra_class: "text-danger"
+ end
+
+ def activate_link_content(translation_key = 'actions.activate')
+ custom_link_content translation_key, 'power-off', extra_class: "text-success"
end
end
diff --git a/app/helpers/multiple_selection_toolbox_helper.rb b/app/helpers/multiple_selection_toolbox_helper.rb
index 85294af6d..e0a1d2dd4 100644
--- a/app/helpers/multiple_selection_toolbox_helper.rb
+++ b/app/helpers/multiple_selection_toolbox_helper.rb
@@ -1,7 +1,11 @@
module MultipleSelectionToolboxHelper
# Box of links that floats at the bottom right of the page
- def multiple_selection_toolbox(actions)
+ # c.f. https://projects.af83.io/issues/5206
+ # #5206 method too long
+ def multiple_selection_toolbox(actions, collection_name:)
links = content_tag :ul do
+
+ # #5206 `if params[:controller]` mieux passer comme parametre si besoin
delete_path = nil
if params[:controller] = 'workbenches'
@@ -15,6 +19,7 @@ module MultipleSelectionToolboxHelper
method: :delete,
data: {
path: delete_path,
+ # #5206 Missing Translations
confirm: 'Etes-vous sûr(e) de vouloir effectuer cette action ?'
},
title: t("actions.#{action}")
@@ -33,7 +38,9 @@ module MultipleSelectionToolboxHelper
class: 'info-msg'
)
- content_tag :div, '', class: 'select_toolbox noselect' do
+ content_tag :div, '',
+ class: 'select_toolbox noselect',
+ id: "selected-#{collection_name}-action-box" do
links + label
end
end
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index 37f01ce0d..dede51920 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -95,6 +95,18 @@ module TableBuilderHelper
class: cls
end
+ def self.item_row_class_name collection
+ if collection.respond_to?(:model)
+ model_name = collection.model.name
+ elsif collection.respond_to?(:first)
+ model_name = collection.first.class.name
+ else
+ model_name = "item"
+ end
+
+ model_name.split("::").last.parameterize
+ end
+
private
def thead(collection, columns, sortable, selectable, has_links, overhead, model )
@@ -187,86 +199,92 @@ module TableBuilderHelper
end
end
- def tbody(collection, columns, selectable, links, overhead)
- content_tag :tbody do
- collection.map do |item|
-
- content_tag :tr do
- bcont = []
-
- if selectable
- bcont << content_tag(
- :td,
- checkbox(id_name: item.try(:id), value: item.try(:id))
- )
- end
-
- columns.each do |column|
- value = column.value(item)
+ def tr item, columns, selectable, links, overhead, model_name
+ klass = "#{model_name}-#{item.id}"
+ content_tag :tr, class: klass do
+ bcont = []
+ if selectable
+ disabled = selectable.respond_to?(:call) && !selectable.call(item)
+ bcont << content_tag(
+ :td,
+ checkbox(id_name: item.try(:id), value: item.try(:id), disabled: disabled)
+ )
+ end
- if column.linkable?
- path = column.link_to(item)
- link = link_to(value, path)
+ columns.each do |column|
+ value = column.value(item)
- if overhead.empty?
- bcont << content_tag(:td, link, title: 'Voir')
+ if column.linkable?
+ path = column.link_to(item)
+ link = link_to(value, path)
- else
- i = columns.index(column)
-
- if overhead[i].blank?
- if (i > 0) && (overhead[i - 1][:width] > 1)
- clsArrayAlt = overhead[i - 1][:cls].split
+ if overhead.empty?
+ bcont << content_tag(:td, link, title: 'Voir')
- bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt))
+ else
+ i = columns.index(column)
- else
- bcont << content_tag(:td, link, title: 'Voir')
- end
+ if overhead[i].blank?
+ if (i > 0) && (overhead[i - 1][:width] > 1)
+ clsArrayAlt = overhead[i - 1][:cls].split
- else
- clsArray = overhead[columns.index(column)][:cls].split
+ bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt))
- bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray))
- end
+ else
+ bcont << content_tag(:td, link, title: 'Voir')
end
else
- if overhead.empty?
- bcont << content_tag(:td, value)
+ clsArray = overhead[columns.index(column)][:cls].split
- else
- i = columns.index(column)
+ bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray))
+ end
+ end
- if overhead[i].blank?
- if (i > 0) && (overhead[i - 1][:width] > 1)
- clsArrayAlt = overhead[i - 1][:cls].split
+ else
+ if overhead.empty?
+ bcont << content_tag(:td, value)
- bcont << content_tag(:td, value, class: td_cls(clsArrayAlt))
+ else
+ i = columns.index(column)
- else
- bcont << content_tag(:td, value)
- end
+ if overhead[i].blank?
+ if (i > 0) && (overhead[i - 1][:width] > 1)
+ clsArrayAlt = overhead[i - 1][:cls].split
- else
- clsArray = overhead[i][:cls].split
+ bcont << content_tag(:td, value, class: td_cls(clsArrayAlt))
- bcont << content_tag(:td, value, class: td_cls(clsArray))
- end
+ else
+ bcont << content_tag(:td, value)
end
+
+ else
+ clsArray = overhead[i][:cls].split
+
+ bcont << content_tag(:td, value, class: td_cls(clsArray))
end
end
+ end
+ end
- if links.any? || item.try(:action_links).try(:any?)
- bcont << content_tag(
- :td,
- build_links(item, links),
- class: 'actions'
- )
- end
+ if links.any? || item.try(:action_links).try(:any?)
+ bcont << content_tag(
+ :td,
+ build_links(item, links),
+ class: 'actions'
+ )
+ end
- bcont.join.html_safe
- end
+ bcont.join.html_safe
+ end
+ end
+
+ def tbody(collection, columns, selectable, links, overhead)
+ model_name = TableBuilderHelper.item_row_class_name collection
+
+ content_tag :tbody do
+ collection.map do |item|
+ tr item, columns, selectable, links, overhead, model_name
end.join.html_safe
end
end
@@ -341,14 +359,20 @@ module TableBuilderHelper
end
end
- def checkbox(id_name:, value:)
+ def checkbox(id_name:, value:, disabled: false)
content_tag :div, '', class: 'checkbox' do
- check_box_tag(id_name, value).concat(
+ check_box_tag(id_name, value, nil, disabled: disabled).concat(
content_tag(:label, '', for: id_name)
)
end
end
+
def gear_menu_link(link)
+ klass = []
+ 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(
@@ -358,7 +382,7 @@ module TableBuilderHelper
) do
link.content
end,
- class: ('delete-action' if link.method == :delete)
+ class: (klass.join(' ') if klass.present?)
)
end
diff --git a/app/helpers/table_builder_helper/url.rb b/app/helpers/table_builder_helper/url.rb
index a53ac5620..28f1ade76 100644
--- a/app/helpers/table_builder_helper/url.rb
+++ b/app/helpers/table_builder_helper/url.rb
@@ -10,7 +10,7 @@ module TableBuilderHelper
polymorph_url << item.route.line if item.is_a?(Chouette::RoutingConstraintZone)
polymorph_url << item if item.respond_to? :line_referential
polymorph_url << item.stop_area if item.respond_to? :stop_area
- polymorph_url << item if item.respond_to?(:stop_points) || item.is_a?(Chouette::TimeTable)
+ polymorph_url << item if item.respond_to?(:stop_points) || item.is_a?(Chouette::TimeTable) || item.is_a?(Chouette::PurchaseWindow)
elsif item.respond_to? :referential
if item.respond_to? :workbench
polymorph_url << item.workbench