Basic interface
This commit is contained in:
parent
458156fafd
commit
14ddbf0ce4
54
server.py
54
server.py
@ -1,9 +1,51 @@
|
|||||||
from models import user, events
|
from flask import Flask, render_template, request, jsonify, make_response, request
|
||||||
from apis import sbb
|
import random
|
||||||
|
import time
|
||||||
|
|
||||||
SBB = sbb.SBBWrapper()
|
from flask.templating import render_template_string
|
||||||
|
|
||||||
ret = SBB.wrapper.locations.get(params={"name":"Zürich"})
|
app = Flask(__name__)
|
||||||
print(ret[:3])
|
|
||||||
|
|
||||||
# def load_events()
|
heading = "Lorem ipsum dolor sit amet."
|
||||||
|
|
||||||
|
content = """
|
||||||
|
Lorem ipsum dolor sit amet consectetur, adipisicing elit.
|
||||||
|
Repellat inventore assumenda laboriosam,
|
||||||
|
obcaecati saepe pariatur atque est? Quam, molestias nisi.
|
||||||
|
"""
|
||||||
|
|
||||||
|
db = list() # The mock database
|
||||||
|
|
||||||
|
posts = 500 # num posts to generate
|
||||||
|
|
||||||
|
quantity = 20 # num posts to return per request
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/")
|
||||||
|
def index():
|
||||||
|
""" Route to render the HTML """
|
||||||
|
context = {
|
||||||
|
"title" : f"Event title {id}",
|
||||||
|
"image_name" : "fallback.jpg",
|
||||||
|
"star_rating" : random.randint(1,4),
|
||||||
|
"reviews" : random.randint(10,30),
|
||||||
|
"user" : "Remy"
|
||||||
|
}
|
||||||
|
return render_template("base.html", context=context)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@app.route("/get_event")
|
||||||
|
def get_event():
|
||||||
|
id = request.args.get("id", type = int)
|
||||||
|
context = {
|
||||||
|
"title" : f"Event title {id}",
|
||||||
|
"image_name" : "fallback.jpg",
|
||||||
|
"star_rating" : random.randint(1,4),
|
||||||
|
"reviews" : random.randint(10,30),
|
||||||
|
"user" : "Remy"
|
||||||
|
}
|
||||||
|
return render_template("event_card.html", context=context)
|
||||||
|
|
||||||
|
|
||||||
|
app.run(port=8000, debug=True)
|
BIN
static/SBB-Logo.png
Normal file
BIN
static/SBB-Logo.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 4.1 KiB |
9
static/custom-bootstrap-override.css
Normal file
9
static/custom-bootstrap-override.css
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
.bg-primary .btn-primary .btn-primary:hover{
|
||||||
|
border-color: red;
|
||||||
|
background-color: red !important;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
* {
|
||||||
|
border-radius: 0 !important;
|
||||||
|
}
|
BIN
static/fallback.jpg
Normal file
BIN
static/fallback.jpg
Normal file
Binary file not shown.
After Width: | Height: | Size: 195 KiB |
33
static/index.js
Normal file
33
static/index.js
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
var currentscrollHeight = 0;
|
||||||
|
var count = 0;
|
||||||
|
jQuery(document).ready(function ($) {
|
||||||
|
for (var i = 0; i < 8; i++) {
|
||||||
|
callData(count);//Call 8 times on page load
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
$(window).on("scroll", function () {
|
||||||
|
const scrollHeight = $(document).height();
|
||||||
|
const scrollPos = Math.floor($(window).height() + $(window).scrollTop());
|
||||||
|
const isBottom = scrollHeight - 100 < scrollPos;
|
||||||
|
if (isBottom && currentscrollHeight < scrollHeight) {
|
||||||
|
//alert('calling...');
|
||||||
|
for (var i = 0; i < 6; i++) {
|
||||||
|
callData(count);//Once at bottom of page -> call 6 times
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
currentscrollHeight = scrollHeight;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
function callData(counter) {
|
||||||
|
$.ajax({
|
||||||
|
type: "GET",
|
||||||
|
url: "http://localhost:8000/get_event?id=" + counter,
|
||||||
|
dataType: "html",
|
||||||
|
success: function (result) {
|
||||||
|
//alert(result[0]);
|
||||||
|
$(result).appendTo('.list');
|
||||||
|
},
|
||||||
|
error: function (result) {}
|
||||||
|
});
|
||||||
|
}
|
32
templates/base.html
Normal file
32
templates/base.html
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<!doctype html>
|
||||||
|
<html lang="en">
|
||||||
|
|
||||||
|
<head>
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||||
|
|
||||||
|
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/css/bootstrap.min.css" integrity="undefined" crossorigin="anonymous">
|
||||||
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.0.1/dist/js/bootstrap.min.js" integrity="undefined" crossorigin="anonymous"></script>
|
||||||
|
<link href="static/custom-bootstrap-override.css" rel="stylesheet">
|
||||||
|
|
||||||
|
<!-- Font Awesome JS -->
|
||||||
|
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9" crossorigin="anonymous">
|
||||||
|
|
||||||
|
<!-- Jquery + ajax (dynamic content) -->
|
||||||
|
<script src="https://code.jquery.com/jquery-3.6.0.min.js" integrity="sha256-/xUj+3OJU5yExlq6GSYGSHk7tPXikynS7ogEvDej/m4=" crossorigin="anonymous"></script>
|
||||||
|
|
||||||
|
<script src="static/index.js"></script>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
{% include "sidebar.html" %}
|
||||||
|
<div class="container-fluid">
|
||||||
|
<h1 class="display-3">Physical doodling</h1>
|
||||||
|
<div class="row row-cols-1 row-cols-lg-2 row-cols-xl-3 row-cols-xxl-4 p-1">
|
||||||
|
<h1 class="display-3">Welcome {{ context.user }}</h1>
|
||||||
|
|
||||||
|
<div class="col">
|
||||||
|
<div class="list">
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</body>
|
||||||
|
</html>
|
24
templates/event_card.html
Normal file
24
templates/event_card.html
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
<div class="card mb-4 shadow">
|
||||||
|
<!-- <div class="card-header"> -->
|
||||||
|
<img src="static/{{ context.image_name }}" class="card-img-top" alt="...">
|
||||||
|
<!-- </div> -->
|
||||||
|
<div class="sep"></div>
|
||||||
|
<div class="card-body">
|
||||||
|
<h5 class="card-title">{{ context.title }}</h5>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<li class="list-group-item"><i class="far fa-clock"></i> Total duration: {{context.duration }}</li>
|
||||||
|
<li class="list-group-item"><i class="far fa-map"></i> {{ context.location }}</li>
|
||||||
|
<ul class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<span>
|
||||||
|
{% for n in range(context.star_rating) %}
|
||||||
|
<i class="fas fa-star"></i>
|
||||||
|
{% endfor %}
|
||||||
|
{% for n in range(5 - context.star_rating) %}
|
||||||
|
<i class="far fa-star"></i>
|
||||||
|
{% endfor %}
|
||||||
|
</span>
|
||||||
|
<span class="badge bg-secondary small rounded-pill">{{ context.reviews }} reviews</span>
|
||||||
|
</ul>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
</div>
|
16
templates/sidebar.html
Normal file
16
templates/sidebar.html
Normal file
@ -0,0 +1,16 @@
|
|||||||
|
<nav class="navbar navbar-dark fixed-top bg-secondary">
|
||||||
|
<div class="container-fluid">
|
||||||
|
<a class="navbar-brand" href="/">
|
||||||
|
<img src="/static/SBB-Logo.png" alt="SBB" width="50px">
|
||||||
|
<span class="font-monospace fw-bold">Click & Hike</span>
|
||||||
|
</a>
|
||||||
|
|
||||||
|
|
||||||
|
<form class="d-flex">
|
||||||
|
<a href="/profile" style="color: inherit; text-decoration: none;">
|
||||||
|
<i class="fas fa-user"></i>
|
||||||
|
</a>
|
||||||
|
</form>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
</nav>
|
Loading…
x
Reference in New Issue
Block a user