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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
|
| 2 |
+
// Feedback Modal POP-UP on Back Button
|
| 3 |
+
backButton.addEventListener("click", async function(event){
|
| 4 |
+
console.log("Back button clicked");
|
| 5 |
+
event.preventDefault();
|
| 6 |
+
|
| 7 |
+
if(!currentZoneId){
|
| 8 |
+
console.log("no configuration selected, going back directly")
|
| 9 |
+
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 10 |
+
return;
|
| 11 |
+
}
|
| 12 |
+
|
| 13 |
+
console.log("Debug BackBtn:", {userId, notebookId, currentZoneId, effortId});
|
| 14 |
+
try {
|
| 15 |
+
console.log("Checking user feedback eligibility...");
|
| 16 |
+
// CHANGED/ADDED: Fetch eligibility data from the server
|
| 17 |
+
const response = await fetch(`/chat_feature/user_feedback_eligibility?user_id=${userId}¬ebook_id=${notebookId}&zone_id=${currentZoneId}`);
|
| 18 |
+
const data = await response.json();
|
| 19 |
+
|
| 20 |
+
if (data.eligible_for_feedback) {
|
| 21 |
+
console.log("User is eligible for feedback:", data);
|
| 22 |
+
// CHANGED/ADDED: Initialize the modal here
|
| 23 |
+
if(data.has_feedback){
|
| 24 |
+
document.getElementById("feedbackLevel").value = data.rating ||"";
|
| 25 |
+
document.getElementById("comment").value = data.comment ||"";
|
| 26 |
+
document.getElementById("updateNotice").style.display = "block";
|
| 27 |
+
}
|
| 28 |
+
else{
|
| 29 |
+
document.getElementById("feedbackLevel").value = data.rating ||"";
|
| 30 |
+
document.getElementById("comment").value = data.comment ||"";
|
| 31 |
+
document.getElementById("updateNotice").style.display = "none";
|
| 32 |
+
}
|
| 33 |
+
// CHANGED/ADDED: Now modal will always be initialized and ready here
|
| 34 |
+
|
| 35 |
+
console.log(bootstrapFeedbackModal);
|
| 36 |
+
if (bootstrapFeedbackModal) {
|
| 37 |
+
console.log("Showing feedback modal");
|
| 38 |
+
bootstrapFeedbackModal.show();
|
| 39 |
+
} else {
|
| 40 |
+
alert("Feedback modal not initialized!");
|
| 41 |
+
}
|
| 42 |
+
} else {
|
| 43 |
+
console.log("User is not eligible for feedback:", data);
|
| 44 |
+
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 45 |
+
}
|
| 46 |
+
} catch (error) {
|
| 47 |
+
console.error('Error checking eligibility:', error);
|
| 48 |
+
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 49 |
+
}
|
| 50 |
+
});
|
| 51 |
+
|
| 52 |
+
// Feedback Submit
|
| 53 |
+
document.getElementById("submitFeedback").addEventListener("click", async function () {
|
| 54 |
+
const rating = document.getElementById("feedbackLevel").value;
|
| 55 |
+
const comment = document.getElementById("comment").value;
|
| 56 |
+
|
| 57 |
+
const payload = {
|
| 58 |
+
user_id: userId,
|
| 59 |
+
notebook_id: parseInt(notebookId),
|
| 60 |
+
effort_id: parseInt(effortId),
|
| 61 |
+
zone_id: parseInt(currentZoneId),
|
| 62 |
+
rating: rating ? parseInt(rating) : null,
|
| 63 |
+
comment: comment
|
| 64 |
+
};
|
| 65 |
+
|
| 66 |
+
try {
|
| 67 |
+
const response = await fetch("/chat_feature/submit_feedback", {
|
| 68 |
+
method: "POST",
|
| 69 |
+
headers: { "Content-Type": "application/json" },
|
| 70 |
+
body: JSON.stringify(payload)
|
| 71 |
+
});
|
| 72 |
+
|
| 73 |
+
if (response.ok) {
|
| 74 |
+
bootstrapFeedbackModal.hide();
|
| 75 |
+
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 76 |
+
} else {
|
| 77 |
+
alert("Error submitting feedback");
|
| 78 |
+
}
|
| 79 |
+
} catch (error) {
|
| 80 |
+
console.error("Error submitting feedback:", error);
|
| 81 |
+
alert("Error submitting feedback");
|
| 82 |
+
}
|
| 83 |
+
});
|
| 84 |
+
|
| 85 |
+
// Skip feedback
|
| 86 |
+
document.getElementById("skipFeedback").addEventListener("click", function () {
|
| 87 |
+
bootstrapFeedbackModal.hide();
|
| 88 |
+
window.location.href = `/notebook/?effort_id=${effortId}&user_id=${userId}`;
|
| 89 |
+
}); ------
|
| 90 |
+
|
| 91 |
+
# #-------to post the feedback data-------
|
| 92 |
+
@chat_feature_bp.route('/submit_feedback', methods=['POST'])
|
| 93 |
+
@login_required
|
| 94 |
+
def submit_feedback():
|
| 95 |
+
data = request.json
|
| 96 |
+
print(data)
|
| 97 |
+
feedback_payload = {
|
| 98 |
+
"user_id": data.get("user_id"),
|
| 99 |
+
"notebook_id": data.get("notebook_id"),
|
| 100 |
+
"effort_id": data.get("effort_id"),
|
| 101 |
+
"zone_id": data.get("zone_id"),
|
| 102 |
+
"rating": data.get("rating"),
|
| 103 |
+
"comment": data.get("comment"),
|
| 104 |
+
}
|
| 105 |
+
|
| 106 |
+
response = requests.post("http://localhost:8044/feedback/", json = feedback_payload)
|
| 107 |
+
|
| 108 |
+
print("Recieved Feedback", feedback_payload)
|
| 109 |
+
|
| 110 |
+
return jsonify(response.json()),response.status_code
|
| 111 |
+
|
| 112 |
+
@chat_feature_bp.route("/user_feedback_eligibility", methods=["GET"])
|
| 113 |
+
@login_required
|
| 114 |
+
def user_feedback_eligibility():
|
| 115 |
+
user_id = request.args.get("user_id")
|
| 116 |
+
notebook_id = request.args.get("notebook_id")
|
| 117 |
+
zone_id = request.args.get("zone_id")
|
| 118 |
+
|
| 119 |
+
if not zone_id:
|
| 120 |
+
return jsonify({"eligible_for_feedback": False})
|
| 121 |
+
|
| 122 |
+
try:
|
| 123 |
+
notebook_response = requests.get(f"http://localhost:8044/user/get_notebook_details/{notebook_id}")
|
| 124 |
+
notebook_response.raise_for_status()
|
| 125 |
+
chat_data = notebook_response.json().get('chat', {}).get('message', [])
|
| 126 |
+
eligible = len(chat_data) > 0
|
| 127 |
+
except Exception as e:
|
| 128 |
+
print(f"Error fetching notebook details: {e}")
|
| 129 |
+
return jsonify({"eligible_for_feedback": False, "error": "notebook fetch failed"}), 500
|
| 130 |
+
|
| 131 |
+
try:
|
| 132 |
+
feedback_response = requests.get(
|
| 133 |
+
"http://localhost:8044/feedback/",
|
| 134 |
+
params={"user_id": user_id, "notebook_id": notebook_id, "zone_id": zone_id}
|
| 135 |
+
)
|
| 136 |
+
feedback_data = feedback_response.json() if feedback_response.ok else {"exists": False}
|
| 137 |
+
except Exception as e:
|
| 138 |
+
print(f"Error fetching feedback: {e}")
|
| 139 |
+
feedback_data = {"exists": False}
|
| 140 |
+
|
| 141 |
+
response = {
|
| 142 |
+
"eligible_for_feedback": eligible,
|
| 143 |
+
"has_feedback": feedback_data.get("exists", False)
|
| 144 |
+
}
|
| 145 |
+
|
| 146 |
+
if feedback_data.get("exists"):
|
| 147 |
+
response.update({
|
| 148 |
+
"rating": feedback_data.get("rating"),
|
| 149 |
+
"comment": feedback_data.get("comment")
|
| 150 |
+
})
|
| 151 |
+
print("User feedback eligibility response:", response)
|
| 152 |
+
return jsonify(response) ---> this is flask ui python file and #created a api to call that create_feedback function-------
|
| 153 |
+
@router.post("/feedback/")
|
| 154 |
+
async def create_feedback_endpoint(feedback: Feedback):
|
| 155 |
+
try:
|
| 156 |
+
# result = create_feedback(user_id= feedback.user_id, notebook_id= feedback.notebook_id, effort_id= feedback.effort_id, rating= feedback.rating, comment= feedback.comment)
|
| 157 |
+
|
| 158 |
+
create_or_update_feedback(
|
| 159 |
+
user_id=feedback.user_id,
|
| 160 |
+
notebook_id=feedback.notebook_id,
|
| 161 |
+
effort_id=feedback.effort_id,
|
| 162 |
+
zone_id=feedback.zone_id,
|
| 163 |
+
rating=feedback.rating,
|
| 164 |
+
comment=feedback.comment
|
| 165 |
+
)
|
| 166 |
+
|
| 167 |
+
return {"message": "Feedback submitted successfully"}
|
| 168 |
+
|
| 169 |
+
except Exception as e:
|
| 170 |
+
raise HTTPException(status_code=500, detail="Failed to submit feedback")
|
| 171 |
+
|
| 172 |
+
@router.get("/feedback/")
|
| 173 |
+
async def get_existing_feedback(user_id: str, notebook_id: str, zone_id: str):
|
| 174 |
+
try:
|
| 175 |
+
feedback= get_feedback(user_id, notebook_id, zone_id)
|
| 176 |
+
if feedback:
|
| 177 |
+
return{"exists": True, "rating": feedback["rating"], "comment": feedback["comment"]}
|
| 178 |
+
else:
|
| 179 |
+
return{"exists": False}
|
| 180 |
+
except Exception as e:
|
| 181 |
+
raise HTTPException(status_code=500, details="Failed to fetch feedback") --> this my backend api endpoint with class #feedbackModal class
|
| 182 |
+
class Feedback(BaseModel):
|
| 183 |
+
user_id: str
|
| 184 |
+
notebook_id: str
|
| 185 |
+
effort_id: str
|
| 186 |
+
zone_id: str
|
| 187 |
+
#rating: Optional[str] = None
|
| 188 |
+
rating: Optional[int] = None
|
| 189 |
+
comment: Optional[str] = None
|