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