riderle commited on
Commit
63424e9
·
1 Parent(s): 9d496c7

Add feedback form modal button (#5)

Browse files

- Add feedback form modal button (14c25abcff5ecc017922414ea30a1fc18947305d)
- Update chat_application/templates/home.html (71bf3c3376376342e8d96c7a65cb403683b912c8)
- Update chat_application/static/styles/styles.css (2fe51e23ad099eb32d220e7f37af3f2f1ecafcc5)
- Update chat_application/static/styles/styles.css (dccf66d0652f81f3b0b74c1f91b85d0853cb4a76)
- Update chat_application/main.py (60df311cf6360dbabcb32e30d033c8517545a83e)

chat_application/main.py CHANGED
@@ -143,6 +143,7 @@ frobot = "projects/700531062565/locations/us-central1/endpoints/2951406418055397
143
  client = MongoClient("mongodb://127.0.0.1:27017/")
144
  db = client["huggingFaceData"]
145
  rooms_collection = db.rooms
 
146
 
147
  # List of fruits to choose display names from
148
  FRUIT_NAMES = ["blueberry", "strawberry", "orange", "cherry"]
@@ -639,6 +640,16 @@ def choose():
639
  "ended": False,
640
  "ended_at": None
641
  })
 
 
 
 
 
 
 
 
 
 
642
 
643
  session['room'] = room_id
644
  session['display_name'] = user_name
@@ -807,6 +818,34 @@ def handle_message(payload):
807
  # Ask each bot for a response
808
  socketio.start_background_task(ask_bot_round, room)
809
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
810
  @socketio.on('disconnect')
811
  def handle_disconnect():
812
  room = session.get("room")
 
143
  client = MongoClient("mongodb://127.0.0.1:27017/")
144
  db = client["huggingFaceData"]
145
  rooms_collection = db.rooms
146
+ feedback_collection = db.feedback
147
 
148
  # List of fruits to choose display names from
149
  FRUIT_NAMES = ["blueberry", "strawberry", "orange", "cherry"]
 
640
  "ended": False,
641
  "ended_at": None
642
  })
643
+ # Create the new feedback in the database
644
+ feedback_collection.insert_one({
645
+ "_id": room_id,
646
+ # creation date/time
647
+ "created_at": datetime.utcnow(),
648
+ # user identity
649
+ "user_id": user_id,
650
+ # empty feedback history
651
+ "feedbacks": [],
652
+ })
653
 
654
  session['room'] = room_id
655
  session['display_name'] = user_name
 
818
  # Ask each bot for a response
819
  socketio.start_background_task(ask_bot_round, room)
820
 
821
+
822
+ @socketio.on('feedback_given')
823
+ def handle_message(payload):
824
+ room = session.get('room')
825
+ name = session.get('display_name')
826
+ if not room or not name:
827
+ return
828
+
829
+ text = payload.get("feedback", "").strip()
830
+ if not text:
831
+ return # ignore empty text
832
+
833
+ # Database-only message (with datetime)
834
+ db_feedback = {
835
+ "message": text,
836
+ "timestamp": datetime.utcnow()
837
+ }
838
+
839
+ print(db_feedback)
840
+ # Store the full version in the database
841
+ result = feedback_collection.update_one(
842
+ {"_id": room},
843
+ {"$push": {"feedback_responses": db_feedback}}
844
+ )
845
+
846
+ #LR TODO: add success/faillure msg and confirmation
847
+
848
+
849
  @socketio.on('disconnect')
850
  def handle_disconnect():
851
  room = session.get("room")
chat_application/static/styles/styles.css CHANGED
@@ -498,15 +498,48 @@ hr {
498
  background: #ccc;
499
  }
500
 
501
- #welcomeOkBtn, #timerOkBtn {
502
  background: green;
503
  color: white;
504
  }
505
 
506
- #welcomeOkBtn:hover, #timerOkBtn:hover {
507
  background: #016601;
508
  }
509
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
510
  #idYesBtn {
511
  background: green;
512
  color: white;
@@ -534,12 +567,12 @@ hr {
534
  background: #016991;
535
  }
536
 
537
- #endNoBtn {
538
  background: #e5e5e5;
539
  color: #333;
540
  }
541
 
542
- #endNoBtn:hover {
543
  background: #ccc;
544
  }
545
 
 
498
  background: #ccc;
499
  }
500
 
501
+ #welcomeOkBtn, #timerOkBtn, #submitFeedbackBtn {
502
  background: green;
503
  color: white;
504
  }
505
 
506
+ #welcomeOkBtn:hover, #timerOkBtn:hover, #submitFeedbackBtn:hover {
507
  background: #016601;
508
  }
509
 
