forked from lin-midas-pages/common_pages
Applied Edwards review suggestions
Removed some unused functions, changed var to let / const whereever possible, adjusted README so it is in sync with the actual code, fixed a logic bug when checking if sequencer.js is loaded, removed last globalThis instance from Voltage_tab.js.
This commit is contained in:
1 parent
5a73e36861
commit
eab406d5cf
4 files changed
+111
-356
No files matched your search
@@ -11,96 +11,15 @@ instrument-specific pages repository such as
|
||||
`pages/common.js` is an ES module that holds the shared front-end logic of
|
||||
the "Mudas" (MIDAS User interface) page. It contains no instrument specific
|
||||
information; that is supplied by the instrument repository. To reuse it in a
|
||||
custom MIDAS UI you need three things:
|
||||
custom MIDAS UI you need the following things:
|
||||
|
||||
1. an HTML page that provides the DOM skeleton `common.js` expects,
|
||||
2. an ES-module init file that imports `common.js`, supplies the instrument
|
||||
1. an ES-module init file that imports `common.js`, supplies the instrument
|
||||
configuration and drives the page, and
|
||||
3. (optionally) per-tab markup/JS files under a `tabs/` directory.
|
||||
2. (optionally) per-tab markup/JS files under a `tabs/` directory.
|
||||
|
||||
After installing (see above) the files live in the MIDAS pages directory
|
||||
(the CMake install prefix), which MIDAS serves and advertises to the browser
|
||||
via the `/ODB/Custom/Path` ODB entry.
|
||||
|
||||
### The page skeleton
|
||||
|
||||
`common.js` finds its targets by element `id`, so the page must contain the
|
||||
structural elements it builds on. The reference implementation is
|
||||
`pages/Mudas.html`. The ids the module looks for, grouped by feature:
|
||||
|
||||
| Feature | Element ids |
|
||||
| --- | --- |
|
||||
| MIDAS header / sidebar (standard mhttpd) | `mheader`, `msidenav`, `mmain` |
|
||||
| Alarms table | `alarmsTable` |
|
||||
| Instrument banner | `instrName` |
|
||||
| Header links | `elogLink`, `musrfitRun`, `SearchDBlink` |
|
||||
| Run status banner / time | `run_statusBanner`, `stopTimetd`, `vstopTimetd`, `stopTime` |
|
||||
| Run control buttons *(optional, guarded)* | `startButton`, `stopButton`, `pauseButton`, `resumeButton`, `writeButton`, `zeroButton` |
|
||||
| HIPA status | `HIPAimg`, plus a HIPA entry with id `100` in the tab menu |
|
||||
| Tab bar | `tabBtns`, `tabMenu`, `tabFrames`, `beforeMenu` |
|
||||
| PySequencer header | `AutoRunState`, `AutoRunLine` |
|
||||
| Proposal / DUO | `propID`, `propPI`, `propGRP`, `propFromDuo` |
|
||||
|
||||
On top of these, any element whose **id** is a key of `instrODB` (below) is
|
||||
bound to that ODB path, and the placeholders named `mvarvalue`, `mvarbox`,
|
||||
`mvarcheckbox`, `mvarselect` and `frappy_enum` are resolved by
|
||||
`mvar_init()` / `frappy_enum_init()`.
|
||||
|
||||
### The init file
|
||||
|
||||
The init file is an ES module loaded with `<script type="module">`. It
|
||||
imports `common.js`, defines the instrument configuration and calls `init()`
|
||||
once, then `update()` to start the periodic refresh loop:
|
||||
|
||||
```js
|
||||
import * as common from "./common.js";
|
||||
|
||||
// Instrument name (used for the banner, DUO and muSRFit queries)
|
||||
const instrName = "VMS";
|
||||
// Color for the banner and the mtable borders
|
||||
const instrColor = "#53b7d3";
|
||||
// Elog URL ("" hides the link)
|
||||
const elogLink = "https://lmu-elog.psi.ch/VMS/";
|
||||
|
||||
// Map of element id -> ODB path. Every listed id must exist in the page.
|
||||
const instrODB = {
|
||||
run_status: "/Runinfo/State",
|
||||
runNumber: "/Runinfo/Run number",
|
||||
sampleName: "/Info/Sample Name",
|
||||
pID: "/Info/MusrRootConfig/Fileheader_Info/Proposal Number",
|
||||
pPI: "/Info/MusrRootConfig/Fileheader_Info/Main Proposer",
|
||||
pGRP: "/Info/MusrRootConfig/Fileheader_Info/P-Group",
|
||||
// ...any other header values you want to bind by id
|
||||
};
|
||||
|
||||
// Tab definitions (see "Tabs" below)
|
||||
const instrTabs = {
|
||||
runControl: {
|
||||
order: 1,
|
||||
label: "Run Control",
|
||||
htmlFile: "RunControl_tab.html",
|
||||
jsFile: "RunControl_tab.js", // optional
|
||||
init: "init_run_control_tab", // optional
|
||||
initArgs: [instrODB], // optional
|
||||
style: "Tab", // "Tab" or "Menu"
|
||||
},
|
||||
cryostat: {
|
||||
order: 2,
|
||||
label: "Cryostat",
|
||||
htmlFile: "Cryostat_tab.html", // no jsFile -> markup only
|
||||
style: "Tab",
|
||||
},
|
||||
};
|
||||
|
||||
window.addEventListener("load", async () => {
|
||||
mhttpd_init("Mudas");
|
||||
await common.init(instrTabs, instrODB, instrName, instrColor, elogLink);
|
||||
common.update(instrODB); // starts the periodic refresh
|
||||
});
|
||||
```
|
||||
|
||||
`common.init()` is `async` because it fetches every tab's markup and imports
|
||||
the tab JS modules before it returns.
|
||||
After installing the files live in the MIDAS pages directory (the CMake install
|
||||
prefix), which MIDAS serves and advertises to the browser via the
|
||||
`/ODB/Custom/Path` ODB entry.
|
||||
|
||||
### Tabs
|
||||
|
||||
@@ -120,26 +39,6 @@ one tab; the full field reference is in the `fill_tabs()` docstring in
|
||||
- `style` — `"Tab"` (top bar) or `"Menu"` (grouped under "More ...").
|
||||
- `order` / `label` — placement and caption.
|
||||
|
||||
### Reaching functions from the static HTML
|
||||
|
||||
`common.js` is a module, so its functions are not on `window`. Handlers written
|
||||
as inline `onclick="..."` in the HTML skeleton can therefore only see globals.
|
||||
Export the functions the static HTML needs onto `globalThis`, for example:
|
||||
|
||||
```js
|
||||
globalThis.set_div_visibility = common.set_div_visibility;
|
||||
globalThis.swap_divs = common.swap_divs;
|
||||
```
|
||||
|
||||
Or better yet, add the handlers in your instrument-specific JS init function:
|
||||
|
||||
```js
|
||||
document.getElementById("your_element_id").addEventListener("click", common.set_div_visibility);
|
||||
```
|
||||
|
||||
Functions that are only called from other JS can stay module-local (or be
|
||||
called through `common.*`).
|
||||
|
||||
### Optional hooks
|
||||
|
||||
- **Run control** — `common.start_run()`, `common.pause_run()`,
|
||||
@@ -190,13 +89,6 @@ has an example.
|
||||
|
||||
## Contact
|
||||
|
||||
Flame:
|
||||
<jonas.krieger@psi.ch>;
|
||||
LEM:
|
||||
<andreas.suter@psi.ch>,
|
||||
<thomas.prokscha@psi.ch>,
|
||||
<zaher.salman@psi.ch>
|
||||
LIN:
|
||||
<alexander.soederqvist@psi.ch>
|
||||
<edward.wall@psi.ch>
|
||||
<stefan.mathis@psi.ch>
|
||||
+8
-8
@@ -875,13 +875,13 @@ function set_running_time(run_state) {
|
||||
stopTime.style.visibility = "hidden";
|
||||
// show running time
|
||||
mjsonrpc_db_get_values(["/Runinfo"]).then(function (rpc) {
|
||||
runinfo = rpc.result.data[0];
|
||||
time = runinfo['start time binary/last_written'];
|
||||
difftime = Math.round(new Date().getTime() / 1000) - time;
|
||||
h = Math.floor(difftime / 3600);
|
||||
m = Math.floor(difftime % 3600 / 60);
|
||||
s = Math.floor(difftime % 60);
|
||||
runTime = h + "h" + ((m < 10) ? "0" + m : m) + "m" + ((s < 10) ? "0" + s : s) + "s";
|
||||
const runinfo = rpc.result.data[0];
|
||||
const time = runinfo['start time binary/last_written'];
|
||||
const difftime = Math.round(new Date().getTime() / 1000) - time;
|
||||
const h = Math.floor(difftime / 3600);
|
||||
const m = Math.floor(difftime % 3600 / 60);
|
||||
const s = Math.floor(difftime % 60);
|
||||
const runTime = h + "h" + ((m < 10) ? "0" + m : m) + "m" + ((s < 10) ? "0" + s : s) + "s";
|
||||
document.getElementById("vstopTimetd").innerHTML = runTime;
|
||||
}).catch(function (error) { console.error(error); });
|
||||
} else {
|
||||
@@ -1138,7 +1138,7 @@ export function open_tab(evt, tab) {
|
||||
* @param {string} command - The script name to load (or "Idle").
|
||||
*/
|
||||
export function run_pysequencer_script(command) {
|
||||
if (typeof dlgParam !== 'function' && typeof checkODBValue !== 'function') {
|
||||
if (typeof dlgParam !== 'function' || typeof checkODBValue !== 'function') {
|
||||
// sequencer.js needs to be loaded
|
||||
console.error("dlgParam and/or checkODBValue missing. Please ensure that sequencer.js is correctly loaded.");
|
||||
return;
|
||||
|
||||
+55
-59
@@ -17,7 +17,7 @@ let instrODB_local;
|
||||
export function init(instrODB) {
|
||||
instrODB_local = instrODB;
|
||||
|
||||
read_tdc_promise(instrODB).then(function () {
|
||||
read_tdc_promise().then(function () {
|
||||
init_config();
|
||||
}).catch(function (error) { console.error(error); });
|
||||
|
||||
@@ -32,44 +32,44 @@ export function init(instrODB) {
|
||||
// Here follows the properties for the first elements "general information"
|
||||
// from the TDC-file.
|
||||
new ODB_element_TDC('/Experiment/', 'Name', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Description', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Data_Window', 'int', ''),
|
||||
new ODB_element_TDC(instrODB.tdcSettingsDir, 'Type', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.tdcSettingsDir, 'Time_Per_Bin', 'str', '0'),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Muon_Delay', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Positron_Delay', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Muon_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Positron_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Veto Pre_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Veto_Post_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'T0_OffSet', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Pre_Pileup_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Post_Pileup_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Description', 'str', ''),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Data_Window', 'int', ''),
|
||||
new ODB_element_TDC(instrODB_local.tdcSettingsDir, 'Type', 'str', ''),
|
||||
new ODB_element_TDC(instrODB_local.tdcSettingsDir, 'Time_Per_Bin', 'str', '0'),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Muon_Delay', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Positron_Delay', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Muon_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Positron_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Veto Pre_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Veto_Post_Coincidence_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'T0_OffSet', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Pre_Pileup_Window', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Post_Pileup_Window', 'int', 0),
|
||||
]
|
||||
|
||||
ODBcontent_channelTDC = [
|
||||
// Here follows the properties for the channels "channel lines"
|
||||
// from the TDC-file.
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Channel_Used', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Channel_Name', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Channel_Type', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.tdcSettingsDir, 'Channel_OffSet', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.logicDir, 'Channel_Logic', 'str', ';'),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Channel_Used', 'str', ''),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Channel_Name', 'str', ''),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Channel_Type', 'str', ''),
|
||||
new ODB_element_TDC(instrODB_local.tdcSettingsDir, 'Channel_OffSet', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.logicDir, 'Channel_Logic', 'str', ';'),
|
||||
]
|
||||
|
||||
ODBcontent_channelHisto = [
|
||||
// Here follows the properties for the channels "channel lines"
|
||||
// from the TDC-file.
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'Number', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'Name', 'str', 'Ch'),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'TDCchannels', 'str', ''),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'T0', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'FirstGood', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'LastGood', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'Length', 'int', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'xUp', 'float', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'xLow', 'float', 0),
|
||||
new ODB_element_TDC(instrODB.histogramDir, 'PP_correction_post_logic', 'bool', false),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'Number', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'Name', 'str', 'Ch'),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'TDCchannels', 'str', ''),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'T0', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'FirstGood', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'LastGood', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'Length', 'int', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'xUp', 'float', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'xLow', 'float', 0),
|
||||
new ODB_element_TDC(instrODB_local.histogramDir, 'PP_correction_post_logic', 'bool', false),
|
||||
]
|
||||
|
||||
document.getElementById("selectTDC").addEventListener("click", display_config);
|
||||
@@ -77,7 +77,7 @@ export function init(instrODB) {
|
||||
document.getElementById("loadV1190").addEventListener("click", display_v1190);
|
||||
document.getElementById("editTDC").addEventListener("click", edit_config);
|
||||
document.getElementById("resetTDC").addEventListener("click", init_config);
|
||||
document.getElementById("loadTDC").addEventListener("click", () => apply_last_config(instrODB));
|
||||
document.getElementById("loadTDC").addEventListener("click", () => apply_last_config(instrODB_local));
|
||||
document.getElementById("tdc_DatWindow_button").addEventListener("click", change_data_window);
|
||||
document.getElementById("run_statusValue").addEventListener("change", disable_by_run_status);
|
||||
document.getElementById("run_statusValue").addEventListener("load", disable_by_run_status);
|
||||
@@ -133,12 +133,12 @@ export function read_tdc_status() { //shortcut without promise
|
||||
read_tdc_promise(instrODB_local).then(function () { }).catch(function (error) { console.error(error); });
|
||||
}
|
||||
|
||||
function read_tdc_promise(instrODB) {
|
||||
function read_tdc_promise() {
|
||||
return new Promise(function (resolve, reject) {
|
||||
mjsonrpc_db_get_values([instrODB.histogramDir + 'Name',
|
||||
instrODB.logicDir + 'Channel_Name', //instrODB.histScalerDir
|
||||
instrODB.logicDir + 'Channel_Used',
|
||||
instrODB.logicDir + 'Channel_Type']
|
||||
mjsonrpc_db_get_values([instrODB_local.histogramDir + 'Name',
|
||||
instrODB_local.logicDir + 'Channel_Name',
|
||||
instrODB_local.logicDir + 'Channel_Used',
|
||||
instrODB_local.logicDir + 'Channel_Type']
|
||||
).then(function (rpc) {
|
||||
tdcStatus['HistoName'] = rpc.result.data[0];
|
||||
tdcStatus['ScalerName'] = rpc.result.data[1];
|
||||
@@ -306,7 +306,7 @@ function init_config() {
|
||||
|
||||
/* Toggle button states depending on experiment status*/
|
||||
function disable_by_run_status() {
|
||||
runStopped = document.getElementById("run_statusValue").value == 1
|
||||
const runStopped = document.getElementById("run_statusValue").value == 1
|
||||
//Enable only if Run stopped
|
||||
if (runStopped) {
|
||||
enable_class("stoppedEditable", set = "enable", "");
|
||||
@@ -352,7 +352,7 @@ function edit_config(enable = true) {
|
||||
|
||||
// Use a default fileName when editing:
|
||||
if (enable == true) {
|
||||
modbset(instrODB.tdcSettingsDir + 'SettingsFile', "Manually edited. Please save!");
|
||||
modbset(instrODB_local.tdcSettingsDir + 'SettingsFile', "Manually edited. Please save!");
|
||||
}
|
||||
//set a red background color in editing mode:
|
||||
const odb_fileName = document.getElementById("TDC_ODB_FILENAME");//current fileName (should be fine without a promise.)
|
||||
@@ -464,10 +464,6 @@ function browse_new_config(newConfig) {
|
||||
DisplayLoadDict(newConfig["Logic"]);
|
||||
DisplayLoadDict(newConfig["Histograms"]);
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
set_class_visibility("tdcNewVal_General", "visible");
|
||||
set_class_visibility("tdcNewVal_Channel", "visible");
|
||||
}
|
||||
@@ -477,7 +473,7 @@ function browse_new_config(newConfig) {
|
||||
* Ignore the Instrument field.
|
||||
* @param {TDCconfig} newConfig
|
||||
*/
|
||||
function apply_new_config(instrODB, newConfig) {
|
||||
function apply_new_config(newConfig) {
|
||||
//ignoring instrument; but set filename:
|
||||
newConfig["Settings"]["SettingsFile"] = gTDClastLoadfileName;
|
||||
//paste into odb.
|
||||
@@ -494,15 +490,15 @@ function apply_new_config(instrODB, newConfig) {
|
||||
let paths = [];
|
||||
let values = [];
|
||||
for (key in newConfig["Logic"]) {
|
||||
paths.push(instrODB.logicDir + key);
|
||||
paths.push(instrODB_local.logicDir + key);
|
||||
values.push(newConfig["Logic"][key]);
|
||||
}
|
||||
for (key in newConfig["Histograms"]) {
|
||||
paths.push(instrODB.histogramDir + key);
|
||||
paths.push(instrODB_local.histogramDir + key);
|
||||
values.push(newConfig["Histograms"][key]);
|
||||
}
|
||||
for (key in newConfig["Settings"]) {
|
||||
paths.push(instrODB.tdcSettingsDir + key);
|
||||
paths.push(instrODB_local.tdcSettingsDir + key);
|
||||
values.push(newConfig["Settings"][key]);
|
||||
}
|
||||
|
||||
@@ -541,16 +537,16 @@ function add_hist_to_display_channels(addHistch) {
|
||||
/*
|
||||
Write the last loaded configuration (gTDClastLoadfileName) into the odb.
|
||||
*/
|
||||
function apply_last_config(instrODB) {
|
||||
function apply_last_config() {
|
||||
|
||||
let extension = gTDClastLoadfileName.split('.').pop();
|
||||
|
||||
if (extension == "v1190") {
|
||||
load_v1190(gTDClastLoadfileName, () => { apply_new_config(instrODB) });
|
||||
load_v1190(gTDClastLoadfileName, () => { apply_new_config() });
|
||||
return;
|
||||
}
|
||||
|
||||
load_config(gTDClastLoadfileName, () => { apply_new_config(instrODB) });
|
||||
load_config(gTDClastLoadfileName, () => { apply_new_config() });
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -616,7 +612,7 @@ function save_config(fileName) {
|
||||
|
||||
//Get a "clean" extract, without metadata:
|
||||
let request = new Object();
|
||||
request.paths = ["/Experiment/Name", instrODB.tdcSettingsDir, instrODB.logicDir, instrODB.histogramDir];
|
||||
request.paths = ["/Experiment/Name", instrODB_local.tdcSettingsDir, instrODB_local.logicDir, instrODB_local.histogramDir];
|
||||
request.omit_names = true;
|
||||
request.omit_last_written = true;
|
||||
request.omit_tid = true;
|
||||
@@ -841,7 +837,7 @@ async function load_v1190(fileName, callback) {
|
||||
}
|
||||
|
||||
|
||||
let histlength = await mjsonrpc_db_get_value(instrODB.logicDir + "Data_Window").then((rpc) => {
|
||||
let histlength = await mjsonrpc_db_get_value(instrODB_local.logicDir + "Data_Window").then((rpc) => {
|
||||
return Number(rpc.result.data[0]) + 1;//Data_Window+1
|
||||
}).catch(function (error) { console.error(error); });
|
||||
console.log(histlength);
|
||||
@@ -1031,7 +1027,7 @@ function change_data_window() {
|
||||
let newValue = parseFloat(valueInput.value);
|
||||
// get time per bin
|
||||
|
||||
mjsonrpc_db_get_value(instrODB.tdcSettingsDir + "Time_Per_Bin").then((rpc) => {
|
||||
mjsonrpc_db_get_value(instrODB_local.tdcSettingsDir + "Time_Per_Bin").then((rpc) => {
|
||||
let time_per_bin = Number(rpc.result.data[0]);//Data_Window+1
|
||||
//Determine Data window
|
||||
newValue = Math.round(newValue / time_per_bin);
|
||||
@@ -1057,27 +1053,27 @@ function change_data_window() {
|
||||
* */
|
||||
function update_data_window(dataWindow) {
|
||||
//change values
|
||||
modbset(instrODB.logicDir + "Data_Window", dataWindow);
|
||||
modbset(instrODB.logicDir + "Pre_Pileup_Window", dataWindow);
|
||||
modbset(instrODB_local.logicDir + "Data_Window", dataWindow);
|
||||
modbset(instrODB_local.logicDir + "Pre_Pileup_Window", dataWindow);
|
||||
|
||||
mjsonrpc_db_get_value(instrODB.logicDir + "Post_Pileup_Window").then((rpc) => {
|
||||
mjsonrpc_db_get_value(instrODB_local.logicDir + "Post_Pileup_Window").then((rpc) => {
|
||||
let postPileupWindow = rpc.result.data[0];
|
||||
//only update it, if it is not zero.
|
||||
if (postPileupWindow != 0) {
|
||||
modbset(instrODB.logicDir + "Post_Pileup_Window", dataWindow);
|
||||
modbset(instrODB_local.logicDir + "Post_Pileup_Window", dataWindow);
|
||||
}
|
||||
}).catch(function (error) { console.error(error); });
|
||||
|
||||
//simultaneously change arrays
|
||||
//determine length first
|
||||
mjsonrpc_db_get_value(instrODB.histogramDir + "Length").then((rpc) => {
|
||||
mjsonrpc_db_get_value(instrODB_local.histogramDir + "Length").then((rpc) => {
|
||||
let histLenghts = rpc.result.data[0];
|
||||
if (Array.isArray(histLenghts)) {
|
||||
let len = histLenghts.length - 1;//last index to adress array with.
|
||||
//set all array elements to the same value
|
||||
modbset(instrODB.histogramDir + "Length[0-" + len + "]", dataWindow + 1);
|
||||
modbset(instrODB.histogramDir + "xUp[0-" + len + "]", dataWindow + 0.5);
|
||||
modbset(instrODB.histogramDir + "LastGood[0-" + len + "]", dataWindow);
|
||||
modbset(instrODB_local.histogramDir + "Length[0-" + len + "]", dataWindow + 1);
|
||||
modbset(instrODB_local.histogramDir + "xUp[0-" + len + "]", dataWindow + 0.5);
|
||||
modbset(instrODB_local.histogramDir + "LastGood[0-" + len + "]", dataWindow);
|
||||
} else {
|
||||
console.error("Unable to change Histogram lengths. Not an array.")
|
||||
}
|
||||
|
||||
+42
-175
@@ -90,12 +90,12 @@ function make_equipment_table(equipment, starti = -1, endi = -1, tableID) {
|
||||
}
|
||||
|
||||
if (eqFlag) {
|
||||
for (var i = starti; i < endi + 1; i++) {
|
||||
for (let i = starti; i < endi + 1; i++) {
|
||||
let odbName = modb_read.replace("dataODBPath", names + "[" + i + "]");
|
||||
let odbDemand = modb_edit.replace("dataODBPath", vardemand + "[" + i + "]");
|
||||
let odbMeasured = modb_read.replace("dataODBPath", varmeas + "[" + i + "]");
|
||||
let row = "<td id='Ch" + i + "n'>" + odbName + "</td>\n";
|
||||
row += "<td class='tdSelectable' onclick='toggle_color(this);' id='Ch" + i + "'>" + odbDemand + "</td>\n";
|
||||
row += "<td class='tdSelectable' id='Ch" + i + "'>" + odbDemand + "</td>\n";
|
||||
row += "<td id='Ch" + i + "m'>" + odbMeasured + "</td>\n";
|
||||
if (ncols == 5) {
|
||||
let odbCurr = modb_read.replace("dataODBPath", curr + "[" + i + "]");
|
||||
@@ -119,6 +119,13 @@ function make_equipment_table(equipment, starti = -1, endi = -1, tableID) {
|
||||
table += "</table>";
|
||||
}
|
||||
document.getElementById(tableID).innerHTML = table;
|
||||
document.getElementById(tableID).addEventListener("click", event => {
|
||||
const cell = event.target.closest(".tdSelectable");
|
||||
if (cell) {
|
||||
toggle_color(cell);
|
||||
}
|
||||
});
|
||||
|
||||
// return as promise ...
|
||||
//return table;
|
||||
}).catch(function (error) {
|
||||
@@ -166,6 +173,12 @@ function open_file(event) {
|
||||
let table = xml_to_table(text);
|
||||
populate_modal("popPrompt");
|
||||
document.getElementById("popHTML").innerHTML = table;
|
||||
document.getElementById("popHTML").addEventListener("click", event => {
|
||||
const cell = event.target.closest(".tdIgnorable, .tdIgnored");
|
||||
if (cell) {
|
||||
toggle_color(cell);
|
||||
}
|
||||
});
|
||||
document.getElementById("popButton").textContent = "Load";
|
||||
document.getElementById("popButton").addEventListener("click", loadHV);
|
||||
document.getElementById("popButton").addEventListener("click", closeModal);
|
||||
@@ -174,8 +187,8 @@ function open_file(event) {
|
||||
}
|
||||
|
||||
function xml_to_table(text, hvSettings) {
|
||||
var parser = new DOMParser();
|
||||
var xmlDoc = parser.parseFromString(text, "text/xml");
|
||||
const parser = new DOMParser();
|
||||
const xmlDoc = parser.parseFromString(text, "text/xml");
|
||||
// Get device name and switch to it, otherwise loading will be a problem
|
||||
let device = xmlDoc.getElementsByTagName("hvDeviceName")[0].innerHTML.trim();
|
||||
let description = xmlDoc.getElementsByTagName("description")[0].innerHTML.trim();
|
||||
@@ -196,7 +209,7 @@ function xml_to_table(text, hvSettings) {
|
||||
let limits = xmlDoc.getElementsByTagName("currentLimit");
|
||||
|
||||
// Create preload table
|
||||
var table = "<table><tr><td>";
|
||||
let table = "<table><tr><td>";
|
||||
table += "<table style='border: 3px;'>\n";
|
||||
table += "<tr><th>Name</th><th>Demand</th><th>Current limit</th></tr>\n"
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
@@ -206,8 +219,8 @@ function xml_to_table(text, hvSettings) {
|
||||
|
||||
table += "<tr>\n";
|
||||
table += "<td id='" + name + "'>" + name + "</td>\n";
|
||||
table += "<td class='tdIgnorable' onclick='toggle_color(this);'><input class='demandVal' type='number' style='width:5em' id='" + name + "d' value='" + demand + "'> ☓ </td>\n";
|
||||
table += "<td class='tdIgnorable' onclick='toggle_color(this);'><input class='currentLim' type='number' style='width:5em' id='" + name + "l' value='" + limit + "'> ☓ </td>\n";
|
||||
table += "<td class='tdIgnorable'><input class='demandVal' type='number' style='width:5em' id='" + name + "d' value='" + demand + "'> ☓ </td>\n";
|
||||
table += "<td class='tdIgnorable'><input class='currentLim' type='number' style='width:5em' id='" + name + "l' value='" + limit + "'> ☓ </td>\n";
|
||||
table += "</tr>\n";
|
||||
}
|
||||
table += "</table></td>\n";
|
||||
@@ -230,10 +243,6 @@ function toggle_color(element) {
|
||||
}
|
||||
}
|
||||
|
||||
// Used by inline onclick="toggle_color(this)" handlers in generated HTML,
|
||||
// which can only resolve names from the global scope.
|
||||
globalThis.toggle_color = toggle_color;
|
||||
|
||||
// This function is used to toggle the highlight of all cells
|
||||
// in the HV tables
|
||||
// newState - all/none toggled to state
|
||||
@@ -248,9 +257,9 @@ function toggle_all(tableID, newState) {
|
||||
|
||||
if (newState == "" || newState == undefined || newState == null) {
|
||||
if (curState == "tdSelectable") {
|
||||
var newState = "tdSelected";
|
||||
newState = "tdSelected";
|
||||
} else {
|
||||
var newState = "tdSelectable";
|
||||
newState = "tdSelectable";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -423,17 +432,17 @@ function saveFile() {
|
||||
}
|
||||
|
||||
// Set correct odb paths
|
||||
var names = "/Equipment/" + equipment + "/Settings/Names";
|
||||
var currlimit = "/Equipment/" + equipment + "/Settings/Current Limit";
|
||||
var vardemand = "/Equipment/" + equipment + "/Variables/Demand";
|
||||
var range = "[" + starti + "-" + endi + "]";
|
||||
const names = "/Equipment/" + equipment + "/Settings/Names";
|
||||
const currlimit = "/Equipment/" + equipment + "/Settings/Current Limit";
|
||||
const vardemand = "/Equipment/" + equipment + "/Variables/Demand";
|
||||
const range = "[" + starti + "-" + endi + "]";
|
||||
|
||||
var odbPaths = [names + range, vardemand + range, currlimit + range];
|
||||
var N = endi - starti;
|
||||
var comment = prompt("Please enter an optional description", "This is a description");
|
||||
const odbPaths = [names + range, vardemand + range, currlimit + range];
|
||||
const N = endi - starti;
|
||||
const comment = prompt("Please enter an optional description", "This is a description");
|
||||
if (comment != null) {
|
||||
mjsonrpc_db_get_values(odbPaths).then(function (rpc) {
|
||||
var doc = '<HV xmlns="http://nemu.web.psi.ch/HV">\n';
|
||||
let doc = '<HV xmlns="http://nemu.web.psi.ch/HV">\n';
|
||||
doc += '<comment>\n';
|
||||
doc += new Date();
|
||||
doc += '\n' + units + '\n';
|
||||
@@ -445,13 +454,10 @@ function saveFile() {
|
||||
doc += '\n</hvDeviceName>\n';
|
||||
for (let i = 0; i <= N; i++) {
|
||||
|
||||
if (instrName == "LEM") {
|
||||
odbname = rpc.result.data[0][i].split("%")[1];
|
||||
} else {
|
||||
odbname = rpc.result.data[0][i];
|
||||
}
|
||||
odbdemand = Math.round(rpc.result.data[1][i] * 1000) / 1000;
|
||||
odblimit = rpc.result.data[2][i];
|
||||
|
||||
const odbname = rpc.result.data[0][i];
|
||||
const odbdemand = Math.round(rpc.result.data[1][i] * 1000) / 1000;
|
||||
const odblimit = rpc.result.data[2][i];
|
||||
doc += '<hvCh name="' + odbname + '">\n';
|
||||
doc += ' <chNo>' + (i + 1) + '</chNo>\n';
|
||||
doc += ' <name>' + odbname + '</name>\n';
|
||||
@@ -460,127 +466,18 @@ function saveFile() {
|
||||
doc += '</hvCh>\n';
|
||||
}
|
||||
doc += '</HV>\n';
|
||||
table = xml_to_table(doc);
|
||||
download(doc, "HV.xml", "text/plain");
|
||||
}).catch(function (error) { console.error(error); });
|
||||
}
|
||||
}
|
||||
|
||||
function saveFileXML() {
|
||||
// doc.appendChild(HVelem);
|
||||
// xmlDoc.createElement("description");
|
||||
|
||||
// get HV device name
|
||||
let device = document.getElementById("HVSettings").value;
|
||||
|
||||
// Read HV details from ODB
|
||||
// Default is FUG
|
||||
let equipment = "HV";
|
||||
let starti = 0;
|
||||
let endi = 15;
|
||||
if (device == "NHR") {
|
||||
equipment = "HV Detectors";
|
||||
starti = 0;
|
||||
endi = 7;
|
||||
} else if (device == "PHVR400") {
|
||||
equipment = "HV Detectors";
|
||||
starti = 8;
|
||||
endi = 10;
|
||||
} else if (device == "NHR400") {
|
||||
equipment = "HV Detectors";
|
||||
starti = 20;
|
||||
endi = 27;
|
||||
} else if (device == "HPP30_107") {
|
||||
equipment = "HV Detectors";
|
||||
starti = 28;
|
||||
endi = 28;
|
||||
} else if (device == "HPN30_107") {
|
||||
equipment = "HV Detectors";
|
||||
starti = 29;
|
||||
endi = 29;
|
||||
} else if (device == "APD") {
|
||||
equipment = "HV Detectors";
|
||||
starti = 30;
|
||||
endi = 93;
|
||||
} else if (device == "hvr80flame") {
|
||||
equipment = "hvr80flame0";
|
||||
starti = 0;
|
||||
endi = 31;
|
||||
}
|
||||
|
||||
// Set correct odb paths
|
||||
var names = "/Equipment/" + equipment + "/Settings/Names";
|
||||
var currlimit = "/Equipment/" + equipment + "/Settings/Current Limit";
|
||||
var vardemand = "/Equipment/" + equipment + "/Variables/Demand";
|
||||
|
||||
var doc = document.implementation.createDocument("http://nemu.web.psi.ch/HV", "", null);
|
||||
var HVElem = doc.createElement("HV");
|
||||
|
||||
var commElem = doc.createElement("comment");
|
||||
var commtext = doc.createTextNode("this is a comment");
|
||||
commElem.appendChild(commtext);
|
||||
HVElem.appendChild(commElem);
|
||||
|
||||
var descElem = doc.createElement("description");
|
||||
var desctext = doc.createTextNode("this is a description");
|
||||
descElem.appendChild(desctext);
|
||||
HVElem.appendChild(descElem);
|
||||
|
||||
var devElem = doc.createElement("hvDeviceName");
|
||||
var devtext = doc.createTextNode(device);
|
||||
devElem.appendChild(devtext);
|
||||
HVElem.appendChild(devElem);
|
||||
|
||||
for (let i = starti; i < endi + 1; i++) {
|
||||
var odbPaths = [names + "[" + i + "]", vardemand + "[" + i + "]", currlimit + "[" + i + "]"];
|
||||
//console.log(odbPaths);
|
||||
mjsonrpc_db_get_values(odbPaths).then(function (rpc) {
|
||||
odbname = rpc.result.data[0].split("%")[1];
|
||||
odbdemand = Math.round(rpc.result.data[1] * 1000) / 1000;
|
||||
odblimit = rpc.result.data[2];
|
||||
//console.log(odbname,odbdemand,odblimit);
|
||||
|
||||
var hvCh = doc.createElement("hvCh");
|
||||
var chNo = doc.createElement("chNo");
|
||||
var i_Order = doc.createTextNode(i + 1);
|
||||
chNo.appendChild(i_Order);
|
||||
hvCh.appendChild(chNo);
|
||||
var name = doc.createElement("name");
|
||||
var namei = doc.createTextNode(odbname);
|
||||
name.appendChild(namei);
|
||||
hvCh.appendChild(name);
|
||||
var hvDem = doc.createElement("hvDemand");
|
||||
var demi = doc.createTextNode(odbdemand);
|
||||
hvDem.appendChild(demi);
|
||||
hvCh.appendChild(hvDem);
|
||||
var curLim = doc.createElement("currentLimit");
|
||||
var limi = doc.createTextNode(odblimit);
|
||||
curLim.appendChild(limi);
|
||||
hvCh.appendChild(curLim);
|
||||
hvCh.setAttribute("name", odbname);
|
||||
HVElem.appendChild(hvCh);
|
||||
}).catch(function (error) { console.error(error); });
|
||||
}
|
||||
|
||||
// HVElem.appendChild(personElem2);
|
||||
doc.appendChild(HVElem);
|
||||
console.log(doc);
|
||||
var serializer = new XMLSerializer();
|
||||
var xmlStr = serializer.serializeToString(doc);
|
||||
xmlStr = '<?xml version="1.0" encoding="ISO-8859-1"?>\n' + xmlStr;
|
||||
|
||||
console.log(xmlStr);
|
||||
download(xmlStr, "text.xml", "text/plain");
|
||||
|
||||
}
|
||||
|
||||
// Function to download data to a file
|
||||
function download(data, filename, type) {
|
||||
var file = new Blob([data], { type: type });
|
||||
const file = new Blob([data], { type: type });
|
||||
if (window.navigator.msSaveOrOpenBlob) // IE10+
|
||||
window.navigator.msSaveOrOpenBlob(file, filename);
|
||||
else { // Others
|
||||
var a = document.createElement("a");
|
||||
const a = document.createElement("a");
|
||||
url = URL.createObjectURL(file);
|
||||
a.href = url;
|
||||
a.download = filename;
|
||||
@@ -593,42 +490,6 @@ function download(data, filename, type) {
|
||||
}
|
||||
}
|
||||
|
||||
// Function to load ODB json file from server
|
||||
function serverBLSet(file) {
|
||||
// force to reload file
|
||||
file = file.replace(/^\/+/, "") + "?" + Date.now();;
|
||||
fetch(file).then(response => response.json()).then(data => {
|
||||
// `data` contains the parsed JSON object
|
||||
const path = data["/ODB path"];
|
||||
const names = data.Settings.Names;
|
||||
const demands = data.Variables.Demand;
|
||||
|
||||
// Create preload table
|
||||
var table = "<table><tr><td>";
|
||||
table += "<table style='border: 3px;'>\n";
|
||||
for (let i = 0; i < names.length; i++) {
|
||||
let name = names[i];
|
||||
let demand = demands[i];
|
||||
|
||||
table += "<tr>\n";
|
||||
table += "<td id='" + name + "'>" + name + "</td>\n";
|
||||
table += "<td class='tdIgnorable' onclick='toggle_color(this);'><input class='demandVal' type='number' style='width:5em' id='" + name + "d' value='" + demand + "'> ☓ </td>\n";
|
||||
table += "</tr>\n";
|
||||
}
|
||||
table += "</table></td>\n";
|
||||
table += "<td style='width:50%;vertical-align:top;'><div class='tdIgnored'>Highlight ( ☓ ) cell to ignore.</div></td></tr></table>";
|
||||
|
||||
// Show table in dialog
|
||||
populate_modal("popPrompt");
|
||||
document.getElementById("popHTML").innerHTML = table;
|
||||
document.getElementById("popButton").textContent = "Load";
|
||||
document.getElementById("popButton").addEventListener("click", load_bl);
|
||||
document.getElementById("popButton").addEventListener("click", closeModal);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
// Function to load standard HV setting from server
|
||||
function serverHVSet(filename) {
|
||||
if (!filename) {
|
||||
@@ -640,6 +501,12 @@ function serverHVSet(filename) {
|
||||
let table = xml_to_table(content);
|
||||
populate_modal("popPrompt");
|
||||
document.getElementById("popHTML").innerHTML = table;
|
||||
document.getElementById("popHTML").addEventListener("click", event => {
|
||||
const cell = event.target.closest(".tdIgnorable, .tdIgnored");
|
||||
if (cell) {
|
||||
toggle_color(cell);
|
||||
}
|
||||
});
|
||||
document.getElementById("popButton").textContent = "Load";
|
||||
document.getElementById("popButton").addEventListener("click", loadHV);
|
||||
document.getElementById("popButton").addEventListener("click", closeModal);
|
||||
|
||||
Reference in new issue
Block a user