Custom Page: Difference between revisions

From MidasWiki
Jump to navigation Jump to search
Line 58: Line 58:


* The functions hide details about the underlying MjsonRPC calls, which should allow a novice to write pretty and sophisticated custom pages quicker.
* The functions hide details about the underlying MjsonRPC calls, which should allow a novice to write pretty and sophisticated custom pages quicker.
* The functions ensure that all the periodic updates of the ODB value (and other MIDAS information) is done in a single MjsonRPC batch call, which should ensure optimal page loading speed.
* The functions ensure that all the periodic updates of the ODB value (and other MIDAS information) are done in a single MjsonRPC batch call, which should ensure optimal page loading speed.


It is also possible for users to write their custom pages using only the underlying [[Mjsonrpc | MjsonRPC library]] calls, but they then need to ensure on their own that the page loading remains efficient.  In particular, if you combine the standard MIDAS navigation bars (described in next section) with your own  
It is also possible for users to write their custom pages using only the underlying [[Mjsonrpc | MjsonRPC library]] calls, but they then need to ensure on their own that the page loading remains efficient.  In particular, if you combine the standard MIDAS navigation bars (described in next section) with your own  

Revision as of 11:58, 21 December 2017


Links


Purpose

A user-created mhttpd Custom Web Page accessible from the Status Page allows the user additional flexibility. For example, a custom page may present the essential parameters of the controlled experiment in a more compact way. A custom page may even replace the default Status Page.

Introduction

Custom web pages provide the user with a means of creating secondary user-created web page(s) activated within the standard MIDAS web interface. These custom pages usually display ODB parameters or data to the user. They can contain specific links to the ODB so the user may also input information relevant to the experiment. Users create Custom Pages when the standard pages do not meet their requirements completely.

We note that MIDAS has provided a number of different ways of providing custom pages over the years. A new scheme of custom pages making use of modern HTML5 techniques has been introduced in 2017. This page will mostly only be providing documentation for the new scheme of custom pages.

Examples of Custom Pages

Click on the thumbnails to enlarge.

Figure 1: MEG Gas System
Example 1
This page (Figure 1) from the MEG experiment at PSI shows a complex gas system. This shows the use of "fills" and "labels". Open valves are represented as green circles, closed valves as red circles. If, for example, an open valve is clicked, the valve closes, and the circle turns red (provided the user successfully supplied the correct password).
Figure 2: ROOT Analyzer (MEG Experiment)
Example 2
Many MIDAS experiments work with ROOT based analyzers today. One problem is that the graphical output of the root analyzer can only be seen through the X server and not through the web. At the MEG experiment, this problem was solved in an elegant way: The ROOT analyzer runs in the background, using a "virtual" X server called Xvfb. It plots its output (several panels) normally using this X server, then saves this panels every ten seconds into GIF files. These GIF files are then served through mhttpd using a custom page. The output is shown in Figure 2.

The buttons on the left sides are actually HTML buttons on that custom page overlaid to the GIF image, which in this case shows one of the 800 PMT channels digitized at 1.6 GSPS. With these buttons one can cycle through the different GIF images, which then automatically update ever ten seconds. Of course it is not possible to feed interaction back to the analyzer (i.e. the waveform cannot be fitted interactively) but for monitoring an experiment in production mode this tool is extremely helpful, since it is seamlessly integrated into mhttpd. All the magic is done with JavaScript, and the buttons are overlaid on the graphics using CSS with absolute positioning. The analysis ratio on the top right is also done with JavaScript accessing the required information from the ODB.

For details using Xvfb server, please contact Ryu Sawada <sawada@icepp.s.u-tokyo.ac.jp>.


Figure 3: SCB Setup (Deap Experiment)
Example 3
This custom page from the Deap Experiment (Figure 3) allows the users to easily set individual channels, or a group of channels, or all channels of the SCB modules to a particular value.



Access a Custom Page from the Regular MIDAS pages

Access to a Custom Page is set up through the /Custom ODB tree (see custom-link). This associates a custom page file on the disk with a button on the status page. Clicking on the resulting custom-button on the mhttpd Status Page will display that custom page.

For example, if the key /Custom/myPage& (see Note) is created, and the contents contains the path of a custom page file on the disk, e.g.

