Skip to content

Commit 8e83abc

Browse files
Filter modules
1 parent ac9a632 commit 8e83abc

File tree

3 files changed

+76
-9
lines changed

3 files changed

+76
-9
lines changed

css/editor.css

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,10 @@ ul {
4848
transform: rotate(90deg);
4949
}
5050

51+
.filtered-out {
52+
display: none;
53+
}
54+
5155
.loading {
5256
animation: loadingAnimation 5s infinite;
5357
}

js/editor.js

Lines changed: 61 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ $(document).ready(function () {
66
$("#browseWorkspace").click(onBrowseWorkspaceHandler);
77
$("#loadModulesBtn").click(onLoadModulesHandler);
88
$("#importProjectBtn").click(onImportProjectHandler);
9+
$("input#filterModules").on("input", onFilterChange);
10+
$("#resetFilter").click(onResetFilter);
911
});
1012

1113
function onWindowMessageHandler (event) {
@@ -60,8 +62,30 @@ function onImportProjectHandler () {
6062
modules: modules
6163
});
6264
}
65+
66+
function onFilterChange () {
67+
const topLevel = $("div#moduleList > ul");
68+
let filter = $("input#filterModules").val().toLowerCase().trim();
69+
if (filter && filter.length > 0) {
70+
filterModules(topLevel, filter);
71+
} else {
72+
resetFilteredModules();
73+
}
74+
}
75+
76+
function onResetFilter () {
77+
clearFilter();
78+
resetFilteredModules();
79+
}
6380
//-----------------------------------------
6481

82+
function resetFilteredModules () {
83+
const topLevel = $("div#moduleList > ul");
84+
topLevel.find("li").each(function () {
85+
$(this).removeClass("filtered-out");
86+
});
87+
}
88+
6589
function onSetWorkspaceHandler (message) {
6690
console.log('on set workspace');
6791
clearModules();
@@ -72,9 +96,20 @@ function disableImportBtn (enabled) {
7296
$("#importProjectBtn").attr("disabled", enabled);
7397
}
7498

99+
function disableFilterTxt (enabled) {
100+
$("input#filterModules").attr("disabled", enabled);
101+
$("#resetFilter").attr("disabled", enabled);
102+
}
103+
104+
function clearFilter () {
105+
$("input#filterModules").val("");
106+
}
107+
75108
function clearModules () {
76109
$("#moduleList").empty();
77110
disableImportBtn(true);
111+
disableFilterTxt(true);
112+
clearFilter();
78113
}
79114

80115
function setLocation (elementId, message) {
@@ -98,10 +133,11 @@ function listModules (message) {
98133
if (modules !== null) {
99134
if (modules.length > 0) {
100135
disableImportBtn(false);
101-
}
102-
const topList = $("<ul></ul>").appendTo("div#moduleList");
103-
for (i = 0; i < modules.length; i++) {
104-
addNode(modules[i], topList);
136+
disableFilterTxt(false);
137+
const topList = $("<ul></ul>").appendTo("div#moduleList");
138+
for (i = 0; i < modules.length; i++) {
139+
addNode(modules[i], topList);
140+
}
105141
}
106142
}
107143
}
@@ -143,6 +179,27 @@ function addNode (module, parentNode) {
143179
}
144180
}
145181

182+
function filterModules (parentNode, filter) {
183+
let filtered = false;
184+
parentNode.children("li").each(function () {
185+
const cbNode = $(this).children("input").first();
186+
let filteredModule = cbNode.attr("name").toLowerCase().includes(filter);
187+
const nested = $(this).children("ul").first();
188+
if (nested && nested.length) {
189+
const nestedFiltered = filterModules(nested, filter);
190+
filteredModule = (filteredModule || nestedFiltered);
191+
}
192+
filtered = (filtered || filteredModule);
193+
if (true === filteredModule) {
194+
$(this).removeClass("filtered-out");
195+
} else {
196+
$(this).addClass("filtered-out");
197+
}
198+
199+
});
200+
return filtered;
201+
}
202+
146203
function collectModules (parentNode, modules) {
147204
parentNode.children("li").each(function () {
148205
const cbNode = $(this).children("input").first();

src/editor.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,18 @@ export function getWebviewContent(panel: vscode.WebviewPanel, extCtx: vscode.Ext
7878
<div>
7979
<label for="workspaceLocation">Project WORKSPACE location</label>
8080
<input type="text" id="workspaceLocation" name="workspaceLocation" style="width: 50%; height: 1.5em;">
81-
<button id="browseWorkspace" name="browseWorkspace"
82-
style="height: 1.5em;">Browse...</button>
81+
<button id="browseWorkspace" name="browseWorkspace" style="height: 1.5em;">Browse...</button>
82+
</div>
83+
<div>
84+
<button id="loadModulesBtn" style="height: 1.5em;">Load modules</button>
85+
<button id="importProjectBtn" style="height: 1.5em;" disabled>Start import</button>
86+
</div>
87+
<br><br>
88+
<div>
89+
<label for="filterModules">Filter modules:</label>
90+
<input type="text" id="filterModules" name="filterModules" style="width: 50%; height: 1.5em;" disabled>
91+
<button id="resetFilter" name="resetFilter" style="height: 1.5em;" disabled>Reset filter</button>
8392
</div>
84-
85-
<button id="loadModulesBtn" style="height: 1.5em;">Load modules</button>
86-
<button id="importProjectBtn" style="height: 1.5em;" disabled>Start import</button>
8793
8894
<div id="moduleList" style="width: 100%; height: 50%; overflow-y: scroll;">
8995
</div>

0 commit comments

Comments
 (0)