WfsJsRequestPanel.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434
  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. $jsFunction = [];
  14. $jsFunction['JS_FUNCTION_UPDATE_RESPONSE'] = 'updateWfsResponse';
  15. $jsFunction['JS_FUNCTION_GET_SELECTED_FORMAT'] = 'getWfsResponseFormat';
  16. $jsFunction['JS_CHANNEL_UPDATE_NAME'] = 'wfsPanel';
  17. $exampleProcesyFltr = [
  18. " <ogc:Filter>",
  19. " <ogc:Or>",
  20. " <ogc:PropertyIsEqualTo>",
  21. " <ogc:PropertyName>ID</ogc:PropertyName>",
  22. " <ogc:Literal>1003</ogc:Literal>",
  23. " </ogc:PropertyIsEqualTo>",
  24. " <ogc:PropertyIsEqualTo>",
  25. " <ogc:PropertyName>ID</ogc:PropertyName>",
  26. " <ogc:Literal>608</ogc:Literal>",
  27. " </ogc:PropertyIsEqualTo>",
  28. " </ogc:Or>",
  29. " </ogc:Filter>",
  30. ];
  31. $examples = [];
  32. $examples['Procesy'] = [];
  33. $examples['Procesy']['lvl1'] = [
  34. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  35. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  36. " <wfs:PropertyName>ID</wfs:PropertyName>",
  37. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  38. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  39. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  40. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  41. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  42. ];
  43. $examples['Procesy']['lvl2-by-@-1'] = [
  44. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  45. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  46. " <wfs:PropertyName>ID</wfs:PropertyName>",
  47. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  48. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  49. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  50. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"1\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  51. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  52. ];
  53. $examples['Procesy']['lvl2-by-@-2'] = [
  54. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  55. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  56. " <wfs:PropertyName>ID</wfs:PropertyName>",
  57. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  58. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  59. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  60. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"2\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  61. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  62. ];
  63. $examples['Procesy']['lvl2-by-@-3'] = [
  64. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  65. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  66. " <wfs:PropertyName>ID</wfs:PropertyName>",
  67. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  68. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  69. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  70. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  71. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  72. ];
  73. $examples['Procesy']['lvl2-by-@-*'] = [
  74. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  75. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  76. " <wfs:PropertyName>ID</wfs:PropertyName>",
  77. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  78. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  79. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  80. " <wfs:PropertyName resolve=\"all\" resolveDepth=\"*\">default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  81. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  82. ];
  83. $examples['Procesy']['lvl2'] = [
  84. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  85. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  86. " <wfs:PropertyName>ID</wfs:PropertyName>",
  87. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  88. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  89. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  90. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  91. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  92. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  93. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  94. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  95. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  96. ];
  97. $examples['Procesy']['lvl2wsk'] = [
  98. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  99. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  100. " <wfs:PropertyName>ID</wfs:PropertyName>",
  101. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  102. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  103. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  104. " <wfs:PropertyName>OPIS</wfs:PropertyName>",
  105. " <wfs:PropertyName>path</wfs:PropertyName>",
  106. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  107. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  108. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  109. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  110. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  111. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK</wfs:PropertyName>",
  112. " <wfs:PropertyName>default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/*</wfs:PropertyName>",
  113. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  114. ];
  115. $examples['Procesy']['lvl3'] = [
  116. 'typeName' => 'default_db__x3A__CRM_PROCES:PROCES',
  117. 'postBody' => "<wfs:Query>" . "\n" . implode("\n", array_merge([
  118. " <wfs:PropertyName>ID</wfs:PropertyName>",
  119. " <wfs:PropertyName>PARENT_ID</wfs:PropertyName>",
  120. " <wfs:PropertyName>TYPE</wfs:PropertyName>",
  121. " <wfs:PropertyName>DESC</wfs:PropertyName>",
  122. " <wfs:PropertyName>OPIS</wfs:PropertyName>",
  123. " <wfs:PropertyName>path</wfs:PropertyName>",
  124. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  125. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  126. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  127. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  128. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/ID</wfs:PropertyName>",
  129. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/PARENT_ID</wfs:PropertyName>",
  130. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/TYPE</wfs:PropertyName>",
  131. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/DESC</wfs:PropertyName>",
  132. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_PROCES:PROCES</wfs:PropertyName>",
  133. " <wfs:PropertyName>default_db__x3A__CRM_PROCES:PROCES/default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/*</wfs:PropertyName>",
  134. " <wfs:PropertyName>default_db__x3A__CRM_WSKAZNIK:CRM_WSKAZNIK/*</wfs:PropertyName>",
  135. ], $exampleProcesyFltr)) . "\n" ."</wfs:Query>",
  136. ];
  137. $examples['BiAudit'] = [];
  138. $examples['BiAudit']['BiAudit'] = [
  139. 'typeName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  140. 'args' => [ 'primaryKey' => 1 ],
  141. ];
  142. $examples['BiAudit']['BiAudit lvl2'] = [
  143. 'typeName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  144. 'postBody' => "<wfs:Query>" . implode("\n\t", [
  145. "<wfs:PropertyName>A_ADM_COMPANY</wfs:PropertyName>",
  146. "<wfs:PropertyName>A_CLASSIFIED</wfs:PropertyName>",
  147. "<wfs:PropertyName>A_STATUS</wfs:PropertyName>",
  148. "<wfs:PropertyName>A_STATUS_INFO</wfs:PropertyName>",
  149. "<wfs:PropertyName>BI_analiza_maxDepth</wfs:PropertyName>",
  150. "<wfs:PropertyName>BI_analiza_reloadCache</wfs:PropertyName>",
  151. "<wfs:PropertyName>FILE_STATUS</wfs:PropertyName>",
  152. "<wfs:PropertyName>FILE_STATUS_info</wfs:PropertyName>",
  153. "<wfs:PropertyName>ID</wfs:PropertyName>",
  154. "<wfs:PropertyName>L_APPOITMENT_USER</wfs:PropertyName>",
  155. // "<wfs:PropertyName>default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY</wfs:PropertyName>",
  156. // "<wfs:PropertyName>default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI</wfs:PropertyName>",
  157. "<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>",
  158. // "<wfs:PropertyName resolve=\"all\" resolveDepth=\"2\">default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person</wfs:PropertyName>",
  159. ]) . "\n" . "</wfs:Query>",
  160. ];
  161. $examples['BiAudit']['BiAudit lvl3'] = [
  162. 'typeName' => 'default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA',
  163. 'postBody' => "<wfs:Query>" . implode("\n\t", [
  164. "<wfs:PropertyName>A_ADM_COMPANY</wfs:PropertyName>",
  165. "<wfs:PropertyName>A_CLASSIFIED</wfs:PropertyName>",
  166. "<wfs:PropertyName>A_STATUS</wfs:PropertyName>",
  167. "<wfs:PropertyName>A_STATUS_INFO</wfs:PropertyName>",
  168. "<wfs:PropertyName>BI_analiza_maxDepth</wfs:PropertyName>",
  169. "<wfs:PropertyName>BI_analiza_reloadCache</wfs:PropertyName>",
  170. "<wfs:PropertyName>FILE_STATUS</wfs:PropertyName>",
  171. "<wfs:PropertyName>FILE_STATUS_info</wfs:PropertyName>",
  172. "<wfs:PropertyName>ID</wfs:PropertyName>",
  173. "<wfs:PropertyName>L_APPOITMENT_USER</wfs:PropertyName>",
  174. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_ENERGA_PRACOWNICY:BI_audit_ENERGA_PRACOWNICY</wfs:PropertyName>",
  175. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI:BI_audit_ENERGA_RUM_KONTRAHENCI</wfs:PropertyName>",
  176. "<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>",
  177. "<wfs:PropertyName resolve=\"all\" resolveDepth=\"3\">default_db__x3A__BI_audit_KW_requested_person:BI_audit_KW_requested_person</wfs:PropertyName>",
  178. ]) . "\n" . "</wfs:Query>",
  179. ];
  180. UI::startContainer();
  181. // Lib::loadClass('Vendor_Monolog');
  182. // $logger = new Vendor_Monolog('dbg-logger-name');
  183. // $logger->pushHandler(new StreamHandler('/tmp/monolog-test.log', Vendor_Monolog::WARNING));
  184. // $logger->warning('Foo');
  185. // $logger->error('Bar');
  186. //
  187. // $logFile = '/tmp/monolog-test-json.log';
  188. // $formatter = new JsonFormatter();
  189. // // Create a handler
  190. // $stream = new StreamHandler($logFile, Vendor_Monolog::INFO);
  191. // $stream->setFormatter($formatter);
  192. // // bind it to a logger object
  193. // $securityLogger = new Vendor_Monolog('View Info');
  194. // $securityLogger->pushHandler($stream);
  195. // $securityLogger->addInfo('debug message / label', [ 'dbg-object' => [ 'x' => 'y', 'z' ] ]);
  196. $namespace = V::get('namespace', '', $_GET);
  197. $defaultTypeName = ($namespace)
  198. ? Api_WfsNs::typeName($namespace)
  199. : $examples['Procesy']['lvl1']['typeName'];
  200. $defaultNamespace = Api_WfsNs::namespaceFromTypeName($defaultTypeName);
  201. $defaultRequestBody = ($namespace)
  202. ? ''
  203. : htmlspecialchars($examples['Procesy']['lvl1']['postBody']);
  204. // 'wfsRequestFeatureTypeName' = 'default_db__x3A__CRM_PROCES:PROCES'
  205. echo UI::h('form', [ 'id' => "wfs_request" ], [
  206. UI::h('div', [ 'style' => "margin-bottom:6px; padding:6px; background-color:#333; color:#fff" ], [
  207. UI::h('table', [ 'style' => "width:100%; margin:0 0 6px 0", 'class' => "table" ], [
  208. UI::h('tr', [], [
  209. UI::h('td', [ 'style' => "width:5%; padding:0 10px 0 0; border:none; line-height:22px; font-size:14px; white-space:nowrap" ], "WFS Request"),
  210. UI::h('td', [ 'style' => "padding:0; border:none" ], [
  211. UI::h('input', [ 'name' => "type_name", 'id' => 'wfsRequestFeatureTypeName', 'class' => "form-control input-xs", 'value' => $defaultTypeName, 'title' => "Feature name" ]),
  212. ]),
  213. UI::h('td', [ 'style' => "width:5%; padding:3px 0 0 6px; line-height:16px; border:none" ], [
  214. UI::h('a', [
  215. 'id' => "typeNameStorageStructLink",
  216. 'href' => "index.php?_route=Storage_AclStruct&namespace={$defaultNamespace}",
  217. 'style' => "color:#68cbfd"
  218. ], "Struktura")
  219. ]),
  220. ])
  221. ]),
  222. UI::h('div', [], [
  223. UI::h('label', [ 'style' => "font-weight:normal" ], [
  224. " root ",
  225. UI::h('input', [ 'name' => "root", 'type' => "checkbox", 'class' => "", 'value' => '1' ]),
  226. ]),
  227. UI::h('label', [ 'style' => "margin-left:8px; font-weight:normal" ], [
  228. " maxFeatures: ",
  229. UI::h('input', [ 'name' => "maxFeatures", 'type' => "number", 'class' => "form-control input-xs", 'style' => "display:inline-block; width:100px", 'value' => '3' ]),
  230. ]),
  231. UI::h('label', [ 'style' => "margin-left:8px; font-weight:normal" ], [
  232. " resolveDepth: ",
  233. UI::h('input', [ 'name' => "resolveDepth", 'type' => "number", 'class' => "form-control input-xs", 'style' => "display:inline-block; width:100px", 'value' => '' ]),
  234. ]),
  235. UI::h('label', [ 'style' => "margin-left:8px; font-weight:normal" ], [
  236. " primaryKey: ",
  237. UI::h('input', [ 'name' => "primaryKey", 'type' => "text", 'class' => "form-control input-xs", 'style' => "display:inline-block; width:100px", 'value' => '' ]),
  238. ]),
  239. ]),
  240. UI::h('details', [ 'style' => "padding:0; background-color:#333; color:#fff", 'open' => "open" ], [
  241. UI::h('summary', [ 'style' => "padding:0 3px; margin-bottom:6px; outline:none; cursor:pointer" ], [
  242. UI::h('span', [ 'style' => "margin-right:6px" ], "Request Body"),
  243. UI::h('label', [ 'style' => "margin-right:6px; cursor:pointer; font-weight:normal", 'onclick' => "return onClickBodyType(event, this, 'ogc:Filter')" ], [
  244. UI::h('input', [ 'type' => "radio", 'name' => "wfs_post_body_type", 'value' => "ogc:Filter", 'style' => "margin-right:6px", 'checked' => "checked" ]),
  245. UI::h('span', [ 'style' => "margin-right:6px" ], "ogc:Filter"),
  246. ]),
  247. UI::h('label', [ 'style' => "margin-right:6px; cursor:pointer; font-weight:normal", 'onclick' => "return onClickBodyType(event, this, 'graphql:query')" ], [
  248. UI::h('input', [ 'type' => "radio", 'name' => "wfs_post_body_type", 'value' => "graphql:query", 'style' => "margin-right:6px" ]),
  249. UI::h('span', [ 'style' => "margin-right:6px" ], "graphql:query"),
  250. ]),
  251. ]),
  252. UI::h('textarea', [ 'id' => 'wfsRequestBody', 'style' => "width:100%; height:300px; color:#000" ], $defaultRequestBody),
  253. ]),
  254. ]),
  255. ]);
  256. echo UI::h('div', [ 'style' => "margin-bottom:6px" ], [
  257. UI::h('button', [ 'class' => "btn btn-primary", 'onClick' => "return sendWfsRequest(this)" ], "Wyslij"),
  258. UI::h('div', [ 'style' => "display:inline", 'id' => "wfs-example-btns" ]),
  259. ]);
  260. echo UI::h('details', [ 'style' => "padding:6px; background-color:#333; color:#fff", 'open' => "open" ], [
  261. UI::h('summary', [ 'style' => "padding:0 3px; outline:none; cursor:pointer" ], [
  262. "WFS Response <i>(converted to JSON)</i> ",
  263. UI::h('form', [ 'id' => "wfs_response_format", 'style' => "display:inline" ], [
  264. UI::h('label', [ 'style' => "margin-right:6px; cursor:pointer; font-weight:normal", 'onclick' => "return onClickResponseFormat(event, this, 'text')" ], [
  265. UI::h('input', [ 'type' => "radio", 'name' => "wfs_post_response_format", 'value' => "text", 'style' => "margin-right:6px", 'checked' => "checked" ]),
  266. UI::h('span', [ 'style' => "margin-right:6px" ], "text"),
  267. ]),
  268. UI::h('label', [ 'style' => "margin-right:6px; cursor:pointer; font-weight:normal", 'onclick' => "return onClickResponseFormat(event, this, 'json')" ], [
  269. UI::h('input', [ 'type' => "radio", 'name' => "wfs_post_response_format", 'value' => "json", 'style' => "margin-right:6px" ]),
  270. UI::h('span', [ 'style' => "margin-right:6px" ], "json tree"),
  271. ]),
  272. ]),
  273. ]),
  274. UI::h('pre', [ 'id' => 'wfsResponse', 'style' => "margin:0; font-size:x-small; border-radius:0" ], 'loading...'),
  275. ]);
  276. echo UI::h('details', [ 'style' => "padding:6px; background-color:#68cbfd; color:#fff" ], [
  277. UI::h('summary', [ 'style' => "padding:0 3px; outline:none; cursor:pointer" ], [
  278. UI::h('i',[ 'class' => "glyphicon glyphicon-question-sign" ]),
  279. " WFS 1.1, 2.0 fetch nested objects (traverse, resolve)",
  280. ]),
  281. UI::h('pre', ['style' => "margin:0; font-size:x-small; border-radius:0"], implode("\n", [
  282. "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"),
  283. "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"),
  284. "",
  285. "WFS 1.1 traverseXlinkDepth type=\"string\" ('*' or int > 0) - recurse limit ('*' - no limit)",
  286. "WFS 1.1 traverseXlinkExpiry type=\"xsd:positiveInteger\" - timeOut in minutes",
  287. "WFS 1.1 Note: traverse used in wfs:GetFeature or inside wfs:Query tag wfs:XlinkPropertyName (same like wfs:PropertyName but with @traverse* attributes)",
  288. "",
  289. "WFS 2.0 resolve type=\"wfs:ResolveValueType\" default=\"none\" (enum: 'local', 'remote', 'all', 'none')",
  290. " - resolve=\"local\" - operation shall only resolve local references",
  291. " - resolve=\"remote\" - operation shall only resolve remote resource references",
  292. " - resolve=\"all\" - means that an operation shall resolve all resource references",
  293. " - resolve=\"none\" - means that an operation shall not resolve any resource references",
  294. "WFS 2.0 resolveDepth type=\"wfs:positiveIntegerWithStar\" default=\"*\" ('*' or int > 0) - recurse limit ('*' - no limit)",
  295. "WFW 2.0 resolveTimeout type=\"xsd:positiveInteger\" default=\"300\" - timeOut in seconds",
  296. "WFS 2.0 Note: resolve used in wfs:GetFeature or inside wfs:Query tag wfs:PropertyName",
  297. " 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"),
  298. "",
  299. "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"),
  300. ])),
  301. ]);
  302. UI::endContainer();
  303. echo UI::h('script', [ 'src' => 'static/postal.min.js' ]);
  304. UI::inlineJS(__FILE__ . '.updateResponseView.js', [
  305. // 'NODE_ID_TREE_VIEW_FROM_TEXT' => "wfsResponseTreeView",
  306. 'NODE_ID_TREE_VIEW_FROM_JSON' => "jsonResponseTreeView",
  307. 'NODE_ID_WFS_RESPONSE' => "wfsResponse",
  308. 'JS_FUNCTION_UPDATE_RESPONSE' => $jsFunction['JS_FUNCTION_UPDATE_RESPONSE'],
  309. 'JS_FUNCTION_GET_SELECTED_FORMAT' => $jsFunction['JS_FUNCTION_GET_SELECTED_FORMAT'],
  310. 'JS_CHANNEL_UPDATE_NAME' => $jsFunction['JS_CHANNEL_UPDATE_NAME'],
  311. ]);
  312. echo UI::h('div', [ 'id' => "ref_graph_node", 'style' => "width:100%; height:300px; border:1px solid silver; margin:10px; padding:0" ]);
  313. echo UI::h('script', [ 'src' => "static/visjs/vis.min.js" ]);
  314. echo UI::h('style', [ 'type' => "text/css", 'src' => "static/visjs/vis.min.css" ]);
  315. // echo UI::h('script', [ 'src' => "static/cytoscape.min.js" ]);
  316. // echo UI::h('script', [ 'src' => "static/cola.min.js" ]);
  317. // echo UI::h('script', [ 'src' => "static/cytoscape-cola.js" ]);
  318. // UI::inlineJS(__FILE__ . '.refGraph-cytoscape-cola.js', [
  319. UI::inlineJS(__FILE__ . '.refGraph.js', [
  320. 'FUNCTION_FETCH_CHILDRENS' => 'refGraphFetchChildrens',
  321. 'FUNCTION_FETCH_PARENTS' => 'refGraphFetchParents',
  322. 'HTML_ID_REF_GRAPH' => 'ref_graph_node',
  323. // 'NODE_ID_TREE_VIEW_FROM_TEXT' => "wfsResponseTreeView",
  324. // 'NODE_ID_TREE_VIEW_FROM_JSON' => "jsonResponseTreeView",
  325. // 'NODE_ID_WFS_RESPONSE' => "wfsResponse",
  326. // 'JS_FUNCTION_UPDATE_RESPONSE' => $jsFunction['JS_FUNCTION_UPDATE_RESPONSE'],
  327. // 'JS_FUNCTION_GET_SELECTED_FORMAT' => $jsFunction['JS_FUNCTION_GET_SELECTED_FORMAT'],
  328. 'JS_CHANNEL_UPDATE_NAME' => $jsFunction['JS_CHANNEL_UPDATE_NAME'],
  329. 'DBG' => (V::get('DBG', 0, $_GET, 'int') > 0),
  330. ]);
  331. echo UI::h('script', [], "
  332. function onClickBodyType(event, n, setBodyType) {
  333. if ('INPUT' === event.target.tagName) {
  334. return true
  335. }
  336. n.form['wfs_post_body_type'].value = setBodyType
  337. return false
  338. }
  339. function onClickResponseFormat(event, n, setFormat) {
  340. if ('INPUT' === event.target.tagName) {
  341. return true
  342. }
  343. n.form['wfs_post_response_format'].value = setFormat
  344. {$jsFunction['JS_FUNCTION_UPDATE_RESPONSE']}()
  345. return false
  346. }
  347. function {$jsFunction['JS_FUNCTION_GET_SELECTED_FORMAT']}() {
  348. return document.getElementById('wfs_response_format')['wfs_post_response_format'].value
  349. }
  350. ");
  351. echo UI::h('script', [], "
  352. var examples = " . json_encode($examples) . ";
  353. console.log('examples', examples)
  354. function setWfsExample(groupName, label) {
  355. console.log('groupName', groupName, 'label', label)
  356. var example = examples[groupName][label]
  357. var typeName = example.typeName
  358. document.getElementById('wfsRequestFeatureTypeName').value = typeName
  359. document.getElementById('typeNameStorageStructLink').href = 'index.php?_route=Storage_AclStruct&namespace=' + typeName.replace('__x3A__', '/').replace(':', '/')
  360. document.getElementById('wfsRequestBody').value = example.postBody || ''
  361. var form = document.getElementById('wfs_request')
  362. form['root'].checked = (example.args && 'root' in example.args && 1 == example.args['root'])
  363. form['maxFeatures'].value = (example.args && 'maxFeatures' in example.args && example.args['maxFeatures'] > 0) ? example.args['maxFeatures'] : 3
  364. form['resolveDepth'].value = (example.args && 'resolveDepth' in example.args && example.args['resolveDepth'] > 0) ? example.args['resolveDepth'] : ''
  365. form['primaryKey'].value = (example.args && 'primaryKey' in example.args && example.args['primaryKey'].length > 0) ? example.args['primaryKey'] : ''
  366. sendWfsRequest()
  367. }
  368. for (var groupName in examples) {
  369. for (var label in examples[groupName]) {
  370. jQuery(document.getElementById('wfs-example-btns')).append('<button class=\"btn btn-default\" style=\"margin-left:12px\" onClick=\"setWfsExample(\''+groupName+'\', \''+label+'\')\">'+label+'</button>')
  371. }
  372. }
  373. ");
  374. echo UI::h('script', [], "
  375. function sendWfsRequest() {
  376. {$jsFunction['JS_FUNCTION_UPDATE_RESPONSE']}('loading...')
  377. var postBody = document.getElementById('wfsRequestBody').value.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
  378. var form = document.getElementById('wfs_request')
  379. var featureTypeName = form['type_name'].value
  380. var wfsParams = Object.assign({ maxFeatures: 3 },
  381. (form['root'] && form['root'].checked && '1' === form['root'].value) ? { root: 1 } : {},
  382. (postBody && form['wfs_post_body_type'] && 'ogc:Filter' === form['wfs_post_body_type'].value) ? {
  383. 'ogc:Filter': document.getElementById('wfsRequestBody').value.replace(/&lt;/g, '<').replace(/&gt;/g, '>')
  384. } : {},
  385. (postBody && form['wfs_post_body_type'] && 'graphql:query' === form['wfs_post_body_type'].value) ? {
  386. 'graphql:query': document.getElementById('wfsRequestBody').value
  387. } : {},
  388. (form['maxFeatures'] && form['maxFeatures'].value > 0) ? { maxFeatures: parseInt(form['maxFeatures'].value) } : {},
  389. (form['resolveDepth'] && form['resolveDepth'].value > 0) ? {
  390. resolve: 'all',
  391. resolveDepth: ('*' === form['resolveDepth'].value) ? '*' : parseInt(form['resolveDepth'].value)
  392. } : {},
  393. (form['primaryKey'] && form['primaryKey'].value) ? { primaryKey: form['primaryKey'].value } : {}
  394. )
  395. console.log('p5WFS_GetFeature', featureTypeName, wfsParams)
  396. p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
  397. console.log('features', features)
  398. {$jsFunction['JS_FUNCTION_UPDATE_RESPONSE']}(features, featureTypeName)
  399. }).catch(function (e) {
  400. console.warn(e)
  401. {$jsFunction['JS_FUNCTION_UPDATE_RESPONSE']}(''+e)
  402. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  403. })
  404. return false
  405. }
  406. (function () {
  407. console.log('p5WFS_GetFeature() ...')
  408. sendWfsRequest()
  409. })()
  410. ");
  411. } catch (Exception $e) {
  412. UI::alert('danger', $e);
  413. }
  414. UI::dol();
  415. }
  416. }