Skip to content

Commit e123283

Browse files
authored
Merge pull request #79 from rjnewsham/filter
Adding filter text box to top of the page for easy filtering of visib…
2 parents 0e1db6f + a758614 commit e123283

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

bzkanban.js

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,16 +210,33 @@ function createQueryFields() {
210210
filterByAssignee(name);
211211
});
212212

213+
var filter = document.createElement("span");
214+
215+
var filterIcon = document.createElement("i");
216+
filterIcon.className = "fa fa-search";
217+
filterIcon.title = "Filter";
218+
219+
var filterText = document.createElement("input");
220+
filterText.id = 'textFilter';
221+
filterText.name = 'textFilter';
222+
filterText.placeholder = 'Filter';
223+
filterText.addEventListener( "keyup", function() {
224+
debounce( filterByString( document.getElementById("textFilter").value ), 500);
225+
});
226+
213227
product.appendChild(productIcon);
214228
product.appendChild(productList);
215229
milestone.appendChild(milestoneIcon);
216230
milestone.appendChild(milestoneList);
217231
assignee.appendChild(assigneeIcon);
218232
assignee.appendChild(assigneeList);
233+
filter.appendChild(filterIcon);
234+
filter.appendChild(filterText);
219235

220236
query.appendChild(product);
221237
query.appendChild(milestone);
222238
query.appendChild(assignee);
239+
query.appendChild(filter);
223240

224241
return query;
225242
}
@@ -898,6 +915,21 @@ function filterByAssignee(name) {
898915
showColumnCounts();
899916
}
900917

918+
function filterByString(string) {
919+
var cards = document.querySelectorAll(".card");
920+
cards.forEach(function(card) {
921+
var regex = new RegExp( string, "i" );
922+
if ( card.innerHTML.match( regex ) || string == "") {
923+
card.style.display = "block";
924+
} else {
925+
card.style.display = "none";
926+
}
927+
});
928+
929+
// force reload
930+
showColumnCounts();
931+
}
932+
901933
function updateUnconfirmedColumnVisibilty() {
902934
var col = document.querySelector(".board-column#UNCONFIRMED");
903935
if (col !== null) {
@@ -909,6 +941,28 @@ function updateUnconfirmedColumnVisibilty() {
909941
}
910942
}
911943

944+
function debounce(func, wait, immediate) {
945+
var timeout;
946+
947+
return function executedFunction() {
948+
var context = this;
949+
var args = arguments;
950+
951+
var later = function() {
952+
timeout = null;
953+
if (!immediate) func.apply(context, args);
954+
};
955+
956+
var callNow = immediate && !timeout;
957+
958+
clearTimeout(timeout);
959+
960+
timeout = setTimeout(later, wait);
961+
962+
if (callNow) func.apply(context, args);
963+
};
964+
};
965+
912966
function httpPut(url, dataObj, successCallback, errorCallback) {
913967
httpRequest("PUT", url, dataObj, successCallback, errorCallback);
914968
}

0 commit comments

Comments
 (0)