aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZog2018-04-19 16:38:15 +0200
committerJohan Van Ryseghem2018-04-27 11:17:19 +0200
commite8e029da36b493827820289f8db50645eb939806 (patch)
tree0e6fa62311641733673f4a53fa3e00c362b90b45
parentc5f45f2a57b225503506c89df6b2a53a84028223 (diff)
downloadchouette-core-e8e029da36b493827820289f8db50645eb939806.tar.bz2
Refs #6572; Update filters on referentials list
-rw-r--r--app/assets/stylesheets/components/_tables.sass4
-rw-r--r--app/controllers/workbenches_controller.rb47
-rw-r--r--app/helpers/referentials_helper.rb13
-rw-r--r--app/helpers/search_helper.rb2
-rw-r--r--app/models/referential.rb4
-rw-r--r--app/models/workbench.rb1
-rw-r--r--app/views/workbenches/_filters.html.slim6
-rw-r--r--app/views/workbenches/show.html.slim2
-rw-r--r--config/locales/referentials.fr.yml2
9 files changed, 60 insertions, 21 deletions
diff --git a/app/assets/stylesheets/components/_tables.sass b/app/assets/stylesheets/components/_tables.sass
index 66ffe9cb1..4952acf92 100644
--- a/app/assets/stylesheets/components/_tables.sass
+++ b/app/assets/stylesheets/components/_tables.sass
@@ -68,10 +68,10 @@
font-weight: 700
color: inherit
- > .fa
+ > .fa, > .sb
&:first-child
margin-right: 3px
-
+
> tr:hover
cursor: default
> td
diff --git a/app/controllers/workbenches_controller.rb b/app/controllers/workbenches_controller.rb
index 35438eaaf..43415ff60 100644
--- a/app/controllers/workbenches_controller.rb
+++ b/app/controllers/workbenches_controller.rb
@@ -5,7 +5,7 @@ class WorkbenchesController < ChouetteController
defaults resource_class: Workbench
include PolicyChecker
-
+
respond_to :html, except: :destroy
def index
@@ -50,7 +50,7 @@ class WorkbenchesController < ChouetteController
end
def sort_result collection
- col = (Workbench.find(params[:id]).referentials.column_names + %w{lines validity_period}).include?(params[:sort]) ? params[:sort] : 'name'
+ col = (Referential.column_names + %w{lines validity_period}).include?(params[:sort]) ? params[:sort] : 'name'
dir = %w[asc desc].include?(params[:direction]) ? params[:direction] : 'asc'
if ['lines', 'validity_period'].include?(col)
@@ -75,16 +75,41 @@ class WorkbenchesController < ChouetteController
# Fake ransack filter
def ransack_status scope
- archived = !params[:q]['archived_at_not_null'].to_i.zero?
- unarchived = !params[:q]['archived_at_null'].to_i.zero?
-
- # Both status checked, means no filter
- return scope unless archived || unarchived
- return scope if archived && unarchived
+ sql = scope.to_sql
+ filters = []
+ (params[:q] && params[:q][:state] || {}).each do |k, v|
+ if v == "1"
+
+ # We get the specific part of the SQL QUERY
+ # It looks a bit weird, bu this way we don't have to duplicate the
+ # logic of the scopes
+ filter_sql = scope.send(k).to_sql
+ j = 0
+ while filter_sql[j] == sql[j]
+ j += 1
+ end
+ i = j
+ while filter_sql[j] != sql[i]
+ j += 1
+ end
+
+ filter_sql = filter_sql[i..j]
+ filter_sql = filter_sql.strip
+ filter_sql = filter_sql.gsub /^AND\s*/i, ''
+ filters << filter_sql
+ end
+ end
- scope = scope.where(archived_at: nil) if unarchived
- scope = scope.where("archived_at is not null") if archived
- scope
+ # archived = !params[:q]['archived_at_not_null'].to_i.zero?
+ # unarchived = !params[:q]['archived_at_null'].to_i.zero?
+ #
+ # # Both status checked, means no filter
+ # return scope unless archived || unarchived
+ # return scope if archived && unarchived
+ #
+ # scope = scope.where(archived_at: nil) if unarchived
+ # scope = scope.where("archived_at is not null") if archived
+ scope.where filters.map{|f| "(#{f})"}.join('OR')
end
# Ignore archived_at_not_null/archived_at_null managed by ransack_status scope
diff --git a/app/helpers/referentials_helper.rb b/app/helpers/referentials_helper.rb
index ef8831cdc..c0a60410a 100644
--- a/app/helpers/referentials_helper.rb
+++ b/app/helpers/referentials_helper.rb
@@ -12,6 +12,19 @@ module ReferentialsHelper
end
end
+ def icon_for_referential_state state
+ case state.to_s
+ when "pending"
+ "<span class='fa fa-clock-o'></span>"
+ when "failed"
+ "<span class='fa fa-times'></span>"
+ when "archived"
+ "<span class='fa fa-archive'></span>"
+ else
+ "<span class='sb sb-lg sb-preparing'></span>"
+ end.html_safe
+ end
+
def referential_state referential
out = if referential.archived?
"<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>"
diff --git a/app/helpers/search_helper.rb b/app/helpers/search_helper.rb
index 16081b660..7d4885312 100644
--- a/app/helpers/search_helper.rb
+++ b/app/helpers/search_helper.rb
@@ -15,7 +15,7 @@ module SearchHelper
if val.is_a?(Array)
active = val.any? &:present?
elsif val.is_a?(Hash)
- active = val.values.any? {|v| v.present? && v != "false" }
+ active = val.values.any? {|v| v.present? && v != "false" && v != "0" }
else
active = true
end
diff --git a/app/models/referential.rb b/app/models/referential.rb
index 2449d767d..9ceb1769e 100644
--- a/app/models/referential.rb
+++ b/app/models/referential.rb
@@ -3,6 +3,8 @@ class Referential < ApplicationModel
include DataFormatEnumerations
include ObjectidFormatterSupport
+ STATES = %i(pending active failed archived)
+
validates_presence_of :name
validates_presence_of :slug
validates_presence_of :prefix
@@ -571,7 +573,7 @@ class Referential < ApplicationModel
update failed_at: nil, archived_at: Time.now
end
- %i(pending active failed archived).each do |s|
+ STATES.each do |s|
define_method "#{s}?" do
state == s
end
diff --git a/app/models/workbench.rb b/app/models/workbench.rb
index ef0b2eaa4..1c54e8904 100644
--- a/app/models/workbench.rb
+++ b/app/models/workbench.rb
@@ -38,7 +38,6 @@ class Workbench < ApplicationModel
.referentials
.joins(:metadatas)
.where(['referential_metadata.line_ids && ARRAY[?]::bigint[]', line_ids])
- .ready
.not_in_referential_suite
end
end
diff --git a/app/views/workbenches/_filters.html.slim b/app/views/workbenches/_filters.html.slim
index c9dd13d96..ffac2d736 100644
--- a/app/views/workbenches/_filters.html.slim
+++ b/app/views/workbenches/_filters.html.slim
@@ -11,11 +11,11 @@
= f.label t('activerecord.models.line.one').upcase, required: false, class: 'control-label'
= f.input :associated_lines_id_eq, as: :select, collection: @workbench.lines.includes(:company).order(:name), input_html: { 'data-select2ed': 'true', 'data-select2ed-placeholder': t('referentials.filters.line') }, label: false, label_method: :display_name, wrapper_html: { class: 'select2ed'}
- .form-group.togglable class=filter_item_class(params[:q], :archived_at_not_null)
+ .form-group.togglable class=filter_item_class(params[:q], :state)
= f.label Referential.human_attribute_name(:status), required: false, class: 'control-label'
.form-group.checkbox_list
- = f.input :archived_at_not_null, label: ("<span>#{t('activerecord.attributes.referential.archived_at')}<span class='fa fa-archive'></span></span>").html_safe, as: :boolean, wrapper_html: { class: 'checkbox-wrapper' }
- = f.input :archived_at_null, label: ("<span>#{t('activerecord.attributes.referential.archived_at_null')}<span class='sb sb-lg sb-preparing'></span></span>").html_safe, as: :boolean, wrapper_html: { class: 'checkbox-wrapper' }
+ - Referential::STATES.each do |s|
+ = f.input "state[#{s}]", input_html: {checked: (params[:q] && params[:q][:state] && params[:q][:state][s]) == "1"}, label: ("<span>#{"referentials.states.#{s}".t}#{icon_for_referential_state(s)}</span>").html_safe, as: :boolean, wrapper_html: { class: 'checkbox-wrapper' }
.form-group.togglable class=filter_item_class(params[:q], :organisation_name_eq_any)
= f.label t('activerecord.models.organisation.one'), required: false, class: 'control-label'
diff --git a/app/views/workbenches/show.html.slim b/app/views/workbenches/show.html.slim
index 7dd1583fa..b0276c5ce 100644
--- a/app/views/workbenches/show.html.slim
+++ b/app/views/workbenches/show.html.slim
@@ -34,7 +34,7 @@
TableBuilderHelper::Column.new( \
key: :archived_at, \
name: Referential.tmf('status'), \
- attribute: Proc.new {|w| w.referential_read_only? ? ("<div class='td-block'><span class='fa fa-archive'></span><span>#{t('activerecord.attributes.referential.archived_at')}</span></div>").html_safe : ("<div class='td-block'><span class='sb sb-lg sb-preparing'></span><span>#{t('activerecord.attributes.referential.archived_at_null')}</span></div>").html_safe} \
+ attribute: Proc.new {|w| "<a href='' title='#{"referentials.states.#{w.state}".t}'>#{icon_for_referential_state(w.state)}</a>".html_safe} \
), \
TableBuilderHelper::Column.new( \
key: :organisation, \
diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml
index e22789873..e932494ce 100644
--- a/config/locales/referentials.fr.yml
+++ b/config/locales/referentials.fr.yml
@@ -107,7 +107,7 @@ fr:
updated_at: "Edité le"
created_at: "Créé le"
merged_at: "Finalisé le"
- archived_at: "Conservé"
+ archived_at: "Archivé"
archived_at_null: "En préparation"
created_from: 'Créé à partir de'
organisation: 'Organisation'