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 634 of file cfg-viewer.py.

Constructor & Destructor Documentation

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

Definition at line 635 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().

635  def __init__(self,name,js,items,theDir, helperDir, pN,pFN):
636  jqName = "%scfgJS.js"%(theDir)
637  jqLocal = "%scfgJS.js"%(helperDir)
638  css = "%sstyle.css"%(theDir)
639  cssL = "%sstyle.css"%(helperDir)
640  js.insert(0,jqLocal)
641  self._jqueryFile(jqName, pN,pFN)
642  self._printHtml(name,self._scripts(js),self._css(css, cssL),
643  self._items(items), self._searchitems(items))
644 
def _scripts(self, js)
Definition: cfg-viewer.py:645
def _css(self, css, cssLocal)
Definition: cfg-viewer.py:704
def _searchitems(self, items)
Definition: cfg-viewer.py:657
def _items(self, items)
Definition: cfg-viewer.py:650
def _jqueryFile(self, name, pN, pFN)
Definition: cfg-viewer.py:746
def __init__(self, name, js, items, theDir, helperDir, pN, pFN)
Definition: cfg-viewer.py:635
def _printHtml(self, name, scrip, css, items, search)
Definition: cfg-viewer.py:662

Member Function Documentation

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

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

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

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

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

References join().

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

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

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

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

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

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

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

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

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

References join().

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

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

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

References join().

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

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