Updating dashboard to include accounts & proxy

This commit is contained in:
Adolfo Gómez García 2017-01-30 08:17:56 +01:00
parent 9b0e1eb7ce
commit a601220771
10 changed files with 59 additions and 73 deletions

View File

@ -58,7 +58,7 @@ class Accounts(ModelHandler):
table_title = _('Accounts') table_title = _('Accounts')
table_fields = [ table_fields = [
{'name': {'title': _('Name'), 'visible': True, 'type': 'iconType'}}, {'name': {'title': _('Name'), 'visible': True}},
{'comments': {'title': _('Comments')}}, {'comments': {'title': _('Comments')}},
{'tags': {'title': _('tags'), 'visible': False}}, {'tags': {'title': _('tags'), 'visible': False}},
] ]

View File

@ -66,15 +66,14 @@ class AccountsUsage(DetailHandler): # pylint: disable=too-many-public-methods
:param full: If full is requested, add "extra" fields to complete information :param full: If full is requested, add "extra" fields to complete information
''' '''
retVal = { retVal = {
'id': item.uuid, 'uuid': item.uuid,
'name': item.name, 'pool_uuid': item.pool_uuid,
'comments': item.comments, 'pool_name': item.pool_name,
'user_uuid': item.user_uuid,
'user_name': item.user_name,
'start': item.start, 'start': item.start,
'end': item.end, 'end': item.end,
'frequency': item.frequency, 'running': item.user_service is not None,
'interval': item.interval,
'duration': item.duration,
'duration_unit': item.duration_unit,
'permission': perm 'permission': perm
} }
@ -85,64 +84,35 @@ class AccountsUsage(DetailHandler): # pylint: disable=too-many-public-methods
perm = permissions.getEffectivePermission(self._user, parent) perm = permissions.getEffectivePermission(self._user, parent)
try: try:
if item is None: if item is None:
return [CalendarRules.usageToDict(k, perm) for k in parent.rules.all()] return [AccountsUsage.usageToDict(k, perm) for k in parent.usages.all()]
else: else:
k = parent.rules.get(uuid=processUuid(item)) k = parent.usages.get(uuid=processUuid(item))
return CalendarRules.usageToDict(k, perm) return AccountsUsage.usageToDict(k, perm)
except Exception: except Exception:
logger.exception('itemId {}'.format(item)) logger.exception('itemId {}'.format(item))
self.invalidItemException() self.invalidItemException()
def getFields(self, parent): def getFields(self, parent):
return [ return [
{'name': {'title': _('Rule name')}}, {'pool_name': {'title': _('Pool name')}},
{'user_name': {'title': _('User name')}},
{'running': {'title': _('Running')}},
{'start': {'title': _('Starts'), 'type': 'datetime'}}, {'start': {'title': _('Starts'), 'type': 'datetime'}},
{'end': {'title': _('Ends'), 'type': 'date'}}, {'end': {'title': _('Ends'), 'type': 'datetime'}},
{'frequency': {'title': _('Repeats'), 'type': 'dict', 'dict': dict((v[0], six.text_type(v[1])) for v in freqs) }},
{'interval': {'title': _('Every'), 'type': 'callback'}},
{'duration': {'title': _('Duration'), 'type': 'callback'}},
{'comments': {'title': _('Comments')}},
] ]
def getRowStyle(self, parent):
return {'field': 'running', 'prefix': 'row-running-'}
def saveItem(self, parent, item): def saveItem(self, parent, item):
# Extract item db fields raise RequestError('Accounts usage cannot be edited')
# We need this fields for all
logger.debug('Saving rule {0} / {1}'.format(parent, item))
fields = self.readFieldsFromParams(['name', 'comments', 'frequency', 'start', 'end', 'interval', 'duration', 'duration_unit'])
if int(fields['interval']) < 1:
self.invalidItemException('Repeat must be greater than zero')
# Convert timestamps to datetimes
fields['start'] = datetime.datetime.fromtimestamp(fields['start'])
if fields['end'] != None:
fields['end'] = datetime.datetime.fromtimestamp(fields['end'])
calRule = None
try:
if item is None: # Create new
calRule = parent.rules.create(**fields)
else:
calRule = parent.rules.get(uuid=processUuid(item))
calRule.__dict__.update(fields)
calRule.save()
except CalendarRule.DoesNotExist:
self.invalidItemException()
except IntegrityError: # Duplicate key probably
raise RequestError(_('Element already exists (duplicate key error)'))
except Exception as e:
logger.exception('Saving calendar')
raise RequestError('incorrect invocation to PUT: {0}'.format(e))
return self.getItems(parent, calRule.uuid)
def deleteItem(self, parent, item): def deleteItem(self, parent, item):
logger.debug('Deleting rule {} from {}'.format(item, parent)) logger.debug('Deleting account usage {} from {}'.format(item, parent))
try: try:
calRule = parent.rules.get(uuid=processUuid(item)) usage = parent.usages.get(uuid=processUuid(item))
calRule.calendar.modified = getSqlDatetime() usage.delete()
calRule.calendar.save()
calRule.delete()
except Exception: except Exception:
logger.exception('Exception') logger.exception('Exception')
self.invalidItemException() self.invalidItemException()
@ -151,6 +121,6 @@ class AccountsUsage(DetailHandler): # pylint: disable=too-many-public-methods
def getTitle(self, parent): def getTitle(self, parent):
try: try:
return _('Rules of {0}').format(parent.name) return _('Usages of {0}').format(parent.name)
except Exception: except Exception:
return _('Current rules') return _('Current usages')

