Compare commits
1 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 0172c86958 |
@@ -1,13 +0,0 @@
|
|||||||
# 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
|
|
||||||
|
|
||||||
@@ -1,31 +0,0 @@
|
|||||||
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
|
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
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
|
||||||
@@ -1,2 +0,0 @@
|
|||||||
module DashboardHelper
|
|
||||||
end
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
class Joint < ApplicationRecord
|
|
||||||
def readonly?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
class JointsDashboard < ApplicationRecord
|
||||||
|
self.table_name = "Joints"
|
||||||
|
|
||||||
|
# Prevent actidental updates from code:
|
||||||
|
def readonly?
|
||||||
|
true
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
end
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
class JointsInfo < ApplicationRecord
|
|
||||||
def readonly?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
class SpecialTest < ApplicationRecord
|
|
||||||
def readonly?
|
|
||||||
true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
@@ -1,88 +0,0 @@
|
|||||||
<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>
|
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
<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>
|
||||||
@@ -23,5 +23,8 @@ 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
|
||||||
|
|||||||
+4
-3
@@ -11,10 +11,11 @@ default: &default
|
|||||||
|
|
||||||
development:
|
development:
|
||||||
adapter: sqlite3
|
adapter: sqlite3
|
||||||
max_connections: 5
|
#database: "file:db/anat_proj.db?mode=ro"
|
||||||
timeout: 5000
|
database: "db/anat_proj.db"
|
||||||
database: storage/anat_proj.db
|
|
||||||
#readonly: true
|
#readonly: true
|
||||||
|
pool: 5
|
||||||
|
timeout: 5000
|
||||||
|
|
||||||
# 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".
|
||||||
|
|||||||
@@ -75,4 +75,8 @@ 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
|
||||||
|
|||||||
+1
-2
@@ -11,6 +11,5 @@ Rails.application.routes.draw do
|
|||||||
|
|
||||||
# Defines the root path route ("/")
|
# Defines the root path route ("/")
|
||||||
# root "posts#index"
|
# root "posts#index"
|
||||||
root "dashboard#index"
|
root "joints#index"
|
||||||
get "dashboard", to: "dashboard#index"
|
|
||||||
end
|
end
|
||||||
|
|||||||
Binary file not shown.
@@ -1,7 +0,0 @@
|
|||||||
require "test_helper"
|
|
||||||
|
|
||||||
class DashboardControllerTest < ActionDispatch::IntegrationTest
|
|
||||||
# test "the truth" do
|
|
||||||
# assert true
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
Vendored
-11
@@ -1,11 +0,0 @@
|
|||||||
# 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
|
|
||||||
Vendored
-11
@@ -1,11 +0,0 @@
|
|||||||
# 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 JointTest < ActiveSupport::TestCase
|
class JointsDashboardTest < ActiveSupport::TestCase
|
||||||
# test "the truth" do
|
# test "the truth" do
|
||||||
# assert true
|
# assert true
|
||||||
# end
|
# end
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
require "test_helper"
|
|
||||||
|
|
||||||
class JointsInfoTest < ActiveSupport::TestCase
|
|
||||||
# test "the truth" do
|
|
||||||
# assert true
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
@@ -1,7 +0,0 @@
|
|||||||
require "test_helper"
|
|
||||||
|
|
||||||
class SpecialTestTest < ActiveSupport::TestCase
|
|
||||||
# test "the truth" do
|
|
||||||
# assert true
|
|
||||||
# end
|
|
||||||
end
|
|
||||||
Reference in New Issue
Block a user