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:
parent
31e6e01cad
commit
fcf030e693
@ -34,6 +34,7 @@ from __future__ import unicode_literals
|
|||||||
|
|
||||||
from django.utils.translation import ugettext, ugettext_lazy as _
|
from django.utils.translation import ugettext, ugettext_lazy as _
|
||||||
from uds.models import DeployedService, OSManager, Service, Image, ServicesPoolGroup
|
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.ui.images import DEFAULT_THUMB_BASE64
|
||||||
from uds.core.util.State import State
|
from uds.core.util.State import State
|
||||||
from uds.core.util.model import processUuid
|
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, ....
|
# 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-'}
|
table_row_style = {'field': 'state', 'prefix': 'row-state-'}
|
||||||
|
|
||||||
custom_methods = [('setFallbackAccess', True)]
|
custom_methods = [('setFallbackAccess', True), ('actionsList', True)]
|
||||||
|
|
||||||
|
|
||||||
def item_as_dict(self, item):
|
def item_as_dict(self, item):
|
||||||
# if item does not have an associated service, hide it (the case, for example, for a removed service)
|
# if item does not have an associated service, hide it (the case, for example, for a removed service)
|
||||||
@ -279,3 +281,17 @@ class ServicesPools(ModelHandler):
|
|||||||
item.fallbackAccess = fallback
|
item.fallbackAccess = fallback
|
||||||
item.save()
|
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
|
||||||
|
@ -34,8 +34,9 @@
|
|||||||
|
|
||||||
from __future__ import unicode_literals
|
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 django.db import models
|
||||||
from uds.models.Calendar import Calendar
|
from uds.models.Calendar import Calendar
|
||||||
from uds.models.UUIDModel import UUIDModel
|
from uds.models.UUIDModel import UUIDModel
|
||||||
@ -48,11 +49,13 @@ import logging
|
|||||||
logger = logging.getLogger(__name__)
|
logger = logging.getLogger(__name__)
|
||||||
|
|
||||||
# Current posible actions
|
# Current posible actions
|
||||||
ACTION_PUBLISH = 'PUBLISH'
|
# Each line describes:
|
||||||
ACTION_CACHE_L1 = 'CACHEL1'
|
#
|
||||||
ACTION_CACHE_L2 = 'CACHEL2'
|
CALENDAR_ACTION_PUBLISH = { 'id' : 'PUBLISH', 'description': _('Publish'), 'params': () }
|
||||||
ACTION_INITIAL = 'INITIAL'
|
CALENDAR_ACTION_CACHE_L1 = { 'id': 'CACHEL1', 'description': _('Sets cache size'), 'params': ({'type': 'numeric', 'name': 'size', 'description': _('Cache size') },) }
|
||||||
ACTION_MAX = 'MAX'
|
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):
|
class CalendarAction(UUIDModel):
|
||||||
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
|
calendar = models.ForeignKey(Calendar, on_delete=models.CASCADE)
|
||||||
|
@ -47,7 +47,7 @@ from uds.models.UUIDModel import UUIDModel
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
__updated__ = '2015-06-17'
|
__updated__ = '2016-03-29'
|
||||||
|
|
||||||
|
|
||||||
logger = logging.getLogger(__name__)
|
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')
|
raise Exception('Tried to get a publication instance for a service that do not needs it')
|
||||||
|
|
||||||
if serviceInstance.publicationType is None:
|
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)
|
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
|
# Only invokes deserialization if data has something. '' is nothing
|
||||||
|
@ -432,6 +432,11 @@ api.servicesPools.setFallbackAccess = (id, fallbackAccess, success_fnc, fail_fnc
|
|||||||
id: id + '/setFallbackAccess?fallbackAccess=' + fallbackAccess
|
id: id + '/setFallbackAccess?fallbackAccess=' + fallbackAccess
|
||||||
success: success_fnc
|
success: success_fnc
|
||||||
fail: fail_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.configuration = new BasicModelRest("config")
|
||||||
api.gallery = new BasicModelRest("gallery/images")
|
api.gallery = new BasicModelRest("gallery/images")
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
gui.servicesPools.actionsCalendars = (servPool, info) ->
|
gui.servicesPools.actionsCalendars = (servPool, info) ->
|
||||||
accessCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "actions", { permission: servPool.permission }), "actions")
|
actionsCalendars = new GuiElement(api.servicesPools.detail(servPool.id, "actions", { permission: servPool.permission }), "actions")
|
||||||
accessCalendarsTable = accessCalendars.table(
|
actionsCalendarsTable = actionsCalendars.table(
|
||||||
doNotLoadData: true
|
doNotLoadData: true
|
||||||
icon: 'assigned'
|
icon: 'assigned'
|
||||||
container: "actions-placeholder"
|
container: "actions-placeholder"
|
||||||
@ -24,20 +24,23 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
|||||||
onNew: (value, table, refreshFnc) ->
|
onNew: (value, table, refreshFnc) ->
|
||||||
api.templates.get "pool_add_access", (tmpl) ->
|
api.templates.get "pool_add_access", (tmpl) ->
|
||||||
api.calendars.overview (data) ->
|
api.calendars.overview (data) ->
|
||||||
modalId = gui.launchModal(gettext("Add access calendar"), api.templates.evaluate(tmpl,
|
api.servicesPools.actionsList servPool.id, (actionsList) ->
|
||||||
|
modalId = gui.launchModal(gettext("Add scheduled action"), api.templates.evaluate(tmpl,
|
||||||
calendars: data
|
calendars: data
|
||||||
priority: 1
|
priority: 1
|
||||||
calendarId: ''
|
calendarId: ''
|
||||||
accessList: accessList
|
actionsList: actionsList
|
||||||
access: 'ALLOW'
|
action: ''
|
||||||
|
eventOffset: 0
|
||||||
|
atStart: true
|
||||||
))
|
))
|
||||||
$(modalId + " .button-accept").on "click", (event) ->
|
$(modalId + " .button-accept").on "click", (event) ->
|
||||||
priority = $(modalId + " #id_priority").val()
|
priority = $(modalId + " #id_priority").val()
|
||||||
calendar = $(modalId + " #id_calendar_select").val()
|
calendar = $(modalId + " #id_calendar_select").val()
|
||||||
access = $(modalId + " #id_access_select").val()
|
action = $(modalId + " #id_action_select").val()
|
||||||
accessCalendars.rest.create
|
actionsCalendars.rest.create
|
||||||
calendarId: calendar
|
calendarId: calendar
|
||||||
access: access
|
action: action
|
||||||
priority: priority
|
priority: priority
|
||||||
, (data) ->
|
, (data) ->
|
||||||
$(modalId).modal "hide"
|
$(modalId).modal "hide"
|
||||||
@ -45,14 +48,29 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
|||||||
return
|
return
|
||||||
|
|
||||||
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" :-)
|
# Makes form "beautyfull" :-)
|
||||||
gui.tools.applyCustoms modalId
|
gui.tools.applyCustoms modalId
|
||||||
return
|
return
|
||||||
|
|
||||||
return
|
return
|
||||||
|
return
|
||||||
return
|
return
|
||||||
|
|
||||||
onEdit: (value, event, table, refreshFnc) ->
|
onEdit: (value, event, table, refreshFnc) ->
|
||||||
@ -73,7 +91,7 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
|||||||
gui.tools.applyCustoms modalId
|
gui.tools.applyCustoms modalId
|
||||||
return
|
return
|
||||||
api.templates.get "pool_add_access", (tmpl) ->
|
api.templates.get "pool_add_access", (tmpl) ->
|
||||||
accessCalendars.rest.item value.id, (item) ->
|
actionsCalendars.rest.item value.id, (item) ->
|
||||||
api.calendars.overview (data) ->
|
api.calendars.overview (data) ->
|
||||||
gui.doLog "Item: ", item
|
gui.doLog "Item: ", item
|
||||||
modalId = gui.launchModal(gettext("Edit access calendar"), api.templates.evaluate(tmpl,
|
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()
|
priority = $(modalId + " #id_priority").val()
|
||||||
calendar = $(modalId + " #id_calendar_select").val()
|
calendar = $(modalId + " #id_calendar_select").val()
|
||||||
access = $(modalId + " #id_access_select").val()
|
access = $(modalId + " #id_access_select").val()
|
||||||
accessCalendars.rest.save
|
actionsCalendars.rest.save
|
||||||
id: item.id
|
id: item.id
|
||||||
calendarId: calendar
|
calendarId: calendar
|
||||||
access: access
|
access: access
|
||||||
@ -103,7 +121,7 @@ gui.servicesPools.actionsCalendars = (servPool, info) ->
|
|||||||
return
|
return
|
||||||
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]
|
||||||
|
@ -2,15 +2,15 @@
|
|||||||
{% verbatim %}
|
{% verbatim %}
|
||||||
<form class="form-horizontal" role="form">
|
<form class="form-horizontal" role="form">
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="id_priority" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
|
<label for="id_priority" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Priority' %}{% verbatim %}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-9">
|
||||||
<input type="numeric" class="modal_field_data" id="id_priority" value="{{ priority }}">
|
<input type="numeric" class="modal_field_data" id="id_priority" value="{{ priority }}">
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="id_calendar_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
|
<label for="id_calendar_select" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Calendar' %}{% verbatim %}</label>
|
||||||
<div class="col-sm-10">
|
<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%">
|
<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>
|
<option value="-1"></option>
|
||||||
{{# each calendars }}
|
{{# each calendars }}
|
||||||
@ -21,14 +21,37 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="form-group">
|
<div class="form-group">
|
||||||
<label for="id_action_select" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Access action' %}{% verbatim %}</label>
|
<label for="id_offset" class="col-sm-3 control-label">{% endverbatim %}{% trans 'Time Offset (min.)' %}{% verbatim %}</label>
|
||||||
<div class="col-sm-10">
|
<div class="col-sm-9">
|
||||||
<select id="id_access_select" class="selectpicker show-menu-arrow show-tick modal_field_data" data-style="btn-default" data-width="100%">
|
<input type="numeric" class="modal_field_data" id="id_offset" value="{{ eventOffset }}">
|
||||||
{{# each accessList }}
|
</div>
|
||||||
<option value="{{ this }}"{{# ifequals this ../access }} selected{{/ ifequals }}>{{ this }}</option>
|
</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 }}
|
{{/ each }}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div id="parameters">
|
||||||
|
</div>
|
||||||
|
|
||||||
</form>
|
</form>
|
||||||
{% endverbatim %}
|
{% endverbatim %}
|
||||||
|
Loading…
Reference in New Issue
Block a user