View all local versions answers "every local version of this model", but the listing request still carried the active folder: versions moved to another folder silently disappeared, and a group-by-model card's version count (counted across the library) no longer matched the list it opened. - suspend the folder filter when the view starts, remember it, and show the root selection so the sidebar and the grid agree - restore the folder when the filter is cleared; keep it suspended across a page reload - picking a folder while the filter is active now exits it instead of being silently ignored (the view is library-wide) - hand a suspended folder back to its own page when another model page clears the stale filter - backend contract unchanged: the client simply omits `folder` while the view is active Tests cover the query params, folder suspend/restore/foreign handoff and the sidebar folder handoff.
114 lines
3.9 KiB
JavaScript
114 lines
3.9 KiB
JavaScript
// CheckpointsControls.js - Specific implementation for the Checkpoints page
|
|
import { PageControls } from './PageControls.js';
|
|
import { getModelApiClient, resetAndReload } from '../../api/modelApiFactory.js';
|
|
import { getSessionItem, removeSessionItem } from '../../utils/storageHelpers.js';
|
|
import { downloadManager } from '../../managers/DownloadManager.js';
|
|
|
|
/**
|
|
* CheckpointsControls class - Extends PageControls for Checkpoint-specific functionality
|
|
*/
|
|
export class CheckpointsControls extends PageControls {
|
|
constructor() {
|
|
// Initialize with 'checkpoints' page type
|
|
super('checkpoints');
|
|
|
|
// Register API methods specific to the Checkpoints page
|
|
this.registerCheckpointsAPI();
|
|
|
|
// Check for custom filters (e.g., from recipe navigation)
|
|
this.checkCustomFilters();
|
|
}
|
|
|
|
/**
|
|
* Register Checkpoint-specific API methods
|
|
*/
|
|
registerCheckpointsAPI() {
|
|
const checkpointsAPI = {
|
|
// Core API functions
|
|
loadMoreModels: async (resetPage = false, updateFolders = false) => {
|
|
return await getModelApiClient().loadMoreWithVirtualScroll(resetPage, updateFolders);
|
|
},
|
|
|
|
resetAndReload: async (updateFolders = false) => {
|
|
return await resetAndReload(updateFolders);
|
|
},
|
|
|
|
|
|
// Add fetch from Civitai functionality for checkpoints
|
|
fetchFromCivitai: async () => {
|
|
return await getModelApiClient().fetchCivitaiMetadata();
|
|
},
|
|
|
|
// Add show download modal functionality
|
|
showDownloadModal: () => {
|
|
downloadManager.showDownloadModal();
|
|
},
|
|
|
|
toggleBulkMode: () => {
|
|
if (window.bulkManager) {
|
|
window.bulkManager.toggleBulkMode();
|
|
} else {
|
|
console.error('Bulk manager not available');
|
|
}
|
|
},
|
|
|
|
clearCustomFilter: async () => {
|
|
await this.clearCustomFilter();
|
|
}
|
|
};
|
|
|
|
// Register the API
|
|
this.registerAPI(checkpointsAPI);
|
|
}
|
|
|
|
/**
|
|
* Check for custom filters sent from other pages (e.g., recipe modal)
|
|
*/
|
|
checkCustomFilters() {
|
|
const filterCheckpointHash = getSessionItem('recipe_to_checkpoint_filterHash');
|
|
const filterRecipeName = getSessionItem('filterCheckpointRecipeName');
|
|
|
|
if (filterCheckpointHash && filterRecipeName) {
|
|
const indicator = document.getElementById('customFilterIndicator');
|
|
const filterText = indicator?.querySelector('.customFilterText');
|
|
|
|
if (indicator && filterText) {
|
|
indicator.classList.remove('hidden');
|
|
|
|
const displayText = `Viewing checkpoint from: ${filterRecipeName}`;
|
|
filterText.textContent = this._truncateText(displayText, 30);
|
|
filterText.setAttribute('title', displayText);
|
|
|
|
const filterElement = indicator.querySelector('.filter-active');
|
|
if (filterElement) {
|
|
filterElement.classList.add('animate');
|
|
setTimeout(() => filterElement.classList.remove('animate'), 600);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Clear checkpoint custom filter and reload
|
|
*/
|
|
async clearCustomFilter() {
|
|
// Check for View Local Versions filter first
|
|
if (this.isVlmActive()) {
|
|
this.clearVlmFilterState();
|
|
await resetAndReload();
|
|
return;
|
|
}
|
|
|
|
removeSessionItem('recipe_to_checkpoint_filterHash');
|
|
removeSessionItem('recipe_to_checkpoint_filterHashes');
|
|
removeSessionItem('filterCheckpointRecipeName');
|
|
|
|
const indicator = document.getElementById('customFilterIndicator');
|
|
if (indicator) {
|
|
indicator.classList.add('hidden');
|
|
}
|
|
|
|
await resetAndReload();
|
|
}
|
|
}
|