WIP Issue #17 - Settings page done, missing forms and other references to warning duration and stop time.

This commit is contained in:
Daniel Thee Roperto
2016-09-08 17:25:28 +10:00
parent 07ee61f4f3
commit 4e46e934d0
9 changed files with 56 additions and 26 deletions

View File

@@ -45,7 +45,7 @@ class edit extends \moodleform {
$mform->addElement('date_time_selector', 'starttime', get_string('starttime', 'auth_outage'));
$mform->addElement('date_time_selector', 'stoptime', get_string('stoptime', 'auth_outage'));
$mform->addElement('duration', 'outageduration', get_string('outageduration', 'auth_outage'));
$mform->addElement('duration', 'warningduration', get_string('warningduration', 'auth_outage'));
@@ -59,6 +59,8 @@ class edit extends \moodleform {
$mform->addElement('editor', 'description', get_string('description', 'auth_outage'));
$mform->addElement('static', 'usagehints', '', get_string('textplaceholdershint', 'auth_outage'));
$this->add_action_buttons();
}

View File

@@ -44,9 +44,9 @@ class outage {
public $stoptime = null;
/**
* @var int Amount of minutes before outage starts to show the warning message.
* @var int Warning start timestamp.
*/
public $warningduration = null;
public $warntime = null;
/**
* @var string Short description of the outage (no HTML).
@@ -85,8 +85,8 @@ class outage {
if (is_object($data) || is_array($data)) {
outagelib::data2object($data, $this);
// FIXME types are wrong. Is this behaving as expected?
$fields = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warningduration'];
// Adjust field types as needed.
$fields = ['createdby', 'id', 'lastmodified', 'modifiedby', 'starttime', 'stoptime', 'warntime'];
foreach ($fields as $f) {
$this->$f = ($this->$f === null) ? null : (int)$this->$f;
}

View File

@@ -158,7 +158,7 @@ class outagedb {
// Gets only one record if available, the one that starts(ed) first and that stops last.
$data = $DB->get_records_select(
'auth_outage',
'(starttime - warningduration <= :datetime1 AND stoptime >= :datetime2)',
'(warntime <= :datetime1 AND stoptime >= :datetime2)',
['datetime1' => $time, 'datetime2' => $time],
'starttime ASC, stoptime DESC, title ASC',
'*',

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8" ?>
<XMLDB PATH="auth/outage/db" VERSION="20160825" COMMENT="XMLDB file for Moodle auth/outage"
<XMLDB PATH="auth/outage/db" VERSION="20160908" COMMENT="XMLDB file for Moodle auth/outage"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../lib/xmldb/xmldb.xsd"
>
@@ -9,7 +9,7 @@
<FIELD NAME="id" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="true"/>
<FIELD NAME="starttime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage starts."/>
<FIELD NAME="stoptime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When outage ends."/>
<FIELD NAME="warningduration" TYPE="int" LENGTH="7" NOTNULL="true" SEQUENCE="false" COMMENT="How many seconds before the outage to display a warning to all users."/>
<FIELD NAME="warntime" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="When the outage will start showing a warning for that outage."/>
<FIELD NAME="title" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" COMMENT="Title for the outage (short description)."/>
<FIELD NAME="description" TYPE="text" NOTNULL="true" SEQUENCE="false" COMMENT="More information about the outage."/>
<FIELD NAME="createdby" TYPE="int" LENGTH="10" NOTNULL="true" SEQUENCE="false" COMMENT="Who created this entry."/>

View File

@@ -26,12 +26,17 @@
$string['auth_outagedescription'] = 'Auxiliary plugin that warns users about a future outage and prevents them from logging in once the outage starts.';
$string['defaultlayoutcss'] = 'Layout CSS';
$string['defaultlayoutcssdescription'] = 'This CSS code will be used to display the Outage Warning Bar.';
$string['defaultwarningmessage'] = 'Default Warning Message';
$string['defaultwarningmessagedescription'] = 'Default warning message for outages. Use [from] and [until] placeholders as required.';
$string['defaultwarningmessagevalue'] = 'There is an scheduled maintenance from [from] to [until] and our system will not be available during that time.';
$string['defaultwarningtime'] = 'Default Warning Time';
$string['defaultwarningtimedescription'] = 'Default warning time (in minutes) for outages.';
$string['description'] = 'Public description';
$string['defaultoutageduration'] = 'Outage Duration';
$string['defaultoutagedurationdescription'] = 'Default duration (in minutes) of an outage.';
$string['defaultwarningduration'] = 'Warning Duration';
$string['defaultwarningdurationdescription'] = 'Default warning time (in minutes) for outages.';
$string['defaultwarningtitle'] = 'Title';
$string['defaultwarningtitledescription'] = 'Default title for outages. Use {{start}} and {{stop}} placeholders as required.';
$string['defaultwarningtitlevalue'] = 'System down from {{start}} to {{stop}}.';
$string['defaultwarningdescription'] = 'Description';
$string['defaultwarningdescriptiondescription'] = 'Default warning message for outages. Use {{start}} and {{stop}} placeholders as required.';
$string['defaultwarningdescriptionvalue'] = 'There is an scheduled maintenance from {{start}} to {{stop}} and our system will not be available during that time.';
$string['description'] = 'Public Description';
$string['menudefaults'] = 'Default Settings';
$string['menumanage'] = 'Manage';
$string['messageoutageongoing'] = 'Our system will be under maintenance until {$a->stop}.';
@@ -40,11 +45,12 @@ $string['outageedit'] = 'Edit Outage';
$string['outagecreate'] = 'Create Outage';
$string['outagedelete'] = 'Delete Outage';
$string['outagedeletewarning'] = 'You are about to permanently delete the outage below. This cannot be undone.';
$string['outageduration'] = 'Outage Duration';
$string['outageslist'] = 'Outages List';
$string['pluginname'] = 'Outage manager';
$string['starttime'] = 'Start date and time';
$string['stoptimeerrornotafterstart'] = 'Stop time must be after start time.';
$string['stoptime'] = 'Stop date and time';
$string['textplaceholdershint'] = 'You can use {{start}} and {{stop}} as placeholders on the title/description for the actual start/stop time.';
$string['titleerrorinvalid'] = 'Title cannot be left blank.';
$string['titleerrortoolong'] = 'Title cannot have more than {$a} characters.';
$string['title'] = 'Title';

10
new.php
View File

@@ -43,6 +43,16 @@ if ($mform->is_cancelled()) {
redirect('/auth/outage/manage.php#auth_outage_id_' . $id);
}
$config = get_config('auth_outage');
$defaults = [
'starttime' => time(),
'outageduration' => ($config->default_duration * 60),
'warningduration' => ($config->warning_duration * 60),
'title' => $config->warning_title,
'description' => ['text' => $config->warning_description, 'format' => '1']
];
$mform->set_data($defaults);
$PAGE->navbar->add(get_string('outagecreate', 'auth_outage'));
echo $OUTPUT->header();

View File

@@ -105,7 +105,7 @@ class auth_outage_renderer extends plugin_renderer_base {
. html_writer::tag('i', $outage->description)
. html_writer::empty_tag('br')
. html_writer::tag('b', 'Warning: ')
. userdate($outage->starttime - ($outage->warningduration * 60))
. userdate($outage->warntime, '%d %h %Y %l:%M%P')
. html_writer::empty_tag('br')
. html_writer::tag('b', 'Starts: ')
. userdate($outage->starttime, '%d %h %Y %l:%M%P')

View File

@@ -28,19 +28,31 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
// Configure default settings page.
$settings->visiblename = get_string('menudefaults', 'auth_outage');
$settings->add(
new admin_setting_configtext('auth_outage_warning_period',
get_string('defaultwarningtime', 'auth_outage'),
get_string('defaultwarningtimedescription', 'auth_outage'),
120, PARAM_INT));
new admin_setting_configtext('auth_outage/default_duration',
get_string('defaultoutageduration', 'auth_outage'),
get_string('defaultoutagedurationdescription', 'auth_outage'),
60, PARAM_INT));
$settings->add(
new admin_setting_configtextarea('auth_outage_warning_text',
get_string('defaultwarningmessage', 'auth_outage'),
get_string('defaultwarningmessagedescription', 'auth_outage'),
get_string('defaultwarningmessagevalue', 'auth_outage'),
new admin_setting_configtext('auth_outage/warning_duration',
get_string('defaultwarningduration', 'auth_outage'),
get_string('defaultwarningdurationdescription', 'auth_outage'),
60, PARAM_INT));
$settings->add(
new admin_setting_configtext('auth_outage/warning_title',
get_string('defaultwarningtitle', 'auth_outage'),
get_string('defaultwarningtitledescription', 'auth_outage'),
get_string('defaultwarningtitlevalue', 'auth_outage'),
PARAM_TEXT)
);
$settings->add(
new admin_setting_configtextarea('auth_outage_css',
new admin_setting_configtextarea('auth_outage/warning_description',
get_string('defaultwarningdescription', 'auth_outage'),
get_string('defaultwarningdescriptiondescription', 'auth_outage'),
get_string('defaultwarningdescriptionvalue', 'auth_outage'),
PARAM_TEXT)
);
$settings->add(
new admin_setting_configtextarea('auth_outage/css',
get_string('defaultlayoutcss', 'auth_outage'),
get_string('defaultlayoutcssdescription', 'auth_outage'),
file_get_contents($CFG->dirroot.'/auth/outage/res/default.css'),

View File

@@ -184,7 +184,7 @@ class outagedb_test extends advanced_testcase {
return outagedb::save(new outage([
'starttime' => $now + ($start * 60 * 60),
'stoptime' => $now + ($stop * 60 * 60),
'warningduration' => ($warning * 60 * 60),
'warntime' => $now - ($warning * 60 * 60),
'title' => 'Test Outage',
'description' => 'Test Outage Description.'
]));