From b3d381bec4c28f08a2b9b7a63da164adce26ba57 Mon Sep 17 00:00:00 2001 From: Eric COURTIAL <57905107+ecourtial@users.noreply.github.com> Date: Sat, 4 Sep 2021 09:06:13 +0200 Subject: [PATCH] Added watched and played icons in the history section (#15) * Added watched and played icons in the history section * Fixed SQL params * fixed history badges URLs --- README.md | 5 ++++- src/controller/history.py | 6 ++++-- src/entity/history.py | 20 ++++++++++++++++++-- src/repository/history_repository.py | 14 +++++++++----- standard.rc | 2 +- static/images/controller.png | Bin 0 -> 783 bytes static/images/eye.png | Bin 0 -> 1032 bytes static/js/pages/history.js | 15 ++++++++++++++- templates/general/history-form.html | 15 ++++++++++++++- templates/layout.html | 2 ++ 10 files changed, 66 insertions(+), 13 deletions(-) create mode 100755 static/images/controller.png create mode 100755 static/images/eye.png diff --git a/README.md b/README.md index d80b93c..6dd8318 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,9 @@ todo list, watch list, ranking... ## Changelog +### 3.4.0 +* Added watched and played badges in the history section. + ### 3.3.0 * Added a new feature: "Best Game Forever". Different from the hall of fames. BGF games are still valuable today, while some entries in the HOF were valuable only at time. @@ -47,7 +50,7 @@ todo list, watch list, ranking... ### 3.1.0 * Added a "todo with help" icon in the game list if the game is to be completed with some help. * The game id is now visible in the game lists. -* Added a History menu to log the games we finish (watch or play). +* Added a History menu to log the games we finish (watched or played). ### 3.0.1 * Fixed a bug when adding a new game while edition was still working. diff --git a/src/controller/history.py b/src/controller/history.py index dbdf27e..fbe19d8 100644 --- a/src/controller/history.py +++ b/src/controller/history.py @@ -30,11 +30,13 @@ def add(cls, mysql): game_id = request.form['game_id'] year = request.form['year'] position = request.form['position'] - if game_id == '' or year == '' or position == '': + watched = request.form['watched'] + played = request.form['played'] + if game_id == '' or year == '' or position == '' or watched == '' or played == '': return "Form is incomplete" history_repo = HistoryRepository(mysql) - history_repo.insert(game_id, year, position) + history_repo.insert(game_id, year, position, watched, played) return jsonify(), 200 diff --git a/src/entity/history.py b/src/entity/history.py index d34140a..b238b15 100644 --- a/src/entity/history.py +++ b/src/entity/history.py @@ -9,13 +9,17 @@ def __init__( game_id, title, year, - position + position, + watched, + played ): self.entity_id = entity_id self.game_id = game_id self.title = title self.year = year self.position = position + self.watched = watched + self.played = played def get_id(self): """Return the id entry.""" @@ -42,6 +46,16 @@ def get_position(self): return self.position + def get_watched(self): + """Did you watched a playthrough?""" + + return self.watched + + def get_played(self): + """Did you played at it?""" + + return self.played + def to_json(self): """Jsonify the object""" return json.dumps(self, default=lambda o: o.__dict__) @@ -53,5 +67,7 @@ def serialize(self): 'game_id': self.game_id, 'title': self.title, 'year': self.year, - 'position': self.position + 'position': self.position, + 'watched': self.watched, + 'played': self.played } diff --git a/src/repository/history_repository.py b/src/repository/history_repository.py index 40b1403..566199d 100644 --- a/src/repository/history_repository.py +++ b/src/repository/history_repository.py @@ -8,15 +8,17 @@ class HistoryRepository(AbstractRepository): def get_all(self): """Gets all the history.""" request = "SELECT history.id as id, history.game_id as game_id, history.year as year" - request += ", history.position as position, games.title as title FROM history, games" + request += ", history.position as position, games.title as title, history.watched" + request += ", history.played FROM history, games" request += " WHERE history.game_id = games.id ORDER BY year, position" return self.fetch_multiple(request, ()) - def insert(self, game_id, year, position): + def insert(self, game_id, year, position, watched, played): """Insert a new history entry""" - request = "INSERT INTO history (game_id, year, position) VALUES (%s,%s,%s)" - return self.write(request, (game_id, year, position,)) + request = "INSERT INTO history (game_id, year, position, watched, played) " + request += "VALUES (%s,%s,%s,%s,%s)" + return self.write(request, (game_id, year, position, watched, played,)) def delete(self, entity_id): """Delete a history entry""" @@ -32,7 +34,9 @@ def hydrate(cls, row): row['game_id'], row['title'], row['year'], - row['position'] + row['position'], + row['watched'], + row['played'] ) return history diff --git a/standard.rc b/standard.rc index 9d28632..04dab9a 100644 --- a/standard.rc +++ b/standard.rc @@ -595,4 +595,4 @@ overgeneral-exceptions=BaseException, Exception # disable=R0913, R0914, R0902, R0904 -disable=R0913 +disable=R0913, W1514 diff --git a/static/images/controller.png b/static/images/controller.png new file mode 100755 index 0000000000000000000000000000000000000000..8eef25cc7976e2513e23a759da2318c6e89c83e2 GIT binary patch literal 783 zcmV+q1MvKbP)VHC&z-`sZg;$F-a zHOojeEif<&0t1T#Dd-_cLLnigAh0LdqKE|Ff_(EO3c5%yDTJX#z4ek{P#Kz5UXT<; zciWl0%zdVB7FnhCz{7JhHx}Q#ubnh394rV_40t@gC~?n>|TU6FH!mkoFW7MiHiMo-uTIiwbc)t0G|o?Y4ncI0%J8;OY5VN`c4_ zw6P3MXbF`01n~X>*mAlquh3@s;|c}Yv@qomd{wikvRO>hwh|s%;`Je|sz`DywrdJB zx-6MkDEE4EaMxIdY1#lPnKFq&GVahV6Z4^H|2~0#8I^?+du!3X51f#qtA@xk{(64p zY?cryBJj1*Z;4KW3eim+M3w@1U^bH>DP4h1XD1K`o=`#Gg`wfm&6oKJEv27ZZv4Eh zrP{B^ok`n-LB|4J+t~60he+de&`YKbIT)Py6>PIL-G4N-8jg&`>6M?R*XV`UujUng z;`y#=!u46AZ*6Dkj#l99A3fEYYuyo&$!ciMLW1^_&mHUFDaQ`-Ol N002ovPDHLkV1j)9ZsGs{ literal 0 HcmV?d00001 diff --git a/static/images/eye.png b/static/images/eye.png new file mode 100755 index 0000000000000000000000000000000000000000..1e2e2953fe378513bdeaa00b84deaa35223f3795 GIT binary patch literal 1032 zcmV+j1o!)iP)_xBE1rXB87rh18rIq8`JKl z?Pe2A(vWPr>weA7W_D+0=fjhV2zn`k;DK{qc;S7{bI$ubFYy0e%HA)Kw>SPV4qwi$ zyC}z*mZ95(a!-V*1Qy}gmP2{o)@xNvTzvCyfTXmM5-G>) zreQFE3egnB(^Bi_sRtLN=C{ot9x}{+`}k zM^ES~D7~`v^_BGa`HR*QhK2MhT8*PgtuDV?%^h6GWU|4v^^EKM(h`EWGhzqIU4e3ABr9I2ykzNNw*KjiXe2@ima#ofTiBQu@$nsIPC{TkBLB z8reDmR_~=iO%tI`FN$>y2SphUIQZNGriM@8^z*auP|ML9surC|e!<9nRNH^FLs>K8 zrmihit8&0}xyf#m;G3J@L$F#nb8ZgFGxNxhX^8PxVD~bRrH^q(>BHw=Ekl-TL=s)n zZu;($URU1d-E9G$y?Rh>G&>82hvf3Ln<&W&7AA)L`=U&9^tODunSx76Fk^c5m z=<*&05{ppxYseI9NH`Ypd)z+TwiY^v#y;a+o(|eK7A0jx#ii3ph{QtMQ5CJ8A@U@DeJT8-Y?9i*L-prRMSSOccRjSBsO}4>+FR zBIV8dBBk7`tV?e->dG_u-JSOJ)H(@t`Y|y*1C#PFIT5#Ruc25{5F72sP^23pkv<5L z9A2O)QRyHKgsX;*g;*;E?+g9AjV z${3Et97?IfOKyXJo(jQsbHCA+=v8?qZW`DQdU%gn~e85geV7Iri*u~xyUDétails'; if (logged) { @@ -46,6 +47,18 @@ define( $('#content').empty().html(content); }, + + getBadges: function(gameEntry, value) { + if (value.watched === 1) { + gameEntry += ' ' + } + + if (value.played === 1) { + gameEntry += ' ' + } + + return gameEntry; + } }; } ); diff --git a/templates/general/history-form.html b/templates/general/history-form.html index 47214a7..b99db78 100644 --- a/templates/general/history-form.html +++ b/templates/general/history-form.html @@ -11,7 +11,20 @@

- +

+ + +

+

+ + +

diff --git a/templates/layout.html b/templates/layout.html index 566567c..618c773 100644 --- a/templates/layout.html +++ b/templates/layout.html @@ -36,6 +36,8 @@

{{ content_title }}

var withHelpImageUrl = "{{ url_for('static', filename='images/help.png') }}"; var hasBoxImageUrl = "{{ url_for('static', filename='images/box.png') }}"; var diamondImageUrl = "{{ url_for('static', filename='images/diamond.png') }}"; + var watchedImageUrl = "{{ url_for('static', filename='images/eye.png') }}"; + var playedImageUrl = "{{ url_for('static', filename='images/controller.png') }}"; // API URLs var hallOfFameUrl = "{{ url_for('get_home_content') }}";