Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issues due to PowerSchool UI update and fixed category weighting bug #308

Merged
merged 6 commits into from
Nov 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/js/components/CategoryWeighting.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,15 @@ export default {
methods: {
async getCatmap () {
let catmap = await getSavedCategoryWeighting();
if (catmap === false) {
if (!catmap) {
catmap = {};
this.categories.sort();
this.categories.forEach((e, i) => {
catmap[e] = { weighting: 0, category: e };
});
}
this.categories.sort();
this.categories.forEach((e, i) => {
if (catmap[e] === undefined) {
catmap[e] = { weighting: 0, category: e };
}
});
const category_set = new Set(this.categories);
for (var cat in catmap) {
category_set.add(cat);
Expand Down
62 changes: 54 additions & 8 deletions src/js/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function extractGradeCategories (table) {
const table_rows = table.getElementsByTagName("tr");
const category_set = new Set();
for (let i = 1; i < table_rows.length - 1; i++) {
category_set.add(table_rows[i].getElementsByTagName("td")[1].getElementsByTagName("a")[0].innerText);
category_set.add(table_rows[i].getElementsByTagName("td")[1].getElementsByTagName("span")[1].innerText);
}
return Array.from(category_set);
}
Expand All @@ -202,11 +202,15 @@ function extractGradeCategories (table) {
* @returns {ClassAssignment[]} List of all assignments
*/
function extractAssignmentList () {
const table = document.querySelector("#content-main > div.box-round > table:nth-child(4) > tbody");
const table = document.querySelector("table.zebra.grid > tbody");
const assignments = [];
[...table.querySelectorAll('tr')].slice(1, -1).forEach((e, i) => {
const curr = e.querySelectorAll('td');
assignments.push(new ClassAssignment(i, curr[0].innerHTML, curr[1].innerText, curr[2].innerHTML, isIndicatorPresent(curr[3]), isIndicatorPresent(curr[4]), isIndicatorPresent(curr[5]), isIndicatorPresent(curr[6]), isIndicatorPresent(curr[7]), curr[9].innerHTML, curr[11].innerHTML));
let offset = 0;
if (curr.length === 14) {
offset = 1;
}
assignments.push(new ClassAssignment(i, curr[0].innerHTML, curr[1].innerText, curr[2].innerHTML, isIndicatorPresent(curr[3 + offset]), isIndicatorPresent(curr[4 + offset]), isIndicatorPresent(curr[5 + offset]), isIndicatorPresent(curr[6 + offset]), isIndicatorPresent(curr[7 + offset]), isIndicatorPresent(curr[8 + offset]), isIndicatorPresent(curr[9 + offset]), curr[10 + offset].innerText, curr[11 + offset].innerText.trim()));
});
return assignments;
}
Expand All @@ -216,17 +220,17 @@ function extractAssignmentList () {
* @returns {boolean} boolean representing whether input has child nodes and are set to visible.
*/
function isIndicatorPresent (node) {
return node.hasChildNodes() && node.childNodes[0].style.display !== 'none';
return node.childNodes?.length === 7 || false;
}
/**
* Return Assignment instances for the given class page.
* @param {Element} node Root node element of the class page.
* @returns {Assignment[]} Assignments in this course
*/
function assignments (node) {
function assignmentsFromNode (node) {
const tr = [];
// Find assignments table, get it's rows, take out the header and legend rows.
[...node.querySelector('table[align=center').querySelectorAll('tr')].slice(1, -1).forEach((e, i) => {
[...node.querySelector('table.zebra.grid').querySelectorAll('tr')].slice(1, -1).forEach((e, i) => {
const curr = e.querySelectorAll('td');
const assignment = new Assignment(curr[2]?.innerText || "", curr[curr.length - 1]?.innerText || "", i);
const missingIcon = e.querySelector('img[src="/images/icon_missing.gif"]');
Expand All @@ -238,12 +242,53 @@ function assignments (node) {
return tr;
}

/**
* Return Assignment instances for the given class page.
* @param {String} student_id student id for the current user
* @param {String} sectino_id section id for the course being requested
* @param {String} start_date start date in YYYY-MM-DD format
* @param {String} end_date end date in YYYY-MM-DD format
* @returns {Assignment[]} Assignments in this course
*/
function assignmentsFromAPI (studentId, sectionId, startDate, endDate) {
const assignmentList = [];
try {
fetch('https://powerschool.sas.edu.sg/ws/xte/assignment/lookup', {
method: "POST",
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
"student_ids": [studentId],
"section_ids": [sectionId],
"start_date": startDate,
"end_date": endDate,
}),
credentials: "same-origin",
}).then(response => response.json()).then(response => {
for (let i = 0; i < response.length; i++) {
if (response[i]._assignmentsections?.length) {
const assignmentData = response[i]._assignmentsections[0];
const assignment = new Assignment(assignmentData.name, assignmentData._assignmentscores[0]?.actualscoreentered || "", i);
if (assignmentData._assignmentscores[0]?.ismissing || null) {
assignment.addStatus(Assignment.statuses.MISSING);
}
assignmentList.push(assignment);
}
}
});
} catch (e) {
return [];
}
return assignmentList;
}

/**
* Return course title of active class page
* @returns {String} Course title
*/
function extractCourseTitle () {
return document.getElementsByTagName('h2')[0].innerHTML;
return document.querySelector("tbody:nth-child(1) > tr:nth-child(2) > td:nth-child(1)").innerText;
}

/**
Expand Down Expand Up @@ -366,7 +411,8 @@ export {
getFinalPercent,
extractGradeCategories,
extractAssignmentList,
assignments,
assignmentsFromNode,
assignmentsFromAPI,
calculate_credit_hours,
getSavedGrades,
saveGradesLocally,
Expand Down
4 changes: 3 additions & 1 deletion src/js/models/ClassAssignment.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,15 @@
*/

export default class ClassAssignment {
constructor (id, date, category, name, collected, late, missing, exempt, excluded, score, grade, hypo = false) {
constructor (id, date, category, name, collected, late, missing, exempt, absent, incomplete, excluded, score, grade, hypo = false) {
this.id = id;
this.date = date;
this.category = category;
this.name = name;
this.collected = collected;
this.late = late;
this.absent = absent;
this.incomplete = incomplete;
this.missing = missing;
this.exempt = exempt;
this.excluded = excluded;
Expand Down
21 changes: 17 additions & 4 deletions src/js/saspowerschoolff.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ import $ from 'jquery';
const browser = require('webextension-polyfill');

import {
assignments,
assignmentsFromNode,
assignmentsFromAPI,
calculate_gpa,
getFinalPercent,
extractGradeCategories,
Expand All @@ -59,6 +60,7 @@ import Course from './models/Course';
import CumulativeGPA from "./components/CumulativeGPA";

var gt;
var gt_mounted;

main();
function main () {
Expand Down Expand Up @@ -111,6 +113,7 @@ async function main_page () {

async function class_page () {
// Show final percent
await new Promise((resolve, reject) => setTimeout(resolve, 750)); // adds delay prior to running to ensure that class page JS is finished running.
const currentUrl = new URL(document.location.href);
const number = await getFinalPercent(currentUrl.searchParams.get("frn"), currentUrl.searchParams.get("fg")) || "";
if (!number) {
Expand All @@ -135,6 +138,10 @@ async function class_page () {
document.getElementById('saspes-categories').style.display = "none";
gt.setCategoryWeighting(false);
} else {
if (!gt_mounted) {
gt_mounted = true;
gt.$mount('table.zebra.grid');
}
document.getElementById('saspes-hypo-assignment').style.display = "none";
document.getElementById('saspes-categories').style.display = "block";
gt.setCategoryWeighting(true);
Expand Down Expand Up @@ -340,7 +347,13 @@ async function getCourses (second_semester, sem1_col, sem2_col) {
fetch(currentUrlString, { credentials: "same-origin" }).then(response => response.text()).then(response => {
const page = document.implementation.createHTMLDocument();
page.documentElement.innerHTML = response;
const assignment_list = assignments(page.querySelector('body'));
const sectionId = page.querySelector("div[data-pss-student-assignment-scores]").getAttribute("data-sectionid");
let startDate = currentUrl.searchParams.get("begdate");
startDate = startDate.split("/")[2] + "-" + startDate.split("/")[0] + "-" + startDate.split("/")[1];
let endDate = currentUrl.searchParams.get("enddate");
endDate = endDate.split("/")[2] + "-" + endDate.split("/")[0] + "-" + endDate.split("/")[1];
const studentId = page.querySelector("div .xteContentWrapper").getAttribute("data-ng-init").split("\n")[0].split("= '")[1].replace("';", "").substring(3);
const assignment_list = assignmentsFromAPI(studentId, sectionId, startDate, endDate);
courses.push(new Course(temp.trim(), currentUrlString, $course.text(), finalPercent, assignment_list));
if (gradeToGPA($course.text()) !== -1) {
new (Vue.extend(ClassGrade))({
Expand Down Expand Up @@ -425,13 +438,13 @@ function addHypoGradeCalc (courses) {
*/
async function addVueGrades () {
const assignments = extractAssignmentList();
const cat = extractGradeCategories(document.querySelector("#content-main > div.box-round > table:nth-child(4) > tbody"));
const cat = extractGradeCategories(document.querySelector("table.zebra.grid > tbody"));
gt = new (Vue.extend(GradeTable))({ // remake grade table to easily read grades
propsData: {
categories: cat,
assignments: assignments,
},
}).$mount('#content-main > div.box-round > table:nth-child(4)');
});
document.querySelector('div.box-round').insertAdjacentHTML('afterend', `<div id="saspes-categories"></div>`);
new (Vue.extend(CategoryWeighting))({ // category weighting widget
propsData: {
Expand Down