Skip to content

Commit

Permalink
Joe comments for draft submission
Browse files Browse the repository at this point in the history
  • Loading branch information
jmuzina committed Apr 15, 2022
1 parent c2fe4bc commit fb36272
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 17 deletions.
9 changes: 5 additions & 4 deletions app.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

# ---------------------------- #
ALLOWED_EXTENSIONS = {'png', 'jpeg', 'jpg', 'gpx'}
#IS_SERVER = exists("/etc/letsencrypt/live/capstone3.cs.kent.edu/fullchain.pem") and exists("/etc/letsencrypt/live/capstone3.cs.kent.edu/privkey.pem")

flaskApp = Flask(__name__)
flaskApp.config['TEMPLATES_AUTO_RELOAD'] = True
Expand Down Expand Up @@ -93,6 +92,7 @@

shareAuthURLs = {}

# Add API networks that should be logged in with (exercise trackers) to the homepage as log in buttons
for networkName in apis:
if not apis[networkName].loginWith:
shareAuthURLs[networkName] = apis[networkName].authUrl
Expand All @@ -107,6 +107,7 @@ def render_index():
return redirect(url_for("render_parameters"))
elif sessionDataValidationResult == False or ("networkName" in session and session["networkName"] == "gpxFile"): # No user ID, not logged in.
networks = {}
# Check for available third party networks; mark unavailable ones
for networkName in apis:
if apis[networkName].loginWith:
networkDetails = False
Expand Down Expand Up @@ -258,8 +259,10 @@ def render_generatePage():
totalLength = request.form["selectedActivityLength"]
totalDistance = request.form["selectedActivityDistance"]

# Activities pulled from API, include total time and distance
if session["networkName"] != "gpxFile":
userCachedData[uniqueId]["visualizationResult"] = functions.getImageBase64String(generateVis.getVis(data=data, lineThickness=int(formArgs["pathThickness"]), gridOn=formArgs["displayGridLines"] == "on", backgroundColor=formArgs["backgroundColor"], backgroundImage = filename, backgroundBlur = formArgs["blurIntensity"], foregroundColor=formArgs["pathColor"], gridColor=formArgs["gridlineColor"], gridThickness=int(formArgs["gridThickness"]), infoText=formArgs["infoText"],silhouetteImage=formArgs["silhouetteImage"], duplicateActivities=formArgs["duplicateActivities"], textBackgroundFade=formArgs["textBackgroundFade"], totalTime=functions.getTimeStr(totalLength), totalDistance=str(totalDistance) + " mi."))
# Activities pulled from GPX file, exclude total time and distance as they are not calculated this way
else:
userCachedData[uniqueId]["visualizationResult"] = functions.getImageBase64String(generateVis.getVis(data=data, lineThickness=int(formArgs["pathThickness"]), gridOn=formArgs["displayGridLines"] == "on", backgroundColor=formArgs["backgroundColor"], backgroundImage = filename, backgroundBlur = formArgs["blurIntensity"], foregroundColor=formArgs["pathColor"], gridColor=formArgs["gridlineColor"], gridThickness=int(formArgs["gridThickness"]), infoText=formArgs["infoText"], silhouetteImage=formArgs["silhouetteImage"], duplicateActivities=formArgs["duplicateActivities"], textBackgroundFade=formArgs["textBackgroundFade"]))

Expand Down Expand Up @@ -331,6 +334,4 @@ def render_privacyPage():

# Store any config items not related to API logins under app.config
for key in config["DEFAULT"]:
flaskApp.config[key] = config["DEFAULT"][key]

#print(networks.twitter.twitterApi(config, flaskApp).getAccessKey())
flaskApp.config[key] = config["DEFAULT"][key]
3 changes: 3 additions & 0 deletions functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

# ---------------------------- #

# Keys that may be stored in the session dict
sessionVars = ["accessKey", "networkName", "userData", "twitterAccessToken", "twitterUserID", "visualizationID"]

def allowed_file(filename, extensions):
Expand Down Expand Up @@ -52,6 +53,7 @@ def uniqueUserId(networkName, idNum):
def metersToMiles(meters):
return meters / 1609.344

# Return time since 1/1/1970
def epoch():
return int(time.time())

Expand Down Expand Up @@ -109,6 +111,7 @@ def validUserData(session):

return False

# Wipe all data from user session
def wipeSession(session):
sessionDataValidationResult = validUserData(session)

