Super basic version

This commit is contained in:
2026-07-27 20:06:15 -06:00
parent 1932ad4f72
commit 7532b938ed
7 changed files with 133 additions and 2 deletions
+29
View File
@@ -1,2 +1,31 @@
class DashboardController < ApplicationController class DashboardController < ApplicationController
def index
joint_column = 'joint'
# Grab distinct values for dropdown filters
@available_joints = Joint.distinct.pluck(joint_column)
# Fetch initial records
@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
end
end
private
def filter_records
records = Joint.all
records = records.where(joint: params[:joint]) if params[:joint].present?
records
end
# old broken: def index
# old broken: @joint = Joint.distinct.pluck(:Joint)
# old broken:
# old broken: @records = Joint.all
# old broken:
# old broken: @records = @records.where(Joint: params[joint]) if params[:joint].present?
# old broken: end
end end
+3
View File
@@ -1,2 +1,5 @@
class Joint < ApplicationRecord class Joint < ApplicationRecord
def readonly?
true
end
end end
+3
View File
@@ -1,2 +1,5 @@
class JointsInfo < ApplicationRecord class JointsInfo < ApplicationRecord
def readonly?
true
end
end end
+3
View File
@@ -1,2 +1,5 @@
class SpecialTest < ApplicationRecord class SpecialTest < ApplicationRecord
def readonly?
true
end
end end
+88
View File
@@ -0,0 +1,88 @@
<h1>Excel Replacement Dashboard</h1>
<!-- Dropdown Filters (No submit button needed, JS handles it) -->
<%= form_with url: dashboard_path, method: :get, id: "filter-form" do |f| %>
<div>
<%= f.label :joint, "Select Joint:" %>
<%= f.select :joint, options_for_select(@available_joints, params[:joint]), include_blank: "All joints", id: "joint" %>
</div>
<% end %>
<hr>
<h2>Dashboard Results</h2>
<div style="overflow-x: auto;">
<table border="1" id="results-table">
<thead>
<tr id="table-headers">
<!-- Dynamically populated headers -->
</tr>
</thead>
<tbody id="table-body">
<!-- Dynamically populated rows (supports 4 to 20+ values) -->
</tbody>
</table>
</div>
<script>
document.addEventListener("DOMContentLoaded", () => {
const jointSelect = document.getElementById("joint");
const tableHeaders = document.getElementById("table-headers");
const tableBody = document.getElementById("table-body");
function fetchFilteredData() {
const joint = jointSelect.value;
// Build query parameters
const params = new URLSearchParams();
if (joint) params.append("joint", joint);
// Fetch data from Rails with JSON format
fetch(`/dashboard?${params.toString()}`, {
headers: { "Accept": "application/json" }
})
.then(response => response.json())
.then(data => {
renderTable(data);
})
.catch(error => console.error("Error fetching dashboard data:", error));
}
function renderTable(records) {
tableHeaders.innerHTML = "";
tableBody.innerHTML = "";
if (records.length === 0) {
tableBody.innerHTML = "<tr><td colspan='100'>No records found</td></tr>";
return;
}
// Extract column keys dynamically from the first record (handles variable lengths)
const columns = Object.keys(records[0]);
// 1. Build dynamic headers
columns.forEach(col => {
const th = document.createElement("th");
th.textContent = col.replace(/_/g, " ").toUpperCase();
tableHeaders.appendChild(th);
});
// 2. Build dynamic rows (whether 4 or 20 attributes long)
records.forEach(record => {
const tr = document.createElement("tr");
columns.forEach(col => {
const td = document.createElement("td");
td.textContent = record[col] !== null ? record[col] : "";
tr.appendChild(td);
});
tableBody.appendChild(tr);
});
}
// Trigger fetch when either dropdown changes
jointSelect.addEventListener("change", fetchFilteredData);
// Load initial data on page load
fetchFilteredData();
});
</script>
+5 -2
View File
@@ -10,8 +10,11 @@ default: &default
timeout: 5000 timeout: 5000
development: development:
<<: *default adapter: sqlite3
database: storage/development.sqlite3 max_connections: 5
timeout: 5000
database: storage/anat_proj.db
#readonly: true
# Warning: The database defined as "test" will be erased and # Warning: The database defined as "test" will be erased and
# re-generated from your development database when you run "rake". # re-generated from your development database when you run "rake".
+2
View File
@@ -11,4 +11,6 @@ Rails.application.routes.draw do
# Defines the root path route ("/") # Defines the root path route ("/")
# root "posts#index" # root "posts#index"
root "dashboard#index"
get "dashboard", to: "dashboard#index"
end end