Skip to content

Commit dd15302

Browse files
author
jacquesbach
committed
Remove Delete Architecture
1 parent 63b4ad2 commit dd15302

3 files changed

Lines changed: 4 additions & 185 deletions

File tree

routes.py

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1098,39 +1098,3 @@ def save_layout():
10981098
except Exception as e:
10991099
print(f"Server-Fehler: {str(e)}")
11001100
return jsonify({"error": "Interner Server Fehler", "details": str(e)}), 500
1101-
1102-
@api_bp.route('/api/cards', methods=['GET'])
1103-
def get_cards():
1104-
conn = get_db_connection()
1105-
c = conn.cursor()
1106-
c.execute("SELECT value FROM user_settings WHERE key = 'removed_cards'")
1107-
row = c.fetchone()
1108-
conn.close()
1109-
1110-
if row:
1111-
return jsonify({"removed": json.loads(row[0])}), 200
1112-
return jsonify({"removed": []}), 200
1113-
1114-
1115-
@api_bp.route('/api/cards', methods=['POST'])
1116-
def save_cards():
1117-
data = request.get_json()
1118-
password = data.get('pw')
1119-
1120-
if password != ADMIN_PASS:
1121-
return jsonify({"error": "Nicht autorisiert"}), 403
1122-
1123-
removed = data.get('removed', [])
1124-
1125-
conn = get_db_connection()
1126-
c = conn.cursor()
1127-
1128-
c.execute(
1129-
"INSERT OR REPLACE INTO user_settings (key, value) VALUES (?, ?)",
1130-
('removed_cards', json.dumps(removed))
1131-
)
1132-
1133-
conn.commit()
1134-
conn.close()
1135-
1136-
return jsonify({"status": "ok"}), 200

static/js/layout.js

Lines changed: 0 additions & 139 deletions
Original file line numberDiff line numberDiff line change
@@ -17,37 +17,6 @@ function initGridstack() {
1717
});
1818
}
1919

