From e097facef73d449cbb76e71e7ef1e96171b756b4 Mon Sep 17 00:00:00 2001 From: Till Tomczak Date: Wed, 19 Feb 2025 21:22:11 +0100 Subject: [PATCH] dashboard fix --- Dashboard_V2/app.py | 122 +++++++++-- Dashboard_V2/templates/admin.html | 350 +++++++++++++++--------------- clickcandit.db | Bin 40960 -> 40960 bytes 3 files changed, 281 insertions(+), 191 deletions(-) diff --git a/Dashboard_V2/app.py b/Dashboard_V2/app.py index 1b816ef..03f53fd 100644 --- a/Dashboard_V2/app.py +++ b/Dashboard_V2/app.py @@ -444,40 +444,54 @@ def dashboard(): user_id = session['user_id'] db = get_db() - # User abfragen + # User und Settings ermitteln user = db.execute("SELECT * FROM users WHERE id = ?", (user_id,)).fetchone() if not user: flash("Benutzer nicht gefunden.", "red") return redirect(url_for('logout')) - # Settings aus user_settings settings = db.execute("SELECT * FROM user_settings WHERE user_id = ?", (user_id,)).fetchone() - # Standardwerte + # Standardwerte aus settings if not settings: wallpaper = '19.png' city = 'Berlin' show_forecast = True - bookmarks = [] + # (Dieses 'bookmarks' ist optional, kannst du weglassen, + # wenn du ausschließlich die DB-Tabelle 'bookmarks' nutzt) + bookmarks_setting = [] else: wallpaper = settings['wallpaper'] city = settings['city'] show_forecast = bool(settings['show_forecast']) if settings['bookmarks']: - bookmarks = settings['bookmarks'].split(",") + bookmarks_setting = settings['bookmarks'].split(",") # Nur als Fallback else: - bookmarks = [] + bookmarks_setting = [] - # Wetter holen (wenn gewünscht) - current_temp, weather_icon, forecast = get_weather(city) - if current_temp is None: - current_temp = "N/A" - weather_icon = "fa-question" - forecast = [] + # DB-Bookmarks für den eingeloggten User + user_bookmarks = db.execute(""" + SELECT id, title, url, icon_class + FROM bookmarks + WHERE user_id=? + ORDER BY id DESC + """, (user_id,)).fetchall() - # Domain, Logo usw. - domain = "example.com" - logo_path = url_for('static', filename='clickcandit.png') + # Notifications für diesen User (user_id) oder globale (user_id IS NULL) + notifications = db.execute(""" + SELECT id, user_id, message, created_at + FROM notifications + WHERE user_id=? OR user_id IS NULL + ORDER BY created_at DESC + """, (user_id,)).fetchall() + + # Ggf. Time-Entries (falls du sie zeigen willst) + time_entries = db.execute(""" + SELECT * + FROM time_entries + WHERE user_id=? + ORDER BY start_time DESC + """, (user_id,)).fetchall() # Beispiel-Apps user_app_chunks = [ @@ -499,19 +513,33 @@ def dashboard(): ] ] + # Wetter (Dummy oder API) + current_temp, weather_icon, forecast = get_weather(city) + if current_temp is None: + current_temp = "N/A" + weather_icon = "fa-question" + forecast = [] + + domain = "clickcandit.com/login" + logo_path = url_for('static', filename='clickcandit.png') + return render_template( 'dashboard.html', user=user['username'], wallpaper=wallpaper, city=city, show_forecast=show_forecast, - bookmarks=bookmarks, + bookmarks=bookmarks_setting, # falls noch gebraucht, sonst weglassen current_temp=current_temp, weather_icon=weather_icon, forecast=forecast, domain=domain, logo_path=logo_path, - user_app_chunks=user_app_chunks + user_app_chunks=user_app_chunks, + # Hier die neuen Variablen: + user_bookmarks=user_bookmarks, + notifications=notifications, + time_entries=time_entries ) # ------------------------------------------------------------ @@ -590,6 +618,66 @@ def inject_wallpaper(): "WALLPAPER_URL": url_for('static', filename='24.png') } +@app.route('/admin/notifications/multi', methods=['POST']) +def add_notification_multi(): + if not is_admin(): + flash("Zugriff verweigert!", "red") + return redirect(url_for('dashboard')) + + message = request.form.get('message') + target_list = request.form.getlist('target_users') # ['all'] oder ['1','2'] etc. + + if not message: + flash("Bitte eine Nachricht eingeben.", "red") + return redirect(url_for('admin_panel')) + + db = get_db() + + # Wenn 'all' in der Liste, Notification für alle + if 'all' in target_list: + db.execute("INSERT INTO notifications (user_id, message) VALUES (NULL, ?)", (message,)) + else: + # Sonst für jede ausgewählte ID + for uid in target_list: + db.execute("INSERT INTO notifications (user_id, message) VALUES (?, ?)", (uid, message)) + + db.commit() + flash("Benachrichtigungen erstellt!", "green") + return redirect(url_for('admin_panel')) + + +@app.route('/admin/bookmarks/multi', methods=['POST']) +def add_bookmarks_multi(): + if not is_admin(): + flash("Zugriff verweigert!", "red") + return redirect(url_for('dashboard')) + + # Checkboxen im Template: name='target_users' + target_list = request.form.getlist('target_users') # Liste der IDs (Strings) + title = request.form.get('title') + url_ = request.form.get('url') + icon = request.form.get('icon_class', 'fas fa-bookmark') + + # Ggf. Validierung + if not title or not url_: + flash("Bitte Titel und URL angeben!", "red") + return redirect(url_for('admin_panel')) + if not target_list: + flash("Bitte mindestens einen Benutzer auswählen!", "red") + return redirect(url_for('admin_panel')) + + db = get_db() + for uid in target_list: + db.execute( + "INSERT INTO bookmarks (user_id, title, url, icon_class) VALUES (?, ?, ?, ?)", + (uid, title, url_, icon) + ) + db.commit() + + flash("Neues Lesezeichen für mehrere Benutzer hinzugefügt!", "green") + return redirect(url_for('admin_panel')) + + @app.route('/save_settings', methods=['POST']) def save_settings(): """ diff --git a/Dashboard_V2/templates/admin.html b/Dashboard_V2/templates/admin.html index 8efc6ab..d2a5306 100644 --- a/Dashboard_V2/templates/admin.html +++ b/Dashboard_V2/templates/admin.html @@ -1,178 +1,180 @@ - - - - - - - Admin-Bereich - - -
-

