CMS 3D CMS Logo

List of all members | Public Member Functions | Private Member Functions
cfg-viewer.html Class Reference

Public Member Functions

def __init__ (self, name, js, items, theDir, helperDir, pN, pFN)
 

Private Member Functions

def _css (self, css, cssLocal)
 
def _items (self, items)
 
def _jqueryFile (self, name, pN, pFN)
 
def _printHtml (self, name, scrip, css, items, search)
 
def _scripts (self, js)
 
def _searchitems (self, items)
 

Detailed Description

Definition at line 632 of file cfg-viewer.py.

Constructor & Destructor Documentation

def cfg-viewer.html.__init__ (   self,
  name,
  js,
  items,
  theDir,
  helperDir,
  pN,
  pFN 
)

Definition at line 633 of file cfg-viewer.py.

References cfg-viewer.html._css(), SequenceTypes._BooleanLogicExpression._items, cfg-viewer.html._items(), cfg-viewer.html._jqueryFile(), cfg-viewer.html._printHtml(), Vispa.Gui.FindDialog.FindDialog._scripts, cfg-viewer.html._scripts(), and cfg-viewer.html._searchitems().

633  def __init__(self,name,js,items,theDir, helperDir, pN,pFN):
634  jqName = "%scfgJS.js"%(theDir)
635  jqLocal = "%scfgJS.js"%(helperDir)
636  css = "%sstyle.css"%(theDir)
637  cssL = "%sstyle.css"%(helperDir)
638  js.insert(0,jqLocal)
639  self._jqueryFile(jqName, pN,pFN)
640  self._printHtml(name,self._scripts(js),self._css(css, cssL),
641  self._items(items), self._searchitems(items))
642 
def _scripts(self, js)
Definition: cfg-viewer.py:643
def _css(self, css, cssLocal)
Definition: cfg-viewer.py:702
def _searchitems(self, items)
Definition: cfg-viewer.py:655
def _items(self, items)
Definition: cfg-viewer.py:648
def _jqueryFile(self, name, pN, pFN)
Definition: cfg-viewer.py:744
def __init__(self, name, js, items, theDir, helperDir, pN, pFN)
Definition: cfg-viewer.py:633
def _printHtml(self, name, scrip, css, items, search)
Definition: cfg-viewer.py:660

Member Function Documentation

def cfg-viewer.html._css (   self,
  css,
  cssLocal 
)
private

Definition at line 702 of file cfg-viewer.py.

Referenced by cfg-viewer.html.__init__().

702  def _css(self, css, cssLocal):
703  with open(css, 'w') as cssfile:
704  cssfile.write("""
705 *{\n font-family:"Lucida Grande", Tahoma, Arial, Verdana, sans-serif;\n}
706 .topBox{\n opacity:0.9;\n background-color:#dfdfdf;\n}\n.topSpec{
707  position:fixed;\n top:0;\n left:0;\n width:100%;\n height:2.5em;
708  border-radius:.9em;\n}\n.hideTopBox, .showTopBox{\n position:absolute;
709  top:2.5em;\n right:2%;\n width:auto;\n height:auto;\n padding: 0.2em;
710  font-weight:bold;\n cursor:pointer;\n border-radius:.3em;\n}\n.negative{
711  position:absolute;\n right:0;\n text-decoration:none;
712  font-weight:bold;\n color:#565656;\n}\n#mode{\n position:absolute;
713  right:50%; \n color:#808080;\n font-size:12pt;\n}\n#editMode,#normalMode{
714  position:absolute;\n left:.3em;\n top:.5em;\n}\n#save{
715  position:absolute;\n top:.5em;\n}\n.helpLinks{\n position:absolute;
716  right:1.3em;\n width:6.2em;\n text-align:right;\n}
717 /* divs for the Pick and Search boxes.*/\n.outerBox{\n width:100%;
718  overflow:hidden;\n}\n.boxTitle{\n float:left;\n margin-left:.6em;
719  color:#A9A9A9;\n}\n.dottedBorder{\n width:25em;\n height:4em;
720  border:.1em dashed #A9A9A9;\n padding:.6em;\n}\n/* -- */
721 /* Right scroll box. */\n.rightScroll{\n position:fixed;\n bottom:50%;
722  right:0; \n width:6.2em;\n text-align:right;\n border:.1em solid #A9A9A9;
723  opacity:0.4;\n background-color:#F0FFF0;\n}\n#hide{\n cursor:default;
724  opacity:0.2;\n}\nli{\n padding-left:.8em;\n}\nul{\n list-style-type:none;
725  padding-left:.1em;\n}\n/* Icons before list items. */\n.expand:before{
726  content:'›';\n}\n.expanded:before{\n content:'ˇ';\n}
727 .expand:before,.expanded:before{\n float:left;\n margin-right:.6em;\n}
728 .expand,.expanded{\n cursor:pointer;\n}\n/* colours of each. */
729 .Path,.EndPath{\n color:#192B33;\n}\n.Modules{ \n color:#800080;\n}
730 .SequenceTypes{\n color:#0191C8\n}\n.paramInner,.Types{\n color:#4B4B81;\n}
731 .param{\n color:#9999CC;\n margin-left:.8em;\n cursor:default; \n}\n.value{
732  color:#0000FF;\n}\n.type{\n color:#00CCFF;\n}
733 /* Header for what's showing */\n#current{\n color:#808080;\n font-size:12pt;
734  text-decoration:underline; \n}\n/* help settings */\n#help{
735  position:absolute;\n display:none;\n background:#ccc;\n border:.1em solid;
736  width:19em;\n right:15em;\n top:1.2em;\n}\nh5{\n font-style:normal;
737  text-decoration:underline; \n margin:0;\n font-size:9pt;\n}\nh6{
738  margin:0;\n color:#666666;\n}\n#attachParams{\n color:#192B33;\n}\nem{
739  color:#FFA500;\n}\n.cellEdit{\n border:.1em dotted #A9A9A9;\n cursor: text;
740 }\n""")
741  return """<link href="%s" rel="stylesheet" \
742  type="text/css"/>"""%(cssLocal)
743 
def _css(self, css, cssLocal)
Definition: cfg-viewer.py:702
def cfg-viewer.html._items (   self,
  items 
)
private

Definition at line 648 of file cfg-viewer.py.

References join().

Referenced by cfg-viewer.html.__init__().

648  def _items(self, items):
649  l= """
650 <option value=%(n)s data-base="%(d)s" data-files="%(f)s"> %(n)s</option>"""
651  s= [l%({"n":x,"f":y["data-files"],"d":y["data-base"]})
652  for x,y in items.iteritems()]
653  return " ".join(s)
654 
def _items(self, items)
Definition: cfg-viewer.py:648
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def cfg-viewer.html._jqueryFile (   self,
  name,
  pN,
  pFN 
)
private

Definition at line 744 of file cfg-viewer.py.

Referenced by cfg-viewer.html.__init__().

744  def _jqueryFile(self,name, pN,pFN):
745  with open(name, 'w')as jq:
746  jq.write("""
747 \n$(document).ready(function(){ \n//Object used to get all details
748 var processName="%s";\nvar processFileName ="%s";
749 var CURRENT_OBJ;\nvar searchShowing= false;\nvar showParams = false
750 var alreadyShowing = false\nvar topClass = "Top"\nvar searching = false
751 var expandDisable = false;\nvar hideVisible=false //nothing is expanded.
752 // ---\n/*\n Functions used to abstract away name of function calls
753  on the object (CURRENT_OBJ).
754  (i.e. so function names can easily be changed.)\n*/
755 function baseParams(inputs){\n return CURRENT_OBJ.getParameters(inputs);\n}
756 function baseInnerParams(inputs, index){
757  return CURRENT_OBJ.getInnerParams(inputs, index);\n}
758 function baseType(inputs){\n return CURRENT_OBJ.getType(inputs);\n}
759 function baseFile(inputs){\n return CURRENT_OBJ.getFile(inputs);\n}
760 function baseTopFile(inputs){\n return CURRENT_OBJ.getTopFile(inputs);\n}
761 // --- Show some inital data operations ---\n/*\n Show something new!\n*/
762 $(document).on('click', '#docSubmit', function(e){
763  var $elem = $('#showType :selected')
764  //get the function we want and the lists\n setCURRENT_OBJ($elem)\n
765  addData($elem.attr("value"), CURRENT_OBJ.getKeys());\n searchShowing= false;
766 });\n/*\n Add data to the html.\n*/
767 function addData(docType, data, dataNames){
768  $("#editMode").removeAttr("disabled"); \n var dataNames = dataNames || data;
769  if(alreadyShowing){\n //need to click cancel if its active.
770  goNormal($("#normalMode"));\n if(!searching)$("#searchCount").html("")
771  invisibleHide()\n paramOptions(false)
772  $(document.getElementsByTagName('body')).children('ul').remove();\n }
773  $("#current").html(docType)\n var gen = getGenericType(docType)
774  var ty = docType\n if(gen != undefined){\n var gL = gen.toLowerCase()
775  if(gL=="modules"||gL=="types") var ty= gen;\n }
776  var $LI = $(document.createElement('li')
777  ).addClass("expand").addClass(ty).addClass(topClass);
778  docType= docType.toLowerCase()\n var showTypes = false\n showParams = true
779  switch(docType){\n case "producer":\n case "consumer":
780  showParams = false\n paramOptions(true)
781  $LI.addClass("Modules")\n showTypes = true\n break;
782  case "modules":\n $LI.addClass("Modules")\n showTypes = true
783  //showParams = true\n break;\n }
784  var $UL = addTopData(data,$LI,showTypes,dataNames)\n alreadyShowing = true;
785  $UL.appendTo('#attachParams');\n}\n/*
786  Used to add the top level data to html.\n*/
787 function addTopData(data,$LI,types,dataName){
788  var dataName = dataName || data;
789  var $UL = $(document.createElement('ul'));\n var doNormalFile = false;
790  var files = document.getElementById("ShowFiles").checked\n if(files){
791  try{\n baseTopFile(dataName[0])\n }\n catch(e){
792  doNormalFile = true;\n }\n }\n for(var i=0; i < data.length;i++){
793  var n = dataName[i]\n var t = data[i];
794  if(types)t += " ("+baseType(n)+")"\n if(files){
795  if(doNormalFile)var file = baseFile(n)
796  else var file = baseTopFile(n)\n t += " ("+file+")"}
797  $UL.append($LI.clone().attr("data-name",n).html(t));\n }\n return $UL;\n}
798 // --- end of inital showing data operations ---\n
799 // --- search operations ---\n
800 //$(document).on('click', "[name='searchTerm1']", function(e){
801 //$(document).on('click', "#searchType option", function(e){
802 $(document).on('click', '#searchType', function(e){\n $("#addSearch").empty()
803  var tname= $(this).text().toLowerCase();\n var sel= jQuery('<select/>', {
804  id:"searchType2"\n })
805  var li = (tname =="modules"|| tname == "producer"|| tname == "consumer")?
806  ["Name", "Type", "File"]: ["Name", "File"]\n for(var i in li){
807  var x = li[i]\n jQuery('<option/>',{\n value:x,\n text:x
808  }).appendTo(sel)\n }\n sel.appendTo("#addSearch");\n});\n/*
809  Current search only searches for top level things.\n*/
810 $(document).on('click','#search', function(e){\n searching = true
811  var first = $('#searchType :selected')\n if(first.length ==0){
812  window.alert("Please chose a search type."); \n return;\n }
813  var doc = first.text()\n var searchTerm = $('#searchWord').val()
814  var $elem = $('option[value="'+doc+'"]')\n setCURRENT_OBJ($elem)
815  var reg = new RegExp(searchTerm, 'g')
816  if($('#rmHilight').prop('checked'))\n var fin = searchTerm\n else
817  var fin = "<em>"+searchTerm+"</em>"
818  switch($('#searchType2 :selected').text()){\n case "File":
819  $("#ShowFiles").prop('checked', true);
820  var items = CURRENT_OBJ.searchFile(reg,searchTerm,fin)
821  var matchCount = fileTypeSearch(doc,items,true)\n break;
822  case "Type":\n var items = CURRENT_OBJ.searchType(reg,searchTerm,fin)
823  var matchCount = fileTypeSearch(doc,items,false)\n break
824  case "Name":\n var matchCount = easySearch(searchTerm,reg, doc, fin)
825  }\n $("#searchCount").html(matchCount+ " found.")\n searching = false;
826  searchShowing= true;\n});\n/*\n Used when searching top level elements.
827  i.e. Module names, path names etc.
828  We dont need to delve into any dictionaries, we just use the keys.\n*/
829 function easySearch(term,reg, doc, fin){\n var keys = CURRENT_OBJ.getKeys()
830  var matches = keys.filter(function(e, i, a){return (e.indexOf(term)>-1)})
831  var highlights = matches.map(function(e,i,a){
832  return e.replace(reg, fin)})
833  addData(doc, highlights,matches)\n return matches.length\n}\n/*
834  When searching type or file names of top level elements.\n*/
835 function fileTypeSearch(doc,items,file){
836  var newFunct = function(name){return items[name]}\n if(file){
837  var backup = baseFile\n var backup2 = baseTopFile
838  baseFile = newFunct \n baseTopFile = newFunct\n }\n else {
839  var backup = baseType\n baseType = newFunct\n }
840  var matches = Object.keys(items)\n addData(doc, matches)\n if(file){
841  baseFile = backup\n baseTopFile = backup2\n }\n else baseType = backup
842  return matches.length\n}\n// --- end of search operations ---\n
843 // --- edit operations ---\n// variables needed:
844 // will contain the highest parents, where something *might*
845 // be changed in its children.\nvar $potential=[]
846 // dict, keys are parentNames and values are lists of children changed
847 // under that parent\nvar parChildNames={}\n
848 $(document).on('click', '#editMode', function(e){\n if(searchShowing)
849  var dataType = $('#searchType :selected').attr("data-base")
850  else var dataType = $('#showType :selected').attr("data-base")
851  // Temp restriction of editing SequenceTypes e.g. Paths,EndPaths etc.
852  if(dataType=="modSeqCreate"){
853  window.alert("At the moment editing for SequenceTypes"+
854  " has been disabled.");\n return;\n }
855  else if (dataType == "prodConCreate"){
856  window.alert("Sorry, it is currently not possible to "+
857  "edit producers and consumers.");\n return;\n }
858  if(CURRENT_OBJ == undefined)return;
859  // this is editing mode, turn off expansion\n expandDisable = true;
860  $("#mode")[0].textContent = "Edit Mode"\n $(this).attr("value", "Cancel");
861  var l = ($(this).width()/ parseFloat($("body").css("font-size"))+2.5)+"em"
862  $(this).after(jQuery('<input>', {\n type:"submit",
863  value:"Save",\n id:"save"\n }).css({\n left:l\n}));
864  $(this).attr("id", "normalMode")\n makeEditable(searchShowing);
865  searchShowing = false;\n});\n/*
866  Adds in div elements to make cells editable.\n*/
867 function makeEditable(rmSearch){\n // add editable div to everything showing.
868  var todo = jQuery.makeArray($(".Top"));\n while(todo.length){
869  var e = $(todo.pop())\n if(rmSearch)
870  e.html(e.html().replace(/(<em>|<\/em>)/g, ""))
871  // we have the item.. lets get children
872  var kids = jQuery.makeArray(e.children());
873  // add divs to all children.\n while(kids.length){
874  var k = $(kids.pop())\n var tag = k.prop("tagName")\n
875  if(tag == "SPAN"){\n if(k.prop("class")!="type")
876  k.html('<div class="cellEdit" contenteditable>'+k.html()+'</div>')
877  continue\n }\n if(tag =="LI"){
878  // add the div but dont get children
879  $(k.contents()[0]).wrap('<div class="cellEdit" contenteditable />');
880  }\n // check if have any children
881  var moreKids = jQuery.makeArray(k.children());
882  if(moreKids.length){\n kids = kids.concat(moreKids)\n }
883  }\n // now do current one
884  $(e.contents()[0]).wrap('<div class="cellEdit" contenteditable />');\n }
885 }\n/*\n A cell which is editable has been clicked.\n*/
886 $(document).on('click', '.cellEdit', function(e){
887  // we're in edit so things have a div parent over the text.
888  // so get parent to get the thing we want.
889  var $itemChanged = $(this).parent()
890  // now go up until we find greatest parent(item with class==topClass)
891  var classes = $itemChanged.attr("class")\n var $parent = $itemChanged
892  while(classes.indexOf(topClass)==-1){\n $parent = $parent.parent();
893  classes = $parent.attr("class") || "";\n }
894  var parentName = $parent.attr("data-name");
895  // doesnt matter if parent and child are the same.
896  var parents = Object.keys(parChildNames)
897  if(parents.indexOf(parentName)>-1){\n // already been edited.
898  var kids = parChildNames[parentName]
899  if(kids.indexOf($itemChanged.attr("data-name"))==-1){
900  kids.push($itemChanged)\n }\n }\n else{
901  parChildNames[parentName]=[$itemChanged]\n }\n $potential.push($parent)
902 });\n//--- end of edit operations ---\n// --- start of save operations ---\n/*
903  Save any changes.\n*/\n$(document).on('click', '#save', function(e){
904  var allData = CURRENT_OBJ.getData();\n var oldData = allData[0]
905  goNormal($("#normalMode"));\n if(allData.length >1){
906  var top = allData[0];\n var rest = allData[1];
907  var changed = save(deepCopy(top),deepCopy(rest))\n }\n else{
908  var changed = save(deepCopy(allData[0]));\n }
909  if(Object.keys(changed).length ==0){
910  window.alert("Nothing was changed.");\n $potential=[]
911  parChildNames={}\n return \n }
912  //$('#svg_export_form > input[name=svg]').val("jhgjhg");
913  changed["processName"]= processName
914  changed["processFileName"]= processFileName\n $("#posty").empty()
915  var form = jQuery('<form/>', {\n id:"edited_write",\n method:"POST",
916  async: "false",\n enctype: "multipart/form-data",
917  style:"display:none;visibility:hidden",\n })\n jQuery('<input/>', {
918  type:"hidden",\n name:"changed",\n value:JSON.stringify(changed),
919  }).appendTo(form)\n form.appendTo("#posty")\n $('#edited_write').submit();
920  $potential=[]\n parChildNames={}\n});\n/*
921  Go to normal viewing mode. Discard any changes.\n*/
922 $(document).on('click', '#normalMode', function(e){
923  //remove all cell edit Divs\n goNormal($(this));\n //$potential =[]
924  //parChildNames={}\n});\n/*\n Couldn't find built-in deep clone or copy.\n*/
925 function deepCopy(obj){\n if(obj instanceof Array){\n var copy=[]
926  obj.forEach(function(x,i,a){copy[i]= deepCopy(x)})\n return copy\n }
927  else if(obj instanceof Object){\n var copy ={}\n for (key in obj){
928  copy[key] = deepCopy(obj[key])\n }\n return copy\n }\n return obj
929 }\n\n/*\n Returns a dict of everything that has changed.\n*/
930 function save(data, restData){\n var allChanged={}\n var done=[]
931  for(var i in $potential){\n var parent = $potential[i];
932  // we have the parent.
933  var oldParentName = $(parent).attr("data-name");
934  //bit iffy, can have same parent name multiple times? todo
935  if(done.indexOf(oldParentName)>-1) continue\n done.push(oldParentName)
936  if(typeof restData =='undefined'){
937  var allDict = deepCopy(data[oldParentName])
938  var allOldData = allDict["Parameters"]
939  var childChanged = parChildNames[oldParentName]
940  var oldToNew= chil(childChanged,parent, true)
941  if(oldToNew.length ==0) continue
942  var newpar = blah(oldToNew, oldParentName, allOldData, parent, false)
943  tempDict = allDict\n tempDict["Parameters"] = allOldData
944  allChanged[newpar] = tempDict\n if(oldToNew.length>0){
945  window.alert("Something went wrong, I did not find all changes.");
946  }\n }\n else{
947  // we have one data for the parents and one for rest
948  var allDict = deepCopy(data[oldParentName])
949  var allKids = allDict["Parameters"]\n var tem ={}
950  var childChanged = parChildNames[oldParentName];
951  var oldToNew = chil(childChanged,parent, false);
952  //if(Object.keys(oldToNew).length ==0) continue
953  if(oldToNew.length ==0) continue\n for (var y in allKids){
954  var n = allKids[y]\n var allOld2 = deepCopy(restData[n])
955  var allOldData = allOld2["Parameters"]
956  // blah chanhes allOldData
957  var newpar = blah(oldToNew, n, allOldData, parent, true)
958  allOld2["Parameters"]= allOldData\n tem[newpar] = allOld2
959  }\n var newParentName = $(parent).contents()[0].nodeValue
960  //allChanged[newParentName]= tem\n tempDict = allDict
961  tempDict["Parameters"] = tem\n allChanged[newParentName] = tempDict
962  continue\n }\n }\n return allChanged\n}\n/*
963  These three functions are used for getting data from
964  a structure such as [{},{},{}]\n*/\nfunction getValue(list, key){\n var re=[]
965  for(x in list){\n di = list[x]\n k = Object.keys(di)[0]
966  if(k==key)re.push(di[k])\n }\n return re\n}\nfunction getKeys(list){
967  var keys = []\n for (x in list)\n keys.push(Object.keys(list[x])[0])
968  return keys\n}\nfunction deleteValue(list, k,d){\n var inde =-1
969  var found = false\n for(var x in list){\n var di = list[x]
970  var key = Object.keys(di)[0]\n if(key==k && di[key]==d){
971  found = true\n inde = x\n break\n }\n }
972  if(found)list.splice(inde,1)\n}\n/*
973  allOldData will be changed with the new data.\n*/
974 function blah(oldToNew, oldParentName, allOldData, parent){
975  var newpar = oldParentName\n var keys = getKeys(oldToNew)
976  if(keys.indexOf(oldParentName)>-1){\n // parent is in
977  var tDatas = getValue(oldToNew,oldParentName);
978  for (var x in tDatas){\n var tData = tDatas[x]
979  if(tData["i"]==0 && tData["p"].length ==0){
980  var newpar = tData["new"];\n // this isnt finding tData
981  deleteValue(oldToNew, oldParentName,tData);\n }\n }\n }
982  // okay so here we have everything for this parent.
983  // now need to loop through the old data and changed for new.
984  if(oldToNew.length >0){
985  loopData(allOldData,oldToNew,[oldParentName], [0]);\n }
986  return newpar\n}\n//need to remember that current format is
987 //[name, parameters,type,optionalType]\n/*\n Loop around the data, \n*/
988 function loopData(thelist, items, parents, pIndex){\n for(var x in thelist){
989  var y = thelist[x]\n if(y instanceof Array){
990  // okay if array, we have full line
991  if(typeof y[0] == "string" && y[1] instanceof Array){
992  // this is what we want.\n var theName = y[0]
993  var rest = y[1]\n var types = [y[2]]\n if(y.length == 4)
994  types.push(y[3])\n // okay, name of this is theName == parent
995  // the index of this is x\n parents.unshift(theName)
996  pIndex.unshift(x)\n loopData(rest, items, parents, pIndex);
997  parents.shift()\n pIndex.shift()
998  rightOne(thelist,x,theName,items,parents,pIndex)
999  for(var index in types){\n var item = types[index]
1000  rightOne(thelist,x,item,items,parents,pIndex)\n }
1001  continue\n }
1002  if(y[0] instanceof Array && y[1] instanceof Array){
1003  // y1 is a parameter\n // y2 is a parameter
1004  for(var e in y){\n loopData(y[e],items,parents,pIndex);
1005  }\n continue;\n }\n // we are here,
1006  //so we have something that does not have parameters in a list
1007  var theName = y[0]\n for(var index in y){\n if(index >0){
1008  parents.unshift(theName) \n pIndex.unshift(x)\n }
1009  var item = y[index]
1010  rightOne(thelist,x,item,items,parents,pIndex)\n if(index >0){
1011  parents.shift()\n pIndex.shift()\n }\n }
1012  continue;\n }\n else {
1013  rightOne(thelist,x,y,items,parents,pIndex)\n }\n }\n}\n/*
1014  Helper function. We have a match, now change old values for new values.\n*/
1015 function rightOne(thelist,x,y,items,parents,pIndex){
1016  if(getKeys(items).indexOf(y)>-1){
1017  // we know that we have a match, but are indexes the same?
1018  // index will be in the same list so we can use x
1019  var dis = getValue(items, y)\n for (inde in dis){
1020  var di= dis[inde]\n if(x == di["i"]){
1021  if(arrayCompare(parents, pIndex,di["p"],di["pIndex"] )){
1022  //okay we can be sure we are changing the right thing.
1023  if(thelist[x] instanceof Array){
1024  for(var ind in thelist[x]){\n var z = thelist[x][ind]
1025  if(y == z){\n thelist[x][ind] = di["new"]
1026  break;\n } \n }\n }
1027  else{\n thelist[x] = di["new"]\n }
1028  deleteValue(items,y,di)\n }\n }\n }\n }\n}\n/*
1029  Returns true if arrays a1 is identical to a2 and
1030  a1Index is identical to a2Index.\n*/
1031 function arrayCompare(a1, a1Index, a2, a2Index) {
1032  if (a1.length != a2.length)return false;
1033  for (var i = 0; i < a1.length; i++) {
1034  if (a1[i] != a2[i] || a1Index[i] != a2Index[i]) {
1035  return false;\n }\n }\n return true;\n}\n/*
1036  Take in the children that might have been changed.
1037  If something has been changed, adds to a dictionary
1038  dictionary format is [data-name]={
1039  "new": newvalue, "i":data-index, "p":[parentNames],
1040  "pIndex": [indicies of parents]}
1041  TODO, need a new format, what if children have
1042  the same data-name and both are changed?\n*/
1043 function chil (childChanged, parent, addParent){\n var oldToNew=[]
1044  for (var x in childChanged){\n var child = childChanged[x]
1045  // we need to check if the child has been changed.
1046  var oldval = child.attr("data-name");
1047  var isSpan = child.prop("tagName") == "SPAN"\n var newval = isSpan ?
1048  child.contents().text(): child.contents()[0].nodeValue;
1049  //remove any enclosing brackets
1050  newval = newval.trim().replace(/\(.*\)$/, "");
1051  oldval = oldval.trim().replace(/\(.*\)$/, "");
1052  if(oldval==newval)continue\n else{
1053  //child has been changed.\n //we want to keep 4 pieces of data.
1054  //1. old name, new name\n //2. data-index
1055  //3. list of direct parents.\n //4. indexes of all parents.
1056  var inner ={}\n inner["new"] = newval;
1057  //depends if it was a span or not. Span means we use parents.
1058  inner["i"]= (isSpan? child.parent().attr("data-index"):
1059  child.attr("data-index")) || 0\n var allP = child.parents()
1060  var pNames =[]\n var pIndex =[]
1061  for(var y=0; y < allP.length; y++){\n var p = $(allP[y])
1062  var tag = p.prop("tagName")
1063  if(p.attr("data-name") == parent.attr("data-name")){
1064  if(addParent){\n pNames.push(parent.attr("data-name"))
1065  pIndex.push(parent.attr("data-index") || 0);\n }
1066  break;\n }\n else if(tag == "LI"){
1067  pNames.push(p.attr("data-name"));
1068  pIndex.push(p.attr("data-index") || 0);\n }\n }
1069  inner["p"] = pNames\n inner["pIndex"] = pIndex\n var t={}
1070  t[oldval]= inner\n oldToNew.push(t)\n }
1071  } // end of childchanged loop\n return oldToNew\n}
1072 // --- end of save operations ---
1073 // --- Expand and show more data operations ---\n/*
1074  Used when in edit mode to stop any items being added to the webpage.
1075  More items added after edit mode- they wont be editable, and when you
1076  click to edit something it loads its children.\n*/
1077 $(document).on('click','.expand, .expanded', function(event){
1078  if(expandDisable){\n event.stopImmediatePropagation();\n }\n});\n/*
1079  Retrieves and expands elements whose objects have multiple lists
1080  (i.e. onese who's data-base !=simpleData)\n*/
1081 $(document).on('click', '.Consumer.expand,.Producer.expand,'
1082 +'.Path.expand,.EndPath.expand ',function(event){
1083  var allModules = CURRENT_OBJ.getModules($(this).attr('data-name'));
1084  var UL = addParams(this,allModules)\n $(this).append(UL);
1085  event.stopPropagation();\n});\n/*\n Adds parameters onto objects.\n*/
1086 $(document).on('click','.Modules.expand,.SequenceTypes,.Types.expand'
1087 , function(event){\n if(showParams){\n addParams(this);\n }
1088  event.stopPropagation();\n});\n/*\n Hides/Shows children from class param.
1089 */ \n$(document).on('click', '.paramInner.expand, .paramInner.expanded',
1090  function(event){\n if($(this).children('ul').length ==0){
1091  // find parents\n var parents = findParents(this)
1092  var result = baseInnerParams(parents,parseInt(
1093  $(this).attr("data-index")) )[1]
1094  addParams(this, result);\n }\n else{
1095  //children already added, so just hide/show.
1096  $(this).children('ul').toggle();\n }\n event.stopPropagation();
1097  });\n/*\n Find the parents of a child.\n*/\nfunction findParents(child){
1098  var parents =[$(child).attr("data-name")]
1099  var theParent = $(child).attr("data-parent")
1100  while(theParent !=undefined){ \n var child = $(child).parent();
1101  if(child.prop("tagName")=="UL") continue;
1102  parents.unshift(child.attr("data-name"));
1103  theParent = child.attr("data-parent");\n }\n return parents\n}\n/*
1104  Helper function: returns filename appended onto val.\n*/
1105 function getFile(theName){\n var f = baseFile(theName)
1106  if(f)return theName+=type(f)\n return theName\n}\n/*
1107  Add params to the object. Object can be of any type
1108  (normally module or param).
1109  Will be used by modules adding parameters, psets adding parameters.\n*/
1110  var $LIBasic = $(document.createElement('li')).attr("class","param");
1111  var $LIExpand = $LIBasic.clone().attr("class","expand");\n
1112 function addParams(obj, params){
1113  var fileChecked = document.getElementById("ShowFiles").checked
1114  var $span = $(document.createElement("span"));
1115  var $typeSpan = $span.clone().addClass("type");
1116  var $valSpan = $span.clone().addClass("value");
1117  var $UL = $(document.createElement("ul"));
1118  var $objName = $(obj).attr('data-name');\n\n if(!params)
1119  params = baseParams($objName)\n for(var i =0; i < params.length; i++){
1120  var all = params[i].slice() // make copy of it
1121  var isList= typeof(all)=="object"
1122  var theName = isList ? all.shift(): all
1123  var typ= !isList || !all.length ? baseType(theName): all.pop()
1124  var gen = getGenericType(typ)
1125  var spt = $typeSpan.clone().attr("data-name",typ).text(type(typ))
1126  if(fileChecked) text = getFile(theName)
1127  if(isList && typeof(all[0]) == "object"){\n // PSets
1128  var cloLI = doLI(false,theName,i,"paramInner",spt)
1129  cloLI.attr("data-parent", $objName)\n }
1130  else if(baseParams(theName)){\n // Modules or sequences
1131  var cloLI = doLI(false,theName,i,gen,spt)\n }\n else{
1132  // Basic type, has no children\n var cloLI= doLI(true,theName,i)
1133  var value =""\n if(all.length)\n var value = all.shift()
1134  // formating so lots of strings look nicer\n var valDataName = value
1135  if(value.indexOf(",")>-1){
1136  value = "<ul><li>"+value.replace(/,/g, ",</li><li>")+"</li></ul>"
1137  }\n var add = type(typ)
1138  cloLI.append($valSpan.clone().attr("data-name",valDataName).html(value))
1139  cloLI.append($typeSpan.clone().attr("data-name",add).text(add))
1140  for(var p=0; p < all.length; p++){\n var n = type(all[p])
1141  cloLI.append($typeSpan.clone().attr("data-name",n).text(n))\n }
1142  } \n $UL.append(cloLI);\n }\n $(obj).append($UL);\n}\n
1143 function type(theName){\n return " ("+theName+")"\n}\n/*
1144  Helper function: Adds data to a LI.\n*/
1145 function doLI(basic,dataN,dataI,classes,html){
1146  if(basic) var $LI = $LIBasic.clone()\n else var $LI = $LIExpand.clone()
1147  $LI.attr("data-name", dataN).attr("data-index", dataI).text(dataN);
1148  if(classes)$LI.addClass(classes)\n if(html)$LI.append(html)\n return $LI
1149 }\n/*\n Box to show params has been clicked.\n*/
1150 $(document).on('click', '#ShowParams', function(e){
1151  if($(this).is (':checked')){\n showParams = true\n }\n else{
1152  $(this).next().hide()\n showParams = false\n }\n});\n/*
1153  Removes children from top level list elements.\n*/
1154 $(document).on('click', '#hide', function(e){
1155  //make sure not called when not needed.
1156  if($(this).css('cursor')!='default'){
1157  var selec = $(".expanded."+topClass).children("ul").hide()
1158  toggleExpand($(".expanded."+topClass ),e)\n invisibleHide()\n }\n});
1159 // --- end of expand and show more data operations ---
1160 // --- general helper operations and functions ---\n\n/*
1161  Return to normal viewing mode.\n*/\nfunction goNormal(it){
1162  expandDisable = false;
1163  $(".cellEdit").replaceWith(function() { return $(this).contents();});
1164  $("#save").remove()\n $("#mode")[0].textContent = "Normal Mode"
1165  it.attr("value", "Edit");\n it.attr("id", "editMode")\n}\n/*
1166  Set what the CURRENT_OBJ is.\n*/\nfunction setCURRENT_OBJ($element){
1167  var thefunction = $element.attr("data-base");
1168  var list = $element.attr("data-files").split(" ");\n if(list.length >1){
1169  CURRENT_OBJ = window[thefunction](list[1], list[0])\n } \n else{
1170  CURRENT_OBJ = window[thefunction](list[0])\n }\n}\n/*
1171  Add option in html to show/hide parameters.\n*/\nfunction paramOptions(bool){
1172  if(!bool){\n $("#attachParams").empty()\n return\n }
1173  var lb= jQuery('<label/>', {\n for:"ShowParams"\n })
1174  jQuery('<input/>', {\n type:"checkbox",\n id:"ShowParams",
1175  name:"ShowParams",\n value:"ShowParams",\n autocomplete:"off"
1176  }).appendTo(lb)\n lb.append("Show Parameters")
1177 lb.appendTo("#attachParams")\n}\n/*\n Small info about each option.\n*/
1178 $('#showType option').mouseover(function(){
1179  var docType = $(this).attr("value").toLowerCase();\n var info;
1180  switch(docType){\n case "producer":
1181  info="What's produced by each module."\n break;
1182  case "consumer":\n info="What's consumed by each module."
1183  break;\n default:\n info ="List of "+ docType+"s."\n }
1184  $(this).attr("title", info);\n});\n/*\n Small info about each option.\n*/
1185 $('span[name="Info"]').mouseover(function(){
1186  var docType = $(this).attr("value").toLowerCase();\n var info;
1187  switch(docType){\n case "producer":
1188  info="What's produced by each module."\n break;
1189  case "consumer":\n info="What's consumed by each module."
1190  break;\n default:\n info ="List of "+ docType+"s."\n }
1191  $(this).attr("title", info);\n});\n/*\n More info about what's shown.\n*/
1192 $("#helpMouse").hover(function(e) {
1193  $($(this).data("help")).stop().show(100);
1194  var title = "<h6>(Read the README file!)</h6><h4>Info:</h4> "
1195  var expl = "<h5>Colour codes:</h5> <h6><ul><li class='Path'>pathName"+
1196  " </li></ul><ul><li class='Modules'>Modules (e.g. "+
1197  "EDProducer, EDFilter etc)</li></ul><ul><li class='Types'>"+
1198  "Types (e.g. PSet)</li></ul><ul><li class='param'>"+
1199  "ParameterName:<span class='value'> value</span><span"+
1200  " class='type'>(type)</span></li></ul></h6>"
1201  var info ="<h5>The data</h5><h6>The headings you can choose from are"+
1202  " what was collected from the config file.<br/><br/> Any "+
1203  "change to the config file means having to run the script "+
1204  "again and then refresh this page (if same output file was "+
1205  "used).</h6><br/>"
1206  var tSearch="<h5>Search</h5><h6>Currently can only search by listing "+
1207  "what items you would like to be searched, and then what part"+
1208  " of each item.<br/><br/> I.e. search the producers for "+
1209  "certain names.</h6><br/>"
1210  var problems = "<h5>HTML/JSON/JS issues</h5><h6>If content isn't "+
1211  "loading,or json files cannot be loaded due to browser"+
1212  " security issues, try runing the local server created"+
1213  " by the script. This will be in the same place as "+
1214  "index.html.<br/><span class='Types'>'python cfgServer.py'"+
1215  " </span></h6><br/>"
1216  var editing = "<h5>Editing</h5><h6>In order to use the edit mode, you "+
1217  "need to run the cfgServer.py file, this will be in the "+
1218  "same directory as the index.html.<br/>Then go to <span"+
1219  " class='Types'> 'http://localhost:8000/index.html.'"+
1220  "</span><br/><strong>Please note that the editing of "+
1221  "SequenceTypes (i.e. Paths, EndPaths etc) and of producers"+
1222  " and consumers has been "
1223  $($(this).data("help")).html(title+expl+info+problems+editing);
1224  "disabled.</strong></h6><br/>"\n}, function() {
1225  $($(this).data("help")).hide();\n});\n/*
1226  These two functions hide/show the top box in browser.\n*/
1227 $(document).on('click', '.hideTopBox', function(e){
1228  $(".topSpec").animate({top: "-2.5em"}, 500);\n $(this).text("show");
1229  $(this).toggleClass("hideTopBox "+"showTopBox");\n});
1230 $(document).on('click', '.showTopBox', function(e){
1231  $(".topSpec").animate({top: "0em"}, 500);\n $(this).text("hide");
1232  $(this).toggleClass("showTopBox "+ "hideTopBox");\n});\n/*
1233  Stop some links from firing.\n*/\n$('a.nowhere').click(function(e)\n{
1234  e.preventDefault();\n});\n\n// Turn off any action for clicking help.
1235 $('a#help').bind('click', function() {\n return false;\n});\n/*
1236  If parameter value is a list, hide/show the list on click.\n*/
1237 $(document).on('click', '.param',function(event){\n if(!expandDisable){
1238  if($(this).find('ul').length >0){\n $(this).find('ul').toggle();\n }}
1239  event.stopPropagation();\n});\n/*
1240  Removes children from expanded paths or modules.\n*/
1241 $(document).on('click', '.expanded',function(event){
1242  var c = $(this).children('ul');\n if(c.length >0){\n $(c).remove();
1243  }\n event.stopPropagation();\n});\nfunction visibleHide(){
1244  $('#hide').css('opacity',1);\n $('#hide').css('cursor','pointer');
1245  hideVisible = true;\n}\nfunction invisibleHide(){
1246  $('#hide').css('opacity','');\n $('#hide').css('cursor','');
1247  hideVisible = false;\n}\n\n// Toggles class names.
1248 $(document).on('click','.expand, .expanded', function(event){
1249  if(!hideVisible && $(this).is('.expand')){\n visibleHide();\n }
1250  toggleExpand(this, event);\n});\n/*\n Helper function toggles class type.
1251 */\nfunction toggleExpand(me,event){\n $(me).toggleClass("expanded expand");
1252  event.stopPropagation();\n}\n});\n// end of jquery\n/*
1253 Function to load the JSON files.\n*/\nfunction loadJSON(theName){
1254  return $.ajax({\n type: "GET",\n url: theName,
1255  beforeSend: function(xhr){\n if (xhr.overrideMimeType)\n {
1256  xhr.overrideMimeType("application/json");\n }\n },
1257  contentType: "application/json",\n async: false,\n dataType: "json"
1258  });\n} \n"""%(pN,pFN))
1259 genericTypes={}
1260 
def _jqueryFile(self, name, pN, pFN)
Definition: cfg-viewer.py:744
def cfg-viewer.html._printHtml (   self,
  name,
  scrip,
  css,
  items,
  search 
)
private

Definition at line 660 of file cfg-viewer.py.

Referenced by cfg-viewer.html.__init__().

660  def _printHtml(self,name,scrip,css,items, search):
661  with open(name,'w') as htmlFile:
662  htmlFile.write("""<!DOCTYPE html>\n<html>\n <head>
663  <meta http-equiv="Content-Type" content="text/html;charset=utf-8" >
664  <title>cfg-browser</title>\n <script type="text/javascript"
665  src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js">
666  </script>\n %(s)s\n %(css)s\n </head>\n <body>
667  <div class="topBox topSpec">
668  <input type="submit" value="Edit" id="editMode" autocomplete="off"
669  disabled/>\n <div class="helpLinks">
670  <a href="#" class="nowhere" id="helpMouse" data-help="#help">help
671  </a></br/>
672  <a href="mailto:susie.murphy@cern.ch?Subject=CfgBrowserhelp"
673  target="_top">Contact</a>\n </div>\n <div id="help"> </div>
674  <span id="mode">Normal Mode</span>
675  <div class="topBox hideTopBox">hide</div>\n </div>
676  <a id="topOfPage"></a>\n <br/><br/><br/>\n <div class="outerBox">
677  <div class="boxTitle"> Pick\n <div class="dottedBorder">
678  <form onsubmit="return false;">\n <select id="showType">
679  %(items)s\n </select>\n <br/><br/>
680  <input type="submit" id="docSubmit" value="submit">
681  </form>\n </div>\n </div>
682  <div class="boxTitle"> Pick\n <div class="dottedBorder">
683  <form onsubmit="return false;">
684  <input type="text" id="searchWord"/>
685  <select id="searchType">\n %(search)s
686  </select> \n <span id="addSearch"> </span>
687  <br/><br/>
688  <input type="submit" value="Search" id="search"/>
689  <input type="checkbox" id="rmHilight" value="File"/>
690  <span>Don't show highlights</span>\n </form>
691  </div>\n </div>\n </div> \n <br/>
692  <input type="checkbox" id="ShowFiles" value="File"/>
693  <span>Show file names</span>\n <br/><br/>\n <script>
694  document.getElementById("searchType").selectedIndex = -1;\n </script>
695  <div id="posty"> </div>\n <br/>\n <div id="current"></div>
696  <br/>\n <div id="searchCount"></div>\n <div id="attachParams"></div>
697  <div class="rightScroll">\n <a href="#topOfPage">Back to Top</a>
698  <p>\n <a id="hide" href="javascript:;" >Hide All</a>\n </p>
699  </div>\n </body>\n</html>\n"""%{
700  "s":scrip,"css":css,"items":items, "search":search})
701 
def _printHtml(self, name, scrip, css, items, search)
Definition: cfg-viewer.py:660
def cfg-viewer.html._scripts (   self,
  js 
)
private

Definition at line 643 of file cfg-viewer.py.

References join().

Referenced by cfg-viewer.html.__init__().

643  def _scripts(self, js):
644  x = """
645 <script type="text/javascript" src="%s"></script>"""
646  return "\n".join([x%(i) for i in js])
647 
def _scripts(self, js)
Definition: cfg-viewer.py:643
static std::string join(char **cmd)
Definition: RemoteFile.cc:18
def cfg-viewer.html._searchitems (   self,
  items 
)
private

Definition at line 655 of file cfg-viewer.py.

References join().

Referenced by cfg-viewer.html.__init__().

655  def _searchitems(self,items):
656  b = """<option value="%(name)s" data-base="%(d)s">%(name)s</option> """
657  return "\n ".join([b%({"name": x, "d":y["data-base"]})
658  for x,y in items.iteritems()])
659 
def _searchitems(self, items)
Definition: cfg-viewer.py:655
static std::string join(char **cmd)
Definition: RemoteFile.cc:18