WfsJsRequestPanel.php 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413
  1. <?php
  2. // use Monolog\Handler\StreamHandler;
  3. // use Monolog\Formatter\JsonFormatter;
  4. Lib::loadClass('RouteBase');
  5. Lib::loadClass('P5');
  6. Lib::loadClass('Core_AclHelper');
  7. Lib::loadClass('ACL');
  8. Lib::loadClass('Api_WfsNs');
  9. class Route_WfsJsRequestPanel extends RouteBase {
  10. public function defaultAction() {
  11. UI::gora();
  12. try {
  13. $exampleProcesyFltr = [
  14. " <ogc:Filter>",
  15. " <ogc:Or>",
  16. " <ogc:PropertyIsEqualTo>",
  17. " <ogc:PropertyName>ID</ogc:PropertyName>",
  18. " <ogc:Literal>1003</ogc:Literal>",
  19. " </ogc:PropertyIsEqualTo>",
  20. " <ogc:PropertyIsEqualTo>",
  21. " <ogc:PropertyName>ID</ogc:PropertyName>",
  22. " <ogc:Literal>608</ogc:Literal>",
  23. " </ogc:PropertyIsEqualTo>",
  24. " </ogc:Or>",
  25. " </ogc:Filter>",
  26. ];
  27. $examples = [];
  28. $examples['Procesy'] = [];
  29. $examples['Procesy']['lvl1'] = [
  30. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  31. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  32. " <wfs:PropertyName>ID</wfs:PropertyName>",
  33. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  34. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  35. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  36. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  37. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  38. ];
  39. $examples['Procesy']['lvl2-by-@-1'] = [
  40. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  41. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  42. " <wfs:PropertyName>ID</wfs:PropertyName>",
  43. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  44. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  45. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  46. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"1\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  47. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  48. ];
  49. $examples['Procesy']['lvl2-by-@-2'] = [
  50. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  51. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  52. " <wfs:PropertyName>ID</wfs:PropertyName>",
  53. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  54. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  55. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  56. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"2\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  57. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  58. ];
  59. $examples['Procesy']['lvl2-by-@-3'] = [
  60. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  61. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  62. " <wfs:PropertyName>ID</wfs:PropertyName>",
  63. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  64. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  65. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  66. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  67. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  68. ];
  69. $examples['Procesy']['lvl2-by-@-*'] = [
  70. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  71. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  72. " <wfs:PropertyName>ID</wfs:PropertyName>",
  73. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  74. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  75. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  76. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"*\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  77. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  78. ];
  79. $examples['Procesy']['lvl2'] = [
  80. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  81. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  82. " <wfs:PropertyName>ID</wfs:PropertyName>",
  83. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  84. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  85. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  86. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  87. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  88. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  89. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  90. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  91. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  92. ];
  93. $examples['Procesy']['lvl2wsk'] = [
  94. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  95. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  96. " <wfs:PropertyName>ID</wfs:PropertyName>",
  97. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  98. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  99. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  100. " <wfs:PropertyName>OPIS</wfs:PropertyName>",
  101. " <wfs:PropertyName>path</wfs:PropertyName>",
  102. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  103. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  104. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  105. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  106. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  107. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK</wfs:PropertyName>",
  108. " <wfs:PropertyName>default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/*</wfs:PropertyName>",
  109. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  110. ];
  111. $examples['Procesy']['lvl3'] = [
  112. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  113. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  114. " <wfs:PropertyName>ID</wfs:PropertyName>",
  115. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  116. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  117. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  118. " <wfs:PropertyName>OPIS</wfs:PropertyName>",
  119. " <wfs:PropertyName>path</wfs:PropertyName>",
  120. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  121. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  122. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  123. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  124. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  125. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  126. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  127. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  128. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  129. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/*</wfs:PropertyName>",
  130. " <wfs:PropertyName>default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/*</wfs:PropertyName>",
  131. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  132. ];
  133. $examples['BiAudit'] = [];
  134. $examples['BiAudit']['BiAudit'] = [
  135. 'typeName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  136. 'args' => [ 'primaryKey' => 1 ],
  137. ];
  138. $examples['BiAudit']['BiAudit lvl2'] = [
  139. 'typeName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  140. 'postBody' => "<wfs:Query>" . implode("\n\t", [
  141. "<wfs:PropertyName>A_ADM_COMPANY</wfs:PropertyName>",
  142. "<wfs:PropertyName>A_CLASSIFIED</wfs:PropertyName>",
  143. "<wfs:PropertyName>A_STATUS</wfs:PropertyName>",
  144. "<wfs:PropertyName>A_STATUS_INFO</wfs:PropertyName>",
  145. "<wfs:PropertyName>BI_analiza_depth</wfs:PropertyName>",
  146. "<wfs:PropertyName>BI_analiza_reloadCache</wfs:PropertyName>",
  147. "<wfs:PropertyName>FILE_STATUS</wfs:PropertyName>",
  148. "<wfs:PropertyName>FILE_STATUS_info</wfs:PropertyName>",
  149. "<wfs:PropertyName>ID</wfs:PropertyName>",
  150. "<wfs:PropertyName>L_APPOITMENT_USER</wfs:PropertyName>",
  151. // "<wfs:PropertyName>default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY</wfs:PropertyName>",
  152. // "<wfs:PropertyName>default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI</wfs:PropertyName>",
  153. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"2\">default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row</wfs:PropertyName>",
  154. // "<wfs:PropertyName resolve=\"all\" resolveDepth=\"2\">default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person</wfs:PropertyName>",
  155. ]) . "\n" . "</wfs:Query>",
  156. ];
  157. $examples['BiAudit']['BiAudit lvl3'] = [
  158. 'typeName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  159. 'postBody' => "<wfs:Query>" . implode("\n\t", [
  160. "<wfs:PropertyName>A_ADM_COMPANY</wfs:PropertyName>",
  161. "<wfs:PropertyName>A_CLASSIFIED</wfs:PropertyName>",
  162. "<wfs:PropertyName>A_STATUS</wfs:PropertyName>",
  163. "<wfs:PropertyName>A_STATUS_INFO</wfs:PropertyName>",
  164. "<wfs:PropertyName>BI_analiza_depth</wfs:PropertyName>",
  165. "<wfs:PropertyName>BI_analiza_reloadCache</wfs:PropertyName>",
  166. "<wfs:PropertyName>FILE_STATUS</wfs:PropertyName>",
  167. "<wfs:PropertyName>FILE_STATUS_info</wfs:PropertyName>",
  168. "<wfs:PropertyName>ID</wfs:PropertyName>",
  169. "<wfs:PropertyName>L_APPOITMENT_USER</wfs:PropertyName>",
  170. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY</wfs:PropertyName>",
  171. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI</wfs:PropertyName>",
  172. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row</wfs:PropertyName>",
  173. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person</wfs:PropertyName>",
  174. ]) . "\n" . "</wfs:Query>",
  175. ];
  176. UI::startContainer();
  177. // Lib::loadClass('Vendor_Monolog');
  178. // $logger = new Vendor_Monolog('dbg-logger-name');
  179. // $logger->pushHandler(new StreamHandler('/tmp/monolog-test.log', Vendor_Monolog::WARNING));
  180. // $logger->warning('Foo');
  181. // $logger->error('Bar');
  182. //
  183. // $logFile = '/tmp/monolog-test-json.log';
  184. // $formatter = new JsonFormatter();
  185. // // Create a handler
  186. // $stream = new StreamHandler($logFile, Vendor_Monolog::INFO);
  187. // $stream->setFormatter($formatter);
  188. // // bind it to a logger object
  189. // $securityLogger = new Vendor_Monolog('View Info');
  190. // $securityLogger->pushHandler($stream);
  191. // $securityLogger->addInfo('debug message / label', [ 'dbg-object' => [ 'x' => 'y', 'z' ] ]);
  192. $namespace = V::get('namespace', '', $_GET);
  193. $defaultTypeName = ($namespace)
  194. ? Api_WfsNs::typeName($namespace)
  195. : $examples['Procesy']['lvl1']['typeName'];
  196. $defaultNamespace = Api_WfsNs::namespaceFromTypeName($defaultTypeName);
  197. $defaultRequestBody = ($namespace)
  198. ? ''
  199. : htmlspecialchars($examples['Procesy']['lvl1']['postBody']);
  200. // 'wfsRequestFeatureTypeName' = 'default_db__x3A__CRM_PROCES:PROCES'
  201. echo UI::h('table', [ 'style' => "width:100%; margin:0", 'class' => "table" ], [
  202. UI::h('tr', [], [
  203. UI::h('td', [ 'style' => "padding:0; border:none" ], [
  204. UI::h('input', [ 'id' => 'wfsRequestFeatureTypeName', 'class' => "form-control", 'value' => $defaultTypeName, 'title' => "Feature name" ]),
  205. ]),
  206. UI::h('td', [ 'style' => "width:5%; line-height:18px; border:none" ], [
  207. UI::h('a', [
  208. 'id' => "typeNameStorageStructLink",
  209. 'href' => "index.php?_route=Storage_AclStruct&namespace={$defaultNamespace}",
  210. ], "Struktura")
  211. ]),
  212. ])
  213. ]);
  214. echo UI::h('label', [], [
  215. " root ",
  216. UI::h('input', [ 'type' => "checkbox", 'id' => 'wfsRequestParam.root', 'class' => "", 'value' => '1' ]),
  217. ]);
  218. echo UI::h('label', [ 'style' => "margin-left:8px" ], [
  219. " maxFeatures: ",
  220. UI::h('input', [ 'type' => "number", 'id' => 'wfsRequestParam.maxFeatures', 'class' => "", 'value' => '3' ]),
  221. ]);
  222. echo UI::h('label', [ 'style' => "margin-left:8px" ], [
  223. " resolveDepth: ",
  224. UI::h('input', [ 'type' => "number", 'id' => 'wfsRequestParam.resolveDepth', 'class' => "", 'value' => '' ]),
  225. ]);
  226. echo UI::h('textarea', [ 'id' => 'wfsRequestBody', 'style' => "width:100%; height:300px" ], $defaultRequestBody);
  227. echo UI::h('button', [ 'class' => "btn btn-primary", 'onClick' => "return sendWfsRequest(this)" ], "Wyslij");
  228. echo UI::h('div', [ 'style' => "display:inline", 'id' => "wfs-example-btns" ]);
  229. echo UI::h('details', [ 'style' => "padding:6px; background-color:#333; color:#fff", 'open' => "open" ], [
  230. UI::h('summary', [ 'style' => "padding:0 3px; outline:none; cursor:pointer" ], [
  231. "WFS Response converted to JSON ",
  232. UI::h('button', [ 'class' => "btn btn-xs btn-default", 'onClick' => "return wfsResponseToggleTreeView(this)" ], "toggle tree view"),
  233. ]),
  234. UI::h('pre', [ 'id' => 'wfsResponse', 'style' => "margin:0; font-size:x-small; border-radius:0" ], 'loading...'),
  235. ]);
  236. echo UI::h('details', [ 'style' => "padding:6px; background-color:#68cbfd; color:#fff" ], [
  237. UI::h('summary', [ 'style' => "padding:0 3px; outline:none; cursor:pointer" ], [
  238. UI::h('i',[ 'class' => "glyphicon glyphicon-question-sign" ]),
  239. " WFS 1.1, 2.0 fetch nested objects (traverse, resolve)",
  240. ]),
  241. UI::h('pre', ['style' => "margin:0; font-size:x-small; border-radius:0"], implode("\n", [
  242. "WFS 1.1 - traverseXlinkDepth, traverseXlinkExpiry " . UI::h('a', ['href'=>"http://docs.opengeospatial.org/is/04-094r1/04-094r1.html#50"], "http://docs.opengeospatial.org/is/04-094r1/04-094r1.html#50"),
  243. "WFS 2.0 - resolve, resolveDepth, resolveTimeout " . UI::h('a', ['href'=>"http://docs.opengeospatial.org/is/09-025r2/09-025r2.html#57"], "http://docs.opengeospatial.org/is/09-025r2/09-025r2.html#57"),
  244. "",
  245. "WFS 1.1 traverseXlinkDepth type=\"string\" ('*' or int > 0) - recurse limit ('*' - no limit)",
  246. "WFS 1.1 traverseXlinkExpiry type=\"xsd:positiveInteger\" - timeOut in minutes",
  247. "WFS 1.1 Note: traverse used in wfs:GetFeature or inside wfs:Query tag wfs:XlinkPropertyName (same like wfs:PropertyName but with @traverse* attributes)",
  248. "",
  249. "WFS 2.0 resolve type=\"wfs:ResolveValueType\" default=\"none\" (enum: 'local', 'remote', 'all', 'none')",
  250. " - resolve=\"local\" - operation shall only resolve local references",
  251. " - resolve=\"remote\" - operation shall only resolve remote resource references",
  252. " - resolve=\"all\" - means that an operation shall resolve all resource references",
  253. " - resolve=\"none\" - means that an operation shall not resolve any resource references",
  254. "WFS 2.0 resolveDepth type=\"wfs:positiveIntegerWithStar\" default=\"*\" ('*' or int > 0) - recurse limit ('*' - no limit)",
  255. "WFW 2.0 resolveTimeout type=\"xsd:positiveInteger\" default=\"300\" - timeOut in seconds",
  256. "WFS 2.0 Note: resolve used in wfs:GetFeature or inside wfs:Query tag wfs:PropertyName",
  257. " in wfs:PropertyName may use resolvePath - @see " . UI::h('a', ['href'=>"http://docs.opengeospatial.org/is/09-025r2/09-025r2.html#103"], "http://docs.opengeospatial.org/is/09-025r2/09-025r2.html#103"),
  258. "",
  259. "WFS 2.0 resolve, resolveDepth example " . UI::h('a', ['href'=>"http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.ogc/ogc-schemas/2.2.0/ogc/wfs/2.0/examples/GetFeature/GetFeature_12.xml"], "http://grepcode.com/file/repo1.maven.org/maven2/org.jvnet.ogc/ogc-schemas/2.2.0/ogc/wfs/2.0/examples/GetFeature/GetFeature_12.xml"),
  260. ])),
  261. ]);
  262. UI::endContainer();
  263. echo UI::h('script', [], "
  264. var examples = " . json_encode($examples) . ";
  265. console.log('examples', examples)
  266. function setWfsExample(groupName, label) {
  267. console.log('groupName', groupName, 'label', label)
  268. var example = examples[groupName][label]
  269. var typeName = example.typeName
  270. document.getElementById('wfsRequestFeatureTypeName').value = typeName
  271. document.getElementById('typeNameStorageStructLink').href = 'index.php?_route=Storage_AclStruct&namespace=' + typeName.replace('__x3A__', '/').replace(':', '/')
  272. document.getElementById('wfsRequestBody').value = example.postBody || ''
  273. document.getElementById('wfsRequestParam.root').checked = (example.args && 'root' in example.args && 1 == example.args['root'])
  274. document.getElementById('wfsRequestParam.maxFeatures').value = (example.args && 'maxFeatures' in example.args && example.args['maxFeatures'] > 0) ? example.args['maxFeatures'] : 3
  275. document.getElementById('wfsRequestParam.resolveDepth').value = (example.args && 'resolveDepth' in example.args && example.args['resolveDepth'] > 0) ? example.args['resolveDepth'] : ''
  276. sendWfsRequest()
  277. }
  278. for (var groupName in examples) {
  279. for (var label in examples[groupName]) {
  280. jQuery(document.getElementById('wfs-example-btns')).append('<button class=\"btn btn-default\" style=\"margin-left:12px\" onClick=\"setWfsExample(\''+groupName+'\', \''+label+'\')\">'+label+'</button>')
  281. }
  282. }
  283. ");
  284. echo UI::h('script', [], "
  285. function sendWfsRequest() {
  286. var treeViewNode = document.getElementById('wfsResponseTreeView')
  287. if (treeViewNode) treeViewNode.parentNode.removeChild(treeViewNode)
  288. document.getElementById('wfsResponse').style.display = 'block'
  289. document.getElementById('wfsResponse').innerHTML = 'loading...'
  290. var featureTypeName = document.getElementById('wfsRequestFeatureTypeName').value
  291. var postBody = document.getElementById('wfsRequestBody').value.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
  292. var wfsParams = {
  293. 'maxFeatures': 3
  294. }
  295. if (document.getElementById('wfsRequestParam.root').checked) wfsParams['root'] = '1'
  296. if (document.getElementById('wfsRequestParam.maxFeatures')) wfsParams['maxFeatures'] = parseInt(document.getElementById('wfsRequestParam.maxFeatures').value)
  297. var resolveDepth = parseInt(document.getElementById('wfsRequestParam.resolveDepth').value)
  298. if (resolveDepth > 0 && !isNaN(resolveDepth)) {
  299. wfsParams['resolve'] = 'all'
  300. wfsParams['resolveDepth'] = resolveDepth
  301. }
  302. if (postBody) wfsParams['ogc:Filter'] = postBody
  303. console.log('p5WFS_GetFeature', featureTypeName, wfsParams)
  304. p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
  305. console.log('features', features)
  306. document.getElementById('wfsResponse').innerHTML = JSON.stringify(features, null, 2)
  307. }).catch(function (e) {
  308. console.warn(e)
  309. document.getElementById('wfsResponse').innerHTML = JSON.stringify(e, null, 2)
  310. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  311. })
  312. return false
  313. }
  314. (function () {
  315. console.log('p5WFS_GetFeature() ...')
  316. sendWfsRequest()
  317. })()
  318. ");
  319. echo UI::h('script', [], "
  320. var DBG = 0;
  321. function wfsResponseToggleTreeView(btnNode) {
  322. btnNode.isTreeViewActive = ! btnNode.isTreeViewActive
  323. if(DBG)console.log('btnNode.isTreeViewActive', btnNode.isTreeViewActive)
  324. if (btnNode.isTreeViewActive) {
  325. document.getElementById('wfsResponse').style.display = 'none'
  326. if (!document.getElementById('wfsResponseTreeView')) {
  327. var respTxtNode = document.getElementById('wfsResponse')
  328. var treeViewNode = document.createElement('div')
  329. treeViewNode.id = 'wfsResponseTreeView'
  330. treeViewNode.style.margin = '0'
  331. treeViewNode.style.padding = '9.5px'
  332. treeViewNode.style.border = '1px solid #ccc'
  333. treeViewNode.style.color = '#333'
  334. treeViewNode.style.backgroundColor = '#f5f5f5'
  335. treeViewNode.style.fontFamily = 'monospace'
  336. treeViewNode.style.fontSize = 'x-small'
  337. treeViewNode.style.lineHeight = '1.42857143'
  338. treeViewNode.style.wordBreak = 'break-all'
  339. treeViewNode.style.wordWrap = 'break-word'
  340. treeViewNode.innerHTML = parseJsonTextToTreeView(respTxtNode.innerHTML)
  341. respTxtNode.parentNode.insertBefore(treeViewNode, respTxtNode.nextSibling);
  342. }
  343. document.getElementById('wfsResponseTreeView').style.display = 'block'
  344. } else {
  345. var treeViewNode = document.getElementById('wfsResponseTreeView')
  346. if (treeViewNode) treeViewNode.parentNode.removeChild(treeViewNode)
  347. document.getElementById('wfsResponse').style.display = 'block'
  348. }
  349. }
  350. function parseJsonTextToTreeView(txtJson) {
  351. var out = ''
  352. var jsonLines = txtJson.split('\\n').map(function (line) {
  353. var whiteSpacePrefix = line.match(/^\s*/)[0].length
  354. return [ whiteSpacePrefix, line.substr(whiteSpacePrefix) ]
  355. })
  356. if(DBG)console.table(jsonLines)
  357. jsonLines = jsonLines.map(function (jsonLine) {
  358. if (jsonLine[1].length > 100) jsonLine[1] = jsonLine[1].substr(0, 100) + '...\"'
  359. return jsonLine
  360. })
  361. return generateTreeView(jsonLines)
  362. }
  363. function generateTreeView(jsonLines) {
  364. if (!jsonLines || !jsonLines.length) return ''
  365. out = ''
  366. if(DBG)console.log('----------------- group Childrens jsonLines:', jsonLines)
  367. groupedChildrens = jsonLines.reduce(function (grouped, cur, idx) {
  368. var last = grouped.pop()
  369. if (!last) {
  370. grouped.push({ deep: cur[0], label: cur[1], childrens: [] })
  371. if(DBG)console.log('groupedChildrens::(!last)', ' cur:[ '+cur[0]+', \"'+cur[1]+'\" ]')
  372. } else if (cur[0] > last.deep) {
  373. last.childrens.push([ cur[0] - 2, cur[1] ])
  374. grouped.push(last)
  375. if(DBG)console.log('groupedChildrens::(deep > cur[0])', ' cur:[ '+cur[0]+', \"'+cur[1]+'\" ]')
  376. } else if (cur[0] === last.deep) {
  377. var isEndOfObject = ([ ']', '],', '}', '},' ].indexOf(cur[1]) > -1)
  378. if (isEndOfObject && !last.childrens.length) last.label += ' ' + cur[1];
  379. grouped.push(last)
  380. if (!isEndOfObject) grouped.push({ deep: cur[0], label: cur[1], childrens: [] })
  381. // if (!isEndOfObject) console.log('groupedChildrens::(deep === cur[0] && !isEndOfObject)', ' cur:[ '+cur[0]+', \"'+cur[1]+'\" ]')
  382. if(DBG)console.log('groupedChildrens::(deep === cur[0])', ' cur:[ '+cur[0]+', \"'+cur[1]+'\" ]')
  383. }
  384. return grouped
  385. }, [])
  386. if(DBG)console.log('groupedChildrens', groupedChildrens)
  387. return groupedChildrens.map(function (group) {
  388. return (group.childrens.length > 0)
  389. ? '<details><summary style=\"outline:none; cursor:pointer\">' + group.label + '</summary><div style=\"padding:0 0 0 20px\">' + generateTreeView(group.childrens) + '</div></details>'
  390. : '<div style=\"padding:0 0 0 11px\">' + group.label + '</div>'
  391. }).join('\\n')
  392. }
  393. ");
  394. } catch (Exception $e) {
  395. UI::alert('danger', $e);
  396. }
  397. UI::dol();
  398. }
  399. }