Advertisement
rimomaguiar

Untitled

Oct 17th, 2022
55
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.66 KB | None | 0 0
  1. const dashboard = document.querySelector('.dashboard');
  2. const projectId = document.querySelector('.project_id');
  3. const btnFetchData = document.querySelector('.fetch_info');
  4.  
  5. const cache_clean = document.querySelector('.fetch_info_cacheclean');
  6. const cloud_dashboard = document.querySelector('.cloud_dashboard');
  7. const new_relic = document.querySelector('.new_relic');
  8. const swat = document.querySelector('.swat');
  9. const observation = document.querySelector('.observation');
  10. const clone = document.querySelector('.clone');
  11.  
  12. const notice = document.querySelector('.notice');
  13.  
  14. window.addEventListener('load', function() {
  15. cache_clean.style.display = 'none';
  16. cloud_dashboard.style.display = 'none';
  17. new_relic.style.display = 'none';
  18. swat.style.display = 'none';
  19. observation.style.display = 'none';
  20. clone.style.display = 'none';
  21. notice.style.display = 'block';
  22. })
  23.  
  24. btnFetchData.addEventListener('click', (e) => {
  25. dashboard.innerHTML = '';
  26. cache_clean.style.display = 'inline';
  27. cloud_dashboard.style.display = 'inline';
  28. new_relic.style.display = 'inline';
  29. swat.style.display = 'inline';
  30. observation.style.display = 'inline';
  31. clone.style.display = 'inline';
  32. notice.style.display = 'none';
  33.  
  34. requestData(projectId.value);
  35.  
  36. })
  37.  
  38. async function requestData(project_id) {
  39. var headers = new Headers();
  40. headers.append('Content-Type', 'application/json');
  41.  
  42. async function getMetadata() {
  43. const response = await fetch('http://localhost:8080/api/info/get_metadata', {
  44. method: 'GET',
  45. headers: headers,
  46. });
  47. const json = await response.json();
  48. return json;
  49. }
  50.  
  51. const metadata = await getMetadata();
  52. let infocheck = [];
  53. let content = [];
  54. let loader = [];
  55. for (let check in metadata) {
  56. infocheck[check] = document.createElement('div');
  57. infocheck[check].classList.add("infocheck");
  58. infocheck[check].innerHTML = '<div id="title" class="title"><h3>' + check.toUpperCase() + '</h3></div>';
  59. content[check] = document.createElement('div');
  60. content[check].classList.add("content");
  61. content[check].innerHTML = '<pre class="content">Loading</pre></div>';
  62. loader[check] = document.createElement('div');
  63. loader[check].classList.add("loader");
  64. content[check].appendChild(loader[check]);
  65. infocheck[check].appendChild(content[check]);
  66. dashboard.appendChild(infocheck[check]);
  67. }
  68.  
  69. var msnry = new Masonry(dashboard, {
  70. itemSelector: '.infocheck'
  71. });
  72.  
  73. for (let check in metadata) {
  74. const data = {
  75. "project_id": project_id,
  76. "action": [
  77. {
  78. "name": metadata[check].method
  79. }
  80. ]
  81. };
  82.  
  83. const response2 = await fetch('http://localhost:8080/api/info', {
  84. method: 'POST',
  85. headers: headers,
  86. body: JSON.stringify(data)
  87. }).then((resp) => resp.json()).then((response) => {
  88. content[check].innerHTML = '';
  89. loader[check].remove();
  90. item = response[0];
  91. if (isObject(item.result) || isArray(item.result)) {
  92. array_traverser_recursive(item.result, function (key, value) {
  93. if ( key == 'href' || key == 'http' || key == 'https' || key == 'ssh'){
  94. content[check].innerHTML += '<pre class="content"><a href="' + value + '" target= _blank>' + value + '</a></pre>';
  95. }else{
  96. content[check].innerHTML += '<pre class="content"><strong>'+key+':</strong> '+value+'</pre></div>';
  97. }
  98.  
  99. infocheck[check].appendChild(content[check]);
  100. });
  101. }else{
  102. content[check].innerHTML += '<pre class="content">'+item.result+'</pre></div>';
  103. infocheck[check].appendChild(content[check]);
  104. }
  105.  
  106. var msnry = new Masonry(dashboard, {
  107. itemSelector: '.infocheck'
  108. });
  109. });
  110. }
  111. }
  112.  
  113.  
  114.  
  115.  
  116.  
  117.  
  118.  
  119.  
  120. function array_traverser_recursive(array, callback) {
  121.  
  122. for (let item in array) {
  123. if (isObject(array[item]) || isArray(array[item])) {
  124. array_traverser_recursive(array[item], callback);
  125. } else {
  126. callback(item, array[item]);
  127. }
  128. }
  129. }
  130.  
  131. function isObject(obj)
  132. {
  133. return obj !== undefined && obj !== null && obj.constructor == Object;
  134. }
  135.  
  136. function isArray(array)
  137. {
  138. return array !== undefined && array !== null && array.constructor == Array;
  139. }
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement