This commit is contained in:
boyska 2020-02-16 00:52:11 +01:00
commit 91386bcc67
9 changed files with 740 additions and 0 deletions

1
.agignore Normal file
View file

@ -0,0 +1 @@
static/jquery-ui/

163
app.py Normal file
View file

@ -0,0 +1,163 @@
import flask
import sqlite3
from datetime import datetime
from flask import Flask, render_template, redirect, url_for, request, jsonify
from flask_sqlalchemy import SQLAlchemy
import sqlalchemy.exc
from sqlalchemy_utils import PasswordType
# from sqlalchemy import Column, Integer, String
# from sqlalchemy.ext.declarative import declarative_base
# TODO: sqlalchemy?
# schema:
# Utente: uid, username, password
# TipoRadio: trid, tipo
# Avvistamento: aid, uid, tipo_radio, data, commento
app = Flask(__name__)
app.config["SQLALCHEMY_DATABASE_URI"] = "sqlite:///map.db"
db = SQLAlchemy(app)
class User(db.Model):
__tablename__ = "user"
uid = db.Column(db.Integer, primary_key=True, nullable=False)
username = db.Column(db.String, unique=True)
password = db.Column(PasswordType(schemes=["pbkdf2_sha512"]))
rapporti = db.relationship("RapportoRicezione")
class TipoRadio(db.Model):
__tablename__ = "tiporadio"
tid = db.Column(db.Integer, primary_key=True, nullable=False)
nome = db.Column(db.Unicode)
descrizione = db.Column(db.Unicode)
rapporti = db.relationship("RapportoRicezione")
class RapportoRicezione(db.Model):
__tablename__ = "rapporto"
rid = db.Column(db.Integer, primary_key=True)
uid = db.Column(db.Integer, db.ForeignKey("user.uid"))
tid = db.Column(db.Integer, db.ForeignKey("tiporadio.tid"))
date = db.Column(db.Date, default=lambda: datetime.now())
lat = db.Column(db.Float)
lng = db.Column(db.Float)
comprensibile = db.Column(db.Integer) # TODO: >= 0 <= 5
stabilita = db.Column(db.Integer) # TODO: >= 0 <= 5
author = db.relationship(User, back_populates="rapporti")
tipo_radio = db.relationship(TipoRadio, back_populates="rapporti")
def serialize(self):
d = {k:v for k,v in self.__dict__.items() if not k.startswith('_')}
d['colore'] = self.colore
d['radius'] = self.radius
d['explaination'] = self.explaination
return d
@property
def colore(self):
c = self.comprensibile
if c > 3:
return 'green'
if c > 1:
return 'yellow'
return 'red'
@property
def radius(self):
return self.stabilita * 70
@property
def explaination(self):
return 'Aggiunto il %s da %s' % (self.date, self.author.username)
def __repr__(self):
return "<Rapporto %s del %s>" % (self.rid, self.date)
@app.before_first_request
def init_db():
db.create_all()
try:
anon = User(username="anonymous", password="antani")
db.session.add(anon)
db.session.commit()
except sqlalchemy.exc.IntegrityError:
db.session.rollback()
for nome in ["radiolina portatile", "autoradio", "stereo fisso dentro casa"]:
try:
t = TipoRadio(nome=nome)
db.session.add(t)
db.session.commit()
except sqlalchemy.exc.IntegrityError:
db.session.rollback()
cnt = int(RapportoRicezione.query.count())
if cnt == 0:
for i in range(6):
r = RapportoRicezione(
uid=User.query.filter(User.username == "anonymous")[0].uid,
tid=TipoRadio.query.all()[0].tid,
stabilita=i,
comprensibile=i,
lat=43.8199 - i * 0.01,
lng=11.22185 + i * 0.03,
)
db.session.add(r)
db.session.commit()
@app.route("/")
def home():
return render_template("index.html")
@app.route("/add")
def add():
return render_template("add.html")
@app.route("/api/rapporti/get")
def get_rapporti():
query = RapportoRicezione.query.all()
# TODO: usa query params per filtrare in base a $cose
return jsonify(dict(rapporti=[r.serialize() for r in query]))
@app.route("/api/rapporti/add", methods=['POST'])
def add_rapporto():
anon = User.query.filter(User.username=='anonymous')[0].uid
r = RapportoRicezione(
uid=anon,
lat=request.form['lat'],
lng=request.form['lng'],
stabilita=request.form['stabilita'],
comprensibile=request.form['comprensibile'],
)
db.session.add(r)
db.session.commit()
r = RapportoRicezione.query.get(r.rid)
return jsonify(r.serialize())
@app.route("/api/rapporti/delete", methods=['POST'])
def delete_rapporto():
r = RapportoRicezione.query.get(int(request.form['rid']))
db.session.delete(r)
db.session.commit()
return jsonify(True)

