Skip to content

Commit

Permalink
Normalize style
Browse files Browse the repository at this point in the history
Keep lines to <=80 characters, simplify some code, fix indentation
  • Loading branch information
psvenk committed Mar 24, 2021
1 parent 0258d6c commit dfec428
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 47 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ trim_trailing_whitespace = true
indent_style = space
indent_size = 2

[{serve.js,scrape.js,public/js/home.js,public/js/clock.js}]
[{serve.js,scrape.js,public/js/{home,clock,snackbar}.js}]
indent_style = space
indent_size = 4

Expand Down
36 changes: 19 additions & 17 deletions public/js/buttonFunctions.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,29 @@
let newAssignment = function() {

currentTableData.currentTermData.classes[selected_class_i].edited = true;

if (!isNaN(selected_class_i)) {

currentTableData.currentTermData.classes[selected_class_i].assignments.unshift({
"assignment_id": newAssignmentIDCounter.toString(),
"name": "Assignment",
"category": Object.keys(currentTableData.currentTermData.classes[selected_class_i].categories)[currentFilterRow >= 0 ? currentFilterRow : 0],
"score": 10,
"max_score": 10,
"percentage": 100,
"color": "green",
"synthetic": "true",
});
currentTableData.currentTermData.classes[selected_class_i].assignments
.unshift({
"assignment_id": newAssignmentIDCounter.toString(),
"name": "Assignment",
"category": Object.keys(
currentTableData.currentTermData.classes[selected_class_i].categories
)[currentFilterRow >= 0 ? currentFilterRow : 0],
"score": 10,
"max_score": 10,
"percentage": 100,
"color": "green",
"synthetic": "true",
});
newAssignmentIDCounter++;

updateGradePage();

}
}

function replaceAssignmentFromID(oldData, newData, classID) {
const assignments = currentTableData.currentTermData.classes[classID].assignments;
const assignments = currentTableData.currentTermData.classes[classID]
.assignments;

const index = assignments.findIndex(({ assignment_id }) =>
assignment_id === oldData.assignment_id
Expand All @@ -32,7 +33,8 @@ function replaceAssignmentFromID(oldData, newData, classID) {
}

function removeAssignmentFromID(id, classID) {
const assignments = currentTableData.currentTermData.classes[classID].assignments;
const assignments = currentTableData.currentTermData.classes[classID]
.assignments;
const newArray = assignments.filter(({ assignment_id }) =>
assignment_id !== id
);
Expand Down Expand Up @@ -149,8 +151,8 @@ let updateGradePage = function() {
categoriesTable.setData(currentTableData.currentTermData.classes[selected_class_i].categoryDisplay);

assignmentsTable.replaceData(currentTableData.currentTermData
.classes[selected_class_i].assignments
.filter(({ placeholder }) => !placeholder)
.classes[selected_class_i].assignments
.filter(({ placeholder }) => !placeholder)
);

currentTableData.currentTermData.calcGPA = computeGPA(currentTableData.currentTermData.classes);
Expand Down
82 changes: 53 additions & 29 deletions public/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,17 +43,21 @@ var newAssignmentIDCounter = 0;
// contains all the undo snackbars
const undoData = []

document.onkeydown = e => {
window.addEventListener("keydown", e => {
var evtobj = window.event || e
if (evtobj.keyCode == 90 && evtobj.ctrlKey && undoData.length !== 0) {
if (undoData[0].Snackbar !== undefined) {
undoData[0].Snackbar.destroy();
undoData[0].Snackbar = undefined;
}
replaceAssignmentFromID({assignment_id: undoData[0].assignment_id, placeholder: true}, undoData[0], undoData[0].selected_class_i);
replaceAssignmentFromID(
{ assignment_id: undoData[0].assignment_id, placeholder: true },
undoData[0],
undoData[0].selected_class_i
);
undoData.shift();
}
}
});


let tempCell;
Expand Down Expand Up @@ -386,9 +390,9 @@ let assignmentsTable = new Tabulator("#assignmentsTable", {
isNaN(cell.getRow().getData().score)
|| currentTableData.currentTermData
.classes[selected_class_i]
.assignments.filter(value => {
return !(value["placeholder"] || false)
})[cell.getRow().getPosition()].synthetic
.assignments.filter(value =>
!value["placeholder"]
)[cell.getRow().getPosition()].synthetic
) ? "" : '<i class="fa fa-info standard-icon tooltip" aria-hidden="true" tooltip="Statistics"></i>',
width: 40,
align: "center",
Expand Down Expand Up @@ -603,33 +607,53 @@ let assignmentsTable = new Tabulator("#assignmentsTable", {
width: 40,
align: "center",
cellClick: function(e, cell) {

const data = cell.getRow().getData();
replaceAssignmentFromID(data, {assignment_id: data["assignment_id"], placeholder: true}, selected_class_i);

const undoSnackbar = new Snackbar(
`You deleted ${data["name"]}`, {
color: "var(--red1)",
textColor: "var(--white)",
buttonText: "Undo",

// Replace the assignment with a placeholder that just
// contains the assignment ID
buttonClick: () => {
// Get index for splicing and comparing
index = undoData.findIndex(a =>
a.assignment_id === data.assignment_id);
arrData = undoData[index];
// Remove snackbar before putting data back
arrData.Snackbar = undefined;
replaceAssignmentFromID({
assignment_id: arrData.assignment_id,
placeholder: true,
}, arrData, arrData.selected_class_i);
undoData.splice(index, 1);
},
timeout: 7500,

// On either a timeout or a bodyclick removes the
// snackbar link
timeoutFunction: () => {
undoData[
undoData.map(arrData => arrData.assignment_id)
.indexOf(data.assignment_id)
].Snackbar = undefined;
},

bodyClick: () => {
undoData[
undoData.map(arrData => arrData.assignment_id)
.indexOf(data.assignment_id)
].Snackbar = undefined;
},
}
).show();

const undoSnackbar = new Snackbar(`You deleted ${data["name"]}`, {
color: "var(--red1)",
textColor: "var(--white)",
buttonText: "Undo",
//buttonclick replaces the assignment with a placeholder that just contains the assignemnt ID
buttonClick: () => {
//gets index for splicing and comparing
index = undoData.map(arrData => arrData.assignment_id).indexOf(data.assignment_id);
arrData = undoData[index]; //undo data at the index
arrData.Snackbar = undefined; //removes snackbar before putting data back
replaceAssignmentFromID({assignment_id: arrData.assignment_id, placeholder: true}, arrData, arrData.selected_class_i);
undoData.splice(index, 1);
},
timeout: 7500,
//on either a timeout or a bodyclick removes the snackbar link
timeoutFunction: () => undoData[undoData.map(arrData => arrData.assignment_id).indexOf(data.assignment_id)].Snackbar = undefined,
bodyClick: () => undoData[undoData.map(arrData => arrData.assignment_id).indexOf(data.assignment_id)].Snackbar = undefined,
}).show();

data.Snackbar = undoSnackbar;
data.selected_class_i = selected_class_i;
undoData.unshift(data);
data.Snackbar = undoSnackbar;
data.selected_class_i = selected_class_i;
undoData.unshift(data);
},
headerSort: false,
cssClass: "icon-col allow-overflow"
Expand Down

0 comments on commit dfec428

Please sign in to comment.