forked from shaba/openuds
Now we can create (but not edit) scheduled actions
This commit is contained in:
parent
fcf030e693
commit
8f9d042cdd
@ -147,6 +147,6 @@ class CalendarRules(DetailHandler): # pylint: disable=too-many-public-methods
|
||||
|
||||
def getTitle(self, parent):
|
||||
try:
|
||||
return _('Services of {0}').format(parent.name)
|
||||
return _('Rules of {0}').format(parent.name)
|
||||
except Exception:
|
||||
return _('Current rules')
|
||||
|
@ -39,6 +39,7 @@ from django.utils.translation import ugettext as _
|
||||
|
||||
|
||||
from uds.models import CalendarAccess, CalendarAction, Calendar
|
||||
from uds.models.CalendarAction import CALENDAR_ACTION_DICT
|
||||
from uds.core.util.State import State
|
||||
from uds.core.util.model import processUuid
|
||||
from uds.core.util import log
|
||||
@ -46,8 +47,7 @@ from uds.REST.model import DetailHandler
|
||||
from uds.REST import ResponseError
|
||||
from uds.core.util import permissions
|
||||
|
||||
|
||||
|
||||
import json
|
||||
import logging
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@ -93,7 +93,7 @@ class AccessCalendars(DetailHandler):
|
||||
|
||||
def saveItem(self, parent, item):
|
||||
# If already exists
|
||||
uuid = processUuid(self._params['id']) if 'id' in self._params else None
|
||||
uuid = processUuid(item) if item is not None else None
|
||||
|
||||
calendar = Calendar.objects.get(uuid=processUuid(self._params['calendarId']))
|
||||
access = self._params['access'].upper()
|
||||
@ -126,10 +126,10 @@ class ActionsCalendars(DetailHandler):
|
||||
'id': item.uuid,
|
||||
'calendarId': item.calendar.uuid,
|
||||
'name': item.calendar.name,
|
||||
'action': item.action,
|
||||
'action': CALENDAR_ACTION_DICT[item.action]['description'],
|
||||
'atStart': item.atStart,
|
||||
'offset': item.eventOffset,
|
||||
'params': item.params
|
||||
'offset': item.eventsOffset,
|
||||
'params': json.loads(item.params)
|
||||
}
|
||||
|
||||
def getItems(self, parent, item):
|
||||
@ -150,18 +150,22 @@ class ActionsCalendars(DetailHandler):
|
||||
return [
|
||||
{'name': {'title': _('Name')}},
|
||||
{'action': {'title': _('Action')}},
|
||||
{'atStart': {'title': _('Referer')}},
|
||||
{'params': {'title': _('Parameters')}},
|
||||
{'atStart': {'title': _('Relative to')}},
|
||||
{'offset': {'title': _('Time offset')}},
|
||||
]
|
||||
|
||||
def saveItem(self, parent, item):
|
||||
# If already exists
|
||||
uuid = processUuid(self._params['id']) if 'id' in self._params else None
|
||||
uuid = processUuid(item) if item is not None else None
|
||||
|
||||
calendar = Calendar.objects.get(uuid=processUuid(self._params['calendarId']))
|
||||
action = self._params['action'].upper()
|
||||
eventOffset = int(self._params['eventOffset'])
|
||||
atStart = (self._params['atStart'] == 'true')
|
||||
eventsOffset = int(self._params['eventsOffset'])
|
||||
atStart = self._params['atStart'] not in ('false', False, '0', 0)
|
||||
params = json.dumps(self._params['params'])
|
||||
|
||||
logger.debug('Got parameters: {} {} {} {} ----> {}'.format(calendar, action, eventsOffset, atStart, params))
|
||||
|
||||
if uuid is not None:
|
||||
calAction = CalendarAction.objects.get(uuid=uuid)
|
||||
@ -169,10 +173,11 @@ class ActionsCalendars(DetailHandler):
|
||||
calAction.servicePool = parent
|
||||
calAction.action = action
|
||||
calAction.atStart = atStart
|
||||
calAction.eventOffset = eventOffset
|
||||
calAction.eventsOffset = eventsOffset
|
||||
calAction.params = params
|
||||
calAction.save()
|
||||
else:
|
||||
CalendarAction.objects.create(calendar=calendar, servicePool=parent, action=action, atStart=atStart, eventOffset=eventOffset)
|
||||
CalendarAction.objects.create(calendar=calendar, servicePool=parent, action=action, atStart=atStart, eventsOffset=eventsOffset, params=params)
|
||||
|
||||
return self.success()
|
||||
|
||||
|
@ -57,6 +57,8 @@ CALENDAR_ACTION_CACHE_L2 = { 'id': 'CACHEL2', 'description': _('Sets L2 cache si
|
||||
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') },) }
|
||||
|
||||
CALENDAR_ACTION_DICT = dict(list((c['id'], c) for c in (CALENDAR_ACTION_PUBLISH, CALENDAR_ACTION_CACHE_L1,
|
||||
CALENDAR_ACTION_CACHE_L2, CALENDAR_ACTION_INITIAL, CALENDAR_ACTION_MAX)))
|
||||
class CalendarAction(UUIDModel):
|
||||
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
|
||||
servicePool = models.ForeignKey(ServicePool, on_delete=models.CASCADE)
|
||||
|
@ -21,8 +21,18 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
|
||||
return true
|
||||
|
||||
onData: (data) ->
|
||||
$.each data, (index, value) ->
|
||||
value.params = ( k + "=" + value.params[k] for k in Object.keys(value.params)).toString()
|
||||
value.atStart = if value.atStart then gettext('Beginning') else gettext('Ending')
|
||||
|
||||
onNew: (value, table, refreshFnc) ->
|
||||
api.templates.get "pool_add_access", (tmpl) ->
|
||||
readParamsFromInputs = (modalId) ->
|
||||
a = {}
|
||||
a[$(v).attr('name')] = $(v).val() for v in $(modalId + ' .action_parameters')
|
||||
return a
|
||||
|
||||
api.templates.get "pool_add_action", (tmpl) ->
|
||||
api.calendars.overview (data) ->
|
||||
api.servicesPools.actionsList servPool.id, (actionsList) ->
|
||||
modalId = gui.launchModal(gettext("Add scheduled action"), api.templates.evaluate(tmpl,
|
||||
@ -31,17 +41,22 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
calendarId: ''
|
||||
actionsList: actionsList
|
||||
action: ''
|
||||
eventOffset: 0
|
||||
eventsOffset: 0
|
||||
atStart: true
|
||||
))
|
||||
$(modalId + " .button-accept").on "click", (event) ->
|
||||
priority = $(modalId + " #id_priority").val()
|
||||
offset = $(modalId + " #id_offset").val()
|
||||
calendar = $(modalId + " #id_calendar_select").val()
|
||||
action = $(modalId + " #id_action_select").val()
|
||||
atStart = $(modalId + " #atStart_field").is(":checked")
|
||||
actionsCalendars.rest.create
|
||||
calendarId: calendar
|
||||
action: action
|
||||
priority: priority
|
||||
eventsOffset: offset
|
||||
atStart: atStart
|
||||
action: action
|
||||
params: readParamsFromInputs(modalId)
|
||||
|
||||
, (data) ->
|
||||
$(modalId).modal "hide"
|
||||
refreshFnc()
|
||||
@ -62,7 +77,11 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||
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>'
|
||||
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="action_parameters" name="' + j['name'] +
|
||||
'" value="' + defval + '"></div></div>'
|
||||
$(modalId + " #parameters").html(html)
|
||||
gui.tools.applyCustoms modalId
|
||||
return
|
||||
|
@ -2,15 +2,15 @@
|
||||
{% verbatim %}
|
||||
<form class="form-horizontal" role="form">
|
||||
<div class="form-group">
|
||||
<label for="id_priority" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
|
||||
<div class="col-sm-9">
|
||||
<label for="id_priority" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<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-3 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
|
||||
<div class="col-sm-9">
|
||||
<label for="id_calendar_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
|
||||
<div class="col-sm-10">
|
||||
<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,37 +21,14 @@
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<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>
|
||||
<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>
|
||||
{{/ each }}
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div id="parameters">
|
||||
</div>
|
||||
|
||||
</form>
|
||||
{% endverbatim %}
|
||||
|
Loading…
Reference in New Issue
Block a user