Adding scheduled action on transports

Fixed PUT for detail items
This commit is contained in:
Adolfo Gómez García 2018-05-07 16:47:19 +02:00
parent eead0d282c
commit 81a358e4e2
7 changed files with 120 additions and 80 deletions

View File

@ -34,10 +34,11 @@ from __future__ import unicode_literals
import servicemanager # @UnresolvedImport, pylint: disable=import-error
import logging
import os
import six
import tempfile
# Valid logging levels, from UDS Broker (uds.core.utils.log)
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in xrange(6))
OTHER, DEBUG, INFO, WARN, ERROR, FATAL = (10000 * (x + 1) for x in six.moves.xrange(6))
class LocalLogger(object):

View File

@ -32,9 +32,12 @@
from __future__ import unicode_literals
from win32com.shell import shell # @UnresolvedImport, pylint: disable=import-error
import _winreg as wreg # @UnresolvedImport, pylint: disable=import-error
try:
import _winreg as wreg # @UnresolvedImport, pylint: disable=import-error
except Exception: # Python3
import winreg as wreg
import win32security # @UnresolvedImport, pylint: disable=import-error
import cPickle
import pickle
DEBUG = False
@ -78,7 +81,7 @@ def readConfig():
key = wreg.OpenKey(baseKey, path, 0, wreg.KEY_QUERY_VALUE) # @UndefinedVariable
data, _ = wreg.QueryValueEx(key, '') # @UndefinedVariable
wreg.CloseKey(key) # @UndefinedVariable
return cPickle.loads(decoder(data))
return pickle.loads(decoder(data))
except Exception:
return None
@ -90,7 +93,7 @@ def writeConfig(data, fixPermissions=True):
if fixPermissions is True:
fixRegistryPermissions(key.handle)
wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, encoder(cPickle.dumps(data))) # @UndefinedVariable
wreg.SetValueEx(key, "", 0, wreg.REG_BINARY, encoder(pickle.dumps(data))) # @UndefinedVariable
wreg.CloseKey(key) # @UndefinedVariable
def useOldJoinSystem():

View File

@ -34,7 +34,15 @@ from __future__ import unicode_literals
from django.utils.translation import ugettext, ugettext_lazy as _
from uds.models import DeployedService, OSManager, Service, Image, ServicesPoolGroup, Account
from uds.models.CalendarAction import CALENDAR_ACTION_INITIAL, CALENDAR_ACTION_MAX, CALENDAR_ACTION_CACHE_L1, CALENDAR_ACTION_CACHE_L2, CALENDAR_ACTION_PUBLISH
from uds.models.CalendarAction import (
CALENDAR_ACTION_INITIAL,
CALENDAR_ACTION_MAX,
CALENDAR_ACTION_CACHE_L1,
CALENDAR_ACTION_CACHE_L2,
CALENDAR_ACTION_PUBLISH,
CALENDAR_ACTION_ADD_TRANSPORT,
CALENDAR_ACTION_DEL_TRANSPORT,
)
from uds.core.ui.images import DEFAULT_THUMB_BASE64
from uds.core.util.State import State
from uds.core.util.model import processUuid
@ -412,4 +420,6 @@ class ServicesPools(ModelHandler):
if itemInfo.publicationType is not None:
validActions += (CALENDAR_ACTION_PUBLISH,)
# Transport actions
validActions += (CALENDAR_ACTION_ADD_TRANSPORT, CALENDAR_ACTION_DEL_TRANSPORT)
return validActions

View File

@ -54,7 +54,7 @@ import logging
logger = logging.getLogger(__name__)
__updated__ = '2018-02-01'
__updated__ = '2018-05-07'
# a few constants
OVERVIEW = 'overview'
@ -412,7 +412,7 @@ class DetailHandler(BaseModelHandler): # pylint: disable=abstract-class-not-use
item = None
if len(self._args) == 1:
item = self._args[0]
else:
elif len(self._args) > 1: # PUT expects 0 or 1 parameters. 0 == NEW, 1 = EDIT
self.invalidRequestException()
logger.debug('Invoking proper saving detail item {}'.format(item))

View File

