Skip to content

Commit

Permalink
Pulse feedback fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
prasanna-lmsace committed Nov 25, 2023
1 parent 2963f45 commit 7f96f45
Show file tree
Hide file tree
Showing 43 changed files with 1,104 additions and 458 deletions.
3 changes: 0 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,3 @@ Thumbs.db
*.mov

*.wmv



325 changes: 167 additions & 158 deletions README.md

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions actions/notification/amd/build/chaptersource.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 actions/notification/amd/build/chaptersource.min.js.map

Large diffs are not rendered by default.

44 changes: 41 additions & 3 deletions actions/notification/amd/src/chaptersource.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/
const previewModalBody = function(contextID, userid = null) {

var params;
if (window.tinyMCE !== undefined) {
if (window.tinyMCE !== undefined && window.tinyMCE.get('id_pulsenotification_headercontent_editor')) {
// EditorPlugin = window.tinyMCE;
params = {
contentheader: window.tinyMCE.get('id_pulsenotification_headercontent_editor').getContent(),
Expand Down Expand Up @@ -130,13 +130,35 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/
}).fail(failure);
},

updateChapter: function() {
updateChapter: function(ctxID, contentMods) {

const SELECTORS = {
chaperType: "#id_pulsenotification_contenttype",
mod: "#id_pulsenotification_dynamiccontent"
};

// Disable the content type option for modules other than book and page.
if (contentMods !== null) {
var type = document.querySelector(SELECTORS.chaperType);
document.querySelector(SELECTORS.mod).addEventListener("change", (e) => {
var target = e.currentTarget;
var selected = target.value;
if (contentMods.includes(selected.toString())) {
Array.prototype.find.call(type.options, function(cmid) {
if (cmid.value == '2') {
cmid.disabled = false;
}
});
} else {
Array.prototype.find.call(type.options, function(cmid) {
if (cmid.value == '2') {
cmid.disabled = true;
}
});
}
});
}

document.querySelector(SELECTORS.chaperType).addEventListener("change", () => resetChapter());
document.querySelector(SELECTORS.mod).addEventListener("change", () => resetChapter());
var chapter = document.querySelector("#id_pulsenotification_chapterid");
Expand All @@ -153,6 +175,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/
},

previewNotification: function(contextid) {

var btn = document.querySelector('[name="pulsenotification_preview"]');

if (btn === null) {
Expand All @@ -166,7 +189,7 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/

reportModal: function(contextID) {
// View content.
var btn = document.querySelectorAll('[data-target="view-content"]');
/* var btn = document.querySelectorAll('[data-target="view-content"]');
if (btn === null) {
return;
Expand All @@ -183,6 +206,21 @@ define(['jquery', 'core/ajax', 'core/notification', 'core/modal_factory', 'core/
notificationModal(contextID, instance, userid); // Notification modal.
});
});
*/

document.addEventListener('click', function(e) {

if (e.target.closest('[data-target="view-content"]') !== null) {

var target = e.target.closest('a');

var instance = target.dataset.instanceid;
var userid = target.dataset.userid;

notificationModal(contextID, instance, userid); // Notification modal.
}

})
}
};

Expand Down
53 changes: 42 additions & 11 deletions actions/notification/classes/actionform.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use mod_pulse\automation\helper;
use pulseaction_notification\notification;
use pulseaction_notification\schedule;
use pulseaction_notification\task\notify_users;

/**
* Notification action form, contains important method and basic plugin details.
Expand Down Expand Up @@ -70,6 +71,23 @@ public function delete_instance_action(int $instanceid) {
return $DB->delete_records($instancetable, ['instanceid' => $instanceid]);
}

/**
* Instances disabled, then disable all the schedules of the instances.
*
* @param stdclass $instancedata
* @param bool $status
* @return void
*/
public function instance_status_updated($instancedata, $status) {
global $DB;

$notificationid = $instancedata->actions['notification']['id'];
$notification = notification::instance($notificationid);
$notification->set_notification_data($instancedata->actions['notification'], $instancedata);

$notification->create_schedule_forinstance();
}

/**
* Prepare editor fileareas.
*
Expand Down Expand Up @@ -154,7 +172,7 @@ public function postupdate_editor_fileareas(&$data, \context $context) {
* Get text editor options to manage files.
*
* @param \stdclass $context
* @return void
* @return array
*/
protected function get_editor_options($context=null) {
global $PAGE;
Expand Down Expand Up @@ -202,10 +220,16 @@ public function delete_template_action($templateid) {
public function trigger_action($instancedata, $userid, $expectedtime=null, $newuser=false) {

$notification = notification::instance($instancedata->pulsenotification_id);
$notificationinstance = helper::filter_record_byprefix($instancedata, $this->config_shortname());
$notificationinstance = (object) helper::filter_record_byprefix($instancedata, $this->config_shortname());

$notification->set_notification_data($notificationinstance, $instancedata);

// Find the suppress conditions are reached.
$course = $instancedata->course;
$suppressreached = notify_users::is_suppress_reached($notificationinstance, $userid, $course, null);
if ($suppressreached) { // Suppress reached not need to setup new schedules.
return '';
}
// Create a schedule for user. This method verify the user activity completion before creating schedules.
$notification->create_schedule_foruser($userid, '', null, $expectedtime ?? null, $newuser);

Expand Down Expand Up @@ -480,7 +504,7 @@ public function load_instance_form(&$mform, $forminstance) {
$completion = new \completion_info(get_course($courseid));
$activities = $completion->get_activities();
array_walk($activities, function(&$value) {
$value = $value->name;
$value = format_string($value->name);
});

$suppress = $mform->createElement('autocomplete', 'pulsenotification_suppress',
Expand All @@ -501,12 +525,18 @@ public function load_instance_form(&$mform, $forminstance) {
$mform->addHelpButton('pulsenotification_suppressoperator', 'suppressoperator', 'pulseaction_notification');

$modules = [0 => get_string('none')];
$books = $modinfo->get_instances_of('book');
$pages = $modinfo->get_instances_of('page');
$list = array_merge($books, $pages);
foreach ($list as $page) {
$modules[$page->id] = $page->get_formatted_name();
$list = $modinfo->get_instances();
$contentmods = [];
foreach ($list as $modname => $mods) {
foreach ($mods as $mod) {
$modules[$mod->id] = $mod->get_formatted_name();
if ($mod->modname == 'page' || $mod->modname == 'book') {
$contentmods[] = $mod->id;
}
}
}
// PAGE modules in this course.
$pages = $modinfo->get_instances_of('page');

$dynamic = $mform->createElement('select', 'pulsenotification_dynamiccontent',
get_string('dynamiccontent', 'pulseaction_notification'), $modules);
Expand All @@ -515,8 +545,9 @@ public function load_instance_form(&$mform, $forminstance) {

// Add 'content_type' element with the following options.
$contenttypeoptions = array(
notification::DYNAMIC_DESCRIPTION => get_string('description', 'pulseaction_notification'),
notification::DYNAMIC_CONTENT => get_string('content', 'pulseaction_notification'),
notification::DYNAMIC_PLACEHOLDER => get_string('dynamicplacholder', 'pulseaction_notification'),
notification::DYNAMIC_DESCRIPTION => get_string('dynamicdescription', 'pulseaction_notification'),
notification::DYNAMIC_CONTENT => get_string('dynamiccontent', 'pulseaction_notification'),
);
$dynamic2 = $mform->createElement('select', 'pulsenotification_contenttype',
get_string('contenttype', 'pulseaction_notification'), $contenttypeoptions);
Expand Down Expand Up @@ -559,7 +590,7 @@ public function load_instance_form(&$mform, $forminstance) {
asort($mform->_elementIndex);

$PAGE->requires->js_call_amd('pulseaction_notification/chaptersource', 'updateChapter',
['contextid' => $PAGE->context->id]
['contextid' => $PAGE->context->id, 'contentmods' => $contentmods]
);
}

Expand Down
25 changes: 17 additions & 8 deletions actions/notification/classes/local/entities/notification.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,15 @@ protected function get_all_columns(): array {
return userdate($value);
});

// Instance id.
$columns[] = (new column(
'instanceid',
new lang_string('instanceid', 'pulseaction_notification'),
$this->get_entity_name()
))
->set_is_sortable(true)
->add_field("{$notificationschalias}.instanceid");

// Message type field.
$columns[] = (new column(
'messagetype',
Expand Down Expand Up @@ -205,16 +214,16 @@ protected function get_all_filters(): array {
$filters[] = (new filter(
text::class,
'automationinstance',
new lang_string('messagetype', 'pulseaction_notification'),
new lang_string('automationinstance', 'pulseaction_notification'),
$this->get_entity_name(),
"IF ({$templatesinsalias}.title <> '', {$templatesinsalias}.title, {$templatesalias}.title)"
"{$templatesinsalias}.title"
));

// Automation template.
$filters[] = (new filter(
text::class,
'automationtemplate',
new lang_string('messagetype', 'pulseaction_notification'),
new lang_string('automationtemplate', 'pulseaction_notification'),
$this->get_entity_name(),
"{$templatesalias}.title"
));
Expand Down Expand Up @@ -298,13 +307,13 @@ public function schedulejoin() {
$notificationalias = $this->get_table_alias('pulseaction_notification');

return "
JOIN {pulse_autoinstances} AS {$autoinstancesalias} ON {$autoinstancesalias}.id = {$notificationschalias}.instanceid
JOIN {pulse_autotemplates} AS {$autotemplatesalias} ON {$autotemplatesalias}.id = {$autoinstancesalias}.templateid
JOIN {pulse_autotemplates_ins} AS {$autotemplatesinsalias}
JOIN {pulse_autoinstances} {$autoinstancesalias} ON {$autoinstancesalias}.id = {$notificationschalias}.instanceid
JOIN {pulse_autotemplates} {$autotemplatesalias} ON {$autotemplatesalias}.id = {$autoinstancesalias}.templateid
JOIN {pulse_autotemplates_ins} {$autotemplatesinsalias}
ON {$autotemplatesinsalias}.instanceid = {$autoinstancesalias}.id
JOIN {pulseaction_notification_ins} AS {$notificationinsalias}
JOIN {pulseaction_notification_ins} {$notificationinsalias}
ON {$notificationinsalias}.instanceid = {$notificationschalias}.instanceid
JOIN {pulseaction_notification} AS {$notificationalias}
JOIN {pulseaction_notification} {$notificationalias}
ON {$notificationalias}.templateid = {$autoinstancesalias}.templateid";
}
}
Loading

0 comments on commit 7f96f45

Please sign in to comment.