diff --git a/app.py b/app.py index cda5edb..64dac6e 100644 --- a/app.py +++ b/app.py @@ -24,6 +24,36 @@ login_manager.login_view = 'login' login_manager.init_app(app) +def rgb_to_hex(rgb_string): + # Split the RGB string into individual components + rgb_list = rgb_string.split(',') + + # Convert each component to an integer + r = int(rgb_list[0]) + g = int(rgb_list[1]) + b = int(rgb_list[2]) + + # Convert the integers to hexadecimal strings and concatenate them + hex_string = "#{:02x}{:02x}{:02x}".format(r, g, b) + + return hex_string + +def hex_to_rgb(hex_string): + # Remove the '#' character if present + hex_string = hex_string.lstrip('#') + + # Convert the hexadecimal string to integers + r = int(hex_string[0:2], 16) + g = int(hex_string[2:4], 16) + b = int(hex_string[4:6], 16) + + # Create the RGB string + rgb_string = "{},{},{}".format(r, g, b) + + return rgb_string + + + @login_manager.user_loader def load_user(user_id): return User.get(user_id) @@ -297,12 +327,12 @@ def habit_list_create(): @app.route('/profile') @login_required def profile(): - print(current_user.name, current_user.email) return render_template( "profile.html", name=current_user.name, email=current_user.email, profile_image_url=current_user.profile_image, + color = rgb_to_hex(current_user.heatmap_color), title="Profil", ) @@ -324,6 +354,7 @@ def profile_change(): name=current_user.name, email=current_user.email, profile_image_url=current_user.profile_image, + color=rgb_to_hex(current_user.heatmap_color), ) @@ -468,6 +499,7 @@ def password_change(): name=current_user.name, email=current_user.email, profile_image_url=current_user.profile_image, + color=rgb_to_hex(current_user.heatmap_color), ) @@ -541,6 +573,23 @@ def upload_profile_image(): return redirect(url_for('profile')) +@app.route('/save_color', methods=['POST']) +def save_heatmap_color(): + # Get the color value from the form + new_color = request.form['color'] + current_user.heatmap_color = hex_to_rgb(new_color) + current_user.update() + + # Back to profile + return render_template( + "profile.html", + name=current_user.name, + email=current_user.email, + profile_image_url=current_user.profile_image, + color=rgb_to_hex(current_user.heatmap_color), + ) + + @app.route('/check', methods=['POST']) @login_required def check_habit(): diff --git a/static/script/script-profile.js b/static/script/script-profile.js index 153f6dd..cb04af7 100644 --- a/static/script/script-profile.js +++ b/static/script/script-profile.js @@ -1,3 +1,5 @@ + + document.addEventListener("DOMContentLoaded", function() { // Get elements const profileImage = document.getElementById("profileImage"); diff --git a/templates/profile.html b/templates/profile.html index aee799f..01dc987 100644 --- a/templates/profile.html +++ b/templates/profile.html @@ -31,6 +31,15 @@ Bearbeiten +
+
+
Heatmap Farbe
+
+ + +
+
+