@ -58,10 +58,14 @@ CALENDAR_ACTION_CACHE_L1 = {'id': 'CACHEL1', 'description': _('Set cache size'),
CALENDAR_ACTION_CACHE_L2 = {'id': 'CACHEL2', 'description': _('Set L2 cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache L2 size'), 'default': '1'},)}
CALENDAR_ACTION_INITIAL = {'id': 'INITIAL', 'description': _('Set initial services'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Initial services'), 'default': '1'},)}
CALENDAR_ACTION_MAX = {'id': 'MAX', 'description': _('Set maximum number of services'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Maximum services'), 'default': '10'},)}
CALENDAR_ACTION_ADD_TRANSPORT = {'id': 'ADD_TRANSPORT', 'description': _('Add a transport'), 'params': ({'type': 'transport', 'name': 'transport', 'description': _('Transport to add'), 'default': ''},)}
CALENDAR_ACTION_DEL_TRANSPORT = {'id': 'REMOVE_TRANSPORT', 'description': _('Remove a transport'), 'params': ({'type': 'transport', 'name': 'transport', 'description': _('Trasport to remove'), 'default': ''},)}
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
CALENDAR_ACTION_CACHE_L2, CALENDAR_ACTION_INITIAL,
CALENDAR_ACTION_MAX, CALENDAR_ACTION_ADD_TRANSPORT,
CALENDAR_ACTION_DEL_TRANSPORT
)))
@ -106,6 +110,9 @@ class CalendarAction(UUIDModel):
elif CALENDAR_ACTION_PUBLISH['id'] == self.action:
self.service_pool.publish(changeLog='Scheduled publication action')
saveServicePool = False
elif CALENDAR_ACTION_ADD_TRANSPORT['id'] == self.action:
# TODO: Insert transport
pass
# On save, will regenerate nextExecution
if save:

View File

@ -1,9 +1,10 @@
readParamsFromInputs = (modalId) ->
a = {}
a[$(v).attr('name')] = $(v).val() for v in $(modalId + ' .action_parameters')
for v in $(modalId + ' select.action_parameters,input.action_parameters')
a[$(v).attr('name')] = $(v).val()
return a
actionSelectChangeFnc = (modalId, actionsList) ->
actionSelectChangeFnc = (modalId, actionsList, context) ->
gui.doLog "onChange"
action = $(modalId + " #id_action_select").val()
if action == '-1'
@ -14,11 +15,25 @@ actionSelectChangeFnc = (modalId, actionsList) ->
if i['params'].length > 0
html = ''
for j in i['params']
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="' + j['default'] + '"></div></div>'
if j['type'] == 'transport'
html += '<div class="form-group"><label for="fld_' + j['name'] +
'" class="col-sm-3 control-label">' + j['description'] +
'</label><div class="col-sm-9"><select class="selectpicker show-menu-arrow show-tick action_parameters"' +
' name="' + j['name'] + '" data-style="btn-default" data-width="100%" data-live-search="true">';
# Add transports
for k in context['transports']
html += '<option value="' + k['id'] + '"'
if k['id'] == j['default']
html += ' selected'
html += '>' + k['name'] + '</option>'
html += '</div></div>'
else
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="' + j['default'] + '"></div></div>'
$(modalId + " #parameters").html(html)
gui.tools.applyCustoms modalId
return
@ -86,38 +101,41 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
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,
calendars: data
calendarId: ''
actionsList: actionsList
action: ''
eventsOffset: 0
atStart: true
))
$(modalId + " .button-accept").on "click", (event) ->
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
eventsOffset: offset
atStart: atStart
action: action
params: readParamsFromInputs(modalId)
api.transports.overview (trans) ->
api.servicesPools.actionsList servPool.id, (actionsList) ->
modalId = gui.launchModal(gettext("Add scheduled action"), api.templates.evaluate(tmpl,
calendars: data
calendarId: ''
actionsList: actionsList
action: ''
eventsOffset: 0
atStart: true
))
$(modalId + " .button-accept").on "click", (event) ->
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
eventsOffset: offset
atStart: atStart
action: action
params: readParamsFromInputs(modalId)
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
$(modalId + ' #id_action_select').on "change", (event) ->
actionSelectChangeFnc(modalId, actionsList, {'transports': trans })
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
$(modalId + ' #id_action_select').on "change", (event) ->
actionSelectChangeFnc(modalId, actionsList)
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
@ -138,43 +156,44 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
gui.doLog 'Setting value'
k['default'] = item.params[j]
api.calendars.overview (data) ->
gui.doLog "Item: ", item
modalId = gui.launchModal(gettext("Edit access calendar"), api.templates.evaluate(tmpl,
calendars: data
calendarId: item.calendarId
actionsList: actionsList
action: item.action
eventsOffset: item.eventsOffset
atStart: item.atStart
))
$(modalId + " .button-accept").on "click", (event) ->
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.save
id: item.id
calendarId: calendar
action: action
eventsOffset: offset
atStart: atStart
action: action
params: readParamsFromInputs(modalId)
, (data) ->
$(modalId).modal "hide"
refreshFnc()
api.transports.overview (trans) ->
api.calendars.overview (data) ->
gui.doLog "Item: ", item
modalId = gui.launchModal(gettext("Edit access calendar"), api.templates.evaluate(tmpl,
calendars: data
calendarId: item.calendarId
actionsList: actionsList
action: item.action
eventsOffset: item.eventsOffset
atStart: item.atStart
))
$(modalId + " .button-accept").on "click", (event) ->
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.save
id: item.id
calendarId: calendar
action: action
eventsOffset: offset
atStart: atStart
action: action
params: readParamsFromInputs(modalId)
, (data) ->
$(modalId).modal "hide"
refreshFnc()
return
return
return
$(modalId + ' #id_action_select').on "change", (event) ->
actionSelectChangeFnc(modalId, actionsList)
$(modalId + ' #id_action_select').on "change", (event) ->
actionSelectChangeFnc(modalId, actionsList, {'transports': trans })
# Triggers the event manually
actionSelectChangeFnc(modalId, actionsList)
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
# Triggers the event manually
actionSelectChangeFnc(modalId, actionsList)
# Makes form "beautyfull" :-)
gui.tools.applyCustoms modalId
return
return
return
return
return

View File

@ -43,6 +43,6 @@ from ..errors import error
from .images import image
from .file_storage import file_storage
__updated__ = '2018-03-14'
__updated__ = '2018-05-04'
logger = logging.getLogger(__name__)