Skip to content

Commit

Permalink
Merge pull request #172 from flask-dashboard/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
FlyingBird95 committed Jun 17, 2018
2 parents 74eb58e + 88b2ba1 commit 94e7462
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 8 deletions.
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/constants.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"version": "2.0.1",
"version": "2.0.2",
"author": "Patrick Vogel, Thijs Klooster & Bogdan Petre",
"email": "patrickvogel@live.nl"
}
6 changes: 4 additions & 2 deletions flask_monitoringdashboard/database/versions.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,16 @@ def get_versions(db_session, endpoint_id=None, limit=None):
return list(reversed([r[0] for r in query.all()]))


def get_first_requests(db_session, limit=None):
def get_first_requests(db_session, endpoint_id, limit=None):
"""
Returns a list with all versions and when they're first used
:param db_session: session for the database
:param limit: only return the most recent versions
:param endpoint_id: id of the endpoint
:return list of tuples with versions
"""
query = db_session.query(Request.version_requested, func.min(Request.time_requested).label('first_used')). \
query = db_session.query(Request.version_requested, func.min(Request.time_requested).label('first_used')).\
filter(Request.endpoint_id == endpoint_id).\
group_by(Request.version_requested).order_by(desc('first_used'))
if limit:
query = query.limit(limit)
Expand Down
16 changes: 16 additions & 0 deletions flask_monitoringdashboard/templates/fmd_dashboard/overview.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
{% block content %}

{% block subcontent %}
<div id="alert"></div>
<div class="card mb-3">
<div class="card-header"><h4>{{ title }}</h4></div>
<div class="card-body">
Expand Down Expand Up @@ -71,5 +72,20 @@
{% block script %}
<script type="text/javascript">
$('#dataTable').DataTable().order([[4, "desc"]]).draw();

$.get( "https://pypi.org/pypi/Flask-MonitoringDashboard/json", function( data ) {

var pypi_version = data['info']['version'];

if (pypi_version !== "{{ version }}"){
var alert = $('#alert');
alert.addClass("alert alert-warning alert-dismissible");
alert.html(
"<a href=\"#\" class=\"close\" data-dismiss=\"alert\" aria-label=\"close\">&times;</a>" +
"<strong>Warning:</strong> Version " + pypi_version + " is now available, while you " +
"are still using version {{ version }}.");
}
});

</script>
{% endblock %}
5 changes: 3 additions & 2 deletions flask_monitoringdashboard/views/dashboard/overview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
from flask_monitoringdashboard.core.auth import secure, is_admin
from flask_monitoringdashboard.core.colors import get_color
from flask_monitoringdashboard.core.timezone import to_local_datetime, to_utc_datetime
from flask_monitoringdashboard.core.utils import get_details
from flask_monitoringdashboard.database import Request, session_scope
from flask_monitoringdashboard.database.count_group import count_requests_group, get_value
from flask_monitoringdashboard.database.data_grouped import get_endpoint_data_grouped
Expand Down Expand Up @@ -46,6 +47,6 @@ def overview():
'median-overall': get_value(median, endpoint.id),
'last-accessed': get_value(access_times, endpoint.name, default=None)
})

version = get_details(db_session)['dashboard-version']
return render_template('fmd_dashboard/overview.html', result=result, is_admin=is_admin(),
title='Dashboard Overview')
title='Dashboard Overview', version=version)
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/views/details/time_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def format_version(version, first_used):

def versions_graph(db_session, endpoint_id, form):
times = get_version_data_grouped(db_session, lambda x: simplify(x, 10), Request.endpoint_id == endpoint_id)
first_requests = get_first_requests(db_session, form.get_slider_value())
first_requests = get_first_requests(db_session, endpoint_id, form.get_slider_value())
data = [boxplot(
name=format_version(request.version_requested, get_value(first_requests, request.version_requested)),
values=get_value(times, request.version_requested),
Expand Down
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/views/details/version_ip.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def version_ip_graph(db_session, endpoint_id, form):
users = get_ips(db_session, endpoint_id, form.get_slider_value(0))
versions = get_versions(db_session, endpoint_id, form.get_slider_value(1))

first_request = get_first_requests(db_session)
first_request = get_first_requests(db_session, endpoint_id)
values = get_two_columns_grouped(db_session, Request.ip, Request.endpoint_id == endpoint_id)
data = [[get_value(values, (user, v)) for v in versions] for user in users]

Expand Down
2 changes: 1 addition & 1 deletion flask_monitoringdashboard/views/details/version_user.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ def version_user_graph(db_session, endpoint_id, form):
users = get_users(db_session, endpoint_id, form.get_slider_value(0))
versions = get_versions(db_session, endpoint_id, form.get_slider_value(1))

first_request = get_first_requests(db_session)
first_request = get_first_requests(db_session, endpoint_id)
values = get_two_columns_grouped(db_session, Request.group_by, Request.endpoint_id == endpoint_id)
data = [[get_value(values, (user, v)) for v in versions] for user in users]

Expand Down

0 comments on commit 94e7462

Please sign in to comment.