diff --git a/app/controllers/dashboard_controller.rb b/app/controllers/dashboard_controller.rb
index 585ea9a..22d55ca 100644
--- a/app/controllers/dashboard_controller.rb
+++ b/app/controllers/dashboard_controller.rb
@@ -1,25 +1,50 @@
-class DashboardController < ApplicationController
- def index
- joint_column = 'joint'
- @available_joints = Joint.distinct.pluck(joint_column)
- @available_data
- @records = filter_records
+require 'yaml'
+class DashboardController < ApplicationController
+ before_action :load_manifest
+
+ def index
+ # Renders the main page
respond_to do |format|
- format.html
- format.json { render json: @records }
+ format.html
+ format.json { render json: @manifest }
end
end
+ # GET /dashboard/options?table=Joint&filter_col=joint_id&value=1
+ def options
+ table = params[:table].constantize
+ if params[:filter_col].present?
+ options = table.where(params[:filter_col] => params[:value]).pluck(params[:pluck_column])
+ else
+ puts table
+ options = table.distinct.pluck(params[:pluck_column])
+ end
+ render json: options
+ end
+
+ # GET /dashboard/data?joint=Acromioclavicular&sub_joint=X
+ def data
+ results = {}
+
+ # Use the data_sources from YAML to aggregate data
+ @manifest['data_sources'].each do |source|
+ table = source['table'].constantize
+ # Find the filter value from the params that matches the filter_column
+ # We assume the filter_column name in DB matches the filter ID in YAML
+ filter_val = params[source['filter_column']] || params['joint'] # Fallback to joint
+
+ record = table.find_by(source['filter_column'] => filter_val)
+ results[source['key']] = record ? record.attributes : {}
+ end
+
+ #debugger
+ render json: results
+ end
+
private
- def filter_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
+ def load_manifest
+ @manifest = YAML.load_file(Rails.root.join('config', 'dashboard_manifest.yml'))
end
end
diff --git a/app/views/dashboard/index.html.erb b/app/views/dashboard/index.html.erb
index d69079b..5c448f6 100644
--- a/app/views/dashboard/index.html.erb
+++ b/app/views/dashboard/index.html.erb
@@ -1,164 +1,392 @@
-
- <%= f.label :joint, "Select Joint:", style: "font-weight: bold;" %>
- <%= f.select :joint, options_for_select(@available_joints, params[:joint]), include_blank: "Select a joint", id: "joint" %>
-
-<% end %>
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/config/dashboard_manifest.yml b/config/dashboard_manifest.yml
new file mode 100644
index 0000000..7d2ea77
--- /dev/null
+++ b/config/dashboard_manifest.yml
@@ -0,0 +1,40 @@
+# Filter Hierarchy: Defines the dropdowns and their dependencies
+filters:
+ - id: "joint"
+ label: "Select Joint"
+ table: "Joint"
+ pluck_column: "Joint"
+ depends_on: null # Root level
+# - id: "joint_info"
+# label: "joint_info"
+# table: "joint_info" # A separate table in SQLite
+# pluck_column: "Common Joint Name"
+# depends_on: "joint" # Only appears after 'joint' is selected
+# filter_column: "Common Joint Name" # Filter SubJoint where joint_id == selected joint value
+
+# Data Mapping: Defines which tables to hit for the final grid
+data_sources:
+ - table: "Joint"
+ key: "main_info" # Nested JSON key
+ filter_column: "joint"
+# - table: "Ligament"
+# key: "lig_info"
+# filter_column: "joint_id"
+
+# Layout: Defines the visual grid
+# colors: dark_blue, light_blue, pale_yellow, pale_green, pale_orange
+layout:
+ - { row: 0, col: 0, colspan: 4, rowspan: 1, text: "Joint Information", class: "bg-dark-blue" }
+ - { row: 1, col: 0, colspan: 1, rowspan: 1, text: "Anatomical Name", class: "bg-light-blue" }
+ - { row: 1, col: 1, colspan: 1, rowspan: 1, value: "main_info.joint", class: "bg-pale-yellow" }
+ - { row: 1, col: 2, colspan: 1, rowspan: 1, text: "Common Name", class: "bg-light-blue" }
+ - { row: 1, col: 3, colspan: 1, rowspan: 1, value: "main_info.common_name", class: "bg-pale-yellow" }
+ - { row: 2, col: 0, colspan: 1, rowspan: 1, text: "Joint Type", class: "bg-light-blue" }
+ - { row: 2, col: 1, colspan: 1, rowspan: 1, value: "main_info.joint_type", class: "bg-pale-yellow" }
+ - { row: 2, col: 2, colspan: 1, rowspan: 1, text: "Planes", class: "bg-light-blue" }
+ - { row: 2, col: 3, colspan: 1, rowspan: 1, value: "main_info.planes", class: "bg-pale-yellow" }
+ - { row: 3, col: 0, colspan: 4, rowspan: 1, value: "main_info.notes", class: "bg-pale-green" }
+
+ # Ligaments Table (separate grid)
+ #- { grid: "ligaments", row: 0, col: 0, colspan: 1, rowspan: 1, text: "Ligaments", class: "bg-dark-blue" }
+ #- { grid: "ligaments", row: 0, col: 1, colspan: 1, rowspan: 1, value: ".list", class: "bg-pale-orange" }
diff --git a/config/routes.rb b/config/routes.rb
index 638ed7c..ba62c0b 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -13,4 +13,6 @@ Rails.application.routes.draw do
# root "posts#index"
root "dashboard#index"
get "dashboard", to: "dashboard#index"
+ get "dashboard/options", to: "dashboard#options"
+ get "dashboard/data", to: "dashboard#data"
end