Compare commits

...

6 Commits

@ -130,9 +130,9 @@ def addme():
@app.route('/')
def index():
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals(), now=datetime.datetime.now())
return render_template('meal_list.html', leaderboard=getLeaderboard(), meals=getUpcomingMeals())
@app.route('/view_meal')
@app.route('/viewmeal')
def view_meal():
meal_id = request.args.get('meal')
meal = getMeal(meal_id)
@ -141,6 +141,29 @@ def view_meal():
print(meal)
return render_template('view_meal.html', leaderboard=getLeaderboard(), meal=meal)
@app.route('/mealplanner')
def meal_planner():
return render_template('meal_planner.html')
@app.route('/searchusers')
def search_users():
q = request.args.get('q')
query = 'select username from users where id>0 and username like :q;'
r = db_engine.execute(text(query), q=(q+'%'))
result = []
for row in r:
result.append(list(row)[0])
r.close()
return str(result)
@app.route('/getkukcandidate')
def get_kuk_candidate():
date = datetime.datetime.strptime(request.args.get('date'), '%Y-%m-%d %H:%M')
meal_eaters = request.args.get('eaters').split(',')
# TODO: Implement
return 'davide'
@app.route('/login', methods=['GET', 'POST'])
def login():
if request.method == 'POST':

@ -0,0 +1,102 @@
var active_timer = 100;
var eaters = []
$( function() {
$(".user-result-container").position({
my: "left top",
at: "left bottom",
of: $('#search-user'), // or $("#otherdiv")
collision: "fit"
});
$('.user-result-container').hide();
$( "#datepicker" ).datepicker({
dateFormat: 'D, yy-mm-dd'
});
$('#spinner-hour').spinner({
min: 0,
max: 23,
numberFormat: 'n'
});
$('#spinner-minute').spinner({
min: 0,
max: 59,
numberFormat: 'n'
});
$('#search-user').on('keyup', function(){
clearTimeout(active_timer);
active_timer = setTimeout(user_search, 500);
});
eaters.push($($('.username')[0]).text()); // Kinda weird but ok
});
function plan_meal() {
}
function add_user() {
$.ajax({
url: "/searchusers?q=" + $('#search-user').val()
}).done(function(results) {
if (results == '[]') {
alert('Invalid username');
return;
}
names = results.substring(1, results.length-1).split(', ');
if (names.length > 1) {
alert('Please choose one.');
return;
}
eaters.push(names[0].substring(1, names[0].length));
var meal_date = $('#datepicker').datepicker('getDate');
var month = (meal_date.getMonth() + 1).toString();
if (month.length == 1)
month = '0' + month;
var date = (meal_date.getDate()).toString();
if (date.length == 1)
date = '0' + date;
if ($('#spinner-hour').val().length == 1)
$('#spinner-hour').val('0' + $('#spinner-hour').val());
if ($('#spinner-minute').val().length == 1)
$('#spinner-minute').val('0' + $('#spinner-minute').val());
var meal_timestamp = meal_date.getFullYear() + '-' +
month + '-' +
date + ' ' +
$('#spinner-hour').val() + ':' +
$('#spinner-minute').val();
$.ajax({
url: "/getkukcandidate?date=" + meal_timestamp + "&eaters=" + eaters.toString()
}).done(function(estkuk) {
$('#est-cook').attr('src', 'static/' + estkuk + '.png')
$('#est-cook').attr('title', estkuk)
});
});
}
function fill_box(name) {
$('#search-user').val(name);
$('.user-result-container').hide();
}
function user_search() {
$('.user-result-container').hide();
if ($('#search-user').val() == '')
return;
$.ajax({
url: "/searchusers?q=" + $('#search-user').val()
}).done(function(results) {
// Load results
if (results == '[]')
return;
$('.user-result-container').empty();
names = results.substring(1, results.length-1).split(', ');
$.each(names, function(i, r){
var name = r.substring(1, r.length-1);
e = '<div class="user-result" onclick="fill_box(\'' + name + '\')">\
<img src="static/' + name + '.png" class="user-result-thumb">\
<span class="username">' + name + '</span>\
</div>'
$('.user-result-container').append($(e));
});
$('.user-result-container').show();
});
}

@ -69,7 +69,7 @@ h2 {
margin: 16px 20px;
}
.flex-card .flex-small-thumb {
.flex-small-thumb {
height: 32px;
width: 32px;
display: inline-block;
@ -120,6 +120,20 @@ h2 {
margin: 16px 20px;
}
.small-round-button {
display: flex;
align-items: center;
justify-content: center;
color: white;
background-color: #FF0000;
cursor: pointer;
width: 30px;
height: 30px;
border-radius: 15px;
font-size: 20px;
margin: auto 30px;
}
.floating-round-button {
display: flex;
align-items: center;
@ -205,3 +219,72 @@ h2 {
text-align: center;
color: white;
}
.flex-card-vert {
width: 30%;
display: inline-flex;
flex-direction: column;
background-color: #F1EDEA;
-webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.5);
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.5);
margin: 0.5%;
padding: 1em;
}
.add-people-container {
display: flex;
justify-content: space-between;
margin: 5px 0;
}
.when {
display: flex;
}
.when * {
margin: auto 3px;
}
#search-user, #flavor-text, #datepicker {
min-width: 0;
padding: 0.5em;
}
#search-user {
margin: auto 0;
}
.ui-spinner {
flex: 4;
}
.user-result-container {
display: flex;
flex-direction: column;
background-color: #F1EDEA;
-webkit-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.5);
-moz-box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.5);
box-shadow: 2px 2px 5px 0px rgba(0,0,0,0.5);
position: fixed;
}
.user-result {
display: flex;
align-items: center;
border: solid 1px #A8A4A1;
cursor: pointer;
}
.user-result:hover {
background-color: #A8A4A1;
}
.user-result span {
margin: auto 20px;
}
.user-result-thumb {
width: 50px;
margin: 10px 20px;
}

