aboutsummaryrefslogtreecommitdiffstats
path: root/app
diff options
context:
space:
mode:
authorLuc Donnet2018-03-15 15:35:55 +0100
committerGitHub2018-03-15 15:35:55 +0100
commitd3d3c0f40c37d716cfccbf9297bfbdc98c692521 (patch)
treead64c5c06322894491a2740d14e30bb1b693561e /app
parent499a46cabdf2ee1aab830f27c3aa3e896ded24e3 (diff)
parente93784cba5e7f07d7ff4e20622088d9506816436 (diff)
downloadchouette-core-d3d3c0f40c37d716cfccbf9297bfbdc98c692521.tar.bz2
Merge pull request #372 from af83/6146-line-states
6146 Line state update
Diffstat (limited to 'app')
-rw-r--r--app/assets/stylesheets/components/_tables.sass3
-rw-r--r--app/controllers/lines_controller.rb38
-rw-r--r--app/helpers/referentials_helper.rb6
-rw-r--r--app/helpers/table_builder_helper.rb24
-rw-r--r--app/helpers/table_builder_helper/column.rb9
-rw-r--r--app/views/lines/_filters.html.slim20
-rw-r--r--app/views/lines/index.html.slim5
-rw-r--r--app/views/referentials/show.html.slim2
8 files changed, 80 insertions, 27 deletions
diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass
index ba51f7de7..66ffe9cb1 100644
--- a/app/assets/stylesheets/components/_tables.sass
+++ b/app/assets/stylesheets/components/_tables.sass
@@ -222,6 +222,8 @@
background: url( image-path('map/lda.png') ) no-repeat left 50%
padding-left: 30px
+ tr.line td.state
+ white-space: nowrap
// select_toolbox
.select_toolbox
@@ -307,7 +309,6 @@
font-style: italic
font-size: 0.85em
-
//-----------------------------//
// Tables (column by column) //
//-----------------------------//
diff --git a/app/controllers/lines_controller.rb b/app/controllers/lines_controller.rb
index 27a9bf9be..ae8c9ed0c 100644
--- a/app/controllers/lines_controller.rb
+++ b/app/controllers/lines_controller.rb
@@ -83,18 +83,23 @@ class LinesController < ChouetteController
end
def collection
- %w(network_id company_id group_of_lines_id comment_id transport_mode).each do |filter|
- if params[:q] && params[:q]["#{filter}_eq"] == '-1'
- params[:q]["#{filter}_eq"] = ''
- params[:q]["#{filter}_blank"] = '1'
+ @lines ||= begin
+ %w(network_id company_id group_of_lines_id comment_id transport_mode).each do |filter|
+ if params[:q] && params[:q]["#{filter}_eq"] == '-1'
+ params[:q]["#{filter}_eq"] = ''
+ params[:q]["#{filter}_blank"] = '1'
+ end
end
- end
- @q = line_referential.lines.search(params[:q])
- if sort_column && sort_direction
- @lines ||= @q.result(:distinct => true).order(sort_column + ' ' + sort_direction).paginate(:page => params[:page]).includes([:network, :company])
- else
- @lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company])
+ scope = ransack_status line_referential.lines
+ @q = scope.search(params[:q])
+
+ if sort_column && sort_direction
+ lines ||= @q.result(:distinct => true).order(sort_column + ' ' + sort_direction).paginate(:page => params[:page]).includes([:network, :company])
+ else
+ lines ||= @q.result(:distinct => true).order(:number).paginate(:page => params[:page]).includes([:network, :company])
+ end
+ lines
end
end
@@ -145,4 +150,17 @@ class LinesController < ChouetteController
)
end
+ # Fake ransack filter
+ def ransack_status scope
+ return scope unless params[:q].try(:[], :status)
+ return scope if params[:q][:status].values.uniq.length == 1
+
+ @status = {
+ activated: params[:q][:status]['activated'] == 'true',
+ deactivated: params[:q][:status]['deactivated'] == 'true',
+ }
+
+ scope.where(deactivated: @status[:deactivated])
+end
+
end
diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb
index e464ec8a5..9c3852322 100644
--- a/app/helpers/referentials_helper.rb
+++ b/app/helpers/referentials_helper.rb
@@ -2,12 +2,12 @@ module ReferentialsHelper
# Outputs a green check icon and the text "Oui" or a red exclamation mark
# icon and the text "Non" based on `status`
def line_status(status)
- if status
+ if status
content_tag(:span, nil, class: 'fa fa-exclamation-circle fa-lg text-danger') +
- t('false')
+ t('activerecord.attributes.line.deactivated')
else
content_tag(:span, nil, class: 'fa fa-check-circle fa-lg text-success') +
- t('true')
+ t('activerecord.attributes.line.activated')
end
end
diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb
index d16858678..63125b161 100644
--- a/app/helpers/table_builder_helper.rb
+++ b/app/helpers/table_builder_helper.rb
@@ -208,7 +208,7 @@ module TableBuilderHelper
end
def tr item, columns, selectable, links, overhead, model_name, action
- klass = "#{model_name}-#{item.id}"
+ klass = "#{model_name} #{model_name}-#{item.id}"
content_tag :tr, class: klass do
bcont = []
if selectable
@@ -221,13 +221,14 @@ module TableBuilderHelper
columns.each do |column|
value = column.value(item)
+ extra_class = column.td_class(item)
if column.linkable?
path = column.link_to(item)
link = value.present? && path.present? ? link_to(value, path) : ""
if overhead.empty?
- bcont << content_tag(:td, link, title: 'Voir')
+ bcont << content_tag(:td, link, title: 'Voir', class: extra_class)
else
i = columns.index(column)
@@ -236,22 +237,22 @@ module TableBuilderHelper
if (i > 0) && (overhead[i - 1][:width] > 1)
clsArrayAlt = overhead[i - 1][:cls].split
- bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt))
+ bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArrayAlt, extra_class))
else
- bcont << content_tag(:td, link, title: 'Voir')
+ bcont << content_tag(:td, link, title: 'Voir', class: extra_class)
end
else
clsArray = overhead[columns.index(column)][:cls].split
- bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray))
+ bcont << content_tag(:td, link, title: 'Voir', class: td_cls(clsArray, extra_class))
end
end
else
if overhead.empty?
- bcont << content_tag(:td, value)
+ bcont << content_tag(:td, value, class: extra_class)
else
i = columns.index(column)
@@ -260,10 +261,10 @@ module TableBuilderHelper
if (i > 0) && (overhead[i - 1][:width] > 1)
clsArrayAlt = overhead[i - 1][:cls].split
- bcont << content_tag(:td, value, class: td_cls(clsArrayAlt))
+ bcont << content_tag(:td, value, class: td_cls(clsArrayAlt, extra_class))
else
- bcont << content_tag(:td, value)
+ bcont << content_tag(:td, value, class: extra_class)
end
else
@@ -299,12 +300,15 @@ module TableBuilderHelper
end
end
- def td_cls(a)
+ def td_cls(a, extra_class="")
+ out = [extra_class]
if a.include? 'full-border'
a.slice!(a.index('full-border'))
- return a.join(' ')
+ out += a
end
+ out = out.select(&:present?).join(' ')
+ out.present? ? out : nil
end
def build_links(item, links, action)
diff --git a/app/helpers/table_builder_helper/column.rb b/app/helpers/table_builder_helper/column.rb
index 907707670..f16fc66be 100644
--- a/app/helpers/table_builder_helper/column.rb
+++ b/app/helpers/table_builder_helper/column.rb
@@ -13,6 +13,7 @@ module TableBuilderHelper
@sortable = sortable
@link_to = link_to
@condition = opts[:if]
+ @extra_class = opts[:class]
end
def value(obj)
@@ -52,6 +53,14 @@ module TableBuilderHelper
end
!!condition_val
end
+
+ def td_class(obj)
+ out = []
+ out << @attribute if @attribute.is_a?(String) || @attribute.is_a?(Symbol)
+ out << @extra_class
+ out = out.compact.join ' '
+ out.present? ? out : nil
+ end
end
diff --git a/app/views/lines/_filters.html.slim b/app/views/lines/_filters.html.slim
index 67ba297cf..da0539bd0 100644
--- a/app/views/lines/_filters.html.slim
+++ b/app/views/lines/_filters.html.slim
@@ -23,6 +23,26 @@
= f.label Chouette::Line.human_attribute_name(:transport_submode), required: false, class: 'control-label'
= f.input :transport_submode_eq_any, collection: StifTransportSubmodeEnumerations.sorted_transport_submodes, as: :check_boxes, label: false, label_method: lambda{|l| ("<span>" + t("enumerize.transport_submode.#{l}") + "</span>").html_safe}, required: false, wrapper_html: { class: 'checkbox_list'}
+ .form-group.togglable class=filter_item_class(params[:q], :status)
+ = f.label Chouette::Line.human_attribute_name(:state), required: false, class: 'control-label'
+ .form-group.checkbox_list
+ = f.simple_fields_for :status do |p|
+ = p.input :activated,
+ label: ("<span>#{t('activerecord.attributes.line.activated')}<span class='fa fa-check-circle text-success'></span></span>").html_safe,
+ as: :boolean,
+ wrapper_html: { class: 'checkbox-wrapper' },
+ checked_value: true,
+ unchecked_value: false,
+ input_html: { checked: @status.try(:[], :activated) }
+ = p.input :deactivated,
+ label: ("<span>#{t('activerecord.attributes.line.deactivated')}<span class='fa fa-exclamation-circle text-danger'></span></span>").html_safe,
+ as: :boolean,
+ wrapper_html: { class: 'checkbox-wrapper' },
+ checked_value: true,
+ unchecked_value: false,
+ input_html: { checked: @status.try(:[], :deactivated) }
+
+
.actions
= link_to 'Effacer', @workbench, class: 'btn btn-link'
= f.submit 'Filtrer', class: 'btn btn-default'
diff --git a/app/views/lines/index.html.slim b/app/views/lines/index.html.slim
index 2d64e5f73..9d491ace4 100644
--- a/app/views/lines/index.html.slim
+++ b/app/views/lines/index.html.slim
@@ -29,8 +29,9 @@
end \
), \
TableBuilderHelper::Column.new( \
- key: :deactivated, \
- attribute: Proc.new { |n| line_status(n.deactivated?) } \
+ name: t('activerecord.attributes.line.state'), \
+ class: :state, \
+ attribute: Proc.new { |n| line_status(n.deactivated) } \
), \
TableBuilderHelper::Column.new( \
key: 'networks.name', \
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index 289e802d7..b2a079ab4 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -40,7 +40,7 @@
end \
), \
TableBuilderHelper::Column.new( \
- key: :deactivated, \
+ key: :state, \
attribute: Proc.new { |n| line_status(n.deactivated?) } \
), \
TableBuilderHelper::Column.new( \