From b2ace0759bb704ba1eb15db012ad4f1b1b61b002 Mon Sep 17 00:00:00 2001 From: amanshah2711 <36978283+amanshah2711@users.noreply.github.com> Date: Tue, 14 Jul 2020 22:53:39 -0400 Subject: [PATCH 1/3] updating oh appts so pending appoints can be restricted by time (#219) --- .../components/admin_appointments_manager.js | 5 +++- oh_queue/views.py | 23 +++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/oh_queue/static/js/components/admin_appointments_manager.js b/oh_queue/static/js/components/admin_appointments_manager.js index cd3001f..382cc3b 100644 --- a/oh_queue/static/js/components/admin_appointments_manager.js +++ b/oh_queue/static/js/components/admin_appointments_manager.js @@ -61,8 +61,11 @@ function AdminAppointmentsManager({ state }) {

- How many appointments should a student have be pending simultaneously? + How many appointments should a student have be pending simultaneously?

+ (by + + ) = 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"], From 7dc19b9905968c15ba16cf1e4d6ebebdadc12268 Mon Sep 17 00:00:00 2001 From: Andrew Chen Date: Wed, 5 Aug 2020 01:26:57 -0700 Subject: [PATCH 2/3] Add day and time to messages --- oh_queue/static/js/components/chat_box.js | 17 +++++++++++------ oh_queue/views.py | 2 ++ 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/oh_queue/static/js/components/chat_box.js b/oh_queue/static/js/components/chat_box.js index f223c86..6405615 100644 --- a/oh_queue/static/js/components/chat_box.js +++ b/oh_queue/static/js/components/chat_box.js @@ -27,10 +27,11 @@ function ChatBox({ currentUser, socket, id, mode }) { content: typed, mode, id, + time: 0 }); setTyped(""); }; - + const scrollDown = () => { $('[data-toggle="tooltip"]').tooltip() historyRef.current.scrollTop = historyRef.current.scrollHeight; @@ -43,30 +44,34 @@ 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) => { if (sender.id === currentUser.id) { return (
-
{message}
+
{message}{time}
) } else if (messages[i + 1] && sender.id === messages[i + 1][0].id) { return (
{sender.shortName[0]}
-
{message}
+
{message}{time}
) } else { return (
{sender.shortName[0]}
-
{message}
+
{message}{time}
) } diff --git a/oh_queue/views.py b/oh_queue/views.py index 0701526..af48b85 100644 --- a/oh_queue/views.py +++ b/oh_queue/views.py @@ -1155,6 +1155,8 @@ def send_chat_message(data): event_id = data["id"] data["sender"] = user_json(current_user) + timeStr = get_current_time().strftime("%a %-I:%M%p") + data["time"] = timeStr if mode == "appointment": appointment = Appointment.query.filter_by(course=get_course(), id=event_id).one() From 003a451c48caa8c39c9cba399f516b080dac988d Mon Sep 17 00:00:00 2001 From: Andrew Chen Date: Wed, 5 Aug 2020 01:30:25 -0700 Subject: [PATCH 3/3] Format time as part of chat bubble tooltip --- oh_queue/static/js/components/chat_box.js | 37 +++++++++++++++++++++-- oh_queue/views.py | 4 +-- 2 files changed, 36 insertions(+), 5 deletions(-) diff --git a/oh_queue/static/js/components/chat_box.js b/oh_queue/static/js/components/chat_box.js index 6405615..da572bf 100644 --- a/oh_queue/static/js/components/chat_box.js +++ b/oh_queue/static/js/components/chat_box.js @@ -23,6 +23,7 @@ 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, @@ -54,24 +55,54 @@ function ChatBox({ currentUser, socket, id, mode }) { }, [messages]); 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 (
-
{message}{time}
+
+ {message} +
) } else if (messages[i + 1] && sender.id === messages[i + 1][0].id) { return (
{sender.shortName[0]}
-
{message}{time}
+
+ {message} +
) } else { return (
{sender.shortName[0]}
-
{message}{time}
+
+ {message} +
) } diff --git a/oh_queue/views.py b/oh_queue/views.py index af48b85..4fa577c 100644 --- a/oh_queue/views.py +++ b/oh_queue/views.py @@ -1155,8 +1155,8 @@ def send_chat_message(data): event_id = data["id"] data["sender"] = user_json(current_user) - timeStr = get_current_time().strftime("%a %-I:%M%p") - data["time"] = timeStr + 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()