Skip to content

Commit

Permalink
fix page refresh not re-applying sort/filter for AUTOMATIC1111#14588
Browse files Browse the repository at this point in the history
fix path sortkey not including the filename for AUTOMATIC1111#14588
  • Loading branch information
AUTOMATIC1111 authored and ruchej committed Sep 30, 2024
1 parent 195341b commit 35670e5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 13 deletions.
2 changes: 1 addition & 1 deletion javascript/extraNetworks.js
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function extraNetworksControlRefreshOnClick(event, tabname, extra_networks_tabna
* @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.
*/
var btn_refresh_internal = gradioApp().getElementById(tabname + "_extra_refresh_internal");
var btn_refresh_internal = gradioApp().getElementById(tabname + "_" + extra_networks_tabname + "_extra_refresh_internal");
btn_refresh_internal.dispatchEvent(new Event("click"));
}

Expand Down
23 changes: 11 additions & 12 deletions modules/ui_extra_networks.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,7 +559,7 @@ def get_sort_keys(self, path):
"date_created": int(mtime),
"date_modified": int(ctime),
"name": pth.name.lower(),
"path": str(pth.parent).lower(),
"path": str(pth).lower(),
}

def find_preview(self, path):
Expand Down Expand Up @@ -638,6 +638,7 @@ def tab_name_score(name):

return sorted(pages, key=lambda x: tab_scores[x.name])


def create_ui(interface: gr.Blocks, unrelated_tabs, tabname):
ui = ExtraNetworksUi()
ui.pages = []
Expand All @@ -648,8 +649,6 @@ def create_ui(interface: gr.Blocks, unrelated_tabs, tabname):

related_tabs = []

button_refresh = gr.Button("Refresh", elem_id=f"{tabname}_extra_refresh_internal", visible=False)

for page in ui.stored_extra_pages:
with gr.Tab(page.title, elem_id=f"{tabname}_{page.extra_networks_tabname}", elem_classes=["extra-page"]) as tab:
with gr.Column(elem_id=f"{tabname}_{page.extra_networks_tabname}_prompts", elem_classes=["extra-page-prompts"]):
Expand Down Expand Up @@ -678,6 +677,15 @@ def create_ui(interface: gr.Blocks, unrelated_tabs, tabname):
)
tab.select(fn=None, _js=jscode, inputs=[], outputs=[], show_progress=False)

def refresh():
for pg in ui.stored_extra_pages:
pg.refresh()
create_html()
return ui.pages_contents

button_refresh = gr.Button("Refresh", elem_id=f"{tabname}_{page.extra_networks_tabname}_extra_refresh_internal", visible=False)
button_refresh.click(fn=refresh, inputs=[], outputs=ui.pages).then(fn=lambda: None, _js="function(){ " + f"applyExtraNetworkFilter('{tabname}_{page.extra_networks_tabname}');" + " }")

def create_html():
ui.pages_contents = [pg.create_html(ui.tabname) for pg in ui.stored_extra_pages]

Expand All @@ -686,16 +694,7 @@ def pages_html():
create_html()
return ui.pages_contents

def refresh():
for pg in ui.stored_extra_pages:
pg.refresh()
create_html()
return ui.pages_contents

interface.load(fn=pages_html, inputs=[], outputs=ui.pages)
# NOTE: Event is manually fired in extraNetworks.js:extraNetworksTreeRefreshOnClick()
# button is unused and hidden at all times. Only used in order to fire this event.
button_refresh.click(fn=refresh, inputs=[], outputs=ui.pages)

return ui

Expand Down

0 comments on commit 35670e5

Please sign in to comment.