1
Fork 0
mirror of https://github.com/Steffo99/estus.git synced 2024-11-25 17:14:19 +00:00

Finiti i dispositivi!

This commit is contained in:
Steffo 2017-02-03 13:04:11 +01:00 committed by Lorenzo
parent 0f929f58af
commit 3e001d3fb5
7 changed files with 76 additions and 133 deletions

View file

@ -27,12 +27,12 @@ class Ente(db.Model):
nomebreveente = db.Column(db.String(16)) nomebreveente = db.Column(db.String(16))
servizi = db.relationship("Servizio", backref='ente', lazy='dynamic') servizi = db.relationship("Servizio", backref='ente', lazy='dynamic')
def __init__(self, nome, nomebreve): def __init__(self, nomeente, nomebreveente):
self.nome = nome self.nomeente = nomeente
self.nomebreve = nomebreve self.nomebreveente = nomebreveente
def __repr__(self): def __repr__(self):
return "<Ente {}>".format(self.nomebreve) return "<Ente {}>".format(self.nomebreveente)
# Servizio di un ente # Servizio di un ente
@ -42,12 +42,12 @@ class Servizio(db.Model):
nomeservizio = db.Column(db.String(128)) nomeservizio = db.Column(db.String(128))
impiegati = db.relationship("Impiegato", backref='servizio', lazy='dynamic') impiegati = db.relationship("Impiegato", backref='servizio', lazy='dynamic')
def __init__(self, eid, nome): def __init__(self, eid, nomeservizio):
self.eid = eid self.eid = eid
self.nome = nome self.nomeservizio = nomeservizio
def __repr__(self): def __repr__(self):
return "<Servizio {}>".format(self.nome) return "<Servizio {}>".format(self.nomeservizio)
class Impiegato(db.Model): class Impiegato(db.Model):
@ -58,9 +58,9 @@ class Impiegato(db.Model):
passwd = db.Column(db.String(32)) passwd = db.Column(db.String(32))
dispositivi = db.relationship("Accesso", backref='impiegato', lazy='dynamic') dispositivi = db.relationship("Accesso", backref='impiegato', lazy='dynamic')
def __init__(self, sid, nome, username, passwd): def __init__(self, sid, nomeimpiegato, username, passwd):
self.sid = sid self.sid = sid
self.nome = nome self.nomeimpiegato = nomeimpiegato
self.username = username self.username = username
self.passwd = passwd self.passwd = passwd
@ -78,7 +78,7 @@ class Dispositivo(db.Model):
inv_ente = db.Column(db.String(8)) inv_ente = db.Column(db.String(8))
fornitore = db.Column(db.String(64)) fornitore = db.Column(db.String(64))
def __init__(self, tipo, marca, modello, inv_ced, inv_ente, fornitore def __init__(self, tipo, marca, modello, inv_ced, inv_ente, fornitore):
self.tipo = tipo self.tipo = tipo
self.marca = marca self.marca = marca
self.modello = modello self.modello = modello
@ -102,6 +102,7 @@ class Accesso(db.Model):
def __repr__(self): def __repr__(self):
return "<Accesso {} su {}>".format(iid, did) return "<Accesso {} su {}>".format(iid, did)
db.create_all() db.create_all()
nuovouser = User('stagista', 'smecds') nuovouser = User('stagista', 'smecds')

View file

@ -101,7 +101,7 @@ class Accesso(db.Model):
self.did = did self.did = did
def __repr__(self): def __repr__(self):
return "<Accesso {} su {}>".format(iid, did) return "<Accesso {} su {}>".format(self.iid, self.did)
# Funzioni del sito # Funzioni del sito
@ -326,6 +326,20 @@ def page_disp_add():
nuovodisp = Dispositivo(request.form['tipo'], request.form['marca'], request.form['modello'], request.form['inv_ced'], request.form['inv_ente'], request.form['fornitore']) nuovodisp = Dispositivo(request.form['tipo'], request.form['marca'], request.form['modello'], request.form['inv_ced'], request.form['inv_ente'], request.form['fornitore'])
db.session.add(nuovodisp) db.session.add(nuovodisp)
db.session.commit() db.session.commit()
# Trova tutti gli utenti, edizione sporco hack in html
users = list()
while True:
# Trova tutti gli utenti esistenti
userstring = 'utente{}'.format(len(users))
if userstring in request.form:
users.append(request.form[userstring])
else:
break
for user in users:
nuovologin = Accesso(int(user), nuovodisp.did)
db.session.add(nuovologin)
db.session.commit()
#TODO: se un dispositivo non ha utenti si incasina parecchio
return redirect(url_for('page_disp_list')) return redirect(url_for('page_disp_list'))
@app.route('/disp_del/<int:did>') @app.route('/disp_del/<int:did>')
@ -341,38 +355,14 @@ def page_disp_del(did):
def page_disp_list(): def page_disp_list():
if 'username' not in session: if 'username' not in session:
return redirect(url_for('page_login')) return redirect(url_for('page_login'))
accessi = list()
dispositivi = Dispositivo.query.all() dispositivi = Dispositivo.query.all()
for dispositivo in dispositivi:
accesso = Accesso.query.join(Dispositivo).filter_by(did=dispositivo.did).join(Impiegato).all()
accessi.append(accesso)
css = url_for("static", filename="style.css") css = url_for("static", filename="style.css")
return render_template("dispositivo/list.html.j2", css=css, dispositivi=dispositivi, type="disp", user=session["username"]) return render_template("dispositivo/list.html.j2", css=css, accessi=accessi, type="disp", user=session["username"])
@app.route('/disp_list/<int:did>') @app.route('/disp_details')
def page_disp_list_plus(did):
if 'username' not in session:
return redirect(url_for('page_login'))
dispositivi = Dispositivo.query.all()
css = url_for("static", filename="style.css")
return render_template("dispositivo/list.html.j2", css=css, impiegati=impiegati, user=session["username"])
@app.route('/disp_show/<int:did>', methods=['GET', 'POST'])
def page_disp_show(did):
if 'username' not in session:
return redirect(url_for('page_login'))
if request.method == "GET":
opzioni = ["Centralino", "Dispositivo generico di rete", "Marcatempo", "PC", "Portatile", "POS", "Router", "Server", "Stampante di rete", "Switch", "Telefono IP", "Monitor", "Scanner", "Stampante locale"]
dev = Dispositivo.query.get(did)
css = url_for("static", filename="style.css")
return render_template("dispositivo/show.html.j2", css=css, dispositivo=dev, tipi=opzioni, user=session["username"])
else:
dev = Dispositivo.query.get(did)
dev.tipo = request.form["tipo"]
dev.marca = request.form["marca"]
dev.modello = request.form["modello"]
dev.inv_ced = request.form["inv_ced"]
dev.inv_ente = request.form["inv_ente"]
dev.fornitore = request.form["fornitore"]
db.session.commit()
return redirect(url_for('page_disp_list'))
@app.route('/details_host')
def page_details_host(): def page_details_host():
return "Non implementato" raise NotImplementedError()

View file

@ -3,6 +3,35 @@
<title>Aggiunta dispositivo - Inventario</title> <title>Aggiunta dispositivo - Inventario</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="{{css}}"> <link rel="stylesheet" href="{{css}}">
<script src="https://code.jquery.com/jquery-3.1.1.slim.min.js" integrity="sha256-/SIrNqv8h6QGKDuNoLGA4iret+kyesCkHGzVUUV0shc=" crossorigin="anonymous"></script>
<script>
var users = 0
function genhtml(n)
{
return "<select id=\"utente" + n + "\" class=\"form-control\" name=\"utente" + n + "\">{% for impiegato in impiegati %}<option value=\"{{impiegato.iid}}\">{{impiegato.nomeimpiegato}} - {{impiegato.username}}</option>{% endfor %}</select>"
}
function adduser()
{
$("#users-column").append(genhtml(users))
users += 1
$("#remove-user").removeClass("disabled")
}
function removeuser()
{
if(users > 0)
{
$("#utente" + (users-1)).remove()
users -= 1
if(users == 0)
{
$("#remove-user").addClass("disabled")
}
}
}
</script>
</head> </head>
<body> <body>
{% include 'nav.html.j2' %} {% include 'nav.html.j2' %}
@ -23,12 +52,9 @@
</div> </div>
<div class="form-group"> <div class="form-group">
<label class="col-xs-2" for="form-utente">Utenti</label> <label class="col-xs-2" for="form-utente">Utenti</label>
<div class="col-xs-10"> <div class="col-xs-10" id="users-column">
<select id="form-utente" multiple class="form-control" name="utente"> <div id="add-user" class="btn btn-success" onclick="adduser()">+</div>
{% for impiegato in impiegati %} <div id="remove-user" class="btn btn-danger disabled" onclick="removeuser()">-</div>
<option value="{{impiegato.iid}}">{{impiegato.nomeimpiegato}} - {{impiegato.username}}</option>
{% endfor %}
</select>
</div> </div>
</div> </div>
<div class="form-group"> <div class="form-group">

View file

@ -21,22 +21,20 @@
<th>Modello</th> <th>Modello</th>
<th>Fornitore</th> <th>Fornitore</th>
<th>Ispeziona</th> <th>Ispeziona</th>
<th>Modifica</th>
<th>Elimina</th> <th>Elimina</th>
</tr> </tr>
</thead> </thead>
{% for dispositivo in dispositivi %} {% for d in accessi %}
<tr> <tr>
<td>{{ dispositivo.tipo }}</td> <td>{{ d[0].dispositivo.tipo }}</td>
<td> ITS A FEATURE </td> <td>{% for u in d %}<p>{{ u.impiegato.nomeimpiegato }}</p>{% endfor %}</td>
<td>{{ dispositivo.inv_ced }}</td> <td>{{ d[0].dispositivo.inv_ced }}</td>
<td>{{ dispositivo.inv_ente }}</td> <td>{{ d[0].dispositivo.inv_ente }}</td>
<td>{{ dispositivo.marca }}</td> <td>{{ d[0].dispositivo.marca }}</td>
<td>{{ dispositivo.modello }}</td> <td>{{ d[0].dispositivo.modello }}</td>
<td>{{ dispositivo.fornitore }}</td> <td>{{ d[0].dispositivo.fornitore }}</td>
<td><a href="/details_host/{{ dispositivo.did }}"><span class="glyphicon glyphicon-list-alt"></span></a></td> <td><a href="/disp_details/{{ d.did }}"><span class="glyphicon glyphicon-list-alt"></span></a></td>
<td><a href="/disp_show/{{ dispositivo.did }}"><span class="glyphicon glyphicon-pencil"></span></a></td> <td><a href="/disp_del/{{ d.did }}"><span class="glyphicon glyphicon-remove"></span></a></td>
<td><a href="/disp_del/{{ dispositivo.did }}"><span class="glyphicon glyphicon-remove"></span></a></td>
</tr> </tr>
{% endfor %} {% endfor %}
</table> </table>

View file

@ -1,73 +0,0 @@
<html>
<head>
<title>Modifica servizio - Inventario</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
<link rel="stylesheet" href="{{css}}">
</head>
<body>
{% include 'nav.html.j2' %}
<div class="container">
<h1>
Modifica servizio
</h1>
<form class="form-horizontal" action="/disp_show/{{dispositivo.did}}" method="post">
<div class="form-group">
<label class="col-xs-2" for="">Tipo dispositivo</label>
<div class="col-xs-10">
<select id="form-tipo" class="form-control" name="tipo">
{% for tipo in tipi %}
<option value="{{tipo}}"{% if tipo == dispositivo.tipo %}selected="selected"{% endif %}>{{tipo}}</option>
{% endfor %}
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-utente">Utenti</label>
<div class="col-xs-10">
<select id="form-utente" multiple class="form-control" name="utente">
{# {% for impiegato in impiegati %}
<option value="{{impiegato.iid}}"{% if i == dispositivo.tipo %}selected="selected"{% endif %}>{{impiegato.nomeimpiegato}} - {{impiegato.username}}</option>
{% endfor %} #}
</select>
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-marca">Marca</label>
<div class="col-xs-10">
<input id="form-marca" class="form-control" type="text" placeholder="Marca" name="marca" value="{{dispositivo.marca}}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-modello">Modello</label>
<div class="col-xs-10">
<input id="form-modello" class="form-control" type="text" placeholder="Modello" name="modello" value="{{dispositivo.modello}}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-ced">Inventario CED</label>
<div class="col-xs-10">
<input id="form-ced" class="form-control" type="text" placeholder="Inventario CED" name="inv_ced" value="{{dispositivo.inv_ced}}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-ente">Inventario ente</label>
<div class="col-xs-10">
<input id="form-ente" class="form-control" type="text" placeholder="Inventario ente" name="inv_ente" value="{{dispositivo.inv_ente}}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-fornitore">Fornitore</label>
<div class="col-xs-10">
<input id="form-fornitore" class="form-control" type="text" placeholder="Fornitore" name="fornitore" value="{{dispositivo.fornitore}}">
</div>
</div>
<div class="form-group">
<label class="col-xs-2" for="form-control"></label>
<div class="col-xs-10">
<input class="form-control btn btn-primary" type="submit">
</div>
</div>
</form>
</div>
</body>
</html>

View file

@ -12,6 +12,7 @@
<li class="{% if type is equalto "ente" %}active{% endif %}"><a href="/ente_list">Enti</a></li> <li class="{% if type is equalto "ente" %}active{% endif %}"><a href="/ente_list">Enti</a></li>
<li class="{% if type is equalto "serv" %}active{% endif %}"><a href="/serv_list">Servizi</a></li> <li class="{% if type is equalto "serv" %}active{% endif %}"><a href="/serv_list">Servizi</a></li>
<li class="{% if type is equalto "imp" %}active{% endif %}"><a href="/imp_list">Impiegati</a></li> <li class="{% if type is equalto "imp" %}active{% endif %}"><a href="/imp_list">Impiegati</a></li>
<li class="{% if type is equalto "disp" %}active{% endif %}"><a href="/disp_list">Dispositivi</a></li>
</ul> </ul>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<p class="navbar-text"> <p class="navbar-text">