Skip to content

Commit

Permalink
CTP-3093 Remove all code related to sync transfer
Browse files Browse the repository at this point in the history
CTP-3101 Trigger page reload when task is done on status page
  • Loading branch information
aydevworks committed Feb 12, 2024
1 parent 3c02e74 commit 6ec3f5a
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 132 deletions.
2 changes: 1 addition & 1 deletion amd/build/sitsgradepush.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion amd/build/sitsgradepush.min.js.map

Large diffs are not rendered by default.

174 changes: 99 additions & 75 deletions amd/src/sitsgradepush.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import {schedulePushTask, getAssessmentsUpdate, updateProgressBar} from "./sitsgradepush_helper";
import {getAssessmentsUpdate, schedulePushTask, updateProgressBar} from "./sitsgradepush_helper";
import notification from 'core/notification';

let updatePageIntervalId = null; // The interval ID for updating the progress.
let updatePageDelay = 15000; // The delay for updating the page.
let taskRunning = false;
let shouldRefresh = false;

/**
* Initialize the course module marks transfer page (index.php).
Expand Down Expand Up @@ -64,73 +66,65 @@ function initConfirmationModal(courseid, coursemoduleid) {

// Add event listener to the confirmation modal.
confirmTransferButton.addEventListener("click", async function() {
// Check if it is an async push button.
let async = confirmTransferButton.getAttribute('data-async');
if (async === "1") {
let promises = [];

// Find all valid assessment mapping IDs.
let mappingtables = document.querySelectorAll('.sitsgradepush-history-table');

// Number of assessment mappings.
let total = mappingtables.length - 1; // Exclude the invalid students table.
let count = 0;

// Schedule a task to push grades to SITS for each assessment mapping.
mappingtables.forEach(function(table) {
let mappingid = table.getAttribute('data-assessmentmappingid');
let markscount = table.getAttribute('data-markscount');
if (mappingid !== null && markscount > 0) {
let promise = schedulePushTask(mappingid)
.then(function(result) {
if (result.success) {
count = count + 1;
} else {
// Create an error message row.
let errormessageid = "error-message-" + mappingid;
let errormessagerow = document.createElement("div");
errormessagerow.setAttribute("id", errormessageid);
errormessagerow.setAttribute("class", "error-message-row");
errormessagerow.innerHTML =
'<div class="alert alert-danger" role="alert">' + result.message + '</div>';

// Find the closest row to the assessment mapping.
let currentrow = document.getElementById(errormessageid);

// Remove the error message row if it exists.
if (currentrow !== null) {
currentrow.remove();
}

// Insert the error message above the table.
table.parentNode.insertBefore(errormessagerow, table);
let promises = [];

// Find all valid assessment mapping IDs.
let mappingtables = document.querySelectorAll('.sitsgradepush-history-table');

// Number of assessment mappings.
let total = mappingtables.length - 1; // Exclude the invalid students table.
let count = 0;

// Schedule a task to push grades to SITS for each assessment mapping.
mappingtables.forEach(function(table) {
let mappingid = table.getAttribute('data-assessmentmappingid');
let markscount = table.getAttribute('data-markscount');
if (mappingid !== null && markscount > 0) {
let promise = schedulePushTask(mappingid)
.then(function(result) {
if (result.success) {
count = count + 1;
} else {
// Create an error message row.
let errormessageid = "error-message-" + mappingid;
let errormessagerow = document.createElement("div");
errormessagerow.setAttribute("id", errormessageid);
errormessagerow.setAttribute("class", "error-message-row");
errormessagerow.innerHTML =
'<div class="alert alert-danger" role="alert">' + result.message + '</div>';

// Find the closest row to the assessment mapping.
let currentrow = document.getElementById(errormessageid);

// Remove the error message row if it exists.
if (currentrow !== null) {
currentrow.remove();
}
return result.success;
})
.catch(function(error) {
window.console.error(error);
});

promises.push(promise);
}
});

// Wait for all the push tasks to be scheduled.
await Promise.all(promises);

// Update the page.
await updateTasksInfo(courseid, coursemoduleid);

// Display a notification.
await notification.addNotification({
message: count + ' of ' + total + ' push tasks have been scheduled.',
type: (count === total) ? 'success' : 'warning'
});
} else {
// Redirect to the legacy synchronous push page.
// Will improve it when we have a more concrete plan for the sync push.
window.location.href = '/local/sitsgradepush/index.php?id=' + coursemoduleid + '&pushgrade=1';
}

// Insert the error message above the table.
table.parentNode.insertBefore(errormessagerow, table);
}
return result.success;
})
.catch(function(error) {
window.console.error(error);
});

promises.push(promise);
}
});

// Wait for all the push tasks to be scheduled.
await Promise.all(promises);

// Update the page.
await updateTasksInfo(courseid, coursemoduleid);

// Display a notification.
await notification.addNotification({
message: count + ' of ' + total + ' push tasks have been scheduled.',
type: (count === total) ? 'success' : 'warning'
});
});
}

Expand Down Expand Up @@ -166,26 +160,56 @@ async function updateTasksInfo(courseid, coursemoduleid) {
* @param {object[]} assessments
*/
function updateProgress(assessments) {
// Check if there is any running task.
taskRunning = hasRunningTask(assessments);

// If there is any running task, mark page should be refreshed.
if (taskRunning) {
shouldRefresh = true;
}

// Refresh the page if there is no running task and should be refreshed.
if (shouldRefresh && !taskRunning) {
shouldRefresh = false;
location.reload();
}

// Get the push button element.
let pushbutton = document.getElementById('push-all-button');
if (pushbutton) {
// Disable the push button if there is any running task, otherwise enable it.
pushbutton.disabled = taskRunning;
} else {
window.console.log('Push button not found');
}

assessments.forEach(assessment => {
let progressContainer = document.getElementById('progress-container-' + assessment.assessmentmappingid);
if (!progressContainer) {
window.console.log('Progress container not found for assessment mapping ID: ' + assessment.assessmentmappingid);
return;
}
let pushbutton = document.getElementById('push-all-button');
if (assessment.task === null) {
// Enable the push button if there is no task running.
if (pushbutton) {
pushbutton.disabled = false;
}
// Hide the progress container if there is no task in progress.
progressContainer.style.display = 'none';
} else {
if (pushbutton) {
pushbutton.disabled = true;
}
progressContainer.style.display = 'block';
updateProgressBar(progressContainer, assessment.task.progress);
}
});
}

