-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtraderjoe-page.html
More file actions
324 lines (269 loc) · 13.9 KB
/
traderjoe-page.html
File metadata and controls
324 lines (269 loc) · 13.9 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
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
<!DOCTYPE html>
<html>
<head>
<title>Business Page</title>
<link rel="stylesheet" href="css\style.css">
<script src="https://kit.fontawesome.com/15d341663e.js" crossorigin="anonymous"></script>
</head>
<body>
<header>
<div class = "navigation">
<ul>
<a href="Home.html"><li>Home</li></a>
<a href="about-us.html"><li>About Us</li></a>
</ul>
</div>
</header>
<div class="banner">
<h1 id="banner-text">Trader Joe's</h1>
</div>
<article>
<div class="rating-section">
<h3 class="user-ratings">Covid Safety Rating:
<div class="ratings">
<div class="empty-stars"></div>
<div id="covid-star" class="full-stars"></div>
</div>
<span id="covidNum"></span>
</h3>
<hr>
<label for="covid-slider" class="input-description">How was your covid safety experience?</label>
<br>
<div class="slider">
<form onsubmit="covidRating(event)">
<input type="range" min="1" max="5" step="1"
id="covid-slider">
<button class="button" type="submit">Rate!</button>
</form>
</div>
</div>
<div class="rating-section">
<h3 class="user-ratings">Busyness Rating:
<div class="ratings">
<div class="empty-stars"></div>
<div id="busy-star" class="full-stars"></div>
</div>
<span id="busyNum"></span>
</h3>
<hr>
<label for="line-slider" class="input-description">How busy was the place? (5 stars for busy)</label>
<br>
<div class="slider">
<form onsubmit="busyRating(event)">
<input type="range" min="1" max="5" step="1"
id="line-slider">
<button class="button" type="submit">Rate!</button>
</form>
</div>
</div>
<!-- Image Name <input id="namebox" type="text"><br><br> -->
<!-- <img id="myimg"> <label id="UpProgress"></label> -->
<button id="uploadimage">Upload Image</button>
<!-- <button id="upload">Upload Image</button> -->
<!-- <button id="retrieve">Retrieve Image</button> -->
<div class="gallery">
<img src="Images\tj1.jpeg" id="bigim" class="gallery-highlight">
<div class="preview">
<img src="Images\tj1.jpeg" id="im1" class="active">
<img src="Images\tj2.jpeg" id="im2">
<img src="Images\tj3.jpeg" id="im3">
</div>
</div>
</article>
<!-- The core Firebase JS SDK is always required and must be listed first -->
<script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-app.js"></script>
<!-- TODO: Add SDKs for Firebase products that you want to use
https://firebase.google.com/docs/web/setup#available-libraries -->
<script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-analytics.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-database.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.2.9/firebase-storage.js"></script>
<script>
// Your web app's Firebase configuration
// For Firebase JS SDK v7.20.0 and later, measurementId is optional
var firebaseConfig = {
apiKey: "AIzaSyAdOQ-Rk1Gm5hlVL2Yjz5tR72KdnfITSBQ",
authDomain: "hacksc-pollen-82499.firebaseapp.com",
projectId: "hacksc-pollen-82499",
storageBucket: "hacksc-pollen-82499.appspot.com",
messagingSenderId: "607618457140",
appId: "1:607618457140:web:59a7e27dabf5c07499b461",
measurementId: "G-P9MSVE83G9"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// firebase.analytics();
var storename = document.querySelector("#banner-text").innerHTML
var covidR, safetyR;
displayRating()
function displayRating(){
firebase.database().ref('/').on('value', function(snapshot){
var covidR = snapshot.val()[storename+" Average Covid Rating"]["covidAvr"]
var busyR = snapshot.val()[storename+" Average Busy Rating"]["busyAvr"]
// console.log("getting value covidr", covidR, "busyr",busyR);
var covidPercentage = (100 * covidR) / 5;
var safePercentage = (100 * busyR) / 5;
// console.log("covidpercentage",covidPercentage)
// console.log("safepercentage",safePercentage)
var covidStar = document.querySelector("#covid-star");
covidStar.style.width = covidPercentage + "%";
document.querySelector("#covidNum").innerHTML = covidR
var busyStar = document.querySelector("#busy-star");
busyStar.style.width = safePercentage + "%";
document.querySelector("#busyNum").innerHTML = busyR
})
}
// -- VARIABLES --
var ImgName, ImgUrl;
var files = [];
var reader;
// function hello(){
// alert("Hello!!");
const uploadbutton = document.querySelector("#uploadimage")
console.log("this working",uploadbutton)
uploadbutton.onclick = function(e){
console.log("I'M HERE");
// ------------------------------- SELECTION PROCESS -------------------------------
var input = document.createElement('input');
input.type='file';
input.onchange = e => {
files = e.target.files;
reader = new FileReader();
reader.onload = function(){
//document.getElementById("myimg").src = reader.result; // displays new image in image box
}
reader.readAsDataURL(files[0]); // assign image link to source
// ------------------------------- UPLOAD PICTURE TO FIREBASE STORAGE -------------------------------
// ImgName = document.getElementById('namebox').value;
// add image to array
// var picsRef = firebase.database().ref('Pictures/'+ImgName);
// picsRef.orderByValue().on("value", function(snapshot)
// {
// snapshot.forEach(function(data)
// {
// pics.push(picsRef);
// console.log(pics[0]);
// });
// });
// upload image at files[0] and image is saved as ImgName.png
var uploadTask = firebase.storage().ref('Images/' + ".png").put(files[0]);
uploadTask.on('state_changed', function(snapshot){
// var progress = (snapshot.bytesTransferred / snapshot.totalBytes) * 100;
// document.getElementById('UpProgress').innerHTML = 'Upload progress: ' + progress + '%';
},
//error handling
function(error){
alert('error saving image');
},
// retrieve link from firebase storage and save to database
function()
{
uploadTask.snapshot.ref.getDownloadURL().then(function(url){
ImgUrl = url;
//console.log("Image URL: " , ImgUrl);
var d = new Date();
var currentTime = d.getTime();
console.log(currentTime);
// save file to firebase
firebase.database().ref('TraderJoes/').push({
Name: "img"+currentTime,
Link: ImgUrl,
Time: currentTime
});
alert('image added successfully :)');
});
});
// ImgName = document.getElementById("namebox").value;
// console.log(ImgName);
firebase.database().ref('TraderJoes/').orderByChild("Time").limitToLast(3).on('value', function(snapshot)
{
var i = 0;
var img1;
var img2;
var img3;
snapshot.forEach(function(childSnapshot){
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
// var myID = childData["Link"];
if(i === 0) {img1 = childData["Link"];}
if(i === 1) {img2 = childData["Link"];}
if(i === 2) {img3 = childData["Link"];}
// if(i === 3) {break;}
console.log("childKey",childKey);
console.log("childData",childData);
console.log(childData["Link"]);
console.log("----------");
i += 1;
})
// console.log(snapshot.val());
document.getElementById("bigim").src = img1;
document.getElementById("im1").src = img1;
document.getElementById("im2").src = img2;
document.getElementById("im3").src = img3;
});
}
input.click();
}
// document.getElementById("select").addEventListener("click", hello);
function covidRating(e) {
event.preventDefault();
covidR = document.getElementById("covid-slider").value;
// console.log("covid on slider",covidR);
firebase.database().ref(storename+" covid").push({
covidRating: covidR,
});
console.log("covid sent")
var totalRating = 0;
var numberOfRating = 0;
firebase.database().ref(storename+" covid").on('value',function(snapshot){
// console.log("snap",snapshot.val())
snapshot.forEach(function(childSnapshot){
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
// console.log("childKey",childKey)
// console.log("childData",childData["covidRating"])
// console.log("-----")
totalRating += parseInt(childData["covidRating"])
numberOfRating += 1
})
})
// console.log("total",totalRating,"numberOfRating",numberOfRating)
var avrRating = (totalRating / numberOfRating).toFixed(2);
// console.log("average", avrRating )
firebase.database().ref(storename+" Average Covid Rating").set({
covidAvr: avrRating,
});
}
function busyRating(event) {
event.preventDefault();
busyR = document.getElementById("line-slider").value;
// console.log("busy on slider",busyR);
firebase.database().ref(storename+" busy").push({
busyRating: busyR,
});
console.log("busy sent")
var totalRating = 0;
var numberOfRating = 0;
firebase.database().ref(storename+" busy").on('value',function(snapshot){
// console.log("snap",snapshot.val())
snapshot.forEach(function(childSnapshot){
var childKey = childSnapshot.key;
var childData = childSnapshot.val();
// console.log("childKey",childKey)
// console.log("childData",childData["busyRating"])
// console.log("-----")
totalRating += parseInt(childData["busyRating"])
numberOfRating += 1
})
})
// console.log("total",totalRating,"numberOfRating",numberOfRating)
var avrRating = (totalRating / numberOfRating).toFixed(2);
// console.log("average", avrRating )
// might need to use update instead of set
firebase.database().ref(storename+" Average Busy Rating").set({
busyAvr: avrRating,
});
}
</script>
</body>
</html>
<script src="scripting.js"></script>