-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
enabling calibration on the table level
currently Boilerplate calibration of a fixed date, next step is to make this dependend on the selected items from the table
- Loading branch information
Martin Hinz
committed
Jun 18, 2024
1 parent
feeadaa
commit e22e29e
Showing
8 changed files
with
160 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
class CalibrationsController < ApplicationController | ||
# GET /:section | ||
def new | ||
@calibration = C14.first.calibration | ||
@calibration.calibrate | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import { Controller } from "@hotwired/stimulus" | ||
import vegaEmbed from "vega-embed" | ||
|
||
export default class extends Controller { | ||
static targets = ["selectAll", "checkbox"] | ||
|
||
connect() { | ||
console.log("TableController connected"); | ||
|
||
this.allPagesSelected = false; | ||
|
||
this.selectAllTarget.addEventListener('change', this.toggleSelectAll.bind(this)); | ||
} | ||
|
||
selectAllPage(event) { | ||
event.preventDefault(); | ||
this.allPagesSelected = false; | ||
this.toggleCheckboxes(true); | ||
} | ||
|
||
changeSelectMode(event) { | ||
event.preventDefault(); | ||
const value = event.target.getAttribute("data-value"); | ||
if (value === "page") { | ||
this.allPagesSelected = false; | ||
this.toggleCheckboxes(true); | ||
} else if (value === "all") { | ||
this.allPagesSelected = true; | ||
this.toggleSelectAllAcrossPages(); | ||
} | ||
console.log(`Select mode changed to: ${value}`); | ||
} | ||
|
||
toggleSelectAll(event) { | ||
const isChecked = event.target.checked; | ||
this.allPagesSelected = false; | ||
this.toggleCheckboxes(isChecked); | ||
console.log(`Toggling checkboxes across all pages: ${this.allPagesSelected}`); | ||
|
||
} | ||
|
||
toggleSelectAllAcrossPages() { | ||
const isChecked = true; | ||
this.toggleCheckboxes(isChecked); | ||
console.log(`Toggling checkboxes across all pages: ${this.allPagesSelected}`); | ||
// Implement the logic to check/uncheck all checkboxes across all pages if needed. | ||
// This may involve an AJAX call to get all items and update their status accordingly. | ||
// For now, we'll just log the state change. | ||
} | ||
|
||
toggleCheckbox(event) { | ||
this.updateSelectAllState(); | ||
} | ||
|
||
toggleCheckboxes(isChecked) { | ||
this.checkboxTargets.forEach(checkbox => { | ||
checkbox.checked = isChecked; | ||
}); | ||
this.updateSelectAllState(); | ||
} | ||
|
||
updateSelectAllState() { | ||
const allChecked = this.checkboxTargets.every(checkbox => checkbox.checked); | ||
const someChecked = this.checkboxTargets.some(checkbox => checkbox.checked); | ||
|
||
this.selectAllTarget.checked = allChecked; | ||
this.selectAllTarget.indeterminate = !allChecked && someChecked; | ||
|
||
if (this.allPagesSelected && allChecked) { | ||
this.selectAllTarget.checked = true; | ||
this.selectAllTarget.indeterminate = false; | ||
} | ||
} | ||
showCalibrationPlot(event) { | ||
console.log("Showing the calibration plot") | ||
|
||
const calibrationId = this.calibrationIdValue | ||
const modalElement = document.querySelector('#remote_modal') | ||
console.log(modalElement ? "#remote_modal found" : "#remote_modal not found") | ||
|
||
if (modalElement) { | ||
modalElement.addEventListener('shown.bs.modal', () => { | ||
const plotDataElement = document.querySelector(`#calibration-plot-data`) | ||
console.log(plotDataElement ? "Calibration plot data found" : "Calibration plot data not found") | ||
|
||
if (plotDataElement) { | ||
const spec = JSON.parse(plotDataElement.textContent) | ||
console.log("Vega spec:", spec) | ||
|
||
const chartContainer = document.querySelector('#vega-chart') | ||
console.log(chartContainer ? "#vega-chart found" : "#vega-chart not found") | ||
|
||
if (chartContainer) { | ||
vegaEmbed('#vega-chart', spec).then(function(result) { | ||
console.log("Vega chart rendered!") | ||
}).catch(error => { | ||
console.error("Error rendering Vega chart:", error) | ||
}) | ||
} else { | ||
console.error("#vega-chart does not exist") | ||
} | ||
} else { | ||
console.error("Calibration plot data not found") | ||
} | ||
}, { once: true }) // Ensure the event listener is only called once | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<%= render "shared/remote_modal", title: "Edit radiocarbon date" do %> | ||
<div id="calibration-plot-data" data-calibration-id="<%= @calibration.id %>" style="display:none;"> | ||
<%= raw calibration_plot_json(@calibration) %> | ||
</div> | ||
|
||
<div id="vega-chart" style="width: 100%; height: 400px;"></div> | ||
|
||
<%= content_for :buttons do %> | ||
<%= button_tag "Close", type: 'reset', class: 'btn btn-danger', data: { "bs-dismiss": "modal" } %> | ||
<% end %> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters