diff --git a/src/gui_main.py b/src/gui_main.py index ab87a94..b1d9e0e 100644 --- a/src/gui_main.py +++ b/src/gui_main.py @@ -1,12 +1,15 @@ +# setuptools must be imported even if not used +# for PyInstaller to compile it into an executable for Linux +import setuptools import atexit import os import sys import tkinter +import traceback from tkinter import filedialog import cript import eel -import requests from python.excel_uploader_main import ExcelUploader @@ -97,7 +100,7 @@ def validate_and_set_user_input(self, user_input): user_input["host"], user_input["apiToken"] ) - except (cript.exceptions.APIAuthError, requests.exceptions.RequestException): + except Exception as error: # send JSON to JS function with fields that have errors and give feedback error_dict["host"] = "invalid host or token" error_dict["apiToken"] = "invalid host or token" @@ -108,13 +111,13 @@ def validate_and_set_user_input(self, user_input): try: self.excel_uploader.set_project(user_input["projectName"]) - except cript.exceptions.APIGetError: + except Exception as error: error_dict["project"] = "Please enter a valid Project name" try: self.excel_uploader.set_collection(user_input["collectionName"]) - except cript.exceptions.APIGetError: + except Exception as error: error_dict["collection"] = "Please enter a valid Collection name" try: @@ -145,20 +148,43 @@ def send_to_upload(self): """ eel.goToLoadingScreen() - # public data is not allowed from Excel Uploader - data_is_public = False + try: + # at the end it returns an error list that I can check for errors + error_list = self.excel_uploader.upload_driver(self.excel_file_path, self) + + except KeyError as error: + error_str = f"Error: {error}" - # at the end it returns an error list that I can check for errors - error_list = self.excel_uploader.upload_driver(self.excel_file_path, self) + # this is used in case of debugging + traceback_error = traceback.format_exc() - # TODO this throws TypeError: object of type 'NoneType' has no len() when taking to globus - # screen and not returning any errors - if len(error_list) > 0: - print("hit error list") - self.display_errors(error_list) + self.display_errors([error_str, traceback_error]) return - else: - self.display_success(self.excel_uploader.get_collections_url()) + + except Exception as error: + error_str = f"Error: {error}" + + # this is used in case of debugging + traceback_error = traceback.format_exc() + + self.display_errors([error_str, traceback_error]) + return + + # when checking the len(error_list) throws "TypeError: object of type 'NoneType' has no len()" + # this happens because the user has been taken to globus auth screen + # and there is no error_list object yet + # the program doesn't need any action here and the exception catching here is + # to not display any errors to the terminal, but not necessarily needed + try: + if len(error_list) > 0: + print("hit error list") + self.display_errors(error_list) + return + else: + self.display_success(self.excel_uploader.get_collections_url()) + return + + except (TypeError, UnboundLocalError) as error: return def globus_auth(self, globus_auth_link): diff --git a/src/web/js/all_screens.js b/src/web/js/all_screens.js index 14db86d..014b8eb 100644 --- a/src/web/js/all_screens.js +++ b/src/web/js/all_screens.js @@ -17,4 +17,85 @@ eel.expose(pythonExitCleanUp); function pythonExitCleanUp() { window.close() -} \ No newline at end of file +} + + +/* + this function runs when user clicks on + "Try Again" from error screen or "Upload again" from success screen + to try re-uploading their data + restarts the start_screen, loading_screen, globus_screen, and error_screen + calls the eel function to clear out the error_list so there are no old errors + from previous upload attempt, and sets the current_progress to 0 so the progress bar + can start from 0 and not from 100 + then takes the user to the start_screen +*/ +function uploadAgain() { + restartAllScreens(); + eel.reset_for_uploading() + goToStartScreen(); +} + +/* + restarts the start_screen, loading_screen, globus_screen, and error_screen +*/ +function restartAllScreens() { + +// restart start screen + restartStartScreen(); + +// restart loading screen + updateLoadingBar(0); + // removing updating label from what the last thing it was + document.getElementById("uploading-specifics").textContent = "..."; + +// restart globus screen + // clears out the form of the token that they have already inputted and ready to accept input + // the link for globus will get auto generated anyways + document.getElementById("globus-auth-token-input").value = ""; + +// restart error screen + // remove any errors that are already appended to the error window +document.getElementById("error-window").textContent = ""; + +} + +/* +function used when start screen needs to be restarted to used again +it enables upload button, changes the text to upload, and +removes any feedback of valid or invalid from the screen. +However, it leaves all the original values that were inputted into the fields +*/ +function restartStartScreen() { + // restart start screen + // enable the start screen button + let uploadButton = document.getElementById("upload-button"); + uploadButton.textContent = "Upload"; + uploadButton.disabled = false; + + // remove all previous errors that there might have been there + document.getElementById("authentication-error-alert").classList.add("hidden"); + + // get all input elements for start_screen + let inputElements = getInputElements(); + + // remove feedback from host + inputElements.host.classList.remove("is-valid"); + inputElements.host.classList.remove("is-invalid"); + + // remove feedback from apiToken + inputElements.apiToken.classList.remove("is-valid"); + inputElements.apiToken.classList.remove("is-invalid"); + + // remove feedback from projectName + inputElements.projectName.classList.remove("is-valid"); + inputElements.projectName.classList.remove("is-invalid"); + + // remove feedback from collectionName + inputElements.collectionName.classList.remove("is-valid"); + inputElements.collectionName.classList.remove("is-invalid"); + + // remove feedback from excelFile + inputElements.excelFile.classList.remove("is-valid"); + inputElements.excelFile.classList.remove("is-invalid"); +} diff --git a/src/web/js/error_screen.js b/src/web/js/error_screen.js index 52ad256..f4bf4bc 100644 --- a/src/web/js/error_screen.js +++ b/src/web/js/error_screen.js @@ -32,70 +32,3 @@ function addErrorsToScreen(errorList) { } } - -/* - this function runs when user clicks on "Try Again" to try re-uploading - restarts the start_screen, loading_screen, globus_screen, and error_screen - calls the eel function to clear out the error_list so there are no old errors - from previous upload attempt, and sets the current_progress to 0 so the progress bar - can start from 0 and not from 100 - then takes the user to the start_screen -*/ -function tryAgain() { - restartAllScreens(); - eel.reset_for_uploading() - goToStartScreen(); -} - -/* - restarts the start_screen, loading_screen, globus_screen, and error_screen -*/ -function restartAllScreens() { -// restart start screen - // enable the start screen button - let uploadButton = document.getElementById("upload-button"); - uploadButton.textContent = "Upload"; - uploadButton.disabled = false; - - // remove all previous errors that there might have been there - document.getElementById("authentication-error-alert").classList.add("hidden"); - - // get all input elements for start_screen - let inputElements = getInputElements(); - - // remove feedback from host - inputElements.host.classList.remove("is-valid"); - inputElements.host.classList.remove("is-invalid"); - - // remove feedback from apiToken - inputElements.apiToken.classList.remove("is-valid"); - inputElements.apiToken.classList.remove("is-invalid"); - - // remove feedback from projectName - inputElements.projectName.classList.remove("is-valid"); - inputElements.projectName.classList.remove("is-invalid"); - - // remove feedback from collectionName - inputElements.collectionName.classList.remove("is-valid"); - inputElements.collectionName.classList.remove("is-invalid"); - - // remove feedback from excelFile - inputElements.excelFile.classList.remove("is-valid"); - inputElements.excelFile.classList.remove("is-invalid"); - - -// restart loading screen - updateLoadingBar(0); - // removing updating label from what the last thing it was - document.getElementById("uploading-specifics").textContent = "..."; - -// restart globus screen - // clears out the form of the token that they have already inputted and ready to accept input - // the link for globus will get auto generated anyways - document.getElementById("globus-auth-token-input").value = ""; - -// restart error screen - // remove any errors that are already appended to the error window -document.getElementById("error-window").textContent = ""; - -} diff --git a/src/web/js/start_screen.js b/src/web/js/start_screen.js index 5d8aa4a..b274518 100644 --- a/src/web/js/start_screen.js +++ b/src/web/js/start_screen.js @@ -1,4 +1,4 @@ -// get input elements, pack them inside JSON, and return JSON package +// get input elements from start screen, pack them inside JSON, and return JSON package function getInputElements() { // get all input elements const host = document.getElementById("host-input"); @@ -18,12 +18,19 @@ function getInputElements() { } function submitForm(event) { + + //restart start screen to remove all validations from previous attempt + restartStartScreen(); + + // get all input elements for start_screen + let inputElements = getInputElements(); + // get all input values - const host = document.getElementById("host-input").value; - const apiToken = document.getElementById("api-token-input").value; - const projectName = document.getElementById("project-name").value; - const collectionName = document.getElementById("collection-name").value; - const excelFilePath = document.getElementById("excel-file-path").value; + const host = inputElements.host.value; + const apiToken = inputElements.apiToken.value; + const projectName = inputElements.projectName.value; + const collectionName = inputElements.collectionName.value; + const excelFilePath = inputElements.excelFile.value; // JSON pack of user input from UI const userInput = { diff --git a/src/web/templates/base.html b/src/web/templates/base.html index 1dc9724..0bbc31e 100644 --- a/src/web/templates/base.html +++ b/src/web/templates/base.html @@ -43,7 +43,7 @@ - CRIPT Excel Uploader - version 0.6.0 + CRIPT Excel Uploader - version 0.6.1
@@ -155,7 +155,8 @@

Excel File: - Upload + -
+
- - - Please refer to our + + + Please refer to our - - documentation - - on how to fill out this screen - - + + documentation + + on how to fill out this screen + @@ -258,7 +259,7 @@

- Globus Authentication for File Uploads + Globus Authentication for Local File Uploads

@@ -277,7 +278,8 @@

- + vpn_lock Globus Authentication @@ -344,7 +346,7 @@

-