Skip to content

Commit

Permalink
WR422914 JS and visual fixes
Browse files Browse the repository at this point in the history
* Updated JS to ingor selecting already selected elements
* Updated lib function to only return modules that are used on the report
* Clear caches when scheduled task runs to keep in sync
* CSS changes for dropdown items click and hover
* Missing lang string
* Activites in progress filter fixed
  • Loading branch information
SimonThornett committed Oct 28, 2024
1 parent c4b5d62 commit be02015
Show file tree
Hide file tree
Showing 18 changed files with 141 additions and 25 deletions.
11 changes: 11 additions & 0 deletions classes/frequency.php
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,17 @@ public function delete_events(int $duedate): void {
}
}

// Clear the caches to prevent desync between caches and database.
cache::make('local_assessfreq', 'siteevents')->purge();
cache::make('local_assessfreq', 'userevents')->purge();
cache::make('local_assessfreq', 'courseevents')->purge();
cache::make('local_assessfreq', 'eventsduemonth')->purge();
cache::make('local_assessfreq', 'monthlyuser')->purge();
cache::make('local_assessfreq', 'eventsdueactivity')->purge();
cache::make('local_assessfreq', 'yearevents')->purge();
cache::make('local_assessfreq', 'usereventsallfrequencyarray')->purge();
cache::make('local_assessfreq', 'eventusers')->purge();

$transaction->allow_commit();
} catch (Exception $e) {
$transaction->rollback($e);
Expand Down
11 changes: 8 additions & 3 deletions lib.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,19 @@ function get_reports($ignoreenabled = false) : array {
* @param $ignoreenabled
* @return array
*/
function get_sources($ignoreenabled = false) : array {
function get_sources($ignoreenabled = false, $requiredmethod = '') : array {
$sources = [];
$pluginmanager = core_plugin_manager::instance();
foreach ($pluginmanager->get_plugins_of_type('assessfreqsource') as $subplugin) {
if ($subplugin->is_enabled() || $ignoreenabled) {
/* @var $class source_base */
$class = "assessfreqsource_{$subplugin->name}\\source";
$source = $class::get_instance();
if (!empty($requiredmethod)) {
if (!method_exists($source, $requiredmethod)) {
continue;
}
}
$sources[$subplugin->name] = $source;
}
}
Expand Down Expand Up @@ -155,9 +160,9 @@ function get_years($preference) : array {
*
* @return array $modules The enabled modules.
*/
function get_modules($preferences) : array {
function get_modules($preferences, $requiredmethod= '') : array {

$sources = get_sources();
$sources = get_sources(false, $requiredmethod);

// Get modules for filters and load into context.
$modules = [];
Expand Down

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

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ const moduleDropdown = () => {
const tableSearchAheadSet = (event) => {
event.preventDefault();
if (event.target.tagName.toLowerCase() === 'a') {
// Don't process already selected links.
if (event.target.classList.contains('active')) {
return;
}
let hours = event.target.dataset.metric;
UserPreference.setUserPreference('assessfreqreport_activities_in_progress_hoursahead_preference', hours);
// Reload based on selected year.
Expand All @@ -145,6 +149,10 @@ const tableSearchAheadSet = (event) => {
const tableSearchBehindSet = (event) => {
event.preventDefault();
if (event.target.tagName.toLowerCase() === 'a') {
// Don't process already selected links.
if (event.target.classList.contains('active')) {
return;
}
let hours = event.target.dataset.metric;
UserPreference.setUserPreference('assessfreqreport_activities_in_progress_hoursbehind_preference', hours);
// Reload based on selected year.
Expand Down
25 changes: 15 additions & 10 deletions report/activities_in_progress/classes/output/renderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function render_report($data) {
]
);

// upcoming activities starting.
// Upcoming activities starting.
$labels = [];
$seriestitle = get_string('upcomingchart:activities', 'assessfreqreport_activities_in_progress');
$participantseries = get_string('upcomingchart:participants', 'assessfreqreport_activities_in_progress');
Expand Down Expand Up @@ -191,19 +191,18 @@ public function render_report($data) {
8 => 'hours8',
];

$preferencemodule = json_decode(
get_user_preferences('assessfreqreport_activities_in_progress_modules_preference', '["all"]'),
true
);
// Only get modules with the "get_inprogress_count" method as only these display on the report.
$modules = get_modules($preferencemodule, 'get_inprogress_count');

return $this->render_from_template(
'assessfreqreport_activities_in_progress/activities-in-progress',
[
'filters' => [
'modules' => get_modules(
json_decode(
get_user_preferences(
'assessfreqreport_activities_in_progress_modules_preference',
'["all"]'
),
true
)
),
'modules' => $modules,
'hoursahead' => [$hours[$preferencehoursahead] => 'true'],
'hoursbehind' => [$hours[$preferencehoursbehind] => 'true'],
],
Expand Down Expand Up @@ -244,8 +243,14 @@ public function render_activities_inprogress_table(
$hoursbehind = (int)get_user_preferences('assessfreqreport_activities_in_progress_hoursbehind_preference', 1);
$sources = get_sources();
$inprogress = [];
$modulepreference = json_decode(
get_user_preferences('assessfreqreport_activities_in_progress_modules_preference', '["all"]')
);
/* @var $source source_base */
foreach ($sources as $source) {
if (!in_array('all', $modulepreference) && !in_array($source->get_module(), $modulepreference)) {
continue;
}
if (method_exists($source, 'get_inprogress_data')) {
$inprogress[] = $source->get_inprogress_data($now, $hoursahead, $hoursbehind);
}
Expand Down
Loading

0 comments on commit be02015

Please sign in to comment.