Skip to content

Commit

Permalink
"Add assignment" button makes it add to current category (#162)
Browse files Browse the repository at this point in the history
adds to buttonFuntions.js and home.js, changing the newAssignment function so it adds to the current category filter (and if none is selected just the first category filter), and tracks what the filter is currently. I did this based off a variable and not the filter because it's easier.
  • Loading branch information
andOrlando authored Nov 7, 2020
1 parent 6c14ecc commit ca56796
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
2 changes: 1 addition & 1 deletion public/js/buttonFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ let newAssignment = function() {

currentTableData.currentTermData.classes[selected_class_i].assignments.unshift({
"name": "Assignment",
"category": Object.keys(currentTableData.currentTermData.classes[selected_class_i].categories)[0],
"category": Object.keys(currentTableData.currentTermData.classes[selected_class_i].categories)[currentFilterRow >= 0 ? currentFilterRow : 0],
"score": 10,
"max_score": 10,
"percentage": 100,
Expand Down
20 changes: 17 additions & 3 deletions public/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,10 @@ let recentActivity = new Tabulator("#recentActivity", {
classesTable.selectRow(1);
},
});

// Index of the row that's currently selected in the categories table
// (gets reset to -1 whenever the class is changed)
let currentFilterRow = -1;
let categoriesTable = new Tabulator("#categoriesTable", {
// height: 400,
selectable: 1,
Expand All @@ -173,9 +177,16 @@ let categoriesTable = new Tabulator("#categoriesTable", {
],
rowClick: function(e, row) { //trigger an alert message when the row is clicked
assignmentsTable.clearFilter();
assignmentsTable.addFilter([
{field: "category", type:"=", value: row.getData().category}
]);

if (currentFilterRow !== row.getPosition()) {
currentFilterRow = row.getPosition();
assignmentsTable.addFilter([
{field: "category", type:"=", value: row.getData().category}
]);
}
else {
currentFilterRow = -1;
}
},
});

Expand Down Expand Up @@ -633,7 +644,10 @@ let classesTable = new Tabulator("#classesTable", {
],
rowClick: function(e, row) { // trigger an alert message when the row is clicked
$("#mostRecentDiv").hide();

assignmentsTable.clearFilter();
currentFilterRow = -1;

document.getElementById("categoriesTable").style.display = "block";
document.getElementById("assignmentsTable").style.display = "block";
selected_class_i = row.getPosition();
Expand Down

0 comments on commit ca56796

Please sign in to comment.