odbedit> ls /Custom/myPage&
   myPage&                           /home/midas/online/expt/custom/test.html

the custom-button will be myPage and the URL for the resulting custom page will be of the form http://myhost.mydomain:myport/CS/myPage (see also mhttpd#usage). Pressing myPage will display the custom page in the same window.

Note
Without the "&" symbol in the key name, the page would appear in a new window. See Key names for more information.

How to write a custom page

A custom page is usually written in a combination of HTML and Javascript. It can contain any of the Custom Page Features, e.g. include images with labelled with ODB values and areas coloured according to ODB values using fills. A Javascript MjsonRPC Library has been written to provide access to the ODB and other functions.

In what follows, we describe a scheme for writing custom pages with the set of mod* javascript functions. The advantages of using these mod* javascript functions are

  • The functions hide details about the underlying MjsonRPC calls, which should allow a novice to write pretty and sophisticated custom pages quicker.
  • The functions ensure that all the periodic updates of the ODB value (and other MIDAS information) are done in a single MjsonRPC batch call, which should ensure optimal page loading speed.

It is also possible for users to write their custom pages using only the underlying MjsonRPC library calls, but they then need to ensure on their own that the page loading remains efficient. In particular, if you combine the standard MIDAS navigation bars (described in next section) with your own MjsonRPC calls then you will probably need at least two separate RPC calls to populate the custom page (instead of one call).

How to use the standard MIDAS navigation bars on your custom page

If you want to have your custom page use the same header and navigation bars as the standard MIDAS pages, you need to use the following syntax

<!DOCTYPE html>
<html class="mcss">
<head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="midas.css">
   <script src="controls.js"></script>
   <script src="midas.js"></script>
   <script src="mhttpd.js"></script>
   <title>Example</title>
</head>

<body class="mcss" onload="mhttpd_init('Test');">

<!-- header and side navigation will be filled in mhttpd_start -->
<div id="mheader"></div>
<div id="msidenav"></div>

<div id="mmain">
 ADD YOUR HTML/JS  CODE here...
</div>

For the call mhttpd_init('name') on page load, name is the name of the page shown on the left menu bar. This syntax will allow you to use the standard MIDAS navigation whether you are using the mod* functions or the underlying javascript libraries.

Complete Example

The following code shows an example page (contained in resources/a_example.html in the MIDAS distribution) of a custom page implementing most of the new features. You activate this page by putting in the ODB:

/Custom
  Path     /midas/resources
  Test     a_example.html

Code

The file a_example.html contains the following code:

<!DOCTYPE html>
<html class="mcss">
<head>
   <meta charset="UTF-8">
   <link rel="stylesheet" href="midas.css">
   <script src="controls.js"></script>
   <script src="midas.js"></script>
   <script src="mhttpd.js"></script>
   <title>Example</title>
</head>

<body class="mcss" onload="mhttpd_init('Test');">

<!-- header and side navigation will be filled in mhttpd_start -->
<div id="mheader"></div>
<div id="msidenav"></div>