Expand Down
17 changes: 15 additions & 2 deletions static/dynamicParameters.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ var overlayBackground;
var clearBackgroundButton;
var backgroundColor;

// Wait for all HTML elements to load, and assign them to variables
waitForElement("displayGridLines", function() { gridCheckBox = document.getElementById("displayGridLines"); });
waitForElement("gridlineColor", function() { gridlineColorSelector = document.getElementById("gridlineColor").parentNode; });
waitForElement("gridThickness", function() { gridThickness = document.getElementById("gridThickness"); gridlineThicknessSelector = gridThickness.parentNode; });
Expand All @@ -31,23 +32,29 @@ waitForElement("textBackgroundFade", function() { overlayBackground = document.g
waitForElement("clearBackgroundButton", function() { clearBackgroundButton = document.getElementById("clearBackgroundButton"); });
waitForElement("backgroundColor", function() { backgroundColor = document.getElementById("backgroundColor").parentNode; });

// Show grid checkbox has been toggled
// Checked: show gridline thickness and color
// Unchecked: hide gridline thickness and color
function gridChecked() {
gridlineColorSelector.parentNode.hidden = !gridCheckBox.checked;
gridlineThicknessSelector.parentNode.hidden =
gridlineColorSelector.parentNode.hidden;
}

// Given a range input value, return its value as a % between min and max
function getSliderPercent(rangeElement) {
return Math.ceil(((rangeElement.value / rangeElement.max) * 100)) + " %"
}

// Show overlay checkbox has been toggled
// Checked: Show overlay backdrop checkbox
// Unchecked: hide overlay backdrop checkbox
function overlayChecked() {
overlayBackground.parentNode.hidden = !overlayCheckBox.checked;
}

function gridThicknessChanged() {
gridThicknessPreview.innerHTML = getSliderPercent(gridThickness);

}

function pathThicknessChanged() {
Expand All @@ -57,6 +64,10 @@ function pathThicknessChanged() {
function blurIntensityChanged() {
blurIntensityPreview.innerHTML = getSliderPercent(blurIntensity);
}

// Silhoutte image value has changed
// Has a value: show the duplicate activities checkbox
// No value: hide the duplicate activities checkbox
function silhouetteImageSelected() {
silhouetteImage = document.getElementById("silhouetteImage")
if (silhouetteImage.value!=""){
Expand All @@ -68,15 +79,17 @@ function silhouetteImageSelected() {

}

// Clear the background image from the background image upload input
function clearBackground() {
backgroundImage.value = null;
clearBackgroundButton.hidden = true;
blurIntensityLabel.parentNode.hidden = true;
backgroundColor.hidden = false;
}

// Perform page-load setup
setTimeout(function () {
// Bootstrap
// Set initial visibility of dependent form inpjuts
overlayChecked();
gridThicknessChanged();
blurIntensityChanged();
Expand Down
29 changes: 21 additions & 8 deletions static/fileVerification.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
const imageFormats = {
"png": true,
"jpg": true,
"jpeg": true,
};

// Details for specific file restriction types
const fileRestrictions = {
"backgroundImage": {
"extensions": {
Expand All @@ -23,33 +18,41 @@ const fileRestrictions = {
}
}

// Given a file type, check fileRestrictions table to see if it is a valid file to upload
function fileUploadIsValid(fileType) {
// Check that the file type has a valid restriction entry
if (fileRestrictions[fileType] && fileRestrictions[fileType]["extensions"] && fileRestrictions[fileType]["maxSize"]) {
const uploadBtn = document.getElementById(fileType);
// Make sure the upload button for this input exists
if (uploadBtn !== null) {
const uploadedFiles = uploadBtn.files;
var totalSize = 0;
// Loop through all uploaded files
for (var i = 0; i < uploadedFiles.length; ++i) {
const file = uploadedFiles[i];
const fileName = file.name.toLowerCase();
const fileExtension = fileName.split(".").pop();

// Make sure that the file has a valid file extension
if (fileRestrictions[fileType]["extensions"][fileExtension] == true) {
const fileSize = file.size / 1000000; // MB
totalSize += fileSize;
// Make sure sum of file uploads is within size limit
if (totalSize >= fileRestrictions[fileType]["totalLimit"]) {
return {
"success": false,
"message": "Sum size of all uploaded files must be less than " + fileRestrictions[fileType]["totalLimit"].toString() + " MB."
}
}
// Make sure individual file is within size limit
else if (fileSize >= fileRestrictions[fileType]["maxSize"]) {
return {
"success": false,
"message": "Uploaded file must be smaller than " + fileRestrictions[fileType]["maxSize"].toString() + " MB."
};
}
}
// File has invalid extension
else {
return {
"success": false,
Expand All @@ -58,47 +61,53 @@ function fileUploadIsValid(fileType) {
}
}
}
// No upload button
else {
return {
"success": false,
"message": "Could not find upload button."
};
}
}
// No entry for this file type in fileRestrictions table
else {
return {
"success": false,
"message": "No matching file restriction configuration for type " + fileType + ".\n\nAllowed types are " + Object.keys(fileRestrictions).toString() + "."
};
}

// Valid upload
return {
"success": true
};
}


function verifyBackgroundImage() {
const fileVerificationResult = fileUploadIsValid("backgroundImage");
const uploadBtn = document.getElementById("backgroundImage");
const blurIntensitySlider = document.getElementById("blurIntensityLabel");
//const clearBackgroundButton = document.getElementById("clearBackgroundButton");

// Background image has been uploaded successfully, show the blur intensity slider
if (fileVerificationResult["success"]) {
if (blurIntensitySlider !== null) {
blurIntensitySlider.parentNode.hidden = false;
}
}
else {
// Notify the player why the file was rejected
alert(fileVerificationResult["message"]);

if (uploadBtn !== null) {
// Clear the image from the file input
uploadBtn.value = null;
// Hide the blur intensity slider, as the background image is invalid
if (blurIntensitySlider !== null) {
blurIntensitySlider.parentNode.hidden = true;
}
}
}
// Show/hide clear background button and flat background color inputs. They should never both be visible.
document.getElementById("clearBackgroundButton").hidden = blurIntensitySlider.hidden;
document.getElementById("backgroundColor").parentNode.hidden = !document.getElementById("clearBackgroundButton").hidden;
}
Expand All @@ -109,17 +118,20 @@ function verifyGPXFile() {
const gpxFiles = document.getElementById("gpxFile");
const gpxFileSubmit = document.getElementById("GPXSubmit");

// Invalid GPX file, notify user the reason and clear input
if (!(fileVerificationResult["success"])) {
alert(fileVerificationResult["message"]);

if (uploadBtn !== null) {
uploadBtn.value = null;
gpxFileSubmit.hidden = true;
gpxFileSubmit.disabled = true;
// Mark upload GPX button as disabled
$(gpxFileSubmit).addClass("disabled-button");
}
}
else {
// Valid GPX file uploaded, enable upload GPX button
if (gpxFiles !== null) {
if (gpxFileSubmit !== null) {
gpxFileSubmit.hidden = gpxFiles.value.length == 0;
Expand All @@ -143,6 +155,7 @@ window.onload = function(){
document.getElementById("blurIntensityLabel").parentNode.hidden = backgroundImage.value.length == 0;
document.getElementById("clearBackgroundButton").hidden = backgroundImage.value.length == 0;
}
// Set initial disabled state of the GPX upload button
if (gpxFiles !== null) {
const gpxFileSubmit = document.getElementById("GPXSubmit");
if (gpxFileSubmit !== null) {
Expand Down
9 changes: 6 additions & 3 deletions static/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,17 @@ var prevWidth = 0;
var portrait;
var gpxUploadSection;

// Window size has been changed
function refreshSize() {
// Window size changing to portrait, hide GPX upload section
if (window.innerWidth < window.innerHeight && !portrait) {
portrait = true;

if (gpxUploadSection != null) {
gpxUploadSection.hidden = true;
}
}
// Window size changing to desktop, show GPX upload section
else if (window.innerWidth >= window.innerHeight && portrait) {
portrait = false;

Expand All @@ -19,13 +22,13 @@ function refreshSize() {
}
}

window.addEventListener("resize", refreshSize);
window.addEventListener("resize", refreshSize); // listen for resize events

// Set initial hidden state of GPX upload section
waitForElement("gpxUpload", function() {
gpxUploadSection = document.getElementById("gpxUpload");
if (gpxUploadSection != null) {
portrait = (window.innerWidth < window.innerHeight);
gpxUploadSection.hidden = portrait;
}
//gpxUploadSection.hidden = true;
//alert("how are you doingz");
});
1 change: 1 addition & 0 deletions static/wait.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
// Wait for the existence of an HTML element, then call the supplied function
function waitForElement(elementID, callback) {
if (document.getElementById(elementID)) callback();
else {
Expand Down

0 comments on commit fb36272

Please sign in to comment.