Skip to content

Commit

Permalink
Merge pull request #38 from ucl-isd/CTP-3973-update-javascript
Browse files Browse the repository at this point in the history
Ctp 3973 update javascript
  • Loading branch information
aspark21 authored Oct 30, 2024
2 parents f4f33e7 + 555d121 commit 5672a43
Show file tree
Hide file tree
Showing 24 changed files with 1,005 additions and 10,257 deletions.
4 changes: 1 addition & 3 deletions actions/allocate.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
// If a session variable holding perpage preference for the specific coursework is not set, set default value (10).
if (!(isset($SESSION->allocate_perpage[$coursemoduleid]))) {
$perpage = optional_param('per_page', 0, PARAM_INT);
$perpage = $perpage ?: (get_config('coursework', 'coursework_per_page') ?? 10);
$perpage = $perpage ?: ($CFG->coursework_per_page ?? 10);
$SESSION->allocate_perpage[$coursemoduleid] = $perpage;
} else {
$perpage = optional_param('per_page', $SESSION->allocate_perpage[$coursemoduleid], PARAM_INT);
Expand Down Expand Up @@ -93,8 +93,6 @@

$PAGE->requires->jquery();

$PAGE->requires->js('/mod/coursework/loadingoverlay.min.js');

// Will set off the function that adds listeners for onclick/onchange etc.
$jsmodule = [
'name' => 'mod_coursework',
Expand Down
6 changes: 3 additions & 3 deletions classes/controllers/deadline_extensions_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,14 @@ public function ajax_submit_mitigation($dataparams) {

public function validation($data) {
global $CFG;
$maxdeadline = $CFG->coursework_max_extension_deadline;

if ($this->coursework->personaldeadlineenabled && $personaldeadline = $this->personal_deadline()) {
$deadline = $personaldeadline->personal_deadline;
} else {
$deadline = $this->coursework->deadline;
}

if ( $data['extended_deadline'] <= $deadline) {
return $errors = 'The new deadline must be later than the current deadline';
return 'The new deadline must be later than the current deadline';
}

return false;
Expand Down Expand Up @@ -320,6 +318,7 @@ public function ajax_edit_mitigation($dataparams) {
'courseworkid' => $deadlineextension->courseworkid,
'id' => $deadlineextension->id,
'pre_defined_reason' => $deadlineextension->pre_defined_reason,
'time_iso_8601' => date(\DateTime::ATOM, $deadlineextension->extended_deadline),
];
$response = [
'error' => 0,
Expand Down Expand Up @@ -370,6 +369,7 @@ public function ajax_new_mitigation($dataparams) {
$deadlineextensiontransform = [
'time_content' => $timecontent,
'time' => $time,
'time_iso_8601' => date(\DateTime::ATOM, $this->coursework->deadline),
];

$response = [
Expand Down
4 changes: 4 additions & 0 deletions classes/controllers/feedback_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,10 @@ protected function update_feedback() {

} else {
$teacherfeedback->destroy();
// Clear cache.
\mod_coursework\models\feedback::remove_cache($this->submission->courseworkid);
\mod_coursework\models\submission::remove_cache($this->submission->courseworkid);

// Remove associated files
$fs = get_file_storage();
$fs->delete_area_files($teacherfeedback->get_coursework()->get_context()->id, 'mod_coursework', 'feedback', $teacherfeedback->id());
Expand Down
55 changes: 28 additions & 27 deletions classes/controllers/personal_deadlines_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
* @property personal_deadline_form form
* @package mod_coursework\controllers
*/
#[\AllowDynamicProperties]
class personal_deadlines_controller extends controller_base {

protected function new_personal_deadline() {
Expand All @@ -47,7 +48,7 @@ protected function new_personal_deadline() {

$params = $this->set_default_current_deadline();
$ability = new ability(user::find($USER), $this->coursework);
$ability->require_can('edit', $this->personal_deadline);
$ability->require_can('edit', $this->personaldeadline);

$params['allocatableid'] = (!is_array($params['allocatableid']))
? $params['allocatableid']
Expand All @@ -58,11 +59,11 @@ protected function new_personal_deadline() {

$this->form = new personal_deadline_form($createurl, ['coursework' => $this->coursework]);

$this->personal_deadline->setpersonaldeadlinespage = $this->params['setpersonaldeadlinespage'];
$this->personal_deadline->multipleuserdeadlines = $this->params['multipleuserdeadlines'];
$this->personaldeadline->setpersonaldeadlinespage = $this->params['setpersonaldeadlinespage'];
$this->personaldeadline->multipleuserdeadlines = $this->params['multipleuserdeadlines'];

$this->personal_deadline->allocatableid = $params['allocatableid'];
$this->form->set_data($this->personal_deadline);
$this->personaldeadline->allocatableid = $params['allocatableid'];
$this->form->set_data($this->personaldeadline);
if ($this->cancel_button_was_pressed()) {
redirect($courseworkpageurl);
}
Expand All @@ -74,14 +75,14 @@ protected function new_personal_deadline() {
if (!$this->get_personal_deadline()) { // personal deadline doesnt exist
// add new
$data->createdbyid = $USER->id;
$this->personal_deadline = personal_deadline::build($data);
$this->personal_deadline->save();
$this->personaldeadline = personal_deadline::build($data);
$this->personaldeadline->save();

} else {
// update
$data->lastmodifiedbyid = $USER->id;
$data->timemodified = time();
$this->personal_deadline->update_attributes($data);
$this->personaldeadline->update_attributes($data);
}
} else {
$allocatables = unserialize($data->allocatableid);
Expand All @@ -94,20 +95,20 @@ protected function new_personal_deadline() {
'allocatabletype' => $data->allocatabletype,
'courseworkid' => $data->courseworkid,
];
$this->personal_deadline = personal_deadline::find_or_build($findparams);
$this->personaldeadline = personal_deadline::find_or_build($findparams);

if (empty($this->personal_deadline->personal_deadline)) { // personal deadline doesnt exist
if (empty($this->personaldeadline->personal_deadline)) { // personal deadline doesnt exist
// add new
$data->createdbyid = $USER->id;
$this->personal_deadline = personal_deadline::build($data);
$this->personal_deadline->save();
$this->personaldeadline = personal_deadline::build($data);
$this->personaldeadline->save();

} else {
// update
$data->id = $this->personal_deadline->id;
$data->id = $this->personaldeadline->id;
$data->lastmodifiedbyid = $USER->id;
$data->timemodified = time();
$this->personal_deadline->update_attributes($data);
$this->personaldeadline->update_attributes($data);
}

}
Expand Down Expand Up @@ -135,14 +136,14 @@ protected function set_default_current_deadline() {
// We use the first element in the array to setup the personal deadline object
$params['allocatableid'] = (is_array($this->params['allocatableid'])) ? current($this->params['allocatableid']) : $this->params['allocatableid'];

$this->personal_deadline = personal_deadline::find_or_build($params);
$this->personaldeadline = personal_deadline::find_or_build($params);

$params['allocatableid'] = $this->params['allocatableid'];

// If the allocatableid is an array then the current page will probably be setting multiple the personal deadlines
// of multiple allocatable ids in which case set the personal deadline to the coursework default
if (is_array($this->params['allocatableid']) || !$this->get_personal_deadline()) { // if no personal deadline then use coursework deadline
$this->personal_deadline->personal_deadline = $this->coursework->deadline;
$this->personaldeadline->personal_deadline = $this->coursework->deadline;

}

Expand Down Expand Up @@ -188,7 +189,7 @@ public function insert_update($time) {
$params = $this->set_default_current_deadline();

$ability = new ability(user::find($USER), $this->coursework);
$ability->require_can('edit', $this->personal_deadline);
$ability->require_can('edit', $this->personaldeadline);
$params['allocatableid'] = (!is_array($params['allocatableid']))
? $params['allocatableid']
: serialize($params['allocatableid']);
Expand All @@ -199,14 +200,14 @@ public function insert_update($time) {
// add new
$data->createdbyid = $USER->id;
$data->personal_deadline = strtotime($time);
$this->personal_deadline = personal_deadline::build($data);
$this->personal_deadline->save();
$this->personaldeadline = personal_deadline::build($data);
$this->personaldeadline->save();
} else {
// update
$data->lastmodifiedbyid = $USER->id;
$data->personal_deadline = strtotime($time);
$data->timemodified = time();
$this->personal_deadline->update_attributes($data);
$this->personaldeadline->update_attributes($data);
}
} else {
$allocatables = unserialize($data->allocatableid);
Expand All @@ -220,23 +221,23 @@ public function insert_update($time) {
'allocatabletype' => $data->allocatabletype,
'courseworkid' => $data->courseworkid,
];
$this->personal_deadline = personal_deadline::find_or_build($findparams);
$this->personaldeadline = personal_deadline::find_or_build($findparams);

if (empty($this->personal_deadline->personal_deadline)) { // personal deadline doesnt exist
if (empty($this->personaldeadline->personal_deadline)) { // personal deadline doesnt exist
// add new
$data->createdbyid = $USER->id;
$this->personal_deadline = personal_deadline::build($data);
$this->personal_deadline->save();
$this->personaldeadline = personal_deadline::build($data);
$this->personaldeadline->save();
} else {
// update
$data->id = $this->personal_deadline->id;
$data->id = $this->personaldeadline->id;
$data->lastmodifiedbyid = $USER->id;
$data->timemodified = time();
$this->personal_deadline->update_attributes($data);
$this->personaldeadline->update_attributes($data);
}
}
}
$timestamp = $this->personal_deadline->personal_deadline;
$timestamp = $this->personaldeadline->personal_deadline;
$date = userdate($timestamp, '%a, %d %b %Y, %H:%M');
return [
'error' => 0,
Expand Down
1 change: 1 addition & 0 deletions classes/controllers/plagiarism_flagging_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
* It is the beginning of the process of tidying things up to make them a bit more MVC where possible.
*
*/
#[\AllowDynamicProperties]
class plagiarism_flagging_controller extends controller_base {

/**
Expand Down
4 changes: 2 additions & 2 deletions classes/forms/plagiarism_flagging_mform.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,8 @@ public function process_data(plagiarism_flag $plagiarismflag) {
$formdata = $this->get_data();

$plagiarismflag->status = $formdata->status;
$plagiarismflag->comment = $formdata->plagiarismcomment['text'];
$plagiarismflag->comment_format = $formdata->plagiarismcomment['format'];
$plagiarismflag->comment = $formdata->plagiarismcomment['text'] ?? '';
$plagiarismflag->comment_format = $formdata->plagiarismcomment['format'] ?? FORMAT_PLAIN;

return $plagiarismflag;
}
Expand Down
1 change: 0 additions & 1 deletion classes/framework/table_base.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@

namespace mod_coursework\framework;

use moodle_database;
use stdClass;

defined('MOODLE_INTERNAL') || die();
Expand Down
1 change: 1 addition & 0 deletions classes/models/plagiarism_flag.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
* @property mixed allocatableid
* @package mod_coursework\models
*/
#[\AllowDynamicProperties]
class plagiarism_flag extends table_base {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,13 @@ public function get_table_cell($rowobject) {
$content .= $OUTPUT->action_icon($link,
$icon,
null,
['class' => $class, 'data-get' => json_encode($newpersonaldeadlineparams), 'data-time' => date('d-m-Y H:i', $deadline) ]);
[
'class' => $class,
'data-get' => json_encode($newpersonaldeadlineparams),
'data-time' => date('d-m-Y H:i', $deadline),
'data-time-iso-8601' => date('Y-m-d\TH:i', $deadline),
]
);
$content .= '</div><div class="show_edit_personal_dealine display-none"> </div>';

return $this->get_new_cell_with_order_data(['display' => $content, '@data-order' => $deadline]);
Expand Down
32 changes: 11 additions & 21 deletions datatables/js/datatables.js → coursework.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,15 @@ $( document ).ready(function() {

require.config({
paths: {
'jquery': base_url + 'jquery-3.3.1.min',
'datatables.net': base_url + 'jquery.datatables',
'datatables.searchpanes': base_url + 'datatables.searchpanes',
'datatables.buttons': base_url + 'datatables.buttons',
'datatables.select': base_url + 'datatables.select',
'datatables.responsive': base_url + 'datatables.responsive.min',
'jquery-mousewheel': base_url + 'jquery.mousewheel',
'datetimepicker': base_url + 'jquery.datetimepicker',

}
});

require(['jquery', 'datatables.net'], function ($, DataTable) {
require(['datatables.net'], function (DataTable) {

$.fn.DataTable = DataTable;
$.fn.DataTableSettings = DataTable.settings;
Expand Down Expand Up @@ -50,24 +46,18 @@ $( document ).ready(function() {
// Return row object.
return this;
});
require(['jquery', 'datatables.searchpanes'], function($) {
require(['jquery', 'datatables.select'], function($) {
require(['jquery', 'datatables.buttons'], function($) {
require(['jquery', 'datatables.responsive'], function($) {
if(isMobileDevice() && $(window).width() < 768) {
is_responsive = true;
initDatatable(is_responsive);
require(['datatables.searchpanes', 'datatables.select', 'datatables.buttons', 'datatables.responsive'], function() {
if(isMobileDevice() && $(window).width() < 768) {
is_responsive = true;
initDatatable(is_responsive);

$('.datatabletest').on('order.dt', function(e) {
$('.submissionrowmulti').removeClass("shown");
});
}
else {
initDatatable(is_responsive);
}
});
$('.datatabletest').on('order.dt', function(e) {
$('.submissionrowmulti').removeClass("shown");
});
});
}
else {
initDatatable(is_responsive);
}
});
});

Expand Down
Loading

0 comments on commit 5672a43

Please sign in to comment.