Skip to content

Commit

Permalink
properly translate chart legend labels, small refactoring of i18n for…
Browse files Browse the repository at this point in the history
… dashboard models
  • Loading branch information
tsubik committed May 10, 2023
1 parent c229eef commit acbefa9
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 71 deletions.
54 changes: 31 additions & 23 deletions app/admin/observations_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -112,19 +112,27 @@
chart_collection_by_date = chart_collection.group_by(&:date)
hidden = {dataset: {hidden: true}}
get_data = ->(&block) { chart_collection_by_date.map { |date, data| {date.to_date => data.map(&block).max} }.reduce(&:merge) }
get_score = ->(score_key, options = {}) {
{
name: ObservationStatistic.human_attribute_name(score_key),
data: get_data.call(&score_key),
**{dataset: {id: score_key.to_s}}.deep_merge(options)
}
}

render partial: "score_evolution", locals: {
scores: [
{name: "Created", **hidden, data: get_data.call(&:created)},
{name: "Ready for QC", **hidden, data: get_data.call(&:ready_for_qc)},
{name: "QC in Progress", **hidden, data: get_data.call(&:qc_in_progress)},
{name: "Approved", **hidden, data: get_data.call(&:approved)},
{name: "Rejected", **hidden, data: get_data.call(&:rejected)},
{name: "Needs Revision", **hidden, data: get_data.call(&:needs_revision)},
{name: "Ready for publication", **hidden, data: get_data.call(&:ready_for_publication)},
{name: "Published no comments", **hidden, data: get_data.call(&:published_no_comments)},
{name: "Published not modified", **hidden, data: get_data.call(&:published_not_modified)},
{name: "Published modified", **hidden, data: get_data.call(&:published_modified)},
{name: "Published all", **hidden, data: get_data.call(&:published_all)}
get_score.call(:created, hidden),
get_score.call(:ready_for_qc, hidden),
get_score.call(:qc_in_progress, hidden),
get_score.call(:approved, hidden),
get_score.call(:rejected, hidden),
get_score.call(:needs_revision, hidden),
get_score.call(:ready_for_publication, hidden),
get_score.call(:published_no_comments, hidden),
get_score.call(:published_not_modified, hidden),
get_score.call(:published_modified, hidden),
get_score.call(:published_all, hidden)
]
}

Expand All @@ -142,18 +150,18 @@
["subcategory", I18n.t("activerecord.models.subcategory")],
["is_active", I18n.t("activerecord.attributes.observation.is_active"), :checked],
["hidden", I18n.t("activerecord.attributes.observation.hidden"), :checked],
["created", I18n.t("shared.created")],
["ready_for_qc", I18n.t("activerecord.enums.observation.statuses.Ready for QC")],
["qc_in_progress", I18n.t("activerecord.enums.observation.statuses.QC in progress")],
["approved", I18n.t("activerecord.enums.observation.statuses.Approved")],
["rejected", I18n.t("activerecord.enums.observation.statuses.Rejected")],
["needs_revision", I18n.t("activerecord.enums.observation.statuses.Needs revision")],
["ready_for_publication", I18n.t("activerecord.enums.observation.statuses.Ready for publication")],
["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"), :checked],
["total_count", I18n.t("active_admin.observation_reports_dashboard_page.total_count")]
["created", ObservationStatistic.human_attribute_name(:created)],
["ready_for_qc", ObservationStatistic.human_attribute_name(:ready_for_qc)],
["qc_in_progress", ObservationStatistic.human_attribute_name(:qc_in_progress)],
["approved", ObservationStatistic.human_attribute_name(:approved)],
["rejected", ObservationStatistic.human_attribute_name(:rejected)],
["needs_revision",ObservationStatistic.human_attribute_name(:needs_revision)],
["ready_for_publication", ObservationStatistic.human_attribute_name(:ready_for_publication)],
["published_no_comments", ObservationStatistic.human_attribute_name(:published_no_comments)],
["published_modified", ObservationStatistic.human_attribute_name(:published_modified)],
["published_not_modified", ObservationStatistic.human_attribute_name(:published_not_modified)],
["published_all", ObservationStatistic.human_attribute_name(:published_all), :checked],
["total_count", ObservationStatistic.human_attribute_name(:total_count)]
]
}
end
Expand Down
63 changes: 35 additions & 28 deletions app/admin/operator_documents_dashboard.rb
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,13 @@
r.document_type.humanize
end
end
column I18n.t("active_admin.producer_documents_dashboard_page.valid_expired"), class: "col-valid_expired", sortable: false, &:valid_and_expired_count
column I18n.t("active_admin.producer_documents_dashboard_page.valid"), class: "col-valid", sortable: false, &:valid_count
column I18n.t("active_admin.producer_documents_dashboard_page.expired"), class: "col-expired", sortable: false, &:expired_count
column I18n.t("active_admin.producer_documents_dashboard_page.pending"), class: "col-pending", sortable: false, &:pending_count
column I18n.t("active_admin.producer_documents_dashboard_page.invalid"), class: "col-invalid", sortable: false, &:invalid_count
column I18n.t("active_admin.producer_documents_dashboard_page.not_required"), class: "col-not_required", sortable: false, &:not_required_count
column I18n.t("active_admin.producer_documents_dashboard_page.not_provided"), class: "col-not_provided", sortable: false, &:not_provided_count
column :valid_and_expired_count, sortable: false
column :valid_count, sortable: false
column :expired_count, sortable: false
column :pending_count, sortable: false
column :invalid_count, sortable: false
column :not_required_count, sortable: false
column :not_provided_count, sortable: false

