updated interface
This commit is contained in:
@@ -1,27 +1,25 @@
|
||||
class DashboardController < ApplicationController
|
||||
def index
|
||||
joint_column = 'joint'
|
||||
# Grab distinct values for dropdown filters
|
||||
@available_joints = Joint.distinct.pluck(joint_column)
|
||||
|
||||
# Fetch initial records
|
||||
@available_data
|
||||
@records = filter_records
|
||||
|
||||
respond_to do |format|
|
||||
format.html # Renders app/views/dashboards/index.html.erb
|
||||
format.json { render json: @records } # Returns filtered data as JSON for JS
|
||||
format.html
|
||||
format.json { render json: @records }
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def filter_records
|
||||
if params.include?(:joint)
|
||||
records = Joint.all
|
||||
records = records.where(joint: params[:joint])
|
||||
records
|
||||
# Using .where(joint: params[:joint]) handles both present and nil values gracefully
|
||||
if params[:joint].present?
|
||||
Joint.where(joint: params[:joint])
|
||||
else
|
||||
[]
|
||||
# Return empty array if no joint selected to avoid loading thousands of records
|
||||
[]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user