Skip to content

Commit

Permalink
Merge branch 'Simon-Initiative:master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
dtiwarATS committed Feb 13, 2024
2 parents e49d098 + f0ce8d0 commit c61b175
Show file tree
Hide file tree
Showing 29 changed files with 1,096 additions and 155 deletions.
1 change: 1 addition & 0 deletions assets/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module.exports = {
moduleDirectories: ['node_modules', 'src'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx'],
moduleNameMapper: {
'^phoenix/(.*)': '<rootDir>/src/phoenix/$1',
'^components/(.*)': '<rootDir>/src/components/$1',
'^state/(.*)': '<rootDir>/src/state/$1',
'^editor/(.*)': '<rootDir>/src/editor/$1',
Expand Down
13 changes: 6 additions & 7 deletions assets/src/apps/scheduler/PageScheduleLine.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,11 @@ export const PageScheduleLine: React.FC<ScheduleLineProps> = ({ item, indent, da

if (item.startDateTime && startDate) {
targetStartDate = new Date();
// Important: Important to set these in order
targetStartDate.setFullYear(startDate.getFullYear());
targetStartDate.setMonth(startDate.getMonth());
targetStartDate.setDate(startDate.getDate());
targetStartDate.setFullYear(
startDate.getFullYear(),
startDate.getMonth(),
startDate.getDate(),
);
targetStartDate.setHours(
item.startDateTime.getHours(),
item.startDateTime.getMinutes(),
Expand All @@ -57,9 +58,7 @@ export const PageScheduleLine: React.FC<ScheduleLineProps> = ({ item, indent, da
// On a drag, need to change the date, but preserve the end time if one exists.
if (item.endDateTime) {
targetEndDate = new Date();
targetEndDate.setFullYear(endDate.getFullYear());
targetEndDate.setMonth(endDate.getMonth());
targetEndDate.setDate(endDate.getDate());
targetEndDate.setFullYear(endDate.getFullYear(), endDate.getMonth(), endDate.getDate());
targetEndDate.setHours(
item.endDateTime.getHours(),
item.endDateTime.getMinutes(),
Expand Down
18 changes: 11 additions & 7 deletions assets/src/apps/scheduler/scheduler-slice.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,11 @@ const schedulerSlice = createSlice({
mutableItem.startDate = action.payload.startDate;

mutableItem.startDateTime = new Date();
mutableItem.startDateTime.setFullYear(action.payload.startDate.getFullYear());
mutableItem.startDateTime.setMonth(action.payload.startDate.getMonth());
mutableItem.startDateTime.setDate(action.payload.startDate.getDate());
mutableItem.startDateTime.setFullYear(
action.payload.startDate.getFullYear(),
action.payload.startDate.getMonth(),
action.payload.startDate.getDate(),
);

mutableItem.startDateTime.setHours(
state.preferredSchedulingTime.hour,
Expand All @@ -237,7 +239,7 @@ const schedulerSlice = createSlice({
datesChanged =
datesChanged || action.payload.endDate.getTime() !== mutableItem.endDateTime?.getTime();

mutableItem.endDate = new DateWithoutTime();
mutableItem.endDate = new DateWithoutTime(2020, 1, 1);
mutableItem.endDate.setFullYear(action.payload.endDate.getFullYear());
mutableItem.endDate.setMonth(action.payload.endDate.getMonth());
mutableItem.endDate.setDate(action.payload.endDate.getDate());
Expand All @@ -256,9 +258,11 @@ const schedulerSlice = createSlice({
// Need to be careful when converting from a timezone-less DateWithoutTime to a Date
// Just doing a simple new Date(d.utcMidnightDateObj) will result in a date that may be off by a day
mutableItem.endDateTime = new Date();
mutableItem.endDateTime.setFullYear(action.payload.endDate.getFullYear());
mutableItem.endDateTime.setMonth(action.payload.endDate.getMonth());
mutableItem.endDateTime.setDate(action.payload.endDate.getDate());
mutableItem.endDateTime.setFullYear(
action.payload.endDate.getFullYear(),
action.payload.endDate.getMonth(),
action.payload.endDate.getDate(),
);
mutableItem.endDateTime.setHours(
state.preferredSchedulingTime.hour,
state.preferredSchedulingTime.minute,
Expand Down
2 changes: 1 addition & 1 deletion assets/src/components/activities/multi_input/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,6 @@ export interface MultiInputSchema extends ActivityModelSchema, ActivityLevelScor
parts: Part[];
transformations: Transformation[];
previewText: string;
responses?: { user_name: string; text: string }[];
responses?: { user_name: string; text: string; type: string }[];
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,16 +48,18 @@ export const QuestionTab: React.FC<Props> = (props) => {
<div className="mt-5">
<table>
<tr>
<th>Student</th>
<th>Student </th>
<th>Response</th>
</tr>
<tbody>
{model.authoring.responses?.map((response, index) => (
<tr key={index}>
<td className="whitespace-nowrap">{response.user_name}</td>
<td>{response.text}</td>
</tr>
))}
{model.authoring.responses
?.filter((response) => response.type === props.input.inputType)
.map((response, index) => (
<tr key={index}>
<td className="whitespace-nowrap">{response.user_name}</td>
<td>{response.text}</td>
</tr>
))}
</tbody>
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion assets/src/phoenix/activity_bridge.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export const initActivityBridge = (elementId: string) => {
makeRequest(
`/api/v1/state/course/${e.detail.sectionSlug}/activity_attempt/${e.detail.attemptGuid}`,
'POST',
{},
{ survey_id: e.detail.props.context.surveyId },
e.detail.continuation,
);
},
Expand Down
29 changes: 23 additions & 6 deletions assets/src/phoenix/countdownTimer.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
export function formatTimerMessage(realDeadlineInMs: number, now: number) {
const distance = realDeadlineInMs - now;

// Calculate how many whole minutes are in distance milliseconds, allowing to
// go past 60 minutes.
const minutes = Math.floor(distance / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);

return 'Time remaining: ' + minutes + 'm ' + seconds + 's ';
}

export function hasExpired(realDeadlineInMs: number, now: number) {
const distance = realDeadlineInMs - now;
return distance < 0;
}

export function initCountdownTimer(
timerId: string,
submitButtonId: string,
Expand All @@ -10,18 +26,18 @@ export function initCountdownTimer(

if (effectiveTimeInMs > now) {
const timeOutInMs = timeOutInMins * 60 * 1000;
const now = new Date().getTime();

const timeLeft = effectiveTimeInMs - now;
const realDeadlineInMs = timeLeft < timeOutInMs ? now + timeLeft : timeOutInMs + startTimeInMs;

const interval = setInterval(function () {
const now = new Date().getTime();
const distance = realDeadlineInMs - now;
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);
update(timerId, 'Time remaining: ' + minutes + 'm ' + seconds + 's ');

if (distance < 0) {
const timerMessage = formatTimerMessage(realDeadlineInMs, now);
update(timerId, timerMessage);

if (hasExpired(realDeadlineInMs, now)) {
clearInterval(interval);
update(timerId, '');

Expand Down Expand Up @@ -50,7 +66,8 @@ export function initEndDateTimer(
const interval = setInterval(function () {
const now = new Date().getTime();
const distance = realDeadlineInMs - now;
const minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60));

const minutes = Math.floor(distance / (1000 * 60));
const seconds = Math.floor((distance % (1000 * 60)) / 1000);

if (minutes < 5) {
Expand Down
36 changes: 36 additions & 0 deletions assets/test/phoenix/countdownTimer_test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { formatTimerMessage, hasExpired } from 'phoenix/countdownTimer';

it('formats the message correctly', () => {
const now = new Date().getTime();

let message = formatTimerMessage(now + 1000 * 60 * 5, now);
expect(message).toEqual('Time remaining: 5m 0s ');

message = formatTimerMessage(now + 1000 * 60 * 60, now);
expect(message).toEqual('Time remaining: 60m 0s ');

message = formatTimerMessage(now + 1000 * 60 * 70, now);
expect(message).toEqual('Time remaining: 70m 0s ');

message = formatTimerMessage(now + 1000 * 60 * 1337, now);
expect(message).toEqual('Time remaining: 1337m 0s ');

message = formatTimerMessage(now, now);
expect(message).toEqual('Time remaining: 0m 0s ');

message = formatTimerMessage(now + 1000 * 60 * 5 + 1000, now);
expect(message).toEqual('Time remaining: 5m 1s ');

message = formatTimerMessage(now + 1000 * 60 * 5 + 59000, now);
expect(message).toEqual('Time remaining: 5m 59s ');

message = formatTimerMessage(now + 1000 * 60 * 5 + 60000, now);
expect(message).toEqual('Time remaining: 6m 0s ');
});

it('determines expiration correctly', () => {
const now = new Date().getTime();
expect(hasExpired(now + 1000, now)).toEqual(false);
expect(hasExpired(now, now)).toEqual(false);
expect(hasExpired(now - 1000, now)).toEqual(true);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ defmodule Oli.Activities.Transformers.VariableSubstitution.Common do
Enum.reduce(evaluation_digest, encoded, fn %{"variable" => v} = e, s ->
r =
case Map.get(e, "result", "") do
s when is_binary(s) -> s
s when is_binary(s) -> String.trim(s)
list when is_list(list) -> Kernel.inspect(list)
number -> Kernel.to_string(number)
end
Expand Down
1 change: 1 addition & 0 deletions lib/oli/application.ex
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule Oli.Application do

# Starts the publication diff agent store
Oli.Publishing.Publications.DiffAgent,
Oli.Delivery.Attempts.PartAttemptCleaner,

# Starts Cachex to store user/author info across requests
Oli.AccountLookupCache,
Expand Down
6 changes: 4 additions & 2 deletions lib/oli/delivery/attempts/activity_lifecycle.ex
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,8 @@ defmodule Oli.Delivery.Attempts.ActivityLifecycle do
section_slug,
activity_attempt_guid,
datashop_session_id,
seed_state_from_previous \\ false
seed_state_from_previous \\ false,
survey_id \\ nil
) do
activity_attempt = get_activity_attempt_by(attempt_guid: activity_attempt_guid)
resource_attempt = get_resource_attempt_and_revision(activity_attempt.resource_attempt_id)
Expand Down Expand Up @@ -139,7 +140,8 @@ defmodule Oli.Delivery.Attempts.ActivityLifecycle do
resource_id: activity_attempt.resource_id,
group_id: activity_attempt.group_id,
revision_id: revision.id,
resource_attempt_id: activity_attempt.resource_attempt_id
resource_attempt_id: activity_attempt.resource_attempt_id,
survey_id: survey_id
}) do
# simulate preloading of the revision
new_activity_attempt = Map.put(new_activity_attempt, :revision, revision)
Expand Down
2 changes: 2 additions & 0 deletions lib/oli/delivery/attempts/core/activity_attempt.ex
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ defmodule Oli.Delivery.Attempts.Core.ActivityAttempt do
field(:group_id, :string, default: nil)
field(:survey_id, :string, default: nil)
field(:selection_id, :string, default: nil)
field(:cleanup, :integer, default: -1)

belongs_to(:resource, Oli.Resources.Resource)
belongs_to(:revision, Oli.Resources.Revision)
Expand Down Expand Up @@ -55,6 +56,7 @@ defmodule Oli.Delivery.Attempts.Core.ActivityAttempt do
:date_submitted,
:scoreable,
:transformed_model,
:cleanup,
:resource_attempt_id,
:resource_id,
:revision_id,
Expand Down
Loading

0 comments on commit c61b175

Please sign in to comment.