Skip to content

Commit a5a899d

Browse files
committedMay 7, 2024
added verify, bar codes and select seats
1 parent 71265d7 commit a5a899d

11 files changed

+600
-51
lines changed
 

‎routers/indexRouter.js

+11-7
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ router.post('/', async (req, res) => {
2828
const distance = earthRadius * c;
2929

3030
const timeTaken = Math.round((distance / 45) * 60)
31-
return [(50 + (12.5 * distance)).toFixed(2), distance.toFixed(2), timeTaken];
31+
return [(15 + (6.5 * distance)).toFixed(2), distance.toFixed(2), timeTaken];
3232
}
3333
const allDrivers = await Users.findOne({type: 'Driver', status: 'free'})
3434
const chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890'
@@ -38,7 +38,7 @@ router.post('/', async (req, res) => {
3838
}
3939
const currentRides = await Rides.find({})
4040
for (let i = 0; i < currentRides.length; i++) {
41-
const maxLimit = currentRides[i].vehicle == 'auto' ? 3 : 10
41+
const maxLimit = currentRides[i].vehicle == 'auto' ? 3 : 16
4242
if (currentRides[i].riders.length >= maxLimit) {
4343
continue;
4444
} else {
@@ -49,7 +49,8 @@ router.post('/', async (req, res) => {
4949
currentMyLocations = currentRides[i].myLocation,
5050
currentTimes = currentRides[i].time,
5151
currentLatitudes = currentRides[i].latitude,
52-
currentLongitudes = currentRides[i].longitude
52+
currentLongitudes = currentRides[i].longitude,
53+
currentSeats = currentRides[i].seats
5354
if (newPeople.includes(req.user.email)) {
5455
return res.redirect('/')
5556
};
@@ -58,13 +59,14 @@ router.post('/', async (req, res) => {
5859
if (currentRides[i].vehicle == 'bus') {
5960
currentPrices.push(getFare(latitude, longitude, myLatitude, myLongitude)[0])
6061
} else {
61-
currentPrices.push(20 + (4.5 * getFare(latitude, longitude, myLatitude, myLongitude)[1]))
62+
currentPrices.push(15 + (7.5 * getFare(latitude, longitude, myLatitude, myLongitude)[1]))
6263
}
6364
currentMyLocations.push(myFinalHomeLocation)
6465
currentDistances.push(getFare(latitude, longitude, myLatitude, myLongitude)[1])
6566
currentTimes.push(getFare(latitude, longitude, myLatitude, myLongitude)[2])
6667
currentLatitudes.push(Number(latitude))
6768
currentLongitudes.push(Number(longitude))
69+
currentSeats.push('noseatfound')
6870
await Rides.updateOne({rideId: currentRides[i].rideId}, {
6971
$set: {
7072
riders: newPeople,
@@ -74,7 +76,8 @@ router.post('/', async (req, res) => {
7476
distance: currentDistances,
7577
time: currentTimes,
7678
latitude: currentLatitudes,
77-
longitude: currentLongitudes
79+
longitude: currentLongitudes,
80+
seats: currentSeats
7881
}
7982
})
8083
const foundMyUser = await Users.findOne({email: req.user.email})
@@ -102,12 +105,13 @@ router.post('/', async (req, res) => {
102105
vehicle: 'auto',
103106
otp: finalOtp,
104107
rideId: myNewRideId,
105-
price: [20 + (4.5 * getFare(latitude, longitude, myLatitude, myLongitude)[1])],
108+
price: [15 + (7.5 * getFare(latitude, longitude, myLatitude, myLongitude)[1])],
106109
distance: [getFare(latitude, longitude, myLatitude, myLongitude)[1]],
107110
myLocation: [myFinalHomeLocation],
108111
time: [getFare(latitude, longitude, myLatitude, myLongitude)[2]],
109112
latitude: [Number(latitude)],
110-
longitude: [Number(longitude)]
113+
longitude: [Number(longitude)],
114+
seats: ['noseatfound']
111115
})
112116
await newRide.save()
113117
await Users.updateOne({email: req.user.email}, {

‎routers/selectRouter.js

+58-3
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,78 @@
11
const router = require('express').Router()
2-
const Ride = require('../schemas/rideSchema')
2+
const Ride = require('../schemas/rideSchema'),
3+
User = require('../schemas/userSchema')
34

45
router.get('/', async (req, res) => {
56
const allRides = await Ride.find({})
67
var verified = false
8+
var seats = []
9+
var mySeat = 'noseatfound'
10+
var myPrice = myDriver = myTime = myDistance = myPickup = myDropOff = myLatitude = myLongitude = ''
11+
var foundDriver;
712
for (let i = 0; i < allRides.length; i++) {
813
if (allRides[i].riders.includes(req.user.email)) {
14+
foundDriver = await User.findOne({email: allRides[i].driver})
15+
const overallIndex = allRides[i].riders.indexOf(req.user.email)
16+
myPrice = allRides[i].price[overallIndex]
17+
myTime = allRides[i].time[overallIndex]
18+
myDistance = allRides[i].distance[overallIndex]
19+
myPickup = allRides[i].myLocation[overallIndex].slice(0, 32) + '...'
20+
myDropOff = allRides[i].location[overallIndex].slice(0, 32) + '...'
21+
myLatitude = allRides[i].latitude[overallIndex]
22+
myLongitude = allRides[i].longitude[overallIndex]
23+
myDriver = allRides[i].driver
924
if (allRides[i].vehicle == 'bus') {
1025
verified = true
26+
seats = allRides[i].seats
27+
mySeat = allRides[i].seats[overallIndex]
1128
break
1229
}
1330
}
1431
}
1532
if (verified) {
16-
return res.render('select', {user: req.user})
33+
return res.render('select', {
34+
user: req.user,
35+
seats: seats,
36+
mySeat: mySeat,
37+
price: myPrice,
38+
time: myTime,
39+
distance: myDistance,
40+
pickup: myPickup,
41+
dropoff: myDropOff,
42+
latitude: myLatitude,
43+
longitude: myLongitude,
44+
driver: myDriver,
45+
pfp: foundDriver.pfp
46+
})
1747
} else {
1848
return res.redirect('/status')
1949
}
20-
console.log(verified)
50+
})
51+
52+
router.post('/', async (req, res) => {
53+
try {
54+
const {seat} = req.body
55+
const allRides = await Ride.find({})
56+
var rideId = ''
57+
for (let i = 0; i < allRides.length; i++) {
58+
if (allRides[i].riders.includes(req.user.email)) {
59+
const overallIndex = allRides[i].riders.indexOf(req.user.email),
60+
currentPrices = allRides[i].price
61+
allRides[i].seats[overallIndex] = seat
62+
allRides[i].price[overallIndex] = Number(allRides[i].price[overallIndex]) + 30
63+
await Ride.updateOne({rideId: allRides[i].rideId}, {
64+
$set: {
65+
seats: allRides[i].seats,
66+
price: currentPrices
67+
}
68+
})
69+
return res.sendStatus(200)
70+
}
71+
}
72+
} catch (err) {
73+
console.log(err)
74+
res.sendStatus(400)
75+
}
2176
})
2277

2378
module.exports = router

‎routers/statusRouter.js

+16-8
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,14 @@ const User = require('../schemas/userSchema')
33
const Ride = require('../schemas/rideSchema')
44

55
router.get('/', async (req, res) => {
6-
const foundUser = await User.findOne({email: req.user.email})
7-
if (foundUser.status == 'free') return res.redirect('/')
6+
const user = req.user
7+
if (user.status == 'free') return res.redirect('/')
88
var myRide = {riders: []};
99
const foundRides = await Ride.find({})
10+
const allUsers = await User.find({})
1011
for (let i = 0; i < foundRides.length; i++) {
11-
if (foundRides[i].riders.includes(req.user.email)) {
12-
const overallIndex = foundRides[i].riders.indexOf(req.user.email)
12+
if (foundRides[i].riders.includes(user.email)) {
13+
const overallIndex = foundRides[i].riders.indexOf(user.email)
1314
const foundDriver = await User.findOne({email: foundRides[i].driver})
1415
myRide.price = foundRides[i].price[overallIndex]
1516
myRide.distance = foundRides[i].distance[overallIndex]
@@ -20,8 +21,13 @@ router.get('/', async (req, res) => {
2021
myRide.latitude = Number(foundRides[i].latitude[overallIndex])
2122
myRide.longitude = Number(foundRides[i].longitude[overallIndex])
2223
for (let k = 0; k < foundRides[i].riders.length; k++) {
23-
const theFoundUser = await User.findOne({email: foundRides[i].riders[k]})
24-
myRide.riders.push(theFoundUser)
24+
for (let n = 0; n < allUsers.length; n++) {
25+
if (allUsers[n].email == foundRides[i].riders[k]) {
26+
myRide.riders.push(allUsers[n])
27+
}
28+
}
29+
// const theFoundUser = await User.findOne({email: foundRides[i].riders[k]})
30+
// myRide.riders.push(theFoundUser)
2531
}
2632
if (foundRides[i].location[overallIndex].length > 20) {
2733
myRide.dropOff = foundRides[i].location[overallIndex].substring(0, 20) + '...'
@@ -36,7 +42,7 @@ router.get('/', async (req, res) => {
3642
break
3743
}
3844
}
39-
res.render('status', {user: foundUser, ride: myRide})
45+
res.render('status', {user: req.user, ride: myRide})
4046
})
4147

4248
router.post('/vehicle', async (req, res) => {
@@ -85,6 +91,7 @@ router.post('/cancel', async (req, res) => {
8591
foundRides[i].time.splice(overallIndex, 1)
8692
foundRides[i].latitude.splice(overallIndex, 1)
8793
foundRides[i].longitude.splice(overallIndex, 1)
94+
foundRides[i].seats.splice(overallIndex, 1)
8895
console.log(foundRides[i])
8996
await Ride.updateOne({rideId: foundRides[i].rideId}, {
9097
$set: {
@@ -95,7 +102,8 @@ router.post('/cancel', async (req, res) => {
95102
distance: foundRides[i].distance,
96103
time: foundRides[i].time,
97104
latitude: foundRides[i].latitude,
98-
longitude: foundRides[i].longitude
105+
longitude: foundRides[i].longitude,
106+
seats: foundRides[i].seats
99107
}
100108
})
101109
await User.updateOne({email: req.user.email}, {

‎routers/tempRouter.js

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
const router = require('express').Router()
2+
const Ride = require('../schemas/rideSchema')
3+
const User = require('../schemas/userSchema')
4+
5+
router.get('/', async (req, res) => {
6+
const foundRide = await Ride.findOne({rideId: 'xHxW6J9lIiSER5fV1Kre'})
7+
await Ride.updateOne({rideId: 'xHxW6J9lIiSER5fV1Kre'}, {
8+
$set: {
9+
seats: ['a3']
10+
}
11+
})
12+
})
13+
14+
module.exports = router

‎routers/verifyRouter.js

+12
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
const router = require('express').Router(),
2+
Ride = require('../schemas/rideSchema')
3+
4+
router.get('/', (req, res) => {
5+
res.render('verify')
6+
})
7+
8+
router.post('/', async (req, res) => {
9+
10+
})
11+
12+
module.exports = router

‎schemas/rideSchema.js

+5
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,11 @@ const driverSchema = new Schema({
4141
longitude: {
4242
type: Array,
4343
required: true
44+
},
45+
seats: {
46+
type: Array,
47+
required: true,
48+
default: []
4449
}
4550
})
4651

‎server.js

+5-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@ const indexRouter = require('./routers/indexRouter'),
2222
statusRouter = require('./routers/statusRouter'),
2323
helpRouter = require('./routers/helpRouter'),
2424
apiRouter = require('./routers/apiRouter'),
25-
selectRouter = require('./routers/selectRouter')
25+
selectRouter = require('./routers/selectRouter'),
26+
tempRouter = require('./routers/tempRouter'),
27+
verifyRouter = require('./routers/verifyRouter')
2628

2729
app.use(express.static('public'))
2830
app.set('view engine', 'ejs')
@@ -57,5 +59,7 @@ app.use('/status', ensureAuthenticated, ensureKyc, statusRouter)
5759
app.use('/help', ensureAuthenticated, ensureKyc, helpRouter)
5860
app.use('/rewards', ensureAuthenticated, ensureKyc, rewardsRouter)
5961
app.use('/select', ensureAuthenticated, selectRouter)
62+
app.use('/temp', tempRouter)
63+
app.use('/verify', verifyRouter)
6064

6165
app.listen(PORT, console.log(`Ordin <3 TS listening on port ${PORT}`))

‎views/partials/cursor.ejs

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
pointer-events: none;
3737
transition: top 0.15s ease-out, left 0.15s ease-out, width 0.15s ease-out,
3838
height 0.15s ease-out, background-color 0.15s ease-out;
39-
z-index: 1001;
39+
z-index: 9999999;
4040
}
4141
* {
4242
box-sizing: border-box;

‎views/select.ejs

+353
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,361 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<title>Select Seats</title>
7+
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
8+
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
9+
<link rel="icon" href="logo.png" type="image/png">
10+
<style>
11+
* {box-sizing: border-box;}
12+
.container {
13+
width: 75vw;
14+
margin-left: 12.5vw;
15+
display: flex;
16+
justify-content: space-between;
17+
margin-top: 5vw;
18+
}
19+
.seatsContainer {
20+
width: 25vw;
21+
border: 1px solid white;
22+
border-radius: 2.5vw;
23+
padding-bottom: 1.5vw;
24+
height: 53.5vw;
25+
}
26+
.seatsKaStampPolygonThingy {
27+
clip-path: polygon(0% 0%, 0% 100%, 75% 100%, 100% 0%);
28+
border-top-left-radius: 2.5vw;
29+
width: 15vw;
30+
height: 10vw;
31+
background-color: #ccc;
32+
padding: 1px;
33+
transform: translate(-0.56px, -0.56px)
34+
}
35+
.seatContainer {
36+
position: relative;
37+
width: 4.5vw;
38+
height: 4.5vw;
39+
border: 0.1vw solid white;
40+
border-radius: 0.8vw;
41+
display: flex;
42+
align-items: flex-end;
43+
}
44+
.seatsRow {
45+
display: flex;
46+
justify-content: space-around;
47+
}
48+
.seatGola {
49+
border: 0.1vw solid white;
50+
border-radius: 1.3vw;
51+
height: 1.5vw;
52+
width: 100%;
53+
transform: translateY(0.048vw);
54+
}
55+
.right {
56+
width: 35vw;
57+
}
58+
.right h1 {
59+
margin: 0.5vw 0px 1.5vw 0px;
60+
font-size: 2.3vw;
61+
}
62+
.rightBox {
63+
border-radius: 1.7vw;
64+
height: 17.5vw;
65+
background-color: #18181b;
66+
padding: 1.6vw 2vw;
67+
}
68+
.boxKaHead {
69+
display: flex;
70+
justify-content: space-between;
71+
align-items: center;
72+
}
73+
.boxKaHead p {
74+
font-size: 1.15vw;
75+
text-align: right;
76+
}
77+
.boxKaHead p:nth-child(2) {
78+
color: #53faaa;
79+
font-size: 1vw;
80+
margin-top: 0.33vw;
81+
}
82+
.driverInfo img {
83+
border-radius: 3vw;
84+
width: 3.2vw;
85+
height: 3.2vw;
86+
object-fit: cover;
87+
margin-right: 0.8vw;
88+
}
89+
.driverInfo {
90+
display: flex;
91+
align-items: center;
92+
font-size: 1.15vw;
93+
}
94+
p.driverInfoTextInfo {
95+
font-size: 1vw;
96+
color: #53faaa;
97+
display: flex;
98+
align-items: center;
99+
gap: 0.45vw;
100+
margin-top: 0.33vw;
101+
}
102+
.dot {
103+
width: 0.2vw;
104+
height: 0.2vw;
105+
background-color: rgba(255, 255, 255, 0.3);
106+
border-radius: 0.2vw;
107+
}
108+
.busIcon {
109+
color: black;
110+
background-color: #466eff;
111+
padding: 0.23vw 1.2vw;
112+
font-size: 1vw;
113+
border-radius: 0.5vw;
114+
}
115+
.pickupInfoContainer {
116+
display: flex;
117+
height: 100%;
118+
gap: 1.5vw;
119+
margin-left: 0.5vw;
120+
margin-top: 1.9vw;
121+
}
122+
.pickupInfoContainer img {
123+
height: 7.5vw;
124+
}
125+
.pickupInfo {
126+
flex: 1;
127+
}
128+
.pickupItem {
129+
display: flex;
130+
justify-content: space-between;
131+
align-items: center;
132+
}
133+
.pickupItem p {
134+
font-size: 1vw;
135+
line-height: 1.4;
136+
}
137+
.pickupItem p:nth-child(1) {
138+
color: rgba(255, 255, 255, 0.3);
139+
}
140+
.pickupItem:nth-child(2) {
141+
margin-top: 3.2vw;
142+
}
143+
.leaflet-container {
144+
width: 35vw;
145+
height: 29.35vw;
146+
border-radius: 1.7vw;
147+
margin-top: 1.9vw;
148+
border: 2px solid #131316;
149+
background: none;
150+
outline: none;
151+
}
152+
.continue {
153+
border: none;
154+
outline: none;
155+
cursor: pointer;
156+
transition: 0.3s;
157+
border-radius: 0.5vw;
158+
color: black;
159+
background-color: #53faaa;
160+
font-size: 0.95vw;
161+
height: fit-content;
162+
padding: 0.6vw 1.8vw;
163+
}
164+
</style>
7165
</head>
8166
<body>
9167
<%- include('./partials/cursor.ejs') %>
168+
<div class="container">
169+
<div class="seatsContainer">
170+
<div class="seatsKaStampPolygonThingy">
171+
<div class="seatsKaStampPolygonThingy" style="width: 100%; height: 100%; background-color: #131316;"></div>
172+
</div>
173+
<div class="seatsRow" style="margin-top: 3.5vw;">
174+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="a1">
175+
<div class="seatGola"></div>
176+
</div>
177+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="a2">
178+
<div class="seatGola"></div>
179+
</div>
180+
<div class="seatContainer" style="visibility: hidden">
181+
<div class="seatGola"></div>
182+
</div>
183+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="a3">
184+
<div class="seatGola"></div>
185+
</div>
186+
</div>
187+
<div class="seatsRow" style="margin-top: 1.5vw;">
188+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="b1">
189+
<div class="seatGola"></div>
190+
</div>
191+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="b2">
192+
<div class="seatGola"></div>
193+
</div>
194+
<div class="seatContainer" style="visibility: hidden">
195+
<div class="seatGola"></div>
196+
</div>
197+
<div class="seatContainer selectableSeats" style="transform: rotate(180deg)" data-cursor="pointer" data-value="b3">
198+
<div class="seatGola"></div>
199+
</div>
200+
</div>
201+
<div class="seatsRow" style="margin-top: 3.5vw;">
202+
<div class="seatContainer selectableSeats" style="transform: rotate(90deg)" data-cursor="pointer" data-value="c1">
203+
<div class="seatGola"></div>
204+
</div>
205+
<div class="seatContainer" style="visibility: hidden;">
206+
<div class="seatGola"></div>
207+
</div>
208+
<div class="seatContainer" style="visibility: hidden;">
209+
<div class="seatGola"></div>
210+
</div>
211+
<div class="seatContainer selectableSeats" style="transform: rotate(270deg)" data-cursor="pointer" data-value="c2">
212+
<div class="seatGola"></div>
213+
</div>
214+
</div>
215+
<div class="seatsRow" style="margin-top: 1.5vw;">
216+
<div class="seatContainer selectableSeats" style="transform: rotate(90deg)" data-cursor="pointer" data-value="d1">
217+
<div class="seatGola"></div>
218+
</div>
219+
<div class="seatContainer" style="visibility: hidden;">
220+
<div class="seatGola"></div>
221+
</div>
222+
<div class="seatContainer" style="visibility: hidden;">
223+
<div class="seatGola"></div>
224+
</div>
225+
<div class="seatContainer selectableSeats" style="transform: rotate(270deg)" data-cursor="pointer" data-value="d2">
226+
<div class="seatGola"></div>
227+
</div>
228+
</div>
229+
<div class="seatsRow" style="margin-top: 3.5vw;">
230+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="e1">
231+
<div class="seatGola"></div>
232+
</div>
233+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="e2">
234+
<div class="seatGola"></div>
235+
</div>
236+
<div class="seatContainer" style="visibility: hidden; transform: rotate(180deg)">
237+
<div class="seatGola"></div>
238+
</div>
239+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="e3">
240+
<div class="seatGola"></div>
241+
</div>
242+
</div>
243+
<div class="seatsRow" style="margin-top: 1.5vw;">
244+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="f1">
245+
<div class="seatGola"></div>
246+
</div>
247+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="f2">
248+
<div class="seatGola"></div>
249+
</div>
250+
<div class="seatContainer" style="visibility: hidden;">
251+
<div class="seatGola"></div>
252+
</div>
253+
<div class="seatContainer selectableSeats" data-cursor="pointer" data-value="f3">
254+
<div class="seatGola"></div>
255+
</div>
256+
</div>
257+
</div>
258+
<div class="right">
259+
<h1><span style="color: #466eff">Select</span> Seat</h1>
260+
<div class="rightBox">
261+
<div class="boxKaHead">
262+
<div class="driverInfo">
263+
<img src="<%= pfp %>">
264+
<div class="driverInfoText">
265+
<p><%= driver %> &nbsp;<span class="busIcon">Bus</span></p>
266+
<p class="driverInfoTextInfo"><%= time %> Mins <span class="dot"></span> <%= distance %> Km</p>
267+
</div>
268+
</div>
269+
<div class="prices">
270+
<p>₹<%= price %></p>
271+
<p>+30.00</p>
272+
</div>
273+
</div>
274+
<div class="pickupInfoContainer">
275+
<img src="pickup.png">
276+
<div class="pickupInfo">
277+
<div class="pickupItem">
278+
<div>
279+
<p>Pickup</p>
280+
<p><%= pickup %></p>
281+
</div>
282+
</div>
283+
<div class="pickupItem">
284+
<div>
285+
<p>Drop Off</p>
286+
<p><%= dropoff %></p>
287+
</div>
288+
<div class="continue" data-cursor="pointer" onclick="window.location.href = '/status'">Continue</div>
289+
</div>
290+
</div>
291+
</div>
292+
</div>
293+
<div id="map" style="position: relative"></div>
294+
</div>
295+
</div>
296+
<script>
297+
var foundOverallSeat, currentlySelected
298+
<% for (let i = 0; i < seats.length; i++) { %>
299+
if ('<%= seats[i] %>' != 'noseatfound') {
300+
foundOverallSeat = document.querySelector('[data-value="<%= seats[i] %>"]')
301+
foundOverallSeat.children[0].style.border = '0.1vw solid rgba(255, 255, 255, 0.4)'
302+
foundOverallSeat.style.border = '0.1vw solid rgba(255, 255, 255, 0.4)'
303+
foundOverallSeat.children[0].style.borderRadius = '1.3vw'
304+
foundOverallSeat.style.borderRadius = '0.8vw'
305+
foundOverallSeat.setAttribute('data-disabled', 'true')
306+
}
307+
<% } %>
308+
<% if (mySeat != 'noseatfound') { %>
309+
const foundSeat = document.querySelector('[data-value="<%= mySeat %>"]')
310+
foundSeat.children[0].style.border = '0.1vw solid #466eff'
311+
foundSeat.style.border = '0.1vw solid #466eff'
312+
foundSeat.children[0].style.borderRadius = '1.3vw'
313+
foundSeat.style.borderRadius = '0.8vw'
314+
foundSeat.setAttribute('data-disabled', 'false')
315+
currentlySelected = '<%= mySeat %>'
316+
<% } %>
317+
function showPosition() {
318+
var redMarker = L.icon({
319+
iconUrl: '/marker.png',
320+
iconSize: [80, 80],
321+
iconAnchor: [40, 40],
322+
popupAnchor: [1, -34],
323+
shadowSize: [41, 41]
324+
});
325+
console.log('called')
326+
var map = L.map('map', {zoomControl: false, attributionControl: false}).setView([<%= latitude %>, <%= longitude %>], 16);
327+
L.tileLayer('https://{s}.basemaps.cartocdn.com/dark_all/{z}/{x}/{y}{r}.png', {
328+
subdomains: 'abcd',
329+
maxZoom: 19
330+
}).addTo(map);
331+
const mapContainer = document.querySelector('.leaflet-container')
332+
var marker = L.marker([<%= latitude %>, <%= longitude %>], {icon: redMarker}).addTo(map);
333+
}
334+
showPosition()
335+
const allSelectableSeats = document.getElementsByClassName('selectableSeats')
336+
for (let i = 0; i < allSelectableSeats.length; i++) {
337+
allSelectableSeats[i].addEventListener('click', () => {
338+
if (allSelectableSeats[i].getAttribute('data-disabled') == 'true') return
339+
const selectedSeat = allSelectableSeats[i].getAttribute('data-value')
340+
console.log(selectedSeat)
341+
fetch('/select', {
342+
method: 'POST',
343+
body: JSON.stringify({
344+
seat: selectedSeat
345+
}),
346+
headers: {
347+
'Content-Type': 'application/json'
348+
}
349+
})
350+
.then(async response => {
351+
if (response.ok) {
352+
window.location.reload()
353+
} else {
354+
console.log('bhosdike')
355+
}
356+
})
357+
.catch(err => {
358+
console.log('Error: ' + err)
359+
})
360+
})
361+
}
362+
</script>
10363
</body>
11364
</html>

‎views/status.ejs

+72-31
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,22 @@
77
<link rel="stylesheet" href="https://unpkg.com/leaflet/dist/leaflet.css" />
88
<link rel="icon" type="image/png" href="/logo.png">
99
<script src="https://unpkg.com/leaflet/dist/leaflet.js"></script>
10+
<script src="https://unpkg.com/bwip-js"></script>
11+
<script src="https://cdn.jsdelivr.net/npm/jsbarcode@3.11.6/dist/barcodes/JsBarcode.code128.min.js"></script>
1012
<style>
13+
::-webkit-scrollbar {
14+
display: block !important;
15+
border-top-right-radius: 50px;
16+
width: 0.6vw;
17+
}
18+
::-webkit-scrollbar-track {
19+
border-top-right-radius: 100vw;
20+
border-bottom-right-radius: 100vw;
21+
background-color: #000;
22+
}
23+
::-webkit-scrollbar-thumb {
24+
background-color: #0d0d0d;
25+
}
1126
* {
1227
box-sizing: border-box;
1328
margin: 0;
@@ -238,19 +253,15 @@
238253
width: 15vw;
239254
padding: 1vw;
240255
text-align: center;
256+
transition: 0.6s;
241257
}
242258
.otpContainer p {
243259
margin: 0.8vw 0;
244260
text-align: center;
245261
font-size: 1.1vw;
246262
}
247-
.otpContainer div {
248-
border: 2px solid #466EFF;
249-
border-radius: 2px;
250-
display: inline;
251-
margin-right: 0.5vw;
252-
padding: 0px 0.7vw;
253-
font-size: 1.6vw;
263+
.otpContainer svg {
264+
width: 10vw;
254265
}
255266
.pfp {
256267
width: 4vw !important;
@@ -261,7 +272,26 @@
261272
.rideStatusPageLink {
262273
color: #466EFF !important;
263274
}
264-
</style>
275+
.fullBodyOverlay {
276+
background-color: rgba(0, 0, 0, 0.9);
277+
position: fixed;
278+
top: 0;
279+
left: 0;
280+
width: 100vw;
281+
height: 100vh;
282+
display: flex;
283+
align-items: center;
284+
justify-content: center;
285+
display: none;
286+
opacity: 0;
287+
z-index: 1000000;
288+
transition: 0.3s opacity;
289+
}
290+
.fullBodyOverlay svg {
291+
max-width: 90vw;
292+
transform: scale(1.6, 1.6) !important;
293+
}
294+
</style>
265295
</head>
266296
<body>
267297
<%- include('./partials/cursor.ejs') %>
@@ -270,10 +300,16 @@
270300
<h1><span style="color: #466EFF;">Ride</span> Status</h1>
271301
<p>Track your journey in a few clicks!</p>
272302
</div>
303+
<div class="fullBodyOverlay" id="fullBodyOverlay" onclick="toggleOverlay(event)">
304+
<svg id="barcode"></svg>
305+
</div>
273306
<main class="main">
274307
<div class="container">
275308
<div id="map" style="position: relative">
276-
<div class="otpContainer"></div>
309+
<div class="otpContainer">
310+
<p>Code for this ride</p>
311+
<svg id="barcode2"></svg>
312+
</div>
277313
</div>
278314
<div class="right">
279315
<div class="top">
@@ -326,7 +362,7 @@
326362
</div>
327363
</div>
328364
<div class="bottom">
329-
<div class="maindiv">
365+
<div class="maindiv" style="overflow: auto;">
330366
<h1>Grouped <span style="color: #466EFF;">Riders</span> <span style="color: rgba(244, 244, 244, 0.25);">(<%= ride.riders.length %>)</span></h1>
331367
<div class="riders">
332368
<% for (let i = 0; i < ride.riders.length; i++) { %>
@@ -347,7 +383,20 @@
347383
</div>
348384
</main>
349385
<script>
350-
function showPosition() {
386+
JsBarcode("#barcode", "<%= ride.otp %>", {
387+
format: 'code128',
388+
displayValue: false,
389+
lineColor: "black",
390+
background: "#fff"
391+
});
392+
JsBarcode("#barcode2", "<%= ride.otp %>", {
393+
format: 'code128',
394+
displayValue: false,
395+
lineColor: "#466eff",
396+
background: "transparent",
397+
height: 55
398+
});
399+
(function showPosition() {
351400
var redMarker = L.icon({
352401
iconUrl: '/marker.png',
353402
iconSize: [80, 80],
@@ -362,28 +411,20 @@
362411
maxZoom: 19
363412
}).addTo(map);
364413
const mapContainer = document.querySelector('.leaflet-container')
365-
const customOverlay = document.createElement('div'),
366-
otp1 = document.createElement('div'),
367-
otp2 = document.createElement('div'),
368-
otp3 = document.createElement('div'),
369-
otp4 = document.createElement('div'),
370-
overlayP = document.createElement('p')
371-
customOverlay.className = 'otpContainer'
372-
otp1.innerHTML = '<%= ride.otp[0] %>'
373-
otp2.innerHTML = '<%= ride.otp[1] %>'
374-
otp3.innerHTML = '<%= ride.otp[2] %>'
375-
otp4.innerHTML = '<%= ride.otp[3] %>'
376-
overlayP.innerHTML = 'OTP for this ride'
377-
customOverlay.appendChild(overlayP)
378-
customOverlay.appendChild(otp1)
379-
customOverlay.appendChild(otp2)
380-
customOverlay.appendChild(otp3)
381-
customOverlay.appendChild(otp4)
382-
mapContainer.appendChild(customOverlay)
414+
const customOverlay = document.createElement('div')
383415
var marker = L.marker([<%= ride.latitude %>, <%= ride.longitude %>], {icon: redMarker}).addTo(map);
416+
})()
417+
const otpContainer = document.getElementsByClassName('otpContainer')[0]
418+
otpContainer.addEventListener('click', (e) => {
419+
document.getElementById('fullBodyOverlay').style.display = 'flex'
420+
document.getElementById('fullBodyOverlay').style.opacity = '1'
421+
})
422+
function toggleOverlay(e) {
423+
if (e.target != document.getElementById('barcode')) {
424+
e.target.style.display = 'none'
425+
e.target.style.opacity = '0'
426+
}
384427
}
385-
showPosition()
386-
387428
</script>
388429
</body>
389430
</html>

‎views/verify.ejs

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>Document</title>
7+
<script src="https://cdn.jsdelivr.net/npm/quagga/dist/quagga.min.js"></script>
8+
<script src="https://unpkg.com/bwip-js"></script>
9+
</head>
10+
<body>
11+
<canvas id="barcode"></canvas>
12+
<div id="barcode-scanner" width="640" height="480"></div>
13+
<button id="btn">Start</button>
14+
<script>
15+
document.getElementById('btn').addEventListener('click', () => {
16+
Quagga.init({
17+
inputStream: {
18+
name: "Live",
19+
type: "LiveStream",
20+
target: "#barcode-scanner"
21+
},
22+
decoder: {
23+
readers: ["ean_reader", "upc_reader"]
24+
}
25+
}, function(err) {
26+
if (err) {
27+
console.error(err);
28+
return;
29+
}
30+
console.log("QuaggaJS initialized successfully");
31+
Quagga.start();
32+
});
33+
})
34+
Quagga.onDetected(function(result) {
35+
console.log("Barcode detected and processed", result);
36+
});
37+
bwipjs.toCanvas(document.getElementById('barcode'), {
38+
bcid: 'code128',
39+
text: 'humbewaaa',
40+
scale: 3,
41+
height: 10,
42+
includetext: false,
43+
barcolor: '#466eff'
44+
}, function (err, canvas) {
45+
if (err) {
46+
console.error(err);
47+
} else {
48+
document.body.appendChild(canvas);
49+
}
50+
});
51+
</script>
52+
</body>
53+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.