diff --git a/war/src/main/js/widgets/config/model/ConfigSection.js b/war/src/main/js/widgets/config/model/ConfigSection.js index 827c8678e8eda2b088901613d34cd833ad8f3cb3..295181af829150c283bf4f19f055b831969d531d 100644 --- a/war/src/main/js/widgets/config/model/ConfigSection.js +++ b/war/src/main/js/widgets/config/model/ConfigSection.js @@ -102,6 +102,29 @@ ConfigSection.prototype.markRowsAsActive = function() { this.updateRowGroupVisibility(); }; +ConfigSection.prototype.hasText = function(text) { + var $ = jQD.getJQuery(); + var selector = ":containsci('" + text + "')"; + var sectionRows = this.getRows(); + + for (var i1 = 0; i1 < sectionRows.length; i1++) { + var row = sectionRows[i1]; + var elementsWithText = $(selector, row); + + if (elementsWithText.size() > 0) { + return true; + } + } + + for (var i2 = 0; i2 < this.subSections.length; i2++) { + if (this.subSections[i2].hasText(text)) { + return true; + } + } + + return false; +}; + ConfigSection.prototype.activeRowCount = function() { var activeRowCount = 0; var rows = this.getRows(); @@ -190,8 +213,8 @@ ConfigSection.prototype.highlightText = function(text) { var selector = ":containsci('" + text + "')"; var rows = this.getRows(); - for (var i = 0; i < rows.length; i++) { - var row = rows[i]; + for (var i1 = 0; i1 < rows.length; i1++) { + var row = rows[i1]; /*jshint loopfunc: true */ $('span.highlight-split', row).each(function() { // jshint ignore:line @@ -209,11 +232,16 @@ ConfigSection.prototype.highlightText = function(text) { $this.contents().each(function () { // We specifically only mess with text nodes if (this.nodeType === 3) { - var highlightedMarkup = this.wholeText.replace(regex, '$1'); - $(this).replaceWith('' + highlightedMarkup + ''); + var $textNode = $(this); + var highlightedMarkup = $textNode.text().replace(regex, '$1'); + $textNode.replaceWith('' + highlightedMarkup + ''); } }); }); } } + + for (var i2 = 0; i2 < this.subSections.length; i2++) { + this.subSections[i2].highlightText(text); + } }; diff --git a/war/src/main/js/widgets/config/model/ConfigTableMetaData.js b/war/src/main/js/widgets/config/model/ConfigTableMetaData.js index a3940eb684f0c5083c5ac9722f993ae5896efa2e..6ee7905a807203ba3f9833aad0803d4ae28b8c7c 100644 --- a/war/src/main/js/widgets/config/model/ConfigTableMetaData.js +++ b/war/src/main/js/widgets/config/model/ConfigTableMetaData.js @@ -262,7 +262,7 @@ ConfigTableMetaData.prototype.showSections = function(withText) { if (withText === '') { if (this.hasSections()) { for (var i1 = 0; i1 < this.sections.length; i1++) { - this.sections[i1].activator.show(); + this.sections[i1].activator.removeClass('hidden'); } var activeSection = this.activeSection(); if (!activeSection) { @@ -273,30 +273,16 @@ ConfigTableMetaData.prototype.showSections = function(withText) { } } else { if (this.hasSections()) { - var $ = jQD.getJQuery(); - var selector = ":containsci('" + withText + "')"; var sectionsWithText = []; for (var i2 = 0; i2 < this.sections.length; i2++) { var section = this.sections[i2]; - var containsText = false; - var sectionRows = section.getRows(); - - for (var i3 = 0; i3 < sectionRows.length; i3++) { - var row = sectionRows[i3]; - var elementsWithText = $(selector, row); - - if (elementsWithText.size() > 0) { - containsText = true; - break; - } - } - if (containsText) { - section.activator.show(); + if (section.hasText(withText)) { + section.activator.removeClass('hidden'); sectionsWithText.push(section); } else { - section.activator.hide(); + section.activator.addClass('hidden'); } } diff --git a/war/src/main/js/widgets/jenkins-widgets.less b/war/src/main/js/widgets/jenkins-widgets.less index 49fc0a6bf2c5350939d33ea5041198733879e7c5..c2a9e87f6b6abf683bef62a8bd75e6cfeb27bf33 100644 --- a/war/src/main/js/widgets/jenkins-widgets.less +++ b/war/src/main/js/widgets/jenkins-widgets.less @@ -10,4 +10,9 @@ /* * Widget styles */ -@import "config/tabbar"; \ No newline at end of file +@import "config/tabbar"; + + +.hidden { + display: none; +} \ No newline at end of file diff --git a/war/src/test/js/widgets/config/freestyle-config.html b/war/src/test/js/widgets/config/freestyle-config.html index c01cf97fd64d23e4494c55cae31754198a676dd9..a236ee0f45c21705990728652ec7c75b513fee4d 100644 --- a/war/src/test/js/widgets/config/freestyle-config.html +++ b/war/src/test/js/widgets/config/freestyle-config.html @@ -129,7 +129,8 @@ - + + diff --git a/war/src/test/js/widgets/config/tabbar-spec.js b/war/src/test/js/widgets/config/tabbar-spec.js index 73edbe4d1b2da43b6403c815116892f6c3ecaf39..071dda22cc22810947161715e4781ea440dc4ddc 100644 --- a/war/src/test/js/widgets/config/tabbar-spec.js +++ b/war/src/test/js/widgets/config/tabbar-spec.js @@ -71,6 +71,102 @@ describe("tabbar-spec tests", function () { done(); }, 'widgets/config/freestyle-config.html'); }); + + it("- test finder - via handler triggering", function (done) { + jsTest.onPage(function() { + var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar'); + var configTabBar = configTabBarWidget.addTabsOnFirst(); + var jQD = require('jquery-detached'); + + var $ = jQD.getJQuery(); + + var tabBar = $('.tabBar'); + + // All tabs should be visible... + expect($('.tab', tabBar).size()).toBe(4); + expect($('.tab.hidden', tabBar).size()).toBe(0); + + var finder = configTabBar.findInput; + expect(finder.size()).toBe(1); + + // Find sections that have the text "trigger" in them... + keydowns('trigger', finder); + + // Need to wait for the change to happen ... there's a 300ms delay. + // We could just call configTabBar.showSections(), but ... + setTimeout(function() { + expect($('.tab.hidden', tabBar).size()).toBe(3); + expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('General|#Advanced Project Options|#Build'); + + var activeSection = configTabBar.activeSection(); + expect(textCleanup(activeSection.title)).toBe('#Build Triggers'); + + expect($('.highlight-split .highlight').text()).toBe('Trigger'); + + done(); + }, 600); + }, 'widgets/config/freestyle-config.html'); + }); + + it("- test finder - via showSections()", function (done) { + jsTest.onPage(function() { + var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar'); + var configTabBar = configTabBarWidget.addTabsOnFirst(); + var jQD = require('jquery-detached'); + + var $ = jQD.getJQuery(); + + var tabBar = $('.tabBar'); + + configTabBar.showSections('quiet period'); + expect($('.tab.hidden', tabBar).size()).toBe(3); + expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('General|#Build Triggers|#Build'); + + var activeSection = configTabBar.activeSection(); + expect(textCleanup(activeSection.title)).toBe('#Advanced Project Options'); + + done(); + }, 'widgets/config/freestyle-config.html'); + }); + + it("- test finder - via showSections() - in inner row-group", function (done) { + jsTest.onPage(function() { + var configTabBarWidget = jsTest.requireSrcModule('widgets/config/tabbar'); + var configTabBar = configTabBarWidget.addTabsOnFirst(); + var jQD = require('jquery-detached'); + + var $ = jQD.getJQuery(); + + var tabBar = $('.tabBar'); + + configTabBar.showSections('Strategy'); + expect($('.tab.hidden', tabBar).size()).toBe(3); + expect(textCleanup($('.tab.hidden', tabBar).text())).toBe('#Advanced Project Options|#Build Triggers|#Build'); + + var activeSection = configTabBar.activeSection(); + expect(textCleanup(activeSection.title)).toBe('General'); + + done(); + }, 'widgets/config/freestyle-config.html'); + }); + + function keydowns(text, onInput) { + var jQD = require('jquery-detached'); + var $ = jQD.getJQuery(); + + // hmmm, for some reason, the key events do not result in the text being + // set in the input, so setting it manually. + onInput.val(text); + + // Now fire a keydown event to trigger the handler + var e = $.Event("keydown"); + e.which = 116; + onInput.trigger(e); + } + + function textCleanup(text) { + return text.trim().replace(/(\r\n|\n|\r)/gm, "").replace(/ +/g, "|"); + } }); // TODO: lots more tests !!! \ No newline at end of file