Skip to content
This repository has been archived by the owner on Jun 15, 2024. It is now read-only.

Commit

Permalink
Bug Fixes (#40)
Browse files Browse the repository at this point in the history
* updating documentation link that was changed because there is no longer a config.yaml

* wrapping all of excel_uploader_main.py in a try catch from gui_main.py

* wrapping all of excel_uploader_main.py in a try catch from gui_main.py

* clarified comment in the section of try catch of len(error_list)

* added except Exception as error

* added small clarification as to why user is going to globus screen

* added comment as to why setuptools is imported but not used for better code readability

* changed version from 0.6.0 to 0.6.1

* added an upload again button to the success screen as well as error screen

* underlined globus auth button link to indicate to the user that the globus auth button is a link

* Exceptions no longer exist because of SDK refactoring, so they have been changed to generic for now and it is working

* turning cursor into "not-allowed" icon for Excel file path input

* fixed start_screen having broken feedback

all_screens.js: put restartStartScreen.js into a function that can be used by restartAllScreens function and start_screen.js submitForm() function

start_screen.js: clearing the start_screen form validations before sending user input to not get any leftover/wrong feedback after submission
  • Loading branch information
nh916 authored Nov 3, 2022
1 parent e843c34 commit 7740f66
Show file tree
Hide file tree
Showing 5 changed files with 161 additions and 106 deletions.
56 changes: 41 additions & 15 deletions src/gui_main.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down Expand Up @@ -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"
Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
83 changes: 82 additions & 1 deletion src/web/js/all_screens.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,85 @@ eel.expose(pythonExitCleanUp);

function pythonExitCleanUp() {
window.close()
}
}


/*
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");
}
67 changes: 0 additions & 67 deletions src/web/js/error_screen.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";

}
19 changes: 13 additions & 6 deletions src/web/js/start_screen.js
Original file line number Diff line number Diff line change
@@ -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");
Expand All @@ -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 = {
Expand Down
42 changes: 25 additions & 17 deletions src/web/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<!-- my styles -->
<link href="../css/styles.css" rel="stylesheet">

<title>CRIPT Excel Uploader - version 0.6.0</title>
<title>CRIPT Excel Uploader - version 0.6.1</title>
</head>
<body>
<header>
Expand Down Expand Up @@ -155,7 +155,8 @@ <h1 class="text-center">
Excel File:
</button>

<input type="text" id="excel-file-path" class="form-control"
<input type="text" id="excel-file-path"
class="form-control" style="cursor: not-allowed;"
placeholder="Excel absolute file path"
aria-label="place host here"
aria-describedby="excel-file-button excel-file-path-validation-feedback"
Expand All @@ -181,19 +182,19 @@ <h1 class="text-center">
Upload
</button>
</div>
</form>

<br>
<br>

<!-- docs link for how to fill out config -->
<small class="documentation-link">
Please refer to our
<!-- docs link for how to fill out config -->
<small class="documentation-link">
Please refer to our

<a href="https://c-accel-cript.github.io/cript-excel-uploader/filling_out_config/" target="_blank">
documentation
</a>
on how to fill out this screen
</small>
</form>
<a href="https://c-accel-cript.github.io/cript-excel-uploader/filling_out_first_screen/" target="_blank">
documentation
</a>
on how to fill out this screen
</small>
</div>

<!-- LOADING SCREEN -->
Expand Down Expand Up @@ -258,7 +259,7 @@ <h1 class="text-center">

<!-- screen header that explains the screen -->
<h2 style="font-size: 1.5rem;" class="text-center">
Globus Authentication for File Uploads
Globus Authentication for <u>Local</u> File Uploads
</h2>

<!-- image -->
Expand All @@ -277,7 +278,8 @@ <h3 class="text-center" style="font-size: 1rem">

<!-- Globus Auth Link -->
<div class="text-center" style="margin-top: 1rem;">
<a id="globus-auth-link" class="btn btn-primary " href="" target="_blank">
<a id="globus-auth-link" class="btn btn-primary" style="text-decoration: underline"
href="" target="_blank">
<i class="material-icons">vpn_lock</i>
Globus Authentication
</a>
Expand Down Expand Up @@ -344,7 +346,7 @@ <h2 id="error-header" class="text-danger" style="margin-left: 1rem;">

<!-- Try again button -->
<div class="d-grid gap-2" style="margin-top: 2rem;">
<button type="button" onclick="tryAgain();"
<button type="button" onclick="uploadAgain();"
class="btn btn-primary btn-lg margin-top d-flex justify-content-center"
style="padding: 0.7rem 7rem 0.7rem 7rem;">
Try again
Expand Down Expand Up @@ -378,12 +380,18 @@ <h2 class="text-center text-success" style="font-size: 5rem">
<img src="../assets/images/done.png" class="img-fluid" style="height: 30rem;"
alt="cartoon picture of task completed">

<!-- success and upload again button -->
<div class="d-grid gap-2">
<!-- onclick close the window -->
<a id="data-in-cript-link" class="btn" href="https://criptapp.org" target="_blank">
<!-- show uploaded collection -->
<a id="data-in-cript-link" class="btn btn-link" href="https://criptapp.org" target="_blank">
<i class="material-icons">cloud_done</i>
See my data in CRIPT
</a>
<!-- upload again -->
<button class="btn btn-primary" type="button" onclick="uploadAgain()">
<i class="material-icons">restart_alt</i>
Upload again
</button>
</div>
</div>

Expand Down

0 comments on commit 7740f66

Please sign in to comment.