-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCode.gs
54 lines (42 loc) · 1.81 KB
/
Code.gs
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
function onOpen() {
SpreadsheetApp.getUi().createMenu('Import Data').addItem('Import Data', 'ImportFromFirestore').addToUi();
}
function getFirestore() {
return FirestoreApp.getFirestore(/* CONFIG GOES HERE */)
}
function ImportFromFirestore() {
const firestore = getFirestore()
const allDocuments = firestore.query('TUG_stopwatch').OrderBy("time", "desc").Execute().map(function(document) {
return document.fields;
});
const first = allDocuments[0]
const ss = SpreadsheetApp.getActiveSpreadsheet()
const sheet = ss.getSheetByName('User Data')
sheet.activate()
sheet.clearContents()
sheet.appendRow(['Name', 'UID', 'Time (1st Time)', 'Timetaken 1', 'Time (2nd Time)', 'Timetaken 2'])
allDocuments.forEach(function(document) {
var done = false;
try {const row = [document.name.stringValue, document.uid.stringValue, document.Time_fmt.stringValue, document.timetaken_c1.stringValue, document.Time_fmt_2.stringValue, document.timetaken_c2.stringValue]
sheet.appendRow(row);
done = true;}
catch (e) {
console.error('error: ' + e);
}
if (!done) {
const row = [document.name.stringValue, document.uid.stringValue, document.Time_fmt.stringValue, document.timetaken_c1.stringValue, 'Not Available', document.timetaken_c2.stringValue]
sheet.appendRow(row);
}
})
const allFeedback = firestore.query('feedback').OrderBy("time", "desc").Execute().map(function(doc) {
return doc.fields; })
const f = allFeedback[0]
const s = ss.getSheetByName('Feedback')
s.activate()
s.clearContents()
s.appendRow(['Name', 'UID', 'Time', 'Feedback'])
allFeedback.forEach(function(feedback) {
const r = [feedback.name.stringValue, feedback.uid.stringValue, feedback.time_fmt.stringValue, feedback.feedback.stringValue]
s.appendRow(r)
})
}