Skip to content

Instantly share code, notes, and snippets.

@n-a-t-e
Last active November 3, 2022 18:26
Show Gist options
  • Save n-a-t-e/940fd12fc0abe8626f5972bca88d8d97 to your computer and use it in GitHub Desktop.
Save n-a-t-e/940fd12fc0abe8626f5972bca88d8d97 to your computer and use it in GitHub Desktop.
erddap compliance link

ERDDAP link to compliance results from datasets pages

This is how I added a link from ERDDAP dataset pages to the results of the IOOS Compliance checker for that page.

Example: https://data.cioospacific.ca/erddap/tabledap/BCSOP_daily.html, see "Compliance Results" link in top right corner

Editing erddap's setup.xml file, this goes in <startHeadHtml5>/<head>:

<script>
     
      // Show an element
      var show = function (elem) {
          elem.style.display = 'block';
      };

      // Hide an element
      var hide = function (elem) {
          elem.style.display = 'none';
      };

      document.addEventListener("DOMContentLoaded", function () {
          const datasetID = location.href.split('/').pop().split('.')[0];
          const hostname = location.hostname;

          // Show this link only on dataset pages
          // Note: This doesn't include the metadata page (yet)
          const reg = new RegExp('/erddap/(table|grid)dap/([^.]+)\.(html|subset|graph)');

          const a = document.getElementById('complianceLink');

          // These pages match the url of regular dataset pages. 
          // Hope there are no datasets named "index"
          const notDatasets = ['allDatasets', 'index']

          const showComplianceLink = (reg.test(location.href) && !notDatasets.includes(datasetID))

          const url = "https://cioos-siooc.github.io/erddap-compliance-runner/" + hostname + "/" +
              datasetID +
              ".html";

          if (showComplianceLink) {
              a.href = url;
              show(a)
          } else {
              hide(a)
          }



      });
  </script>

This goes wherever you want it in the section:

<a id="complianceLink" href="" style="display:none">Compliance Results</a>

See these links for more info: https://github.com/cioos-siooc/erddap-compliance-runner

https://github.com/cioos-siooc/erddap-compliance

https://github.com/ioos/compliance-checker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment