If you create a tag with the same name as an existing tag it will update it rather then creating a new instance, still needs further work to improve UX

This commit is contained in:
Peter Stockings
2023-07-13 22:04:03 +10:00
parent 8802d37124
commit 1970bc6417
2 changed files with 25 additions and 9 deletions

30
db.py
View File

@@ -197,7 +197,7 @@ class DataBase():
note = next((t['Note'] for t in topsets), '')
return {
'PersonId': next((t['PersonId'] for t in topsets), -1),
'PersonId': person_id,
'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'),
'WorkoutId': workout_id,
'StartDate': topsets[0]['StartDate'],
@@ -273,9 +273,17 @@ class DataBase():
ORDER BY
T.name""", [person_id])
def add_tag_for_person(self, person_id, tag_name, tag_filter):
self.execute('INSERT INTO Tag (person_id, name, filter) VALUES (%s, %s, %s)', [
person_id, tag_name, tag_filter], commit=True)
def add_or_update_tag_for_person(self, person_id, tag_name, tag_filter):
# check if a tag exists for dashboard with the same tag_name
tag = self.execute('SELECT tag_id AS "TagId" FROM Tag WHERE person_id=%s AND name=%s LIMIT 1', [
person_id, tag_name], one=True)
if tag:
# update the tag
self.execute('UPDATE Tag SET filter=%s WHERE tag_id=%s', [
tag_filter, tag['TagId']], commit=True)
else:
self.execute('INSERT INTO Tag (person_id, name, filter) VALUES (%s, %s, %s)', [
person_id, tag_name, tag_filter], commit=True)
def delete_tag_for_person(self, person_id, tag_id):
self.execute('DELETE FROM Tag WHERE person_id=%s AND tag_id=%s', [
@@ -295,9 +303,17 @@ class DataBase():
ORDER BY
T.name""", [])
def add_tag_for_dashboard(self, tag_name, tag_filter):
self.execute('INSERT INTO Tag (name, filter) VALUES (%s, %s)', [
tag_name, tag_filter], commit=True)
def add_or_update_tag_for_dashboard(self, tag_name, tag_filter):
# check if a tag exists for dashboard with the same tag_name
tag = self.execute('SELECT tag_id AS "TagId" FROM Tag WHERE person_id IS NULL AND name=%s LIMIT 1', [
tag_name], one=True)
if tag:
# update the tag
self.execute('UPDATE Tag SET filter=%s WHERE tag_id=%s', [
tag_filter, tag['TagId']], commit=True)
else:
self.execute('INSERT INTO Tag (name, filter) VALUES (%s, %s)', [
tag_name, tag_filter], commit=True)
def delete_tag_for_dashboard(self, tag_id):
self.execute('DELETE FROM Tag WHERE tag_id=%s', [tag_id], commit=True)