1
0
mirror of https://github.com/dkmstr/openuds.git synced 2024-12-22 13:34:04 +03:00

Advanfing on action editing for services pools

This commit is contained in:
Adolfo Gómez García 2016-03-29 05:30:05 +02:00
parent 31e6e01cad
commit fcf030e693
6 changed files with 115 additions and 50 deletions

View File

@ -34,6 +34,7 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _
from uds.models import DeployedService, OSManager, Service, Image, ServicesPoolGroup
from uds.models.CalendarAction import CALENDAR_ACTION_INITIAL, CALENDAR_ACTION_MAX, CALENDAR_ACTION_CACHE_L1, CALENDAR_ACTION_CACHE_L2, CALENDAR_ACTION_PUBLISH
from uds.core.ui.images import DEFAULT_THUMB_BASE64
from uds.core.util.State import State
from uds.core.util.model import processUuid
@ -82,7 +83,8 @@ class ServicesPools(ModelHandler):
# Field from where to get "class" and prefix for that class, so this will generate "row-state-A, row-state-X, ....
table_row_style = {'field': 'state', 'prefix': 'row-state-'}
custom_methods = [('setFallbackAccess', True)]
custom_methods = [('setFallbackAccess', True), ('actionsList', True)]
def item_as_dict(self, item):
# if item does not have an associated service, hide it (the case, for example, for a removed service)
@ -278,4 +280,18 @@ class ServicesPools(ModelHandler):
logger.debug('Setting fallback of {} to {}'.format(item.name, fallback))
item.fallbackAccess = fallback
item.save()
return ''
return ''
# Returns the action list based on current element, for calendar
def actionsList(self, item):
validActions = ()
itemInfo = item.service.getType()
if itemInfo.usesCache is True:
validActions += (CALENDAR_ACTION_INITIAL, CALENDAR_ACTION_CACHE_L1, CALENDAR_ACTION_MAX)
if itemInfo.usesCache_L2 is True:
validActions += (CALENDAR_ACTION_CACHE_L2,)
if itemInfo.publicationType is not None:
validActions += (CALENDAR_ACTION_PUBLISH,)
return validActions

View File