510
+ #feedback-btn {
511
+ color: white;
512
+ font-weight: 800;
513
+ background-color: green;
514
+ text-decoration: none;
515
+ padding: 6px;
516
+ border: 2px solid green;
517
+ display: inline-block;
518
+ margin-top: 5px;
519
+ border-radius: 10px;
520
+ transition: all 0.1s ease-in;
521
+ }
522
+
523
+ #feedback-btn:hover {
524
+ color: green;
525
+ background-color: white;
526
+ }
527
+
528
+ .feedback-col {
529
+ display: flex;
530
+ flex-direction: column;
531
+ gap: 6px;
532
+
533
+ textarea {
534
+ width: 100%;
535
+ min-height: 120px;
536
+ padding: 10px;
537
+ border: 1px solid #ccc;
538
+ border-radius: 6px;
539
+ resize: vertical;
540
+ }
541
+ }
542
+
543
  #idYesBtn {
544
  background: green;
545
  color: white;
 
567
  background: #016991;
568
  }
569
 
570
+ #endNoBtn, #cancelFeedbackBtn {
571
  background: #e5e5e5;
572
  color: #333;
573
  }
574
 
575
+ #endNoBtn:hover, #cancelFeedbackBtn:hover {
576
  background: #ccc;
577
  }
578
 
chat_application/templates/home.html CHANGED
@@ -11,9 +11,6 @@
11
  <button type="button" id="continue">Continue</button>
12
  </div>
13
  <hr />
14
- <div class="feedback-notice">
15
- <p>We encourage you to message us directly through Prolific about any concerns. Additionally, you may provide feedback regarding the experiment <a class="feedback-link" target="_blank" href="{{ feedback_form_url | default('https://umw.qualtrics.com/jfe/form/SV_08v26NssCOwZTP8') }}">in this form</a>.</p>
16
- </div>
17
  </form>
18
  </div>
19
  <div id="confirmID-modal" class="modal">
 
11
  <button type="button" id="continue">Continue</button>
12
  </div>
13
  <hr />
 
 
 
14
  </form>
15
  </div>
16
  <div id="confirmID-modal" class="modal">
chat_application/templates/room.html CHANGED
@@ -30,6 +30,7 @@
30
  <h2 id="room-code-display">Topic: <span class="topic-title">{{ topic_info.title }}</span></h2>
31
  </div>
32
  <div class="topic-header-buttons">
 
33
  <button id="end-exp-btn">End Chat Session</button>
34
  <button id="abort-exp-btn">Abort Experiment</button>
35
  </div>
@@ -67,6 +68,22 @@
67
  </div>
68
  </div>
69
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  </div>
71
  <div id="chat-room-widget">
72
  <div id="msgs-container">
@@ -251,6 +268,30 @@
251
  document.getElementById("abortNoBtn").onclick = function () {
252
  abortModalConfirm.style.display = "none";
253
  };
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
254
 
255
  // add auto scroll
256
  function isNearBottom(container, threshold = 120) {
 
30
  <h2 id="room-code-display">Topic: <span class="topic-title">{{ topic_info.title }}</span></h2>
31
  </div>
32
  <div class="topic-header-buttons">
33
+ <button id="feedback-btn">Provide Feedback</button>
34
  <button id="end-exp-btn">End Chat Session</button>
35
  <button id="abort-exp-btn">Abort Experiment</button>
36
  </div>
 
68
  </div>
69
  </div>
70
  </div>
71
+ <div id="feedback-modal" class="modal">
72
+ <div class="modal-content">
73
+ <h3>Feedback</h3>
74
+ <form id="feedback-form">
75
+ <div class="feedback-col">
76
+ <label for="enter-feedback">Enter Feedback</label>
77
+ <textarea id="enter-feedback" name="feedback"></textarea>
78
+ </div>
79
+ <br>
80
+ <div class="modal-buttons">
81
+ <button class="modal-btn" id="submitFeedbackBtn" type="submit">Submit</button>
82
+ <button type="button" class="modal-btn" id="cancelFeedbackBtn">Cancel</button>
83
+ </div>
84
+ </form>
85
+ </div>
86
+ </div>
87
  </div>
88
  <div id="chat-room-widget">
89
  <div id="msgs-container">
 
268
  document.getElementById("abortNoBtn").onclick = function () {
269
  abortModalConfirm.style.display = "none";
270
  };
271
+
272
+ //handler for feedback modal popup
273
+ let feedbackModal = document.getElementById("feedback-modal");
274
+ let form = document.getElementById("feedback-form");
275
+ document.getElementById("feedback-btn").onclick = function () {
276
+ feedbackModal.style.display = "block";
277
+ };
278
+ document.getElementById("cancelFeedbackBtn").onclick = function () {
279
+ feedbackModal.style.display = "none";
280
+ };
281
+
282
+ //override form function to instead emit save feedback event
283
+ form.addEventListener("submit", function (e) {
284
+ e.preventDefault();
285
+
286
+ const data = new FormData(form);
287
+ const feedback = data.get("feedback")?.trim();
288
+
289
+ if (!feedback) return;
290
+ socketio.emit("feedback_given", { feedback });
291
+
292
+ form.reset();
293
+ document.getElementById("feedback-modal").style.display = "none";
294
+ });
295
 
296
  // add auto scroll
297
  function isNearBottom(container, threshold = 120) {