Issue #39 - Minor UI changes.

This commit is contained in:
Daniel Thee Roperto
2016-09-19 17:06:16 +10:00
parent 6de4f3b82a
commit 54b72de472
10 changed files with 188 additions and 71 deletions

View File

@@ -168,7 +168,7 @@ class create extends clibase {
$outage = outagedb::get_by_id((int)$id);
$this->set_defaults([
'warn' => $outage->get_warning_duration(),
'duration' => $outage->get_duration(),
'duration' => $outage->get_duration_planned(),
'title' => $outage->title,
'description' => $outage->description,
]);

View File

@@ -134,7 +134,7 @@ class edit extends \moodleform {
$this->_form->setDefaults([
'id' => $outage->id,
'starttime' => $outage->starttime,
'outageduration' => $outage->get_duration(),
'outageduration' => $outage->get_duration_planned(),
'warningduration' => $outage->get_warning_duration(),
'title' => $outage->title,
'description' => ['text' => $outage->description, 'format' => '1']

View File

@@ -207,6 +207,17 @@ class outage {
return $this->replace_placeholders($this->title);
}
/**
* Gets the duration of the outage (start to actual finish, warning not included).
* @return int|null Duration in seconds or null if not finished.
*/
public function get_duration_actual() {
if (is_null($this->finished)) {
return null;
}
return $this->finished - $this->starttime;
}
/**
* Returns the input string with all placeholders replaced.
* @param $str string Input string.
@@ -222,17 +233,17 @@ class outage {
[
userdate($this->starttime, get_string('datetimeformat', 'auth_outage')),
userdate($this->stoptime, get_string('datetimeformat', 'auth_outage')),
format_time($this->get_duration()),
format_time($this->get_duration_planned()),
],
$str
);
}
/**
* Gets the duration of the outage (start to stop, warning not included).
* Gets the planned duration of the outage (start to planned stop, warning not included).
* @return int Duration in seconds.
*/
public function get_duration() {
public function get_duration_planned() {
return $this->stoptime - $this->starttime;
}

View File

@@ -333,7 +333,7 @@ class outagedb {
'eventtype' => 'auth_outage',
'timestart' => $outage->starttime,
'visible' => true,
'timeduration' => $outage->get_duration(),
'timeduration' => $outage->get_duration_planned(),
];
}

View File

@@ -0,0 +1,80 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage\tables\manage;
use auth_outage\models\outage;
use html_writer;
use moodle_url;
require_once($CFG->libdir . '/tablelib.php');
/**
* Manage outages table.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class history extends managebase {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->define_columns(['warning', 'starts', 'durationplanned', 'durationactual', 'title', 'actions']);
$this->define_headers([
get_string('tableheaderwarnbefore', 'auth_outage'),
get_string('tableheaderstarttime', 'auth_outage'),
get_string('tableheaderdurationplanned', 'auth_outage'),
get_string('tableheaderdurationactual', 'auth_outage'),
get_string('tableheadertitle', 'auth_outage'),
get_string('actions'),
]
);
$this->setup();
}
/**
* Sets the data of the table.
* @param outage[] $outages An array with outage objects.
*/
public function set_data(array $outages) {
foreach ($outages as $outage) {
$title = html_writer::link(
new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
$outage->get_title(),
['title' => get_string('edit')]
);
$finished = $outage->get_duration_actual();
$finished = is_null($finished) ? '-' : format_time($finished);
$this->add_data([
format_time($outage->get_warning_duration()),
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
format_time($outage->get_duration_planned()),
$finished,
$title,
$this->set_data_buttons($outage, false),
]);
}
}
}

View File

@@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage\tables;
namespace auth_outage\tables\manage;
use auth_outage\models\outage;
use flexible_table;
@@ -24,14 +24,14 @@ use moodle_url;
require_once($CFG->libdir . '/tablelib.php');
/**
* Manage outages table.
* Manage outages table base.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class manage extends flexible_table {
class managebase extends flexible_table {
private static $autoid = 0;
/**
@@ -44,55 +44,8 @@ class manage extends flexible_table {
$id = (is_null($id) ? self::$autoid++ : $id);
parent::__construct('auth_outage_manage_' . $id);
$this->define_columns(['starttime', 'stopsafter', 'warnbefore', 'finished', 'title', '']);
$this->define_headers([
get_string('tableheaderwarnbefore', 'auth_outage'),
get_string('tableheaderstarttime', 'auth_outage'),
get_string('tableheaderstopsafter', 'auth_outage'),
get_string('tableheaderfinishedat', 'auth_outage'),
get_string('tableheadertitle', 'auth_outage'),
get_string('actions'),
]
);
$this->define_baseurl($PAGE->url);
$this->set_attribute('class', 'generaltable admintable');
$this->setup();
}
/**
* Sets the data of the table.
* @param outage[] $outages An array with outage objects.
* @param bool $editdelete If it should display the edit and delete button.
*/
public function set_data(array $outages, $editdelete) {
if (!is_bool($editdelete)) {
throw new \InvalidArgumentException('$editdelete must be a bool.');
}
foreach ($outages as $outage) {
$title = $outage->get_title();
if ($editdelete) {
$title = html_writer::link(
new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]),
$title,
['title' => get_string('edit')]
);
}
$finished = $outage->finished;
$finished = is_null($finished) ? '-' : userdate($finished, get_string('datetimeformat', 'auth_outage'));
$this->add_data([
format_time($outage->get_warning_duration()),
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
format_time($outage->get_duration()),
$finished,
$title,
$this->set_data_buttons($outage, $editdelete),
]);
}
}
/**
@@ -101,7 +54,7 @@ class manage extends flexible_table {
* @param bool $editdelete If it should display the edit and delete button.
* @return string The HTML code of the action buttons.
*/
private function set_data_buttons(outage $outage, $editdelete) {
protected function set_data_buttons(outage $outage, $editdelete) {
global $OUTPUT;
$buttons = '';
@@ -171,6 +124,6 @@ class manage extends flexible_table {
);
}
return $buttons;
return '<nobr>' . $buttons . '</nobr>';
}
}

