Added information for groups

This commit is contained in:
Adolfo Gómez García 2017-01-24 09:56:01 +01:00
parent 4268004fcf
commit 675d502f73
8 changed files with 276 additions and 16 deletions

View File

@ -243,7 +243,7 @@ class Services(DetailHandler): # pylint: disable=too-many-public-methods
'id': i.uuid,
'name': i.name,
'thumb': i.image.thumb64 if i.image is not None else DEFAULT_THUMB_BASE64,
'user_services_count': i.userServices.count(),
'user_services_count': i.userServices.exclude(state__in=(State.REMOVED, State.ERROR)).count(),
'state': _('With errors') if i.isRestrained() else _('Ok'),
})

View File

@ -57,8 +57,17 @@ logger = logging.getLogger(__name__)
# Details of /auth
def getPoolsForGroups(groups):
def getGroupsFromMeta(groups):
for g in groups:
if g.is_meta:
for x in g.groups.all():
yield x
else:
yield g
def getPoolsForGroups(groups):
for g in getGroupsFromMeta(groups):
for servicePool in g.deployedServices.all():
yield servicePool
@ -184,7 +193,7 @@ class Users(DetailHandler):
'id': i.uuid,
'name': i.name,
'thumb': i.image.thumb64 if i.image is not None else DEFAULT_THUMB_BASE64,
'user_services_count': i.userServices.count(),
'user_services_count': i.userServices.exclude(state__in=(State.REMOVED, State.ERROR)).count(),
'state': _('With errors') if i.isRestrained() else _('Ok'),
})
@ -207,7 +216,7 @@ class Users(DetailHandler):
class Groups(DetailHandler):
custom_methods = ['servicesPools']
custom_methods = ['servicesPools', 'users']
def getItems(self, parent, item):
try:
@ -337,8 +346,26 @@ class Groups(DetailHandler):
'id': i.uuid,
'name': i.name,
'thumb': i.image.thumb64 if i.image is not None else DEFAULT_THUMB_BASE64,
'user_services_count': i.userServices.count(),
'user_services_count': i.userServices.exclude(state__in=(State.REMOVED, State.ERROR)).count(),
'state': _('With errors') if i.isRestrained() else _('Ok'),
})
return res
def users(self, parent, item):
uuid = processUuid(item)
group = parent.groups.get(uuid=processUuid(uuid))
groups = getGroupsFromMeta((group,))
res = []
for group in groups:
for i in group.users.all():
res.append({
'id': i.uuid,
'name': i.name,
'real_name': i.real_name,
'state': i.state,
'last_access': i.last_access
})
return res

View File