@ -41,7 +41,7 @@
{% if meal.needs_confirmation %}
<div class="flex-card" onclick="location.href='/verify?meal={{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
{% else %}
<div class="flex-card" onclick="location.href='/view_meal?meal={{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
<div class="flex-card" onclick="location.href='/viewmeal?meal={{meal.id}}';" style="cursor: pointer; width: 60%; justify-content: space-between;">
{% endif %}
<span{% if meal.needs_confirmation%} style="color: #EE7500;"{% endif %}><b>{{meal.meal_time}}</b></span>
<p style="text-align: left;">{% if meal.needs_confirmation %}Did &nbsp;{% endif %}{% if meal.kuk != "" %}<img class="flex-small-thumb" src="{{url_for('static', filename=meal.kuk + '.png')}}" title="{{meal.kuk}}" align="middle" style="margin: " /> &nbsp; {% if not meal.needs_confirmation %}<b>WILL</b>{% endif %}{% else %}<img class="flex-small-thumb" src="{{url_for('static', filename=meal.candidate + '.png')}}" title="{{meal.kuk}}" align="middle" style="margin: " /> &nbsp; {% if not meal.needs_confirmation %}<b>SHOULD</b>{% endif %}{% endif%} cook for <br>{% for e in meal.eaters %}<img class="flex-small-thumb" src="{{url_for('static', filename=e + '.png')}}" title="{{e}}" align="middle"/>&nbsp; {% endfor %}{% if meal.needs_confirmation %}<b>?</b>{% endif %}</p>

@ -0,0 +1,75 @@
<!DOCTYPE html>
<html>
<head>
<title>Plan a meal</title>
<meta name="viewport" content="width=device-width">
<script
src="https://code.jquery.com/jquery-3.2.1.min.js"
integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4="
crossorigin="anonymous"></script>
<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
<link rel="stylesheet" type="text/css" href="{{ url_for('static', filename='style.css') }}">
<link rel="stylesheet" type="text/css" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
<script src="{{ url_for('static', filename='mealplanner_script.js') }}"></script>
<link href="https://fonts.googleapis.com/css?family=Roboto" rel="stylesheet">
<script src="https://use.fontawesome.com/2fef7be393.js"></script>
<style type="text/css">
html {
background-image: url({{url_for('static', filename='burger.jpg')}});
background-position: left top;
background-repeat: no-repeat;
background-size: 100% auto;
background-color: #aeaeac;
background-attachment: fixed;
}
</style>
</head>
<body>
<h1 style="margin: 40px;">Plan a meal</h1>
<div class="flex-card-vert">
<h3>When</h3>
<div class="when">
<input type="text" id="datepicker" name="date" style="flex: 7;">
<span style="flex: 0.5;">@</span>
<input type="text" id="spinner-hour" name="hour" style="flex: 4;">
<span style="flex: 0.5;">:</span>
<input type="text" id="spinner-minute" name="minute" style="flex: 4;">
</div>
<h3>Choose a description</h3>
<input type="text" name="flavor_text" id="flavor-text">
<h3>Estimated cook: <img src="{{url_for('static', filename=current_user.name + '.png')}}" id="est-cook" class="flex-small-thumb" title="{{current_user.name}}"></h3>
</div>
<div class="flex-card-vert">
<h3>Add people</h3>
<div class="add-people-container">
<div class="flex-card" style="margin: 0">
<img src="{{url_for('static', filename=current_user.name + '.png')}}">
<span class="username">{{ current_user.name }}</span>
</div>
<div class="small-round-button"><i class="fa fa-minus" aria-hidden="true"></i></div>
</div>
<div class="add-people-container">
<div class="flex-card" style="margin: 0">
<img src="{{url_for('static', filename=current_user.name + '.png')}}">
<span class="username">{{ current_user.name }}</span>
</div>
<div class="small-round-button"><i class="fa fa-minus" aria-hidden="true"></i></div>
</div>
<div class="add-people-container">
<input type="text" id="search-user">
<div class="user-result-container"></div>
<div class="round-button" onclick="add_user()"><i class="fa fa-plus" aria-hidden="true"></i></div>
</div>
</div>
<div class="user-card">
<img src="{{url_for('static', filename=current_user.name + '.png')}}">
<div class="user-info">
<span>{{current_user.name}}</span>
<div class="rect-button" onclick="location.href='/logout';" style="background-color: #EE7500;">LOGOUT</div>
</div>
</div>
<div class="floating-round-button" onclick="plan_meal()" style="bottom: 20px; right: 20px;"><i class="fa fa-check" aria-hidden="true"></i></div>
<!-- Pick a date <input type="text" id="datepicker"><br>
Pick a time <input type="text" id="spinner-hour" style="width: 3em;">&nbsp;:&nbsp;<input type="text" id="spinner-minute" style="width: 3em;"> -->
</body>
</html>

@ -44,7 +44,7 @@
</div>
<h2>Eaters</h2>
{% for eater in meal.eaters %}
<div class="flex-card">
<div class="flex-card">
<img src="{{url_for('static', filename=eater + '.png')}}">
<span class="username">{{ eater }}</span>
</div>

Loading…
Cancel
Save