From ed894cb7dec7040f7f5030b575f7595cd9de08c5 Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 18:25:31 +0700 Subject: [PATCH 01/53] Add tags table schema --- data/schema.sql | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/data/schema.sql b/data/schema.sql index 6a3ffff..78d3f2f 100644 --- a/data/schema.sql +++ b/data/schema.sql @@ -6,3 +6,8 @@ create table cards ( back text not null, known boolean default 0 ); + +create table tags ( + id integer primary key autoincrement, + tagName text not null +); From 7132484b8f319d23599242443f7df22b87ab34e0 Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 20:02:37 +0700 Subject: [PATCH 02/53] Add page tags --- templates/tags.html | 52 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 templates/tags.html diff --git a/templates/tags.html b/templates/tags.html new file mode 100644 index 0000000..8cffc0f --- /dev/null +++ b/templates/tags.html @@ -0,0 +1,52 @@ +{% extends "layout.html" %} +{% block body %} + +
+

Add a Tag

+
+
+ + +
+
+ +
+
+
+ + + + + + +{% endblock %} From c0b1668f04df4b83fdeebc5178c7bc41fd9a6864 Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 20:05:19 +0700 Subject: [PATCH 03/53] Implement method select tag and add tag to db --- flash_cards.py | 33 +++++++++++++++++++++++++++++---- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/flash_cards.py b/flash_cards.py index 6d34a44..dfca21b 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -49,10 +49,10 @@ def close_db(error): # Uncomment and use this to initialize database, then comment it # You can rerun it to pave the database and start over -# @app.route('/initdb') -# def initdb(): -# init_db() -# return 'Initialized the database.' +@app.route('/initdb') +def initdb(): + init_db() + return 'Initialized the database.' @app.route('/') @@ -276,6 +276,31 @@ def logout(): flash("You've logged out") return redirect(url_for('index')) +@app.route('/tags') +def tags(): + if not session.get('logged_in'): + return redirect(url_for('login')) + db = get_db() + query = ''' + SELECT id, tagName + FROM tags + ORDER BY id DESC + ''' + cur = db.execute(query) + tags = cur.fetchall() + return render_template('tags.html', tags=tags, filter_name="all") + +@app.route('/addTag', methods=['POST']) +def add_tag(): + if not session.get('logged_in'): + return redirect(url_for('login')) + db = get_db() + db.execute('INSERT INTO tags (tagName) VALUES (?)', + [request.form['tagName']]) + db.commit() + flash('New tag was successfully added.') + return redirect(url_for('tags')) + if __name__ == '__main__': app.run(host='0.0.0.0') From 9d0743d517810796e911230dea334e2ed87f5804 Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 21:08:13 +0700 Subject: [PATCH 04/53] Show table all tag --- templates/tags.html | 24 ++++++++---------------- 1 file changed, 8 insertions(+), 16 deletions(-) diff --git a/templates/tags.html b/templates/tags.html index 8cffc0f..1e8f97c 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -14,39 +14,31 @@ - - - - + {% endblock %} From 08f73bc6812fc4e71cc918d570ac7526ad632e0f Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 21:08:29 +0700 Subject: [PATCH 05/53] Add page edit tag --- templates/editTag.html | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 templates/editTag.html diff --git a/templates/editTag.html b/templates/editTag.html new file mode 100644 index 0000000..90c2402 --- /dev/null +++ b/templates/editTag.html @@ -0,0 +1,18 @@ +{% extends "layout.html" %} +{% block body %} +
+

Edit Tag #{{ tag.id }}

