refactor dashboard

This commit is contained in:
deflax 2017-12-17 18:57:28 +02:00
parent b170b07ef5
commit 0550142d2c
4 changed files with 79 additions and 59 deletions

View file

@ -57,20 +57,24 @@ def market(group_id=0):
@main.route("/dashboard", methods=['GET', 'POST']) @main.route("/dashboard", methods=['GET', 'POST'])
@login_required @login_required
def dashboard(): def dashboard():
sys_regions = Region.query.all()
cuser = current_user cuser = current_user
inv_bridges = cuser.inv_bridges.order_by(Bridge.bridge_id.asc()).all()
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
inv_routers = cuser.inv_routers.order_by(Router.date_created.asc()).all()
inv_deployments = cuser.inv_deployments.filter_by(deleted=False).order_by(Deployment.date_created.desc()).all() inv_deployments = cuser.inv_deployments.filter_by(deleted=False).order_by(Deployment.date_created.desc()).all()
regions = {}
for region in sys_regions:
regions[region.pid] = region.description
inv_deploycubeids = [] inv_deploycubeids = []
for invcls in inv_deployments: for invcls in inv_deployments:
if invcls.user_id == cuser.pid: if invcls.user_id == cuser.pid:
inv_deploycubeids.extend([invcls.machine_id]) inv_deploycubeids.extend([invcls.machine_id])
inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all() inv_services = cuser.inv_services.filter_by(deleted=False).order_by(Service.date_last_charge.asc()).all()
inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all() inv_domains = cuser.inv_domains.filter_by(deleted=False).order_by(Domain.date_created.desc()).all()
inv_addresses = cuser.inv_addresses.order_by(Address.ip.asc()).all()
inv_bridges = cuser.inv_bridges.order_by(Bridge.bridge_id.asc()).all()
sys_regions = Region.query.all()
regions = {}
for region in sys_regions:
regions[region.pid] = region.description
#extract rrd and status from the deployments #extract rrd and status from the deployments
rrd = {} rrd = {}
@ -102,5 +106,6 @@ def dashboard():
flash('Support is notified.'.format(str(unit_id))) flash('Support is notified.'.format(str(unit_id)))
send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id), send_email(current_app.config['MAIL_USERNAME'], 'Cube {} is unreachable'.format(unit_id),
'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id, error=str(e)) 'vmanager/email/adm_unreachable', user=current_user, unit_id=unit_id, error=str(e))
return render_template('main/dashboard.html', rrd=rrd, status=statuses, inv_bridges=inv_bridges, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, region=regions)
return render_template('main/dashboard.html', sys_regions=sys_regions, inv_bridges=inv_bridges, inv_deployments=inv_deployments, inv_services=inv_services, inv_domains=inv_domains, inv_addresses=inv_addresses, rrd=rrd, status=statuses)

View file

@ -1,3 +1,5 @@
# FAT MODEL
from werkzeug.security import generate_password_hash, check_password_hash from werkzeug.security import generate_password_hash, check_password_hash
from itsdangerous import TimedJSONWebSignatureSerializer as Serializer from itsdangerous import TimedJSONWebSignatureSerializer as Serializer
@ -226,30 +228,47 @@ def contact_proxmaster(data, method):
except: except:
return { 'status': 'UNREACHABLE' } return { 'status': 'UNREACHABLE' }
class Router(db.Model): #VDC
__tablename__ = 'routers' class Region(db.Model):
__tablename__ = 'regions'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK inv_addresses = db.relationship('Address', backref='region', lazy='dynamic')
date_created = db.Column(db.DateTime, default=datetime.utcnow) inv_bridges = db.relationship('Bridge', backref='region', lazy='dynamic')
deleted = db.Column(db.Boolean, default=False)
inv_addresses = db.relationship('Address', backref='router', lazy='dynamic') enabled = db.Column(db.Boolean)
name = db.Column(db.String)
machine_id = db.Column(db.BigInteger) #unit_id description = db.Column(db.String)
extraprice = db.Column(db.Float)
class Bridge(db.Model): class Bridge(db.Model):
__tablename__ = 'bridges' __tablename__ = 'bridges'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
region_id = db.Column(db.Integer, db.ForeignKey('regions.pid')) #FK
inv_routers = db.relationship('Router', backref='bridge', lazy='dynamic')
inv_deployments = db.relationship('Deployment', backref='bridge', lazy='dynamic')
date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False)
bridge_id = db.Column(db.String)
class Router(db.Model):
__tablename__ = 'routers'
pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
bridge_id = db.Column(db.Integer, db.ForeignKey('bridges.pid')) #FK
inv_addresses = db.relationship('Address', backref='router', lazy='dynamic')
date_created = db.Column(db.DateTime, default=datetime.utcnow) date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False) deleted = db.Column(db.Boolean, default=False)
bridge_id = db.Column(db.String) machine_id = db.Column(db.BigInteger) #unit_id
class Deployment(db.Model): class Deployment(db.Model):
__tablename__ = 'deployments' __tablename__ = 'deployments'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
bridge_id = db.Column(db.Integer, db.ForeignKey('bridges.pid')) #FK
date_created = db.Column(db.DateTime, default=datetime.utcnow) date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False) deleted = db.Column(db.Boolean, default=False)
@ -267,34 +286,6 @@ class Deployment(db.Model):
machine_hdd = db.Column(db.Integer) machine_hdd = db.Column(db.Integer)
discount = db.Column(db.Integer) discount = db.Column(db.Integer)
class Service(db.Model):
__tablename__ = 'services'
pid = db.Column(db.Integer, primary_key=True) #PK
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=False)
warning = db.Column(db.Boolean, default=False)
date_last_charge = db.Column(db.DateTime)
period = db.Column(db.Integer)
daysleft = db.Column(db.Integer)
category = db.Column(db.String)
description = db.Column(db.Unicode)
price = db.Column(db.Float)
class Region(db.Model):
__tablename__ = 'regions'
pid = db.Column(db.Integer, primary_key=True)
enabled = db.Column(db.Boolean)
inv_addresses = db.relationship('Address', backref='region', lazy='dynamic')
name = db.Column(db.String)
description = db.Column(db.String)
extraprice = db.Column(db.Float)
class Address(db.Model): class Address(db.Model):
__tablename__ = 'address' __tablename__ = 'address'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)
@ -330,6 +321,24 @@ class Address(db.Model):
else: else:
return mac return mac
#MISC ITEMS
class Service(db.Model):
__tablename__ = 'services'
pid = db.Column(db.Integer, primary_key=True) #PK
user_id = db.Column(db.Integer, db.ForeignKey('users.pid')) #FK
date_created = db.Column(db.DateTime, default=datetime.utcnow)
deleted = db.Column(db.Boolean, default=False)
enabled = db.Column(db.Boolean, default=False)
warning = db.Column(db.Boolean, default=False)
date_last_charge = db.Column(db.DateTime)
period = db.Column(db.Integer)
daysleft = db.Column(db.Integer)
category = db.Column(db.String)
description = db.Column(db.Unicode)
price = db.Column(db.Float)
class Domain(db.Model): class Domain(db.Model):
__tablename__ = 'domains' __tablename__ = 'domains'
pid = db.Column(db.Integer, primary_key=True) pid = db.Column(db.Integer, primary_key=True)

