RefGraph.php.view.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538
  1. // @require variables:
  2. if ('undefined' === typeof HTML_ID_REF_GRAPH) throw "Missing HTML_ID_REF_GRAPH";
  3. if ('undefined' === typeof TYPENAME) throw "Missing TYPENAME";
  4. if ('undefined' === typeof PRIMARY_KEY) throw "Missing PRIMARY_KEY";
  5. // if ('undefined' === typeof FUNCTION_FETCH_CHILDRENS) throw "Missing FUNCTION_FETCH_CHILDRENS";
  6. // if ('undefined' === typeof FUNCTION_FETCH_PARENTS) throw "Missing FUNCTION_FETCH_PARENTS";
  7. // if ('undefined' === typeof JS_CHANNEL_UPDATE_NAME) throw "Missing JS_CHANNEL_UPDATE_NAME";
  8. var DBG = DBG || 0;
  9. var _isFullScreen = true; // TODO: get from arg
  10. var _html = {
  11. container: null,
  12. top: null,
  13. fullscreenBtn: null,
  14. selected: null
  15. }
  16. var _nodes = new vis.DataSet(); // [ { id: '', label: '' }, ... ]
  17. var _edges = new vis.DataSet(); // [ { id: '', from: '', to: '' }, ... ]
  18. var _network = null; // graph object
  19. var _todoGraphData = [ { nodes: [], edges: [] } ]; // data by levels
  20. var _defaultWfsParams = {
  21. resolve: 'all',
  22. resolveDepth: 2,
  23. }
  24. if ('undefined' !== typeof WFS_URL) {
  25. _defaultWfsParams['WFS_URL'] = WFS_URL
  26. }
  27. var _defaultVisJsOptions = {
  28. nodes: {
  29. shape: 'box'
  30. },
  31. interaction: {
  32. dragNodes: false
  33. },
  34. physics: {
  35. enabled: false
  36. },
  37. layout: {
  38. hierarchical: {
  39. direction: 'LR',
  40. levelSeparation: 500, // hierarchical.levelSeparation Number 150 The distance between the different levels.
  41. nodeSpacing: 50, // hierarchical.nodeSpacing Number 100 Minimum distance between nodes on the free axis. This is only for the initial layout. If you enable physics, the node distance there will be the effective node distance.
  42. treeSpacing: 500, // hierarchical.treeSpacing Number 200 Distance between different trees (independent networks). This is only for the initial layout. If you enable physics, the repulsion model will denote the distance between the trees.
  43. sortMethod: 'directed'
  44. // hierarchical.enabled Boolean false Toggle the usage of the hierarchical layout system. If this option is not defined, it is set to true if any of the properties in this object are defined.
  45. // hierarchical.blockShifting Boolean true Method for reducing whitespace. Can be used alone or together with edge minimization. Each node will check for whitespace and will shift it's branch along with it for as far as it can, respecting the nodeSpacing on any level. This is mainly for the initial layout. If you enable physics, they layout will be determined by the physics. This will greatly speed up the stabilization time though!
  46. // hierarchical.edgeMinimization Boolean true Method for reducing whitespace. Can be used alone or together with block shifting. Enabling block shifting will usually speed up the layout process. Each node will try to move along its free axis to reduce the total length of it's edges. This is mainly for the initial layout. If you enable physics, they layout will be determined by the physics. This will greatly speed up the stabilization time though!
  47. // hierarchical.parentCentralization Boolean true When true, the parents nodes will be centered again after the the layout algorithm has been finished.
  48. // hierarchical.direction String 'UD' The direction of the hierarchical layout. The available options are: UD, DU, LR, RL. To simplify: up-down, down-up, left-right, right-left.
  49. // hierarchical.sortMethod String 'hubsize' The algorithm used to ascertain the levels of the nodes based on the data. The possible options are: hubsize, directed.
  50. //
  51. // Hubsize takes the nodes with the most edges and puts them at the top. From that the rest of the hierarchy is evaluated.
  52. //
  53. // Directed adheres to the to and from data of the edges. A --> B so B is a level lower than A.
  54. }
  55. }
  56. };
  57. function dataMakeNode(params) {
  58. var objectName = params.typeName.substr(params.typeName.indexOf(':') + 1)
  59. var nodeId = objectName + '.' + params.primaryKey // TODO: primaryKey?
  60. return {
  61. id: nodeId,
  62. label: makeShortLabel(nodeId), // TODO: get from schema assert @label attribute
  63. group: objectName,
  64. _loaded: true,
  65. typeName: params.typeName,
  66. primaryKey: params.primaryKey // TODO: _primaryKey
  67. }
  68. }
  69. function dataMakeEdge(parentNodeId, nodeObject) {
  70. return {
  71. id: parentNodeId + nodeObject.id,
  72. from: parentNodeId,
  73. to: nodeObject.id,
  74. }
  75. }
  76. function dataMakeXlinkNode(params) {
  77. var objectName = params.typeName.substr(params.typeName.indexOf(':') + 1)
  78. var nodeId = params.xlink.substr(params.xlink.indexOf('#') + 1)
  79. var primaryKey = nodeId.substr(nodeId.lastIndexOf('.') + 1)
  80. return {
  81. id: nodeId,
  82. label: makeShortLabel(nodeId) + ' (+)',
  83. group: objectName,
  84. _loaded: false,
  85. typeName: params.typeName,
  86. primaryKey: primaryKey
  87. }
  88. }
  89. function dataMakeFetchMoreNode(params) {
  90. // params = {
  91. // parentNodeId: parentNodeId,
  92. // type: json.type,
  93. // objectName: objectName,
  94. // ref: json,
  95. // }
  96. if(DBG)console.log('DBG dataMakeFetchMoreNode(params)', params)
  97. var nodeId = params.parentNodeId+'fetch-more-features-'+params.type+'-on-' + params.objectName;
  98. return {
  99. id: nodeId,
  100. label: 'Pobierz więcej (+)',
  101. group: 'fetch-more-data', // params.objectName,
  102. _loaded: false,
  103. _type: 'ref',
  104. parentNodeId: params.parentNodeId,
  105. ref: params.ref,
  106. // typeName: typeName,
  107. // primaryKey: nodeId.substr(nodeId.lastIndexOf('.') + 1)
  108. };
  109. }
  110. function dataMakeFetchMoreEdge(parentNodeId, fetchMoreNode) {
  111. // @param parentNodeId - from node id
  112. // @param fetchMoreNode - from dataMakeFetchMoreNode
  113. if(DBG)console.log('DBG dataMakeFetchMoreEdge(parentNodeId, fetchMoreNode)', {parentNodeId:parentNodeId, fetchMoreNode:fetchMoreNode})
  114. return {
  115. id: fetchMoreNode.id,
  116. from: parentNodeId,
  117. to: fetchMoreNode.id
  118. }
  119. }
  120. (function () {
  121. var form = document.getElementById('wfs_request')
  122. var featureTypeName = TYPENAME
  123. var wfsParams = Object.assign({}, _defaultWfsParams, {
  124. primaryKey: PRIMARY_KEY,
  125. })
  126. if(DBG)console.log('p5WFS_GetFeature', featureTypeName, wfsParams)
  127. p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
  128. if(DBG)console.log('features', features)
  129. updateWfsResponse(features, featureTypeName)
  130. }).catch(function (e) {
  131. if(DBG)console.warn(e)
  132. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  133. })
  134. renderLayout()
  135. })();
  136. function updateWfsResponse(features, featureTypeName) {
  137. if(DBG)console.log('updateWfsResponse', { features: features, featureTypeName: featureTypeName })
  138. // if (_network !== null) {
  139. // _network.destroy();
  140. // _network = null;
  141. // }
  142. parseResponseRec(_todoGraphData, features, featureTypeName)
  143. var _graphData = {
  144. nodes: _nodes,
  145. edges: _edges,
  146. };
  147. _todoGraphData.forEach(function (levelData, levelIdx) {
  148. if (levelData.nodes && levelData.nodes.length) {
  149. levelData.nodes.forEach(function (node) {
  150. try {
  151. _nodes.add(node)
  152. } catch (e) {
  153. if(DBG)console.log('_graphData.nodes.add [level='+levelIdx+'] error:', e);
  154. }
  155. })
  156. }
  157. if (levelData.edges && levelData.edges.length) {
  158. levelData.edges.forEach(function (edge) {
  159. try {
  160. _edges.add(edge)
  161. } catch (e) {
  162. if(DBG)console.log('_graphData.edges.add [level='+levelIdx+'] error:', e);
  163. }
  164. })
  165. }
  166. })
  167. _todoGraphData = [ { nodes: [], edges: [] } ]; // clear to default values
  168. var options = _defaultVisJsOptions
  169. if(DBG)console.log('_graphData', _graphData)
  170. if (!_network) {
  171. _network = new vis.Network(_html['container'], _graphData, options); // graphData: { nodes: [], edges: [] }
  172. // add event listeners
  173. _network.on('selectNode', function (params) {
  174. if(DBG)console.log('Selection: ', params.nodes)
  175. var featureID = params.nodes[0]
  176. if (!featureID) return;
  177. if ('-loading' === featureID.substr(-1 * '-loading'.length)) {
  178. // TODO: gui msg...
  179. if(DBG)console.log('loading nodes connected with: "' +featureID.substr(0, featureID.length - '-loading'.length) + '" ...')
  180. return;
  181. }
  182. var selectedNode = _nodes.get(featureID)
  183. if(DBG)console.log('Selection: selectedNode:', selectedNode)
  184. if (!selectedNode) return;
  185. if ('ref' === selectedNode._type) {
  186. fetchNodeMoreRefs(selectedNode, featureID)
  187. } else {
  188. renderSelectedNode(selectedNode)
  189. if (selectedNode._loaded) return;
  190. fetchNodeRecurse(selectedNode, featureID)
  191. }
  192. });
  193. }
  194. }
  195. function isP5LinkObject(json) {
  196. if ( !('type' in json) || !json['type'] ) return false;
  197. if ( !('value' in json) || !json['value'] ) return false;
  198. if ( !('@typeName' in json) || !json['@typeName'] ) return false;
  199. if ( !('@startIndex' in json) || !json['@startIndex'] ) return false;
  200. if ( !('@backRefPK' in json) || !json['@backRefPK'] ) return false;
  201. if ( !('@backRefNS' in json) || !json['@backRefNS'] ) return false;
  202. return true;
  203. }
  204. function parseResponseRec(_todoGraphData, json, typeName, parentNodeId, level) {
  205. var level = level || 0
  206. var parentNodeId = parentNodeId || null
  207. if(DBG)console.log('DBG::parseResponseRec', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
  208. if (p5Utils__isArray(json)) {
  209. // TODO: create named group
  210. var isXlinkList = (json.length > 0 && p5Utils__isString(json[0]))
  211. json.forEach(function (subJson) {
  212. if (isXlinkList) {
  213. parseResponseXlinkListRec(_todoGraphData, subJson, typeName, parentNodeId, level)
  214. } else {
  215. parseResponseRec(_todoGraphData, subJson, typeName, parentNodeId, level)
  216. }
  217. })
  218. } else if (p5Utils__isObject(json) && isP5LinkObject(json)) {
  219. if(DBG)console.log('DBG::parseResponseRec isP5LinkObject');
  220. parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
  221. } else if (p5Utils__isObject(json)) {
  222. // _todoGraphData.nodes.add({ id: nodeId, label: nodeId })
  223. if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
  224. var nodeObject = dataMakeNode({
  225. typeName: typeName,
  226. primaryKey: (json['ID']) ? json['ID'] : null, // TODO: get primaryKey from object
  227. })
  228. var nodeId = nodeObject.id
  229. _todoGraphData[level].nodes.push(nodeObject)
  230. if (parentNodeId) {
  231. _todoGraphData[level].edges.push(dataMakeEdge(parentNodeId, nodeObject))
  232. }
  233. Object.keys(json).filter(function (fieldName) {
  234. return (fieldName.indexOf(':') > -1)
  235. })
  236. .forEach(function (fieldName) {
  237. var value = json[fieldName]
  238. parseResponseRec(_todoGraphData, value, fieldName, nodeId, level + 1)
  239. })
  240. } else if (p5Utils__isString(json)) {
  241. if(DBG)console.log('TODO: Not implemented - parseResponseRec isString');
  242. } else {
  243. if(DBG)console.log('TODO: Not implemented - parseResponseRec is not string, not array and not object');
  244. }
  245. }
  246. function parseResponseXlinkListRec(_todoGraphData, json, typeName, parentNodeId, level) {
  247. if(DBG)console.log('DBG::parseResponseRec:XlinkList', {json:json, typeName:typeName, parentNodeId:parentNodeId, isString: p5Utils__isString(json), isArray: p5Utils__isArray(json), isObject: p5Utils__isObject(json)});
  248. if (p5Utils__isString(json)) { // xlink "https://biuro.biall-net.pl/wfs/default_db/BI_audit_ENERGA_RUM_KONTRAHENCI#BI_audit_ENERGA_RUM_KONTRAHENCI.9233",
  249. var nodeId = json.substr(json.indexOf('#') + 1)
  250. {
  251. // _graphData.nodes.add({ id: nodeId, label: nodeId })
  252. if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
  253. var nodeObject = dataMakeXlinkNode({
  254. xlink: json,
  255. typeName: typeName,
  256. primaryKey: (json['ID']) ? json['ID'] : null, // TODO: get primaryKey from object
  257. })
  258. _todoGraphData[level].nodes.push(nodeObject)
  259. if (parentNodeId) {
  260. _todoGraphData[level].edges.push(dataMakeEdge(parentNodeId, nodeObject))
  261. }
  262. }
  263. } else if (p5Utils__isObject(json) && isP5LinkObject(json)) {
  264. parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level)
  265. } else {
  266. if(DBG)console.log('TODO: Not implemented - parseResponseRec:XlinkList is not string and not object');
  267. }
  268. }
  269. function parseResponseP5Link(_todoGraphData, json, typeName, parentNodeId, level) {
  270. if(DBG)console.log('parseResponseRec isObject and P5Link - fetch more xlink object');
  271. // example json: { type: "next",
  272. // @backRefNS: "default_db/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA/BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA",
  273. // @backRefPK: "42",
  274. // @typeName: "default_db__x3A__BI_audit_ENERGA_RUM_KONTRAHENCI_P…ow:BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row",
  275. // @startIndex: "10" }
  276. if (!parentNodeId) throw "Missing parentNodeId for ref link object";
  277. var objectName = typeName.substr(typeName.indexOf(':') + 1)
  278. {
  279. // _graphData.nodes.add({ id: nodeId, label: nodeId })
  280. if (!_todoGraphData[level]) _todoGraphData[level] = { nodes: [], edges: [] }
  281. switch (json.type) {
  282. case 'next': {
  283. var nodeObject = dataMakeFetchMoreNode({
  284. parentNodeId: parentNodeId,
  285. type: json.type,
  286. objectName: objectName,
  287. ref: json,
  288. })
  289. _todoGraphData[level].nodes.push(nodeObject)
  290. _todoGraphData[level].edges.push(dataMakeFetchMoreEdge(parentNodeId, nodeObject))
  291. } break;
  292. default: {
  293. if(DBG)console.log('TODO: Not implemented - parseResponseRec isObject with type "'+json.type+'" - fetch more xlink object');
  294. }
  295. }
  296. }
  297. }
  298. function fetchNodeMoreRefs(selectedNode, featureID) {
  299. try {
  300. if (!selectedNode) throw "Missing featureID"
  301. if (!featureID) throw "Missing featureID"
  302. if (!selectedNode.ref) throw "Missing selectedNode.ref"
  303. var idSelectedNode = selectedNode.id
  304. var idSelectedEdge = selectedNode.id
  305. var parentNodeId = selectedNode.parentNodeId
  306. var featureTypeName = selectedNode.ref['@typeName']
  307. var backRefNS = selectedNode.ref['@backRefNS']
  308. var backRefPK = selectedNode.ref['@backRefPK']
  309. var backRefField = selectedNode.ref['@typeName']
  310. var startIndex = selectedNode.ref['@startIndex']
  311. _nodes.update({
  312. id: idSelectedNode,
  313. label: "Pobieranie danych..."
  314. })
  315. var wfsParams = {
  316. backRefNS: backRefNS,
  317. backRefPK: backRefPK,
  318. backRefField: backRefField,
  319. startIndex: startIndex,
  320. maxFeatures: 10,
  321. };
  322. p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
  323. if(DBG)console.log('features', features)
  324. if (!features.length) throw "Brak danych"
  325. features.forEach(function (feature) {
  326. // TODO: validate
  327. var objectName = featureTypeName.substr(featureTypeName.indexOf(':') + 1)
  328. var nodeId = objectName + '.' + feature.ID // TODO: primaryKey?
  329. _todoGraphData[0].edges.push({ id: parentNodeId + nodeId, from: parentNodeId, to: nodeId })
  330. })
  331. // var refFields = Object.keys(features[0]).filter(function (fieldName) {
  332. // return (fieldName.indexOf(':') > -1)
  333. // }).filter(function (fieldName) {
  334. // return (features[0][fieldName].length > 0)
  335. // })
  336. // if (!refFields.length) return "Brak danych"
  337. // features = features.map(function (feature) {
  338. // return {
  339. // feature
  340. // }
  341. // })
  342. // console.log('TODO: features: ', features);
  343. // updateWfsResponse(features[0], featureTypeName) // TODO: RMME DBG
  344. // updateWfsResponse(features[1], featureTypeName) // TODO: RMME DBG
  345. // var feature = features[1]
  346. // var nodeId = featureTypeName + '.' + feature['ID']
  347. // try {
  348. // _edges.add({
  349. // id: parentNodeId + nodeId,
  350. // from: parentNodeId,
  351. // to: nodeId
  352. // })
  353. // } catch (e) {
  354. // if(DBG)console.warn('TODO: XXX: ' + e)
  355. // }
  356. features.forEach(function (feature) {
  357. updateWfsResponse(feature, featureTypeName)
  358. })
  359. var nodeSelectedData = _nodes.get(idSelectedNode)
  360. var edgeSelectedData = _nodes.get(idSelectedEdge)
  361. _nodes.remove({ id: idSelectedNode })
  362. _edges.remove({ id: idSelectedEdge })
  363. if (features.length >= 10) {
  364. var nodeObject = dataMakeFetchMoreNode({
  365. parentNodeId: nodeSelectedData.parentNodeId,
  366. type: nodeSelectedData.type,
  367. objectName: nodeSelectedData.objectName,
  368. ref: Object.assign(nodeSelectedData.ref, {
  369. '@startIndex': (10 + parseInt(startIndex)),
  370. value: nodeSelectedData.ref.value.replace('startIndex=' + startIndex, 'startIndex=' + (10 + parseInt(startIndex)))
  371. })
  372. })
  373. _nodes.add(nodeObject)
  374. _edges.add(dataMakeFetchMoreEdge(parentNodeId, nodeObject))
  375. }
  376. return "Pobrano nowe dane"
  377. }).then(function (msg) {
  378. p5UI__notifyAjaxCallback({ type: 'info', msg: msg })
  379. }).catch(function (e) {
  380. if(DBG)console.warn(e)
  381. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  382. _nodes.remove({ id: idSelectedNode })
  383. _edges.remove({ id: idSelectedEdge })
  384. })
  385. } catch (e) {
  386. if(DBG)console.warn(e)
  387. }
  388. }
  389. function fetchNodeRecurse(selectedNode, featureID) {
  390. try {
  391. var selectedNodeId = selectedNode.id
  392. if (!selectedNode) throw "Missing featureID"
  393. if (!featureID) throw "Missing featureID"
  394. var featureEx = featureID.split('.')
  395. if (2 !== featureEx.length) throw "Not supported featureID format"
  396. var featureTypeName = 'default_db__x3A__' + featureEx[0] + ':' + featureEx[0]
  397. var wfsParams = Object.assign({}, _defaultWfsParams, {
  398. primaryKey: featureEx[1]
  399. });
  400. // view-source:http://visjs.org/examples/network/data/dynamicData.html
  401. _nodes.update({
  402. id: featureID,
  403. label: makeShortLabel(selectedNodeId) + ' ...'
  404. })
  405. p5WFS_GetFeature(featureTypeName, wfsParams).then(function (features) {
  406. if(DBG)console.log('features', features)
  407. if (!features.length || 1 !== features.length) throw "Brak danych" // require 1 feature with recurse
  408. var refFields = Object.keys(features[0]).filter(function (fieldName) {
  409. return (fieldName.indexOf(':') > -1)
  410. }).filter(function (fieldName) {
  411. return (features[0][fieldName].length > 0)
  412. })
  413. if (!refFields.length) return "Brak danych"
  414. updateWfsResponse(features, featureTypeName)
  415. return "Pobrano nowe dane"
  416. }).then(function (msg) {
  417. p5UI__notifyAjaxCallback({ type: 'info', msg: msg })
  418. _nodes.update({ id: featureID, label: makeShortLabel(selectedNodeId), _loaded: true })
  419. }).catch(function (e) {
  420. if(DBG)console.warn(e)
  421. p5UI__notifyAjaxCallback({ type: 'error', msg: e })
  422. _nodes.update({ id: featureID, label: makeShortLabel(selectedNodeId), _loaded: true })
  423. })
  424. } catch (e) {
  425. if(DBG)console.warn(e)
  426. }
  427. }
  428. function makeShortLabel(label) { // TODO: shorter name
  429. // BI_audit_ENERGA_RUM_KONTRAHENCI_POWIAZANIA_row_object.1234567
  430. if (label.length < 30) return label;
  431. var exLabel = label.split('.')
  432. if (exLabel.length !== 2) return label;
  433. return exLabel[0].substr(0, 24) + '...' + exLabel[0].substr(-10) + '.' + exLabel[1];
  434. }
  435. function renderLayout(mode) {
  436. if ('undefined' !== typeof mode && _isFullScreen !== mode) _isFullScreen = mode
  437. // create a network
  438. if (!_html['container']) {
  439. _html['container'] = document.getElementById(HTML_ID_REF_GRAPH)
  440. }
  441. _html['container'].style.position = (_isFullScreen) ? 'fixed' : 'relative'
  442. _html['container'].style.top = (_isFullScreen) ? '40px' : ''
  443. _html['container'].style.left = '0px'
  444. _html['container'].style.margin = '0'
  445. _html['container'].style.border = (_isFullScreen) ? '0' : '1px solid silver'
  446. _html['container'].style.padding = '0'
  447. _html['container'].style.backgroundColor = '#fff'
  448. _html['container'].style.height = (_isFullScreen) ? ''+(window.innerHeight-40)+'px' : ''+(window.innerHeight-60-_html['container'].offsetTop)+'px'
  449. _html['container'].style.width = (_isFullScreen) ? '' + (window.innerWidth) + 'px' : '100%'
  450. if (!_html['top']) {
  451. _html['top'] = document.createElement('div')
  452. _html['container'].parentNode.insertBefore(_html['top'], _html['container'].nextSibling)
  453. }
  454. _html['top'].style.position = (_isFullScreen) ? 'fixed' : 'relative'
  455. _html['top'].style.top = '0px'
  456. _html['top'].style.left = '0px'
  457. _html['top'].style.margin = '0'
  458. _html['top'].style.border = '0'
  459. _html['top'].style.padding = '0'
  460. _html['top'].style.backgroundColor = '#101010'
  461. _html['top'].style.height = '40px'
  462. _html['top'].style.width = (_isFullScreen) ? '' + (window.innerWidth) + 'px' : '100%'
  463. _html['top'].style.zIndex = 3
  464. if (!_html['fullscreenBtn']) {
  465. _html['fullscreenBtn'] = document.createElement('button')
  466. _html['fullscreenBtn'].className = 'btn btn-lg btn-link'
  467. _html['top'].appendChild(_html['fullscreenBtn'])
  468. _html['fullscreenBtn'].style.color = '#fff'
  469. _html['fullscreenBtn'].style.float = 'right'
  470. _html['fullscreenBtn'].style.outline = 'none'
  471. _html['fullscreenBtn'].addEventListener('click', function () {
  472. _isFullScreen = !_isFullScreen
  473. renderLayout()
  474. })
  475. }
  476. _html['fullscreenBtn'].innerHTML = (_isFullScreen)
  477. ? '<i class="glyphicon glyphicon-resize-small" title="Zamknij pełny ekran"></i>'
  478. : '<i class="glyphicon glyphicon-resize-full" title="Pełny ekran"></i>'
  479. ;
  480. if (!_html['selected']) {
  481. _html['selected'] = document.createElement('span')
  482. var htmlSelectedWrap = document.createElement('div')
  483. htmlSelectedWrap.style.color = '#fff'
  484. htmlSelectedWrap.style.fontSize = '14px'
  485. htmlSelectedWrap.style.lineHeight = '40px'
  486. htmlSelectedWrap.style.paddingLeft = '12px'
  487. htmlSelectedWrap.appendChild(document.createTextNode("Wybrany: "))
  488. htmlSelectedWrap.appendChild(_html['selected'])
  489. _html['top'].appendChild(htmlSelectedWrap)
  490. _html['selected'].innerHTML = 'brak'
  491. }
  492. }
  493. function renderSelectedNode(node) {
  494. var gotToTableLink = (node.typeName)
  495. ? '<a href="index.php?_route=ViewTableAjax&namespace=' + node.typeName.replace('__x3A__', '/').replace(':', '/') + '" class="btn btn-link" style="color:#fff" title="Przejdź do tabeli ' + node.typeName + '">' +
  496. '<i class="glyphicon glyphicon-list-alt"></i>' +
  497. '</a>'
  498. : ''
  499. ;
  500. var editLink = (node.typeName && node.primaryKey)
  501. ? '<a href="index.php?_route=ViewTableAjax&namespace=' + node.typeName.replace('__x3A__', '/').replace(':', '/') + '#EDIT/' + node.primaryKey + '" class="btn btn-link" style="color:#fff" title="Edytuj rekord ' + node.primaryKey + '">' +
  502. '<i class="glyphicon glyphicon-pencil"></i>' +
  503. '</a>'
  504. : ''
  505. ;
  506. _html['selected'].innerHTML = '' + node.id + ' ' + gotToTableLink + ' ' + editLink;
  507. }
  508. // global['FUNCTION_FETCH_CHILDRENS'] = 'refGraphFetchChildrens'
  509. // global['FUNCTION_FETCH_PARENTS'] = 'refGraphFetchParents'
  510. // global['_nodes'] = _nodes // TODO: DBG
  511. // global['_edges'] = _edges // TODO: DBG