Skip to content

Commit

Permalink
[JENKINS-73969] [JENKINS-73970] Remove inline JavaScript to become CS…
Browse files Browse the repository at this point in the history
…P compliant (#72)
  • Loading branch information
mawinter69 authored Oct 16, 2024
1 parent 0c06a8e commit 2c0a4dd
Show file tree
Hide file tree
Showing 6 changed files with 44 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@
<j:invokeStatic className="hudson.views.ViewGraph" method="toName" var="thisViewName">
<j:arg value="${it}" type="hudson.model.View"/>
</j:invokeStatic>
<f:select checkUrl="'${rootURL}/descriptorByName/hudson.views.OtherViewsFilter/checkOtherViewName?otherViewName=' + encodeURIComponent((this.options.length == 0) ? '' : this.options[this.selectedIndex].value) + '&amp;viewName=' + encodeURIComponent('${h.jsStringEscape(thisViewName)}')"/>
<f:invisibleEntry>
<f:textbox name="viewName" value="${thisViewName}"/>
</f:invisibleEntry>
<f:select checkUrl="${rootURL}/descriptorByName/hudson.views.OtherViewsFilter/checkOtherViewName" checkDependsOn="viewName otherViewName"/>
</f:entry>
<st:include page="config.jelly" class="hudson.views.AbstractIncludeExcludeJobFilter" optional="false"/>
</j:jelly>
7 changes: 4 additions & 3 deletions src/main/resources/hudson/views/RegExJobFilter/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form"
xmlns:i="jelly:fmt" xmlns:p="/lib/hudson/project">
<f:entry title="${%Regular Expression}:">
<f:textbox name="regex" field="regex" checkUrl="'${rootURL}/descriptorByName/hudson.views.RegExJobFilter/checkRegex?value='+encodeURIComponent(this.value)"/>
<f:textbox name="regex" field="regex"/>
</f:entry>
<f:entry title="${%Match Value}:">
<div class="valueType">
<div class="jenkins-select jenkins-!-margin-bottom-2">
<select name="valueTypeString" class="jenkins-select__input" onchange="this.parentElement.querySelector('.nameOptions').style.display = ((this.options[this.selectedIndex].value.match(/NAME/)) ? 'block' : 'none')">
<select name="valueTypeString" class="jenkins-select__input vjf-regex-select">
<f:option value="NAME" selected="${instance.valueTypeString == 'NAME'}">${%Job name}</f:option>
<f:option value="FOLDER_NAME" selected="${instance.valueTypeString == 'FOLDER_NAME'}">${%Job folder name}</f:option>
<f:option value="DESCRIPTION" selected="${instance.valueTypeString == 'DESCRIPTION'}">${%Job description}</f:option>
Expand All @@ -19,7 +19,7 @@
<f:option value="NODE" selected="${instance.valueTypeString == 'NODE'}">${%Node label expression}</f:option>
</select>
</div>
<div class="nameOptions" style="display: ${(empty instance.valueTypeString || instance.valueTypeString.contains('NAME')) ? 'block' : 'none'}">
<div class="nameOptions ${(empty instance.valueTypeString || instance.valueTypeString.contains('NAME')) ? '' : 'jenkins-hidden'}">
<div>
<f:checkbox title="${%Name}" field="matchName" default="true"/>
</div>
Expand All @@ -36,4 +36,5 @@
</div>
</f:entry>
<st:include page="config.jelly" class="hudson.views.AbstractIncludeExcludeJobFilter" optional="false"/>
<st:adjunct includes="hudson.views.RegExJobFilter.nameOptions"/>
</j:jelly>
6 changes: 6 additions & 0 deletions src/main/resources/hudson/views/RegExJobFilter/nameOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Behaviour.specify(".vjf-regex-select", "vjf-regex-select", 0, function (e) {
e.addEventListener("change", function () {
const nameOptions = e.closest(".valueType").querySelector(".nameOptions");
nameOptions.classList.toggle("jenkins-hidden", !e.options[e.selectedIndex].value.match(/NAME/))
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,12 @@
<j:invokeStatic className="hudson.views.ViewGraph" method="toName" var="thisViewName">
<j:arg value="${it}" type="hudson.model.View"/>
</j:invokeStatic>
<f:invisibleEntry>
<f:textbox name="viewName" value="${thisViewName}"/>
</f:invisibleEntry>
<f:entry>
<div style="display:none">
<f:textbox name="dummy" checkUrl="'${rootURL}/descriptorByName/hudson.views.UnclassifiedJobsFilter/check?viewName=' + encodeURIComponent('${h.jsStringEscape(thisViewName)}')"/>
<f:textbox name="dummy" checkUrl="${rootURL}/descriptorByName/hudson.views.UnclassifiedJobsFilter/check" checkDependsOn="viewName"/>
</div>
</f:entry>
<st:include page="config.jelly" class="hudson.views.AbstractIncludeExcludeJobFilter" optional="false"/>
Expand Down
28 changes: 3 additions & 25 deletions src/main/resources/hudson/views/UserRelevanceFilter/config.jelly
Original file line number Diff line number Diff line change
Expand Up @@ -29,31 +29,11 @@
</div>
<div>
<f:checkbox title="${%Match jobs with builds 'started by' user}" name="matchBuilder" field="matchBuilder" default="true"
onclick="showOrHideBuildOptions(this)"/>
class="showOrHideBuildOptions"/>
</div>
<div>
<f:checkbox title="${%Match jobs with builds where user is source code committer}" name="matchScmChanges" field="matchScmChanges"
default="true" onclick="showOrHideBuildOptions(this)"/>
</div>
<div class="showOrHideBuildOptions">
<script>
function showOrHideBuildOptions(elem) {
var jobFilter = elem.closest('[name="jobFilters"]');
var matchBuilder = jobFilter.querySelector('[name="matchBuilder"]');
var matchScmChanges = jobFilter.querySelector('[name="matchScmChanges"]');

var tr2 = jobFilter.querySelector('[name="buildCountTypeString"]').parentElement.parentElement.parentElement;
var tr3 = jobFilter.querySelector('[name="amountTypeString"]').parentElement.parentElement.parentElement;

if (matchBuilder.checked || matchScmChanges.checked) {
tr2.classList.remove('jenkins-hidden');
tr3.classList.remove('jenkins-hidden');
} else {
tr2.classList.add('jenkins-hidden');
tr3.classList.add('jenkins-hidden');
}
}
</script>
class="showOrHideBuildOptions"/>
</div>
</f:entry>
<f:entry title="${%Build trend type}:">
Expand All @@ -66,7 +46,5 @@
</div>
</f:entry>
<st:include page="config.jelly" class="hudson.views.AbstractBuildTrendFilter" optional="false"/>
<script>
Array.prototype.forEach.call(document.querySelectorAll('.showOrHideBuildOptions'), showOrHideBuildOptions);
</script>
<st:adjunct includes="hudson.views.UserRelevanceFilter.showOptions"/>
</j:jelly>
23 changes: 23 additions & 0 deletions src/main/resources/hudson/views/UserRelevanceFilter/showOptions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
function showOrHideBuildOptions(elem) {
var jobFilter = elem.closest('[name="jobFilters"]');
var matchBuilder = jobFilter.querySelector('[name="matchBuilder"]');
var matchScmChanges = jobFilter.querySelector('[name="matchScmChanges"]');

var tr2 = jobFilter.querySelector('[name="buildCountTypeString"]').parentElement.parentElement.parentElement;
var tr3 = jobFilter.querySelector('[name="amountTypeString"]').parentElement.parentElement.parentElement;

if (matchBuilder.checked || matchScmChanges.checked) {
tr2.classList.remove("jenkins-hidden");
tr3.classList.remove("jenkins-hidden");
} else {
tr2.classList.add("jenkins-hidden");
tr3.classList.add("jenkins-hidden");
}
}

Behaviour.specify(".showOrHideBuildOptions", "showOrHideBuildOptions", 0, function (element) {
element.addEventListener("click", function () {
showOrHideBuildOptions(element);
});
showOrHideBuildOptions(element);
});

0 comments on commit 2c0a4dd

Please sign in to comment.