chart_collection = if params.dig(:q, :by_country).present?
collection
Expand All @@ -74,15 +74,22 @@
chart_collection_by_date = chart_collection.group_by(&:date)
hidden = {dataset: {hidden: true}}
get_data = ->(&block) { chart_collection_by_date.map { |date, data| {date.to_date => data.map(&block).max} }.reduce(&:merge) }
get_score = ->(score_key, options = {}) {
{
name: OperatorDocumentStatistic.human_attribute_name(score_key),
data: get_data.call(&score_key),
**{dataset: {id: score_key.to_s}}.deep_merge(options)
}
}
render partial: "score_evolution", locals: {
scores: [
{name: "Not Provided", **hidden, data: get_data.call(&:not_provided_count)},
{name: "Pending", **hidden, data: get_data.call(&:pending_count)},
{name: "Invalid", **hidden, data: get_data.call(&:invalid_count)},
{name: "Valid & Expired", data: get_data.call(&:valid_and_expired_count)},
{name: "Valid", data: get_data.call(&:valid_count)},
{name: "Expired", data: get_data.call(&:expired_count)},
{name: "Not Required", **hidden, data: get_data.call(&:not_required_count)}
get_score.call(:not_provided_count, hidden),
get_score.call(:pending_count, hidden),
get_score.call(:invalid_count, hidden),
get_score.call(:valid_and_expired_count),
get_score.call(:valid_count),
get_score.call(:expired_count, hidden),
get_score.call(:not_required_count, hidden)
]
}

Expand All @@ -95,13 +102,13 @@
["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"), :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")]
["valid_and_expired_count", OperatorDocumentStatistic.human_attribute_name(:valid_and_expired_count), :checked],
["valid_count", OperatorDocumentStatistic.human_attribute_name(:valid_count), :checked],
["expired_count", OperatorDocumentStatistic.human_attribute_name(:expired_count), :checked],
["invalid_count", OperatorDocumentStatistic.human_attribute_name(:invalid_count)],
["pending_count", OperatorDocumentStatistic.human_attribute_name(:pending_count)],
["not_provided_count", OperatorDocumentStatistic.human_attribute_name(:not_provided_count)],
["not_required_count", OperatorDocumentStatistic.human_attribute_name(:not_required_count)]
]
}
end
Expand Down Expand Up @@ -133,13 +140,13 @@
r.document_type.humanize
end
end
column I18n.t("active_admin.producer_documents_dashboard_page.valid_expired"), &:valid_and_expired_count
column I18n.t("active_admin.producer_documents_dashboard_page.valid"), &:valid_count
column I18n.t("active_admin.producer_documents_dashboard_page.expired"), &:expired_count
column I18n.t("active_admin.producer_documents_dashboard_page.pending"), &:pending_count
column I18n.t("active_admin.producer_documents_dashboard_page.invalid"), &:invalid_count
column I18n.t("active_admin.producer_documents_dashboard_page.not_required"), &:not_required_count
column I18n.t("active_admin.producer_documents_dashboard_page.not_provided"), &:not_provided_count
column :valid_and_expired_count
column :valid_count
column :expired_count
column :pending_count
column :invalid_count
column :not_required_count
column :not_provided_count
end

