Home Reference Source

cables_dev/cables_ui/src/ui/components/opselect_treelist.js

  1. import GlPatch from "../glpatch/glpatch.js";
  2.  
  3. /**
  4. * tree view for namespaces in op select dialog
  5. *
  6. * @export
  7. * @class OpTreeList
  8. */
  9. export default class OpTreeList
  10. {
  11. constructor()
  12. {
  13. this.data = this._serializeOps(window.Ops, "Ops");
  14. }
  15.  
  16.  
  17. searchFor(txt)
  18. {
  19. const opSearch = document.getElementById("opsearch");
  20. opSearch.value = txt;
  21.  
  22. const event = new Event("input", {
  23. "bubbles": true,
  24. "cancelable": true,
  25. });
  26.  
  27. opSearch.dispatchEvent(event);
  28. }
  29.  
  30. itemHtml(item, html, level)
  31. {
  32. if (!item.childs || item.childs.length == 0) return "";
  33. if (!item) return "";
  34. html = "";
  35.  
  36. let i = 0;
  37. for (i = 0; i < level; i++) html += "&nbsp;&nbsp;&nbsp;";
  38.  
  39. // const style = defaultops.getNamespaceClassName(item.fullname);
  40.  
  41. const color = GlPatch.getOpNamespaceColor(item.fullname) || [1, 1, 1, 1];
  42.  
  43. html += "<a style=\"color:rgba(" + Math.round(color[0] * 255) + "," + Math.round(color[1] * 255) + "," + Math.round(color[2] * 255) + ",1);\" onclick=\"gui.opSelect().tree.searchFor('" + item.fullname + ".')\">";
  44. html += "" + item.name;
  45. html += "</a>";
  46.  
  47. // if(item.childs && item.childs.length>0)html+=' ('+item.childs.length+')';
  48. html += "<br/>";
  49.  
  50. if (item.childs)
  51. for (i = 0; i < item.childs.length; i++)
  52. html += this.itemHtml(item.childs[i], html, level + 1);
  53.  
  54. return html;
  55. }
  56.  
  57. html()
  58. {
  59. const perf = CABLES.UI.uiProfiler.start("opselect.treelist");
  60.  
  61. let html = "";
  62.  
  63. for (let i = 0; i < this.data.length; i++)
  64. html += this.itemHtml(this.data[i], html, 0);
  65.  
  66. perf.finish();
  67.  
  68. return html;
  69. }
  70.  
  71. _serializeOps(root, prefix)
  72. {
  73. let items = [];
  74.  
  75. for (const i in root)
  76. {
  77. if (i != "Deprecated" && i != "Admin" && i != "Dev")
  78. items.push(
  79. {
  80. "name": i,
  81. "fullname": prefix + "." + i,
  82. "childs": this._serializeOps(root[i], prefix + "." + i)
  83. });
  84. }
  85.  
  86. items = items.sort(
  87. function (a, b)
  88. {
  89. if (a.name < b.name) return -1;
  90. if (a.name > b.name) return 1;
  91. return 0;
  92. });
  93.  
  94. return items;
  95. }
  96. }