Skip to content

Commit

Permalink
refactor unchecked visible columns
Browse files Browse the repository at this point in the history
  • Loading branch information
tsubik committed Apr 20, 2023
1 parent 636765e commit 130d8f8
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 19 deletions.
14 changes: 5 additions & 9 deletions app/admin/observations_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -131,10 +131,10 @@
panel "Visible columns" do
render partial: "fields", locals: {
attributes: [
["date", I18n.t("activerecord.attributes.operator_document_statistic.date")],
["country", I18n.t("activerecord.attributes.operator_document_statistic.country.one")],
["is_active", I18n.t("activerecord.attributes.observation.is_active")],
["hidden", I18n.t("activerecord.attributes.observation.hidden")],
["date", I18n.t("activerecord.attributes.operator_document_statistic.date"), :checked],
["country", I18n.t("activerecord.attributes.operator_document_statistic.country.one"), :checked],
["is_active", I18n.t("activerecord.attributes.observation.is_active"), :checked],
["hidden", I18n.t("activerecord.attributes.observation.hidden"), :checked],
["observation_type", I18n.t("activerecord.attributes.observation.observation_type")],
["operator", I18n.t("activerecord.models.operator")],
["severity_level", I18n.t("activerecord.attributes.severity.level")],
Expand All @@ -151,12 +151,8 @@
["published_no_comments", I18n.t("activerecord.enums.observation.statuses.Published (no comments)")],
["published_modified", I18n.t("activerecord.enums.observation.statuses.Published (modified)")],
["published_not_modified", I18n.t("activerecord.enums.observation.statuses.Published (not modified)")],
["published_all", I18n.t("active_admin.observations_dashboard_page.published_all")],
["published_all", I18n.t("active_admin.observations_dashboard_page.published_all"), :checked],
["total_count", I18n.t("active_admin.observation_reports_dashboard_page.total_count")]
],
unchecked: %w[
operator severity_level observation_type category subcategory fmu_forest_type ready_for_qc approved rejected needs_revision ready_for_publication
published_no_comments published_modified published_not_modified total_count created qc_in_progress
]
}
end
Expand Down
13 changes: 6 additions & 7 deletions app/admin/operator_documents_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -89,20 +89,19 @@
panel I18n.t("active_admin.producer_documents_dashboard_page.visible_columns") do
render partial: "fields", locals: {
attributes: [
["date", I18n.t("activerecord.attributes.operator_document_statistic.date")],
["country", I18n.t("activerecord.attributes.operator_document_statistic.country.one")],
["date", I18n.t("activerecord.attributes.operator_document_statistic.date"), :checked],
["country", I18n.t("activerecord.attributes.operator_document_statistic.country.one"), :checked],
["required_operator_document_group", I18n.t("activerecord.models.required_operator_document_group.one")],
["fmu_forest_type", I18n.t("activerecord.attributes.fmu.forest_type")],
["document_type", I18n.t("activerecord.attributes.required_gov_document.document_type")],
["valid_expired", I18n.t("active_admin.producer_documents_dashboard_page.valid_expired")],
["valid", I18n.t("active_admin.producer_documents_dashboard_page.valid")],
["expired", I18n.t("active_admin.producer_documents_dashboard_page.expired")],
["valid_expired", I18n.t("active_admin.producer_documents_dashboard_page.valid_expired"), :checked],
["valid", I18n.t("active_admin.producer_documents_dashboard_page.valid"), :checked],
["expired", I18n.t("active_admin.producer_documents_dashboard_page.expired"), :checked],
["invalid", I18n.t("active_admin.producer_documents_dashboard_page.invalid")],
["pending", I18n.t("active_admin.producer_documents_dashboard_page.pending")],
["not_provided", I18n.t("active_admin.producer_documents_dashboard_page.not_provided")],
["not_required", I18n.t("active_admin.producer_documents_dashboard_page.not_required")]
],
unchecked: %w[required_operator_document_group fmu_forest_type document_type invalid pending not_provided not_required]
]
}
end
end
Expand Down
5 changes: 2 additions & 3 deletions app/views/active_admin/resource/_fields.html.erb
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
<% save_to_localstorage ||= true %>
<div class="observation-attributes" data-save-to-localstorage="<%= save_to_localstorage %>">
<% unchecked ||= [] %>
<% attributes.each do |column, name| %>
<% attributes.each do |column, name, checked| %>
<%
column_id = column.gsub('_&_', '_')
name = column if name.blank?
%>
<div class="observations-checkbox" id="attribute-<%= column_id %>">
<label>
<input type="checkbox" class="observation-checkbox" id="<%= column_id %>" <%= unchecked.exclude?(column) ? 'checked' : '' %>>
<input type="checkbox" class="observation-checkbox" id="<%= column_id %>" <%= checked == :checked ? 'checked' : '' %>>
<%=name %>
</label>
</div>
Expand Down

0 comments on commit 130d8f8

Please sign in to comment.