This is an automated email from the ASF dual-hosted git repository. sebb pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/whimsy.git
The following commit(s) were added to refs/heads/master by this push: new eccb8c58 Get notice details from Status.notice eccb8c58 is described below commit eccb8c58fba576f7bae3da9f9429e57e2569f8ae Author: Sebb <s...@apache.org> AuthorDate: Sat Mar 15 23:07:40 2025 +0000 Get notice details from Status.notice --- www/getnotice.cgi | 18 ++++++++++++++++++ www/index.html | 40 ++++++++++++---------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/www/getnotice.cgi b/www/getnotice.cgi new file mode 100755 index 00000000..b5a2c9f0 --- /dev/null +++ b/www/getnotice.cgi @@ -0,0 +1,18 @@ +#!/usr/bin/env ruby + +# Provide access to Status.notice method from Javascript + +$LOAD_PATH.unshift '/srv/whimsy/lib' + +require 'wunderbar' +require 'whimsy/asf/status' + +noticetext, noticepath, noticeclass = Status.notice + +_json do + if noticetext + {noticetext: noticetext, noticepath: noticepath, noticeclass: noticeclass} + else + {noticetext: nil} + end +end diff --git a/www/index.html b/www/index.html index d5fa2ba6..b51049b1 100644 --- a/www/index.html +++ b/www/index.html @@ -20,40 +20,24 @@ } </style> <script> - // TODO: replace with interface to Status.notice? - const notice = '/notice.txt' + const notice = '/getnotice.cgi' fetch(notice) .then(response => { - console.log(response); if (response.ok) { - return response.text(); + return response.json(); } + return {}; }) - .then(data => { - const noticeDiv = document.getElementById('notice'); - text = data.split('\n',2)[0]; // first line - link = document.createElement('a'); - link.text = text; - link.href = notice; - pfx = text.split(':',2)[0]; - // These classes should agree with Status.notice - switch (pfx) { - case 'DANGER': - case 'BEWARE': - classes = "h3 bg-danger"; - break; - case 'WARNING': - classes = "h3 bg-warning"; - break; - case 'INFO': - classes = "h3 bg-info"; - break; - default: - classes = "h3 bg-light"; - break; + .then(jzon => { + noticetext = jzon['noticetext']; + if (noticetext) { + const noticeDiv = document.getElementById('notice'); + link = document.createElement('a'); + link.text = noticetext; + link.href = jzon['noticepath']; + noticeDiv.classList = `h3 ${jzon['noticeclass']}`; + noticeDiv.append(link); } - noticeDiv.classList = classes; - noticeDiv.append(link); }); </script> </head>