-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfirebase-test-2.js
executable file
·131 lines (114 loc) · 5.04 KB
/
firebase-test-2.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
//<script src="https://www.gstatic.com/firebasejs/5.9.2/firebase.js"></script>
//<script src="https://www.gstatic.com/firebasejs/5.9.2/firebase-app.js"></script>
var config = {
apiKey: "AIzaSyA1njsn06UVdJUBzU4nOCaNRUPbZLUInic",
authDomain: "hackathon-74ece.firebaseio.com",
databaseURL: "https://hackathon-74ece.firebaseio.com/",
projectId: "hackathon-74ece",
storageBucket: "hackathon-74ece.appspot.com",
messagingSenderId: "859830193730"
};
//firebase.initializeApp(config);
var mainApp=firebase.initializeApp(config);
//console.log(mainApp.name);
var fireDatabase=firebase.database();
var databaseTree;
/*fireDatabase.ref("Pothole_Reports/").on('value', function(snapshot){
console.log(snapshot.val());
databaseTree=JSON.parse(snapshot.val());
//console.log(databaseTree[0]);
snapshot.forEach(function(childSnapshot){
console.log(childSnapshot.key);
$("#details").find('tbody')
.append($('<tr>')
.append($('<td>')
.text(data)
)
);
childSnapshot.forEach(function(child_oneSnapshot){
//console.log(child_oneSnapshot.val());
});
//console.log(childSnapshot.val());
});
console.log(snapshot.key);
});*/
//console.log(fireDatabase.ref("Pothole_Reports/"));
//firebase call is asyncrhonous in nature
var users=[];
var photos=[];
var count=0;
var keyValue=new Object;
function mail(i){
var status = document.getElementById(i+'stat').innerHTML;
var time = document.getElementById(i+'time').innerHTML;
var location = document.getElementById(i+'loc').innerHTML;
var area = document.getElementById(i+'area').innerHTML;
var email = document.getElementById(i+'drop').value;
//var photo = document.getElementById(i+'stat');
console.log(location);
if(status == 50){
Email.send({
Host : "smtp.elasticemail.com",
Port : 2525,
SMTPAuth : true,
SMTPSecure : 'tls',
Username : "[email protected]",
Password : "0B2074A44DBCA2E33E722D9A31DFC2FCF3CB",
To : email,
From : "[email protected]",
Subject : "You have to work according to the details mentioned",
Body : "The location is " + location + ". This was reported on " + time + ". The estimated area of the pothole is " + area + "."
}).then(
message => alert(message)
);
}
else{
alert('unsuccessful')
}
}
function test(childSnapshot, child_childSnapshot){
fireDatabase.ref("Pothole_Reports/").child(childSnapshot).child(child_childSnapshot).update({"Status":70});
}
function popup(childSnapshot, child_childSnapshot){
if(confirm("Do you want to submit this report?")){
fireDatabase.ref("Pothole_Reports/").child(childSnapshot).child(child_childSnapshot).update({"Status":80});
fireDatabase.ref("Users/"+childSnapshot).once('value', function(snapshot){
var userCredits = snapshot.val().credits;
//console.log(userCredits);
userCredits += 20;
fireDatabase.ref("Users/").child(childSnapshot).update({"credits":userCredits});
location.reload();
});
}
}
var i = 1;
fireDatabase.ref("Pothole_Reports/").once('value', function(snapshot){
snapshot.forEach(function(childSnapshot){
console.log(childSnapshot.key);
//users.push(childSnapshot.key);
//console.log(users[count++]);
childSnapshot.forEach(function(child_childSnapshot){
//photos.push(child_childSnapshot.key);
if(child_childSnapshot.val().Status>=50 && child_childSnapshot.val().Status < 80){
//console.log(child_childSnapshot.val().Status+" "+childSnapshot.key+" "+child_childSnapshot.key+" "+child_childSnapshot.val().GPS_Coordinates+" "+child_childSnapshot.val().RealArea);
console.log(child_childSnapshot.key+" "+childSnapshot.key);
$("#t_body").append("<tr id="+i+"row><td>"+i+"</td><td id = "+i+"time>"+child_childSnapshot.key+"</td><td id="+i+"loc>"+child_childSnapshot.val().GPS_Coordinates+"</td><td id = "+i+"area>"+child_childSnapshot.val().RealArea+"</td><td><select id='"+i+"drop'><option value='[email protected]'>[email protected]</option><option value='[email protected]'>[email protected]</option><option value='[email protected]'>[email protected]</option><option value='[email protected]'>[email protected]</option></select></td><td scope='col'><input id = "+i+ '-eng' + " onclick='mail("+i+");test("+JSON.stringify(childSnapshot.key)+"," +JSON.stringify(child_childSnapshot.key)+");' class='btn btn-primary' type='button' name='engineer' value='Send' data-toggle='modal' data-target='#exampleModal'></td><td scope='col'><input id = "+i+'-user'+" onclick='popup("+JSON.stringify(childSnapshot.key)+"," +JSON.stringify(child_childSnapshot.key)+");' class='btn btn-primary' type='button' name='user' value='Acknowledge' data-toggle='modal' data-target='#UserModal'></td></tr>");
//hide(i);
i += 1;
}
});
console.log(users[0]);
});
});
/*
var photos=[];
var count=0;
for(var i=0; i<users.length; i++){
firebase.ref("Pothole_Reports/"+users[i]).once('value', function(snapshot){
photos.push(snapshot.key);
console.log(photos[count++]);
});
}
*/
//console.log(photos[1]);
//document.getElementById("special-id1").innerHTML=photos[0];