|
@@ -0,0 +1,46 @@
|
|
1
|
+var articles;
|
|
2
|
+axios.get(`http://localhost:5000/articles`)
|
|
3
|
+ .then(response => {
|
|
4
|
+ articles = response.data;
|
|
5
|
+ for (let i = 0; i < articles.length; i++) {
|
|
6
|
+ let element = articles[i];
|
|
7
|
+ axios.get(`http://localhost:5000/articles/${element}`)
|
|
8
|
+ .then(response => {
|
|
9
|
+ let articlesHeading = document.querySelector("#articles-heading").parentElement;
|
|
10
|
+ let articleButton = document.createElement("button");
|
|
11
|
+ articleButton.textContent = response.data;
|
|
12
|
+
|
|
13
|
+ articleButton.classList.add("m-5", "article-content");
|
|
14
|
+ articleButton.setAttribute("data-toggle", "modal");
|
|
15
|
+ articleButton.setAttribute("data-target", `#articleModal${i}`);
|
|
16
|
+
|
|
17
|
+ let modal = document.createElement("div");
|
|
18
|
+ modal.classList.add("modal", "fade");
|
|
19
|
+ modal.setAttribute("id", `articleModal${i}`);
|
|
20
|
+ modal.setAttribute("tabindex", "-1");
|
|
21
|
+ modal.setAttribute("aria-labelledby", `articleModalLabel${i}`);
|
|
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="articleModalLabel${i}">${element}</h5>
|
|
28
|
+ <button type="button" class="close" data-dismiss="modal" aria-label="Close">
|
|
29
|
+ <span aria-hidden="true">×</span>
|
|
30
|
+ </button>
|
|
31
|
+ </div>
|
|
32
|
+ <div class="modal-body">
|
|
33
|
+ ${response.data}
|
|
34
|
+ </div>
|
|
35
|
+ <div class="modal-footer">
|
|
36
|
+ <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
|
|
37
|
+ </div>
|
|
38
|
+ </div>
|
|
39
|
+ </div>`;
|
|
40
|
+ document.body.appendChild(modal);
|
|
41
|
+ articlesHeading.appendChild(articleButton);
|
|
42
|
+ })
|
|
43
|
+ .catch(error => console.error(error));
|
|
44
|
+ }
|
|
45
|
+ })
|
|
46
|
+ .catch(error => console.error(error));
|