<div id="mmain">
   <table class="mtable">
      <tr>
         <th colspan="2" class="mtableheader">Status</th>
      </tr>
      <tr>
         <td style="width: 200px;">
            Run number:
         </td>
         <td>
            <div name="modbvalue" data-odb-path="/Runinfo/Run number" data-odb-editable="1"></div>
         </td>
      </tr>
      <tr>
         <td>
            Last run start:
         </td>
         <td>
            <div name="modbvalue" data-odb-path="/Runinfo/Start time"></div>
         </td>
      </tr>
      <tr>
         <td>
            Last run stop:
         </td>
         <td>
            <div name="modbvalue" data-odb-path="/Runinfo/Stop time"></div>
         </td>
      </tr>
      <tr>
         <td>
            Check box:
         </td>
         <td>
            <input type="checkbox" name="modbcheckbox" data-odb-path="/Logger/Write data"></input>
         </td>
      </tr>
      <tr>
         <td>
            Color box:
         </td>
         <td>
            <div name="modbbox" style="width: 30px; height: 30px;" data-odb-path="/Logger/Write data"
                 data-color="lightgreen" data-background-color="red"></div>
         </td>
      </tr>
      <tr>
         <td>
            Horizontal bars:
         </td>
         <td>
            <div name="modbhbar" style="width: 500px; height: 18px;" data-odb-path="/Runinfo/Run number" data-max-value="10"
                 data-color="lightgreen" data-value="0"></div><br /><br />
            <div name="modbhbar" style="width: 200px; height: 10px;" data-odb-path="/Runinfo/Run number" data-max-value="10"
                 data-color="green" data-value="0"></div>
         </td>
      </tr>
      <tr>
         <td>
            Vertical bars:
         </td>
         <td>
            <div name="modbvbar" style="width:20px;height:100px;" data-odb-path="/Runinfo/Run number" data-min-value="4" data-max-value="20"
                 data-color="lightgreen"></div>
            <div name="modbvbar" style="width:10px;height:100px;" data-odb-path="/Runinfo/Run number" data-max-value="10"
                 data-color="red"></div>
         </td>
      </tr>

      <tr>
         <td>
            Thermometer:
         </td>
         <td>
            <div name="modbthermo" style="width:30px;height:100px;" data-odb-path="/Runinfo/Run number" data-min-value="-10" data-max-value="30"
                 data-color="darkgreen"></div>
            <div name="modbthermo" style="width:60px;height:100px;" data-odb-path="/Runinfo/Run number" data-min-value="-10" data-max-value="30"
                 data-color="blue" data-scale="1"
                 onchange="this.dataset.color=this.value > 9?'red':'blue';"></div>
            <div name="modbthermo" style="width:30px;height:100px;" data-odb-path="/Runinfo/Run number" data-min-value="-10" data-max-value="30"
                 data-color="blue" data-background-color="white" data-value="1"></div>
         </td>
      </tr>

      <tr>
         <td>
            Gauges:
         </td>
         <td>
            <div name="modbgauge" style="width:100px;height:50px;" data-odb-path="/Runinfo/Run number" data-min-value="0" data-max-value="10"
                 data-color="darkgreen" data-background-color="lightgrey" ></div>
            <div name="modbgauge" style="width:100px;height:65px;" data-odb-path="/Runinfo/Run number" data-min-value="0" data-max-value="10"
                 data-color="red" data-value="1" data-scale="1"></div>
         </td>
      </tr>

      <tr>
         <td colspan="2" style="text-align: center;">
            <!-- div around image with "relative" position as anchor for labels and bars -->
            <div style="position:relative;width:300px;margin:auto">

               <img src="tank.gif"> <!-- background image of tank -->

               <!-- label next to valve -->
               <div name="modbvalue" data-odb-path="/Runinfo/Run number" data-odb-editable="1"
                    style="position:absolute;top:157px;left:288px;"></div>

               <!-- vertical bar inside tank, render red if value > 9 -->
               <div name="modbvbar" style="position:absolute;top:80px;left:10px;width:104px;height:170px;"
                    data-odb-path="/Runinfo/Run number" data-max-value="11" data-color="green"
                    onchange="this.firstChild.style.backgroundColor=(this.value > 9)?'red':'green';"></div>

               <!-- thermometer inside tank -->
               <div name="modbthermo" style="position:absolute;top:140px;left:20px;width:20px;height:100px;"
                    data-odb-path="/Runinfo/Run number" data-min-value="-10" data-max-value="30"
                    data-color="blue" data-value="1"></div>

            </div>
         </td>
      </tr>

      <tr>
         <td colspan="2" style="text-align: center;">
            <button name="modbbutton" class="mbutton" data-odb-path="/Runinfo/Run number" data-odb-value="1">Set run
               number to 1
            </button>
            </button>
            <button name="modbbutton" class="mbutton" data-odb-path="/Runinfo/Run number" data-odb-value="5">Set run
               number to 5
            </button>
            </button>
            <button name="modbbutton" class="mbutton" data-odb-path="/Runinfo/Run number" data-odb-value="10">Set run
               number to 10
            </button>
            </button>
         </td>
      </tr>
   </table>
</div>

</body>
</html>

which results in the page shown in Figure 1 below.

Figure 1 Example custom page using new (2017) features

Custom17.png

Old custom page feature

There are a number of deprecated custom page features, which can be seen here: Old Custom Page Features.