@ -174,10 +174,8 @@ gui.authenticators.link = (event) ->
id = selected[0].id
type = gui.authenticators.types[selected[0].type]
gui.doLog "Type", type
userAPI = api.authenticators.detail(id, "users", { permission: selected[0].permission })
user = new GuiElement(userAPI, "users")
groupAPI = api.authenticators.detail(id, "groups", { permission: selected[0].permission })
group = new GuiElement(groupAPI, "groups")
user = new GuiElement(api.authenticators.detail(id, "users", { permission: selected[0].permission }), "users")
group = new GuiElement(api.authenticators.detail(id, "groups", { permission: selected[0].permission }), "groups")
grpTable = group.table(
icon: 'groups'
container: "groups-placeholder"
@ -186,6 +184,133 @@ gui.authenticators.link = (event) ->
buttons: [
"new"
"edit"
{
text: gui.tools.iconAndText( 'fa-info', gettext('Information') )
css: "disabled"
disabled: true
click: (vals, value, btn, tbl, refreshFnc) ->
if vals.length > 1
return
val = vals[0]
group.rest.invoke val.id + "/servicesPools", (pools) ->
group.rest.invoke val.id + "/users", (users) ->
group.rest.overview (groups) -> # Get groups
renderDate = gui.tools.renderDate(api.tools.djangoFormat(get_format("SHORT_DATETIME_FORMAT")))
#for _, i in users
# users[i].last_access = renderDate(users[i].last_access)
gui.tools.renderDate(api.tools.djangoFormat(get_format("SHORT_DATETIME_FORMAT")))
gui.doLog "Pools", pools
api.templates.get "group-info", (tmpl) ->
content = api.templates.evaluate(tmpl,
id: 'information',
pools: pools,
users: users,
groups: if val.type == 'meta' then val.groups else null,
meta: val.type == 'meta',
meta_if_any: val.meta_if_any,
groups_all: groups,
goClass: 'goLink'
)
modalId = gui.launchModal(gettext('Group information'), content,
actionButton: " "
)
$('#information-pools-table').DataTable(
colReorder: true
stateSave: true
paging: true
info: false
autoWidth: false
lengthChange: false
pageLength: 10
columnDefs: [
{ 'width': '50%', 'targets': 0 },
{ 'width': '120px', 'targets': 1 },
{ 'width': '40px', 'targets': 2 },
{ 'width': '160px', 'targets': 3 },
]
ordering: true
order: [[ 1, 'asc' ]]
dom: '<>fr<"uds-table"t>ip'
language: gui.config.dataTablesLanguage
)
$('#information-users-table').DataTable(
colReorder: true
stateSave: true
paging: true
info: false
autoWidth: false
lengthChange: false
pageLength: 10
columnDefs: [
{ 'width': '30%', 'targets': 0 },
{ 'width': '30%', 'targets': 1 },
{ 'width': '15%', 'targets': 2 },
{ 'width': '25%', 'targets': 3, 'render': renderDate },
]
ordering: true
order: [[ 1, 'asc' ]]
dom: '<>fr<"uds-table"t>ip'
language: gui.config.dataTablesLanguage
)
$('#information-groups-table').DataTable(
colReorder: true
stateSave: true
paging: true
info: false
autoWidth: false
lengthChange: false
pageLength: 10
columnDefs: [
{ 'width': '40%', 'targets': 0 },
{ 'width': '60%', 'targets': 1 },
]
ordering: true
order: [[ 1, 'asc' ]]
dom: '<>fr<"uds-table"t>ip'
language: gui.config.dataTablesLanguage
)
$('.goLink').on('click', (event) ->
$this = $(this);
event.preventDefault();
gui.lookupUuid = $this.attr('href').substr(1)
$(modalId).modal('hide')
setTimeout( ->
$(".lnk-deployed_services").click();
, 500);
)
return
select: (vals, value, btn, tbl, refreshFnc) ->
unless vals.length == 1
$(btn).addClass("disabled").prop('disabled', true)
return
$(btn).removeClass("disabled").prop('disabled', false)
return
}
"delete"
"xls"
]
@ -305,8 +430,8 @@ gui.authenticators.link = (event) ->
return
val = vals[0]
userAPI.invoke val.id + "/servicesPools", (pools) ->
userAPI.invoke val.id + "/userServices", (userServices) ->
user.rest.invoke val.id + "/servicesPools", (pools) ->
user.rest.invoke val.id + "/userServices", (userServices) ->
user.rest.item val.id, (item) ->
group.rest.overview (groups) -> # Get groups
gui.doLog "Pools", pools

View File

@ -322,8 +322,9 @@ gui.servicesPools.link = (event) ->
$select = $(modalId + " #id_group_select")
$select.empty()
# Sorts groups, expression means that "if a > b returns 1, if b > a returns -1, else returns 0"
maxCL = 32
$.each data, (undefined_, value) ->
$select.append "<option value=\"" + value.id + "\">" + value.name + "</option>"
$select.append "<option value=\"" + value.id + "\">" + value.name + " (" + value.comments.substr(0, maxCL - 1) + ((if value.comments.length > maxCL then "&hellip;" else "")) + ")</option>"
return

View File

@ -192,6 +192,7 @@
{% js_template 'service-info' %}
{% js_template 'authenticators' %}
{% js_template 'user-info' %}
{% js_template 'group-info' %}
{% js_template 'osmanagers' %}
{% js_template 'connectivity' %}
{% js_template 'services_pool' %}

View File

@ -0,0 +1,106 @@
{% load i18n html5 %}
{% verbatim %}
<ul class="nav nav-tabs">
<li class="active in"><a href="#{{ id }}-pools_tab" data-toggle="tab">{% endverbatim %}{% trans 'Services Pools' %}{% verbatim %}</a></li>
<li><a href="#{{ id }}-users_tab" data-toggle="tab">{% endverbatim %}{% trans 'Users' %}{% verbatim %}</a></li>
{{# if meta }}
<li><a href="#{{ id }}-groups_tab" data-toggle="tab">{% endverbatim %}{% trans 'Groups' %}{% verbatim %}</a></li>
{{/ if }}
</ul>
<div class="tab-content">
<div class="tab-pane fade in active" id="{{ id }}-pools_tab">
<div class="row">
<div class="col-xs-12">
<table id="{{ id }}-pools-table" style="width:100%;" class="display">
<thead>
<tr>
<th>{% endverbatim %}{% trans 'Pool' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'State' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'Image' %}{% verbatim %}</th>
<th></th>
</tr>
</thead>
<tbody>
{{#each pools }}
<tr>
<td>{{ name }}<span style="float: right;"><a href="#{{ id }}" class="{{ ../goClass }}"><i class="fa fa-external-link"> </i></a></span></td>
<td>{{ state }}</td>
<td><img src="data:image/png;base64,{{ thumb }}" style="width: 32px; height: auto;"/></td>
<td>{{ user_services_count }}</td>
</tr>
{{/each }}
</tbody>
</table>
</div>
</div>
</div>
<div class="tab-pane fade" id="{{ id }}-users_tab">
<div class="row">
<div class="col-xs-12">
<table id="{{ id }}-users-table" style="width:100%;" class="display">
<thead>
<tr>
<th>{% endverbatim %}{% trans 'Name' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'Real Name' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'State' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'Last Access' %}{% verbatim %}</th>
</tr>
</thead>
<tbody>
{{#each users }}
<tr>
<td>{{ name }}</td>
<td>{{ real_name }}</td>
<td>
{{# ifequals state 'A'}}{% endverbatim %}{% trans 'Enabled' %}{% verbatim %}{{/ ifequals }}
{{# ifequals state 'I'}}{% endverbatim %}{% trans 'Disabled' %}{% verbatim %}{{/ ifequals }}
{{# ifequals state 'B'}}{% endverbatim %}{% trans 'Blocked' %}{% verbatim %}{{/ ifequals }}
</td>
<td>{{{ last_access }}}</td>
</tr>
{{/each }}
</tbody>
</table>
</div>
</div>
</div>
{{#if meta }}
<div class="tab-pane fade" id="{{ id }}-groups_tab">
<div class="row">
<div class="col-xs-12">
<label for="id_matchifany" class="col-sm-2 control-label">{% endverbatim %}{% trans 'Match mode' %}{% verbatim %}</label>
<div class="col-sm-10">
{{# if meta_if_any}}
{% endverbatim %}{% trans 'Any' %}{% verbatim %}
{{ else }}
{% endverbatim %}{% trans 'All' %}{% verbatim %}
{{/if }}
</div>
</div>
</div>
<div class="row">
<div class="col-xs-12">
<table id="{{ id }}-groups-table" style="width:100%;" class="display">
<thead>
<tr>
<th>{% endverbatim %}{% trans 'Name' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'Comment' %}{% verbatim %}</th>
</tr>
</thead>
<tbody>
{{#each groups_all }}
{{# ifbelongs id ../groups }}
<tr>
<td>{{ name }}</td>
<td>{{ comments }}</td>
</tr>
{{/ ifbelongs}}
{{/each }}
</tbody>
</table>
</div>
</div>
</div>
{{/if }}
</div>
{% endverbatim %}

View File

@ -1,8 +1,8 @@
{% load i18n html5 %}
{% verbatim %}
<ul class="nav nav-tabs">
<li class="active in"><a href="#{{ id }}-overview_tab" data-toggle="tab">{% endverbatim %}{% trans 'Overview' %}{% verbatim %}</a></li>
<li><a href="#{{ id }}-pools_tab" data-toggle="tab">{% endverbatim %}{% trans 'Services Pools' %}{% verbatim %}</a></li>
<!-- <li class="active in"><a href="#{{ id }}-overview_tab" data-toggle="tab">{% endverbatim %}{% trans 'Overview' %}{% verbatim %}</a></li> -->
<li class="active in"><a href="#{{ id }}-pools_tab" data-toggle="tab">{% endverbatim %}{% trans 'Services Pools' %}{% verbatim %}</a></li>
<li><a href="#{{ id }}-logs_tab" data-toggle="tab">{% endverbatim %}{% trans 'Logs' %}{% verbatim %}</a></li>
</ul>
<div class="tab-content">
@ -21,7 +21,7 @@
<th>{% endverbatim %}{% trans 'Pool' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'State' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'Image' %}{% verbatim %}</th>
<th></th>
<th>{% endverbatim %}{% trans 'User Services' %}{% verbatim %}</th>
</tr>
</thead>
<tbody>

View File

@ -37,7 +37,7 @@
<th>{% endverbatim %}{% trans 'Pool' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'State' %}{% verbatim %}</th>
<th>{% endverbatim %}{% trans 'Image' %}{% verbatim %}</th>
<th></th>
<th>{% endverbatim %}{% trans 'User Services' %}{% verbatim %}</th>
</tr>
</thead>
<tbody>