edited db models to separate address and tele no. added map for locations

This commit is contained in:
Sitt Min Oo 2019-02-14 18:45:24 +01:00
parent 0a36eab231
commit baf000eaab
9 changed files with 90 additions and 12 deletions

View file

@ -18,7 +18,7 @@ specials = ["Nasi Kippenbolletjes Zoetzuur", "Bami Kippenbolletjes Zoetzuur",
def add():
chinees = Location()
chinees.configure("Oceans's Garden",
"Zwijnaardsesteenweg 399 9000 Gent, tel: 09/222.72.74",
"Zwijnaardsesteenweg 399 9000 Gent", "tel: 09/222.72.74",
"http://oceangarden.byethost3.com/studentenmenus.html")
db.session.add(chinees)

View file

@ -45,7 +45,7 @@ pizzasTA = {
def addTA():
primadonna_takeaway = Location()
primadonna_takeaway.configure("Primadonna (takeaway laten bezorgen)", "Overpoortstraat 46 9000 Gent, tel: 0475 40 13 00", "https://www.takeaway.com/be-en/prima-donna")
primadonna_takeaway.configure("Primadonna (takeaway laten bezorgen)", "Overpoortstraat 46 9000 Gent", "tel: 0475 40 13 00", "https://www.takeaway.com/be-en/prima-donna")
db.session.add(primadonna_takeaway)
for pizza, price in pizzasTA.items():
@ -93,7 +93,7 @@ pizzasAfhalen = {
def addAfhalen():
primadonna_afhalen = Location()
primadonna_afhalen.configure("Primadonna (bellen en afhalen)", "Overpoortstraat 46 9000 Gent, tel: 0475 40 13 00", "http://primadonnagent.be/Menu.html")
primadonna_afhalen.configure("Primadonna (bellen en afhalen)", "Overpoortstraat 46 9000 Gent", "tel: 0475 40 13 00", "http://primadonnagent.be/Menu.html")
db.session.add(primadonna_afhalen)
for pizza, price in pizzasAfhalen.items():

View file

@ -11,7 +11,7 @@ pizzas = ['Bolognese de luxe', 'Hawaï', 'Popeye', 'Pepperoni', 'Seafood', 'Hot
def add():
simpizza = Location()
simpizza.configure("Sim-pizza", "De Pintelaan 252 9000 Gent, tel: 09/321.02.00", "http://simpizza.be")
simpizza.configure("Sim-pizza", "De Pintelaan 252 9000 Gent", "tel: 09/321.02.00", "http://simpizza.be")
db.session.add(simpizza)
for pizza in pizzas:

View file

@ -50,10 +50,11 @@ class Location(db.Model):
products = db.relationship('Product', backref='location', lazy='dynamic')
orders = db.relationship('Order', backref='location', lazy='dynamic')
def configure(self, name, address, website):
def configure(self, name, address, telephone, website):
self.name = name
self.address = address
self.website = website
self.telephone = telephone
def __repr__(self):
return '%s' % (self.name)

4
app/static/css/map.css Normal file
View file

@ -0,0 +1,4 @@
#mapid {
min-height: 400px;
height: 600px;
}

View file

@ -6,6 +6,7 @@
('home', 'Home'),
('order_bp.orders', 'Orders'),
('locations', 'Locations'),
('map', 'Map'),
('about', 'About'),
('stats', 'Stats'),
] -%}

View file

@ -15,7 +15,7 @@
{% for loc in locations -%}
<tr>
<td><a href="{{ url_for('location', id=loc.id) }}">{{ loc.name }}</a></td>
<td>{{ loc.address }}<td>
<td>{{ loc.address }} {{ loc.telephone }}<td>
<td><a href="{{ loc.website}}"><span class="glyphicon glyphicon-link"></span></a></td>
</tr>
{%- endfor %}

View file

@ -1,18 +1,85 @@
{% extends "layout.html" %}
{% set active_page = "locations" -%}
{% set active_page = "map" -%}
{% import "utils.html" as util %}
{% block container %}
<div id="mapid"></div>
{% endblock %}
{% block styles %}
{{ super() }}
<link rel="stylesheet" href="{{ url_for('static', filename='css/leaflet.css') }}">
<link rel="stylesheet" href="{{url_for('static', filename='css/map.css')}}">
{% endblock %}
{% block scripts %}
{{super()}}
<script src="{{ url_for('static', filename='js/leaflet.js')}}" ></script>
{% endblock %}
<script src="{{ url_for('static', filename='js/leaflet.js')}}"></script>
{% block container %}
<script>
var map = L.map('mapid').setView([51.0231183, 3.708106], 13);
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
attribution: '&copy; <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
}).addTo(map);
function performRequest(url, success_callback) {
var request = new XMLHttpRequest();
request.open('GET', url, true);
request.onload = function () {
if (this.status >= 200 && this.status < 400) {
// Success!
var data = JSON.parse(this.response);
success_callback(data);
} else {
// We reached our target server, but it returned an error
}
};
request.onerror = function () {
// There was a connection error of some sort
};
request.send();
}
let callback = function OSMCallBack(data){
var lat, lon;
if (data.features.length < 1) {
lat = 51.0538286;
lon = 3.7250121;
var className = 'is-invisible';
var el = document.getElementById('map-error');
if (el.classList)
el.classList.remove(className);
else
el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
} else {
var place = data.features[0].properties;
lat = data.features[0].geometry.coordinates[1];
lon = data.features[0].geometry.coordinates[0];
L.marker([lat, lon]).addTo(map)
.bindPopup(place.name + ', ' + place.street + ' ' + place.housenumber)
.openPopup();
}
};
let locations = [];
let loc = {};
{% for loc in locations -%}
loc = { "address" : "{{loc.address}}",
"name" : "{{loc.name}}"
};
locations.push(loc);
{%- endfor %}
for (let loc of locations) {
performRequest("https://photon.komoot.de/api/?limit=1&q=" + loc.address, callback)
};
</script>
{% endblock %}

View file

@ -19,9 +19,14 @@ def home():
return render_template('home.html', orders=get_orders(),
recently_closed=recently_closed)
@app.route('/map', defaults= {'id': None})
@app.route('/map/<int:id>')
def map(id):
return render_template('maps.html')
locs = Location.query.order_by('name')
return render_template('maps.html', locations= locs)
@app.route('/location')
def locations():
locs = Location.query.order_by('name')