diff options
author | Mantas Vilčinskas <hi@mnts.lt> | 2021-03-06 16:01:11 +0200 |
---|---|---|
committer | Mantas Vilčinskas <hi@mnts.lt> | 2021-03-06 16:01:11 +0200 |
commit | d64bfe770d5ccb46c6ca7fb07c90a1ce03b40f13 (patch) | |
tree | 275d3f196669282b3d6f7ce172f23385db8ea26f /layouts/partials/index | |
parent | 9bbc616c7328ff0fd205b0bbb6f8b0ba2855fb6f (diff) |
fix #101 - add category status, #161 ref in config.yml
Diffstat (limited to 'layouts/partials/index')
-rw-r--r-- | layouts/partials/index/components.html | 64 |
1 files changed, 51 insertions, 13 deletions
diff --git a/layouts/partials/index/components.html b/layouts/partials/index/components.html index 82964fe..acb1aa7 100644 --- a/layouts/partials/index/components.html +++ b/layouts/partials/index/components.html @@ -10,18 +10,8 @@ {{ $systems := .Site.Params.systems }} {{ $categories := .Site.Params.categories }} - <script> - function toggleCategoryHead(el) { - if (el.parentNode.className == 'category category--open') { - el.parentNode.className = 'category category--closed'; - } else { - el.parentNode.className = 'category category--open'; - } - } - </script> - {{ range $categories }} - <div class="category {{ if .closed }}category--closed{{ else }}category--open{{ end }}" id="{{ .name | urlize }}"> + <div class="category {{ if .closed }}category--closed{{ else }}category--open{{ end }}{{ if not .untitled }} category--titled{{ end }}" id="{{ .name | urlize }}"> {{ if not .untitled }} <div class="bold padding clicky category__head" onclick="toggleCategoryHead(this)"> <span class="hide-without-js"> @@ -42,6 +32,8 @@ </span> </span> {{ end }} + + <span class="category-status"></span> </div> {{ else }} @@ -94,8 +86,54 @@ {{ end }} </div> {{ end }} - </div> + </div> + + <!-- + Get category status + --> + <script> + // We will look at all components in one category + thisCategory = document.currentScript.parentNode + + componentsOfThisCategory = thisCategory.querySelectorAll('.component') + + // We will cycle through all components and show + // the worst status found + // + // By default, all is good but we change this value + // for progressively worse statuses + var highlestLevelStatus = ''; + + function checkStatus(element) { + var status = element.getAttribute('data-status'); + + if (status === 'down') { + highlestLevelStatus = 'down' + } else if (status === 'disrupted' && highlestLevelStatus !== 'down') { + highlestLevelStatus = 'disrupted' + } else if (status === 'notice' && highlestLevelStatus !== 'down' && highlestLevelStatus !== 'disrupted') { + highlestLevelStatus = 'notice' + } + } + + componentsOfThisCategory.forEach(element => checkStatus(element)); + + // Human readable (i18n) status name variable + var highlestLevelStatusReadable = highlestLevelStatus; + + if (highlestLevelStatus === 'ok') { highlestLevelStatusReadable = '{{ T "thisIsOk" }}' } + if (highlestLevelStatus === 'notice') { highlestLevelStatusReadable = '{{ T "thisIsNotice" }}' } + if (highlestLevelStatus === 'dsirupted') { highlestLevelStatusReadable = '{{ T "thisIsDisrupted" }}' } + if (highlestLevelStatus === 'down') { highlestLevelStatusReadable = '{{ T "thisIsDown" }}' } + + // Finally we can show the status + // (but only for categories with a name) + if (thisCategory.classList.contains('category--titled')) { + thisCategory.querySelector('.category__head').setAttribute('data-status', highlestLevelStatus); + thisCategory.querySelector('.category-status').innerHTML = highlestLevelStatusReadable; + } + </script> </div> {{ end }} -</div> +</div>
\ No newline at end of file |