WfsJsRequestPanel.php 24 KB

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