Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add toolmsg webhook to EU #1413

Merged
merged 5 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions group_vars/sn06/toolmsg.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
---
# This file is used to define custom messages for tools that are displayed in the tool form
# The toolmsg webhook wil be triggered and the message will be displayed in the tool form if the tool_id matches

# Format:
# toolmsg_messages:
# - tool_id: to match subject.startsWith(tool_id)
# Best to use remove version numbers and trailing slash
# e.g. toolshed.g2.bx.psu.edu/repos/galaxyp/diann/diann
# message: A custom HTML message to be displayed for this tool
# class: bootstrap class [primary, info, success, warning, danger]

# Example 1: Display a warning message for the tool ncbi_blastp_wrapper, the message will be in bold format
# toolmsg_messages:
# - tool_id: toolshed.g2.bx.psu.edu/repos/devteam/ncbi_blast_plus/ncbi_blastp_wrapper
# message: <strong>We recommend using Diamond instead.</strong>
# class: warning

# Example 2: Display a warning message for the tool ncbi_blastp_wrapper, the message will be in bold format and will have a link to the Diamond tool
# toolmsg_messages:
# - tool_id: toolshed.g2.bx.psu.edu/repos/devteam/ncbi_blast_plus/ncbi_blastp_wrapper
# message: >
# <strong>We recommend using
# <a href="https://usegalaxy.eu/?tool_id=toolshed.g2.bx.psu.edu%2Frepos%2Fbgruening%2Fdiamond%2Fbg_diamond%2F2.1.11%2Bgalaxy0&version=latest"
# target="_blank"
# >
# Diamond
# </a>
# instead.</strong>
# class: warning

toolmsg_messages:
- tool_id: toolshed.g2.bx.psu.edu/repos/devteam/fastqc/fastqc
message: >
<strong>We recommend using
<a href="https://usegalaxy.eu/?tool_id=falco" target="_blank">
Falco
</a>
instead. Falco is 3 times faster and offers the same functionality as FASTQC.</strong>
class: warning
5 changes: 3 additions & 2 deletions roles/usegalaxy-eu.webhooks/defaults/main.yml
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
galaxy_webhook_url: "https://github.com/usegalaxy-eu/galaxy-webhooks"
galaxy_webhook_dir: "{{ galaxy_mutable_data_dir }}/webhooks"
galaxy_webhook_url: 'https://github.com/usegalaxy-eu/galaxy-webhooks'
galaxy_webhook_dir: '{{ galaxy_mutable_data_dir }}/webhooks'
galaxy_webhook_plugins_template_dir: 'templates/galaxy/webhooks/'
23 changes: 19 additions & 4 deletions roles/usegalaxy-eu.webhooks/tasks/main.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
- name: Clone webhook repository
git:
repo: "{{ galaxy_webhook_url }}"
dest: "{{ galaxy_webhook_dir }}"
ansible.builtin.git:
repo: '{{ galaxy_webhook_url }}'
dest: '{{ galaxy_webhook_dir }}'
version: master
force: "yes"
force: 'yes'

- name: Create toolmsg plugins directory in webhook directory
ansible.builtin.file:
path: '{{ galaxy_webhook_dir }}/toolmsg_24.2'
state: directory
mode: '0755'

- name: Template toolmsg_24.2 webhook files
ansible.builtin.template:
src: '{{ item }}'
dest: "{{ galaxy_webhook_dir }}/toolmsg_24.2/{{ item | basename | regex_replace('\\.j2$', '') }}"
mode: 0644
with_fileglob:
- '{{ galaxy_webhook_plugins_template_dir }}/toolmsg_24.2/*'
notify: Restart Galaxy
1 change: 1 addition & 0 deletions sn06.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
- group_vars/sn06/sn06.yml
- group_vars/sn06/themes_conf.yml
- group_vars/sn06/subdomains.yml
- group_vars/sn06/toolmsg.yml
- group_vars/tiaas.yml # All of the training infrastructure
- group_vars/gxconfig.yml # The base galaxy configuration
- group_vars/toolbox.yml # User controlled toolbox
Expand Down
1 change: 1 addition & 0 deletions templates/galaxy/webhooks/toolmsg_24.2/GALAXY_VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
galaxy >= 24.2
4 changes: 4 additions & 0 deletions templates/galaxy/webhooks/toolmsg_24.2/config.yml.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
id: toolmsg
type:
- onload
activate: true
82 changes: 82 additions & 0 deletions templates/galaxy/webhooks/toolmsg_24.2/script.js.j2
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// Custom messages for tool forms

const enableDebug = false;
const debugLog = (msg) => enableDebug && console.debug("[ToolMsg]: " + msg);

const WAIT_TOOL_MAX_TRIES = 3;
const WAIT_TOOL_INTERVAL = 500;
const toolMessages = [
{% if toolmsg_messages is defined and toolmsg_messages %}
{% for message in toolmsg_messages %}
{
tool_id: "{{ message.tool_id }}",
message: `{{ message.message }}`,
class: "{{ message.class }}"
},
{% endfor %}
{% endif %}
];

function waitToolFormLoad() {
tries++;
let matched = false;
const element = document.querySelector('div[tool_id]');
if (element) {
debugLog('Tool form has been loaded');
matched = showToolMessages();
tries = WAIT_TOOL_MAX_TRIES;
} else {
debugLog("No tool form detected (tries: " + tries + ")");
}
tries < WAIT_TOOL_MAX_TRIES
&& !matched
&& setTimeout(waitToolFormLoad, WAIT_TOOL_INTERVAL);
}

function isCurrentToolForm(toolId) {
const elements = document.querySelectorAll('[tool_id]');
for (let element of elements) {
const thisToolId = element.getAttribute('tool_id');
if (thisToolId && thisToolId.startsWith(toolId)) {
debugLog(toolId + " matches " + thisToolId);
return true;
}
}
debugLog(toolId + " not found in page.");
return false;
}

function showToolMessages() {
let match = false;
toolMessages.forEach( (toolMessage) => {
if (isCurrentToolForm(toolMessage.tool_id)) {
const newElement = document.createElement('p');
newElement.className = 'alert alert-' + toolMessage.class + ' my-3';
newElement.innerHTML = toolMessage.message;
const referenceElement = document.getElementById('tool-card-body');
if (referenceElement) {
referenceElement.parentNode.insertBefore(newElement, referenceElement);
} else {
debugLog('Reference element with id="tool-card-body" not found.');
}
match = true;
}
})
return match;
}

let tries = 0;
let lastUrlPath = null;

// Add observer for Vue pathname changes
const observer = new MutationObserver( () => {
if (lastUrlPath !== window.location.href) {
debugLog("Triggered mutation observer");
tries = 0;
lastUrlPath = window.location.href;
setTimeout(waitToolFormLoad, 500);
}
});

// Observe the document body for changes (or another relevant element)
observer.observe(document.body, { childList: true, subtree: true });
Empty file.
Loading