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:
4
app.py
4
app.py
@@ -347,9 +347,9 @@ def add_tag():
|
|||||||
tag = request.args.get('tag')
|
tag = request.args.get('tag')
|
||||||
tag_filter = request.args.get('filter')
|
tag_filter = request.args.get('filter')
|
||||||
if person_id:
|
if person_id:
|
||||||
db.add_tag_for_person(person_id, tag, tag_filter)
|
db.add_or_update_tag_for_person(person_id, tag, tag_filter)
|
||||||
else:
|
else:
|
||||||
db.add_tag_for_dashboard(tag, tag_filter)
|
db.add_or_update_tag_for_dashboard(tag, tag_filter)
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
22
db.py
22
db.py
@@ -197,7 +197,7 @@ class DataBase():
|
|||||||
note = next((t['Note'] for t in topsets), '')
|
note = next((t['Note'] for t in topsets), '')
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'PersonId': next((t['PersonId'] for t in topsets), -1),
|
'PersonId': person_id,
|
||||||
'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'),
|
'PersonName': next((t['PersonName'] for t in topsets), 'Unknown'),
|
||||||
'WorkoutId': workout_id,
|
'WorkoutId': workout_id,
|
||||||
'StartDate': topsets[0]['StartDate'],
|
'StartDate': topsets[0]['StartDate'],
|
||||||
@@ -273,7 +273,15 @@ class DataBase():
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
T.name""", [person_id])
|
T.name""", [person_id])
|
||||||
|
|
||||||
def add_tag_for_person(self, person_id, tag_name, tag_filter):
|
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)', [
|
self.execute('INSERT INTO Tag (person_id, name, filter) VALUES (%s, %s, %s)', [
|
||||||
person_id, tag_name, tag_filter], commit=True)
|
person_id, tag_name, tag_filter], commit=True)
|
||||||
|
|
||||||
@@ -295,7 +303,15 @@ class DataBase():
|
|||||||
ORDER BY
|
ORDER BY
|
||||||
T.name""", [])
|
T.name""", [])
|
||||||
|
|
||||||
def add_tag_for_dashboard(self, tag_name, tag_filter):
|
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)', [
|
self.execute('INSERT INTO Tag (name, filter) VALUES (%s, %s)', [
|
||||||
tag_name, tag_filter], commit=True)
|
tag_name, tag_filter], commit=True)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user