Browse Source

implement rendering the server overview in JS to allow dynamically rendering it in the server list

Natenom/support-murmur-13-1446181288462
Michael Ziegler 15 years ago
parent
commit
a66e932dd1
  1. 32
      htdocs/js/rendermumbleserver.js
  2. 8
      pyweb/mumble/models.py
  3. 12
      pyweb/mumble/templates/mumble/list.html
  4. 9
      pyweb/mumble/templates/mumble/mumble.html
  5. 19
      pyweb/mumble/views.py

32
htdocs/js/rendermumbleserver.js

@ -0,0 +1,32 @@
function renderserverinfos( server ){
var buf = [];
if( server.connecturl ){
buf.push( String.format( '{0}: <a href="{1}">{1}</a>', gettext("Server Address"), server.connecturl ) );
}
if( server.url ){
buf.push( String.format( '{0}: {1}', gettext("Website"), server.url ) );
}
buf.push( interpolate( "This server is running Murmur version %s.", [server.prettyversion] ) );
buf.push( interpolate(
ngettext( "Currently, %s user is registered.", "Currently, %s users are registered.", server.users_regged ),
[server.users_regged] ) );
buf.push( interpolate(
ngettext( "Currently, %s user is online.", "Currently, %s users are online.", server.users_online ),
[server.users_online] ) );
buf.push( interpolate(
ngettext( "Currently, there is %s channel.", "Currently, there are %s channels.", server.channel_cnt ),
[server.channel_cnt] ) );
if( server.uptime ){
buf.push( interpolate( "This server is running since %s.", [server.upsince] ) );
}
buf.push( String.format( '<a href="{0}">{1}</a>', server.minurl, gettext( "Switch to minimal view" ) ) );
res = ['<div class="mumble-ext" id="serverstuffz">', '<ul>'];
for( var i = 0; i < buf.length; i++ )
res.push( '<li>'+buf[i]+'</li>' );
res.push( '</ul><br /><br />' );
res.push( String.format( '<b>{0}:</b><br />', gettext("Welcome message") ) );
res.push( String.format( '<div style="padding: 10px">{0}</div>', server.motd ) );
res.push( '</div>' );
return res.join('');
}

8
pyweb/mumble/models.py

@ -16,6 +16,8 @@
""" """
import re import re
import datetime
from time import time
from sys import stderr from sys import stderr
from urllib import urlopen from urllib import urlopen
from StringIO import StringIO from StringIO import StringIO
@ -293,9 +295,11 @@ class Mumble( models.Model ):
users_online = property( lambda self: len(self.ctl.getPlayers(self.srvid)), doc="Number of online users." ) users_online = property( lambda self: len(self.ctl.getPlayers(self.srvid)), doc="Number of online users." )
channel_cnt = property( lambda self: len(self.ctl.getChannels(self.srvid)), doc="Number of channels." ) channel_cnt = property( lambda self: len(self.ctl.getChannels(self.srvid)), doc="Number of channels." )
is_public = property( lambda self: not self.passwd, is_public = property( lambda self: not self.passwd,
doc="False if a password is needed to join this server." )
doc="False if a password is needed to join this server." )
uptime = property( lambda self: self.ctl.getUptime(self.srvid), uptime = property( lambda self: self.ctl.getUptime(self.srvid),
doc="Number of seconds this instance has been running." )
doc="Number of seconds this instance has been running." )
upsince = property( lambda self: datetime.datetime.fromtimestamp( float( time() - self.uptime ) ),
doc="Datetime since when the server is running." )
is_server = True is_server = True
is_channel = False is_channel = False

12
pyweb/mumble/templates/mumble/list.html

