-
Notifications
You must be signed in to change notification settings - Fork 0
/
dashboard.html
254 lines (210 loc) · 9.83 KB
/
dashboard.html
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>mcf.db | Dashboard</title>
<script src="https://kit.fontawesome.com/4467197cc4.js" crossorigin="anonymous"></script>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Karla:wght@400;700;800&display=swap" rel="stylesheet">
<link rel="stylesheet" href="css/db.css">
</head>
<body>
<div id="header">
<div id="logo">
<img src="assets/logo_white.png">
<!-- <p id="logo-text">mcf.db</p> -->
</div>
<div id="cur-user">
<p id="logout">Logout</p>
<!-- <p id="cur-username"></p> -->
</div>
</div>
<div id="playground">
<!-- <div class="fb-card">
<div class="fb-details">
<p class="fb-rating"><b>Rating:</b> <i class="far fa-meh"></i></p>
<p class="fb-msg">
Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>
<p class="fb-email"><b>From:</b> <a href="mailto:ryanchong@u.nus.edu">ryanchong@u.nus.edu</a></p>
<div class="fb-topic" id="genreq">
<span class="fb-topic-cat">General Requests</span>
</div>
</div>
<div class="fb-options">
<button class="fb-done">Mark as done</button>
<button class="fb-delete">Archive</button>
</div>
</div> -->
</div>
</body>
<script type="module">
// Import the functions you need from the SDKs you need
import { initializeApp } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-app.js";
import { getDatabase, get, onValue, child, ref, set, push } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-database.js";
import { getAuth, signOut, signInWithPopup, GoogleAuthProvider } from "https://www.gstatic.com/firebasejs/9.0.2/firebase-auth.js";
// TODO: Add SDKs for Firebase products that you want to use
// https://firebase.google.com/docs/web/setup#available-libraries
// Your web app's Firebase configuration
const firebaseConfig = {
apiKey: "AIzaSyCn9v6eXCTzJw7z_OHfpH4NEOw8mEnU62g",
authDomain: "mc-feedback.firebaseapp.com",
databaseURL: "https://mc-feedback-default-rtdb.asia-southeast1.firebasedatabase.app",
projectId: "mc-feedback",
storageBucket: "mc-feedback.appspot.com",
messagingSenderId: "821071166410",
appId: "1:821071166410:web:e2d3283e7b87b590eced33"
}
// Initialize Firebase
const app = initializeApp(firebaseConfig)
const database = getDatabase(app)
function Card(logs) {
this.logs = logs
}
function assignColor(cat) {
var table = {
"sugg-fb": "sugg-fb",
"gen-queries": "genque",
"gen-requests": "genreq",
"acads": "acads",
"merch": "merch",
"events": "events",
"elections-recruitment": "elections-recruitment"
}
return table[cat]
}
function assignRating(rating) {
var table = {
1: `<i class="far fa-sad-tear"></i>`,
2: `<i class="far fa-meh"></i>`,
3: `<i class="far fa-meh-blank"></i>`,
4: `<i class="far fa-smile"></i>`,
5: `<i class="far fa-grin-beam"></i>`,
}
return table[rating]
}
function assignCategory(cat) {
var table = {
"sugg-fb": "Suggestions",
"gen-queries": "General Queries",
"gen-requests": "General Requests",
"acads": "Academics",
"merch": "Merchandise",
"events": "Events",
"elections-recruitment": "Recruitment"
}
return table[cat]
}
Card.prototype.addCard = function() {
var cardBox = document.createElement('div')
cardBox.classList += "fb-card"
var cardDetails = document.createElement('div')
cardDetails.classList += 'fb-details'
var fbRating = document.createElement('p')
fbRating.classList += 'fb-rating'
fbRating.innerHTML = "<b>Rating:</b> " + assignRating(this.logs['rating'])
var fbMsg = document.createElement('p')
fbMsg.classList += 'fb-msg'
fbMsg.innerHTML = this.logs['msg']
var fbEmail = document.createElement('p')
fbEmail.classList += 'fb-email'
fbEmail.innerHTML = this.logs['email'] === undefined ? "<b>From: </b> N/A" : "<b>From: </b> " + `<a href="mailto:${this.logs['email']}">${this.logs['email']}</a>`
var fbTopic = document.createElement('p')
fbTopic.classList += 'fb-topic'
fbTopic.id = assignColor(this.logs['category'])
var span = document.createElement('span')
span.classList += 'fb-topic-cat'
span.innerHTML = assignCategory(this.logs['category'])
fbTopic.appendChild(span)
cardDetails.appendChild(fbRating)
cardDetails.appendChild(fbMsg)
cardDetails.appendChild(fbEmail)
cardDetails.appendChild(fbTopic)
var cardOptions = document.createElement('div')
cardOptions.classList += 'fb-options'
var assignBtn = document.createElement('button')
assignBtn.classList += 'fb-done'
assignBtn.innerHTML = "Assign"
assignBtn.addEventListener('click', () => {
console.log("Assign to ...")
var body = "Hey!\n\nWe recently received this message via our feedback channel:\n\n"
+ `\"${this.logs['msg']}\"` + "\n\nWe believe you're the best person to handle this.\n\nBest regards!"
var title = "Re: Assignment of ComClub Feedback"
let email = window.prompt('Enter a destination email within NUS Computing Club: ')
if (email.length > 0 && email.includes("@")) {
window.open(`mailto:${email}?subject=${title}&body=${encodeURIComponent(body)}`)
} else {
window.alert("You have provided an invalid email. Please try again!")
}
})
var archiveBtn = document.createElement('button')
archiveBtn.classList += 'fb-archive'
archiveBtn.innerHTML = "Archive"
archiveBtn.addEventListener('click', () => {
console.log("Archiving " + this.logs['msg'])
const feedbackRef = ref(database, `/24MC/feedback/${this.logs['fid']}/`)
var updatedLogs = this.logs
updatedLogs['status'] = 'archived'
console.log(updatedLogs)
set(feedbackRef, updatedLogs).then(() => {
window.alert(`Selected feedback has been archived!!`)
playground.removeChild(cardBox)
})
})
cardOptions.appendChild(assignBtn)
cardOptions.appendChild(archiveBtn)
/**
* div.fb-card
* div.fb-details
* p.fb-rating
* p.fb-msg
* p.fb-email
* div.fb-topic
* span.fb-topic-cat
* div.fb-options
* btn.fb-archive
* btn.fb-assign
*/
cardBox.appendChild(cardDetails)
cardBox.appendChild(cardOptions)
playground.appendChild(cardBox)
}
console.log("app loaded")
const playground = document.getElementById("playground")
// const curUser = document.getElementById('cur-username')
const logout = document.getElementById('logout')
function loadFeedback() {
const feedbackRef = ref(database, '/24MC/feedback/')
get(feedbackRef).then((snapshot) => {
const data = snapshot.val()
const ids = Object.keys(data)
const logs = Object.values(data)
logs.forEach(child => {
if (child['status'] === 'active') {
var card = new Card(child)
card.addCard()
}
})
})
}
loadFeedback()
// const auth = getAuth()
// const user = auth.currentUser
// if (user !== null) {
// const displayName = user.displayName;
// curUser.innerHTML = displayName
// const email = user.email;
// }
logout.addEventListener('click', () => {
const auth = getAuth();
signOut(auth).then(() => {
window.location.href = "index.html"
}).catch((error) => {
console.log(error)
})
})
</script>
</html>