forked from shaba/openuds
Added some more info to providers && services
This commit is contained in:
parent
2b7ad74f2f
commit
77127664af
@ -36,35 +36,50 @@ from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from uds.models import DeployedService, Service
|
||||
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util import log
|
||||
from uds.core.Environment import Environment
|
||||
from uds.REST.model import ModelHandler
|
||||
from uds.REST import NotFound, ResponseError, RequestError
|
||||
from django.db import IntegrityError
|
||||
|
||||
from services import Services
|
||||
from osmanagers import OsManagers
|
||||
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
class DeployedServices(ModelHandler):
|
||||
model = DeployedService
|
||||
save_fields = ['name', 'comments', 'service', 'osmanager', 'initial_srvs', 'cache_l1_srvs', 'cache_l2_srvs', 'max_srvs']
|
||||
|
||||
table_title = _('Deployed services')
|
||||
table_fields = [
|
||||
{ 'name': {'title': _('Name'), 'visible': True, 'type': 'iconType' } },
|
||||
{ 'name': {'title': _('Name'), 'visible': True, 'type': 'icon', 'icon': 'fa fa-laptop text-info' } },
|
||||
{ 'state': { 'title': _('state'), 'type': 'dict', 'dict': State.dictionary() } },
|
||||
{ 'comments': {'title': _('Comments')}},
|
||||
]
|
||||
table_row_style = { 'field': 'state', 'prefix': 'row-state-' }
|
||||
|
||||
def item_as_dict(self, item):
|
||||
type_ = item.getType()
|
||||
return { 'id': item.id,
|
||||
val = { 'id': item.id,
|
||||
'name': item.name,
|
||||
'comments': item.comments,
|
||||
'state' : item.state,
|
||||
'service': Services.serviceToDict(item.service),
|
||||
'initial_srvs' : item.initial_srvs,
|
||||
'cache_l1_srvs' : item.cache_l1_srvs,
|
||||
'cache_l2_srvs' : item.cache_l2_srvs,
|
||||
'max_srvs' : item.max_srvs,
|
||||
'user_services_count': item.userServices.count(),
|
||||
}
|
||||
|
||||
if item.osmanager is not None:
|
||||
val['osmanager'] = OsManagers.osmToDict(item.osmanager)
|
||||
|
||||
return val
|
||||
|
||||
# Gui related
|
||||
def getGui(self, type_):
|
||||
try:
|
||||
|
@ -57,7 +57,8 @@ class OsManagers(ModelHandler):
|
||||
{ 'deployed_count': {'title': _('Used by'), 'type': 'numeric', 'width': '8em'}}
|
||||
]
|
||||
|
||||
def item_as_dict(self, osm):
|
||||
@staticmethod
|
||||
def osmToDict(osm):
|
||||
type_ = osm.getType()
|
||||
return { 'id': osm.id,
|
||||
'name': osm.name,
|
||||
@ -65,6 +66,9 @@ class OsManagers(ModelHandler):
|
||||
'type': type_.type(),
|
||||
'comments': osm.comments,
|
||||
}
|
||||
|
||||
def item_as_dict(self, item):
|
||||
return OsManagers.osmToDict(item)
|
||||
|
||||
def checkDelete(self, item):
|
||||
if item.deployedServices.count() > 0:
|
||||
|
@ -33,7 +33,7 @@
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||
from uds.models import Provider
|
||||
from uds.models import Provider, UserService
|
||||
from services import Services as DetailServices
|
||||
from uds.core import services
|
||||
|
||||
@ -57,6 +57,7 @@ class Providers(ModelHandler):
|
||||
{ 'name': {'title': _('Name'), 'type': 'iconType' } },
|
||||
{ 'comments': {'title': _('Comments')}},
|
||||
{ 'services_count': {'title': _('Services'), 'type': 'numeric', 'width': '5em'}},
|
||||
{ 'user_services_count': {'title': _('User Services'), 'type': 'numeric', 'width': '8em'}},
|
||||
]
|
||||
|
||||
def item_as_dict(self, provider):
|
||||
@ -72,6 +73,7 @@ class Providers(ModelHandler):
|
||||
return { 'id': provider.id,
|
||||
'name': provider.name,
|
||||
'services_count': provider.services.count(),
|
||||
'user_services_count': UserService.objects.filter(deployed_service__service__provider=provider).count(),
|
||||
'offers': offers,
|
||||
'type': type_.type(),
|
||||
'comments': provider.comments,
|
||||
|
@ -35,7 +35,7 @@ from __future__ import unicode_literals
|
||||
from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from uds.models import Service
|
||||
from uds.models import Service, UserService
|
||||
|
||||
from uds.core.util import log
|
||||
from uds.core.Environment import Environment
|
||||
@ -50,32 +50,30 @@ logger = logging.getLogger(__name__)
|
||||
|
||||
class Services(DetailHandler):
|
||||
|
||||
@staticmethod
|
||||
def serviceToDict(item):
|
||||
return {
|
||||
'id':item.id,
|
||||
'name': item.name,
|
||||
'comments': item.comments,
|
||||
'type': item.data_type,
|
||||
'typeName' : _(item.getType().name()),
|
||||
'deployed_services_count' : item.deployedServices.count(),
|
||||
'user_services_count': UserService.objects.filter(deployed_service__service=item).count(),
|
||||
}
|
||||
|
||||
def getItems(self, parent, item):
|
||||
# Extract provider
|
||||
try:
|
||||
if item is None:
|
||||
return [{
|
||||
'id':k.id,
|
||||
'name': k.name,
|
||||
'comments': k.comments,
|
||||
'type': k.data_type,
|
||||
'typeName' : _(k.getType().name()),
|
||||
'deployed_services_count' : k.deployedServices.count(),
|
||||
} for k in parent.services.all() ]
|
||||
return [Services.serviceToDict(k) for k in parent.services.all() ]
|
||||
else:
|
||||
k = parent.services.get(pk=item)
|
||||
val = {
|
||||
'id':k.id,
|
||||
'name': k.name,
|
||||
'comments': k.comments,
|
||||
'type': k.data_type,
|
||||
'typeName' : _(k.getType().name()),
|
||||
'deployed_services_count' : k.deployedServices.count(),
|
||||
}
|
||||
val = Services.serviceToDict(k)
|
||||
return self.fillIntanceFields(k, val)
|
||||
except:
|
||||
logger.exception('getItems')
|
||||
return { 'error': 'not found' }
|
||||
self.invalidItemException()
|
||||
|
||||
def saveItem(self, parent, item):
|
||||
# Extract item db fields
|
||||
@ -126,6 +124,7 @@ class Services(DetailHandler):
|
||||
{ 'comments': { 'title': _('Comments') } },
|
||||
{ 'type': {'title': _('Type') } },
|
||||
{ 'deployed_services_count': {'title': _('Deployed services'), 'type': 'numeric', 'width': '7em'}},
|
||||
{ 'user_services_count': {'title': _('User services'), 'type': 'numeric', 'width': '7em'}},
|
||||
]
|
||||
|
||||
def getTypes(self, parent, forType):
|
||||
|
@ -84,6 +84,9 @@ class Users(DetailHandler):
|
||||
{ 'last_access': { 'title': _('Last access'), 'type': 'datetime' } },
|
||||
]
|
||||
|
||||
def getRowStyle(self, parent):
|
||||
return { 'field': 'state', 'prefix': 'row-state-' }
|
||||
|
||||
def getLogs(self, parent, item):
|
||||
try:
|
||||
user = parent.users.get(pk=item)
|
||||
|
@ -127,18 +127,8 @@ class BaseModelHandler(Handler):
|
||||
})
|
||||
return res
|
||||
|
||||
def processTableFields(self, title, fields):
|
||||
# processedFields = [{ 'id' : {'visible': False, 'sortable': False, 'searchable': False } }]
|
||||
# for f in fields:
|
||||
# for k1, v1 in f.iteritems():
|
||||
# dct = {}
|
||||
# for k2, v2 in v1.iteritems():
|
||||
# if type(v2) in (bool, int, long, float, unicode, list, tuple, dict):
|
||||
# dct[k2] = v2
|
||||
# else:
|
||||
# dct[k2] = unicode(v2)
|
||||
# processedFields.append({k1: dct})
|
||||
return { 'title': unicode(title), 'fields': fields };
|
||||
def processTableFields(self, title, fields, row_style):
|
||||
return { 'title': unicode(title), 'fields': fields, 'row-style': row_style };
|
||||
|
||||
def readFieldsFromParams(self, fldList):
|
||||
args = {}
|
||||
@ -214,7 +204,7 @@ class DetailHandler(BaseModelHandler):
|
||||
elif self._args[0] == TYPES:
|
||||
return self.getTypes(parent, None)
|
||||
elif self._args[0] == TABLEINFO:
|
||||
return self.processTableFields(self.getTitle(parent), self.getFields(parent))
|
||||
return self.processTableFields(self.getTitle(parent), self.getFields(parent), self.getRowStyle(parent))
|
||||
|
||||
# try to get id
|
||||
return self.getItems(parent, self._args[0])
|
||||
@ -294,6 +284,9 @@ class DetailHandler(BaseModelHandler):
|
||||
def getFields(self, parent):
|
||||
return []
|
||||
|
||||
def getRowStyle(self, parent):
|
||||
return {}
|
||||
|
||||
def getGui(self, parent, forType):
|
||||
raise RequestError('Gui not provided for this type of object')
|
||||
|
||||
@ -330,6 +323,7 @@ class ModelHandler(BaseModelHandler):
|
||||
save_fields = []
|
||||
# Table info needed fields and title
|
||||
table_fields = []
|
||||
table_row_style = {}
|
||||
table_title = ''
|
||||
|
||||
# This methods must be override, depending on what is provided
|
||||
@ -429,7 +423,7 @@ class ModelHandler(BaseModelHandler):
|
||||
elif self._args[0] == TYPES:
|
||||
return list(self.getTypes())
|
||||
elif self._args[0] == TABLEINFO:
|
||||
return self.processTableFields(self.table_title, self.table_fields)
|
||||
return self.processTableFields(self.table_title, self.table_fields, self.table_row_style)
|
||||
elif self._args[0] == GUI:
|
||||
return self.getGui(None)
|
||||
|
||||
|
@ -105,9 +105,20 @@ div.dataTables_scrollFoot table {
|
||||
color: white;
|
||||
}
|
||||
|
||||
.table tbody tr.active:hover td,
|
||||
.table tbody tr.active:hover th {
|
||||
background-color: #0075b0 !important;
|
||||
.table-striped > tbody > tr:nth-child(2n+1) > td { background-color: #d9edf7; }
|
||||
.table-striped > tbody > tr:nth-child(2n) > td { background-color: white; }
|
||||
|
||||
.table-striped > tbody > tr:nth-child(2n+1) > td.sorting_1 { background-color: #b3dbef; }
|
||||
.table-striped > tbody > tr:nth-child(2n) > td.sorting_1 { background-color: #F5F5F5; }
|
||||
|
||||
|
||||
/*table.dataTable tr.odd td.sorting_1 { background-color: #E5E5E5; }
|
||||
table.dataTable tr.even td.sorting_1 { background-color: #F5F5F5; }*/
|
||||
|
||||
.table tbody tr:hover td,
|
||||
.table tbody tr:hover th {
|
||||
background-color: #08C !important;
|
||||
color: white;
|
||||
}
|
||||
|
||||
.table tbody tr.active a {
|
||||
|
@ -31,21 +31,15 @@ table.dataTable td.dataTables_empty {
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
/*table.dataTable tr.odd { background-color: #F5F5F5; }
|
||||
table.dataTable tr.even { background-color: white; }*/
|
||||
|
||||
table.dataTable tr.odd td.sorting_1 { background-color: #E5E5E5; }
|
||||
table.dataTable tr.even td.sorting_1 { background-color: #F5F5F5; }
|
||||
|
||||
/* Overwrites all color selection on selected rows */
|
||||
.table tbody tr.active td { background-color: #0075B0 !important; }
|
||||
|
||||
/*table.dataTable tr.odd td.sorting_1 { background-color: #D3D6FF; }
|
||||
table.dataTable tr.odd td.sorting_1 { background-color: #D3D6FF; }
|
||||
table.dataTable tr.odd td.sorting_2 { background-color: #DADCFF; }
|
||||
table.dataTable tr.odd td.sorting_3 { background-color: #E0E2FF; }
|
||||
table.dataTable tr.even td.sorting_1 { background-color: #EAEBFF; }
|
||||
table.dataTable tr.even td.sorting_2 { background-color: #F2F3FF; }
|
||||
table.dataTable tr.even td.sorting_3 { background-color: #F9F9FF; } */
|
||||
table.dataTable tr.even td.sorting_3 { background-color: #F9F9FF; }
|
||||
|
||||
|
||||
/*
|
||||
|
@ -78,6 +78,21 @@ body {
|
||||
z-index: 2014;
|
||||
}
|
||||
|
||||
/* Tables */
|
||||
|
||||
/* Tables "styling" */
|
||||
tr.row-state-A, tr.row-state-F, tr.row-state-U, tr.row-state-W {
|
||||
color: black;
|
||||
}
|
||||
|
||||
tr.row-state-B, tr.row-state-C, tr.row-state-E {
|
||||
color: red;
|
||||
}
|
||||
|
||||
tr.row-state-M, tr.row-state-R, tr.row-state-I {
|
||||
color: #858585;
|
||||
}
|
||||
|
||||
/* Edit Below to Customize Widths > 768px */
|
||||
@media (min-width:768px) {
|
||||
|
||||
|
@ -127,7 +127,7 @@
|
||||
|
||||
|
||||
// Public attributes
|
||||
api.debug = true;
|
||||
api.debug = false;
|
||||
}(window.api = window.api || {}, jQuery));
|
||||
|
||||
|
||||
|
@ -11,6 +11,12 @@ gui.deployedservices.link = function(event) {
|
||||
deployed_services : 'deployed-services-placeholder',
|
||||
}));
|
||||
gui.setLinksEvents();
|
||||
|
||||
var tableId = gui.deployedservices.table({
|
||||
container : 'deployed-services-placeholder',
|
||||
rowSelect : 'single',
|
||||
buttons : [ 'new', 'edit', 'delete', 'xls' ],
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
|
@ -139,6 +139,8 @@ GuiElement.prototype = {
|
||||
};
|
||||
|
||||
this.rest.tableInfo(function(data) { // Gets tableinfo data (columns, title, visibility of fields, etc...
|
||||
var row_style = data['row-style'];
|
||||
gui.doLog(row_style);
|
||||
var title = data.title;
|
||||
var columns = [];
|
||||
$.each(data.fields, function(index, value) {
|
||||
@ -178,6 +180,7 @@ GuiElement.prototype = {
|
||||
if( opts.icon !== undefined ) {
|
||||
column.mRender = renderIcon(opts.icon);
|
||||
}
|
||||
break;
|
||||
case 'icon_dict':
|
||||
if( opts.icon_dict !== undefined ) {
|
||||
column.mRender = renderIconDict(opts.icon_dict);
|
||||
@ -348,8 +351,6 @@ GuiElement.prototype = {
|
||||
"fnClick" : function() { // Export to excel
|
||||
api.templates.get('spreadsheet', function(tmpl) {
|
||||
var styles = { 'bold': 's21', };
|
||||
var uri = 'data:application/vnd.ms-excel;base64,',
|
||||
base64 = function(s) { return window.btoa(unescape(encodeURIComponent(s))); };
|
||||
|
||||
var headings = [], rows = [];
|
||||
$.each(columns, function(index, heading){
|
||||
@ -412,8 +413,8 @@ GuiElement.prototype = {
|
||||
rowDeselectedFnc(this.fnGetSelectedData(), $('#' + tableId).dataTable(), self);
|
||||
};
|
||||
}
|
||||
|
||||
$('#' + tableId).dataTable({
|
||||
|
||||
var dataTableOptions = {
|
||||
"aaData" : data,
|
||||
"aoColumns" : columns,
|
||||
"oLanguage" : gui.config.dataTablesLanguage,
|
||||
@ -423,7 +424,21 @@ GuiElement.prototype = {
|
||||
// (pagination) row
|
||||
"sDom" : "<'row'<'col-xs-8'T><'col-xs-4'f>r>t<'row'<'col-xs-5'i><'col-xs-7'p>>",
|
||||
"bDeferRender": options.deferedRender || false,
|
||||
});
|
||||
};
|
||||
|
||||
// If row is "styled"
|
||||
if( row_style.field ) {
|
||||
var field = row_style.field;
|
||||
var dct = row_style.dict;
|
||||
var prefix = row_style.prefix;
|
||||
dataTableOptions["fnCreatedRow"] = function( nRow, aData, iDataIndex ) {
|
||||
var v = dct !== undefined ? dct[this.fnGetData(iDataIndex)[field]] : this.fnGetData(iDataIndex)[field];
|
||||
$(nRow).addClass(prefix + v);
|
||||
gui.doLog(prefix + v);
|
||||
};
|
||||
}
|
||||
|
||||
$('#' + tableId).dataTable(dataTableOptions);
|
||||
// Fix 3dbuttons
|
||||
gui.tools.fix3dButtons('#' + tableId + '_wrapper .btn-group-3d');
|
||||
// Fix form
|
||||
|
Loading…
x
Reference in New Issue
Block a user