View file

@ -138,21 +138,7 @@ addEventListener("DOMContentLoaded", function() {
{% endif %} {% endif %}
<div class="row"> <div class="row">
{% include "main/vdc_pool.html" %}
<div class="col-md-12">
<div class="panel panel-info" id="deployments">
<div class="panel-heading">Device Manager</div>
<div class="panel-body"><p>
{% if inv_deployments != [] %}
{% include "main/dashboard_pool.html" %}
<!-- Cloud Storage icon by Icons8 -->
{% else %}
<button class="btn btn-default btn-lg btn-block" onclick="window.open('{{ url_for('vmanager.createvm') }}','_self')"><img class="icon icons8-Cloud-Storage" width="48" height="48" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoC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N9xzacnv+R7noDFTwuaKOXSizSPKVcwasqEnhDqbu+iPI73dg4aekCwuHMtjZikPvd2TLTc4X10HVhiJI19cDe7oLeZ55suukFDRfO/tZxXTTOhMdxZK/iWnFNtf0bTKRLy7DjxmcX99meLFvYat5RodW61uYZo2PsH9fX5pxexV7gTTqGn1DGzswODwbGbPYWsZiWSgtTGhZxVjpoTxRfm3mL2In8tBY6ZS60C1icRFJrevojaReAF8bkAykkcqAxDz+W0dFxOlXVsCU///5aYy2NZxMVHadbCv4H7IC+CuA/djyg7C/AeJ36h1J+7ehgAAAABJRU5ErkJggg=="> Create</button>
{% endif %}
</div>
</div>
</div>
{% if inv_domains != [] %} {% if inv_domains != [] %}
<div class="col-md-12"> <div class="col-md-12">

View file

@ -1,3 +1,8 @@
<div class="col-md-12">
<div class="panel panel-info" id="deployments">
<div class="panel-heading">Device Manager</div>
<div class="panel-body"><p>
{% if inv_deployments != [] %}
<div class="panel-group" id="deploycubes" role="tablist" aria-multiselectable="true"> <div class="panel-group" id="deploycubes" role="tablist" aria-multiselectable="true">
{% for deploy in inv_deployments %} {% for deploy in inv_deployments %}
{% if deploy.enabled == False %} {% if deploy.enabled == False %}
@ -99,3 +104,18 @@
{% endfor %} {% endfor %}
</div> </div>
<!--Cloud Storage icon by Icons8 -->
{% else %}
<button class="btn btn-default btn-lg btn-block" onclick="window.open('{{ url_for('vmanager.createvm') }}','_self')"><img class="icon icons8-Cloud-Storage" width="48" height="48" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAEEklEQVRYhe3Xy0/bBhwHcA6btEMP0077A3boYYdK23EHLiQ0hQBtVC1S9zjs0L069TCkSUWNpgZCshDYItZOI+tKH7Cibgw6Wu2RAXWMYyc8mpAoUAIEp6VuTR5OwAnJd5dBEbYJKDSA1J/0PfjgXz6y5W/ssrKDNm9dYl4+aqYeq00kSpnK5pGUusX1WkGgxux+/ePLvmQ4lkcp88nPfkHV6DpcEFhpGnnH2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Dz+W0dFxOlXVsCU///5aYy2NZxMVHadbCv4H7IC+CuA/djyg7C/AeJ36h1J+7ehgAAAABJRU5ErkJggg=="> Create</button>
{% endif %}
</div>
</div>
</div>
{% else %}
<button class="btn btn-default btn-lg btn-block" onclick="window.open('{{ url_for('vmanager.createvm') }}','_self')"><img class="icon icons8-Cloud-Storage" width="48" height="48" src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAACgAAAAoCAYAAACM/rhtAAAEEklEQVRYhe3Xy0/bBhwHcA6btEMP0077A3boYYdK23EHLiQ0hQBtVC1S9zjs0L069TCkSUWNpgZCshDYItZOI+tKH7Cibgw6Wu2RAXWMYyc8mpAoUAIEp6VuTR5OwAnJd5dBEbYJKDSA1J/0PfjgXz6y5W/ssrKDNm9dYl4+aqYeq00kSpnK5pGUusX1WkGgxux+/ePLvmQ4lkcp88nPfkHV6DpcEFhpGnnH2D8XKzXwQv98UtXoqioIVDeRH/1IcKlSAzsIbqXSTJ0tCKy2uNt/uy+slhrYez8JrY25XhCotdKDgzNiSXHhWB5DYRFaK+0tfAWt9Pzow9WSA8cereKYheILAo/bGDHE72z5n8E46rsC0LXR0LXRqO8K4O5kbEc7pvg8TrQxuXKD8xVFnLrJ9canVyYTO1k84FvCe+1eXCcWwPLLYPlldJMsPrg4ipsMtyPkmasBQWUk3twKWGm8PRff7kImsoxT7V5MLwrYPPNP0tDbPfh3KrltoGkgIqgaXbVbAT9zuLi00oIHfA6O4ShOOyZQZaFQZ3Pjbx8nwa3NcPAp1CYSersH529NwcuubAn8iXya0VjcXykCtVa6o9cn5JVwZzr9OHcziNBDAWI2hzCXwmourwgEAF7IgEuI6CJZ6FppMJFlRWCfX0BNq6dLEVjdQlODYfmK6RiK4twvwS0xheYasYCGnpAi8N6sCK2V8SsCq76hFsce5WRPPu2YQIBNFgXkEiL0do8icGIxB42Fisviyg3Ol463MtkpmYoZj4qoslAQs7migACgNpFo7Hsge6unl/I4+Z0nW25wHpIAVY2uw593BiQVMx4V8eGlMVwZjhSNA4B4OgtL/zROfsvIIs/eCAoVRuKIHLC26Y+IBGjqn0GHc25XcBvnh39mcaF3WgK03F1IqZoJnQR41EzVO1xPVjaf8P73o2D55V0HTi8K0LXREmAnxWe1VtogrZgW+sbvPkFygt7uAZcQdx2o9MDcnkyh1sb8KgNkvEMyFXP+1hS6SXbXgd0kK1s5rrkMalqYSQlQY6HichXjZVdwqt2LHioKXsgUDeMSIrpJFnU2N9xzacnv+R7noDFTwuaKOXSizSPKVcwasqEnhDqbu+iPI73dg4aekCwuHMtjZikPvd2TLTc4X10HVhiJI19cDe7oLeZ55suukFDRfO/tZxXTTOhMdxZK/iWnFNtf0bTKRLy7DjxmcX99meLFvYat5RodW61uYZo2PsH9fX5pxexV7gTTqGn1DGzswODwbGbPYWsZiWSgtTGhZxVjpoTxRfm3mL2In8tBY6ZS60C1icRFJrevojaReAF8bkAykkcqAxDz+W0dFxOlXVsCU///5aYy2NZxMVHadbCv4H7IC+CuA/djyg7C/AeJ36h1J+7ehgAAAABJRU5ErkJggg=="> Create</button>
{% endif %}
</div>
</div>
</div>