View File

@ -48,7 +48,7 @@ import logging
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
__updated__ = '2016-09-16' __updated__ = '2017-01-30'
@python_2_unicode_compatible @python_2_unicode_compatible
@ -90,7 +90,7 @@ class User(UUIDModel):
@property @property
def pretty_name(self): def pretty_name(self):
return self.manager.name + '@' + self.name return self.name + '@' + self.manager.name
def getManager(self): def getManager(self):
''' '''

File diff suppressed because one or more lines are too long

View File

@ -3,6 +3,8 @@ gui.accounts = new GuiElement(api.accounts, "accounts")
gui.accounts.link = (event) -> gui.accounts.link = (event) ->
"use strict" "use strict"
useTable = undefined useTable = undefined
clearUsage = -> clearUsage = ->
if useTable if useTable
@ -36,20 +38,26 @@ gui.accounts.link = (event) ->
$("#detail-placeholder").removeClass "hidden" $("#detail-placeholder").removeClass "hidden"
# gui.tools.blockUI() # gui.tools.blockUI()
id = selected[0].id id = selected[0].id
usage = new GuiElement(api.accounts.detail(id, "usage", { permission: selected[0].permission }), "rules") usage = new GuiElement(api.accounts.detail(id, "usage", { permission: selected[0].permission }), "Usage")
usageTable = usage.table( usageTable = usage.table(
icon: 'calendars' icon: 'accounts'
container: "usage-placeholder" container: "usage-placeholder"
rowSelect: "single" rowSelect: "single"
buttons: [ buttons: [
"new"
"edit"
"delete" "delete"
"xls" "xls"
] ]
onLoad: (k) -> onLoad: (k) ->
# gui.tools.unblockUI() # gui.tools.unblockUI()
return # null return return # null return
onData: (data) ->
gui.doLog 'Accounts data received'
$.each data, (index, value) ->
value.running = if value.running then gettext('Yes') else gettext('No')
return
return
) )
return return
@ -63,8 +71,8 @@ gui.accounts.link = (event) ->
"xls" "xls"
"permissions" "permissions"
] ]
onNew: gui.methods.typedNew(gui.calendars, gettext("New calendar"), gettext("Calendar creation error")) onNew: gui.methods.typedNew(gui.accounts, gettext("New Account"), gettext("Account creation error"))
onEdit: gui.methods.typedEdit(gui.calendars, gettext("Edit calendar"), gettext("Calendar saving error")) onEdit: gui.methods.typedEdit(gui.accounts, gettext("Edit Account"), gettext("Account saving error"))
onDelete: gui.methods.del(gui.calendars, gettext("Delete calendar"), gettext("Calendar deletion error")) onDelete: gui.methods.del(gui.accounts, gettext("Delete Account"), gettext("Account deletion error"))
false false
false false

View File

@ -231,6 +231,11 @@
exec: gui.sPoolGroups.link exec: gui.sPoolGroups.link
cleanup: true cleanup: true
} }
{
id: "lnk-accounts"
exec: gui.accounts.link
cleanup: true
}
] ]
$.each sidebarLinks, (index, value) -> $.each sidebarLinks, (index, value) ->
gui.doLog "Adding " + value.id gui.doLog "Adding " + value.id

View File