@ -34,8 +34,9 @@
from __future__ import unicode_literals
__updated__ = '2016-03-16'
__updated__ = '2016-03-29'
from django.utils.translation import ugettext_lazy as _
from django.db import models
from uds.models.Calendar import Calendar
from uds.models.UUIDModel import UUIDModel
@ -48,11 +49,13 @@ import logging
logger = logging.getLogger(__name__)
# Current posible actions
ACTION_PUBLISH = 'PUBLISH'
ACTION_CACHE_L1 = 'CACHEL1'
ACTION_CACHE_L2 = 'CACHEL2'
ACTION_INITIAL = 'INITIAL'
ACTION_MAX = 'MAX'
# Each line describes:
#
CALENDAR_ACTION_PUBLISH = { 'id' : 'PUBLISH', 'description': _('Publish'), 'params': () }
CALENDAR_ACTION_CACHE_L1 = { 'id': 'CACHEL1', 'description': _('Sets cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache size') },) }
CALENDAR_ACTION_CACHE_L2 = { 'id': 'CACHEL2', 'description': _('Sets L2 cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache L2 size') },) }
CALENDAR_ACTION_INITIAL = { 'id': 'INITIAL', 'description': _('Set initial services'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Initial services') },) }
CALENDAR_ACTION_MAX = { 'id': 'MAX', 'description': _('Change maximum number of services'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Maximum services') },) }
class CalendarAction(UUIDModel):
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)

View File

@ -47,7 +47,7 @@ from uds.models.UUIDModel import UUIDModel
import logging
__updated__ = '2015-06-17'
__updated__ = '2016-03-29'
logger = logging.getLogger(__name__)
@ -132,7 +132,7 @@ class DeployedServicePublication(UUIDModel):
raise Exception('Tried to get a publication instance for a service that do not needs it')
if serviceInstance.publicationType is None:
raise Exception('Class {0} do not have defined publicationType but needs to be published!!!'.format(serviceInstance.__class__.__name))
raise Exception('Class {0} do not have defined publicationType but needs to be published!!!'.format(serviceInstance.__class__))
dpl = serviceInstance.publicationType(self.getEnvironment(), service=serviceInstance, osManager=osManagerInstance, revision=self.revision, dsName=self.deployed_service.name)
# Only invokes deserialization if data has something. '' is nothing

View File

@ -432,6 +432,11 @@ api.servicesPools.setFallbackAccess = (id, fallbackAccess, success_fnc, fail_fnc
id: id + '/setFallbackAccess?fallbackAccess=' + fallbackAccess
success: success_fnc
fail: fail_fnc
api.servicesPools.actionsList = (id, success_fnc, fail_fnc) ->
@get
id: id + '/actionsList'
success: success_fnc
fail: fail_fnc
api.configuration = new BasicModelRest("config")
api.gallery = new BasicModelRest("gallery/images")

View File

@ -1,6 +1,6 @@
gui.servicesPools.actionsCalendars = (servPool, info) ->
accessCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "actions", { permission: servPool.permission }), "actions")
accessCalendarsTable = accessCalendars.table(
actionsCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "actions", { permission: servPool.permission }), "actions")
actionsCalendarsTable = actionsCalendars.table(
doNotLoadData: true
icon: 'assigned'
container: "actions-placeholder"
@ -24,35 +24,53 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
onNew: (value, table, refreshFnc) ->
api.templates.get "pool_add_access", (tmpl) ->
api.calendars.overview (data) ->
modalId = gui.launchModal(gettext("Add access calendar"), api.templates.evaluate(tmpl,
calendars: data
priority: 1
calendarId: ''
accessList: accessList
access: 'ALLOW'
))
$(modalId + " .button-accept").on "click", (event) ->
priority = $(modalId + " #id_priority").val()
calendar = $(modalId + " #id_calendar_select").val()
access = $(modalId + " #id_access_select").val()
accessCalendars.rest.create
calendarId: calendar
access: access
priority: priority
, (data) ->
$(modalId).modal "hide"
refreshFnc()
api.servicesPools.actionsList servPool.id, (actionsList) ->
modalId = gui.launchModal(gettext("Add scheduled action"), api.templates.evaluate(tmpl,
calendars: data
priority: 1
calendarId: ''
actionsList: actionsList
action: ''
eventOffset: 0
atStart: true
))
$(modalId + " .button-accept").on "click", (event) ->
priority = $(modalId + " #id_priority").val()
calendar = $(modalId + " #id_calendar_select").val()
action = $(modalId + " #id_action_select").val()
actionsCalendars.rest.create
calendarId: calendar
action: action
priority: priority
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
return
$(modalId + ' #id_action_select').on "change", (event) ->
action = $(modalId + " #id_action_select").val()
if action == '-1'
return
$(modalId + " #parameters").empty()
for i in actionsList
if i['id'] == action
if i['params'].length > 0
html = ''
for j in i['params']
if j['type'] == 'numeric'
defval = '1'
else
defval = ''
html += '<div class="form-group"><label for="fld_' + j['name'] + '" class="col-sm-3 control-label">' + j['description'] + '</label><div class="col-sm-9"><input type="' + j['type'] + '" class="modal_field_data" id="fld_' + j['name'] + '" value="' + defval + '"></div></div>'
$(modalId + " #parameters").html(html)
gui.tools.applyCustoms modalId
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
onEdit: (value, event, table, refreshFnc) ->
@ -73,7 +91,7 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
gui.tools.applyCustoms modalId
return
api.templates.get "pool_add_access", (tmpl) ->
accessCalendars.rest.item value.id, (item) ->
actionsCalendars.rest.item value.id, (item) ->
api.calendars.overview (data) ->
gui.doLog "Item: ", item
modalId = gui.launchModal(gettext("Edit access calendar"), api.templates.evaluate(tmpl,
@ -87,7 +105,7 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
priority = $(modalId + " #id_priority").val()
calendar = $(modalId + " #id_calendar_select").val()
access = $(modalId + " #id_access_select").val()
accessCalendars.rest.save
actionsCalendars.rest.save
id: item.id
calendarId: calendar
access: access
@ -103,7 +121,7 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
return
return
onDelete: gui.methods.del(accessCalendars, gettext("Remove access calendar"), gettext("Access calendar removal error"))
onDelete: gui.methods.del(actionsCalendars, gettext("Remove access calendar"), gettext("Access calendar removal error"))
)
return [accessCalendarsTable]
return [actionsCalendarsTable]

View File

@ -2,15 +2,15 @@
{% verbatim %}
<form class="form-horizontal" role="form">
<div class="form-group">
<label for="id_priority" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
<div class="col-sm-10">
<label for="id_priority" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
<div class="col-sm-9">
<input type="numeric" class="modal_field_data" id="id_priority" value="{{ priority }}">
</div>
</div>
<div class="form-group">
<label for="id_calendar_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
<div class="col-sm-10">
<label for="id_calendar_select" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
<div class="col-sm-9">
<select id="id_calendar_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
<option value="-1"></option>
{{# each calendars }}
@ -21,14 +21,37 @@
</div>
<div class="form-group">
<label for="id_action_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Access action' %}{% verbatim %}</label>
<div class="col-sm-10">
<select id="id_access_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
{{# each accessList }}
<option value="{{ this }}"{{# ifequals this ../access }} selected{{/ ifequals }}>{{ this }}</option>
<label for="id_offset" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Time Offset (min.)' %}{% verbatim %}</label>
<div class="col-sm-9">
<input type="numeric" class="modal_field_data" id="id_offset" value="{{ eventOffset }}">
</div>
</div>
<div class="form-group">
<label for="atStart_field" class="col-sm-3 control-label">{% endverbatim %}{% trans 'At interval beginning?' %}{% verbatim %}</label>
<div class="col-sm-9">
<input type="checkbox"
data-on-text="{% endverbatim %}{% trans 'Yes' %}{% verbatim %}"
data-off-text="{% endverbatim %}{% trans 'No' %}{% verbatim %}"
class="modal_field_data"
id="atStart_field"{{# ifequals atStart true }} checked{{/ ifequals }}>
</div>
</div>
<div class="form-group">
<label for="id_action_select" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Action' %}{% verbatim %}</label>
<div class="col-sm-9">
<select id="id_action_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
<option value="-1"></option>
{{# each actionsList }}
<option value="{{ id }}"{{# ifequals id ../action }} selected{{/ ifequals }}>{{ description }}</option>
{{/ each }}
</select>
</div>
</div>
<div id="parameters">
</div>
</form>
{% endverbatim %}