Advancing on admin interface

This commit is contained in:
Adolfo Gómez 2014-01-27 06:57:42 +00:00
parent 1e74a82a40
commit 0d3a724ab8
5 changed files with 86 additions and 14 deletions

View File

@ -35,6 +35,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext_lazy as _, ugettext
from uds.models import Network
from uds.core.util import net
from uds.core.ui.UserInterface import gui
from uds.REST.model import ModelHandler, SaveException
@ -68,10 +69,10 @@ class Networks(ModelHandler):
def getGui(self, type_):
return self.addField(self.addDefaultFields([], ['name']),{
'name': 'net_string',
'value': True,
'value': '',
'label': ugettext('Network range'),
'tooltip': ugettext('Network range. Accepts most network definitions formats (range, subnet, host, etc...'),
'type': 'text',
'type': gui.InputField.TEXT_TYPE,
'order': 100, # At end
})

View File

@ -35,11 +35,13 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext as _
from uds.models import DeployedService
from uds.models import DeployedService, OSManager, Service
from uds.core.util.State import State
from uds.core.util import log
from uds.REST.model import ModelHandler
from uds.REST import NotFound
from django.utils.translation import ugettext
from uds.REST import ResponseError
from uds.core.ui.UserInterface import gui
from user_services import AssignedService, CachedService, Groups, Transports, Publications
import logging
@ -89,10 +91,66 @@ class ServicesPool(ModelHandler):
# Gui related
def getGui(self, type_):
try:
return self.addDefaultFields(['name', 'comments'])
except:
raise NotFound('type not found')
if OSManager.objects.count() < 1: # No os managers, can't create db
raise ResponseError(ugettext('Create at least one OS Manager before creating a new service pool'))
if Service.objects.count() < 1:
raise ResponseError(ugettext('Create at least a service before creating a new service pool'))
g = self.addDefaultFields([], ['name', 'comments'])
for f in [{
'name': 'service',
'values': [ gui.choiceItem(v.id, v.name) for v in Service.objects.all() ],
'label': ugettext('Base service'),
'tooltip': ugettext('Service used as base of this service pool'),
'type': gui.InputField.CHOICE_TYPE,
'order': 100, # At end
},{
'name': 'osmanager',
'values': [ gui.choiceItem(v.id, v.name) for v in OSManager.objects.all() ],
'label': ugettext('OS Manager'),
'tooltip': ugettext('OS Manager used as base of this service pool'),
'type': gui.InputField.CHOICE_TYPE,
'order': 101, # At end
},{
'name': 'initial_services',
'value': '0',
'label': ugettext('Initial available services'),
'tooltip': ugettext('Services created initially for this service pool'),
'type': gui.InputField.NUMERIC_TYPE,
'order': 102, # At end
},{
'name': 'cached_services',
'value': '0',
'label': ugettext('Services to keep in cache'),
'tooltip': ugettext('Services keeped in cache for improved user service assignation'),
'type': gui.InputField.NUMERIC_TYPE,
'order': 103, # At end
},{
'name': 'cached_services_l2',
'value': '0',
'label': ugettext('Services to keep in L2 cache'),
'tooltip': ugettext('Services keeped in cache of level2 for improved service generation'),
'type': gui.InputField.NUMERIC_TYPE,
'order': 104, # At end
},{
'name': 'max_services',
'value': '0',
'label': ugettext('Maximum number of services to provide'),
'tooltip': ugettext('Maximum number of service (assigned and L1 cache) that can be created for this service'),
'type': gui.InputField.NUMERIC_TYPE,
'order': 105, # At end
},{
'name': 'publish_on_save',
'value': True,
'label': ugettext('Publish on creation'),
'tooltip': ugettext('If selected, will initiate the publication on service inmediatly pool after creation'),
'type': gui.InputField.CHECKBOX_TYPE,
'order': 106, # At end
}]:
self.addField(g, f)
return g
# Logs
def getLogs(self, item):

View File

@ -35,8 +35,9 @@ from __future__ import unicode_literals
from handlers import NotFound, RequestError
from django.utils.translation import ugettext as _
from django.db import IntegrityError
from uds.REST.handlers import Handler
from uds.core.ui.UserInterface import gui as uiGui
from uds.REST.handlers import Handler
from uds.core.util import log
import logging
@ -70,7 +71,7 @@ class BaseModelHandler(Handler):
'multiline': field.get('multiline', 0),
'tooltip': field.get('tooltip', ''),
'rdonly': field.get('rdonly', False),
'type': field.get('type', 'text'),
'type': field.get('type', uiGui.InputField.TEXT_TYPE),
'order': field.get('order', 0),
'values': field.get('values', [])
}
@ -100,6 +101,8 @@ class BaseModelHandler(Handler):
'type': 'numeric',
'label': _('Priority'),
'tooltip': _('Selects the priority of this element (lower number means higher priority)'),
'required': True,
'value': 1,
'length': 4,
'order': -98,
})
@ -109,6 +112,7 @@ class BaseModelHandler(Handler):
'type': 'text',
'label': _('Small name'),
'tooltip': _('Small name of this element'),
'required': True,
'length': 128,
'order': -97,
})

View File

@ -205,6 +205,9 @@ gui.servicesPool.link = function(event) {
value.parent = gettext('unknown (needs reload)');
}
});
},
onNew: function(type, table, refreshFnc) {
gui.methods.typedNew(gui.servicesPool, gettext('New service pool'), gettext('Error deleting service pool'))(type, table, refreshFnc);
}
});
});

View File

@ -278,7 +278,7 @@
return function(value, event, table, refreshFnc) {
gui.tools.blockUI();
parent.rest.gui(value.type, function(guiDefinition) {
var buttons;
var buttons = null;
if( options.testButton ) {
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, value.type);
}
@ -313,19 +313,25 @@
gui.tools.blockUI();
parent.rest.gui(type, function(guiDefinition) {
gui.tools.unblockUI();
var buttons;
var buttons = null;
if( options.testButton ) {
buttons = gui.methods.typedTestButton(parent.rest, options.testButton.text, options.testButton.css, type);
}
var tabs = options.guiProcessor ? options.guiProcessor(guiDefinition) : guiDefinition; // Preprocess fields (probably generate tabs...)
var title = modalTitle;
if( parent.types[type] !== undefined ) {
title += ' ' + gettext('of type') +' <b>' + parent.types[type].name + '</b>';
}
gui.forms.launchModal({
title: modalTitle + ' ' + gettext('of type') +' <b>' + parent.types[type].name + '</b>',
title: title,
fields: tabs,
item: undefined,
buttons: buttons,
success: function(form_selector, closeFnc) {
var fields = gui.forms.read(form_selector);
fields.data_type = type;
if( parent.types[type] !== undefined ) {
fields.data_type = type;
}
fields = options.fieldsProcessor ? options.fieldsProcessor(fields) : fields; // Process fields before creating?
parent.rest.create(fields, function(data) { // Success on put
closeFnc();