Polish auto-sync manager modal

Upgrade the Auto-Sync modal into a tabbed manager with a richer schedule board and a separate read-only Automation Pipelines tab for existing playlist_pipeline automations.
This commit is contained in:
Broque Thomas 2026-05-24 20:39:48 -07:00
parent 854141f903
commit 5421f3800e
2 changed files with 333 additions and 66 deletions

View file

@ -386,8 +386,9 @@ let _autoSyncScheduleState = {
playlists: [],
automations: [],
playlistSchedules: {},
automationManaged: [],
automationPipelines: [],
};
let _autoSyncActiveTab = 'schedule';
/**
* Fire-and-forget helper: send parsed playlist data to be mirrored on the backend.
@ -637,25 +638,26 @@ function autoSyncIsScheduleOwned(auto) {
function buildAutoSyncScheduleState(playlists, automations) {
const playlistSchedules = {};
const automationManaged = [];
automations.filter(autoSyncIsPipelineAutomation).forEach(auto => {
const automationPipelines = [];
const pipelineAutomations = automations.filter(autoSyncIsPipelineAutomation);
pipelineAutomations.forEach(auto => {
const playlistId = autoSyncPlaylistIdFromAutomation(auto);
const hours = auto.trigger_type === 'schedule' ? autoSyncHoursFromTrigger(auto.trigger_config || {}) : null;
if (playlistId && hours) {
if (playlistId && hours && autoSyncIsScheduleOwned(auto)) {
playlistSchedules[playlistId] = {
automation_id: auto.id,
automation_name: auto.name,
hours,
enabled: auto.enabled !== false && auto.enabled !== 0,
owned: autoSyncIsScheduleOwned(auto),
owned: true,
next_run: auto.next_run,
trigger_config: auto.trigger_config || {},
};
} else {
automationManaged.push(auto);
automationPipelines.push(auto);
}
});
return { playlists, automations, playlistSchedules, automationManaged };
return { playlists, automations, playlistSchedules, automationPipelines };
}
async function openAutoSyncScheduleModal() {
@ -679,7 +681,7 @@ async function openAutoSyncScheduleModal() {
</div>
`;
overlay.style.display = 'flex';
overlay.addEventListener('click', e => { if (e.target === overlay) closeAutoSyncScheduleModal(); }, { once: true });
overlay.onclick = e => { if (e.target === overlay) closeAutoSyncScheduleModal(); };
await refreshAutoSyncScheduleModal();
}
@ -719,7 +721,49 @@ function renderAutoSyncScheduleModal() {
const overlay = document.getElementById('auto-sync-schedule-modal');
if (!overlay) return;
const { playlists, playlistSchedules, automationManaged } = _autoSyncScheduleState;
const { playlists, playlistSchedules, automationPipelines } = _autoSyncScheduleState;
const scheduledCount = Object.keys(playlistSchedules).length;
const enabledCount = Object.values(playlistSchedules).filter(s => s.enabled).length;
const pipelineCount = automationPipelines.length;
const totalTracks = playlists.reduce((sum, p) => sum + (parseInt(p.track_count, 10) || 0), 0);
const scheduleActive = _autoSyncActiveTab === 'schedule';
const automationsActive = _autoSyncActiveTab === 'automations';
const schedulePanel = renderAutoSyncSchedulePanel(playlists, playlistSchedules);
const automationPanel = renderAutoSyncAutomationPanel(automationPipelines, playlists);
overlay.innerHTML = `
<div class="auto-sync-modal">
<div class="auto-sync-header">
<div>
<div class="auto-sync-eyebrow">Playlist automation</div>
<h3>Auto-Sync Manager</h3>
<p>Schedule mirrored playlists through the same playlist-pipeline engine used by Automations.</p>
</div>
<button class="auto-sync-close" onclick="closeAutoSyncScheduleModal()">&times;</button>
</div>
<div class="auto-sync-summary">
<div><span>${scheduledCount}</span><small>scheduled playlists</small></div>
<div><span>${enabledCount}</span><small>active schedules</small></div>
<div><span>${pipelineCount}</span><small>automation pipelines</small></div>
<div><span>${totalTracks}</span><small>mirrored tracks</small></div>
</div>
<div class="auto-sync-tabs">
<button class="${scheduleActive ? 'active' : ''}" onclick="setAutoSyncTab('schedule')">Schedule Board</button>
<button class="${automationsActive ? 'active' : ''}" onclick="setAutoSyncTab('automations')">Automation Pipelines</button>
</div>
<div class="auto-sync-tab-panel ${scheduleActive ? 'active' : ''}" id="auto-sync-schedule-panel">${schedulePanel}</div>
<div class="auto-sync-tab-panel ${automationsActive ? 'active' : ''}" id="auto-sync-automation-panel">${automationPanel}</div>
</div>
`;
}
function setAutoSyncTab(tab) {
_autoSyncActiveTab = tab === 'automations' ? 'automations' : 'schedule';
renderAutoSyncScheduleModal();
}
function renderAutoSyncSchedulePanel(playlists, playlistSchedules) {
const grouped = playlists.reduce((acc, p) => {
const key = p.source || 'other';
if (!acc[key]) acc[key] = [];
@ -737,7 +781,7 @@ function renderAutoSyncScheduleModal() {
return `
<div class="auto-sync-playlist ${schedule ? 'scheduled' : ''}" draggable="true" data-playlist-id="${p.id}" ondragstart="autoSyncDragStart(event)">
<div class="auto-sync-playlist-name">${_esc(p.name)}</div>
<div class="auto-sync-playlist-meta">${p.track_count || 0} tracks · ${_esc(assigned)}</div>
<div class="auto-sync-playlist-meta">${p.track_count || 0} tracks &middot; ${_esc(assigned)}</div>
</div>
`;
}).join('')}
@ -753,29 +797,20 @@ function renderAutoSyncScheduleModal() {
<small>${assigned.length}</small>
</div>
<div class="auto-sync-column-list">
${assigned.length ? assigned.map(p => autoSyncScheduledCardHtml(p, playlistSchedules[p.id])).join('') : '<div class="auto-sync-drop-hint">Drop playlists here</div>'}
${assigned.length ? assigned.map(p => autoSyncScheduledCardHtml(p, playlistSchedules[p.id])).join('') : '<div class="auto-sync-drop-hint"><strong>Drop here</strong><span>Schedule playlists at this interval</span></div>'}
</div>
</div>
`;
}).join('');
const managedHtml = automationManaged.length ? `
<div class="auto-sync-managed">
<div class="auto-sync-managed-title">Automation-managed pipelines</div>
${automationManaged.map(a => `<span title="${_escAttr(_autoFormatTrigger(a.trigger_type, a.trigger_config || {}))}">${_esc(a.name || 'Playlist Pipeline')}</span>`).join('')}
</div>
` : '';
overlay.innerHTML = `
<div class="auto-sync-modal">
<div class="auto-sync-header">
<div>
<h3>Auto-Sync Schedule</h3>
<p>Drag mirrored playlists into an interval. Each placement creates or updates a matching playlist-pipeline automation.</p>
</div>
<button class="auto-sync-close" onclick="closeAutoSyncScheduleModal()">&times;</button>
return `
<div class="auto-sync-board-intro">
<div>
<strong>Drag playlists into an interval</strong>
<span>Each placement creates or updates an Auto-Sync-owned playlist-pipeline automation.</span>
</div>
${managedHtml}
<button onclick="refreshAutoSyncScheduleModal()">Refresh</button>
</div>
<div class="auto-sync-body">
<aside class="auto-sync-sidebar">
<div class="auto-sync-sidebar-title">Mirrored playlists</div>
@ -783,22 +818,61 @@ function renderAutoSyncScheduleModal() {
</aside>
<main class="auto-sync-board">${bucketHtml}</main>
</div>
`;
}
function renderAutoSyncAutomationPanel(automationPipelines, playlists) {
if (!automationPipelines.length) {
return '<div class="auto-sync-automation-empty">No Automations-page playlist pipelines found.</div>';
}
return `
<div class="auto-sync-automation-intro">
<strong>Read-only Automations-page pipelines</strong>
<span>These use the playlist pipeline but are managed from the Automations page, so this modal only displays them.</span>
</div>
<div class="auto-sync-automation-list">
${automationPipelines.map(auto => autoSyncAutomationCardHtml(auto, playlists)).join('')}
</div>
`;
}
function autoSyncAutomationCardHtml(auto, playlists) {
const cfg = auto.action_config || {};
const playlistId = autoSyncPlaylistIdFromAutomation(auto);
const playlist = playlistId ? playlists.find(p => parseInt(p.id, 10) === playlistId) : null;
const target = cfg.all === true || cfg.all === 'true'
? 'All refreshable mirrored playlists'
: playlist ? playlist.name : playlistId ? `Playlist #${playlistId}` : 'Custom pipeline target';
const trigger = _autoFormatTrigger(auto.trigger_type, auto.trigger_config || {});
const enabled = auto.enabled !== false && auto.enabled !== 0;
const next = auto.next_run ? autoSyncNextRunLabel(auto.next_run) : 'not scheduled';
return `
<div class="auto-sync-automation-card">
<div class="auto-sync-automation-main">
<div class="auto-sync-automation-title-row">
<span class="auto-sync-status ${enabled ? 'enabled' : 'disabled'}">${enabled ? 'Enabled' : 'Disabled'}</span>
<strong>${_esc(auto.name || 'Playlist Pipeline')}</strong>
</div>
<div class="auto-sync-automation-meta">
<span>${_esc(trigger)}</span>
<span>${_esc(target)}</span>
<span>${_esc(next)}</span>
</div>
</div>
<div class="auto-sync-automation-lock">Read only</div>
</div>
`;
}
function autoSyncScheduledCardHtml(playlist, schedule) {
const enabled = schedule?.enabled !== false;
const owned = schedule?.owned === true;
return `
<div class="auto-sync-scheduled-card ${enabled ? '' : 'disabled'}" draggable="true" data-playlist-id="${playlist.id}" ondragstart="autoSyncDragStart(event)">
<div>
<div class="auto-sync-scheduled-name">${_esc(playlist.name)}</div>
<div class="auto-sync-scheduled-meta">${_esc(autoSyncSourceLabel(playlist.source))} · ${playlist.track_count || 0} tracks${schedule?.next_run ? ` · ${autoSyncNextRunLabel(schedule.next_run)}` : ''}${owned ? '' : ' · Automations page'}</div>
<div class="auto-sync-scheduled-meta">${_esc(autoSyncSourceLabel(playlist.source))} &middot; ${playlist.track_count || 0} tracks${schedule?.next_run ? ` &middot; ${autoSyncNextRunLabel(schedule.next_run)}` : ''}</div>
</div>
${owned
? `<button onclick="event.stopPropagation(); unscheduleAutoSyncPlaylist(${playlist.id})" title="Remove this Auto-Sync schedule">&times;</button>`
: '<span class="auto-sync-lock" title="Managed from Automations page">Lock</span>'}
<button onclick="event.stopPropagation(); unscheduleAutoSyncPlaylist(${playlist.id})" title="Remove this Auto-Sync schedule">&times;</button>
</div>
`;
}
@ -839,10 +913,6 @@ async function saveAutoSyncPlaylistSchedule(playlistId, hours) {
const playlist = _autoSyncScheduleState.playlists.find(p => parseInt(p.id, 10) === parseInt(playlistId, 10));
if (!playlist) return;
const existing = _autoSyncScheduleState.playlistSchedules[playlistId];
if (existing && !existing.owned) {
showToast('This playlist pipeline is managed from the Automations page for now.', 'info');
return;
}
const payload = {
name: `Auto-Sync: ${playlist.name}`,
trigger_type: 'schedule',

View file

@ -11196,9 +11196,9 @@ body.helper-mode-active #dashboard-activity-feed:hover {
}
.auto-sync-modal {
width: min(1420px, calc(100vw - 48px));
height: min(820px, calc(100vh - 48px));
background: rgba(18, 20, 28, 0.98);
width: min(1500px, calc(100vw - 40px));
height: min(860px, calc(100vh - 40px));
background: rgba(17, 19, 27, 0.98);
border: 1px solid rgba(255, 255, 255, 0.12);
border-radius: 8px;
box-shadow: 0 28px 80px rgba(0, 0, 0, 0.5);
@ -11216,6 +11216,14 @@ body.helper-mode-active #dashboard-activity-feed:hover {
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.auto-sync-eyebrow {
margin-bottom: 6px;
color: #7dd3fc;
font-size: 11px;
font-weight: 800;
text-transform: uppercase;
}
.auto-sync-header h3 {
margin: 0 0 6px;
color: rgba(255, 255, 255, 0.92);
@ -11246,6 +11254,116 @@ body.helper-mode-active #dashboard-activity-feed:hover {
color: #fff;
}
.auto-sync-summary {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 1px;
background: rgba(255, 255, 255, 0.08);
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}
.auto-sync-summary div {
padding: 14px 20px;
background: rgba(255, 255, 255, 0.025);
}
.auto-sync-summary span {
display: block;
color: rgba(255, 255, 255, 0.92);
font-size: 20px;
font-weight: 800;
}
.auto-sync-summary small {
display: block;
margin-top: 2px;
color: rgba(255, 255, 255, 0.42);
font-size: 11px;
font-weight: 700;
text-transform: uppercase;
}
.auto-sync-tabs {
display: flex;
gap: 8px;
padding: 12px 18px;
border-bottom: 1px solid rgba(255, 255, 255, 0.08);
background: rgba(255, 255, 255, 0.018);
}
.auto-sync-tabs button {
height: 32px;
padding: 0 14px;
border: 1px solid rgba(255, 255, 255, 0.09);
border-radius: 6px;
background: rgba(255, 255, 255, 0.04);
color: rgba(255, 255, 255, 0.58);
cursor: pointer;
font-size: 12px;
font-weight: 700;
}
.auto-sync-tabs button:hover,
.auto-sync-tabs button.active {
border-color: rgba(56, 189, 248, 0.35);
background: rgba(56, 189, 248, 0.12);
color: #e0f2fe;
}
.auto-sync-tab-panel {
display: none;
min-height: 0;
flex: 1;
}
.auto-sync-tab-panel.active {
display: flex;
flex-direction: column;
}
.auto-sync-board-intro,
.auto-sync-automation-intro {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 12px 18px;
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
background: rgba(56, 189, 248, 0.035);
}
.auto-sync-board-intro strong,
.auto-sync-automation-intro strong {
display: block;
color: rgba(255, 255, 255, 0.86);
font-size: 13px;
}
.auto-sync-board-intro span,
.auto-sync-automation-intro span {
display: block;
margin-top: 2px;
color: rgba(255, 255, 255, 0.46);
font-size: 12px;
}
.auto-sync-board-intro button {
height: 30px;
padding: 0 12px;
border: 1px solid rgba(255, 255, 255, 0.1);
border-radius: 6px;
background: rgba(255, 255, 255, 0.05);
color: rgba(255, 255, 255, 0.7);
cursor: pointer;
font-size: 12px;
font-weight: 700;
}
.auto-sync-board-intro button:hover {
background: rgba(255, 255, 255, 0.1);
color: #fff;
}
.auto-sync-body {
min-height: 0;
flex: 1;
@ -11262,7 +11380,7 @@ body.helper-mode-active #dashboard-activity-feed:hover {
}
.auto-sync-sidebar-title {
padding: 16px 18px 12px;
padding: 16px 18px 10px;
color: rgba(255, 255, 255, 0.72);
font-size: 12px;
font-weight: 700;
@ -11295,7 +11413,7 @@ body.helper-mode-active #dashboard-activity-feed:hover {
}
.auto-sync-playlist {
padding: 10px;
padding: 11px 10px;
margin-bottom: 8px;
}
@ -11331,7 +11449,7 @@ body.helper-mode-active #dashboard-activity-feed:hover {
overflow-x: auto;
padding: 18px;
display: grid;
grid-template-columns: repeat(10, minmax(170px, 1fr));
grid-template-columns: repeat(10, minmax(185px, 1fr));
gap: 12px;
}
@ -11381,6 +11499,22 @@ body.helper-mode-active #dashboard-activity-feed:hover {
padding: 18px 10px;
}
.auto-sync-drop-hint strong,
.auto-sync-drop-hint span {
display: block;
}
.auto-sync-drop-hint strong {
color: rgba(255, 255, 255, 0.52);
font-size: 12px;
}
.auto-sync-drop-hint span {
margin-top: 3px;
color: rgba(255, 255, 255, 0.32);
font-size: 11px;
}
.auto-sync-loading,
.auto-sync-error {
padding: 48px;
@ -11414,40 +11548,103 @@ body.helper-mode-active #dashboard-activity-feed:hover {
background: rgba(239, 68, 68, 0.12);
}
.auto-sync-lock {
align-self: flex-start;
padding: 4px 6px;
border-radius: 5px;
background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.38);
.auto-sync-automation-list {
min-height: 0;
overflow-y: auto;
padding: 18px;
display: flex;
flex-direction: column;
gap: 10px;
}
.auto-sync-automation-card {
display: flex;
align-items: center;
justify-content: space-between;
gap: 16px;
padding: 14px 16px;
border: 1px solid rgba(255, 255, 255, 0.08);
border-radius: 8px;
background: rgba(255, 255, 255, 0.035);
}
.auto-sync-automation-card:hover {
border-color: rgba(255, 255, 255, 0.14);
background: rgba(255, 255, 255, 0.055);
}
.auto-sync-automation-main {
min-width: 0;
flex: 1;
}
.auto-sync-automation-title-row {
display: flex;
align-items: center;
gap: 10px;
min-width: 0;
}
.auto-sync-automation-title-row strong {
color: rgba(255, 255, 255, 0.88);
font-size: 14px;
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
}
.auto-sync-status {
padding: 3px 7px;
border-radius: 999px;
font-size: 10px;
font-weight: 700;
font-weight: 800;
text-transform: uppercase;
flex-shrink: 0;
}
.auto-sync-managed {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 24px;
border-bottom: 1px solid rgba(255, 255, 255, 0.07);
color: rgba(255, 255, 255, 0.48);
font-size: 12px;
overflow-x: auto;
.auto-sync-status.enabled {
background: rgba(34, 197, 94, 0.14);
color: #4ade80;
}
.auto-sync-managed-title {
color: rgba(255, 255, 255, 0.72);
font-weight: 700;
.auto-sync-status.disabled {
background: rgba(148, 163, 184, 0.14);
color: #94a3b8;
}
.auto-sync-automation-meta {
display: flex;
flex-wrap: wrap;
gap: 8px;
margin-top: 8px;
}
.auto-sync-automation-meta span {
padding: 4px 8px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.05);
color: rgba(255, 255, 255, 0.48);
font-size: 11px;
}
.auto-sync-automation-lock {
padding: 6px 9px;
border-radius: 6px;
background: rgba(255, 255, 255, 0.06);
color: rgba(255, 255, 255, 0.42);
font-size: 11px;
font-weight: 800;
text-transform: uppercase;
flex-shrink: 0;
}
.auto-sync-managed span {
padding: 4px 8px;
border-radius: 999px;
background: rgba(255, 255, 255, 0.06);
white-space: nowrap;
.auto-sync-automation-empty {
margin: 24px;
padding: 44px;
border: 1px dashed rgba(255, 255, 255, 0.12);
border-radius: 8px;
color: rgba(255, 255, 255, 0.42);
text-align: center;
}
/* Enhanced Progress Bar Animation */