No Description

fetch_articles.js 5.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. function get_articles(single = false) {
  2. var articles;
  3. axios.get("http://136.145.231.32:8080/")
  4. .then(response => {
  5. articles = response.data;
  6. if (single) {
  7. let artName = articles[articles.length - 1];
  8. let artNameNoExt = artName.substr(0, artName.lastIndexOf()) || artName;
  9. axios.get(`http://136.145.231.32:8080/${artName}`)
  10. .then(response => {
  11. let homeArticleParent = document.querySelector("#home-article")
  12. let articleButton = document.createElement("button");
  13. articleButton.textContent = response.data;
  14. articleButton.classList.add("m-5", "article-content");
  15. articleButton.setAttribute("data-toggle", "modal");
  16. articleButton.setAttribute("data-target", "#homeArticleModal");
  17. let modal = document.createElement("div");
  18. modal.classList.add("modal", "fade");
  19. modal.setAttribute("id", "homeArticleModal");
  20. modal.setAttribute("tabindex", "-1");
  21. modal.setAttribute("aria-labelledby", "homeArticleModalLabel");
  22. modal.setAttribute("aria-hidden", "true");
  23. modal.innerHTML = `
  24. <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg">
  25. <div class="modal-content">
  26. <div class="modal-header">
  27. <h5 class="modal-title" id="homeArticleModal">${artNameNoExt}</h5>
  28. <button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
  29. <span aria-hidden="true">&times;</span>
  30. </button>
  31. </div>
  32. <div class="modal-body">
  33. <p>${response.data}</p>
  34. </div>
  35. <div class="modal-footer">
  36. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
  37. </div>
  38. </div>
  39. </div>`;
  40. document.body.appendChild(modal);
  41. homeArticleParent.appendChild(articleButton);
  42. })
  43. .catch(error => console.log(error));
  44. }
  45. else {
  46. for (let i = 0; i < articles.length; i++) {
  47. let element = articles[i];
  48. let elementNoExt = element.substr(0, element.lastIndexOf('.')) || element;
  49. axios.get(`http://136.145.231.32:8080/${element}`)
  50. .then(response => {
  51. let articlesHeading = document.querySelector("#articles-heading").parentElement;
  52. let articleButton = document.createElement("button");
  53. articleButton.textContent = response.data;
  54. articleButton.classList.add("m-5", "article-content");
  55. articleButton.setAttribute("data-toggle", "modal");
  56. articleButton.setAttribute("data-target", `#articleModal${i}`);
  57. let modal = document.createElement("div");
  58. modal.classList.add("modal", "fade");
  59. modal.setAttribute("id", `articleModal${i}`);
  60. modal.setAttribute("tabindex", "-1");
  61. modal.setAttribute("aria-labelledby", `articleModalLabel${i}`);
  62. modal.setAttribute("aria-hidden", "true");
  63. modal.innerHTML = `
  64. <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable modal-lg">
  65. <div class="modal-content">
  66. <div class="modal-header">
  67. <h5 class="modal-title" id="articleModalLabel${i}">${elementNoExt}</h5>
  68. <button type="button" class="close" data-dismiss="modal" aria-label="Cerrar">
  69. <span aria-hidden="true">&times;</span>
  70. </button>
  71. </div>
  72. <div class="modal-body">
  73. <p>${response.data}</p>
  74. </div>
  75. <div class="modal-footer">
  76. <button type="button" class="btn btn-secondary" data-dismiss="modal">Cerrar</button>
  77. </div>
  78. </div>
  79. </div>`;
  80. document.body.appendChild(modal);
  81. articlesHeading.appendChild(articleButton);
  82. })
  83. .catch(error => console.error(error));
  84. }
  85. }
  86. })
  87. .catch(error => console.error(error));
  88. }