-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathreport.js
152 lines (114 loc) · 4.36 KB
/
report.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
function sortingElementsByDate() {
var paragraphs = document.querySelectorAll("p");
const paragraphsWithDates = [];
paragraphs.forEach(paragraph => {
const dateStr = paragraph.id;
const date = new Date(dateStr);
paragraphsWithDates.push({ element: paragraph, date: date });
});
//sort the array by date
paragraphsWithDates.sort((a, b) => b.date - a.date);
paragraphsWithDates.forEach(item => {
document.body.appendChild(item.element);
});
}
async function fetchData() {
var snap = await db.collection("reports").get();
var results = [];
snap.forEach((doc) => {
results.push(doc.data());
});
return results;
}
fetchData().then((results) => {
console.log(results.length == 0);
if (results.length == 0) {
addReports = document.getElementById("addReports");
noData = document.createElement("p");
noData.setAttribute("style", "text-align : center");
noData.innerHTML = "No Reports Yet <br> Reports will appear here once added";
addReports.append(noData);
}
else {
for (var i = 0; i < results.length; i++) {
addReports = document.getElementById("addReports");
if (results[i].comments != "") {
for (var c = 0; c < results[i].comments.length; c++) {
reports = document.createElement("p");
str = results[i].comments[c];
stringArray = str.split('-');
date = stringArray[stringArray.length - 1];
reports.setAttribute("id", date);
reports.innerHTML =
"<strong>" +
stringArray[0][0].toUpperCase() + stringArray[0].slice(1) +
" Reported " +
date +
" </strong> " +
results[i].name +
". <strong> Report content: </strong> " +
stringArray[1];
console.log(reports);
addReports.append(reports);
}
}
if (results[i].description != "") {
for (var c = 0; c < results[i].description.length; c++) {
reports = document.createElement("p");
str = results[i].description[c];
stringArray = str.split('-');
date = stringArray[stringArray.length - 1];
reports.setAttribute("id", date);
reports.innerHTML =
"<strong> Description Reported " +
date +
" </strong> " +
results[i].name +
". <strong> Report content: </strong> " +
stringArray[0];
console.log(reports);
addReports.append(reports);
}
}
if (results[i].link != "") {
for (var c = 0; c < results[i].link.length; c++) {
reports = document.createElement("p");
str = results[i].link[c];
stringArray = str.split('-');
date = stringArray[stringArray.length - 1];
reports.setAttribute("id", date);
reports.innerHTML =
"<strong> Link Reported " +
date +
" </strong> " +
results[i].name +
". <strong> Report content: </strong> " +
stringArray[0];
console.log(reports);
addReports.append(reports);
}
}
if (results[i].tags != "") {
for (var c = 0; c < results[i].tags.length; c++) {
reports = document.createElement("p");
str = results[i].tags[c];
stringArray = str.split('-');
date = stringArray[stringArray.length - 1];
reports.setAttribute("id", date);
reports.innerHTML =
"<strong>" +
stringArray[0][0].toUpperCase() + stringArray[0].slice(1) +
" Reported " +
date +
" </strong> " +
results[i].name +
". <strong> Report content: </strong> " +
stringArray[1];
console.log(reports);
addReports.append(reports);
}
}
}}
sortingElementsByDate();
}
);