2 Commits

Author SHA1 Message Date
bionickatana 7532b938ed Super basic version 2026-07-27 20:06:15 -06:00
bionickatana 1932ad4f72 Created new stuff 2026-07-27 18:45:09 -06:00
22 changed files with 198 additions and 76 deletions
+13
View File
@@ -0,0 +1,13 @@
# Setting up the application
## Create the database connections:
bin/rails generate model Joints --no-migration
bin/rails generate model JointsInfo --no-migration
bin/rails generate model SpecialTest --no-migration
# Setup the views
bin/rails generate controller dashboard
+31
View File
@@ -0,0 +1,31 @@
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
-14
View File
@@ -1,14 +0,0 @@
class JointsController < ApplicationController
def index
# Grab values:
@available_categories = JointsDashboard.distinct.pluck(:Joint)
# Start with base query:
@records = JointsDashboard.all
# Filter data based on dropdown selection params
@records = @records.where(Joint: params[:joint]) if params[:joint].present?
#@records = @records.where(Joint == params[:joint]) if params[:joint].present?
puts @records
end
end
+2
View File
@@ -0,0 +1,2 @@
module DashboardHelper
end
+5
View File
@@ -0,0 +1,5 @@
class Joint < ApplicationRecord
def readonly?
true
end
end
-10
View File
@@ -1,10 +0,0 @@
class JointsDashboard < ApplicationRecord
self.table_name = "Joints"
# Prevent actidental updates from code:
def readonly?
true
end
end
+5
View File
@@ -0,0 +1,5 @@
class JointsInfo < ApplicationRecord
def readonly?
true
end
end
+5
View File
@@ -0,0 +1,5 @@
class SpecialTest < ApplicationRecord
def readonly?
true
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>
-39
View File
@@ -1,39 +0,0 @@
<h1>Excel Replacement Dashboard</h1>
<!-- Dropdown Filters Form -->
<%= form_with url: dashboard_path, method: :get, local: true do |f| %>
<div>
<%= f.label :category, "Select Category:" %>
<%= f.select :category, options_for_select(@available_categories, params[:category]), include_blank: "All Categories" %>
</div>
<div>
<%= f.label :region, "Select Region:" %>
<%= f.select :region, options_for_select(@available_regions, params[:region]), include_blank: "All Regions" %>
</div>
<%= f.submit "Filter Data" %>
<% end %>
<hr>
<!-- Displaying the Data in Specific Locations / Table -->
<h2>Dashboard Results</h2>
<table>
<thead>
<tr>
<th>Column 1</th>
<th>Column 2</th>
<th>Value</th>
</tr>
</thead>
<tbody>
<% @records.each do |record| %>
<tr>
<td><%= record.category_column %></td>
<td><%= record.region_column %></td>
<td><%= record.metric_value_column %></td>
</tr>
<% end %>
</tbody>
</table>
-3
View File
@@ -23,8 +23,5 @@ module Site
# #
# config.time_zone = "Central Time (US & Canada)" # config.time_zone = "Central Time (US & Canada)"
# config.eager_load_paths << Rails.root.join("extras") # config.eager_load_paths << Rails.root.join("extras")
# Disable activerecord performing migrations.
config.active_record.migration_error = false
end end
end end
+3 -4
View File
@@ -11,11 +11,10 @@ default: &default
development: development:
adapter: sqlite3 adapter: sqlite3
#database: "file:db/anat_proj.db?mode=ro" max_connections: 5
database: "db/anat_proj.db"
#readonly: true
pool: 5
timeout: 5000 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".
-4
View File
@@ -75,8 +75,4 @@ Rails.application.configure do
# Apply autocorrection by RuboCop to files generated by `bin/rails generate`. # Apply autocorrection by RuboCop to files generated by `bin/rails generate`.
# config.generators.apply_rubocop_autocorrect_after_generate! # config.generators.apply_rubocop_autocorrect_after_generate!
config.active_record.migration_error = false
config.log_level = :debug
#config.active_record,verbose_query_logs = true
end end
+2 -1
View File
@@ -11,5 +11,6 @@ Rails.application.routes.draw do
# Defines the root path route ("/") # Defines the root path route ("/")
# root "posts#index" # root "posts#index"
root "joints#index" root "dashboard#index"
get "dashboard", to: "dashboard#index"
end end
BIN
View File
Binary file not shown.
@@ -0,0 +1,7 @@
require "test_helper"
class DashboardControllerTest < ActionDispatch::IntegrationTest
# test "the truth" do
# assert true
# end
end
+11
View File
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
+11
View File
@@ -0,0 +1,11 @@
# Read about fixtures at https://api.rubyonrails.org/classes/ActiveRecord/FixtureSet.html
# This model initially had no columns defined. If you add columns to the
# model remove the "{}" from the fixture names and add the columns immediately
# below each fixture, per the syntax in the comments below
#
one: {}
# column: value
#
two: {}
# column: value
@@ -1,6 +1,6 @@
require "test_helper" require "test_helper"
class JointsDashboardTest < ActiveSupport::TestCase class JointTest < ActiveSupport::TestCase
# test "the truth" do # test "the truth" do
# assert true # assert true
# end # end
+7
View File
@@ -0,0 +1,7 @@
require "test_helper"
class JointsInfoTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end
+7
View File
@@ -0,0 +1,7 @@
require "test_helper"
class SpecialTestTest < ActiveSupport::TestCase
# test "the truth" do
# assert true
# end
end