Commit f91fd079 by Tomas Hlavacek

Add support for CommonSelectionParameter

There are problems with page size and page loading speed when there
are more routers with several peers and several BGP related commands
because selection commands multiplicate the peer tables in the resulting
javascript placed into the resulting page. This is not effective enough and
therefore sligh rewrite is needed.

Introduce new type of SelectionParameter - CommonSelectionParameter that
has its ID and it is placed to a JS variable in the beginning of the page
or function that uses the values inside only once. Then construction of the
select boxes uses this variables to feed needed values according to the
ID of the content.
parent 8fa1f03e
......@@ -20,53 +20,69 @@
var rs=document.getElementById("routerselect");
var cs=document.getElementById("commandselect");
<py:for each="cp in commonparams.keys()">
var commondict_${cp} = ' \
<py:for each="paridx,partuple in enumerate(commonparams[cp].getOptions())">
<option value="${partuple[0]}"> ${partuple[1]} </option> \
</py:for>
';
</py:for>
<py:for each="ridx,router in enumerate(routers)">
<py:for each="cidx,cmd in enumerate(routers[ridx].listCommands())">
<![CDATA[ if((rs.options[rs.selectedIndex].value==$ridx) && (cs.options[cs.selectedIndex].value==$cidx)) { ]]>
document.getElementById("paramsect").innerHTML=' \
document.getElementById("paramsect").innerHTML=' \
<py:for each="pidx,param in enumerate(routers[ridx].listCommands()[cidx].getParamSpecs())">
<fieldset> \
<label for="param${pidx}"> \
${pidx+3}. ${param.getName()}: \
</label> \
<fieldset> \
<label for="param${pidx}"> \
${pidx+3}. ${param.getName()}: \
</label> \
<py:choose>
<py:when test="param.getType() == 'commonselect'">
<select name="param${pidx}" id="param${pidx}"> \
' + commondict_${param.getID()} + ' \
</select> \
</py:when>
<py:when test="param.getType() == 'select'">
<select name="param${pidx}" id="param${pidx}"> \
<py:for each="paridx,partuple in enumerate(param.getOptions())">
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx and defined('default_params') and partuple[0] == default_params[pidx]">
<option value="${partuple[0]}" selected="selected"> \
${partuple[1]} \
</option> \
</py:when>
<py:when test="partuple[0] == param.getDefault()">
<option value="${partuple[0]}" selected="selected"> \
${partuple[1]} \
</option> \
</py:when>
<py:otherwise>
<option value="${partuple[0]}"> \
${partuple[1]} \
</option> \
</py:otherwise>
</py:choose>
</py:for>
</select> \
<select name="param${pidx}" id="param${pidx}"> \
<py:for each="paridx,partuple in enumerate(param.getOptions())">
<option value="${partuple[0]}"> \
${partuple[1]} \
</option> \
</py:for>
</select> \
</py:when>
<py:otherwise>
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx and defined('default_params') and pidx &lt; len(default_params)">
<input type="text" name="param${pidx}" id="param${pidx}" value="${default_params[pidx]}" onfocus="this.className=\'hover\'" onblur="this.className=\'out\'" /> \
<input type="text" name="param${pidx}" id="param${pidx}" value="${default_params[pidx]}" onfocus="this.className=\'hover\'" onblur="this.className=\'out\'" /> \
</py:when>
<py:otherwise>
<input type="text" name="param${pidx}" id="param${pidx}" value="${param.getDefault()}" onfocus="this.className=\'hover\'" onblur="this.className=\'out\'" /> \
<input type="text" name="param${pidx}" id="param${pidx}" value="${param.getDefault()}" onfocus="this.className=\'hover\'" onblur="this.className=\'out\'" /> \
</py:otherwise>
</py:choose>
</py:otherwise>
</py:choose>
</fieldset> \
</fieldset> \
</py:for>';
<py:for each="pidx,param in enumerate(routers[ridx].listCommands()[cidx].getParamSpecs())">
<py:choose>
<py:when test="(param.getType() == 'select') or (param.getType() == 'commonselect')">
<py:for each="paridx,partuple in enumerate(param.getOptions())">
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx and defined('default_params') and partuple[0] == default_params[pidx]">
document.getElementById("param${pidx}").selectedIndex=${paridx};
</py:when>
<py:when test="partuple[0] == param.getDefault()">
document.getElementById("param${pidx}").selectedIndex=${paridx};
</py:when>
</py:choose>
</py:for>
</py:when>
</py:choose>
</py:for>
}
</py:for>
</py:for>
......@@ -77,14 +93,14 @@
var rs=document.getElementById("routerselect");
<py:for each="ridx,router in enumerate(routers)">
if(rs.options[rs.selectedIndex].value==$ridx) {
document.getElementById("commandselect").innerHTML=' \
document.getElementById("commandselect").innerHTML=' \
<py:for each="cidx,cmd in enumerate(routers[ridx].listCommands())">
<py:choose>
<py:when test="default_routerid == ridx and default_commandid == cidx">
<option value="$cidx" selected="selected">${cmd.getName()}</option> \
<option value="$cidx" selected="selected">${cmd.getName()}</option> \
</py:when>
<py:otherwise>
<option value="$cidx">${cmd.getName()}</option> \
<option value="$cidx">${cmd.getName()}</option> \
</py:otherwise>
</py:choose>
</py:for>';
......
......@@ -28,7 +28,7 @@ import re
import fcntl
import traceback
import urllib
import md5
import hashlib
import time
import random
......@@ -90,7 +90,7 @@ class Session(object):
self.save()
def __genSessionId__(self):
return md5.new(str(time.time())+str(random.randint(1,1000000))).hexdigest()
return hashlib.md5(str(time.time())+str(random.randint(1,1000000))).hexdigest()
def save(self):
try:
......@@ -462,6 +462,16 @@ class ULGCgi:
else:
return defaults.refresh_interval
def getCommonParams(self):
res = {}
for r in config.routers:
for c in r.listCommands():
for ps in c.getParamSpecs():
if(ps.getType() == 'commonselect'):
res[ps.getID()] = ps
return res
def HTTPRedirect(self,url):
return """<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
......@@ -531,6 +541,7 @@ class ULGCgi:
return template.generate(defaults=defaults,
routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=routerid,
default_commandid=commandid,
default_sessionid=sessionid,
......@@ -617,6 +628,7 @@ class ULGCgi:
template = self.loader.load(defaults.index_template_file)
return template.generate(defaults=defaults,
routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=session.getRouterId(),
default_commandid=session.getCommandId(),
default_params=session.getParameters(),
......@@ -639,6 +651,7 @@ class ULGCgi:
return template.generate(defaults=defaults,
routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=0,
default_commandid=0,
default_sessionid=None,
......@@ -657,6 +670,7 @@ class ULGCgi:
return template.generate(defaults=defaults,
routers=config.routers,
commonparams=self.getCommonParams(),
default_routerid=0,
default_commandid=0,
default_sessionid=None,
......
......@@ -301,6 +301,20 @@ class SelectionParameter(TextParameter):
else:
raise Exception("Invalid input encountered: Check did not passed.")
class CommonSelectionParameter(SelectionParameter):
def __init__(self,oid,option_tuples=[],name=defaults.STRING_PARAMETER,default=None):
SelectionParameter.__init__(self,option_tuples,name,default)
self.setID(oid)
def getType(self):
return 'commonselect'
def setID(self,oid):
self.oid = oid
def getID(self):
return self.oid
class TextCommand(object):
def __init__(self,command,param_specs=[],name=None):
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment