Home Reference Source

cables_dev/cables_ui/src/ui/components/opparampanel/op_params_htmlgen.js

  1. import defaultOps from "../../defaultops.js";
  2. import text from "../../text.js";
  3. import userSettings from "../usersettings.js";
  4.  
  5. class PortHtmlGenerator
  6. {
  7. constructor(panelId)
  8. {
  9. this._panelId = panelId;
  10. this._templateHead = Handlebars.compile(document.getElementById("params_op_head").innerHTML);
  11. this._templatePortGeneral = Handlebars.compile(document.getElementById("params_port_general").innerHTML);
  12. this._templatePortGeneralEnd = Handlebars.compile(document.getElementById("params_port_general_end").innerHTML);
  13. this._templatePortInput = Handlebars.compile(document.getElementById("params_port_input").innerHTML);
  14. this._templatePortOutput = Handlebars.compile(document.getElementById("params_port_output").innerHTML);
  15. this._templatePortsHead = Handlebars.compile(document.getElementById("params_ports_head").innerHTML);
  16. }
  17.  
  18. getHtmlOpHeader(op)
  19. {
  20. let isBookmarked = false;
  21. let oldversion = false;
  22. let newestVersion = false;
  23. let hasExample = false;
  24. let doc = null;
  25.  
  26. if (op) isBookmarked = gui.bookmarks.hasBookmarkWithId(op.id);
  27.  
  28. const canEditOp = gui.serverOps.canEditOp(gui.user, op.objName);
  29. if (defaultOps.isDeprecatedOp(op.objName))
  30. {
  31. op.isDeprecated = true;
  32. const notDeprecatedName = op.objName.replace("Deprecated.", "");
  33. const alt = CABLES.Patch.getOpClass(notDeprecatedName);
  34. if (alt) op.isDeprecatedAlternative = notDeprecatedName;
  35. }
  36. if (defaultOps.isDevOp(op.objName)) op.isExperimental = true;
  37.  
  38. if (gui.opDocs)
  39. {
  40. op.summary = gui.opDocs.getSummary(op.objName);
  41. doc = gui.opDocs.getOpDocByName(op.objName);
  42. }
  43.  
  44. if (doc)
  45. {
  46. hasExample = doc.hasExample;
  47. if (doc.oldVersion) oldversion = doc.oldVersion;
  48. newestVersion = doc.newestVersion;
  49. }
  50.  
  51. const o = {
  52. "op": op,
  53. "panelid": this._panelId,
  54. "frontendOptions": CABLES.platform.frontendOptions,
  55. "isBookmarked": isBookmarked,
  56. "colorClass": defaultOps.getNamespaceClassName(op.objName),
  57. "texts": text,
  58. "user": gui.user,
  59. "optitle": op.getTitle(),
  60. "canEditOp": canEditOp,
  61. "showRenameButton": canEditOp && defaultOps.isNonCoreOp(op.objName),
  62. "oldVersion": oldversion,
  63. "minified": userSettings.get("minifiedOpHead"),
  64. "newestVersion": newestVersion,
  65. "cablesUrl": CABLES.platform.getCablesUrl(),
  66.  
  67.  
  68. "hasExample": hasExample,
  69. };
  70.  
  71. o.cablesDocsUrl = CABLES.platform.getCablesDocsUrl();
  72.  
  73. return this._templateHead(o);
  74. }
  75.  
  76. getHtmlHeaderPorts(dir, title)
  77. {
  78. return this._templatePortsHead({
  79. "dirStr": dir,
  80. "title": title,
  81. "texts": text,
  82. });
  83. }
  84.  
  85. getHtmlInputPorts(ports)
  86. {
  87. let html = "";
  88. let lastGroup = null;
  89.  
  90. for (let i = 0; i < ports.length; i++)
  91. {
  92. const opGroup = ports[i].uiAttribs.group;
  93. let startGroup = null;
  94. let groupSpacer = false;
  95.  
  96. if (!ports[i].uiAttribs.hideParam)
  97. {
  98. if (lastGroup != opGroup && !opGroup) groupSpacer = true;
  99.  
  100. if (lastGroup != opGroup)
  101. {
  102. groupSpacer = true;
  103. lastGroup = opGroup;
  104. startGroup = lastGroup;
  105. }
  106. }
  107.  
  108. ports[i].watchId = "in_" + i;
  109.  
  110. const tmplData = {
  111. "port": ports[i],
  112. "panelid": this._panelId,
  113. "startGroup": startGroup,
  114. "groupSpacer": groupSpacer,
  115. "dirStr": "in",
  116. "cablesUrl": CABLES.platform.getCablesUrl(),
  117. "openLocalFiles": CABLES.platform.frontendOptions.openLocalFiles,
  118. "portnum": i,
  119. "isInput": true,
  120. "op": ports[i].op,
  121. "texts": text,
  122. "vars": ports[i].op.patch.getVars(ports[i].type)
  123. };
  124.  
  125. html += this._templatePortGeneral(tmplData);
  126. html += this._templatePortInput(tmplData);
  127. html += this._templatePortGeneralEnd(tmplData);
  128. }
  129. return html;
  130. }
  131.  
  132. getHtmlOutputPorts(ports)
  133. {
  134. let foundPreview = false;
  135. let lastGroup = null;
  136. let html = "";
  137. for (const i in ports)
  138. {
  139. if (
  140. ports[i].getType() == CABLES.OP_PORT_TYPE_VALUE ||
  141. ports[i].getType() == CABLES.OP_PORT_TYPE_ARRAY ||
  142. ports[i].getType() == CABLES.OP_PORT_TYPE_STRING ||
  143. ports[i].getType() == CABLES.OP_PORT_TYPE_OBJECT)
  144. {
  145. ports[i].watchId = "out_" + i;
  146. }
  147.  
  148. let startGroup = null;
  149. let groupSpacer = false;
  150.  
  151. const opGroup = ports[i].uiAttribs.group;
  152.  
  153. if (lastGroup != opGroup && !opGroup) groupSpacer = true;
  154. if (lastGroup != opGroup)
  155. {
  156. groupSpacer = true;
  157. lastGroup = opGroup;
  158. startGroup = lastGroup;
  159. }
  160.  
  161.  
  162.  
  163. const tmplData = {
  164. "port": ports[i],
  165. "dirStr": "out",
  166. "panelid": this._panelId,
  167. "groupSpacer": groupSpacer,
  168. "startGroup": startGroup,
  169. "portnum": i,
  170. "isInput": false,
  171. "op": ports[i].op
  172. };
  173. html += this._templatePortGeneral(tmplData);
  174. html += this._templatePortOutput(tmplData);
  175. html += this._templatePortGeneralEnd(tmplData);
  176. }
  177.  
  178. return html;
  179. }
  180. }
  181.  
  182. export { PortHtmlGenerator };