Skip to content

Commit

Permalink
Clean up override form
Browse files Browse the repository at this point in the history
  • Loading branch information
bwalkerl committed Feb 27, 2024
1 parent aab0ff8 commit 44ed2ab
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 28 deletions.
24 changes: 1 addition & 23 deletions classes/form/override_form.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ public function definition() {
// Ref.
$mform->addElement('static', 'ref', get_string('check'));
$mform->setConstant('ref', $this->_customdata['ref']);
$mform->hardFreeze('ref');

// Override.
$mform->addElement('select', 'override', get_string('override', 'tool_heartbeat'), [
Expand All @@ -60,39 +59,18 @@ public function definition() {
result::CRITICAL => 'Critical',
result::ERROR => 'Error',
]);
$mform->addRule(
'override',
get_string('overriderequired', 'tool_heartbeat'),
'required',
null,
'client'
);

// Note.
$mform->addElement('textarea', 'note', get_string('notes', 'core_notes'), ['rows' => 3]);
$mform->addRule(
'note',
get_string('noterequired', 'tool_heartbeat'),
'required',
null,
'client'
);
$mform->addRule('note', get_string('noterequired', 'tool_heartbeat'), 'required', null, 'client');

// URL.
$mform->addElement('text', 'url', get_string('url'), ['size' => 80]);
$mform->setType('url', PARAM_URL);

// Override until.
$mform->addElement('date_selector', 'expires_at', get_string('expiresat', 'tool_heartbeat'));
$mform->addRule(
'expires_at',
get_string('muteuntilrequired', 'tool_heartbeat'),
'required',
null,
'client'
);

$this->add_action_buttons();
}

}
2 changes: 0 additions & 2 deletions lang/en/tool_heartbeat.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,7 @@
$string['addmute'] = 'Add mute';
$string['editmute'] = 'Edit mute';
$string['overriderestore'] = 'Fields have been pre-filled with information from a previous override.';
$string['overriderequired'] = 'Please select an status to use while muted';
$string['noterequired'] = 'Please add some notes';
$string['muteuntilrequired'] = 'Please select a date';
$string['settings:mutedefault'] = 'Default mute duration';
$string['settings:mutedefault:desc'] = 'Adjust the default duration of a check mute.';

Expand Down
11 changes: 8 additions & 3 deletions override.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@
$PAGE->set_context(context_system::instance());
$PAGE->set_url(new moodle_url('/admin/tool/heartbeat/override.php', ['ref' => $ref]));

// The URL used for redirection.
$statuspage = new moodle_url('/admin/tool/heartbeat/status.php');

// Attempt to instantiate a persistent object.
$override = override::get_active_override($ref);

Expand All @@ -51,7 +54,7 @@
} catch (Exception $e) {
\core\notification::error($e->getMessage());
}
redirect(new moodle_url('/admin/tool/heartbeat/status.php'));
redirect($statuspage);
}

// Try restoring override.
Expand All @@ -71,7 +74,9 @@
$form = new override_form($PAGE->url->out(false), $customdata);

// Get the data. This ensures that the form was validated.
if ($data = $form->get_data()) {
if ($form->is_cancelled()) {
redirect($statuspage);
} else if ($data = $form->get_data()) {

try {
if (empty($data->id)) {
Expand All @@ -90,7 +95,7 @@
}

// Redirect to heartbeat status page when done.
redirect(new moodle_url('/admin/tool/heartbeat/status.php'));
redirect($statuspage);
}

if ($restored) {
Expand Down

0 comments on commit 44ed2ab

Please sign in to comment.