mirror of
https://github.com/Growstuff/growstuff.git
synced 2026-05-19 06:15:44 -04:00
Optimize Data Improvement Page (#4356)
* feat: Add data improvement page to crops controller This commit introduces a new data improvement page to the crops controller. The page displays tabbed lists of crops with missing data, allowing users to easily identify areas for data quality improvement. The following data quality categories are included: - Crops without photos - Crops without descriptions - Crops without a youtube video - Crops without alternate names - Crops without a scientific name with a wikidata id - Crops without row spacing - Crops without sun requirements - Crops without height All lists are sorted by planting count in descending order. * refactor: Optimize data improvement page to load tab data on demand This commit refactors the data improvement page to load data for each tab on demand, rather than loading all queries at once. This improves the performance of the page by only executing the query for the currently active tab. The controller action now uses a `case` statement based on a `tab` URL parameter to execute the appropriate query. The view has been updated to pass this parameter when a tab is clicked. --------- Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
30e7c5d01c
commit
323c7dc3ee
@@ -149,6 +149,32 @@ class CropsController < ApplicationController
|
||||
respond_with @crop
|
||||
end
|
||||
|
||||
def data_improvement
|
||||
@active_tab = params[:tab] || 'photos'
|
||||
|
||||
@crops = case @active_tab
|
||||
when 'photos'
|
||||
Crop.approved.where(photo_associations_count: 0).order(plantings_count: :desc)
|
||||
when 'descriptions'
|
||||
Crop.approved.where(description: [nil, '']).order(plantings_count: :desc)
|
||||
when 'youtube'
|
||||
Crop.approved.where(en_youtube_url: [nil, '']).order(plantings_count: :desc)
|
||||
when 'alternate_names'
|
||||
Crop.approved.left_joins(:alternate_names).where(alternate_names: { id: nil }).order(plantings_count: :desc)
|
||||
when 'wikidata'
|
||||
crops_with_wikidata = Crop.joins(:scientific_names).where.not(scientific_names: { wikidata_id: nil }).distinct
|
||||
Crop.approved.where.not(id: crops_with_wikidata).order(plantings_count: :desc)
|
||||
when 'row_spacing'
|
||||
Crop.approved.where(row_spacing: nil).order(plantings_count: :desc)
|
||||
when 'sun_requirements'
|
||||
Crop.approved.where(sun_requirements: [nil, '']).order(plantings_count: :desc)
|
||||
when 'height'
|
||||
Crop.approved.where(height: nil).order(plantings_count: :desc)
|
||||
else
|
||||
Crop.none
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def notifier
|
||||
|
||||
10
app/views/crops/_crop_list.html.haml
Normal file
10
app/views/crops/_crop_list.html.haml
Normal file
@@ -0,0 +1,10 @@
|
||||
%table.table.table-striped
|
||||
%thead
|
||||
%tr
|
||||
%th Name
|
||||
%th Plantings
|
||||
%tbody
|
||||
- crops.each do |crop|
|
||||
%tr
|
||||
%td= link_to crop.name, crop
|
||||
%td= crop.plantings_count
|
||||
13
app/views/crops/data_improvement.html.haml
Normal file
13
app/views/crops/data_improvement.html.haml
Normal file
@@ -0,0 +1,13 @@
|
||||
%h1 Data Improvement
|
||||
|
||||
- tabs = { photos: "Photos", descriptions: "Descriptions", youtube: "YouTube videos", alternate_names: "Alternate names", wikidata: "Wikidata ID", row_spacing: "Row spacing", sun_requirements: "Sun requirements", height: "Height" }
|
||||
|
||||
%ul.nav.nav-tabs
|
||||
- tabs.each do |key, value|
|
||||
%li{class: ('active' if @active_tab == key.to_s)}
|
||||
= link_to value, data_improvement_crops_path(tab: key)
|
||||
|
||||
.tab-content
|
||||
.tab-pane.active
|
||||
%h2= "Crops without #{tabs[@active_tab.to_sym]}"
|
||||
= render 'crop_list', crops: @crops
|
||||
@@ -3,6 +3,7 @@
|
||||
- content_for :buttonbar do
|
||||
- if can? :wrangle, Crop
|
||||
= link_to 'Wrangle Crops', wrangle_crops_path, class: 'btn btn-secondary'
|
||||
= link_to 'Data Improvement', data_improvement_crops_path, class: 'btn btn-info'
|
||||
- if can? :create, Crop
|
||||
= link_to 'Add New Crop', new_crop_path, class: 'btn btn-primary'
|
||||
|
||||
|
||||
@@ -89,6 +89,7 @@ Rails.application.routes.draw do
|
||||
get 'wrangle'
|
||||
get 'hierarchy'
|
||||
get 'search'
|
||||
get 'data_improvement'
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user