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

Multiple study codes #4 #5

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
Open
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
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
*.psd
/releases
/misc
/misc
.vscode
1 change: 1 addition & 0 deletions DEVELOPMENT.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ The request body needs to contain the following key-value pairs:
| `jakarta.faces.ClientWindow` | A window id | The id is found in the url as the "dswid" parameter |
| `jakarta.faces.ViewState` | A valid ViewState | See [ViewState](#viewstate) |
| `regForm:subgrouplist` (Optional) | Slot value | **Only needed if registering for exam with slots**<br />The confirmation page contains a dropdown menu (`<select>`) with the available slots to choose from<br />The value is the value attribute of the option (e.g. `<option value="138848">`) of the slot you want to choose |
| `regForm:studyCode` (Optional) | Study code | **Only needed if account has to select study code during a registration**<br />This is for those who are enrolled into multiple curricula. The value is the 6-digit study code (e.g. `033521`) |

## Example curl commands

Expand Down
19 changes: 12 additions & 7 deletions content-scripts/sendRegistration.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ client.runtime.onMessage.addListener((message, sender, sendResponse) => {
// Set a timeout that will run START_OFFSET milliseconds before the registration opens
// This will start the refresh loop, which will then start the register loop
tabId = message.tabId;
let { timestamp, optionId, slot, timeOverride } = message;
let { timestamp, optionId, slot, timeOverride, studyCode } = message;
let currentTime = timeOverride || Date.now();
let remainingTime = Math.max(0, timestamp - currentTime - START_OFFSET);

Expand All @@ -74,7 +74,7 @@ client.runtime.onMessage.addListener((message, sender, sendResponse) => {
clearInterval(sessionRefresh);

// Start the refresh loop
refreshLoop(optionId, slot);
refreshLoop(optionId, slot, studyCode);
}, remainingTime);

// Close the message connection
Expand All @@ -95,7 +95,7 @@ let getButtonFromPage = (page, optionId) => {

// Continously refresh the page until the register button is found, then get the ViewState and start the registration loop
// Requests are sent in series at, if the button is not found after the specified time, the loop will stop
let refreshLoop = async (optionId, slot) => {
let refreshLoop = async (optionId, slot, studyCode) => {
let stopTime = Date.now() + START_OFFSET + STOP_OFFSET;
let viewState, buttonId;

Expand All @@ -122,7 +122,7 @@ let refreshLoop = async (optionId, slot) => {
}

// Start the registration loop
registerLoop(viewState, buttonId, optionId, slot);
registerLoop(viewState, buttonId, optionId, slot, studyCode);
};

// Updates the status of the registration task
Expand All @@ -146,7 +146,7 @@ let updateTaskToRunning = async () => {
// - While sending many requests at once, it has been observed that the response is an error, even if the registration was successfully processed internally
// All the following requests will then get a response which says they're already registered, which causes issues for the result handler
// The observed issues are not fully understood, so it could be considered to change this to a parallel request loop in the future, if it's faster
let registerLoop = async (firstViewState, buttonId, optionId, slot) => {
let registerLoop = async (firstViewState, buttonId, optionId, slot, studyCode) => {
logExactTime("Valid ViewState obtained, starting register loop...");

// Update the status of the registration task
Expand Down Expand Up @@ -185,7 +185,7 @@ let registerLoop = async (firstViewState, buttonId, optionId, slot) => {
}

// Throws an error here if the request fails in any way
response = await sendRequest(viewState, buttonId, slot);
response = await sendRequest(viewState, buttonId, slot, studyCode);

// Reaching this point means the request succeeded
// (Note that this doesn't mean the registration was successful, as the response has to be checked)
Expand Down Expand Up @@ -219,13 +219,18 @@ const CONFIRM_ENDPOINT = "https://tiss.tuwien.ac.at/education/course/register.xh

// This function attempts to send the two POST requests required to register and returns a promise of the body of the second request
// If any of the requests fail, it will throw an error (caused by the validateResponse function)
let sendRequest = async (viewState, buttonId, slot) => {
let sendRequest = async (viewState, buttonId, slot, studyCode) => {
// Define the request body
let bodyData = {
"jakarta.faces.ClientWindow": windowId,
"jakarta.faces.ViewState": viewState
};

// Handle mutiple multiple studycodes
if (studyCode) {
bodyData = {...bodyData, "regForm:studyCode": studyCode }
}

// Create the body together with the additional required data and define endpoint
let targetUrl, firstBody;
if (pageType == "lva") {
Expand Down
8 changes: 6 additions & 2 deletions popup-scripts/registerButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ document.getElementById("slot-select").addEventListener("change", () => {
// Main button callback, it expects that the selected options are valid
registerButton.addEventListener("click", async () => {
// Get the info of the selected options
let optionInfo, optionId, slot;
let optionInfo, optionId, slot, studyCode;
if (pageType == "lva") {
optionInfo = pageInfo.options[0]; // If the page is an LVA page, there is only one option
} else {
Expand All @@ -46,6 +46,9 @@ registerButton.addEventListener("click", async () => {
}
}

// Get the studycode from input field
studyCode = document.getElementById("studycode-input").value;

// Disable the button and select elements
registerButton.disabled = true;
document.getElementById("option-select").disabled = true;
Expand Down Expand Up @@ -85,7 +88,8 @@ registerButton.addEventListener("click", async () => {
timestamp: optionInfo.start,
optionId,
slot,
timeOverride
timeOverride,
studyCode,
});

// Store the active registration task
Expand Down
7 changes: 7 additions & 0 deletions popup-scripts/studyCodeInput.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
// This file simply toggles the visibilty of the study code input field for now
// In the future this might need to sanitize the input and do other validation, but for now this should suffice

document.getElementById("hasStudyCode-input").onchange = function() {
let input = document.getElementById("studycode-input");
input.hidden = !input.hidden;
}
9 changes: 9 additions & 0 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,14 @@ <h1>Lightning Registrator</h1>
</p>
</section>

<section name="studyCode">
<p>
<input type="checkbox" id="hasStudyCode-input" onchange="">
<label for="hasStudyCode-input">Multi-Program Enrollment</label>
<input hidden type="number" id="studycode-input" placeholder="033521">
</p>
</section>

<section hidden name="register">
<select disabled id="option-select">
<option selected hidden value="">Select a registration option</option>
Expand Down Expand Up @@ -66,6 +74,7 @@ <h2>Active Registrations</h2>
<script src="popup-scripts/popupComponents.js"></script>
<script src="popup-scripts/registerButton.js"></script>
<script src="popup-scripts/registrationTasks.js"></script>
<script src="popup-scripts/studyCodeInput.js"></script>
<script src="index.js"></script>
</body>
</html>
13 changes: 11 additions & 2 deletions styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,14 @@ main {

/* Set transitions for hover effects and button clicks */
select,
button {
button,
input {
transition: filter ease-in-out 0.2s, border-radius ease-in-out 0.2s, transform ease-in-out 0.15s;
}

select:hover,
button:hover {
button:hover,
input:hover {
filter: brightness(1.1);
}

Expand Down Expand Up @@ -119,6 +121,13 @@ section[name="register"] select:enabled:hover {
border-radius: 15px;
}

/* Study Code input */
section[name="studyCode"] {
width: 100%;
margin: 0;
padding: 0px 12px 0px 12px;
}

/* Register button */
section[name="register"] button {
width: 100%;
Expand Down