Skip to content
This repository was archived by the owner on Sep 7, 2020. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion oh_queue/static/js/components/admin_appointments_manager.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,11 @@ function AdminAppointmentsManager({ state }) {
<tr>
<td>
<p>
How many appointments should a student have be pending simultaneously?
How many appointments should a student have be pending simultaneously?
</p>
(by
<ConfigLinkedToggle config={state.config} configKey="appointment_or_minutes" onText="minutes" offText="number"/>
)
</td>
<td className="col-md-3">
<ConfigLinkedNumeric
Expand Down
48 changes: 42 additions & 6 deletions oh_queue/static/js/components/chat_box.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,16 @@ function ChatBox({ currentUser, socket, id, mode }) {
if (!typed.trim()) {
return;
}
// Time is initialized in "send_chat_message".
app.makeRequest("send_chat_message", {
content: typed,
mode,
id,
time: 0
});
setTyped("");
};

const scrollDown = () => {
$('[data-toggle="tooltip"]').tooltip()
historyRef.current.scrollTop = historyRef.current.scrollHeight;
Expand All @@ -43,30 +45,64 @@ function ChatBox({ currentUser, socket, id, mode }) {
if (message.mode !== mode || message.id !== id) {
return;
}
setMessages(messages.concat([[message.sender, message.content]]));
setMessages(messages.concat([[
message.sender,
message.content,
message.time
]]));
});
return () => socket.removeAllListeners("chat_message");
}, [messages]);

const body = messages.map(([sender, message], i) => {
const body = messages.map(([sender, message, time], i) => {
function formatTitle(name, time) {
if (name === undefined) {
return time
} else if (time === undefined) {
return name
}
return name + ' | ' + time;
}

if (sender.id === currentUser.id) {
return (
<div className="my-chat-bubble">
<div className="chat-text">{message}</div>
<div
className="chat-text"
data-toggle="tooltip"
data-placement="right"
title={formatTitle(time)}
>
{message}
</div>
</div>
)
} else if (messages[i + 1] && sender.id === messages[i + 1][0].id) {
return (
<div className="chat-bubble">
<div className="chat-icon none">{sender.shortName[0]}</div>
<div className="chat-text" data-toggle="tooltip" data-placement="right" title={sender.name}>{message}</div>
<div
className="chat-text"
data-toggle="tooltip"
data-placement="right"
title={formatTitle(sender.name, time)}
>
{message}
</div>
</div>
)
} else {
return (
<div className="chat-bubble">
<div className="chat-icon">{sender.shortName[0]}</div>
<div className="chat-text" data-toggle="tooltip" data-placement="right" title={sender.name}>{message}</div>
<div
className="chat-text"
data-toggle="tooltip"
data-placement="right"
title={formatTitle(sender.name, time)}
>
{message}
</div>
</div>
)
}
Expand Down
25 changes: 21 additions & 4 deletions oh_queue/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ def init_config():
public=True,
course=get_course(),
))
db.session.add(ConfigEntry(
key='appointment_or_minutes',
value='false',
public=True,
course=get_course(),
))
db.session.add(ConfigEntry(
key='show_okpy_backups',
value='false',
Expand Down Expand Up @@ -922,6 +928,7 @@ def assign_appointment(data):
daily_threshold = int(ConfigEntry.query.filter_by(key="daily_appointment_limit", course=get_course()).one().value)
weekly_threshold = int(ConfigEntry.query.filter_by(key="weekly_appointment_limit", course=get_course()).one().value)
pending_threshold = int(ConfigEntry.query.filter_by(key="simul_appointment_limit", course=get_course()).one().value)
pending_metric= ConfigEntry.query.filter_by(key="appointment_or_minutes", course=get_course()).one().value

start = appointment.start_time.replace(hour=0, minute=0, second=0, microsecond=0)
week_start = start - datetime.timedelta(days=appointment.start_time.weekday())
Expand All @@ -940,13 +947,21 @@ def assign_appointment(data):
).count()
if num_today >= daily_threshold:
return socket_error("You have already signed up for {} OH slots for the same day".format(daily_threshold))

num_pending = AppointmentSignup.query.join(AppointmentSignup.appointment).filter(
Appointment.status == AppointmentStatus.pending,
AppointmentSignup.user_id == current_user.id,
).count()
if num_pending >= pending_threshold:
return socket_error("You have already signed up for {} OH slots that have not yet occurred.".format(pending_threshold))
)
if pending_metric != 'false':
start = appointment.duration
num_pend = [appt.appointment.duration for appt in list(num_pending)]
threshold = datetime.timedelta(minutes=pending_threshold)
for item in num_pend:
start += item
if start > threshold:
return socket_error("You cannot sign up for more than {} minutes of OH that have not yet occurred.".format(pending_threshold))
else:
if num_pending.count() >= pending_threshold:
return socket_error("You have already signed up for {} OH slots that have not yet occurred.".format(pending_threshold))

old_signup = AppointmentSignup.query.filter_by(
appointment_id=data["appointment_id"],
Expand Down Expand Up @@ -1140,6 +1155,8 @@ def send_chat_message(data):
event_id = data["id"]

data["sender"] = user_json(current_user)
message_time = get_current_time().strftime("%a %-I:%M%p")
data["time"] = message_time

if mode == "appointment":
appointment = Appointment.query.filter_by(course=get_course(), id=event_id).one()
Expand Down