-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprofile.html
executable file
·360 lines (308 loc) · 12.4 KB
/
profile.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
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
<!DOCTYPE html>
<html lang="en" >
<head>
<script src="https://cdn.firebase.com/js/client/2.2.9/firebase.js"></script>
<!--<script>var Firebase = require("firebase");</script>-->
<meta charset="utf-8" />
<meta name="author" content="Script Tutorials" />
<title>Study With Me | My Profile</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<link rel="shortcut icon" href="images/people.png" type="image">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/font-awesome/4.4.0/css/font-awesome.min.css">
<link href='https://fonts.googleapis.com/css?family=Montserrat:400,700' rel='stylesheet' type='text/css'>
<script src='https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js'></script>
<!-- attach CSS styles -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/profile.css" rel="stylesheet" />
<link rel='stylesheet' href='https://cdn.firebase.com/libs/firechat/2.0.0/firechat.min.css' />
<script src='./firechat/dist/firechat.js'></script>
<!-- liveReload - So developers dont have to hit the refresh button. Delete in production version -->
<!--<script>document.write('<script src="http://' + (location.host || 'localhost').split(':')[0] + ':35729/livereload.js?snipver=1"></' + 'script>')</script>-->
</head>
<body>
<!-- navigation panel -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target="#navbar-collapse-main">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="profile.html">Welcome, <span class="fname">User</span>!</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse-main">
<ul class="nav navbar-nav navbar-right">
<li><a href="profile.html">My Profile</a></li>
<li><a href="settings.html">Settings</a></li>
<li><a href="index.html" onclick="disconnect()">Sign Out</a></li>
</ul>
</div><!-- /.navbar-collapse -->
</div><!-- /.container-fluid -->
</nav>
<!-- first section - Home -->
<div id="home" class="home">
<br>
<br>
<br>
<div class="text-vcenter">
<div class="signin-card">
<div class="row">
<div class="col-m-3">
<i id="userImg" class="fa fa-user"></i>
</div>
<div class="col-sm-4">
<p class="name"><span id="ffname" class="fname"></span> <span class="lname"></span></p>
<p class="info">Florida State University</p>
</div>
</div>
<div id="userCourses" class="col-sm-4">
</div>
<hr>
<div class="row">
<div id="userMatches" class="col-md-7">
</div>
<div class="col-md-5">
<div id="firechat-wrapper">
<!-- Include this file on any page you wish to see a chatter box.-->
<span id="nameholder" style="display:none;"></span>
</div>
</div>
</div>
<br>
<br>
<br>
<br>
</div>
<br>
<br>
<br>
</div>
</div>
</div>
<!-- /first section -->
<!-- footer -->
<footer>
<div class="text-vcenter">
<div class="container">
<!-- <a href="userContactUs.html" class="blueLink">Contact Us</a> -->
<p class="text-center">Copyright © Study With Me | 2015</p>
</div>
</div>
</footer>
<!-- /footer -->
<!-- attach JavaScripts -->
<script src="js/jquery-1.10.2.js"></script>
<script src="js/bootstrap.min.js"></script>
<script type="text/javascript" src="js/jquery.scrollTo.min.js"></script>
<script type="text/javascript" src="js/jquery.localScroll.min.js"></script>
<script>
var ref = new Firebase("https://vivid-torch-1590.firebaseio.com");
var authData = ref.getAuth();
//$snapshot.val().firstname
function isUserLoggedIn(authData) {
//Previously called authDataCallback by Firebase Docs https://www.firebase.com/docs/web/guide/user-auth.html
if (authData) {
//console.log('AUTH-ED', "https://vivid-torch-1590.firebaseio.com/users/" + authData.uid, authData);
// console.log("User " + authData.uid + " is logged in with " + authData.provider);
var profileRef = new Firebase("https://vivid-torch-1590.firebaseio.com/users/" + authData.uid);
profileRef.once('value', function(snapshot) {
$(".fname").text(snapshot.val().firstname);
$(".lname").text(snapshot.val().lastname);
});
// console.log(dump(authData));
} else {
console.log("User is logged out");
}
}
ref.onAuth(isUserLoggedIn);
// REGISTER DOM ELEMENTS
var messageField = $('#messageInput');
var messageList = $('#example-messages');
// LISTEN FOR KEYPRESS EVENT
messageField.keypress(function (e) {
if (e.keyCode == 13) {
//FIELD VALUES
var username = $("#ffname").text();
var message = messageField.val();
var myChild = ref.child("message");
//SAVE DATA TO FIREBASE AND EMPTY FIELD
myChild.push({name:username, text:message});
messageField.val('');
}
});
var myChild = ref.child("message");
myChild.on('child_added', function(snapshot) {
var message = snapshot.val();
displayChatMessage(message.name, message.text);
});
function displayChatMessage(name, text) {
$('<div/>').text(text).prepend($('<em/>').text(name+': ')).appendTo($('#chatter'));
$('#chatter')[0].scrollTop = $('#chatter')[0].scrollHeight;
};
/*$(document).ready(function(){
$('#chatterBox').animate({
scrollTop: $('#chatterBox')[0].scrollHeight}, 2000);
});*/
/* repeatString() returns a string which has been repeated a set number of times */
function repeatString(str, num) {
out = '';
for (var i = 0; i < num; i++) {
out += str;
}
return out;
}
function disconnect(){
ref.unauth();
}
var globalarray = new Array(Array());
var existingval2 = new Array();
function grabstuff(){
var ref = new Firebase("https://vivid-torch-1590.firebaseio.com");
var grabusers =ref.child("/users");
grabusers.once("value",
function(snap){
// console.log(snap.val());
snap.forEach(function(childsnap){
var currentkey = childsnap.key();
if(currentkey !=authData.uid){
var grabcourses = grabusers.child("/"+currentkey+"/courses");
var grabfirst = grabusers.child("/"+currentkey+"/firstname");
var grablast = grabusers.child("/"+currentkey+"/lastname");
var existingval = new Array();
existingval.push(currentkey.toString());
grabfirst.once("value",
function(snap2){
//console.log(snap2.val());
var data = snap2.val();
existingval.push(data.toString());
//console.log(existingval);
});
grablast.once("value",
function(snap2){
//console.log(snap2.val());
var data = snap2.val();
existingval.push(data.toString());
//console.log(existingval);
});
grabcourses.once("value",
function(snap2){
//console.log(snap2.val());
snap2.forEach(function(doublesnaps){
var data = doublesnaps.val();
existingval.push(data.toString());
//console.log(existingval);
});
});
globalarray.push(existingval);
}
});
});
//console.log(globalarray);
}
function holyshit(){
var ref2 = new Firebase("https://vivid-torch-1590.firebaseio.com/users/"+authData.uid+"/courses");
ref2.once("value",
function(snap){
//console.log(snap.val());
snap.forEach(function(childsnap){
var data = childsnap.val();
existingval2.push(data.toString());
});
//console.log(existingval2);
});
}
grabstuff();
holyshit();
var matches = new Array(Array());
function findMatches(){
for(var x = 0; x < existingval2.length; x++)
{
for(var y = 1; y < globalarray.length; y++)
{
for(var z = 3; z < globalarray[y].length; z++)
{
if(existingval2[x].toLowerCase() == globalarray[y][z].toLowerCase())
{
var temp = globalarray[y][1].toString() + ' '+globalarray[y][2].toString();
var index = matches.indexOf(temp);
if(index < 0){
matches.push('c');
matches.push(globalarray[y][0])
matches.push('x');
matches.push(temp);
matches.push(existingval2[x]);
}
else
matches.splice(index+1, 0, existingval2[x])
}
}
}
}
}
function populatelist(){
var id;
for(var x = 0; x < matches.length; ++x)
{
if (matches[x] == 'c'){
id = matches[x+1];
x+=1;
continue;
}
if( matches[x] == 'x'){
var d = x+1;
for(; d < matches.length; ++d)
{
if(matches[d] != 'c')
continue;
else{
console.log(id);
break;
}
}
var newarray = matches.slice(x+2,d);
var stringify = newarray.toString();
document.getElementById("userMatches").insertAdjacentHTML('beforeend','<div class = "sillywilly"><h3>'+matches[x+1]+'</h3><h2>'+stringify+'</h2><button value='+id+' onclick="startchat(this.value)">Chat</button></div>');
x = d-1;
}
}
var newstring = existingval2.toString();
document.getElementById("userCourses").insertAdjacentHTML('beforeend','<div class = "sillywilly2"><p>Courses You\'re In: '+newstring+'</p></div>');
}
function startchat(value){
console.log(value);
var chatRef = new Firebase('https://vivid-torch-1590.firebaseio.com/chat');
chatRef.onAuth(function(authData) {
// Once authenticated, instantiate Firechat with our user id and user name
if (authData) {
console.log(authData)
var chat = new FirechatUI(chatRef, document.getElementById('firechat-wrapper'));
var fireChat = chat._chat;
var usersRef = new Firebase('https://vivid-torch-1590.firebaseio.com/users/' + authData.uid);
usersRef.once('value', function(snap) {
var user = snap.val();
fireChat.setUser(authData.uid, user.firstname + ' '+ user.lastname, function(user){
fireChat.resumeSession();
fireChat.createRoom("StudyChat","private", function(roomId) {
console.log(roomId,fireChat._userId,fireChat._sessionId);
console.log(fireChat);
fireChat.inviteUser(value, roomId);
fireChat.enterRoom(roomId);
});
});
});
}
});
}
setTimeout(function(){
console.log(existingval2);
console.log(globalarray);
findMatches();
populatelist();
console.log(matches);
},2000);
</script>
</body>
</html>