View File

@@ -0,0 +1,67 @@
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
namespace auth_outage\tables\manage;
use auth_outage\models\outage;
require_once($CFG->libdir . '/tablelib.php');
/**
* Manage outages table.
*
* @package auth_outage
* @author Daniel Thee Roperto <danielroperto@catalyst-au.net>
* @copyright Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class planned extends managebase {
/**
* Constructor
*/
public function __construct() {
parent::__construct();
$this->define_columns(['warning', 'starts', 'duration', 'title', 'actions']);
$this->define_headers([
get_string('tableheaderwarnbefore', 'auth_outage'),
get_string('tableheaderstarttime', 'auth_outage'),
get_string('tableheaderduration', 'auth_outage'),
get_string('tableheadertitle', 'auth_outage'),
get_string('actions'),
]
);
$this->setup();
}
/**
* Sets the data of the table.
* @param outage[] $outages An array with outage objects.
*/
public function set_data(array $outages) {
foreach ($outages as $outage) {
$this->add_data([
format_time($outage->get_warning_duration()),
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage')),
format_time($outage->get_duration_planned()),
$outage->get_title(),
$this->set_data_buttons($outage, true),
]);
}
}
}

View File

@@ -98,9 +98,10 @@ $string['outageslistpast'] = 'Outage history';
$string['pluginname'] = 'Outage manager';
$string['starttime'] = 'Start date and time';
$string['starttime_help'] = 'At which date and time the outage starts, preventing general access to the system.';
$string['tableheaderfinishedat'] = 'Finished at';
$string['tableheaderduration'] = 'Duration';
$string['tableheaderdurationplanned'] = 'Planned Duration';
$string['tableheaderdurationactual'] = 'Actual Duration';
$string['tableheaderstarttime'] = 'Starts on';
$string['tableheaderstopsafter'] = 'Stops after';
$string['tableheaderwarnbefore'] = 'Warns before';
$string['tableheadertitle'] = 'Title';
$string['textplaceholdershint'] = 'You can use {{start}}, {{stop}} and {{duration}} as placeholders on the title and description.';

View File

@@ -15,6 +15,7 @@
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\models\outage;
use auth_outage\tables\manage\planned;
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
@@ -87,8 +88,8 @@ class auth_outage_renderer extends plugin_renderer_base {
if (empty($future)) {
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
} else {
$table = new \auth_outage\tables\manage();
$table->set_data($future, true);
$table = new planned();
$table->set_data($future);
$table->finish_output();
}
@@ -96,8 +97,8 @@ class auth_outage_renderer extends plugin_renderer_base {
if (empty($past)) {
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
} else {
$table = new \auth_outage\tables\manage();
$table->set_data($past, false);
$table = new \auth_outage\tables\manage\history();
$table->set_data($past);
$table->finish_output();
}
}
@@ -146,7 +147,11 @@ class auth_outage_renderer extends plugin_renderer_base {
$linkdelete = html_writer::link($url, $img, ['title' => get_string('delete')]);
$finished = $outage->finished;
$finished = is_null($finished) ? '-' : userdate($finished, get_string('datetimeformat', 'auth_outage'));
if (is_null($finished)) {
$finished = get_string('na', 'auth_outage');
} else {
$finished = userdate($finished, get_string('datetimeformat', 'auth_outage'));
}
return html_writer::div(
html_writer::tag('blockquote',
@@ -161,11 +166,11 @@ class auth_outage_renderer extends plugin_renderer_base {
. userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
)
. html_writer::div(
html_writer::tag('b', get_string('tableheaderstopsafter', 'auth_outage') . ': ')
. format_time($outage->get_duration())
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage') . ': ')
. format_time($outage->get_duration_planned())
)
. html_writer::div(
html_writer::tag('b', get_string('tableheaderfinishedat', 'auth_outage') . ': ')
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage') . ': ')
. $finished
)
. html_writer::div(
@@ -201,7 +206,7 @@ class auth_outage_renderer extends plugin_renderer_base {
'startofwarning' => -$outage->get_warning_duration(),
'15secondsbefore' => -15,
'start' => 0,
'endofoutage' => $outage->get_duration(),
'endofoutage' => $outage->get_duration_planned(),
] as $title => $delta) {
$adminlinks[] = html_writer::link(
new moodle_url(

View File

@@ -148,7 +148,7 @@ class create_test extends cli_testcase {
$outage = outagedb::get_by_id($id);
self::assertSame($now, $outage->starttime);
self::assertSame(10, $outage->get_warning_duration());
self::assertSame(30, $outage->get_duration());
self::assertSame(30, $outage->get_duration_planned());
self::assertNull($outage->finished);
self::assertSame('A Title', $outage->title);
self::assertSame('A Description', $outage->description);
@@ -235,7 +235,7 @@ class create_test extends cli_testcase {
$cloned = outagedb::get_by_id((int)$id);
self::assertSame($now + 60, $cloned->starttime);
self::assertSame($original->get_warning_duration(), $cloned->get_warning_duration());
self::assertSame($original->get_duration(), $cloned->get_duration());
self::assertSame($original->get_duration_planned(), $cloned->get_duration_planned());
self::assertSame($original->title, $cloned->title);
self::assertSame($original->description, $cloned->description);
}