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 0000000..8eef25c Binary files /dev/null and b/static/images/controller.png differ diff --git a/static/images/eye.png b/static/images/eye.png new file mode 100755 index 0000000..1e2e295 Binary files /dev/null and b/static/images/eye.png differ diff --git a/static/js/pages/history.js b/static/js/pages/history.js index 53c2def..0e2cc6f 100644 --- a/static/js/pages/history.js +++ b/static/js/pages/history.js @@ -14,6 +14,7 @@ define( $('#contentTitle').html("Historique"); var content = '

Jeux vus ou joués

'; var currentYear = 0; + var that = this; $.each(data.games, function (index, value) { var gameYear = parseInt(value.year); @@ -30,7 +31,7 @@ define( } var gameEntry = value.position + "- " + tools.filterContent(value.title); - + gameEntry = that.getBadges(gameEntry, value); gameEntry += ' - Dé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') }}";