/**
* Check if there is a running task.
*
* @param {object[]} assessments
* @return {boolean}
*/
function hasRunningTask(assessments) {
for (let i = 0; i < assessments.length; i++) {
if (assessments[i].task !== null) {
return true;
}
}
return false;
}
1 change: 0 additions & 1 deletion classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,6 @@ public function render_marks_transfer_history_page(array $assessmentdata, int $c
'transfer-all-button-label' => get_string('label:pushgrade', 'local_sitsgradepush'),
'latest-transferred-text' => $this->get_latest_tranferred_text($assessmentdata['mappings']),
'invalid-students' => !empty($assessmentdata['invalidstudents']->students) ? $assessmentdata['invalidstudents'] : null,
'async' => get_config('local_sitsgradepush', 'async'),
]);
}

Expand Down
22 changes: 0 additions & 22 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -81,29 +81,7 @@
// Get page content.
$content = $manager->get_assessment_data($coursemoduleid);

// Check if asynchronous grade push is enabled.
$async = get_config('local_sitsgradepush', 'async');

if (!empty($content)) {
// Transfer marks if it is a sync transfer and pushgrade is set.
if (!$async && $pushgrade == 1) {
// Loop through each mapping.
foreach ($content['mappings'] as $mapping) {
// Skip if there is no student in the mapping.
if (empty($mapping->students)) {
continue;
}
// Push grades for each student in the mapping.
foreach ($mapping->students as $student) {
$manager->push_grade_to_sits($mapping, $student->userid);
$manager->push_submission_log_to_sits($mapping, $student->userid);
}
}

// Refresh data after completed all pushes.
$content = $manager->get_assessment_data($coursemoduleid);
}

// Render the page.
echo $renderer->render_marks_transfer_history_page($content, $coursemodule->course);
} else {
Expand Down
4 changes: 0 additions & 4 deletions lang/en/local_sitsgradepush.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@
$string['settings:apiclient:desc'] = 'Choose which API client to use';
$string['settings:enable'] = 'Enable Marks Transfer';
$string['settings:enable:desc'] = 'Enable Marks Transfer to SITS';
$string['settings:enableasync'] = 'Enable Async Marks Transfer';
$string['settings:enableasync:desc'] = 'If enabled, marks transfer will be done by an ad-hoc task';
$string['settings:enablesublogpush'] = 'Enable Submission Log transfer';
$string['settings:enablesublogpush:desc'] = 'Enable submission log transfer to SITS';
$string['settings:generalsettingsheader'] = 'General Settings';
Expand All @@ -48,8 +46,6 @@
$string['settings:concurrenttasks:desc'] = 'Number of concurrent ad-hoc tasks allowed';
$string['settings:userprofilefield'] = 'User Profile Field';
$string['settings:userprofilefield:desc'] = 'User profile field for export staff';
$string['settings:sync_threshold'] = 'Sync Threshold';
$string['settings:sync_threshold:desc'] = 'The threshold to allow for running synchronous mark transfer task';
$string['settings:support_page_url'] = 'Support Page URL';
$string['settings:support_page_url:desc'] = 'Used in the notification email to provide a link to the support page';
$string['label:gradepushassessmentselect'] = 'Select SITS assessment to link to';
Expand Down
16 changes: 0 additions & 16 deletions settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,22 +49,6 @@
'1'
));

// Setting to enable/disable the async push.
$settings->add(new admin_setting_configcheckbox(
'local_sitsgradepush/async',
get_string('settings:enableasync', 'local_sitsgradepush'),
get_string('settings:enableasync:desc', 'local_sitsgradepush'),
0
));

// Threshold to allow for synchronous mark transfer.
$settings->add(new admin_setting_configtext('local_sitsgradepush/sync_threshold',
get_string('settings:sync_threshold', 'local_sitsgradepush'),
get_string('settings:sync_threshold:desc', 'local_sitsgradepush'),
30,
PARAM_INT
));

// Setting to enable/disable submission log push.
$settings->add(new admin_setting_configcheckbox(
'local_sitsgradepush/sublogpush',
Expand Down
Loading

0 comments on commit 6ec3f5a

Please sign in to comment.