Skip to content

Commit

Permalink
This schema goes on forever :(
Browse files Browse the repository at this point in the history
  • Loading branch information
notrodes authored and psvenk committed Nov 11, 2020
1 parent 459e854 commit 82b0fbe
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 12 deletions.
57 changes: 46 additions & 11 deletions public/js/home.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ let currentTerm = "current";
* @property {GPA} [cumGPA]
* @property {Term} [currentTermData]
* @property {string} [name]
* @property {OverviewItem[]} [overview]
* @property {Recent} [recent]
* @property {Overview[]} [overview]
* @property {RecentActivity} [recent]
* @property {Schedule} [schedule]
* @property {Terms} [terms]
* @property {?string} [username]
Expand Down Expand Up @@ -96,15 +96,29 @@ let noStats = function() {
document.getElementById("stats_modal_content").style.height = "5rem";
};

/**
* Hide a modal window
* @param {string} key Name of modal window.
*/
let hideModal = function(key) {
modals[key].style.display = "none";
if (key === "stats") noStats();

if (key === "corrections") {
document.getElementById("corrections_modal_input").value = "";
switch (key)
{
case 'stats':
noStats();
break;
case 'corrections':
document.getElementById("corrections_modal_input").value = "";
break;
default:
console.error(`${key} is not a valid modal name`)
}
}

/**
* Un-hide a modal window
* @param {string} key Name of modal window.
*/
let showModal = function(key) {
modals[key].style.display = "inline-block";
}
Expand Down Expand Up @@ -693,18 +707,39 @@ $("#corrections_modal_input").keypress(({ which }) => {
correct();
}
});

/**
* Callback for response from /data
* @typedef {object} Classes
* @param {string} name
* @param {string} grade
* @param {object} categories
* @param {object[]} assignments
* @param {object} tokens
*
* @typedef {object} RecentActivity
* @param {RecentAttendance[]} recentAttendanceArray
* @param {RecentAssignments[]} recentActivityArray
* @param {string} studentName
*
* @typedef {object} scrapedStudent
* @param {Classes[]} response.classes
* @param {RecentActivity} response.recent
* @param {Overview[]} response.overview
* @param {string} response.username
* @param {string} response.quarter
*
* @typedef {object} noLogin response object on no login
* @oaram {boolean} noLogin.nologin - parameter present on login fail
*/
/** Callback for response from /data
*
* @param {TableDataObject} response
* @param {?(string|object)} includedTerms - optional parameter which contains the terms included in an import (in the case that
* @param {noLogin|scrapedStudent} response
* @param {(scrapedStudent|string)} includedTerms - optional parameter which contains the terms included in an import (in the case that
* currentTableData is imported and not all of the terms' data have been put into currentTableData)
*/
function responseCallback(response, includedTerms) {
// console.log(response);
if (response.nologin) {
tableData = [];
tableData = []; // TODO: dont manipulate global state here, return values
currentTableData = undefined;
currentTableDataIndex = -1;

Expand Down
15 changes: 14 additions & 1 deletion scrape.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ async function scrape_overview(username, password) {
let data = [];
$("tr.gradesCell").each(function(i, elem) {
// Description Teacher Schedule term Q1 Q2 Q3 Q4 YTD Abs Tdy Dsm
let row = {};
let row = {}; // TODO: remember how to declare objects cache $(this).children at top or make lamda to remove boilerplate
//row["name"] = $(this).find("a").first().text();
//row["category"] = $(this).children().eq(2).text().trim();
row["class"] = $(this).children().eq(0).text().trim();
Expand All @@ -396,6 +396,18 @@ async function scrape_overview(username, password) {
}

// Returns object of recent activity
/**
* @typedef {object} RecentActivity
* @property {string} date
* @property {string} classname
* @property {string} score
* @property {string} assignment
*/
/**
* @param {string} username
* @param {string} password
* @returns {Promise<Promise<object>>}
*/
async function scrape_recent(username, password) {
let session = await scrape_login();
let page = await submit_login(username, password, session.apache_token, session.session_id);
Expand Down Expand Up @@ -876,6 +888,7 @@ async function scrape_assignments(session_id, apache_token) {

while (true) {
$("tr.listCell.listRowHeight").each(function(i, elem) {
// TODO: hello fix me
let row = {};
//row["name"] = $(this).find("a").first().text();
//row["category"] = $(this).children().eq(2).text().trim();
Expand Down
1 change: 1 addition & 0 deletions serve.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ app.post('/data', async (req, res) => {
res.send({ nologin: true });
}
else {
// TODO add nologin field for consistency
res.send(await scraper.scrape_student(
req.session.username, req.session.password, req.body.quarter
));
Expand Down

0 comments on commit 82b0fbe

Please sign in to comment.