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-73960] Extract event handlers in BuildCardExtension/buildCardTemplate.jelly #142

Open
wants to merge 26 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
16aad96
fix: Update jQuery filter removal syntax for 3.x compatibility
shlomomdahan Oct 23, 2024
d74f129
address first csp issue: https://github.com/jenkinsci/build-pipeline-…
shlomomdahan Oct 23, 2024
317e0fa
address first csp issue: https://github.com/jenkinsci/build-pipeline-…
shlomomdahan Oct 23, 2024
913d01a
line 97: https://github.com/jenkinsci/build-pipeline-plugin/blob/mast…
shlomomdahan Oct 23, 2024
6537326
Merge branch 'master' into JENKINS-73960
shlomomdahan Oct 28, 2024
31008b1
fix: https://github.com/jenkinsci/build-pipeline-plugin/blob/master/s…
shlomomdahan Oct 29, 2024
85d08a3
fix:https://github.com/jenkinsci/build-pipeline-plugin/blob/master/sr…
shlomomdahan Oct 29, 2024
f5f7cc7
fix:https://github.com/jenkinsci/build-pipeline-plugin/blob/master/sr…
shlomomdahan Oct 29, 2024
2147df2
fix: https://github.com/jenkinsci/build-pipeline-plugin/blob/master/s…
shlomomdahan Oct 30, 2024
047a747
fix: https://github.com/jenkinsci/build-pipeline-plugin/blob/master/s…
shlomomdahan Oct 30, 2024
6ef4240
fix: https://github.com/jenkinsci/build-pipeline-plugin/blob/master/s…
shlomomdahan Oct 30, 2024
a3b8458
dynamic behaviour.specify
shlomomdahan Oct 30, 2024
ed0c9e5
dynamic behaviour.specify
shlomomdahan Oct 30, 2024
30476d5
update names, update java method, all working
shlomomdahan Oct 30, 2024
5572051
remove Behaviour.specify \ Use dynamic approach
shlomomdahan Oct 30, 2024
ba67a4b
remove Behaviour.specify \ Use dynamic approach
shlomomdahan Oct 30, 2024
9bf83a9
remove Behaviour.specify \ Use dynamic approach
shlomomdahan Oct 30, 2024
59e2952
rerun tests
shlomomdahan Oct 31, 2024
7beca34
specify pipeline wrapper - fixes onclick issues
shlomomdahan Nov 7, 2024
188bc43
select all pipeline wrappers - incase multiple builds selected
shlomomdahan Nov 7, 2024
b456e59
Merge branch 'master' into JENKINS-73960
shlomomdahan Nov 8, 2024
8e66cab
Merge branch 'master' into JENKINS-73960
shlomomdahan Nov 8, 2024
b3e23da
remove redundant parameters span
shlomomdahan Nov 10, 2024
fd147b5
simplify dependency ID parsing
shlomomdahan Nov 12, 2024
0a748ce
simplify/cleanup
shlomomdahan Nov 25, 2024
e501c9e
simplify/cleanup
shlomomdahan Nov 25, 2024
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
Expand Up @@ -105,7 +105,7 @@ public static boolean isManualTrigger(final AbstractProject<?, ?> upstreamProjec
final String manualDownstreamProjects = ((BuildPipelineTrigger) upstreamPub).getDownstreamProjectNames();
final String[] downstreamProjs = manualDownstreamProjects.split(",");
for (final String nextProj : downstreamProjs) {
if (Jenkins.getInstance().getItem(nextProj.trim(), upstreamProject) == downstreamProject) {
if (Jenkins.getInstance().getItem(nextProj.trim(), upstreamProject).getName().equals(downstreamProject.getName())) {
manualTrigger = true;
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
</j:if>

<st:adjunct includes="io.jenkins.plugins.jquery3"/>
<st:adjunct includes="au.com.centrumsystems.hudson.plugin.buildpipeline.extension.BuildCardExtension.build-card-template-onclicks"/>
<script src="${rootURL}/plugin/build-pipeline-plugin/js/jquery-migrate-1.2.1.min.js"></script>
<script type="text/javascript" src="${rootURL}/plugin/build-pipeline-plugin/js/jquery-ui-1.8.14.custom.min.js"></script>
<script type="text/javascript" src="${rootURL}/plugin/build-pipeline-plugin/js/handlebars-1.0.0.beta.6.js"></script>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
function parseDataAttributes(container) {
return {
id: parseInt(container.dataset.showSpinnerId, 10),
buildExtId: container.dataset.rerunBuildExtId,
dependencyIds: container.dataset.rerunBuildDependencyIds
.split(",")
.map(id => parseInt(id))
};
}

function parseTriggerAttributes(container) {
return {
id: parseInt(container.dataset.showSpinnerId, 10),
upstreamProjectName: container.dataset.upstreamProjectName,
upstreamBuildNumber: parseInt(container.dataset.upstreamBuildNumber, 10),
projectName: container.dataset.projectName,
dependencyIds: container.dataset.dependencyIds
.split(",")
.map(id => parseInt(id))
};
}

function handleDialogClick(dataContainer) {
const href = dataContainer.dataset.fillDialogHref;
const title = dataContainer.dataset.fillDialogTitle;
buildPipeline.fillDialog(href, title);
}

function handleRerunClick(dataContainer) {
const { id, buildExtId, dependencyIds } = parseDataAttributes(dataContainer);
buildPipeline.showSpinner(id);
buildPipeline.rerunBuild(id, buildExtId, dependencyIds);
}

function handleTriggerBuild(dataContainer) {
const { id, upstreamProjectName, upstreamBuildNumber, projectName, dependencyIds } = parseTriggerAttributes(dataContainer);
buildPipeline.showSpinner(id);
buildPipeline.triggerBuild(id, upstreamProjectName, upstreamBuildNumber, projectName, dependencyIds);
}

function createClickHandler(parentElement, targetSelector, handlerFn) {
const newHandler = function(event) {
const clickTarget = event.target.closest(targetSelector);
if (!clickTarget || !parentElement.contains(clickTarget)) return;

handlerFn(clickTarget);
};

parentElement.addEventListener("click", newHandler);
}

const onclickElements = {
".bct-progress-bar-onclick": handleDialogClick,
".bct-console-icon-onclick": handleDialogClick,
".bct-rerun-successful-build-onclick": handleRerunClick,
".bct-rerun-failed-latest-build-onclick": handleRerunClick,
".bct-rerun-failed-manual-build-onclick": handleTriggerBuild,
".bct-rerun-failed-build-onclick": handleRerunClick,
".bct-trigger-manual-build-latest-onclick": handleTriggerBuild,
".bct-trigger-manual-build-onclick": handleTriggerBuild
};

document.addEventListener("DOMContentLoaded", function () {
const pipelineWrappers = document.querySelectorAll(".pipeline-wrapper");

if (!pipelineWrappers.length) return;

pipelineWrappers.forEach(wrapper => {
Object.entries(onclickElements).forEach(function([selector, handler]) {
createClickHandler(wrapper, selector, handler);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
{{#unless project.disabled}}
<div class="status-bar" id="status-bar-{{id}}">
{{#if build.isBuilding}}
<div onclick="buildPipeline.fillDialog('${app.rootUrl}{{build.url}}console', 'Console output for {{project.name}} #{{build.number}}')">
<div class="bct-progress-bar-onclick" data-fill-dialog-href="${app.rootUrl}{{build.url}}console" data-fill-dialog-title="Console output for {{project.name}} #{{build.number}}">
<table class="progress-bar" align="center">
<tbody>
<tr title="Estimated remaining time: {{build.estimatedRemainingTime}}">
Expand Down Expand Up @@ -94,7 +94,7 @@
</a>
</j:when>
<j:otherwise>
<span onclick="buildPipeline.fillDialog('${app.rootUrl}{{build.url}}console', 'Console output for {{project.name}} #{{build.number}}')">
<span class="bct-console-icon-onclick" data-fill-dialog-href="${app.rootUrl}{{build.url}}console" data-fill-dialog-title="Console output for {{project.name}} #{{build.number}}">
<l:icon src="${consoleOutputIconUrl} icon-sm" alt="console" />
</span>
</j:otherwise>
Expand All @@ -106,7 +106,7 @@
{{#if build.isSuccess}}
{{#if ${!it.triggerOnlyLatestJob}}}
<j:if test="${it.hasBuildPermission()}">
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.rerunBuild({{id}}, '{{build.extId}}', [{{build.dependencyIds}}])">
<span class="bct-rerun-successful-build-onclick" data-show-spinner-id="{{id}}" data-rerun-build-ext-id="{{build.extId}}" data-rerun-build-dependency-ids="{{build.dependencyIds}}">
<l:icon src="icon-clock icon-sm" alt="re-run" />
</span>
</j:if>
Expand All @@ -115,18 +115,18 @@
{{#if ${it.triggerOnlyLatestJob}}}
{{#if build.isLatestBuild}}
{{#if build.isUpstreamBuildLatest}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.rerunBuild({{id}}, '{{build.extId}}', [{{build.dependencyIds}}])">
<span class="bct-rerun-failed-latest-build-onclick" data-show-spinner-id="{{id}}" data-rerun-build-ext-id="{{build.extId}}" data-rerun-build-dependency-ids="{{build.dependencyIds}}">
<l:icon src="icon-clock icon-sm" alt="retry" />
</span>
{{/if}}
{{/if}}
{{else}}
{{#if build.isManual}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.triggerBuild({{id}}, '{{upstream.projectName}}', {{upstream.buildNumber}}, '{{project.name}}', [{{build.dependencyIds}}])">
{{#if build.isManualTrigger}}
shlomomdahan marked this conversation as resolved.
Show resolved Hide resolved
<span class="bct-rerun-failed-manual-build-onclick" data-show-spinner-id="{{id}}" data-upstream-project-name="{{upstream.projectName}}" data-upstream-build-number="{{upstream.buildNumber}}" data-project-name="{{project.name}}" data-dependency-ids="{{build.dependencyIds}}">
<l:icon src="icon-clock icon-sm" alt="retry" />
</span>
{{else}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.rerunBuild({{id}}, '{{build.extId}}', [{{build.dependencyIds}}])">
<span class="bct-rerun-failed-build-onclick" data-show-spinner-id="{{id}}" data-rerun-build-ext-id="{{build.extId}}" data-rerun-build-dependency-ids="{{build.dependencyIds}}">
<l:icon src="icon-clock icon-sm" alt="retry" />
</span>
{{/if}}
Expand All @@ -137,12 +137,12 @@
{{#if build.isReadyToBeManuallyBuilt}}
{{#if ${it.triggerOnlyLatestJob}}}
{{#if build.isUpstreamBuildLatestSuccess}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.triggerBuild({{id}}, '{{upstream.projectName}}', {{upstream.buildNumber}}, '{{project.name}}', [{{build.dependencyIds}}])">
<span class="bct-trigger-manual-build-latest-onclick" data-show-spinner-id="{{id}}" data-upstream-project-name="{{upstream.projectName}}" data-upstream-build-number="{{upstream.buildNumber}}" data-project-name="{{project.name}}" data-dependency-ids="{{build.dependencyIds}}">
<l:icon src="icon-clock icon-sm" alt="trigger" />
</span>
{{/if}}
{{else}}
<span onclick="buildPipeline.showSpinner({{id}}); buildPipeline.triggerBuild({{id}}, '{{upstream.projectName}}', {{upstream.buildNumber}}, '{{project.name}}', [{{build.dependencyIds}}])">
<span class="bct-trigger-manual-build-onclick" data-show-spinner-id="{{id}}" data-upstream-project-name="{{upstream.projectName}}" data-upstream-build-number="{{upstream.buildNumber}}" data-project-name="{{project.name}}" data-dependency-ids="{{build.dependencyIds}}">
<l:icon src="icon-clock icon-sm" alt="trigger" />
</span>
{{/if}}
Expand Down