Add toggle button for tree view. Use default settings for sortmode and direction.

This commit is contained in:
Sj-Si 2024-01-20 11:43:45 -05:00
parent 69f4f148dc
commit 2310cd66e5
5 changed files with 133 additions and 74 deletions

View File

@ -1,8 +1,55 @@
<div id='{tabname}_{extra_networks_tabname}_pane' class='extra-network-pane'>
<div id='{tabname}_{extra_networks_tabname}_tree' class='extra-network-tree'>
{tree_html}
<div class="extra-network-control">
<div class="extra-network-control--search">
<input
id="{tabname}_{extra_networks_tabname}_extra_search"
class="extra-network-control--search-text"
type="search"
placeholder="Filter files"
>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_sort"
class="extra-network-control--sort"
data-sortmode="{data_sortmode}"
data-sortkey="{data_sortkey}"
title="Sort by path"
onclick="extraNetworksControlSortOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="extra-network-control--sort-icon"></i>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_sort_dir"
class="extra-network-control--sort-dir"
data-sortdir="{data_sortdir}"
title="Sort ascending"
onclick="extraNetworksControlSortDirOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="extra-network-control--sort-dir-icon"></i>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_tree_view"
class="extra-network-control--tree-view extra-network-control--enabled"
title="Enable Tree View"
onclick="extraNetworksControlTreeViewOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="extra-network-control--tree-view-icon"></i>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_refresh"
class="extra-network-control--refresh"
title="Refresh page"
onclick="extraNetworksControlRefreshOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="extra-network-control--refresh-icon"></i>
</div>
</div>
<div id='{tabname}_{extra_networks_tabname}_cards' class='extra-network-cards'>
{items_html}
<div class="extra-network-pane-content">
<div id='{tabname}_{extra_networks_tabname}_tree' class='extra-network-tree'>
{tree_html}
</div>
<div id='{tabname}_{extra_networks_tabname}_cards' class='extra-network-cards'>
{items_html}
</div>
</div>
</div>

View File

@ -1,41 +1,4 @@
<div class="tree-list">
<div class="tree-list-controls">
<div class="tree-list-search">
<input
id="{tabname}_{extra_networks_tabname}_extra_search"
class="tree-list-search-text"
type="search"
placeholder="Filter files"
>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_sort"
class="tree-list-sort"
data-sortmode="path"
data-sortkey="sortPath-Ascending-640"
title="Sort by path"
onclick="extraNetworksTreeSortOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="tree-list-sort-icon"></i>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_sort_dir"
class="tree-list-sort-dir"
data-sortdir="Ascending"
title="Sort ascending"
onclick="extraNetworksTreeSortDirOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="tree-list-sort-dir-icon"></i>
</div>
<div
id="{tabname}_{extra_networks_tabname}_extra_refresh"
class="tree-list-refresh"
title="Refresh page"
onclick="extraNetworksTreeRefreshOnClick(event, '{tabname}', '{extra_networks_tabname}');"
>
<i class="tree-list-refresh-icon"></i>
</div>
</div>
<div class="tree-list-container">
{tree}
</div>

View File

