MIGRATE: Implemented user color setting.
This commit is contained in:
parent
164534ada1
commit
45f23c88e2
11
app.py
11
app.py
@ -132,11 +132,13 @@ def index():
|
||||
habit_lists = current_user.get_habitLists()
|
||||
name = "Hallo " + current_user.name
|
||||
heatmap_values, day = current_user.get_heatmap()
|
||||
heatmap_color = current_user.heatmap_color
|
||||
else:
|
||||
habit_lists = []
|
||||
name = "Bitte melde dich an."
|
||||
heatmap_values = []
|
||||
day = None
|
||||
heatmap_color = None
|
||||
|
||||
# Sort habits by whether they have been checked today and then by slot
|
||||
for habit_list in habit_lists:
|
||||
@ -146,7 +148,6 @@ def index():
|
||||
"Friday": "Freitag", "Saturday": "Samstag", "Sunday": "Sonntag"}
|
||||
|
||||
date = datetime.datetime.now().strftime("%d.%m.%Y %H:%M ") + days[datetime.datetime.now().strftime("%A")]
|
||||
color = '255, 0, 255'
|
||||
|
||||
return render_template(
|
||||
'index.html',
|
||||
@ -155,7 +156,7 @@ def index():
|
||||
habit_lists=habit_lists,
|
||||
heatmap_values=heatmap_values,
|
||||
day=day,
|
||||
color=color,
|
||||
color=heatmap_color,
|
||||
errors={}
|
||||
)
|
||||
|
||||
@ -513,7 +514,8 @@ def save_profile_image(image_file):
|
||||
# Save the processed image
|
||||
image_path = os.path.join(app.config['UPLOAD_FOLDER'], filename.replace(".gif", ".jpg"))
|
||||
image.save(image_path, 'JPEG', quality=100)
|
||||
current_user.update_profile_image(image_path)
|
||||
current_user.profile_image = image_path
|
||||
current_user.update()
|
||||
|
||||
|
||||
def save_profile_animated(image_file, filename):
|
||||
@ -522,7 +524,8 @@ def save_profile_animated(image_file, filename):
|
||||
gif_path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
|
||||
image_file.save(gif_path)
|
||||
|
||||
current_user.update_profile_image(gif_path)
|
||||
current_user.profile_image = gif_path
|
||||
current_user.update()
|
||||
|
||||
|
||||
@app.route('/upload', methods=['POST'])
|
||||
|
||||
@ -27,11 +27,11 @@ def create_user_profile_image(user_id):
|
||||
return relative_destination_path
|
||||
|
||||
|
||||
def create_user(name: str, email: str, password: str, profile_image: str = None):
|
||||
def create_user(name: str, email: str, password: str, heatmap_color: str, profile_image: str = None):
|
||||
password = hashlib.sha256(password.encode()).hexdigest()
|
||||
now = datetime.now().isoformat()
|
||||
query = (f"INSERT INTO users (name, email, password, profile_image, created_at, updated_at) VALUES "
|
||||
f"('{name}', '{email}', '{password}', '{profile_image}', '{now}', '{now}');")
|
||||
query = (f"INSERT INTO users (name, email, password, profile_image, heatmap_color, created_at, updated_at) VALUES "
|
||||
f"('{name}', '{email}', '{password}', '{profile_image}', '{heatmap_color}', '{now}', '{now}');")
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
@ -66,24 +66,15 @@ def get_user_by_email(email: str):
|
||||
return user
|
||||
|
||||
|
||||
def update_user(id: int, name: str, email: str, password: str):
|
||||
def update_user(id: int, name: str, email: str, password: str, profile_image: str, heatmap_color: str):
|
||||
now = datetime.now().isoformat()
|
||||
if password:
|
||||
query = (f"UPDATE users SET name = '{name}', email = '{email}', password = '{password}', updated_at = '{now}' "
|
||||
query = (f"UPDATE users SET name = '{name}', email = '{email}', password = '{password}', "
|
||||
f"profile_image ='{profile_image}', heatmap_color = '{heatmap_color}', updated_at = '{now}' "
|
||||
f"WHERE id = {id};")
|
||||
else:
|
||||
query = f"UPDATE users SET name = '{name}', email = '{email}', updated_at = '{now}' WHERE id = {id};"
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
conn.commit()
|
||||
conn.close()
|
||||
return cursor.lastrowid
|
||||
|
||||
|
||||
def update_user_profile(id: int, profile_image: str):
|
||||
now = datetime.now().isoformat()
|
||||
query = f"UPDATE users SET profile_image = '{profile_image}', updated_at = '{now}' WHERE id = {id};"
|
||||
query = (f"UPDATE users SET name = '{name}', email = '{email}', profile_image ='{profile_image}', "
|
||||
f"heatmap_color = '{heatmap_color}', updated_at = '{now}' WHERE id = {id};")
|
||||
conn = con3()
|
||||
cursor = conn.cursor()
|
||||
cursor.execute(query)
|
||||
|
||||
1
db/migrations/1709825341_delete_users_table.sql
Normal file
1
db/migrations/1709825341_delete_users_table.sql
Normal file
@ -0,0 +1 @@
|
||||
DROP TABLE users;
|
||||
11
db/migrations/1709825360_create_users_table.sql
Normal file
11
db/migrations/1709825360_create_users_table.sql
Normal file
@ -0,0 +1,11 @@
|
||||
CREATE TABLE IF NOT EXISTS users
|
||||
(
|
||||
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||
name TEXT NOT NULL,
|
||||
email TEXT NOT NULL,
|
||||
password TEXT NOT NULL,
|
||||
profile_image TEXT NOT NULL,
|
||||
heatmap_color TEXT NOT NULL,
|
||||
created_at TEXT NOT NULL,
|
||||
updated_at TEXT NOT NULL
|
||||
);
|
||||
@ -53,7 +53,7 @@ class HabitList:
|
||||
raw_users = get_users(self.id)
|
||||
users = []
|
||||
for user in raw_users:
|
||||
user = User(user[0], user[1], user[2], user[3], user[4])
|
||||
user = User(user[0], user[1], user[2], user[3], user[4], user[5])
|
||||
users.append(user)
|
||||
|
||||
return users
|
||||
|
||||
@ -2,40 +2,39 @@ from datetime import datetime
|
||||
|
||||
from flask_login import UserMixin
|
||||
from db.SQLiteClient import (create_user, get_user, get_user_by_email, update_user, delete_user,
|
||||
get_habitLists, get_heatmap_value, update_user_profile)
|
||||
get_habitLists, get_heatmap_value)
|
||||
|
||||
|
||||
class User(UserMixin):
|
||||
def __init__(self, id: int, name: str, email: str, password: str = None, profile_image:str = None):
|
||||
def __init__(self, id: int, name: str, email: str, password: str=None, profile_image:str=None, heatmap_color: str=None):
|
||||
self.id = id
|
||||
self.name = name
|
||||
self.email = email
|
||||
self.password = password
|
||||
self.profile_image = profile_image
|
||||
self.heatmap_color = heatmap_color
|
||||
|
||||
|
||||
@staticmethod
|
||||
def create(name: str, email: str, password: str):
|
||||
id, profile_image = create_user(name, email, password)
|
||||
return User(id=id, name=name, email=email, profile_image=profile_image)
|
||||
heatmap_color = "0, 255, 0"
|
||||
id, profile_image = create_user(name, email, password, heatmap_color)
|
||||
return User(id=id, name=name, email=email, profile_image=profile_image, heatmap_color=heatmap_color)
|
||||
|
||||
@staticmethod
|
||||
def get(id: int):
|
||||
user = get_user(id)
|
||||
return User(user[0], user[1], user[2], user[3], user[4]) if user else None
|
||||
return User(user[0], user[1], user[2], user[3], user[4], user[5]) if user else None
|
||||
|
||||
@staticmethod
|
||||
def get_by_email(email: str):
|
||||
user = get_user_by_email(email)
|
||||
return User(user[0], user[1], user[2], user[3], user[4]) if user else None
|
||||
return User(user[0], user[1], user[2], user[3], user[4], user[5]) if user else None
|
||||
|
||||
|
||||
# Updates: name, email, password
|
||||
def update(self):
|
||||
update_user(self.id, self.name, self.email, self.password if self.password else None)
|
||||
|
||||
def update_profile_image(self, profile_image: str):
|
||||
update_user_profile(self.id, profile_image)
|
||||
update_user(self.id, self.name, self.email, self.password if self.password else None, self.profile_image, self.heatmap_color)
|
||||
|
||||
# Deletes the User
|
||||
def delete(self):
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
|
||||
// Funktion zum Erstellen der Heatmap
|
||||
function createHeatmap(data, day, color) {
|
||||
function createHeatmap(data, day) {
|
||||
const heatmapContainer = document.getElementById('heatmap');
|
||||
|
||||
const days = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']
|
||||
@ -18,7 +18,6 @@ function createHeatmap(data, day, color) {
|
||||
// console.log(i * 7 + j, data[i * 7 + j], Math.max(...data));
|
||||
const opacity = data[i * 7 + j] / (Math.max(...data) <= 0 ? 1 : Math.max(...data)); // Berechne die Opazität basierend auf Aktivitätsanzahl
|
||||
|
||||
if (data[i * 7 + j]) {
|
||||
const dayElement = document.createElement('div');
|
||||
dayElement.classList.add('day');
|
||||
dayElement.style.backgroundColor = `rgba(${color}, ${opacity})`;
|
||||
@ -30,7 +29,6 @@ function createHeatmap(data, day, color) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function deleteHeatmap() {
|
||||
const heatmapContainer = document.getElementById('heatmap');
|
||||
@ -165,6 +163,7 @@ $(function () {
|
||||
$('[data-toggle="tooltip"]').tooltip()
|
||||
|
||||
})
|
||||
console.log(activityData, day, color)
|
||||
// Erstelle die Heatmap mit den simulierten Daten
|
||||
createHeatmap(activityData, day, color);
|
||||
|
||||
|
||||
@ -11,4 +11,5 @@
|
||||
const activityData = {{ heatmap_values }};
|
||||
const day = {{ day }};
|
||||
const color = "{{ color }}";
|
||||
console.log(activityData, day, color)
|
||||
</script>
|
||||
Loading…
x
Reference in New Issue
Block a user