Skip to content

Commit c40802a

Browse files
committed
Small tweaks from feedback and API planning for visit stealing
Redirect to queue on home page when logged in, add a 404 page, "Start Visit" instead of "Call"
1 parent 3601320 commit c40802a

11 files changed

Lines changed: 143 additions & 28 deletions

File tree

api/queue/controller.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,3 +46,25 @@ def remove_from_queue_without_visit(student, reason):
4646
db.end_visit(visit, reason)
4747
return True
4848

49+
def get_tas_visit(ta):
50+
51+
in_progress = db.get_in_progress_visits()
52+
in_progress = list(filter(lambda v: v["ta_id"] == ta, in_progress))
53+
54+
if len(in_progress) == 0:
55+
return None
56+
57+
visit = in_progress[0]
58+
student = db.lookup_identifier(visit["student_id"])
59+
60+
return {
61+
"id": visit["student_id"],
62+
"username": student["ubit"],
63+
"pn": student["person_num"],
64+
"preferred_name": student["preferred_name"],
65+
"visitID": visit["visit_id"],
66+
"visit_reason": visit["student_visit_reason"]
67+
}
68+
69+
70+

api/queue/routes.py

Lines changed: 64 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
import api.queue.controller as controller
66
from api.auth.controller import get_user
7-
from api.queue.controller import remove_from_queue_without_visit
7+
from api.queue.controller import remove_from_queue_without_visit, get_tas_visit
88
from api.roster.controller import min_level
99
from api.database.db import db
1010

@@ -121,23 +121,73 @@ def restore_visit():
121121

122122
user_id = user["user_id"]
123123

124+
return get_tas_visit(user_id)
125+
126+
@blueprint.route("/active-visits", methods=["GET"])
127+
@min_level('ta')
128+
def get_active_visits():
124129
in_progress = db.get_in_progress_visits()
125-
in_progress = list(filter(lambda v: v["ta_id"] == user_id, in_progress))
126130

127-
if len(in_progress) == 0:
128-
return {"message": "You have no in-progress visits."}, 404
131+
visits = []
132+
133+
for visit in in_progress:
134+
student = db.lookup_identifier(visit["student_id"])
135+
136+
if visit["ta_id"] is not None:
137+
ta = db.lookup_identifier(visit["ta_id"])
138+
ta_name = ta["preferred_name"]
139+
else:
140+
ta_name = None
141+
142+
visits.append({
143+
"student_id": visit["student_id"],
144+
"student_username": student["ubit"],
145+
"student_name": student["preferred_name"],
146+
"visitID": visit["visit_id"],
147+
"visit_reason": visit["student_visit_reason"],
148+
"ta_id": visit["ta_id"],
149+
"ta_name": ta_name
150+
})
151+
152+
@blueprint.route("/visits/<id>", methods=["GET"])
153+
@min_level('instructor')
154+
def get_visit(visit_id):
155+
"""
156+
Retrieve all information about the specified visit.
157+
158+
"""
159+
160+
pass
161+
162+
@blueprint.route("/steal-visit/<id>", methods=["PATCH"])
163+
@min_level('ta')
164+
def steal_visit(visit_id):
165+
"""
166+
Replace the TA associated with the visit with the TA who sent
167+
the request. Returns all information about the visit being stolen.
168+
169+
Does not work on visits that are not in progress, or if the TA
170+
has an active visit.
171+
172+
"""
173+
174+
pass
175+
176+
@blueprint.route("/abandon-visit", methods=["PATCH"])
177+
@min_level('ta')
178+
def abandon_visit():
179+
"""
180+
Abandon the visit associated with the TA who sent the request.
181+
Does not end the visit.
182+
183+
Returns an error if the TA isn't in an active visit. Future retrievals
184+
of this visit should return "None" as the TA's ID and name.
185+
186+
187+
"""
188+
pass
129189

130-
visit = in_progress[0]
131-
student = db.lookup_identifier(visit["student_id"])
132190

133-
return {
134-
"id": visit["student_id"],
135-
"username": student["ubit"],
136-
"pn": student["person_num"],
137-
"preferred_name": student["preferred_name"],
138-
"visitID": visit["visit_id"],
139-
"visit_reason": visit["student_visit_reason"]
140-
}
141191

