From 146b20dc0a84b1e8e5afcc8c46ee76ef8497ca0a Mon Sep 17 00:00:00 2001 From: Fleur Gahimbare Date: Wed, 30 Aug 2023 17:41:29 -0400 Subject: [PATCH 01/10] start adding resubmit button --- .../admin_routes/allPendingForms.py | 21 +++++++++++++++++++ app/static/js/allPendingForms.js | 12 +++++++++++ app/templates/snips/studentHistoryModal.html | 4 ++++ 3 files changed, 37 insertions(+) diff --git a/app/controllers/admin_routes/allPendingForms.py b/app/controllers/admin_routes/allPendingForms.py index ed91569b..4df7be3c 100644 --- a/app/controllers/admin_routes/allPendingForms.py +++ b/app/controllers/admin_routes/allPendingForms.py @@ -244,6 +244,27 @@ def finalUpdateStatus(raw_status): form_ids = eval(request.data.decode("utf-8")) return saveStatus(new_status, form_ids, currentUser) +@admin.route('/admin/addToBanner', methods=['POST']) +def addToBanner(form_ids, currenttUser): + for id in form_ids: + history_type_data = FormHistory.get(FormHistory.formHistoryID == int(id)) + history_type = str(history_type_data.historyType) + + labor_forms = FormHistory.get(FormHistory.formHistoryID == int(id), FormHistory.historyType == history_type) + labor_forms.status = Status.get(Status.statusName == new_status) + labor_forms.reviewedDate = date.today() + labor_forms.reviewedBy = currentUser + + # Add to BANNER + save_status = True # default true so that we will still save in other cases + if new_status == 'Approved' and history_type == "Labor Status Form" and labor_forms.formID.POSN_CODE != "S12345": # don't update banner for Adjustment forms or for CS dummy position + if labor_forms.formID.POSN_CODE == "SNOLAB": + labor_forms.formID.weeklyHours = 10 + conn = Banner() + save_status = conn.insert(labor_forms) + + + def saveStatus(new_status, form_ids, currentUser): try: if new_status == 'Denied': diff --git a/app/static/js/allPendingForms.js b/app/static/js/allPendingForms.js index 1d2f98e2..9e1e59d1 100644 --- a/app/static/js/allPendingForms.js +++ b/app/static/js/allPendingForms.js @@ -145,6 +145,18 @@ function finalApproval() { //this method changes the status of the lsf from pend }); } +function addToBanner(){ + $.ajax({ + type: "POST", + url: "/admin/addToBanner", + datatype: "json", + data: data, + contentType: 'application/json', + + }); +} + + var laborDenialInfo = []; //this arrary is for insertDenial() and finalDenial() methods //This method calls AJAX from checkforms methods in the controller function insertDenial(val) { diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index 0797974f..d35714a7 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -234,6 +234,10 @@ {% endif %} + {% if buttonState.evaluation_exists %} + + + {% endif %} {% endif %} From 64b3a14e56d7dda1aae62d4269ee1388d9133342 Mon Sep 17 00:00:00 2001 From: bineta doucoure Date: Wed, 30 Aug 2023 18:06:07 -0600 Subject: [PATCH 02/10] Button for the resubmitting form to banner --- app/templates/snips/studentHistoryModal.html | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index d35714a7..b9281481 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -232,10 +232,10 @@ + {% endif %} {% if buttonState.evaluation_exists %} - {% endif %} {% endif %} From 032baac180961f97350a8b6eb5a90fdfb87b7d03 Mon Sep 17 00:00:00 2001 From: Fleur Gahimbare Date: Tue, 5 Sep 2023 15:20:15 -0400 Subject: [PATCH 03/10] create a function to submit to banner --- .../admin_routes/allPendingForms.py | 50 ++++++++++++++----- app/static/js/allPendingForms.js | 27 ++++++++-- app/templates/snips/studentHistoryModal.html | 34 +++++++------ 3 files changed, 79 insertions(+), 32 deletions(-) diff --git a/app/controllers/admin_routes/allPendingForms.py b/app/controllers/admin_routes/allPendingForms.py index 4df7be3c..5b911b24 100644 --- a/app/controllers/admin_routes/allPendingForms.py +++ b/app/controllers/admin_routes/allPendingForms.py @@ -242,27 +242,51 @@ def finalUpdateStatus(raw_status): print("Unknown status: ", raw_status) return jsonify({"success": False}) form_ids = eval(request.data.decode("utf-8")) + return saveStatus(new_status, form_ids, currentUser) -@admin.route('/admin/addToBanner', methods=['POST']) -def addToBanner(form_ids, currenttUser): - for id in form_ids: - history_type_data = FormHistory.get(FormHistory.formHistoryID == int(id)) - history_type = str(history_type_data.historyType) +# Add a new route for submitting to Banner +@app.route('/admin/submitToBanner', methods=['POST']) +def submitToBanner(): + form_ids = eval(request.data.decode("utf-8")) + print(form_ids) + form_ids = form_ids[:1] - labor_forms = FormHistory.get(FormHistory.formHistoryID == int(id), FormHistory.historyType == history_type) - labor_forms.status = Status.get(Status.statusName == new_status) - labor_forms.reviewedDate = date.today() - labor_forms.reviewedBy = currentUser - # Add to BANNER - save_status = True # default true so that we will still save in other cases - if new_status == 'Approved' and history_type == "Labor Status Form" and labor_forms.formID.POSN_CODE != "S12345": # don't update banner for Adjustment forms or for CS dummy position + currentUser = require_login() + if not currentUser: # Not logged in + return render_template('errors/403.html'), 403 + if not currentUser.isLaborAdmin: # Not an admin + return render_template('errors/403.html'), 403 + + try: + if not form_ids: + return jsonify({"success": False, "error": "No form IDs provided"}), 400 # Return an error if form_ids is empty + + for form_id in form_ids: + labor_forms = FormHistory.get(FormHistory.formHistoryID == form_id) + history_type = str(labor_forms.historyType) + + # Check if it's an Adjustment Form or CS dummy position + if history_type == "Labor Status Form" and labor_forms.formID.POSN_CODE != "S12345": if labor_forms.formID.POSN_CODE == "SNOLAB": - labor_forms.formID.weeklyHours = 10 + labor_forms.formID.weeklyHours = 10 conn = Banner() save_status = conn.insert(labor_forms) + if save_status: + labor_forms.save() + else: + print("Unable to submit to Banner for formHistoryID {}.".format(form_id)) + return jsonify({"success": False}), 500 + + return jsonify({"success": True}) # Return success JSON response + + except Exception as e: + print("Error preparing form for submission to Banner:", e) + return jsonify({"success": False}), 500 + + def saveStatus(new_status, form_ids, currentUser): diff --git a/app/static/js/allPendingForms.js b/app/static/js/allPendingForms.js index 9e1e59d1..4176c642 100644 --- a/app/static/js/allPendingForms.js +++ b/app/static/js/allPendingForms.js @@ -145,18 +145,37 @@ function finalApproval() { //this method changes the status of the lsf from pend }); } -function addToBanner(){ +function submitToBanner() { + $(".btn").prop("disabled", true); + $(".close").prop("disabled", true); + $("#submitToBannerButton").text("Processing..."); + var data = JSON.stringify(labor_details_ids); $.ajax({ type: "POST", - url: "/admin/addToBanner", - datatype: "json", - data: data, + url: "/admin/submitToBanner", // Remove the trailing slash + data: data, // Pass the JSON data in the request body contentType: 'application/json', + success: function(response) { + if (response) { + if (response.success) { + $(".btn").prop("disabled", false); + $(".close").prop("disabled", false); + $("#submitToBannerButton").text("Submit to Banner"); + // Handle success as needed + alert("Form submitted to Banner successfully!"); + } else { + // Handle submission failure + alert("Failed to submit form to Banner."); + } + } + } }); } + + var laborDenialInfo = []; //this arrary is for insertDenial() and finalDenial() methods //This method calls AJAX from checkforms methods in the controller function insertDenial(val) { diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index b9281481..98828d4d 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -221,26 +221,30 @@ {% endif %} {% if buttonState.evaluate %} - - - - + + + + {% endif %} {% if buttonState.evaluation_exists %} - - - - - + + + + {% endif %} - {% if buttonState.evaluation_exists %} - - {% endif %} + +
+ {% endif %} + + + + + + - From fe77afec9ac18243d6ec72c97830383c23f4459d Mon Sep 17 00:00:00 2001 From: Fleur Gahimbare Date: Wed, 6 Sep 2023 19:12:29 -0400 Subject: [PATCH 04/10] fixed errors when submitting to banner --- .../admin_routes/allPendingForms.py | 60 ++++++++----------- app/static/js/allPendingForms.js | 29 +++------ app/templates/snips/studentHistoryModal.html | 2 +- 3 files changed, 33 insertions(+), 58 deletions(-) diff --git a/app/controllers/admin_routes/allPendingForms.py b/app/controllers/admin_routes/allPendingForms.py index 5b911b24..4e46d0f9 100644 --- a/app/controllers/admin_routes/allPendingForms.py +++ b/app/controllers/admin_routes/allPendingForms.py @@ -242,52 +242,42 @@ def finalUpdateStatus(raw_status): print("Unknown status: ", raw_status) return jsonify({"success": False}) form_ids = eval(request.data.decode("utf-8")) - return saveStatus(new_status, form_ids, currentUser) -# Add a new route for submitting to Banner -@app.route('/admin/submitToBanner', methods=['POST']) -def submitToBanner(): - form_ids = eval(request.data.decode("utf-8")) - print(form_ids) - form_ids = form_ids[:1] - +@admin.route('/admin/addToBanner/', methods=['POST']) +def submitToBanner(form_id): + print(form_id) + print("Hell000000") + ''' This method adds a form to Banner if it's not already approved ''' currentUser = require_login() if not currentUser: # Not logged in - return render_template('errors/403.html'), 403 + return jsonify({"success": False, "message": "User not logged in"}), 403 if not currentUser.isLaborAdmin: # Not an admin - return render_template('errors/403.html'), 403 + return jsonify({"success": False, "message": "User is not an admin"}), 403 try: - if not form_ids: - return jsonify({"success": False, "error": "No form IDs provided"}), 400 # Return an error if form_ids is empty - - for form_id in form_ids: - labor_forms = FormHistory.get(FormHistory.formHistoryID == form_id) - history_type = str(labor_forms.historyType) - - # Check if it's an Adjustment Form or CS dummy position - if history_type == "Labor Status Form" and labor_forms.formID.POSN_CODE != "S12345": - if labor_forms.formID.POSN_CODE == "SNOLAB": - labor_forms.formID.weeklyHours = 10 - conn = Banner() - save_status = conn.insert(labor_forms) + form_history = FormHistory.get(FormHistory.formHistoryID == int(form_id)) + if form_history.status.statusName == "Approved": + print("-------------------------yes-------------------") + # Add to Banner only if the form is approved - if save_status: - labor_forms.save() - else: - print("Unable to submit to Banner for formHistoryID {}.".format(form_id)) - return jsonify({"success": False}), 500 - - return jsonify({"success": True}) # Return success JSON response + history_type_data = FormHistory.get(FormHistory.formHistoryID == int(form_id)) + history_type = str(history_type_data.historyType) + labor_form = FormHistory.get(FormHistory.formHistoryID == int(form_id), FormHistory.historyType == history_type) + + conn = Banner() + save_status = conn.insert(labor_form) + if save_status: + return jsonify({"success": True, "message": "Form added to Banner"}) + else: + return jsonify({"success": False, "message": "Unable to add form to Banner"}), 500 + else: + return jsonify({"success": False, "message": "Form has not been approved yet"}) except Exception as e: - print("Error preparing form for submission to Banner:", e) - return jsonify({"success": False}), 500 - - - + print("Error adding form to Banner:", e) + return jsonify({"success": False, "message": "Error adding form to Banner"}), 500 def saveStatus(new_status, form_ids, currentUser): try: diff --git a/app/static/js/allPendingForms.js b/app/static/js/allPendingForms.js index 4176c642..818a3b2a 100644 --- a/app/static/js/allPendingForms.js +++ b/app/static/js/allPendingForms.js @@ -145,37 +145,22 @@ function finalApproval() { //this method changes the status of the lsf from pend }); } -function submitToBanner() { - $(".btn").prop("disabled", true); - $(".close").prop("disabled", true); - $("#submitToBannerButton").text("Processing..."); - var data = JSON.stringify(labor_details_ids); + +function submitToBanner(formId) { $.ajax({ type: "POST", - url: "/admin/submitToBanner", // Remove the trailing slash - data: data, // Pass the JSON data in the request body - contentType: 'application/json', + url: "/admin/addToBanner/" + formId, success: function(response) { - if (response) { - if (response.success) { - $(".btn").prop("disabled", false); - $(".close").prop("disabled", false); - $("#submitToBannerButton").text("Submit to Banner"); - - // Handle success as needed - alert("Form submitted to Banner successfully!"); - } else { - // Handle submission failure - alert("Failed to submit form to Banner."); - } + if (response.success) { + alert(response.message); + } else { + alert("Error: " + response.message); } } }); } - - var laborDenialInfo = []; //this arrary is for insertDenial() and finalDenial() methods //This method calls AJAX from checkforms methods in the controller function insertDenial(val) { diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index 98828d4d..e02917dd 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -234,7 +234,7 @@ {% endif %} - +
{% endif %} From e52d9678793d50fd2246205bb2f1190749059d51 Mon Sep 17 00:00:00 2001 From: Fleur Gahimbare Date: Fri, 8 Sep 2023 14:23:42 -0400 Subject: [PATCH 05/10] close the modal after submittion --- .../admin_routes/allPendingForms.py | 31 +++++++++---------- app/static/js/allPendingForms.js | 11 +++++-- app/templates/snips/studentHistoryModal.html | 2 +- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/app/controllers/admin_routes/allPendingForms.py b/app/controllers/admin_routes/allPendingForms.py index 4e46d0f9..5adb44e0 100644 --- a/app/controllers/admin_routes/allPendingForms.py +++ b/app/controllers/admin_routes/allPendingForms.py @@ -247,37 +247,34 @@ def finalUpdateStatus(raw_status): @admin.route('/admin/addToBanner/', methods=['POST']) def submitToBanner(form_id): print(form_id) - print("Hell000000") - ''' This method adds a form to Banner if it's not already approved ''' + ''' This method adds a form to Banner if it's already approved ''' currentUser = require_login() - if not currentUser: # Not logged in - return jsonify({"success": False, "message": "User not logged in"}), 403 - if not currentUser.isLaborAdmin: # Not an admin - return jsonify({"success": False, "message": "User is not an admin"}), 403 + if not currentUser: # Not logged in + return render_template('errors/403.html'), 403 + if not currentUser.isLaborAdmin: # Not an admin + return render_template('errors/403.html'), 403 try: - form_history = FormHistory.get(FormHistory.formHistoryID == int(form_id)) + form_history = FormHistory.get(FormHistory.formID == int(form_id)) + + # Add to Banner only if the form is approved if form_history.status.statusName == "Approved": - print("-------------------------yes-------------------") - # Add to Banner only if the form is approved - - history_type_data = FormHistory.get(FormHistory.formHistoryID == int(form_id)) + history_type_data = FormHistory.get(FormHistory.formID == int(form_id)) history_type = str(history_type_data.historyType) - - labor_form = FormHistory.get(FormHistory.formHistoryID == int(form_id), FormHistory.historyType == history_type) + labor_form = FormHistory.get(FormHistory.formID == int(form_id), FormHistory.historyType == history_type) conn = Banner() save_status = conn.insert(labor_form) if save_status: - return jsonify({"success": True, "message": "Form added to Banner"}) + return jsonify({"success": True}) else: - return jsonify({"success": False, "message": "Unable to add form to Banner"}), 500 + return jsonify({"success": False}), 500 else: - return jsonify({"success": False, "message": "Form has not been approved yet"}) + return jsonify({"success": False}) except Exception as e: print("Error adding form to Banner:", e) - return jsonify({"success": False, "message": "Error adding form to Banner"}), 500 + return jsonify({"success": False}), 500 def saveStatus(new_status, form_ids, currentUser): try: diff --git a/app/static/js/allPendingForms.js b/app/static/js/allPendingForms.js index 818a3b2a..282997c8 100644 --- a/app/static/js/allPendingForms.js +++ b/app/static/js/allPendingForms.js @@ -145,6 +145,9 @@ function finalApproval() { //this method changes the status of the lsf from pend }); } +function studentHistoryModalClose(){ + modal.style.display = "none"; +} function submitToBanner(formId) { $.ajax({ @@ -152,15 +155,17 @@ function submitToBanner(formId) { url: "/admin/addToBanner/" + formId, success: function(response) { if (response.success) { - alert(response.message); + msgFlash("Form submitted to banner successfully ", "success"); + studentHistoryModalClose(); } else { - alert("Error: " + response.message); + msgFlash("Form failed to submit to banner", "fail"); + studentHistoryModalClose(); + } } }); } - var laborDenialInfo = []; //this arrary is for insertDenial() and finalDenial() methods //This method calls AJAX from checkforms methods in the controller function insertDenial(val) { diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index e02917dd..781a52b9 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -234,7 +234,7 @@ {% endif %} - +
{% endif %} From cb7c40486bd0e7dcd1ccd2c62d5a3e4a8aff4014 Mon Sep 17 00:00:00 2001 From: Fleur Gahimbare Date: Fri, 8 Sep 2023 16:51:01 -0400 Subject: [PATCH 06/10] remove print statement --- app/controllers/admin_routes/allPendingForms.py | 2 -- app/templates/snips/studentHistoryModal.html | 4 +--- 2 files changed, 1 insertion(+), 5 deletions(-) diff --git a/app/controllers/admin_routes/allPendingForms.py b/app/controllers/admin_routes/allPendingForms.py index 5adb44e0..86852d78 100644 --- a/app/controllers/admin_routes/allPendingForms.py +++ b/app/controllers/admin_routes/allPendingForms.py @@ -246,8 +246,6 @@ def finalUpdateStatus(raw_status): @admin.route('/admin/addToBanner/', methods=['POST']) def submitToBanner(form_id): - print(form_id) - ''' This method adds a form to Banner if it's already approved ''' currentUser = require_login() if not currentUser: # Not logged in diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index 781a52b9..35cfa337 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -234,9 +234,7 @@ {% endif %} - -
- + {% endif %} From 19b48b278f0fa2b73090c101939eac5bcadf97bf Mon Sep 17 00:00:00 2001 From: Fleur Gahimbare Date: Fri, 8 Sep 2023 16:58:40 -0400 Subject: [PATCH 07/10] fix spacing --- app/static/js/allPendingForms.js | 1 - app/templates/snips/studentHistoryModal.html | 61 ++++++++++---------- 2 files changed, 30 insertions(+), 32 deletions(-) diff --git a/app/static/js/allPendingForms.js b/app/static/js/allPendingForms.js index 282997c8..45aa4d28 100644 --- a/app/static/js/allPendingForms.js +++ b/app/static/js/allPendingForms.js @@ -160,7 +160,6 @@ function submitToBanner(formId) { } else { msgFlash("Form failed to submit to banner", "fail"); studentHistoryModalClose(); - } } }); diff --git a/app/templates/snips/studentHistoryModal.html b/app/templates/snips/studentHistoryModal.html index 35cfa337..f607581d 100755 --- a/app/templates/snips/studentHistoryModal.html +++ b/app/templates/snips/studentHistoryModal.html @@ -199,49 +199,48 @@ + + + + {% endif %} {% if buttonState.evaluation_exists %} - - - - + + + + {% endif %} {% endif %} From 22b38ba60082fea1b2895876e83f76b09432ffc9 Mon Sep 17 00:00:00 2001 From: bineta doucoure Date: Mon, 11 Sep 2023 17:23:39 -0600 Subject: [PATCH 10/10] history_type_data remove because declared twice --- app/controllers/admin_routes/allPendingForms.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/app/controllers/admin_routes/allPendingForms.py b/app/controllers/admin_routes/allPendingForms.py index 86852d78..251de895 100644 --- a/app/controllers/admin_routes/allPendingForms.py +++ b/app/controllers/admin_routes/allPendingForms.py @@ -258,8 +258,7 @@ def submitToBanner(form_id): # Add to Banner only if the form is approved if form_history.status.statusName == "Approved": - history_type_data = FormHistory.get(FormHistory.formID == int(form_id)) - history_type = str(history_type_data.historyType) + history_type = str(form_history.historyType) labor_form = FormHistory.get(FormHistory.formID == int(form_id), FormHistory.historyType == history_type) conn = Banner()