-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfirebaseapp.js
More file actions
116 lines (103 loc) · 3.88 KB
/
firebaseapp.js
File metadata and controls
116 lines (103 loc) · 3.88 KB
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
// FIREBASE AUTH
var firebaseConfig = {
apiKey: "AIzaSyCJuUb2TnP3EFw1IFYypHY6K8AUZpuiQeE",
authDomain: "api-project-797042688460.firebaseapp.com",
databaseURL: "https://api-project-797042688460.firebaseio.com",
projectId: "api-project-797042688460",
storageBucket: "api-project-797042688460.appspot.com",
messagingSenderId: "797042688460",
appId: "1:797042688460:web:f7948cf3ed0be9e9"
};
firebase.initializeApp(firebaseConfig);
var uiConfig = {
callbacks: {
signInSuccessWithAuthResult: function(authResult, redirectUrl) { // User successfully signed in.
return false;
}
},
credentialHelper: firebaseui.auth.CredentialHelper.NONE,
signInFlow: 'popup',
signInSuccessUrl: '#',
signInOptions: [firebase.auth.EmailAuthProvider.PROVIDER_ID],
// TODO Terms of service url/callback.
tosUrl: '<your-tos-url>',
// TODO Privacy policy url/callback.
privacyPolicyUrl: function() {
window.location.assign('<your-privacy-policy-url>');
}
};
var ui = new firebaseui.auth.AuthUI(firebase.auth());
ui.start('#firebaseui-auth-container', uiConfig);
var db = firebase.firestore();
firebase.auth().onAuthStateChanged(function(user) {
if (user) {
console.log(user);
document.getElementById('userIdInput').value = user.uid;
document.getElementById('userName').innerHTML = user.displayName;
document.getElementById('bodyContainer').style.display = "grid";
document.getElementById('firebaseui-auth-container').style.display = "none";
document.getElementsByTagName("BODY")[0].classList.remove("notSignedIn");
document.getElementById('welcomeDiv').style.display = "none";
$('#bodyContainer').fadeIn();
/*db.collection("projects").where("userId", "==", user.uid)
.get()
.then(function(querySnapshot) {
var projectCount = 0;
querySnapshot.forEach(function(doc) {
projectCount++;
doc = doc.data();
$('#projectsTable').append('<tr><td><i class="material-icons">book</i></td><td><span>' + doc.projectName + '</span><br /><div class="codePreview">' + doc.code + '</div></td></tr>');
});
if (projectCount !== 0) {
$('#projectsTable').show();
$('#noProjectsDiv').hide();
}
else {
$('#projectsTable').hide();
$('#noProjectsDiv').show();
}
$('#projects .spinIcon').hide();
})
.catch(function(error) {
console.log("Error getting documents");
});*/
} else {
/*document.getElementById('userIdInput').value = "";
document.getElementById('bodyContainer').style.display = "none";
document.getElementById('firebaseui-auth-container').style.display = "flex";
document.getElementsByTagName("BODY")[0].classList.add("notSignedIn");
document.getElementById('welcomeDiv').style.display = "flex";*/
}
});
// FIRESTORE
// JQUERY
document.getElementById('addProjectButton').onclick = function() { // TODO Create command for add project
db.collection("projects").add({
userId: document.getElementById('userIdInput').value,
projectName: document.getElementById('currProjNameInput').value,
code: document.getElementById('currWorkflowInput').value
})
.then(function(docRef) {
console.log("Document written with ID: ", docRef.id);
})
.catch(function(error) {
console.error("Error adding document: ", error);
});
};
/*document.getElementById('signOut').onclick = function() {
firebase.auth().signOut().then(function () {
document.getElementById('bodyContainer').style.display = "none";
document.getElementById('firebaseui-auth-container').style.display = "flex";
console.log("You signed out");
}).catch(function (error) {
console.log("You couldn't sign out");
});
};*/
document.getElementById('manualTextarea').oninput = function() {
var lines = document.getElementById('manualTextarea').value.split("\n").length;
var lineNumberHTML = "";
for (var l=1; l<=lines; l++) {
lineNumberHTML += l + "\n";
}
document.getElementById("lineNumbersTextarea").value = lineNumberHTML;
};