142192
@blueprint.route("/help-a-student", methods=["POST"])
143193
@min_level("ta")

api/server.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
import datetime
77
import io
88
import os
9-
109
import requests
1110
from flask import Flask, render_template, request, redirect
1211
from flask import send_file

client/src/App.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<script setup lang="ts">
22
3-
3+
44
55
</script>
66

@@ -15,4 +15,4 @@
1515
@import "assets/css/base.css";
1616
1717
18-
</style>
18+
</style>
192 KB
Loading

client/src/components/EnrollmentEntry.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,11 @@
33
const props = defineProps(['user_id', 'username', 'pn', 'preferred_name',
44
'last_name', 'course_role'])
55
6-
76
</script>
87

98
<template>
109
<tr>
11-
<td>{{ username }}</td>
10+
<td contenteditable="true" @input="() => { console.log(username) }">{{ username }}</td>
1211
<td>{{ pn }}</td>
1312
<td>{{ preferred_name }}</td>
1413
<td>{{ last_name }}</td>

client/src/components/QueueEntry.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ const dropdownVisible = ref<boolean>(false);
1515
<div @click='dropdownVisible = !dropdownVisible' class="queue-entry">
1616
<div class="queue-entry-info">{{ name }} ({{ ubit }})</div>
1717
<div class="queue-entry-buttons">
18-
<button @click="$emit('call-student', id)">Call</button>
18+
<button @click="$emit('call-student', id)">Start Visit</button>
1919
<button @click="$emit('remove-student', id)">Remove</button>
2020
<button @click="$emit('move-to-end', id)">Move to End</button>
2121
</div>

client/src/main.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import ManageCourse from "@/pages/ManageCourse.vue";
99
import Swipe from "@/pages/Swipe.vue";
1010
import SwipeAuth from "@/pages/SwipeAuth.vue";
1111
import AppLayout from "@/layouts/AppLayout.vue";
12+
import NotFound from "@/pages/NotFound.vue";
1213

1314
const router = createRouter({
1415
history: createWebHistory(),
@@ -18,7 +19,8 @@ const router = createRouter({
1819
{ path: '/queue', component: AppLayout, children: [{path: '/queue', component: Queue}]},
1920
{ path: '/manage', component: AppLayout, children: [{path: '/manage', component: ManageCourse}]},
2021
{ path: '/swipe', component: Swipe},
21-
{ path: '/swipe-auth', component: SwipeAuth}
22+
{ path: '/swipe-auth', component: SwipeAuth},
23+
{ path: '/:pathMatch(.*)*', component: AppLayout, children: [{path: '/:pathMatch(.*)*', component: NotFound}]}
2224
]
2325
})
2426

client/src/pages/Home.vue

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,12 @@ const router = useRouter()
99
1010
const autolabLink = ref<HTMLAnchorElement>();
1111
12+
fetch("/api/me").then(res => {
13+
if (res.ok) {
14+
router.push("/queue")
15+
}
16+
})
17+
1218
</script>
1319

1420
<template>

client/src/pages/NotFound.vue

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<script setup lang="ts">
2+
3+
import {useRouter} from "vue-router";
4+
5+
const router = useRouter()
6+
7+
</script>
8+
9+
<template>
10+
<div id="content">
11+
<img src="../assets/makeopenhorse.png" alt="Make Open Horse logo" class="big-logo">
12+
<p>Couldn't find what you were looking for. (Unless it was this horse)</p>
13+
<button class="no-grow" @click="router.push('/')">Go Home</button>
14+
</div>
15+
</template>
16+
17+
<style scoped>
18+
19+
#content {
20+
margin: 16px;
21+
display: flex;
22+
flex-direction: column;
23+
justify-content: center;
24+
text-align: center;
25+
gap: 8px;
26+
}
27+
28+
.big-logo {
29+
margin: auto;
30+
max-height: 65vh;
31+
}
32+
33+
button {
34+
margin: auto;
35+
}
36+
37+
</style>

0 commit comments

Comments
 (0)