11
requirements.txt Normal file
View file

@ -0,0 +1,11 @@
Click==7.0
Flask-SQLAlchemy==2.4.1
Flask==1.1.1
Jinja2==2.11.1
MarkupSafe==1.1.1
SQLAlchemy-Utils==0.36.1
SQLAlchemy==1.3.13
Werkzeug==1.0.0
itsdangerous==1.1.0
passlib==1.7.2
six==1.14.0

View file

@ -0,0 +1,333 @@
Authors ordered by first contribution
A list of current team members is available at http://jqueryui.com/about
Paul Bakaus <paul.bakaus@gmail.com>
Richard Worth <rdworth@gmail.com>
Yehuda Katz <wycats@gmail.com>
Sean Catchpole <sean@sunsean.com>
John Resig <jeresig@gmail.com>
Tane Piper <piper.tane@gmail.com>
Dmitri Gaskin <dmitrig01@gmail.com>
Klaus Hartl <klaus.hartl@gmail.com>
Stefan Petre <stefan.petre@gmail.com>
Gilles van den Hoven <gilles@webunity.nl>
Micheil Bryan Smith <micheil@brandedcode.com>
Jörn Zaefferer <joern.zaefferer@gmail.com>
Marc Grabanski <m@marcgrabanski.com>
Keith Wood <kbwood@iinet.com.au>
Brandon Aaron <brandon.aaron@gmail.com>
Scott González <scott.gonzalez@gmail.com>
Eduardo Lundgren <eduardolundgren@gmail.com>
Aaron Eisenberger <aaronchi@gmail.com>
Joan Piedra <theneojp@gmail.com>
Bruno Basto <b.basto@gmail.com>
Remy Sharp <remy@leftlogic.com>
Bohdan Ganicky <bohdan.ganicky@gmail.com>
David Bolter <david.bolter@gmail.com>
Chi Cheng <cloudream@gmail.com>
Ca-Phun Ung <pazu2k@gmail.com>
Ariel Flesler <aflesler@gmail.com>
Maggie Wachs <maggie@filamentgroup.com>
Scott Jehl <scottjehl@gmail.com>
Todd Parker <todd@filamentgroup.com>
Andrew Powell <andrew@shellscape.org>
Brant Burnett <btburnett3@gmail.com>
Douglas Neiner <doug@dougneiner.com>
Paul Irish <paul.irish@gmail.com>
Ralph Whitbeck <ralph.whitbeck@gmail.com>
Thibault Duplessis <thibault.duplessis@gmail.com>
Dominique Vincent <dominique.vincent@toitl.com>
Jack Hsu <jack.hsu@gmail.com>
Adam Sontag <ajpiano@ajpiano.com>
Carl Fürstenberg <carl@excito.com>
Kevin Dalman <development@allpro.net>
Alberto Fernández Capel <afcapel@gmail.com>
Jacek Jędrzejewski (http://jacek.jedrzejewski.name)
Ting Kuei <ting@kuei.com>
Samuel Cormier-Iijima <sam@chide.it>
Jon Palmer <jonspalmer@gmail.com>
Ben Hollis <bhollis@amazon.com>
Justin MacCarthy <Justin@Rubystars.biz>
Eyal Kobrigo <kobrigo@hotmail.com>
Tiago Freire <tiago.freire@gmail.com>
Diego Tres <diegotres@gmail.com>
Holger Rüprich <holger@rueprich.de>
Ziling Zhao <zilingzhao@gmail.com>
Mike Alsup <malsup@gmail.com>
Robson Braga Araujo <robsonbraga@gmail.com>
Pierre-Henri Ausseil <ph.ausseil@gmail.com>
Christopher McCulloh <cmcculloh@gmail.com>
Andrew Newcomb <ext.github@preceptsoftware.co.uk>
Lim Chee Aun <cheeaun@gmail.com>
Jorge Barreiro <yortx.barry@gmail.com>
Daniel Steigerwald <daniel@steigerwald.cz>
John Firebaugh <john_firebaugh@bigfix.com>
John Enters <github@darkdark.net>
Andrey Kapitcyn <ru.m157y@gmail.com>
Dmitry Petrov <dpetroff@gmail.com>
Eric Hynds <eric@hynds.net>
Chairat Sunthornwiphat <pipo@sixhead.com>
Josh Varner <josh.varner@gmail.com>
Stéphane Raimbault <stephane.raimbault@gmail.com>
Jay Merrifield <fracmak@gmail.com>
J. Ryan Stinnett <jryans@gmail.com>
Peter Heiberg <peter@heiberg.se>
Alex Dovenmuehle <adovenmuehle@gmail.com>
Jamie Gegerson <git@jamiegegerson.com>
Raymond Schwartz <skeetergraphics@gmail.com>
Phillip Barnes <philbar@gmail.com>
Kyle Wilkinson <kai@wikyd.org>
Khaled AlHourani <me@khaledalhourani.com>
Marian Rudzynski <mr@impaled.org>
Jean-Francois Remy <jeff@melix.org>
Doug Blood <dougblood@gmail.com>
Filippo Cavallarin <filippo.cavallarin@codseq.it>
Heiko Henning <heiko@thehennings.ch>
Aliaksandr Rahalevich <saksmlz@gmail.com>
Mario Visic <mario@mariovisic.com>
Xavi Ramirez <xavi.rmz@gmail.com>
Max Schnur <max.schnur@gmail.com>
Saji Nediyanchath <saji89@gmail.com>
Corey Frang <gnarf37@gmail.com>
Aaron Peterson <aaronp123@yahoo.com>
Ivan Peters <ivan@ivanpeters.com>
Mohamed Cherif Bouchelaghem <cherifbouchelaghem@yahoo.fr>
Marcos Sousa <falecomigo@marcossousa.com>
Michael DellaNoce <mdellanoce@mailtrust.com>
George Marshall <echosx@gmail.com>
Tobias Brunner <tobias@strongswan.org>
Martin Solli <msolli@gmail.com>
David Petersen <public@petersendidit.com>
Dan Heberden <danheberden@gmail.com>
William Kevin Manire <williamkmanire@gmail.com>
Gilmore Davidson <gilmoreorless@gmail.com>
Michael Wu <michaelmwu@gmail.com>
Adam Parod <mystic414@gmail.com>
Guillaume Gautreau <guillaume+github@ghusse.com>
Marcel Toele <EleotleCram@gmail.com>
Dan Streetman <ddstreet@ieee.org>
Matt Hoskins <matt@nipltd.com>
Giovanni Giacobbi <giovanni@giacobbi.net>
Kyle Florence <kyle.florence@gmail.com>
Pavol Hluchý <lopo@losys.sk>
Hans Hillen <hans.hillen@gmail.com>
Mark Johnson <virgofx@live.com>
Trey Hunner <treyhunner@gmail.com>
Shane Whittet <whittet@gmail.com>
Edward A Faulkner <ef@alum.mit.edu>
Adam Baratz <adam@adambaratz.com>
Kato Kazuyoshi <kato.kazuyoshi@gmail.com>
Eike Send <eike.send@gmail.com>
Kris Borchers <kris.borchers@gmail.com>
Eddie Monge <eddie@eddiemonge.com>
Israel Tsadok <itsadok@gmail.com>
Carson McDonald <carson@ioncannon.net>
Jason Davies <jason@jasondavies.com>
Garrison Locke <gplocke@gmail.com>
David Murdoch <david@davidmurdoch.com>
Benjamin Scott Boyle <benjamins.boyle@gmail.com>
Jesse Baird <jebaird@gmail.com>
Jonathan Vingiano <jvingiano@gmail.com>
Dylan Just <dev@ephox.com>
Hiroshi Tomita <tomykaira@gmail.com>
Glenn Goodrich <glenn.goodrich@gmail.com>
Tarafder Ashek-E-Elahi <mail.ashek@gmail.com>
Ryan Neufeld <ryan@neufeldmail.com>
Marc Neuwirth <marc.neuwirth@gmail.com>
Philip Graham <philip.robert.graham@gmail.com>
Benjamin Sterling <benjamin.sterling@kenzomedia.com>
Wesley Walser <waw325@gmail.com>
Kouhei Sutou <kou@clear-code.com>
Karl Kirch <karlkrch@gmail.com>
Chris Kelly <ckdake@ckdake.com>
Jason Oster <jay@kodewerx.org>
Felix Nagel <info@felixnagel.com>
Alexander Polomoshnov <alex.polomoshnov@gmail.com>
David Leal <dgleal@gmail.com>
Igor Milla <igor.fsp.milla@gmail.com>
Dave Methvin <dave.methvin@gmail.com>
Florian Gutmann <f.gutmann@chronimo.com>
Marwan Al Jubeh <marwan.aljubeh@gmail.com>
Milan Broum <midlis@googlemail.com>
Sebastian Sauer <info@dynpages.de>
Gaëtan Muller <m.gaetan89@gmail.com>
Michel Weimerskirch <michel@weimerskirch.net>
William Griffiths <william@ycymro.com>
Stojce Slavkovski <stojce@gmail.com>
David Soms <david.soms@gmail.com>
David De Sloovere <david.desloovere@outlook.com>
Michael P. Jung <michael.jung@terreon.de>
Shannon Pekary <spekary@gmail.com>
Dan Wellman <danwellman@hotmail.com>
Matthew Edward Hutton <meh@corefiling.co.uk>
James Khoury <james@jameskhoury.com>
Rob Loach <robloach@gmail.com>
Alberto Monteiro <betimbrasil@gmail.com>
Alex Rhea <alex.rhea@gmail.com>
Krzysztof Rosiński <rozwell69@gmail.com>
Ryan Olton <oltonr@gmail.com>
Genie <386@mail.com>
Rick Waldron <waldron.rick@gmail.com>
Ian Simpson <spoonlikesham@gmail.com>
Lev Kitsis <spam4lev@gmail.com>
TJ VanToll <tj.vantoll@gmail.com>
Justin Domnitz <jdomnitz@gmail.com>
Douglas Cerna <douglascerna@yahoo.com>
Bert ter Heide <bertjh@hotmail.com>
Jasvir Nagra <jasvir@gmail.com>
Yuriy Khabarov <13real008@gmail.com>
Harri Kilpiö <harri.kilpio@gmail.com>
Lado Lomidze <lado.lomidze@gmail.com>
Amir E. Aharoni <amir.aharoni@mail.huji.ac.il>
Simon Sattes <simon.sattes@gmail.com>
Jo Liss <joliss42@gmail.com>
Guntupalli Karunakar <karunakarg@yahoo.com>
Shahyar Ghobadpour <shahyar@gmail.com>
Lukasz Lipinski <uzza17@gmail.com>
Timo Tijhof <krinklemail@gmail.com>
Jason Moon <jmoon@socialcast.com>
Martin Frost <martinf55@hotmail.com>
Eneko Illarramendi <eneko@illarra.com>
EungJun Yi <semtlenori@gmail.com>
Courtland Allen <courtlandallen@gmail.com>
Viktar Varvanovich <non4eg@gmail.com>
Danny Trunk <dtrunk90@gmail.com>
Pavel Stetina <pavel.stetina@nangu.tv>
Michael Stay <metaweta@gmail.com>
Steven Roussey <sroussey@gmail.com>
Michael Hollis <hollis21@gmail.com>
Lee Rowlands <lee.rowlands@previousnext.com.au>
Timmy Willison <timmywillisn@gmail.com>
Karl Swedberg <kswedberg@gmail.com>
Baoju Yuan <the_guy_1987@hotmail.com>
Maciej Mroziński <maciej.k.mrozinski@gmail.com>
Luis Dalmolin <luis.nh@gmail.com>
Mark Aaron Shirley <maspwr@gmail.com>
Martin Hoch <martin@fidion.de>
Jiayi Yang <tr870829@gmail.com>
Philipp Benjamin Köppchen <xgxtpbk@gws.ms>
Sindre Sorhus <sindresorhus@gmail.com>
Bernhard Sirlinger <bernhard.sirlinger@tele2.de>
Jared A. Scheel <jared@jaredscheel.com>
Rafael Xavier de Souza <rxaviers@gmail.com>
John Chen <zhang.z.chen@intel.com>
Robert Beuligmann <robertbeuligmann@gmail.com>
Dale Kocian <dale.kocian@gmail.com>
Mike Sherov <mike.sherov@gmail.com>
Andrew Couch <andy@couchand.com>
Marc-Andre Lafortune <github@marc-andre.ca>
Nate Eagle <nate.eagle@teamaol.com>
David Souther <davidsouther@gmail.com>
Mathias Stenbom <mathias@stenbom.com>
Sergey Kartashov <ebishkek@yandex.ru>
Avinash R <nashpapa@gmail.com>
Ethan Romba <ethanromba@gmail.com>
Cory Gackenheimer <cory.gack@gmail.com>
Juan Pablo Kaniefsky <jpkaniefsky@gmail.com>
Roman Salnikov <bardt.dz@gmail.com>
Anika Henke <anika@selfthinker.org>
Samuel Bovée <samycookie2000@yahoo.fr>
Fabrício Matté <ult_combo@hotmail.com>
Viktor Kojouharov <vkojouharov@gmail.com>
Pawel Maruszczyk (http://hrabstwo.net)
Pavel Selitskas <p.selitskas@gmail.com>
Bjørn Johansen <post@bjornjohansen.no>
Matthieu Penant <thieum22@hotmail.com>
Dominic Barnes <dominic@dbarnes.info>
David Sullivan <david.sullivan@gmail.com>
Thomas Jaggi <thomas@responsive.ch>
Vahid Sohrabloo <vahid4134@gmail.com>
Travis Carden <travis.carden@gmail.com>
Bruno M. Custódio <bruno@brunomcustodio.com>
Nathanael Silverman <nathanael.silverman@gmail.com>
Christian Wenz <christian@wenz.org>
Steve Urmston <steve@urm.st>
Zaven Muradyan <megalivoithos@gmail.com>
Woody Gilk <shadowhand@deviantart.com>
Zbigniew Motyka <zbigniew.motyka@gmail.com>
Suhail Alkowaileet <xsoh.k7@gmail.com>
Toshi MARUYAMA <marutosijp2@yahoo.co.jp>
David Hansen <hansede@gmail.com>
Brian Grinstead <briangrinstead@gmail.com>
Christian Klammer <christian314159@gmail.com>
Steven Luscher <jquerycla@steveluscher.com>
Gan Eng Chin <engchin.gan@gmail.com>
Gabriel Schulhof <gabriel.schulhof@intel.com>
Alexander Schmitz <arschmitz@gmail.com>
Vilhjálmur Skúlason <vis@dmm.is>
Siebrand Mazeland <siebrand@kitano.nl>
Mohsen Ekhtiari <mohsenekhtiari@yahoo.com>
Pere Orga <gotrunks@gmail.com>
Jasper de Groot <mail@ugomobi.com>
Stephane Deschamps <stephane.deschamps@gmail.com>
Jyoti Deka <dekajp@gmail.com>
Andrei Picus <office.nightcrawler@gmail.com>
Ondrej Novy <novy@ondrej.org>
Jacob McCutcheon <jacob.mccutcheon@gmail.com>
Monika Piotrowicz <monika.piotrowicz@gmail.com>
Imants Horsts <imants.horsts@inbox.lv>
Eric Dahl <eric.c.dahl@gmail.com>
Dave Stein <dave@behance.com>
Dylan Barrell <dylan@barrell.com>
Daniel DeGroff <djdegroff@gmail.com>
Michael Wiencek <mwtuea@gmail.com>
Thomas Meyer <meyertee@gmail.com>
Ruslan Yakhyaev <ruslan@ruslan.io>
Brian J. Dowling <bjd-dev@simplicity.net>
Ben Higgins <ben@extrahop.com>
Yermo Lamers <yml@yml.com>
Patrick Stapleton <github@gdi2290.com>
Trisha Crowley <trisha.crowley@gmail.com>
Usman Akeju <akeju00+github@gmail.com>
Rodrigo Menezes <rod333@gmail.com>
Jacques Perrault <jacques_perrault@us.ibm.com>
Frederik Elvhage <frederik.elvhage@googlemail.com>
Will Holley <willholley@gmail.com>
Uri Gilad <antishok@gmail.com>
Richard Gibson <richard.gibson@gmail.com>
Simen Bekkhus <sbekkhus91@gmail.com>
Chen Eshchar <eshcharc@gmail.com>
Bruno Pérel <brunoperel@gmail.com>
Mohammed Alshehri <m@dralshehri.com>
Lisa Seacat DeLuca <ldeluca@us.ibm.com>
Anne-Gaelle Colom <coloma@westminster.ac.uk>
Adam Foster <slimfoster@gmail.com>
Luke Page <luke.a.page@gmail.com>
Daniel Owens <daniel@matchstickmixup.com>
Michael Orchard <morchard@scottlogic.co.uk>
Marcus Warren <marcus@envoke.com>
Nils Heuermann <nils@world-of-scripts.de>
Marco Ziech <marco@ziech.net>
Patricia Juarez <patrixd@gmail.com>
Ben Mosher <me@benmosher.com>
Ablay Keldibek <atomio.ak@gmail.com>
Thomas Applencourt <thomas.applencourt@irsamc.ups-tlse.fr>
Jiabao Wu <jiabao.foss@gmail.com>
Eric Lee Carraway <github@ericcarraway.com>
Victor Homyakov <vkhomyackov@gmail.com>
Myeongjin Lee <aranet100@gmail.com>
Liran Sharir <lsharir@gmail.com>
Weston Ruter <weston@xwp.co>
Mani Mishra <manimishra902@gmail.com>
Hannah Methvin <hannahmethvin@gmail.com>
Leonardo Balter <leonardo.balter@gmail.com>
Benjamin Albert <benjamin_a5@yahoo.com>
Michał Gołębiowski <m.goleb@gmail.com>
Alyosha Pushak <alyosha.pushak@gmail.com>
Fahad Ahmad <fahadahmad41@hotmail.com>
Matt Brundage <github@mattbrundage.com>
Francesc Baeta <francesc.baeta@gmail.com>
Piotr Baran <piotros@wp.pl>
Mukul Hase <mukulhase@gmail.com>
Konstantin Dinev <kdinev@mail.bw.edu>
Rand Scullard <rand@randscullard.com>
Dan Strohl <dan@wjcg.net>
Maksim Ryzhikov <rv.maksim@gmail.com>
Amine HADDAD <haddad@allegorie.tv>
Amanpreet Singh <apsdehal@gmail.com>
Alexey Balchunas <bleshik@gmail.com>
Peter Kehl <peter.kehl@gmail.com>
Peter Dave Hello <hsu@peterdavehello.org>
Johannes Schäfer <johnschaefer@gmx.de>
Ville Skyttä <ville.skytta@iki.fi>
Ryan Oriecuia <ryan.oriecuia@visioncritical.com>

69
static/js/addmap.js Normal file
View file

@ -0,0 +1,69 @@
function viewMap() {
var map = L.map('mapid').setView([43.797, 11.2400], 11);
// Set up the OSM layer
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
).addTo(map);
$.getJSON('/api/rapporti/get', function(data) {
for(var i in data.rapporti) {
var p = data.rapporti[i]
L.circle([p.lat, p.lng], {
color: p.colore,
fillColor:p.colore,
fillOpacity: 0.2,
opacity: 0.7,
radius: p.radius,
}).addTo(map)
}
})
function addPointToDb(dati) {
$.post('/api/rapporti/add', dati
, function(p) {
console.log(p)
L.circle([p.lat, p.lng], {
color: p.colore,
fillColor:p.colore,
fillOpacity: 0.5,
radius: p.radius,
}).addTo(map)
})
}
function onFormSubmit() {
addPointToDb({
lat: $('#pointform input[name=lat]').val(),
lng: $('#pointform input[name=lng]').val(),
stabilita: $('#pointform select[name=stabilita]').val(),
comprensibile: $('#pointform select[name=comprensibile]').val(),
})
$('#pointform').addClass('hidden')
return false;
}
function onMapClick(e) {
console.log('click', e)
console.log(e.latlng)
var stabilita = 3
console.log(map.getZoom())
if(map.getZoom() > 15) {
stabilita = 19 - map.getZoom()
}
console.log('st', stabilita)
$('#pointform input[name=lat]').val(e.latlng.lat)
$('#pointform input[name=lng]').val(e.latlng.lng)
$('#pointform select[name=stabilita]').val(stabilita)
$('#pointform').removeClass('hidden')
// TODO: aggiungi punto temporaneo, ma poi va rimosso
}
map.on('click', onMapClick)
$('#addPoint').on('click', onFormSubmit)
}
jQuery(function($) {
$('#mapid').css('height', $(window).height() - 200)
viewMap()
})

55
static/js/viewmap.js Normal file
View file

@ -0,0 +1,55 @@
RapportoMarker = L.Circle.extend({ options: { originalData: 0 } });
function viewMap() {
var map = L.map('mapid').setView([43.797, 11.2400], 11);
// Set up the OSM layer
L.tileLayer(
'https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png'
).addTo(map);
$.getJSON('/api/rapporti/get', function(data) {
for(var i in data.rapporti) {
var p = data.rapporti[i]
var marker = new RapportoMarker([p.lat, p.lng], {
color: p.colore,
fillColor:p.colore,
fillOpacity: 0.3,
radius: p.radius,
originalData: p,
})
marker.addTo(map).bindPopup(p.explaination)
marker.off('click')
marker.on('click', onMarkerClicked)
}
})
function onMarkerClicked(evt) {
console.log('T', this)
var data = evt.target.options.originalData
var rid = data.rid
$('#dialog').html('<div class="explaination"></div><div class="actions"></div>')
$('#dialog .explaination').text(data.explaination)
$('#dialog .actions').html('<button class="btn-elimina">Elimina</button>')
$('#dialog').attr('title', rid)
$('#dialog').data('rid', rid)
$('#dialog').data('marker', this)
$('#dialog').dialog({
modal: true,
beforeClose: function(event, ui) {
$('#dialog').dialog('destroy')
$('#dialog')[0].outerHTML = '<div id="dialog"></div>'
}
})
}
$('body').on('click', '.btn-elimina', function onCancella(evt) {
var rid = $('#dialog').data('rid')
console.log('cancelliamo?', rid)
$.post('/api/rapporti/delete', {rid: rid}, function() {
map.removeLayer($('#dialog').data('marker'))
$('#dialog').dialog('close')
})
})
}
jQuery(function($) {
$('#mapid').css('height', $(window).height() - 200)
viewMap()
})

33
templates/add.html Normal file
View file

@ -0,0 +1,33 @@
{% extends 'base.html' %}
{% block extra_scripts %}
<script src="{{url_for('static', filename='js/addmap.js')}}">
</script>
{% endblock extra_scripts %}
{% block content %}
<form id="pointform" class="hidden">
<label>Ricezione</label> <select name="comprensibile">
<option value="0">Segnale del tutto assente</option>
<option value="1">Tracce vaghe di una radio in sottofondo</option>
<option value="2">Si capisce che c'è una radio, ma non si capisce nulla</option>
<option value="3">La ricezione è disturbata ma con attenzione si capisce cosa stanno dicendo o il
genere di
musica che sta passando</option>
<option value="4">si capisce cosa dicono o che canzone sta andando ma ci sono fruscii e disturbi vari</option>
<option value="5">Segnale limpido, si sente bene</option>
</select>
<label>Questa osservazione si verifica</label> <select name="stabilita">
<option value="1">Solo in un punto precisissimo. Se ti sposti anche di poco, non vale più</option>
<option value="2">Nel raggio di 30 metri, in base a come giochi con l'atenna</option>
<option value="3">In tutta la piazza, muovere l'antenna o cambiare radio cambia poco</option>
<option value="4">Nel raggio di 500 metri</option>
<option value="5">In tutto il quartiere</option>
</select>
<input type="hidden" name="lat" />
<input type="hidden" name="lng" />
<button id="addPoint">Aggiungi</button>
</form>
{% endblock content %}

63
templates/base.html Normal file
View file

@ -0,0 +1,63 @@
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
{% block all_css %}
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.6.0/dist/leaflet.css"
integrity="sha512-xwE/Az9zrjBIphAcBb3F6JVqxf46+CDLwfLMHloNu6KEQCAWi6HcDUbeOfBIptF7tcCzusKFjFw2yuvEpDL9wQ=="
crossorigin=""/>
{% block extra_css %}
{% endblock extra_css %}
{% endblock all_css %}
<style>
#mapid { height: 700px; z-index: 2;}
.hidden { display: none; }
nav > ul {
background: #fbfbfb;
padding: 1em 0;
}
nav li { display: inline; }
nav li.brand { padding-right: 2em; }
nav li.navigation {
border: 1px solid gray;
border-radius: 0.4em;
padding: 0.1em 1em;
}a[href] {
color: darkred;
font-size: 1.4em;
font-family: Verdana, sans-serif;
text-decoration: none;
}
/*.ui-dialog, .ui-front, #dialog { z-index: 1000 !important; }*/
</style>
</head>
<body>
<nav>
<ul>
<li class="brand"><strong>WomMap</strong></li>
<li class="navigation"><a href="{{url_for('home')}}">Vedi</a></li>
<li class="navigation"><a href="{{url_for('add')}}">Aggiungi</a></li>
</ul>
</nav>
{% block main %}
<div id="main">
<div id="content">
{% block content %}
{% endblock content %}
</div>
<div id="mapid"></div>
</div>
{% endblock main %}
{% block all_scripts %}
<!-- Make sure you put this AFTER Leaflet's CSS -->
<script src="https://unpkg.com/leaflet@1.6.0/dist/leaflet.js"
integrity="sha512-gZwIG9x3wUXg2hdXF6+rVkLF/0Vi9U8D2Ntg4Ga5I5BZpVkVxlJWbSQtXPSiUTtC0TjtGOmxa1AJPuV0CPthew=="
crossorigin=""></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
{% block extra_scripts %}
{% endblock extra_scripts %}
{% endblock %}
</body>
</html>

12
templates/index.html Normal file
View file

@ -0,0 +1,12 @@
{% extends 'base.html' %}
{% block extra_css %}
<link rel="stylesheet" href="{{url_for('static', filename='jquery-ui/jquery-ui.min.css')}}" />
{% endblock extra_css %}
{% block extra_scripts %}
<script src="{{url_for('static', filename='js/viewmap.js')}}"> </script>
<script src="{{url_for('static', filename='jquery-ui/jquery-ui.min.js')}}"> </script>
{% endblock extra_scripts %}
{% block content %}
<div id="dialog"></div>
{% endblock content %}