Updated dashboared

This commit is contained in:
Adolfo Gómez 2014-01-28 06:07:58 +00:00
parent 0d3a724ab8
commit 8a9f32dd03
11 changed files with 237 additions and 42 deletions

View File

@ -20,6 +20,7 @@ encoding//src/uds/REST/methods/osmanagers.py=utf-8
encoding//src/uds/REST/methods/providers.py=utf-8
encoding//src/uds/REST/methods/services.py=utf-8
encoding//src/uds/REST/methods/services_pool.py=utf-8
encoding//src/uds/REST/methods/system.py=utf-8
encoding//src/uds/REST/methods/transports.py=utf-8
encoding//src/uds/REST/methods/user_services.py=utf-8
encoding//src/uds/REST/methods/users_groups.py=utf-8

View File

@ -41,6 +41,7 @@ function minify_admin() {
'gui-element',
// Gui definition
'gui-definition',
'gui-d-dashboard',
'gui-d-services',
'gui-d-authenticators',
'gui-d-osmanagers',

View File

@ -0,0 +1,65 @@
# -*- coding: utf-8 -*-
#
# Copyright (c) 2014 Virtual Cable S.L.
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# * Redistributions of source code must retain the above copyright notice,
# this list of conditions and the following disclaimer.
# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.
# * Neither the name of Virtual Cable S.L. nor the names of its contributors
# may be used to endorse or promote products derived from this software
# without specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
'''
@author: Adolfo Gómez, dkmaster at dkmon dot com
'''
from __future__ import unicode_literals
from uds.models import User, Service, UserService, DeployedService
from uds.REST import Handler, RequestError
import logging
logger = logging.getLogger(__name__)
# Enclosed methods under /auth path
class System(Handler):
needs_admin = True # By default, staff is lower level needed
def get(self):
logger.debug('args: {0}'.format(self._args))
if len(self._args) == 1 and self._args[0] == 'overview': # System overview
users = User.objects.count()
services = Service.objects.count()
user_services = UserService.objects.count()
restrained_services_pools = len(DeployedService.getRestraineds())
return {
'users': users,
'services': services,
'user_services': user_services,
'restrained_services_pools': restrained_services_pools,
}
raise RequestError('invalid request')
def put(self):
raise RequestError('todo')

View File

@ -929,6 +929,23 @@ class DeployedService(models.Model):
'''
return [username, password]
@staticmethod
def getRestraineds():
from uds.core.util.Config import GlobalConfig
from django.db.models import Count
if GlobalConfig.RESTRAINT_TIME.getInt() <= 0:
return [] # Do not perform any restraint check if we set the globalconfig to 0 (or less)
date = getSqlDatetime() - timedelta(seconds=GlobalConfig.RESTRAINT_TIME.getInt())
min = GlobalConfig.RESTRAINT_COUNT.getInt()
res = []
for v in UserService.objects.filter(state=State.ERROR, state_date__gt=date).values('deployed_service').annotate(how_many=Count('deployed_service')):
if v['how_many'] >= min:
res.append(v['deployed_service'])
return DeployedService.objects.filter(pk__in=res)
def isRestrained(self):
'''
Maybe this deployed service is having problems, and that may block some task in some

View File

@ -501,3 +501,4 @@ api.networks = new BasicModelRest('networks');
api.servicesPool = new BasicModelRest('servicespool');
api.configuration = new BasicModelRest('config');
api.system = new BasicModelRest('system');

View File

@ -0,0 +1,30 @@
gui.dashboard = new BasicGuiElement('Dashboard');
gui.dashboard.link = function(event) {
"use strict";
gui.clearWorkspace();
api.templates.get('dashboard', function(tmpl) {
api.system.overview(function(data){
gui.doLog('enter dashboard');
gui.appendToWorkspace(api.templates.evaluate(tmpl, {
users: data.users,
services: data.services,
user_services: data.user_services,
restrained_services_pools: data.restrained_services_pools,
}));
gui.setLinksEvents();
$.each($('.btn3d'), function() {
console.log(this);
var counter = 0;
$(this).click(function(){
counter += 1;
$(this).text($(this).text().split(' ')[0] + ' ' + counter);
/*$('<span>Click ' + counter + ' on ' + $(this).text() + '<b>--</b></span>').appendTo('#out');*/
});
});
});
gui.tools.fix3dButtons('#test');
});
};

View File

@ -1,29 +1,6 @@
/* jshint strict: true */
// Basic GUI components
gui.dashboard = new BasicGuiElement('Dashboard');
gui.dashboard.link = function(event) {
"use strict";
gui.clearWorkspace();
api.templates.get('dashboard', function(tmpl) {
gui.doLog('enter dashboard');
gui.appendToWorkspace(api.templates.evaluate(tmpl, {
}));
gui.setLinksEvents();
$.each($('.btn3d'), function() {
console.log(this);
var counter = 0;
$(this).click(function(){
counter += 1;
$(this).text($(this).text().split(' ')[0] + ' ' + counter);
/*$('<span>Click ' + counter + ' on ' + $(this).text() + '<b>--</b></span>').appendTo('#out');*/
});
});
gui.tools.fix3dButtons('#test');
});
};
// Tools
gui.clear_cache = new BasicGuiElement('Clear cache');

View File

@ -243,9 +243,11 @@
var val = ((x < y) ? 1 : ((x > y) ? -1 : 0));
return val;
};
gui.setLinksEvents();
gui.dashboard.link();
// Wait a bit before activating links to give tome tine to initializations
setTimeout(function(){
gui.setLinksEvents();
gui.dashboard.link();
}, 500);
};
gui.showDashboard = function() {

View File

@ -103,6 +103,7 @@
<!-- user interface management -->
<script src="{% get_static_prefix %}adm/js/gui-definition.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-dashboard.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-services.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-authenticators.js"></script>
<script src="{% get_static_prefix %}adm/js/gui-d-osmanagers.js"></script>

View File

@ -15,11 +15,11 @@
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li><a class="lnk-dashboard" href="#"><i class="fa fa-dashboard"></i> Dashboard</a></li>
<li><a class="lnk-service_providers" href="#"><i class="fa fa-bar-chart-o"></i> {% trans 'Services' %}</a></li>
<li><a class="lnk-authenticators" href="#"><i class="fa fa-user"></i> {% trans 'Authenticators' %}</a></li>
<li><a class="lnk-osmanagers" href="#"><i class="fa fa-edit"></i> Os Managers</a></li>
<li><a class="lnk-connectivity" href="#"><i class="fa fa-font"></i> {% trans 'Connectivity' %}</a></li>
<li><a class="lnk-deployed_services" href=""><i class="fa fa-desktop"></i> {% trans 'Services pools' %}</a></li>
<li><a class="lnk-service_providers" href="#"><i class="fa fa-desktop"></i> {% trans 'Services' %}</a></li>
<li><a class="lnk-authenticators" href="#"><i class="fa fa-key"></i> {% trans 'Authenticators' %}</a></li>
<li><a class="lnk-osmanagers" href="#"><i class="fa fa-gears"></i> Os Managers</a></li>
<li><a class="lnk-connectivity" href="#"><i class="fa fa-sitemap"></i> {% trans 'Connectivity' %}</a></li>
<li><a class="lnk-deployed_services" href=""><i class="fa fa-puzzle-piece"></i> {% trans 'Services pools' %}</a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-caret-square-o-down"></i> Tools <b class="caret"></b></a>
<ul class="dropdown-menu">

View File

@ -1,4 +1,5 @@
{% load i18n html5 static %}
<div class="row">
<div class="col-xs-12">
<h1>Dashboard <small>{% trans 'overview' %}</small></h1>
@ -7,16 +8,115 @@
</ol>
</div>
</div><!-- /.row -->
<div id="test" class="row">
<div class="col-xs-12">
<button class="btn btn3d-info btn3d">Botón</button>
<button class="btn btn3d-info btn3d">Botón-2</button>
<button class="btn btn3d-info btn3d">Botón-3</button>
<button class="btn btn-info">Test button</button>
</div>
</div>
{% verbatim %}
<div class="row">
<div id="out" class="col-xs-12">
<div class="col-lg-3">
<div class="panel panel-info">
<div class="panel-heading">
<div class="row">
<div class="col-xs-6">
<i class="fa fa-key fa-5x"></i>
</div>
<div class="col-xs-6 text-right">
<p class="announcement-heading">{{ users }}</p>
<p class="announcement-text">{% endverbatim %}{% trans 'Users' %}{% verbatim %}</p>
</div>
</div>
</div>
<a class="lnk-authenticators" href="#">
<div class="panel-footer announcement-bottom">
<div class="row">
<div class="col-xs-6">
{% endverbatim %}{% trans 'View Authenticators' %}{% verbatim %}
</div>
<div class="col-xs-6 text-right">
<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</a>
</div>
</div>
</div>
<div class="col-lg-3">
<div class="panel panel-info">
<div class="panel-heading">
<div class="row">
<div class="col-xs-6">
<i class="fa fa-desktop fa-5x"></i>
</div>
<div class="col-xs-6 text-right">
<p class="announcement-heading">{{ services }}</p>
<p class="announcement-text">{% endverbatim %}{% trans 'Services' %}{% verbatim %}</p>
</div>
</div>
</div>
<a class="lnk-service_providers" href="#">
<div class="panel-footer announcement-bottom">
<div class="row">
<div class="col-xs-6">
{% endverbatim %}{% trans 'View services' %}{% verbatim %}
</div>
<div class="col-xs-6 text-right">
<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</a>
</div>
</div>
<div class="col-lg-3">
<div class="panel panel-success">
<div class="panel-heading">
<div class="row">
<div class="col-xs-6">
<i class="fa fa-comments fa-5x"></i>
</div>
<div class="col-xs-6 text-right">
<p class="announcement-heading">{{ user_services }}</p>
<p class="announcement-text">{% endverbatim %}{% trans 'User services' %}{% verbatim %}</p>
</div>
</div>
</div>
<a class="lnk-deployed_services" href="#">
<div class="panel-footer announcement-bottom">
<div class="row">
<div class="col-xs-6">
{% endverbatim %}{% trans 'View services pools' %}{% verbatim %}
</div>
<div class="col-xs-6 text-right">
<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</a>
</div>
</div>
<div class="col-lg-3">
<div class="panel panel-{{# if restrained_services_pools }}danger{{ else }}success{{/ if }}">
<div class="panel-heading">
<div class="row">
<div class="col-xs-6">
<i class="fa fa-heart fa-5x"></i>
</div>
<div class="col-xs-6 text-right">
<p class="announcement-heading">{{ restrained_services_pools }}</p>
<p class="announcement-text">{% endverbatim %}{% trans 'Restrained services pools' %}{% verbatim %}</p>
</div>
</div>
</div>
<a class="lnk-deployed_services" href="#">
<div class="panel-footer announcement-bottom">
<div class="row">
<div class="col-xs-6">
{% endverbatim %}{% trans 'View services pools' %}{% verbatim %}
</div>
<div class="col-xs-6 text-right">
<i class="fa fa-arrow-circle-right"></i>
</div>
</div>
</div>
</a>
</div>
</div>
</div><!-- /.row -->
{% endverbatim %}