@ -348,7 +348,7 @@ function extraNetworksTreeOnClick(event, tabname, extra_networks_tabname) {
}
}
function extraNetworksTreeSortOnClick(event, tabname, extra_networks_tabname) {
function extraNetworksControlSortOnClick(event, tabname, extra_networks_tabname) {
/**
* Handles `onclick` events for the Sort Mode button.
*
@ -382,7 +382,7 @@ function extraNetworksTreeSortOnClick(event, tabname, extra_networks_tabname) {
applyExtraNetworkSort(tabname + "_" + extra_networks_tabname);
}
function extraNetworksTreeSortDirOnClick(event, tabname, extra_networks_tabname) {
function extraNetworksControlSortDirOnClick(event, tabname, extra_networks_tabname) {
/**
* Handles `onclick` events for the Sort Direction button.
*
@ -403,7 +403,21 @@ function extraNetworksTreeSortDirOnClick(event, tabname, extra_networks_tabname)
applyExtraNetworkSort(tabname + "_" + extra_networks_tabname);
}
function extraNetworksTreeRefreshOnClick(event, tabname, extra_networks_tabname) {
function extraNetworksControlTreeViewOnClick(event, tabname, extra_networks_tabname) {
/**
* Handles `onclick` events for the Tree View button.
*
* Toggles the tree view in the extra networks pane.
*
* @param event The generated event.
* @param tabname The name of the active tab in the sd webui. Ex: txt2img, img2img, etc.
* @param extra_networks_tabname The id of the active extraNetworks tab. Ex: lora, checkpoints, etc.
*/
gradioApp().getElementById(tabname + "_" + extra_networks_tabname + "_tree").classList.toggle("hidden");
event.currentTarget.classList.toggle("extra-network-control--enabled");
}
function extraNetworksControlRefreshOnClick(event, tabname, extra_networks_tabname) {
/**
* Handles `onclick` events for the Refresh Page button.
*

View File

@ -526,10 +526,17 @@ class ExtraNetworksPage:
if "user_metadata" not in item:
self.read_user_metadata(item)
data_sortdir = shared.opts.extra_networks_card_order
data_sortmode = shared.opts.extra_networks_card_order_field.lower().replace("sort", "").replace(" ", "_").rstrip("_").strip()
data_sortkey = f"{data_sortmode}-{data_sortdir}-{len(self.items)}"
return self.pane_tpl.format(
**{
"tabname": tabname,
"extra_networks_tabname": self.extra_networks_tabname,
"data_sortmode": data_sortmode,
"data_sortkey": data_sortkey,
"data_sortdir": data_sortdir,
"tree_html": self.create_tree_view_html(tabname),
"items_html": self.create_card_view_html(tabname),
}

View File

@ -1178,6 +1178,13 @@ body.resizing .resize-handle {
height: calc(100vh - 24rem);
resize: vertical;
min-height: 52rem;
flex-direction: column;
}
.extra-network-pane .extra-network-pane-content {
display: flex;
flex: 1;
flex-direction: row;
}
.extra-network-pane .extra-network-tree {
@ -1234,7 +1241,7 @@ body.resizing .resize-handle {
display: none;
}
.extra-network-tree .tree-list .tree-list-controls {
.extra-network-pane .extra-network-control {
position: relative;
display: grid;
width: 100%;
@ -1248,8 +1255,7 @@ body.resizing .resize-handle {
border: none;
transition: background 33.333ms linear;
grid-template-rows: min-content;
grid-template-areas: "tree-list-controls-col-0 tree-list-controls-col-1 tree-list-controls-col-2 tree-list-controls-col-3";
grid-template-columns: minmax(0, auto) min-content min-content min-content;
grid-template-columns: minmax(0, auto) repeat(4, min-content);
grid-gap: 0.1rem;
align-items: start;
}
@ -1342,16 +1348,16 @@ body.resizing .resize-handle {
background-color: var(--neutral-700);
}
.extra-network-tree div.tree-list-content[data-selected] {
background-color: var(--neutral-300);
}
.extra-network-tree div.tree-list-content:hover {
-webkit-transition: all 0.05s ease-in-out;
transition: all 0.05s ease-in-out;
background-color: var(--neutral-200);
}
.extra-network-tree div.tree-list-content[data-selected] {
background-color: var(--neutral-300);
}
/* ==== CHEVRON ICON ACTIONS ==== */
/* Define the animation for the arrow when it is clicked. */
.extra-network-tree .tree-list-content-dir .tree-list-item-action-chevron {
@ -1378,7 +1384,7 @@ body.resizing .resize-handle {
/* ==== SEARCH INPUT ACTIONS ==== */
/* Add icon to left side of <input> */
.extra-network-tree .tree-list-controls .tree-list-search::before {
.extra-network-pane .extra-network-control .extra-network-control--search::before {
content: "🔎︎";
position: absolute;
margin: 0.5rem;
@ -1386,14 +1392,12 @@ body.resizing .resize-handle {
color: var(--input-placeholder-color);
}
.extra-network-tree .tree-list-controls .tree-list-search {
.extra-network-pane .extra-network-control .extra-network-control--search {
display: inline-flex;
grid-area: tree-list-controls-col-0;
position: relative;
margin: 0.5rem;
}
.extra-network-tree .tree-list-controls .tree-list-search .tree-list-search-text {
.extra-network-pane .extra-network-control .extra-network-control--search .extra-network-control--search-text {
border: 1px solid var(--button-secondary-border-color);
border-radius: 0.5rem;
color: var(--button-secondary-text-color);
@ -1404,7 +1408,7 @@ body.resizing .resize-handle {
}
/* <input> clear button (x on right side) styling */
.extra-network-tree .tree-list-controls .tree-list-search .tree-list-search-text::-webkit-search-cancel-button {
.extra-network-pane .extra-network-control .extra-network-control--search .extra-network-control--search-text::-webkit-search-cancel-button {
-webkit-appearance: none;
appearance: none;
cursor: pointer;
@ -1418,8 +1422,7 @@ body.resizing .resize-handle {
}
/* ==== SORT ICON ACTIONS ==== */
.extra-network-tree .tree-list-controls .tree-list-sort {
grid-area: tree-list-controls-col-1;
.extra-network-pane .extra-network-control .extra-network-control--sort {
padding: 0.25rem;
display: inline-flex;
cursor: pointer;
@ -1427,7 +1430,7 @@ body.resizing .resize-handle {
align-self: center;
}
.extra-network-tree .tree-list-controls .tree-list-sort .tree-list-sort-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort .extra-network-control--sort-icon {
height: 1.5rem;
width: 1.5rem;
mask-repeat: no-repeat;
@ -1436,25 +1439,24 @@ body.resizing .resize-handle {
background-color: var(--input-placeholder-color);
}
.extra-network-tree .tree-list-sort[data-sortmode="path"] .tree-list-sort-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort[data-sortmode="path"] .extra-network-control--sort-icon {
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M1 5C1 3.34315 2.34315 2 4 2H8.43845C9.81505 2 11.015 2.93689 11.3489 4.27239L11.7808 6H13.5H20C21.6569 6 23 7.34315 23 9V11C23 11.5523 22.5523 12 22 12C21.4477 12 21 11.5523 21 11V9C21 8.44772 20.5523 8 20 8H13.5H11.7808H4C3.44772 8 3 8.44772 3 9V10V19C3 19.5523 3.44772 20 4 20H9C9.55228 20 10 20.4477 10 21C10 21.5523 9.55228 22 9 22H4C2.34315 22 1 20.6569 1 19V10V9V5ZM3 6.17071C3.31278 6.06015 3.64936 6 4 6H9.71922L9.40859 4.75746C9.2973 4.3123 8.89732 4 8.43845 4H4C3.44772 4 3 4.44772 3 5V6.17071ZM20.1716 18.7574C20.6951 17.967 21 17.0191 21 16C21 13.2386 18.7614 11 16 11C13.2386 11 11 13.2386 11 16C11 18.7614 13.2386 21 16 21C17.0191 21 17.967 20.6951 18.7574 20.1716L21.2929 22.7071C21.6834 23.0976 22.3166 23.0976 22.7071 22.7071C23.0976 22.3166 23.0976 21.6834 22.7071 21.2929L20.1716 18.7574ZM13 16C13 14.3431 14.3431 13 16 13C17.6569 13 19 14.3431 19 16C19 17.6569 17.6569 19 16 19C14.3431 19 13 17.6569 13 16Z" fill="%23000000"></path></g></svg>');
}
.extra-network-tree .tree-list-sort[data-sortmode="name"] .tree-list-sort-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort[data-sortmode="name"] .extra-network-control--sort-icon {
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill-rule="evenodd" clip-rule="evenodd" d="M17.1841 6.69223C17.063 6.42309 16.7953 6.25 16.5002 6.25C16.2051 6.25 15.9374 6.42309 15.8162 6.69223L11.3162 16.6922C11.1463 17.07 11.3147 17.514 11.6924 17.6839C12.0701 17.8539 12.5141 17.6855 12.6841 17.3078L14.1215 14.1136H18.8789L20.3162 17.3078C20.4862 17.6855 20.9302 17.8539 21.308 17.6839C21.6857 17.514 21.8541 17.07 21.6841 16.6922L17.1841 6.69223ZM16.5002 8.82764L14.7965 12.6136H18.2039L16.5002 8.82764Z" fill="%231C274C"></path><path opacity="0.5" fill-rule="evenodd" clip-rule="evenodd" d="M2.25 7C2.25 6.58579 2.58579 6.25 3 6.25H13C13.4142 6.25 13.75 6.58579 13.75 7C13.75 7.41421 13.4142 7.75 13 7.75H3C2.58579 7.75 2.25 7.41421 2.25 7Z" fill="%231C274C"></path><path opacity="0.5" d="M2.25 12C2.25 11.5858 2.58579 11.25 3 11.25H10C10.4142 11.25 10.75 11.5858 10.75 12C10.75 12.4142 10.4142 12.75 10 12.75H3C2.58579 12.75 2.25 12.4142 2.25 12Z" fill="%231C274C"></path><path opacity="0.5" d="M2.25 17C2.25 16.5858 2.58579 16.25 3 16.25H8C8.41421 16.25 8.75 16.5858 8.75 17C8.75 17.4142 8.41421 17.75 8 17.75H3C2.58579 17.75 2.25 17.4142 2.25 17Z" fill="%231C274C"></path></g></svg>');
}
.extra-network-tree .tree-list-sort[data-sortmode="date_created"] .tree-list-sort-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort[data-sortmode="date_created"] .extra-network-control--sort-icon {
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M17 11C14.2386 11 12 13.2386 12 16C12 18.7614 14.2386 21 17 21C19.7614 21 22 18.7614 22 16C22 13.2386 19.7614 11 17 11ZM17 11V9M2 9V15.8C2 16.9201 2 17.4802 2.21799 17.908C2.40973 18.2843 2.71569 18.5903 3.09202 18.782C3.51984 19 4.0799 19 5.2 19H13M2 9V8.2C2 7.0799 2 6.51984 2.21799 6.09202C2.40973 5.71569 2.71569 5.40973 3.09202 5.21799C3.51984 5 4.0799 5 5.2 5H13.8C14.9201 5 15.4802 5 15.908 5.21799C16.2843 5.40973 16.5903 5.71569 16.782 6.09202C17 6.51984 17 7.0799 17 8.2V9M2 9H17M5 3V5M14 3V5M15 16H17M17 16H19M17 16V14M17 16V18" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>');
}
.extra-network-tree .tree-list-sort[data-sortmode="date_modified"] .tree-list-sort-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort[data-sortmode="date_modified"] .extra-network-control--sort-icon {
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M10 21H6.2C5.0799 21 4.51984 21 4.09202 20.782C3.71569 20.5903 3.40973 20.2843 3.21799 19.908C3 19.4802 3 18.9201 3 17.8V8.2C3 7.0799 3 6.51984 3.21799 6.09202C3.40973 5.71569 3.71569 5.40973 4.09202 5.21799C4.51984 5 5.0799 5 6.2 5H17.8C18.9201 5 19.4802 5 19.908 5.21799C20.2843 5.40973 20.5903 5.71569 20.782 6.09202C21 6.51984 21 7.0799 21 8.2V10M7 3V5M17 3V5M3 9H21M13.5 13.0001L7 13M10 17.0001L7 17M14 21L16.025 20.595C16.2015 20.5597 16.2898 20.542 16.3721 20.5097C16.4452 20.4811 16.5147 20.4439 16.579 20.399C16.6516 20.3484 16.7152 20.2848 16.8426 20.1574L21 16C21.5523 15.4477 21.5523 14.5523 21 14C20.4477 13.4477 19.5523 13.4477 19 14L14.8426 18.1574C14.7152 18.2848 14.6516 18.3484 14.601 18.421C14.5561 18.4853 14.5189 18.5548 14.4903 18.6279C14.458 18.7102 14.4403 18.7985 14.405 18.975L14 21Z" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>');
}
/* ==== SORT DIRECTION ICON ACTIONS ==== */
.extra-network-tree .tree-list-controls .tree-list-sort-dir {
grid-area: tree-list-controls-col-2;
.extra-network-pane .extra-network-control .extra-network-control--sort-dir {
padding: 0.25rem;
display: inline-flex;
cursor: pointer;
@ -1462,7 +1464,7 @@ body.resizing .resize-handle {
align-self: center;
}
.extra-network-tree .tree-list-controls .tree-list-sort-dir .tree-list-sort-dir-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort-dir .extra-network-control--sort-dir-icon {
height: 1.5rem;
width: 1.5rem;
mask-repeat: no-repeat;
@ -1471,17 +1473,16 @@ body.resizing .resize-handle {
background-color: var(--input-placeholder-color);
}
.extra-network-tree .tree-list-sort-dir[data-sortdir="Ascending"] .tree-list-sort-dir-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort-dir[data-sortdir="Ascending"] .extra-network-control--sort-dir-icon {
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M13 12H21M13 8H21M13 16H21M6 7V17M6 7L3 10M6 7L9 10" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>');
}
.extra-network-tree .tree-list-sort-dir[data-sortdir="Descending"] .tree-list-sort-dir-icon {
.extra-network-pane .extra-network-control .extra-network-control--sort-dir[data-sortdir="Descending"] .extra-network-control--sort-dir-icon {
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path d="M13 12H21M13 8H21M13 16H21M6 7V17M6 17L3 14M6 17L9 14" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"></path></g></svg>');
}
/* ==== REFRESH ICON ACTIONS ==== */
.extra-network-tree .tree-list-controls .tree-list-refresh {
grid-area: tree-list-controls-col-3;
/* ==== TREE VIEW ICON ACTIONS ==== */
.extra-network-pane .extra-network-control .extra-network-control--tree-view {
padding: 0.25rem;
display: inline-flex;
cursor: pointer;
@ -1489,7 +1490,34 @@ body.resizing .resize-handle {
align-self: center;
}
.extra-network-tree .tree-list-controls .tree-list-refresh .tree-list-refresh-icon {
.extra-network-pane .extra-network-control .extra-network-control--tree-view .extra-network-control--tree-view-icon {
height: 1.5rem;
width: 1.5rem;
mask-image: url('data:image/svg+xml,<svg viewBox="0 0 16 16" version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" fill="black"><g id="SVGRepo_bgCarrier" stroke-width="0"></g><g id="SVGRepo_tracerCarrier" stroke-linecap="round" stroke-linejoin="round"></g><g id="SVGRepo_iconCarrier"><path fill="black" d="M16 10v-4h-11v1h-2v-3h9v-4h-12v4h2v10h3v2h11v-4h-11v1h-2v-5h2v2z"></path></g></svg>');
mask-repeat: no-repeat;
mask-position: center center;
mask-size: 100%;
background-color: var(--input-placeholder-color);
}
.dark .extra-network-pane .extra-network-control .extra-network-control--enabled {
background-color: var(--neutral-700);
}
.dark .extra-network-pane .extra-network-control .extra-network-control--enabled {
background-color: var(--neutral-300);
}
/* ==== REFRESH ICON ACTIONS ==== */
.extra-network-pane .extra-network-control .extra-network-control--refresh {
padding: 0.25rem;
display: inline-flex;
cursor: pointer;
justify-self: center;
align-self: center;
}
.extra-network-pane .extra-network-control .extra-network-control--refresh .extra-network-control--refresh-icon {
height: 1.5rem;
width: 1.5rem;
mask-image: url('data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="black" stroke-width="2" stroke-linecap="round" stroke-linejoin="bevel"><path d="M21.5 2v6h-6M21.34 15.57a10 10 0 1 1-.57-8.38"/></svg>');
@ -1499,7 +1527,7 @@ body.resizing .resize-handle {
background-color: var(--input-placeholder-color);
}
.extra-network-tree .tree-list-refresh-icon:active {
.extra-network-pane .extra-network-control .extra-network-control--refresh-icon:active {
-ms-transform: rotate(180deg);
-webkit-transform: rotate(180deg);
transform: rotate(180deg);