Skip to content

Commit

Permalink
Added ability to flip card back over to review question.
Browse files Browse the repository at this point in the history
Added button to bookmark the current card, since dormant pages will refresh on iPad, losing the card you were working on.
  • Loading branch information
jwasham committed Jul 25, 2016
1 parent 18f0523 commit c3c6f40
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
33 changes: 27 additions & 6 deletions flash_cards.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,28 +173,33 @@ def delete(card_id):


@app.route('/general')
def general():
@app.route('/general/<card_id>')
def general(card_id=None):
if not session.get('logged_in'):
return redirect(url_for('login'))
return memorize("general")
return memorize("general", card_id)


@app.route('/code')
def code():
@app.route('/code/<card_id>')
def code(card_id=None):
if not session.get('logged_in'):
return redirect(url_for('login'))
return memorize("code")
return memorize("code", card_id)


def memorize(card_type):
def memorize(card_type, card_id):
if card_type == "general":
type = 1
elif card_type == "code":
type = 2
else:
return redirect(url_for('cards'))

card = get_card(type)
if card_id:
card = get_card_by_id(card_id)
else:
card = get_card(type)
if not card:
flash("You've learned all the " + card_type + " cards.")
return redirect(url_for('cards'))
Expand Down Expand Up @@ -223,6 +228,22 @@ def get_card(type):
return cur.fetchone()


def get_card_by_id(card_id):
db = get_db()

query = '''
SELECT
id, type, front, back, known
FROM cards
WHERE
id = ?
LIMIT 1
'''

cur = db.execute(query, [card_id])
return cur.fetchone()


@app.route('/mark_known/<card_id>/<card_type>')
def mark_known(card_id, card_type):
if not session.get('logged_in'):
Expand Down
9 changes: 7 additions & 2 deletions static/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,13 @@ $(document).ready(function(){
if ($('.memorizePanel').length != 0) {

$('.flipCard').click(function(){
$('.cardFront').hide();
$('.cardBack').show();
if ($('.cardFront').is(":visible") == true) {
$('.cardFront').hide();
$('.cardBack').show();
} else {
$('.cardFront').show();
$('.cardBack').hide();
}
});
}

Expand Down
12 changes: 12 additions & 0 deletions templates/memorize.html
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,17 @@ <h3 class="text-center">{{ card.front }}</h3>
</a>
</div>
</div>
<div class="row">
<div class="col-xs-12 text-center">
<br />
<br />
<br />
<a href="{{ url_for(card_type, card_id=card.id) }}" class="btn btn-default btn-sm">
<i class="fa fa-bookmark"></i>
bookmark this card (#{{ card.id }})
</a>

</div>
</div>

{% endblock %}

0 comments on commit c3c6f40

Please sign in to comment.