Skip to content

Commit

Permalink
Added watched and played icons in the history section (#15)
Browse files Browse the repository at this point in the history
* Added watched and played icons in the history section

* Fixed SQL params

* fixed history badges URLs
  • Loading branch information
ecourtial authored Sep 4, 2021
1 parent 7ae820c commit b3d381b
Show file tree
Hide file tree
Showing 10 changed files with 66 additions and 13 deletions.
5 changes: 4 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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.
Expand Down
6 changes: 4 additions & 2 deletions src/controller/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
20 changes: 18 additions & 2 deletions src/entity/history.py
Original file line number Diff line number Diff line change
Expand Up @@ -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."""
Expand All @@ -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__)
Expand All @@ -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
}
14 changes: 9 additions & 5 deletions src/repository/history_repository.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand All @@ -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
2 changes: 1 addition & 1 deletion standard.rc
Original file line number Diff line number Diff line change
Expand Up @@ -595,4 +595,4 @@ overgeneral-exceptions=BaseException,
Exception

# disable=R0913, R0914, R0902, R0904
disable=R0913
disable=R0913, W1514
Binary file added static/images/controller.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added static/images/eye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 14 additions & 1 deletion static/js/pages/history.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ define(
$('#contentTitle').html("Historique");
var content = '<p id="subtitle">Jeux vus ou joués</p>';
var currentYear = 0;
var that = this;

$.each(data.games, function (index, value) {
var gameYear = parseInt(value.year);
Expand All @@ -30,7 +31,7 @@ define(
}

var gameEntry = value.position + "- " + tools.filterContent(value.title);

gameEntry = that.getBadges(gameEntry, value);
gameEntry += ' - <a data-link-type="gameDetails" id="entryD' + tools.filterContent(value.game_id) + '" href="">Détails</a>';

if (logged) {
Expand All @@ -46,6 +47,18 @@ define(

$('#content').empty().html(content);
},

getBadges: function(gameEntry, value) {
if (value.watched === 1) {
gameEntry += ' <img title="Je l\'ai regardé" src="' + watchedImageUrl + '"/>'
}

if (value.played === 1) {
gameEntry += ' <img title="J\'y ai joué" src="' + playedImageUrl + '"/>'
}

return gameEntry;
}
};
}
);
15 changes: 14 additions & 1 deletion templates/general/history-form.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,20 @@
<label for="position">Position</label>
<input type='int' name='position' id='position' value="{%- if history -%}{{game.get_position()}}{% endif %}" required/>
</p>

<p>
<label for="watched">L'as-tu regardé ?</label>
<select id="watched" name="watched">
<option value="0">Non</option>
<option value="1">Oui</option>
</select>
</p>
<p>
<label for="played">Y as-tu joué ?</label>
<select id="played" name="played">
<option value="0">Non</option>
<option value="1">Oui</option>
</select>
</p>
<input type='hidden' name='_token' value='{{ token }}'/>
<input type='submit' name='submit' value="Enregistrer"/>
</form>
Expand Down
2 changes: 2 additions & 0 deletions templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ <h1 id="contentTitle">{{ content_title }}</h1>
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') }}";
Expand Down

0 comments on commit b3d381b

Please sign in to comment.