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

[JENKINS-73968] Extract event handler in QuickDiskUsagePlugin/sidepanel.jelly #113

Merged
merged 17 commits into from
Nov 6, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
function refreshDiskUsage(a, ev) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This code was broken before this PR (presumably due to some previous Jenkins core changes) so I fixed the existing code and retested. The new code works like jenkinsci/jenkins#9787 where the callback takes two elements, the element and the event. The element isn't actually used, but it could be used to fetch data attributes for example. When the callback is executed, the POST request is made, and then we call ev.preventDefault() to prevent link navigation from taking place. When the POST response is received, we display a notification on the notification bar for either success or failure, using the appropriate color.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great stuff, thanks!

fetch("refresh", {
method: "post",
headers: crumb.wrap({}),
}).then((rsp) => {
if (rsp.ok) {
notificationBar.show("Refresh scheduled", notificationBar.SUCCESS);
} else {
notificationBar.show("Failed to schedule refresh", notificationBar.ERROR);
}
});
ev.preventDefault();
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,16 @@
Side panel for the build view.
-->
<?jelly escape-by-default='true'?>
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout">
<j:jelly xmlns:j="jelly:core" xmlns:l="/lib/layout" xmlns:st="jelly:stapler">
<l:header />
<l:side-panel>
<l:tasks>
<l:task href="${rootURL}/" icon="icon-up icon-md" title="${%Back to Dashboard}"/>
<l:task href="${rootURL}/manage" icon="icon-setting icon-md" title="${%Manage Jenkins}"/>
<l:task href="." icon="/plugin/cloudbees-disk-usage-simple/images/disk.png" title="${%Disk usage}"/>
<j:if test="${not it.running}">
<l:task href="." onclick="return refresh(this)" icon="icon-refresh icon-md" title="${%Refresh disk usage}" post="true"/>
<script>
function refresh(a) {
fetch("refresh", {
method: "post",
headers: crumb.wrap({}),
});
hoverNotification('${%Refresh scheduled}',a.parentNode);
return true;
}
</script>
<st:adjunct includes="com.cloudbees.simplediskusage.QuickDiskUsagePlugin.refresh-disk-usage"/>
<l:task href="." data-callback="refreshDiskUsage" icon="icon-refresh icon-md" title="${%Refresh disk usage}" post="true"/>
</j:if>
</l:tasks>
</l:side-panel>
Expand Down