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)'
+ }
+
+ 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 @@