Skip to content

Commit

Permalink
Implement #85
Browse files Browse the repository at this point in the history
  • Loading branch information
LLytho committed Mar 28, 2021
1 parent 7e31976 commit 5415fd7
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 0 deletions.
16 changes: 16 additions & 0 deletions assets/scripts/collection.js
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,23 @@ export const newCollection = (selector, type, setup) => {
});
};

const applyFilter = (filterStr) => {
const multiWhitespacesRgx = new RegExp(/\s+/g);
filterStr = filterStr || "";
const cleanFilterStr = filterStr.trim().replace(multiWhitespacesRgx).toLowerCase();

collection.data.forEach((element) => {
const row = element.row;
const cleanName = row.name.trim().replace(multiWhitespacesRgx).toLowerCase();

element.visible = cleanName.includes(cleanFilterStr);
});

render();
}

return {
applyFilter,
setData,
updateItem,
deleteItem,
Expand Down
1 change: 1 addition & 0 deletions assets/styles/components.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@
@import "./components/managementNav.css";
@import "./components/errorBox.css";
@import "./components/card.css";
@import "./components/searchbar.css";
15 changes: 15 additions & 0 deletions assets/styles/components/searchbar.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
.searchbar-wrapper {

}

.searchbar {
border: none;
text-decoration: none;
outline: none;
}

.searchbar:hover, .searchbar:focus {
border: none;
text-decoration: none;
outline: none;
}
14 changes: 14 additions & 0 deletions views/heightmaps.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<div class="mb-4 flex justify-between items-center">
<div class="schematic-quick-actions"></div>
<div>
<span class="mr-4 border-solid border border-gray-300 px-1 py-1 rounded-lg">
<input type="text" class="searchbar"/>
<i class="fas fa-search"></i>
</span>
<button class="rounded-lg inline-flex items-center bg-green-600 text-white hover:bg-green-700 py-2 px-2 md:px-4"
onclick="WEL.heightmaps.create(heightmapCategories)">
<span>Upload</span>
Expand Down Expand Up @@ -118,6 +122,16 @@
}
},
});
document.querySelector(".searchbar").addEventListener("keyup", (e) => {
e.preventDefault();
if(collectionHeightmaps) {
const value = e.target.value;
collectionHeightmaps.applyFilter(value);
}
});
<% if (header.username) { %>
WEL.heightmaps.dragDrop(collectionHeightmaps.dom, heightmapCategories);
<% } %>
Expand Down
14 changes: 14 additions & 0 deletions views/schematics.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
<div class="mb-4 flex justify-between items-center">
<div class="schematic-quick-actions"></div>
<div>
<span class="mr-4 border-solid border border-gray-300 px-1 py-1 rounded-lg">
<input type="text" class="searchbar"/>
<i class="fas fa-search"></i>
</span>
<button class="rounded-lg inline-flex items-center bg-green-600 text-white hover:bg-green-700 py-2 px-2 md:px-4"
onclick="WEL.schematics.create(schematicCategories)">
<span>Upload</span>
Expand Down Expand Up @@ -190,6 +194,16 @@
},
<% } %>
});
document.querySelector(".searchbar").addEventListener("keyup", (e) => {
e.preventDefault();
if(collectionSchematic) {
const value = e.target.value;
collectionSchematic.applyFilter(value);
}
});
<% if (header.username) { %>
WEL.schematics.dragDrop(collectionSchematic.dom, schematicCategories);
<% } %>
Expand Down

0 comments on commit 5415fd7

Please sign in to comment.