refactor: Enhance checkpoint download functionality with new modal and manager integration

This commit is contained in:
Will Miao
2025-04-11 18:25:37 +08:00
parent 3df96034a1
commit 1db49a4dd4
10 changed files with 699 additions and 43 deletions

View File

@@ -2,6 +2,7 @@
import { PageControls } from './PageControls.js';
import { loadMoreCheckpoints, resetAndReload, refreshCheckpoints, fetchCivitai } from '../../api/checkpointApi.js';
import { showToast } from '../../utils/uiHelpers.js';
import { CheckpointDownloadManager } from '../../managers/CheckpointDownloadManager.js';
/**
* CheckpointsControls class - Extends PageControls for Checkpoint-specific functionality
@@ -11,6 +12,9 @@ export class CheckpointsControls extends PageControls {
// Initialize with 'checkpoints' page type
super('checkpoints');
// Initialize checkpoint download manager
this.downloadManager = new CheckpointDownloadManager();
// Register API methods specific to the Checkpoints page
this.registerCheckpointsAPI();
}
@@ -38,6 +42,11 @@ export class CheckpointsControls extends PageControls {
return await fetchCivitai();
},
// Add show download modal functionality
showDownloadModal: () => {
this.downloadManager.showDownloadModal();
},
// No clearCustomFilter implementation is needed for checkpoints
// as custom filters are currently only used for LoRAs
clearCustomFilter: async () => {

View File

@@ -103,13 +103,12 @@ export class PageControls {
fetchButton.addEventListener('click', () => this.fetchFromCivitai());
}
const downloadButton = document.querySelector('[data-action="download"]');
if (downloadButton) {
downloadButton.addEventListener('click', () => this.showDownloadModal());
}
if (this.pageType === 'loras') {
// Download button - LoRAs only
const downloadButton = document.querySelector('[data-action="download"]');
if (downloadButton) {
downloadButton.addEventListener('click', () => this.showDownloadModal());
}
// Bulk operations button - LoRAs only
const bulkButton = document.querySelector('[data-action="bulk"]');
if (bulkButton) {
@@ -349,14 +348,9 @@ export class PageControls {
}
/**
* Show download modal (LoRAs only)
* Show download modal
*/
showDownloadModal() {
if (this.pageType !== 'loras' || !this.api) {
console.error('Download modal is only available for LoRAs');
return;
}
this.api.showDownloadModal();
}