forked from Simon-Initiative/oli-torus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'Simon-Initiative:master' into master
- Loading branch information
Showing
68 changed files
with
1,316 additions
and
698 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
export const DelayedSubmit = { | ||
mounted() { | ||
this.el.addEventListener('click', (event: any) => { | ||
event.preventDefault(); // Prevent immediate click action | ||
|
||
const inputs = document.querySelectorAll( | ||
'input[type="text"], input[type="number"], textarea, select', | ||
); | ||
|
||
// Loop through each element and disable it. This prevents students from making any | ||
// edits in activities while the submission is processing. | ||
inputs.forEach((input: any) => { | ||
input.disabled = true; | ||
}); | ||
|
||
// Disable the button to prevent additional clicks | ||
this.el.disabled = true; | ||
|
||
// Change the button label and show the spinner | ||
this.el.querySelector('.button-text').textContent = 'Submitting Answers...'; | ||
this.el.querySelector('.spinner').classList.remove('hidden'); | ||
|
||
// Delay the phx-click event by two full seconds | ||
setTimeout(() => { | ||
// Trigger the Phoenix event after the delay | ||
this.pushEvent('finalize_attempt'); | ||
|
||
// Optionally, remove the spinner and reset button state if needed | ||
}, 2000); | ||
}); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
// disjunction allows for both .300 and 300. | ||
const regex = /^[+-]?((\d+\.?\d*)|(\.\d+))([eE][-+]?\d+)?$/; | ||
export const isValidNumber = (value: string) => regex.test(value); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { isValidNumber } from '../../src/utils/number'; | ||
|
||
describe('isValidNumber', () => { | ||
// Valid cases | ||
test('should return true for valid integers', () => { | ||
expect(isValidNumber('0')).toBe(true); | ||
expect(isValidNumber('3')).toBe(true); | ||
expect(isValidNumber('-3')).toBe(true); | ||
expect(isValidNumber('+3')).toBe(true); | ||
expect(isValidNumber('123456')).toBe(true); | ||
}); | ||
|
||
test('should return true for valid floating-point numbers', () => { | ||
expect(isValidNumber('0.0')).toBe(true); | ||
expect(isValidNumber('3.14')).toBe(true); | ||
expect(isValidNumber('-3.14')).toBe(true); | ||
expect(isValidNumber('123.456')).toBe(true); | ||
expect(isValidNumber('.456')).toBe(true); | ||
// not allowed in HTML standard but desired in significant figure contexts: | ||
expect(isValidNumber('320.')).toBe(true); | ||
}); | ||
|
||
test('should return true for valid scientific notation', () => { | ||
expect(isValidNumber('3e10')).toBe(true); | ||
expect(isValidNumber('-3e10')).toBe(true); | ||
expect(isValidNumber('3.14e-2')).toBe(true); | ||
expect(isValidNumber('2.5E+5')).toBe(true); | ||
}); | ||
|
||
// Invalid cases | ||
test('should return false for invalid numbers', () => { | ||
expect(isValidNumber('3g')).toBe(false); | ||
expect(isValidNumber('abc')).toBe(false); | ||
expect(isValidNumber('3.14.15')).toBe(false); | ||
expect(isValidNumber('++3')).toBe(false); | ||
expect(isValidNumber('--3')).toBe(false); | ||
expect(isValidNumber('3e+')).toBe(false); | ||
expect(isValidNumber('e3')).toBe(false); | ||
expect(isValidNumber('3e3e4')).toBe(false); | ||
expect(isValidNumber('.')).toBe(false); | ||
}); | ||
|
||
// Edge cases | ||
test('should return false for empty strings', () => { | ||
expect(isValidNumber('')).toBe(false); | ||
}); | ||
|
||
test('should return false for whitespace', () => { | ||
expect(isValidNumber(' ')).toBe(false); | ||
expect(isValidNumber('\t')).toBe(false); | ||
expect(isValidNumber('\n')).toBe(false); | ||
}); | ||
|
||
test('should return false for only a decimal point', () => { | ||
expect(isValidNumber('.')).toBe(false); | ||
expect(isValidNumber('-')).toBe(false); | ||
}); | ||
|
||
test('should return true for zero in different formats', () => { | ||
expect(isValidNumber('0')).toBe(true); | ||
expect(isValidNumber('0.0')).toBe(true); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -199,6 +199,17 @@ defmodule Oli.Accounts do | |
""" | ||
def get_user_by(clauses), do: Repo.get_by(User, clauses) | ||
|
||
@doc """ | ||
Gets a single independent user by query parameter | ||
## Examples | ||
iex> get_independent_user_by(email: "[email protected]") | ||
%User{independent_learner: true, ...} | ||
iex> get_independent_user_by(email: "[email protected]") | ||
nil | ||
""" | ||
def get_independent_user_by(clauses), | ||
do: Repo.get_by(User, Enum.into([independent_learner: true], clauses)) | ||
|
||
@doc """ | ||
Gets a single user with platform roles and author preloaded | ||
Returns `nil` if the User does not exist. | ||
|
Oops, something went wrong.