From b02cbdfad9710662ca9b2e543952cee36f74b7cd Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Wed, 1 Sep 2021 15:48:51 +0200 Subject: [PATCH 1/6] Implement news webhook to handle release announcements --- config/plugins/webhooks/news/config.yml | 7 ++ config/plugins/webhooks/news/script.js | 103 ++++++++++++++++++++++++ config/plugins/webhooks/news/styles.css | 28 +++++++ 3 files changed, 138 insertions(+) create mode 100644 config/plugins/webhooks/news/config.yml create mode 100644 config/plugins/webhooks/news/script.js create mode 100644 config/plugins/webhooks/news/styles.css diff --git a/config/plugins/webhooks/news/config.yml b/config/plugins/webhooks/news/config.yml new file mode 100644 index 00000000000..9c35b671c8c --- /dev/null +++ b/config/plugins/webhooks/news/config.yml @@ -0,0 +1,7 @@ +id: news +type: + - masthead +activate: true + +icon: fa-bell +tooltip: See the Galaxy Release Notes diff --git a/config/plugins/webhooks/news/script.js b/config/plugins/webhooks/news/script.js new file mode 100644 index 00000000000..0931a9f5c49 --- /dev/null +++ b/config/plugins/webhooks/news/script.js @@ -0,0 +1,103 @@ +function removeNewsOverlay() { + document.getElementById("news-container").style.visibility = "hidden"; +} + +function showNewsOverlay() { + document.getElementById("news-container").style.visibility = "visible"; + newsSeen(); +} + +function newsSeen() { + var el = document.getElementById("news-unseen-pip"); + el.parentNode.removeChild(el); + window.localStorage.setItem( + "galaxy-news-seen-release", + Galaxy.config.version_major + ); +} + +function newsUnseen() { + let econtainer = document.getElementById("news").children[0]; + econtainer.insertAdjacentHTML( + "beforeend", + ` + + ` + ); +} + +function addNewsIframe() { + let currentGalaxyVersion = Galaxy.config.version_major; + let releaseNotes = `https://docs.galaxyproject.org/en/master/releases/${currentGalaxyVersion}_announce_user.html`; + let lastSeenVersion = window.localStorage.getItem("galaxy-news-seen-release"); + // Check that they've seen the current version's release notes. + if (lastSeenVersion != currentGalaxyVersion) { + newsUnseen(); + } + + document.querySelector("body.full-content").insertAdjacentHTML( + "afterbegin", + ` + ` + ); + + // Clicking outside of GTN closes it + document.getElementById("news-screen").addEventListener("click", () => { + removeNewsOverlay(); + }); +} + +/* The masthead icon may not exist yet when this webhook executes; we need this to wait for that to happen. + * elementReady function from gist: + * https://gist.github.com/jwilson8767/db379026efcbd932f64382db4b02853e + */ +function elementReadyNews(selector) { + return new Promise((resolve, reject) => { + let el = document.querySelector(selector); + if (el) { + resolve(el); + } + new MutationObserver((mutationRecords, observer) => { + // Query for elements matching the specified selector + Array.from(document.querySelectorAll(selector)).forEach(element => { + resolve(element); + //Once we have resolved we don't need the observer anymore. + observer.disconnect(); + }); + }).observe(document.documentElement, { + childList: true, + subtree: true + }); + }); +} + +elementReadyNews("#news a").then(el => { + // External stuff may also have attached a click handler here (vue-based masthead) + // replace with a clean copy of the node to remove all that cruft. + clean = el.cloneNode(true); + el.parentNode.replaceChild(clean, el); + + // This gets added by default. + addNewsIframe(); + + clean.addEventListener("click", e => { + e.preventDefault(); + e.stopPropagation(); + showNewsOverlay(); + }); +}); + +// Remove the overlay on escape button click +document.addEventListener("keydown", e => { + // Check for escape button - "27" + if (e.which === 27 || e.keyCode === 27) { + removeNewsOverlay(); + } +}); diff --git a/config/plugins/webhooks/news/styles.css b/config/plugins/webhooks/news/styles.css new file mode 100644 index 00000000000..7ac3231209d --- /dev/null +++ b/config/plugins/webhooks/news/styles.css @@ -0,0 +1,28 @@ +#news-screen { + position: fixed; + z-index: 202; + width:100%; + height:100%; +} + +#news-screen-overlay { + position: fixed; + top:0; + left:0; + background: rgba(224, 224, 224, 0.75); + z-index: 201; + width:100%; + height:100%; + opacity: 2; +} + +#news-header { + position: fixed; + height: 100%; + width: 100%; + z-index: 203; + display: flex; + justify-content: center; + flex-direction: column; + align-items: center; +} From b5b4af7a24588f64a87ba2b173ef09f0176afb9c Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 2 Sep 2021 08:18:37 -0400 Subject: [PATCH 2/6] Use fontawesome-regular to show no notifications --- config/plugins/webhooks/news/script.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/config/plugins/webhooks/news/script.js b/config/plugins/webhooks/news/script.js index 0931a9f5c49..457ff90552a 100644 --- a/config/plugins/webhooks/news/script.js +++ b/config/plugins/webhooks/news/script.js @@ -8,8 +8,10 @@ function showNewsOverlay() { } function newsSeen() { - var el = document.getElementById("news-unseen-pip"); - el.parentNode.removeChild(el); + // When it's seen, remove fa and far, add fas. + const newsIconSpan = document.getElementById("news").querySelector(".fa-bell") + newsIconSpan.classList.remove("fa"); + newsIconSpan.classList.add("far"); window.localStorage.setItem( "galaxy-news-seen-release", Galaxy.config.version_major @@ -17,13 +19,10 @@ function newsSeen() { } function newsUnseen() { - let econtainer = document.getElementById("news").children[0]; - econtainer.insertAdjacentHTML( - "beforeend", - ` - - ` - ); + // When there is news, set far instead of fa + const newsIconSpan = document.getElementById("news").querySelector(".fa-bell") + newsIconSpan.classList.remove("far"); + newsIconSpan.classList.add("fa"); } function addNewsIframe() { @@ -33,6 +32,8 @@ function addNewsIframe() { // Check that they've seen the current version's release notes. if (lastSeenVersion != currentGalaxyVersion) { newsUnseen(); + } else { + newsSeen(); } document.querySelector("body.full-content").insertAdjacentHTML( From 33c64034dc38438402c1b3508c8e06fadbab92e9 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 2 Sep 2021 08:19:43 -0400 Subject: [PATCH 3/6] Cleanup --- config/plugins/webhooks/news/script.js | 127 ++++++++++++------------- 1 file changed, 62 insertions(+), 65 deletions(-) diff --git a/config/plugins/webhooks/news/script.js b/config/plugins/webhooks/news/script.js index 457ff90552a..d506b527669 100644 --- a/config/plugins/webhooks/news/script.js +++ b/config/plugins/webhooks/news/script.js @@ -1,44 +1,41 @@ function removeNewsOverlay() { - document.getElementById("news-container").style.visibility = "hidden"; + document.getElementById("news-container").style.visibility = "hidden"; } function showNewsOverlay() { - document.getElementById("news-container").style.visibility = "visible"; - newsSeen(); + document.getElementById("news-container").style.visibility = "visible"; + newsSeen(); } function newsSeen() { - // When it's seen, remove fa and far, add fas. - const newsIconSpan = document.getElementById("news").querySelector(".fa-bell") - newsIconSpan.classList.remove("fa"); - newsIconSpan.classList.add("far"); - window.localStorage.setItem( - "galaxy-news-seen-release", - Galaxy.config.version_major - ); + // When it's seen, remove fa and far, add fas. + const newsIconSpan = document.getElementById("news").querySelector(".fa-bell"); + newsIconSpan.classList.remove("fa"); + newsIconSpan.classList.add("far"); + window.localStorage.setItem("galaxy-news-seen-release", Galaxy.config.version_major); } function newsUnseen() { - // When there is news, set far instead of fa - const newsIconSpan = document.getElementById("news").querySelector(".fa-bell") - newsIconSpan.classList.remove("far"); - newsIconSpan.classList.add("fa"); + // When there is news, set far instead of fa + const newsIconSpan = document.getElementById("news").querySelector(".fa-bell"); + newsIconSpan.classList.remove("far"); + newsIconSpan.classList.add("fa"); } function addNewsIframe() { - let currentGalaxyVersion = Galaxy.config.version_major; - let releaseNotes = `https://docs.galaxyproject.org/en/master/releases/${currentGalaxyVersion}_announce_user.html`; - let lastSeenVersion = window.localStorage.getItem("galaxy-news-seen-release"); - // Check that they've seen the current version's release notes. - if (lastSeenVersion != currentGalaxyVersion) { - newsUnseen(); - } else { - newsSeen(); - } + const currentGalaxyVersion = Galaxy.config.version_major; + const releaseNotes = `https://docs.galaxyproject.org/en/master/releases/${currentGalaxyVersion}_announce_user.html`; + const lastSeenVersion = window.localStorage.getItem("galaxy-news-seen-release"); + // Check that they've seen the current version's release notes. + if (lastSeenVersion != currentGalaxyVersion) { + newsUnseen(); + } else { + newsSeen(); + } - document.querySelector("body.full-content").insertAdjacentHTML( - "afterbegin", - ` + document.querySelector("body.full-content").insertAdjacentHTML( + "afterbegin", + ` ` - ); + ); - // Clicking outside of GTN closes it - document.getElementById("news-screen").addEventListener("click", () => { - removeNewsOverlay(); - }); + // Clicking outside of GTN closes it + document.getElementById("news-screen").addEventListener("click", () => { + removeNewsOverlay(); + }); } /* The masthead icon may not exist yet when this webhook executes; we need this to wait for that to happen. @@ -60,45 +57,45 @@ function addNewsIframe() { * https://gist.github.com/jwilson8767/db379026efcbd932f64382db4b02853e */ function elementReadyNews(selector) { - return new Promise((resolve, reject) => { - let el = document.querySelector(selector); - if (el) { - resolve(el); - } - new MutationObserver((mutationRecords, observer) => { - // Query for elements matching the specified selector - Array.from(document.querySelectorAll(selector)).forEach(element => { - resolve(element); - //Once we have resolved we don't need the observer anymore. - observer.disconnect(); - }); - }).observe(document.documentElement, { - childList: true, - subtree: true + return new Promise((resolve, reject) => { + const el = document.querySelector(selector); + if (el) { + resolve(el); + } + new MutationObserver((mutationRecords, observer) => { + // Query for elements matching the specified selector + Array.from(document.querySelectorAll(selector)).forEach((element) => { + resolve(element); + //Once we have resolved we don't need the observer anymore. + observer.disconnect(); + }); + }).observe(document.documentElement, { + childList: true, + subtree: true, + }); }); - }); } -elementReadyNews("#news a").then(el => { - // External stuff may also have attached a click handler here (vue-based masthead) - // replace with a clean copy of the node to remove all that cruft. - clean = el.cloneNode(true); - el.parentNode.replaceChild(clean, el); +elementReadyNews("#news a").then((el) => { + // External stuff may also have attached a click handler here (vue-based masthead) + // replace with a clean copy of the node to remove all that cruft. + clean = el.cloneNode(true); + el.parentNode.replaceChild(clean, el); - // This gets added by default. - addNewsIframe(); + // This gets added by default. + addNewsIframe(); - clean.addEventListener("click", e => { - e.preventDefault(); - e.stopPropagation(); - showNewsOverlay(); - }); + clean.addEventListener("click", (e) => { + e.preventDefault(); + e.stopPropagation(); + showNewsOverlay(); + }); }); // Remove the overlay on escape button click -document.addEventListener("keydown", e => { - // Check for escape button - "27" - if (e.which === 27 || e.keyCode === 27) { - removeNewsOverlay(); - } +document.addEventListener("keydown", (e) => { + // Check for escape button - "27" + if (e.which === 27 || e.keyCode === 27) { + removeNewsOverlay(); + } }); From 5c78a7912357c5e4cd5b6c249d915831bfb415a6 Mon Sep 17 00:00:00 2001 From: Dannon Baker Date: Thu, 2 Sep 2021 08:52:06 -0400 Subject: [PATCH 4/6] Had my comments backwards, simplify selector --- config/plugins/webhooks/news/script.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/config/plugins/webhooks/news/script.js b/config/plugins/webhooks/news/script.js index d506b527669..86727ad8793 100644 --- a/config/plugins/webhooks/news/script.js +++ b/config/plugins/webhooks/news/script.js @@ -8,16 +8,16 @@ function showNewsOverlay() { } function newsSeen() { - // When it's seen, remove fa and far, add fas. - const newsIconSpan = document.getElementById("news").querySelector(".fa-bell"); + // When it's seen, remove fa, add far. + const newsIconSpan = document.querySelector("#news .fa-bell"); newsIconSpan.classList.remove("fa"); newsIconSpan.classList.add("far"); window.localStorage.setItem("galaxy-news-seen-release", Galaxy.config.version_major); } function newsUnseen() { - // When there is news, set far instead of fa - const newsIconSpan = document.getElementById("news").querySelector(".fa-bell"); + // When there is news, remove far, add fa for (default -- same as fas) solid style. + const newsIconSpan = document.querySelector("#news .fa-bell"); newsIconSpan.classList.remove("far"); newsIconSpan.classList.add("fa"); } From 36782f9b9d9898ca0866c1c56b1301551231b197 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Wed, 8 Sep 2021 17:12:57 +0200 Subject: [PATCH 5/6] Downgrade 21.09 to 05, temporarily --- config/plugins/webhooks/news/script.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/config/plugins/webhooks/news/script.js b/config/plugins/webhooks/news/script.js index 86727ad8793..f09cbf51e83 100644 --- a/config/plugins/webhooks/news/script.js +++ b/config/plugins/webhooks/news/script.js @@ -23,7 +23,16 @@ function newsUnseen() { } function addNewsIframe() { - const currentGalaxyVersion = Galaxy.config.version_major; + var currentGalaxyVersion = Galaxy.config.version_major; + + // TODO/@hexylena: By 21.01 we will have a proper solution for this. For + // now we'll hardcode the version users 'see'. @hexylena will remove this + // code when she writes the user-facing release notes, and then will file + // an issue for how we'll fix this properly. + if(currentGalaxyVersion == "21.09") { + currentGalaxyVersion = "21.05"; + } + const releaseNotes = `https://docs.galaxyproject.org/en/master/releases/${currentGalaxyVersion}_announce_user.html`; const lastSeenVersion = window.localStorage.getItem("galaxy-news-seen-release"); // Check that they've seen the current version's release notes. From f805b0dd17d730b2f20a2fcbf8ed97f93b5219d4 Mon Sep 17 00:00:00 2001 From: Helena Rasche Date: Wed, 8 Sep 2021 17:27:05 +0200 Subject: [PATCH 6/6] Add future runway --- config/plugins/webhooks/news/script.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/config/plugins/webhooks/news/script.js b/config/plugins/webhooks/news/script.js index f09cbf51e83..a7d2fafe0d9 100644 --- a/config/plugins/webhooks/news/script.js +++ b/config/plugins/webhooks/news/script.js @@ -29,7 +29,9 @@ function addNewsIframe() { // now we'll hardcode the version users 'see'. @hexylena will remove this // code when she writes the user-facing release notes, and then will file // an issue for how we'll fix this properly. - if(currentGalaxyVersion == "21.09") { + if(currentGalaxyVersion == "22.01") { + currentGalaxyVersion = "21.09"; + } else if(currentGalaxyVersion == "21.09") { currentGalaxyVersion = "21.05"; }