20-
function injectDeleteButtons() {
21-
document.querySelectorAll('.grid-stack-item').forEach(item => {
22-
23-
if (!item.id || !ALL_CARDS.includes(item.id)) return;
24-
25-
if (item.querySelector('.card-delete-btn')) return;
26-
27-
const btn = document.createElement('div');
28-
btn.className = 'card-delete-btn';
29-
btn.innerHTML = '🗑️';
30-
31-
Object.assign(btn.style, {
32-
position: 'absolute',
33-
top: '8px',
34-
right: '8px',
35-
cursor: 'pointer',
36-
fontSize: '14px',
37-
opacity: '0.7',
38-
display: currentPw ? 'block' : 'none',
39-
zIndex: 20
40-
});
41-
42-
btn.onclick = (e) => {
43-
e.stopPropagation();
44-
removeCard(item.id);
45-
};
46-
47-
item.appendChild(btn);
48-
});
49-
}
50-
5120
// 2. Layout speichern (Nur in DB und nur wenn PW da ist)
5221
async function saveLayout() {
5322
if (!dashboardGrid || !currentPw || currentPw === "") {
@@ -116,118 +85,10 @@ async function resetDatabaseLayout() {
11685
}
11786
}
11887

119-
let removedCards = [];
120-
121-
function removeCard(cardId) {
122-
if (!currentPw) return;
123-
124-
const el = document.getElementById(cardId);
125-
if (!el) return;
126-
127-
el.style.display = 'none';
128-
129-
if (!removedCards.includes(cardId)) {
130-
removedCards.push(cardId);
131-
}
132-
133-
saveRemovedCards();
134-
updateAdminCardList();
135-
}
136-
137-
function restoreCard(cardId) {
138-
const el = document.getElementById(cardId);
139-
if (!el) return;
140-
141-
el.style.display = '';
142-
143-
removedCards = removedCards.filter(id => id !== cardId);
144-
145-
saveRemovedCards();
146-
updateAdminCardList();
147-
}
148-
149-
async function loadRemovedCards() {
150-
const res = await fetch('/api/cards');
151-
const data = await res.json();
152-
153-
removedCards = data.removed || [];
154-
155-
removedCards.forEach(id => {
156-
const el = document.getElementById(id);
157-
if (el) el.style.display = 'none';
158-
});
159-
160-
updateAdminCardList();
161-
}
162-
163-
async function saveRemovedCards() {
164-
if (!currentPw) return;
165-
166-
await fetch('/api/cards', {
167-
method: 'POST',
168-
headers: { 'Content-Type': 'application/json' },
169-
body: JSON.stringify({
170-
removed: removedCards,
171-
pw: currentPw
172-
})
173-
});
174-
}
175-
176-
const ALL_CARDS = [
177-
"card-total",
178-
"card-live",
179-
"card-main-chart",
180-
"card-panel-chart",
181-
"card-hourly-heatmap",
182-
"card-donut-chart",
183-
"card-records",
184-
"card-roi",
185-
"card-yearly-heatmap",
186-
"card-forecast",
187-
"card-shap-details",
188-
"card-global-shap",
189-
"card-feature-importance"
190-
];
191-
192-
function updateAdminCardList() {
193-
const container = document.getElementById('cardManagerList');
194-
if (!container) return;
195-
196-
container.innerHTML = '';
197-
198-
ALL_CARDS.forEach(id => {
199-
const isRemoved = removedCards.includes(id);
200-
201-
const row = document.createElement('div');
202-
row.style.display = 'flex';
203-
row.style.justifyContent = 'space-between';
204-
row.style.marginBottom = '6px';
205-
206-
row.innerHTML = `
207-
<span>${id}</span>
208-
<button onclick="${isRemoved
209-
? `restoreCard('${id}')`
210-
: `removeCard('${id}')`}">
211-
${isRemoved ? '➕' : '🗑️'}
212-
</button>
213-
`;
214-
215-
container.appendChild(row);
216-
});
217-
}
218-
219-
function toggleDeleteButtons(show) {
220-
document.querySelectorAll('.card-delete-btn').forEach(btn => {
221-
btn.style.display = show ? 'block' : 'none';
222-
});
223-
}
224-
22588
document.addEventListener("DOMContentLoaded", async () => {
22689
// --- PHASE 1: Das Gerüst aufbauen ---
22790
initGridstack();
22891
await loadLayout(); // Wartet, bis Boxen aus DB oder LocalStorage da sind
229-
await loadRemovedCards();
230-
injectDeleteButtons();
23192

23293
// --- PHASE 2: Startwerte für Datumsfelder setzen ---
23394
const t = new Date().toISOString().split('T')[0];

static/js/script.js

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,14 @@ async function unlockAdmin() {
4040

4141
document.getElementById('unlockBtn').style.display = 'none';
4242
document.getElementById('adminArea').style.display = 'flex';
43-
43+
4444
if (dashboardGrid) {
45+
// Grid bearbeitbar machen
4546
dashboardGrid.setStatic(false);
4647
document.getElementById('dashboard-grid').classList.add('edit-mode');
4748
}
48-
49-
setTimeout(() => {
50-
injectDeleteButtons();
51-
toggleDeleteButtons(true);
52-
}, 100);
5349

5450
loadTariffs();
55-
updateAdminCardList();
5651
} else {
5752
alert("Falsches Passwort!");
5853
}
@@ -62,10 +57,9 @@ function closeAdmin() {
6257
currentPw = "";
6358
document.getElementById('adminArea').style.display = 'none';
6459
document.getElementById('unlockBtn').style.display = 'block';
65-
66-
toggleDeleteButtons(false);
67-
60+
6861
if (dashboardGrid) {
62+
// Grid wieder für alle sperren
6963
dashboardGrid.setStatic(true);
7064
document.getElementById('dashboard-grid').classList.remove('edit-mode');
7165
}

0 commit comments

Comments
 (0)