@ -9,6 +9,7 @@
{% block HeadTag %} {% block HeadTag %}
<script type="text/javascript" src="/jsi18n/"></script> <script type="text/javascript" src="/jsi18n/"></script>
<script type="text/javascript" src="/mumble/api/api.js"></script> <script type="text/javascript" src="/mumble/api/api.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/rendermumbleserver.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/buttoniframewindow.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/buttoniframewindow.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/loginout_buttons.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/loginout_buttons.js"></script>
<script type="text/javascript"> <script type="text/javascript">
@ -67,14 +68,9 @@
selectionchange: function(listview, nodes){ selectionchange: function(listview, nodes){
selectedstuff = listview.getSelectedRecords(); selectedstuff = listview.getSelectedRecords();
MumbleList.serverinfo( selectedstuff[0].data.id, function(provider, response){ MumbleList.serverinfo( selectedstuff[0].data.id, function(provider, response){
mainpanel.descrippanel.el.dom.innerHTML = String.format(
"<ul><li>Serveradresse: {0}</li><li>Version: {1}</li></ul>"+
"<br /><fieldset><legend>Willkommensnachricht</legend>{2}</fieldset>",
response.result.connurl,
response.result.version,
response.result.motd
);
});
var info = renderserverinfos(response.result);
mainpanel.descrippanel.el.dom.children[1].children[0].innerHTML = info;
});
} }
}, },
}, { }, {

9
pyweb/mumble/templates/mumble/mumble.html

@ -12,6 +12,7 @@
<script type="text/javascript" src="/mumble/forms/api.js"></script> <script type="text/javascript" src="/mumble/forms/api.js"></script>
<script type="text/javascript" src="/mumble/forms/{{ RegForm|lower }}.js"></script> <script type="text/javascript" src="/mumble/forms/{{ RegForm|lower }}.js"></script>
<script type="text/javascript" src="/mumble/forms/mumbleform.js"></script> <script type="text/javascript" src="/mumble/forms/mumbleform.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/rendermumbleserver.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/channelviewer.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/channelviewer.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/usereditor.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/usereditor.js"></script>
<script type="text/javascript" src="{{ MEDIA_URL }}/js/logviewer.js"></script> <script type="text/javascript" src="{{ MEDIA_URL }}/js/logviewer.js"></script>
@ -64,13 +65,7 @@
activeTab: 0, activeTab: 0,
items: [{ items: [{
title: gettext("Server info"), title: gettext("Server info"),
html: String.format(
"<ul><li>Serveradresse: {0}</li><li>Version: {1}</li></ul>"+
"<br /><fieldset><legend>Willkommensnachricht</legend>{2}</fieldset>",
"{{ MumbleServer.connecturl }}",
"{{ MumbleServer.prettyversion }}",
"{{ MumbleServer.motd }}"
),
html: renderserverinfos( {{ ServerDict|safe }} ),
}, { }, {
title: gettext("Registration"), title: gettext("Registration"),
xtype: "{{ RegForm|lower }}", xtype: "{{ RegForm|lower }}",

19
pyweb/mumble/views.py

@ -116,12 +116,20 @@ def servers( request ):
@EXT_DIRECT_PROVIDER.register_method( "MumbleList" ) @EXT_DIRECT_PROVIDER.register_method( "MumbleList" )
def serverinfo( request, server ): def serverinfo( request, server ):
srv = Mumble.objects.get( id=int(server) ) srv = Mumble.objects.get( id=int(server) )
# users_regged users_online channel_cnt uptime upsince minurl
return { return {
'id': srv.id,
'name': srv.name,
'motd': srv.motd,
'connurl': srv.connecturl,
'version': srv.prettyversion
'id': srv.id,
'name': srv.name,
'motd': srv.motd,
'connecturl': srv.connecturl,
'prettyversion': srv.prettyversion,
'url': srv.url,
'users_regged': srv.users_regged,
'users_online': srv.users_online,
'channel_cnt': srv.channel_cnt,
'uptime': srv.uptime,
'upsince': unicode(srv.upsince),
'minurl': reverse( mobile_show, args=(server,) )
} }
@EXT_DIRECT_PROVIDER.register_method( "MumbleList" ) @EXT_DIRECT_PROVIDER.register_method( "MumbleList" )
@ -170,6 +178,7 @@ def show( request, server ):
return render_to_response( 'mumble/mumble.html', { return render_to_response( 'mumble/mumble.html', {
'MumbleServer': srv, 'MumbleServer': srv,
'ServerDict': simplejson.dumps(serverinfo(request, server)),
'RegForm': regformname, 'RegForm': regformname,
'MumbleActive': True, 'MumbleActive': True,
'MumbleAccount':user, 'MumbleAccount':user,

Loading…
Cancel
Save