controller do
Expand Down
12 changes: 6 additions & 6 deletions app/assets/javascripts/visibility.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,11 @@ $(document).ready(function() {
if (!Chartkick || !Chartkick.charts['chart-1']) return;

const chart = Chartkick.charts['chart-1'].chart;
const dataset = chart.data.datasets.find(x => x.id === elemId);

const lookupId = elemId.replaceAll('_', '');
const legendItem = chart.legend.legendItems.find(
x => x.text.replaceAll('&', '').replace(/\s/g, '').toLowerCase() === lookupId
);
if (legendItem) {
if (dataset) {
const datasetIndex = chart.data.datasets.indexOf(dataset);
const legendItem = chart.legend.legendItems.find(x => x.datasetIndex === datasetIndex);
legendItem.hidden = !checked;

if (checked) {
Expand All @@ -38,7 +37,8 @@ $(document).ready(function() {
const oldOnClick = chart.legend.options.onClick;

const newLegendClickHandler = function (e, legendItem, legend) {
const id = legendItem.text.replaceAll(' & ', ' ').replaceAll(' ', '_').toLowerCase();
const dataset = chart.data.datasets[legendItem.datasetIndex];
const id = dataset.id;
const column = $(`.col-${id}`);

$('#' + id).prop('checked', legendItem.hidden);
Expand Down
14 changes: 7 additions & 7 deletions config/locales/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -295,13 +295,6 @@ en:
all_groups: 'All Groups'
all_forest_types: 'All Forest Types'
fmu_country: 'Fmu/Country'
valid_expired: 'Valid & Expired'
not_provided: 'Not Provided'
pending: 'Pending'
invalid: 'Invalid'
valid: 'Valid'
expired: 'Expired'
not_required: 'Not Required'
observation_reports_dashboard_page:
name: 'Observation Reports Dashboard'
reports: 'Reports'
Expand Down Expand Up @@ -1183,6 +1176,13 @@ en:
document_type: Document type #g
fmu_forest_type: Fmu forest type #g
required_operator_document_group: :activerecord.models.required_operator_document_group #g
valid_and_expired_count: Valid & Expired
not_provided_count: Not Provided
pending_count: Pending
invalid_count: Invalid
valid_count: Valid
expired_count: Expired
not_required_count: Not Required

paper_trail/version:
event: Event #g
Expand Down
14 changes: 7 additions & 7 deletions config/locales/fr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -304,13 +304,6 @@ fr:
all_groups: 'Tous les groupes'
all_forest_types: 'Tous types de forêts'
fmu_country: 'Fmu/Pays'
valid_expired: 'Valide & Expiré'
not_provided: 'Non fourni'
pending: 'En attente'
invalid: 'Invalide'
valid: 'Valide'
expired: 'Expiré'
not_required: 'Not Requis'
observation_reports_dashboard_page:
name: "Tableau de bord du rapport d'observation"
reports: 'Rapports'
Expand Down Expand Up @@ -1091,6 +1084,13 @@ fr:
document_type: Type de document #g
fmu_forest_type: Type de forêt Fmu #g
required_operator_document_group: :activerecord.models.required_operator_document_group #g
valid_and_expired_count: 'Valide & Expiré'
not_provided_count: 'Non fourni'
pending_count: 'En attente'
invalid_count: 'Invalide'
valid_count: 'Valide'
expired_count: 'Expiré'
not_required_count: 'Not Requis'

paper_trail/version:
event: Événement #g
Expand Down

0 comments on commit acbefa9

Please sign in to comment.