Admin-Bereich

+ +{% extends "base.html" %} +{% block title %} +Admin-Bereich +{% endblock title %} - {% with messages = get_flashed_messages(with_categories=true) %} - {% if messages %} - {% for category, message in messages %} -
- {{ message }} -
- {% endfor %} - {% endif %} - {% endwith %} +{% block content %} +
+

Admin-Bereich

- -
+ + {% with messages = get_flashed_messages(with_categories=true) %} + {% if messages %} + {% for category, message in messages %} +
+ {{ message }} +
+ {% endfor %} + {% endif %} + {% endwith %} - -
-

Neuen Benutzer anlegen

-
- - - - - - - - - -
-
- - -
-

Benutzerverwaltung

- - - - - - - - - - - {% for u in users %} - - - - - - - {% endfor %} - -
IDUsernameAdmin?Aktion
{{ u.id }}{{ u.username }}{{ 'Ja' if u.is_admin else 'Nein' }} - - - Lesezeichen - - -
- -
-
-
- - -
-

Benachrichtigung erstellen

-
- - - - - - - -
-
- - -
-

Lesezeichen-Verwaltung

- - -
-

Für welche Benutzer soll dieses Lesezeichen gelten?

-
- {% for u in users %} - - {% endfor %} -
- - - - - - - - - - - -
- - - {% if single_user and bookmarks %} -

Lesezeichen für {{ single_user.username }}:

-
    - {% for bm in bookmarks %} -
  • - -
    - -
    -
  • - {% endfor %} -
- {% else %} -

Wähle oben in der Benutzerverwaltung „Lesezeichen“ für den gewünschten Nutzer, um bestehende Einträge zu sehen.

- {% endif %} -
- -
- - - Zurück zum Dashboard - + +
+ +
+

Neuen Benutzer anlegen

+
+
+ + +
+
+ + +
+
+ + Als Admin markieren +
+ +
- - \ No newline at end of file + + +
+

Benutzerverwaltung

+ + + + + + + + + + + {% for u in users %} + + + + + + + {% endfor %} + +
IDUsernameAdmin?Aktion
{{ u.id }}{{ u.username }}{{ 'Ja' if u.is_admin else 'Nein' }} + + + Lesezeichen + + +
+ +
+
+
+ + +
+

Benachrichtigung erstellen

+
+
+ + +
+
+

Für welche Benutzer?

+ +
+ + {% for u in users %} + + {% endfor %} +
+
+ +
+
+ + +
+

Lesezeichen-Verwaltung

+
+

Für welche Benutzer soll das Lesezeichen gelten?

+
+ {% for u in users %} + + {% endfor %} +
+ +
+ + +
+
+ + +
+
+ + +
+ +
+ + + {% if single_user and bookmarks %} +

Lesezeichen für {{ single_user.username }}:

+ + {% else %} +

Wähle oben in der Benutzerverwaltung „Lesezeichen“ für einen Nutzer aus, um konkrete Einträge zu sehen.

+ {% endif %} +
+ +
+ + + Zurück zum Dashboard + +
+{% endblock content %} diff --git a/clickcandit.db b/clickcandit.db index eaedbbb0e623d21f53eeaecb56d860fa268ed92e..ae91edfa314666c09d73876b0054b1fb8e5455ca 100644 GIT binary patch delta 266 zcmZoTz|?SnX@WGP&_o$$Mxl)f3-tvV7#LXjH!|>lMUGILYoQ}arSGE<9rS(xP+lk)Ska}$fQi9YQ?tz-@ihW$jQj@}_zwUzY~y#ZV+3h%bVS!+Xk}<& hWn`vjY-C|*VTNp!p_P%Lm4S(#fw6(Hk?Eoa1pq*DMl=8b delta 141 zcmZoTz|?SnX@WE(-$WT_M!t;+3-x*VFEOz2Z)D*A#{YzW<7NSah5V)r41&ze>Wq2$ zC7EfN$%!SI`FX`mJS@!eoJsll*|~{D*~JVD3_?JR1SUVRS72l0|G>ciVY6VuGycgR k{6#pJ_&XT*AM$r>7F4L=-`o*jBe0nzfk|L9Tf;AT0KIxAL;wH)