refactor: split CSS and JS into modular files (SRP)
This commit is contained in:
124
src/server/web/static/js/index/scheduler-config.js
Normal file
124
src/server/web/static/js/index/scheduler-config.js
Normal file
@@ -0,0 +1,124 @@
|
||||
/**
|
||||
* AniWorld - Scheduler Config Module
|
||||
*
|
||||
* Handles scheduler configuration and scheduled rescan settings.
|
||||
*
|
||||
* Dependencies: constants.js, api-client.js, ui-utils.js
|
||||
*/
|
||||
|
||||
var AniWorld = window.AniWorld || {};
|
||||
|
||||
AniWorld.SchedulerConfig = (function() {
|
||||
'use strict';
|
||||
|
||||
const API = AniWorld.Constants.API;
|
||||
|
||||
/**
|
||||
* Load scheduler configuration
|
||||
*/
|
||||
async function load() {
|
||||
try {
|
||||
const response = await AniWorld.ApiClient.get(API.SCHEDULER_CONFIG);
|
||||
if (!response) return;
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
const config = data.config;
|
||||
|
||||
// Update UI elements
|
||||
document.getElementById('scheduled-rescan-enabled').checked = config.enabled;
|
||||
document.getElementById('scheduled-rescan-time').value = config.time || '03:00';
|
||||
document.getElementById('auto-download-after-rescan').checked = config.auto_download_after_rescan;
|
||||
|
||||
// Update status display
|
||||
document.getElementById('next-rescan-time').textContent =
|
||||
config.next_run ? new Date(config.next_run).toLocaleString() : 'Not scheduled';
|
||||
document.getElementById('last-rescan-time').textContent =
|
||||
config.last_run ? new Date(config.last_run).toLocaleString() : 'Never';
|
||||
|
||||
const statusBadge = document.getElementById('scheduler-running-status');
|
||||
statusBadge.textContent = config.is_running ? 'Running' : 'Stopped';
|
||||
statusBadge.className = 'info-value status-badge ' + (config.is_running ? 'running' : 'stopped');
|
||||
|
||||
// Enable/disable time input based on checkbox
|
||||
toggleTimeInput();
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error loading scheduler config:', error);
|
||||
AniWorld.UI.showToast('Failed to load scheduler configuration', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Save scheduler configuration
|
||||
*/
|
||||
async function save() {
|
||||
try {
|
||||
const enabled = document.getElementById('scheduled-rescan-enabled').checked;
|
||||
const time = document.getElementById('scheduled-rescan-time').value;
|
||||
const autoDownload = document.getElementById('auto-download-after-rescan').checked;
|
||||
|
||||
const response = await AniWorld.ApiClient.post(API.SCHEDULER_CONFIG, {
|
||||
enabled: enabled,
|
||||
time: time,
|
||||
auto_download_after_rescan: autoDownload
|
||||
});
|
||||
|
||||
if (!response) return;
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
AniWorld.UI.showToast('Scheduler configuration saved successfully', 'success');
|
||||
await load();
|
||||
} else {
|
||||
AniWorld.UI.showToast('Failed to save config: ' + data.error, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error saving scheduler config:', error);
|
||||
AniWorld.UI.showToast('Failed to save scheduler configuration', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Test scheduled rescan
|
||||
*/
|
||||
async function testRescan() {
|
||||
try {
|
||||
const response = await AniWorld.ApiClient.post(API.SCHEDULER_TRIGGER, {});
|
||||
|
||||
if (!response) return;
|
||||
const data = await response.json();
|
||||
|
||||
if (data.success) {
|
||||
AniWorld.UI.showToast('Test rescan triggered successfully', 'success');
|
||||
} else {
|
||||
AniWorld.UI.showToast('Failed to trigger test rescan: ' + data.error, 'error');
|
||||
}
|
||||
} catch (error) {
|
||||
console.error('Error triggering test rescan:', error);
|
||||
AniWorld.UI.showToast('Failed to trigger test rescan', 'error');
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Toggle scheduler time input visibility
|
||||
*/
|
||||
function toggleTimeInput() {
|
||||
const enabled = document.getElementById('scheduled-rescan-enabled').checked;
|
||||
const timeConfig = document.getElementById('rescan-time-config');
|
||||
|
||||
if (enabled) {
|
||||
timeConfig.classList.add('enabled');
|
||||
} else {
|
||||
timeConfig.classList.remove('enabled');
|
||||
}
|
||||
}
|
||||
|
||||
// Public API
|
||||
return {
|
||||
load: load,
|
||||
save: save,
|
||||
testRescan: testRescan,
|
||||
toggleTimeInput: toggleTimeInput
|
||||
};
|
||||
})();
|
||||
Reference in New Issue
Block a user