+
+
+ + +
+ +
+
+ + +
+
+
+{% endblock %} From c3f58971e481f2ff5be7e1be5cf4326c787a3c4b Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 21:08:50 +0700 Subject: [PATCH 06/53] Update css --- static/style.css | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/static/style.css b/static/style.css index 7750666..df864ab 100644 --- a/static/style.css +++ b/static/style.css @@ -7,7 +7,7 @@ textarea { font-family: monospace; } -.cardContent h4 { +.cardContent .tagContent h4 { margin-top: 0; } From 52c00dfaf2f549a7a004e70170c5384e19a9899d Mon Sep 17 00:00:00 2001 From: duongban Date: Sun, 23 May 2021 21:09:24 +0700 Subject: [PATCH 07/53] Implement method update tag to db --- flash_cards.py | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/flash_cards.py b/flash_cards.py index dfca21b..4117aa0 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -301,6 +301,38 @@ def add_tag(): flash('New tag was successfully added.') return redirect(url_for('tags')) +@app.route('/editTag/') +def editTag(tag_id): + if not session.get('logged_in'): + return redirect(url_for('login')) + db = get_db() + query = ''' + SELECT id, tagName + FROM tags + WHERE id = ? + ''' + cur = db.execute(query, [tag_id]) + tag = cur.fetchone() + return render_template('editTag.html', tag=tag) + +@app.route('/edit_tag', methods=['POST']) +def edit_tag(): + if not session.get('logged_in'): + return redirect(url_for('login')) + db = get_db() + command = ''' + UPDATE tags + SET + tagName = ? + WHERE id = ? + ''' + db.execute(command, + [request.form['tagName'], + request.form['tag_id'] + ]) + db.commit() + flash('Tag saved.') + return redirect(url_for('tags')) if __name__ == '__main__': app.run(host='0.0.0.0') From 4f4bcdf31d4412590a5bea940fd1b94ae22f47f5 Mon Sep 17 00:00:00 2001 From: duongban Date: Tue, 25 May 2021 22:43:18 +0700 Subject: [PATCH 08/53] Use suitable name route --- flash_cards.py | 6 +++--- templates/editTag.html | 2 +- templates/tags.html | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/flash_cards.py b/flash_cards.py index 4117aa0..8547334 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -302,7 +302,7 @@ def add_tag(): return redirect(url_for('tags')) @app.route('/editTag/') -def editTag(tag_id): +def edit_tag(tag_id): if not session.get('logged_in'): return redirect(url_for('login')) db = get_db() @@ -315,8 +315,8 @@ def editTag(tag_id): tag = cur.fetchone() return render_template('editTag.html', tag=tag) -@app.route('/edit_tag', methods=['POST']) -def edit_tag(): +@app.route('/updateTag', methods=['POST']) +def update_tag(): if not session.get('logged_in'): return redirect(url_for('login')) db = get_db() diff --git a/templates/editTag.html b/templates/editTag.html index 90c2402..08c87e6 100644 --- a/templates/editTag.html +++ b/templates/editTag.html @@ -2,7 +2,7 @@ {% block body %}

Edit Tag #{{ tag.id }}

-
+
diff --git a/templates/tags.html b/templates/tags.html index 1e8f97c..ce619c4 100644 --- a/templates/tags.html +++ b/templates/tags.html @@ -24,7 +24,7 @@ {% for tag in tags %} - +

From 9ef4f85fe907fc59fdd44defa85f041193682bfa Mon Sep 17 00:00:00 2001 From: duongban Date: Wed, 26 May 2021 00:12:38 +0700 Subject: [PATCH 09/53] Refactor get tag --- flash_cards.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/flash_cards.py b/flash_cards.py index 8547334..cd9e433 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -75,7 +75,8 @@ def cards(): ''' cur = db.execute(query) cards = cur.fetchall() - return render_template('cards.html', cards=cards, filter_name="all") + tags = getAllTag() + return render_template('cards.html', cards=cards, tags=tags, filter_name="all") @app.route('/filter_cards/') @@ -97,7 +98,8 @@ def filter_cards(filter_name): return redirect(url_for('cards')) db = get_db() - fullquery = "SELECT id, type, front, back, known FROM cards " + query + " ORDER BY id DESC" + fullquery = "SELECT id, type, front, back, known FROM cards " + \ + query + " ORDER BY id DESC" cur = db.execute(fullquery) cards = cur.fetchall() return render_template('cards.html', cards=cards, filter_name=filter_name) @@ -276,8 +278,8 @@ def logout(): flash("You've logged out") return redirect(url_for('index')) -@app.route('/tags') -def tags(): + +def getAllTag(): if not session.get('logged_in'): return redirect(url_for('login')) db = get_db() @@ -288,8 +290,17 @@ def tags(): ''' cur = db.execute(query) tags = cur.fetchall() + return tags + + +@app.route('/tags') +def tags(): + if not session.get('logged_in'): + return redirect(url_for('login')) + tags = getAllTag() return render_template('tags.html', tags=tags, filter_name="all") + @app.route('/addTag', methods=['POST']) def add_tag(): if not session.get('logged_in'): @@ -301,6 +312,7 @@ def add_tag(): flash('New tag was successfully added.') return redirect(url_for('tags')) + @app.route('/editTag/') def edit_tag(tag_id): if not session.get('logged_in'): @@ -315,6 +327,7 @@ def edit_tag(tag_id): tag = cur.fetchone() return render_template('editTag.html', tag=tag) + @app.route('/updateTag', methods=['POST']) def update_tag(): if not session.get('logged_in'): @@ -334,5 +347,6 @@ def update_tag(): flash('Tag saved.') return redirect(url_for('tags')) + if __name__ == '__main__': app.run(host='0.0.0.0') From 1061ce12f74044f50e1ce709b14be54bff1723cb Mon Sep 17 00:00:00 2001 From: duongban Date: Wed, 26 May 2021 00:12:58 +0700 Subject: [PATCH 10/53] Show all tag when create card --- templates/cards.html | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/templates/cards.html b/templates/cards.html index 08b8906..caaa3b9 100644 --- a/templates/cards.html +++ b/templates/cards.html @@ -11,6 +11,11 @@ + {% for tag in tags %} + + {% endfor %}

From 6264a4ba78df869f88ce79e7990cae4bb61b6b7a Mon Sep 17 00:00:00 2001 From: duongban Date: Wed, 26 May 2021 22:14:01 +0700 Subject: [PATCH 11/53] Fix bug toggle button selected tag in for loop --- templates/cards.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/cards.html b/templates/cards.html index caaa3b9..41c43a4 100644 --- a/templates/cards.html +++ b/templates/cards.html @@ -13,7 +13,7 @@ {% for tag in tags %} {% endfor %}
From 53dd1eb5eb19e5fe39974321513313cb6fe10d73 Mon Sep 17 00:00:00 2001 From: duongban Date: Wed, 26 May 2021 22:55:04 +0700 Subject: [PATCH 12/53] Init tag general & code when init db --- flash_cards.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/flash_cards.py b/flash_cards.py index cd9e433..62a7c8a 100644 --- a/flash_cards.py +++ b/flash_cards.py @@ -28,7 +28,6 @@ def init_db(): db.cursor().executescript(f.read()) db.commit() - def get_db(): """Opens a new database connection if there is none yet for the current application context. @@ -52,6 +51,7 @@ def close_db(error): @app.route('/initdb') def initdb(): init_db() + init_tag() return 'Initialized the database.' @@ -347,6 +347,17 @@ def update_tag(): flash('Tag saved.') return redirect(url_for('tags')) +def init_tag(): + if not session.get('logged_in'): + return redirect(url_for('login')) + db = get_db() + db.execute('INSERT INTO tags (tagName) VALUES (?)', + ["general"]) + db.commit() + db.execute('INSERT INTO tags (tagName) VALUES (?)', + ["code"]) + db.commit() + if __name__ == '__main__': app.run(host='0.0.0.0') From 24af06944cac1c33355998cc199f8557d0e54705 Mon Sep 17 00:00:00 2001 From: duongban Date: Wed, 26 May 2021 22:55:27 +0700 Subject: [PATCH 13/53] Comment unused code --- static/general.js | 10 +++++----- templates/cards.html | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/static/general.js b/static/general.js index b72bad7..5587358 100644 --- a/static/general.js +++ b/static/general.js @@ -40,11 +40,11 @@ $(document).ready(function(){ $('.toggleButton').removeClass('toggleSelected'); $(this).addClass('toggleSelected'); - if (checkedVal == '1') { - $('textarea[name=back]').attr('rows', 5); - } else { - $('textarea[name=back]').attr('rows', 12); - } + // if (checkedVal == '1') { + // $('textarea[name=back]').attr('rows', 5); + // } else { + // $('textarea[name=back]').attr('rows', 12); + // } $('.fieldFront').show(); $('.fieldBack').show(); diff --git a/templates/cards.html b/templates/cards.html index 41c43a4..0b06dd1 100644 --- a/templates/cards.html +++ b/templates/cards.html @@ -5,12 +5,12 @@

Add a Card

-