@ -26,21 +26,20 @@
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/connectivity.png"/> <span class="menu-lnk">{% trans 'Connectivity' %} <b class="caret"></b></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/connectivity.png"/> <span class="menu-lnk">{% trans 'Connectivity' %} <b class="caret"></b></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="lnk-connectivity" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/transports.png"/> <span class="menu-lnk">{% trans 'Transports' %}</span></a></li> <li><a class="lnk-connectivity" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/transports.png"/> <span class="menu-lnk">{% trans 'Transports' %}</span></a></li>
<li><a class="lnk-connectivity" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/proxy.png"/> <span class="menu-lnk">{% trans 'Proxies' %}</span></a></li> <li><a class="lnk-proxy" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/proxy.png"/> <span class="menu-lnk">{% trans 'Proxies' %}</span></a></li>
</ul> </ul>
</li> </li>
<li><a class="lnk-deployed_services" href=""><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/pools.png"/> <span class="menu-lnk">{% trans 'Service Pools' %}</span></a></li>
<li class="dropdown"> <li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/miscellaneous.png"/> <span class="menu-lnk">{% trans 'Pools Config' %} <b class="caret"></b></span></a> <a href="#" class="dropdown-toggle" data-toggle="dropdown"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/miscellaneous.png"/> <span class="menu-lnk">{% trans 'Pools' %} <b class="caret"></b></span></a>
<ul class="dropdown-menu"> <ul class="dropdown-menu">
<li><a class="lnk-deployed_services" href=""><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/pools.png"/> <span class="menu-lnk">{% trans 'Service Pools' %}</span></a></li>
{% if admin %} {% if admin %}
<li><a class="lnk-spoolsgroup" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/groups.png"/> <span class="menu-lnk">{% trans 'Groups' %}</span></a></li> <li><a class="lnk-spoolsgroup" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/groups.png"/> <span class="menu-lnk">{% trans 'Groups' %}</span></a></li>
<li><a class="lnk-gallery" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/gallery.png"/> <span class="menu-lnk">{% trans 'Gallery' %}</span></a></li> <li><a class="lnk-gallery" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/gallery.png"/> <span class="menu-lnk">{% trans 'Gallery' %}</span></a></li>
{% endif %} {% endif %}
<li><a class="lnk-calendars" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/calendars.png"/> <span class="menu-lnk">{% trans 'Calendars' %}</span></a></li> <li><a class="lnk-calendars" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/calendars.png"/> <span class="menu-lnk">{% trans 'Calendars' %}</span></a></li>
<li><a class="lnk-accounts" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/miscellaneous.png"/> <span class="menu-lnk">{% trans 'Accounts' %}</span></a></li> <li><a class="lnk-accounts" href="#"><img class="icon" src="{{ STATIC_URL }}/adm/img/icons/accounts.png"/> <span class="menu-lnk">{% trans 'Accounts' %}</span></a></li>
</ul> </ul>
</li> </li>

View File

@ -23,7 +23,7 @@
<div id="detail-placeholder" class="row hidden"> <div id="detail-placeholder" class="row hidden">
<div class="col-xs-12"> <div class="col-xs-12">
<ul class="bottom_tabs nav nav-tabs"> <ul class="bottom_tabs nav nav-tabs">
<li class="active"><a href="#{{ usage }}_tab" data-toggle="tab">{% endverbatim %}{% trans 'Rules' %}{% verbatim %}</a></li> <li class="active"><a href="#{{ usage }}_tab" data-toggle="tab">{% endverbatim %}{% trans 'Usage' %}{% verbatim %}</a></li>
</ul> </ul>
<div class="tab-content"> <div class="tab-content">
<div class="tab-pane fade in active" id="{{ usage }}_tab"> <div class="tab-pane fade in active" id="{{ usage }}_tab">

View File

@ -70,17 +70,20 @@ This states displays as default
} }
.row-state-S { .row-state-S {
color: gray; color: gray;
}
.row-running-Yes {
color: green;
} }
@media (max-width: 768px) { @media (max-width: 768px) {
.label-tbl-button { .label-tbl-button {
display: none; display: none;
} }
.uds-table { .uds-table {
min-height: 0px; min-height: 0px;
} }
} }

View File

@ -1,2 +1,3 @@
#!/bin/sh #!/bin/sh
grunt build
cp dist/css/main.css ../../src/uds/static/adm/css/uds.css cp dist/css/main.css ../../src/uds/static/adm/css/uds.css