Update Bsb
Browse files
Bsb
CHANGED
|
@@ -541,4 +541,236 @@ backButton.addEventListener("click", async function(event){
|
|
| 541 |
console.error('Error checking eligibility:', error);
|
| 542 |
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 543 |
}
|
| 544 |
-
}); ---> in this why my 'bootstrapFeedbackModal.show();'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 541 |
console.error('Error checking eligibility:', error);
|
| 542 |
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 543 |
}
|
| 544 |
+
}); ---> in this why my 'bootstrapFeedbackModal.show();'
|
| 545 |
+
|
| 546 |
+
|
| 547 |
+
---------------------------
|
| 548 |
+
|
| 549 |
+
Feedback Modal Feature – Technical Design
|
| 550 |
+
|
| 551 |
+
|
| 552 |
+
---
|
| 553 |
+
|
| 554 |
+
1. Overview
|
| 555 |
+
|
| 556 |
+
This feature enables contextual user feedback collection in the “Document Chat & Summarization” UI.
|
| 557 |
+
Feedback (rating/comment) is requested only if the user selects a configuration (zone), engages in chat or summarization, and then attempts to leave the page via the back button.
|
| 558 |
+
|
| 559 |
+
|
| 560 |
+
---
|
| 561 |
+
|
| 562 |
+
2. Technical Architecture
|
| 563 |
+
|
| 564 |
+
Frontend
|
| 565 |
+
|
| 566 |
+
Stack: JavaScript (Vanilla), Bootstrap 5 (modal)
|
| 567 |
+
|
| 568 |
+
Session State:
|
| 569 |
+
|
| 570 |
+
Tracks currentZoneId (active configuration) and hasChatted (true if user has sent a message or summarized)
|
| 571 |
+
|
| 572 |
+
|
| 573 |
+
Eligibility Check:
|
| 574 |
+
|
| 575 |
+
On back button click, modal is triggered only if both currentZoneId is set and hasChatted is true.
|
| 576 |
+
|
| 577 |
+
|
| 578 |
+
API Integration:
|
| 579 |
+
|
| 580 |
+
AJAX/fetch to /user_feedback_eligibility endpoint for final eligibility confirmation and feedback prefill.
|
| 581 |
+
|
| 582 |
+
POST to /submit_feedback endpoint for feedback persistence.
|
| 583 |
+
|
| 584 |
+
|
| 585 |
+
|
| 586 |
+
Backend
|
| 587 |
+
|
| 588 |
+
Stack: Flask (UI Gateway), FastAPI (microservices), PostgreSQL
|
| 589 |
+
|
| 590 |
+
Security: All feedback endpoints protected via Flask’s @login_required decorator.
|
| 591 |
+
|
| 592 |
+
Eligibility Endpoint:
|
| 593 |
+
/user_feedback_eligibility returns:
|
| 594 |
+
|
| 595 |
+
eligible_for_feedback (True if chat exists for notebook/zone)
|
| 596 |
+
|
| 597 |
+
has_feedback (True if prior feedback exists)
|
| 598 |
+
|
| 599 |
+
rating, comment (prefill values if present)
|
| 600 |
+
|
| 601 |
+
|
| 602 |
+
Submission Endpoint:
|
| 603 |
+
/submit_feedback creates or updates feedback in DB.
|
| 604 |
+
|
| 605 |
+
|
| 606 |
+
Data Model
|
| 607 |
+
|
| 608 |
+
feedback (
|
| 609 |
+
id SERIAL PRIMARY KEY,
|
| 610 |
+
user_id VARCHAR,
|
| 611 |
+
notebook_id INT,
|
| 612 |
+
effort_id INT,
|
| 613 |
+
zone_id INT,
|
| 614 |
+
rating INT,
|
| 615 |
+
comment TEXT,
|
| 616 |
+
created_at TIMESTAMP DEFAULT NOW(),
|
| 617 |
+
UNIQUE(user_id, notebook_id, effort_id, zone_id)
|
| 618 |
+
)
|
| 619 |
+
|
| 620 |
+
|
| 621 |
+
---
|
| 622 |
+
|
| 623 |
+
3. Flow Sequence (with Tech Detail)
|
| 624 |
+
|
| 625 |
+
1. Zone selection:
|
| 626 |
+
User selects a configuration from the dropdown; currentZoneId is set.
|
| 627 |
+
|
| 628 |
+
|
| 629 |
+
2. Chat/Summarize interaction:
|
| 630 |
+
On any message or summary, hasChatted = true; in JS.
|
| 631 |
+
|
| 632 |
+
|
| 633 |
+
3. Back button event:
|
| 634 |
+
On click, JS checks:
|
| 635 |
+
|
| 636 |
+
If no zone or hasChatted == false, navigates away with no modal.
|
| 637 |
+
|
| 638 |
+
If both present, calls /user_feedback_eligibility.
|
| 639 |
+
|
| 640 |
+
|
| 641 |
+
|
| 642 |
+
4. Eligibility check (backend):
|
| 643 |
+
Flask endpoint verifies chat history via FastAPI; returns feedback eligibility and prefill values.
|
| 644 |
+
|
| 645 |
+
|
| 646 |
+
5. Modal Display:
|
| 647 |
+
|
| 648 |
+
If eligible, Bootstrap modal is shown. Prefilled if feedback exists.
|
| 649 |
+
|
| 650 |
+
|
| 651 |
+
|
| 652 |
+
6. Feedback submission:
|
| 653 |
+
|
| 654 |
+
On modal submit, JS POSTs feedback to /submit_feedback.
|
| 655 |
+
|
| 656 |
+
FastAPI microservice creates or updates DB row.
|
| 657 |
+
|
| 658 |
+
|
| 659 |
+
|
| 660 |
+
|
| 661 |
+
|
| 662 |
+
---
|
| 663 |
+
|
| 664 |
+
4. API Reference
|
| 665 |
+
|
| 666 |
+
Eligibility Request (GET):
|
| 667 |
+
|
| 668 |
+
/user_feedback_eligibility?user_id=...¬ebook_id=...&zone_id=...
|
| 669 |
+
|
| 670 |
+
Returns:
|
| 671 |
+
|
| 672 |
+
|
| 673 |
+
{
|
| 674 |
+
"eligible_for_feedback": true,
|
| 675 |
+
"has_feedback": true,
|
| 676 |
+
"rating": 4,
|
| 677 |
+
"comment": "Nice"
|
| 678 |
+
}
|
| 679 |
+
|
| 680 |
+
Feedback Submission (POST):
|
| 681 |
+
|
| 682 |
+
/submit_feedback
|
| 683 |
+
Payload:
|
| 684 |
+
{
|
| 685 |
+
"user_id": "PI0001",
|
| 686 |
+
"notebook_id": 2,
|
| 687 |
+
"effort_id": 1,
|
| 688 |
+
"zone_id": 36,
|
| 689 |
+
"rating": 4,
|
| 690 |
+
"comment": "Nice"
|
| 691 |
+
}
|
| 692 |
+
|
| 693 |
+
|
| 694 |
+
---
|
| 695 |
+
|
| 696 |
+
5. Edge Cases & Error Handling
|
| 697 |
+
|
| 698 |
+
Session loss:
|
| 699 |
+
If the user refreshes, hasChatted resets. Modal will not pop up unless the user interacts again.
|
| 700 |
+
|
| 701 |
+
API failure:
|
| 702 |
+
|
| 703 |
+
Eligibility API failure: User is redirected back.
|
| 704 |
+
|
| 705 |
+
Submission API failure: User sees an error alert.
|
| 706 |
+
|
| 707 |
+
|
| 708 |
+
Feedback updates:
|
| 709 |
+
Existing feedback is prefilled and updatable via the modal.
|
| 710 |
+
|
| 711 |
+
Security:
|
| 712 |
+
All endpoints require authentication (@login_required).
|
| 713 |
+
|
| 714 |
+
|
| 715 |
+
|
| 716 |
+
---
|
| 717 |
+
|
| 718 |
+
6. Pseudocode (Frontend Eligibility Logic)
|
| 719 |
+
|
| 720 |
+
let hasChatted = false;
|
| 721 |
+
function sendMessage() { ... hasChatted = true; }
|
| 722 |
+
function summarize() { ... hasChatted = true; }
|
| 723 |
+
|
| 724 |
+
backButton.addEventListener("click", async function(event) {
|
| 725 |
+
if (!currentZoneId) { goBack(); return; }
|
| 726 |
+
if (!hasChatted) { goBack(); return; }
|
| 727 |
+
// Call backend for eligibility check and show modal if eligible
|
| 728 |
+
});
|
| 729 |
+
|
| 730 |
+
|
| 731 |
+
---
|
| 732 |
+
|
| 733 |
+
7. Sequence Diagram (Textual)
|
| 734 |
+
|
| 735 |
+
User
|
| 736 |
+
↓
|
| 737 |
+
[Select Zone] --(sets currentZoneId)-->
|
| 738 |
+
↓
|
| 739 |
+
[Chat/Summarize] --(sets hasChatted)-->
|
| 740 |
+
↓
|
| 741 |
+
[Click Back]
|
| 742 |
+
↓
|
| 743 |
+
[JS: If both set, call API]
|
| 744 |
+
↓
|
| 745 |
+
[Flask: /user_feedback_eligibility]
|
| 746 |
+
↓
|
| 747 |
+
[FastAPI: Checks chat history]
|
| 748 |
+
↓
|
| 749 |
+
[Return eligible? Prefill values?]
|
| 750 |
+
↓
|
| 751 |
+
[If eligible: Show modal]
|
| 752 |
+
↓
|
| 753 |
+
[User submits feedback]
|
| 754 |
+
↓
|
| 755 |
+
[JS: POST to /submit_feedback]
|
| 756 |
+
↓
|
| 757 |
+
[FastAPI: Store/update feedback in DB]
|
| 758 |
+
|
| 759 |
+
|
| 760 |
+
---
|
| 761 |
+
|
| 762 |
+
8. Security & Robustness Notes
|
| 763 |
+
|
| 764 |
+
State variables (hasChatted, currentZoneId) are session-only and do not persist on page reload.
|
| 765 |
+
|
| 766 |
+
Server-side check guarantees modal is shown only after real chat/summarize event.
|
| 767 |
+
|
| 768 |
+
No feedback collection for passive/idle sessions.
|
| 769 |
+
|
| 770 |
+
|
| 771 |
+
|
| 772 |
+
---
|
| 773 |
+
|
| 774 |
+
Summary
|
| 775 |
+
|
| 776 |
+
This design guarantees that feedback is solicited only after meaningful user interaction in the correct context, prevents duplicate feedback, and provides seamless update flows. All actions are secured, API-driven, and fail-safe against common errors.
|