fix que / add auto
This commit is contained in:
@@ -343,6 +343,39 @@
|
||||
.btn-confirm:hover { background: #c99ef0; }
|
||||
.btn-confirm:disabled { background: #444; color: var(--muted); cursor: not-allowed; }
|
||||
|
||||
/* ── Auto toggle ── */
|
||||
.auto-toggle {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 0;
|
||||
border: 1px solid var(--border);
|
||||
border-radius: 8px;
|
||||
overflow: hidden;
|
||||
width: fit-content;
|
||||
font-size: 0.76rem;
|
||||
font-weight: 700;
|
||||
}
|
||||
.auto-toggle button {
|
||||
padding: 5px 12px;
|
||||
border: none;
|
||||
background: #1e1e30;
|
||||
color: var(--muted);
|
||||
cursor: pointer;
|
||||
transition: all .2s;
|
||||
}
|
||||
.auto-toggle button.active-manual { background: #2a2a40; color: var(--text); }
|
||||
.auto-toggle button.active-auto { background: rgba(180,130,220,0.25); color: var(--purple); }
|
||||
.cel-card.auto-on { border-color: rgba(180,130,220,0.6); box-shadow: 0 0 12px rgba(180,130,220,0.08); }
|
||||
.auto-badge {
|
||||
font-size: 0.7rem;
|
||||
background: rgba(180,130,220,0.15);
|
||||
color: var(--purple);
|
||||
border: 1px solid rgba(180,130,220,0.3);
|
||||
border-radius: 6px;
|
||||
padding: 2px 7px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.toast {
|
||||
position: fixed;
|
||||
bottom: 1.5rem;
|
||||
@@ -488,8 +521,10 @@
|
||||
}
|
||||
|
||||
function celebCard(town, type) {
|
||||
const cel = town[type];
|
||||
const label = TYPE_LABELS[type];
|
||||
const cel = town[type];
|
||||
const label = TYPE_LABELS[type];
|
||||
const autoKey = type === 'party' ? 'auto_party' : 'auto_triumph';
|
||||
const autoOn = !!town[autoKey];
|
||||
|
||||
let costsHtml = '';
|
||||
if (type === 'party') {
|
||||
@@ -512,19 +547,33 @@
|
||||
? `<div class="reason-box ${cel.status === 'cooldown' ? '' : 'error'}">${cel.reason}</div>`
|
||||
: '';
|
||||
|
||||
const btnLabel = cel.status === 'cooldown' ? `⏰ ${cel.reason}`
|
||||
: cel.status === 'unavailable' ? '✖ Μη διαθέσιμο'
|
||||
: `▶ Εκκίνηση ${label}`;
|
||||
const autoToggle = `
|
||||
<div class="auto-toggle" title="Αυτόματη εκτέλεση όταν ξεκλειδώσουν πόροι/cooldown">
|
||||
<button id="btn-manual-${town.town_id}-${type}"
|
||||
class="${!autoOn ? 'active-manual' : ''}"
|
||||
onclick="saveAutoSetting('${town.town_id}','${type}',false)">
|
||||
Χειροκίνητο
|
||||
</button>
|
||||
<button id="btn-auto-${town.town_id}-${type}"
|
||||
class="${autoOn ? 'active-auto' : ''}"
|
||||
onclick="saveAutoSetting('${town.town_id}','${type}',true)">
|
||||
⚡ Αυτόματο
|
||||
</button>
|
||||
</div>`;
|
||||
|
||||
return `
|
||||
<div class="cel-card ${cel.status}">
|
||||
<div class="cel-card-title">${label}</div>
|
||||
<div class="cel-card ${cel.status}${autoOn ? ' auto-on' : ''}">
|
||||
<div class="cel-card-title">
|
||||
${label}
|
||||
${autoOn ? '<span class="auto-badge">AUTO</span>' : ''}
|
||||
</div>
|
||||
${costsHtml}
|
||||
${reasonHtml}
|
||||
${autoToggle}
|
||||
<button class="cel-btn primary"
|
||||
${cel.available ? '' : 'disabled'}
|
||||
${(cel.available && !autoOn) ? '' : 'disabled'}
|
||||
onclick="openModal('${town.town_id}','${town.town_name}','${type}')">
|
||||
${cel.available ? `▶ Εκκίνηση` : (cel.status === 'cooldown' ? `⏰ Σε αναμονή` : `✖ Μη διαθέσιμο`)}
|
||||
${autoOn ? '⚡ Αυτόματο ενεργό' : cel.available ? '▶ Εκκίνηση' : (cel.status === 'cooldown' ? '⏰ Σε αναμονή' : '✖ Μη διαθέσιμο')}
|
||||
</button>
|
||||
</div>`;
|
||||
}
|
||||
@@ -534,6 +583,37 @@
|
||||
return n;
|
||||
}
|
||||
|
||||
// ── Auto-setting toggle ───────────────────────────────────
|
||||
async function saveAutoSetting(townId, type, enable) {
|
||||
const town = agoraData.find(t => t.town_id === townId);
|
||||
if (!town) return;
|
||||
|
||||
const payload = {
|
||||
player_id: PLAYER_ID,
|
||||
world_id: WORLD_ID,
|
||||
town_id: townId,
|
||||
auto_party: type === 'party' ? enable : !!town.auto_party,
|
||||
auto_triumph: type === 'triumph' ? enable : !!town.auto_triumph
|
||||
};
|
||||
|
||||
try {
|
||||
const r = await fetch('/dashboard/culture-settings', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
body: JSON.stringify(payload)
|
||||
});
|
||||
const d = await r.json();
|
||||
if (d.ok) {
|
||||
// Optimistically update local state and re-render card
|
||||
town[type === 'party' ? 'auto_party' : 'auto_triumph'] = enable;
|
||||
renderCards(town);
|
||||
showToast(enable ? `⚡ Αυτόματο ενεργό — ${TYPE_LABELS[type]}` : `✓ Χειροκίνητο — ${TYPE_LABELS[type]}`, 'ok');
|
||||
}
|
||||
} catch (e) {
|
||||
showToast(`❌ Αποτυχία αποθήκευσης: ${e}`, 'err');
|
||||
}
|
||||
}
|
||||
|
||||
// ── Modal ────────────────────────────────────────────────────────
|
||||
function openModal(townId, townName, celType) {
|
||||
pendingCmd = { townId, townName, celType };
|
||||
@@ -633,7 +713,10 @@
|
||||
<span class="log-town">${row.town_name}</span>
|
||||
<span class="log-type">${TYPE_LABELS[row.celebration_type] || row.celebration_type}</span>
|
||||
<span class="log-status ${row.status}">${row.status === 'success' ? '✅' : row.status === 'failed' ? '❌' : '⏳'}</span>
|
||||
<span class="log-msg">${costStr}${row.result_msg ? ' — ' + row.result_msg : ''}</span>`;
|
||||
<span class="log-msg">
|
||||
${row.source === 'auto' ? '<span class="auto-badge" style="margin-right:4px">AUTO</span>' : ''}
|
||||
${costStr}${row.result_msg ? ' — ' + row.result_msg : ''}
|
||||
</span>`;
|
||||
body.insertBefore(el, body.firstChild);
|
||||
});
|
||||
} catch (e) { /* silent */ }
|
||||
|
||||
Reference in New Issue
Block a user