Issue #32 - UX improvements, detect end of outage and show in warning bar. Does not redirect user to info page anymore.

This commit is contained in:
Daniel Thee Roperto
2016-09-23 15:53:28 +10:00
parent 80ed7b69ad
commit ded6b2d005
16 changed files with 598 additions and 377 deletions

32
checkfinished.php Normal file
View File

@@ -0,0 +1,32 @@
<?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/>.
/**
* Called async from warning bar to check if the outage has finished.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\dml\outagedb;
require_once(__DIR__.'/../../config.php');
$active = outagedb::get_active();
echo $active ? 'ongoing' : 'finished';

View File

@@ -19,6 +19,7 @@ namespace auth_outage\local\controllers;
use auth_outage\dml\outagedb;
use auth_outage\local\outage;
use auth_outage\local\outagelib;
use auth_outage\output\renderer;
use coding_exception;
use context_system;
use file_exception;
@@ -186,9 +187,15 @@ class infopage {
}
}
$viewbag = [
'admin' => is_siteadmin(),
'outage' => $this->outage,
];
$PAGE->set_context(context_system::instance());
if ($this->static) {
require($CFG->dirroot.'/auth/outage/views/info/static.php');
$viewbag['admin'] = false;
renderer::get()->output_view('info/static.php', $viewbag);
} else {
$PAGE->set_title($this->outage->get_title());
$PAGE->set_heading($this->outage->get_title());

View File

@@ -18,7 +18,7 @@ namespace auth_outage\local;
use auth_outage\dml\outagedb;
use auth_outage\local\controllers\infopage;
use auth_outage_renderer;
use auth_outage\output\renderer;
use Exception;
use moodle_url;
use stdClass;
@@ -38,22 +38,13 @@ class outagelib {
/**
* Initializes admin pages for outage.
* @return auth_outage_renderer The outage renderer for the page.
* @return renderer The outage renderer for the page.
*/
public static function page_setup() {
global $PAGE;
admin_externalpage_setup('auth_outage_manage');
$PAGE->set_url(new moodle_url('/auth/outage/manage.php'));
return self::get_renderer();
}
/**
* Returns the outage renderer.
* @return auth_outage_renderer The outage renderer.
*/
public static function get_renderer() {
global $PAGE;
return $PAGE->get_renderer('auth_outage');
return renderer::get();
}
/**
@@ -74,9 +65,10 @@ class outagelib {
$previewid = optional_param('auth_outage_preview', null, PARAM_INT);
$time = time();
if (is_null($previewid)) {
if (!$active = outagedb::get_active()) {
if (!$active = outagedb::get_active($time)) {
return;
}
$preview = false;
} else {
if (!$active = outagedb::get_by_id($previewid)) {
return;
@@ -86,10 +78,11 @@ class outagelib {
if (!$active->is_active($time)) {
return;
}
$preview = true;
}
// There is a previewing or active outage.
$CFG->additionalhtmltopofbody = self::get_renderer()->renderoutagebar($active, $time).
$CFG->additionalhtmltopofbody = renderer::get()->render_warningbar($active, $time, false, $preview).
$CFG->additionalhtmltopofbody;
} catch (Exception $e) {
debugging('Exception occured while injecting our code: '.$e->getMessage());
@@ -119,7 +112,7 @@ class outagelib {
'default_warning_duration' => 60,
'default_warning_title' => get_string('defaultwarningtitlevalue', 'auth_outage'),
'default_warning_description' => get_string('defaultwarningdescriptionvalue', 'auth_outage'),
'css' => file_get_contents($CFG->dirroot.'/auth/outage/views/warningbar.css'),
'css' => file_get_contents($CFG->dirroot.'/auth/outage/views/warningbar/warningbar.css'),
];
}

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\local\output\manage;
namespace auth_outage\output\manage;
use auth_outage\local\outage;
use flexible_table;

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\local\output\manage;
namespace auth_outage\output\manage;
use auth_outage\local\outage;

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\local\output\manage;
namespace auth_outage\output\manage;
use auth_outage\local\outage;
use html_writer;

263
classes/output/renderer.php Normal file
View File

@@ -0,0 +1,263 @@
<?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\output;
use auth_outage\local\outage;
use auth_outage\output\manage\history_table;
use auth_outage\output\manage\planned_table;
use coding_exception;
use html_writer;
use moodle_url;
use plugin_renderer_base;
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage auth_outage_renderer
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class renderer extends plugin_renderer_base {
/**
* Returns the outage renderer.
* @return renderer The outage renderer.
*/
public static function get() {
global $PAGE;
return $PAGE->get_renderer('auth_outage');
}
/**
* Outputs the view in a separate scope to avoid conflicts with variable names.
* @param string $view View PHP file.
* @param mixed[] $viewbag Values to be used in the view.
* @throws coding_exception
*/
public function output_view($view, $viewbag = []) {
global $CFG;
$viewbag['viewfile'] = $view;
unset($view);
require($CFG->dirroot.'/auth/outage/views/'.$viewbag['viewfile']);
}
/**
* Renders the view in a separate scope to avoid conflicts with variable names.
* @param string $view View PHP file.
* @param mixed[] $viewbag Values to be used in the view.
* @return string The rendered view code.
*/
public function render_view($view, $viewbag = []) {
ob_start();
$this->output_view($view, $viewbag);
$html = ob_get_contents();
ob_end_clean();
return $html;
}
/**
* Renders the subtitle of the page.
* @param string $subtitlekey Key to be used and localized.
* @return string HTML for the subtitle.
* @throws coding_exception
*/
public function rendersubtitle($subtitlekey) {
if (!is_string($subtitlekey)) {
throw new coding_exception('$subtitlekeym is not a string.', $subtitlekey);
}
return html_writer::tag('h2', get_string($subtitlekey, 'auth_outage'));
}
/**
* Renders a confirmation to delete an outage.
* @param outage $outage Outage to be deleted.
* @return string HTML for the page.
*/
public function renderdeleteconfirmation(outage $outage) {
return $this->rendersubtitle('outagedelete').
html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage')).
$this->renderoutage($outage, false);
}
/**
* Renders a confirmation to finish an outage.
* @param outage $outage Outage to be finished.
* @return string HTML for the page.
*/
public function renderfinishconfirmation(outage $outage) {
return $this->rendersubtitle('outagefinish').
html_writer::tag('p', get_string('outagefinishwarning', 'auth_outage')).
$this->renderoutage($outage, false);
}
/**
* Outputs the HTML data listing all given outages.
* @param outage[] $future Outages to list as planned.
* @param outage[] $past Outages to list as history.
*/
public function renderoutagelist(array $future, array $past) {
global $OUTPUT;
// Add 'add' button.
$url = new moodle_url('/auth/outage/new.php');
$img = html_writer::empty_tag('img',
['src' => $OUTPUT->pix_url('t/add'), 'alt' => get_string('create'), 'class' => 'iconsmall']);
echo html_writer::tag('p',
html_writer::link(
$url,
$img.' '.get_string('outagecreate', 'auth_outage'),
['title' => get_string('delete')]
)
);
echo $this->rendersubtitle('outageslistfuture');
if (empty($future)) {
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
} else {
$table = new planned_table();
$table->set_data($future);
$table->finish_output();
}
echo $this->rendersubtitle('outageslistpast');
if (empty($past)) {
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
} else {
$table = new history_table();
$table->set_data($past);
$table->finish_output();
}
}
/**
* Renders the warning bar.
* @param outage $outage The outage to show in the warning bar.
* @param int $time Timestamp to send to the outage bar in order to render the outage.
* @param bool $static If the warning bar is rendering in a static page.
* @param bool $preview If in preview mode the warning bar will not check if we are back online.
* @return string HTML of the warning bar.
* @throws coding_exception
* @SuppressWarnings("unused") because $viewbag is used inside require()
*/
public function render_warningbar(outage $outage, $time, $static, $preview) {
global $CFG;
if (!is_int($time) || ($time <= 0)) {
throw new coding_exception('$time is not an positive int or null.', $time);
}
if (!is_bool($static)) {
throw new coding_exception('$static is not a bool.');
}
if (!is_bool($preview)) {
throw new coding_exception('$preview is not a bool.');
}
$viewbag = [
'time' => $time,
'outage' => $outage,
'static' => $static,
'preview' => $preview,
];
return $this->render_view('warningbar/warningbar.php', $viewbag);
}
/**
* Returns the HTML for displaying and outage information.
* @param outage $outage Outage to display.
* @param bool $buttons If should display management buttons (edit, delete, etc).
* @return string The formatted HTML.
*/
private function renderoutage(outage $outage, $buttons) {
global $OUTPUT;
if ($outage->createdby == 0) {
$created = get_string('na', 'auth_outage');
} else {
$created = core_user::get_user($outage->createdby, 'firstname,lastname', MUST_EXIST);
$created = html_writer::link(
new moodle_url('/user/profile.php', ['id' => $outage->createdby]),
trim($created->firstname.' '.$created->lastname)
);
}
if ($outage->modifiedby == 0) {
$modified = get_string('na', 'auth_outage');
} else {
$modified = core_user::get_user($outage->modifiedby, 'firstname,lastname', MUST_EXIST);
$modified = html_writer::link(
new moodle_url('/user/profile.php', ['id' => $outage->modifiedby]),
trim($modified->firstname.' '.$modified->lastname)
);
}
$url = new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]);
$img = html_writer::empty_tag(
'img',
['src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
);
$linkedit = html_writer::link($url, $img, ['title' => get_string('edit')]);
$url = new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]);
$img = html_writer::empty_tag(
'img',
['src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall']
);
$linkdelete = html_writer::link($url, $img, ['title' => get_string('delete')]);
$finished = $outage->finished;
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',
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id])).
html_writer::div(html_writer::tag('i', $outage->get_description())).
html_writer::div(
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage').': ').
format_time($outage->get_warning_duration())
).
html_writer::div(
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage').': ').
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
).
html_writer::div(
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage').': ').
format_time($outage->get_duration_planned())
).
html_writer::div(
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage').': ').
$finished
).
html_writer::div(
html_writer::tag('small',
'Created by '.$created.
', modified by '.$modified.' on '.
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
)
).
($buttons ? html_writer::div($linkedit.$linkdelete) : '')
)
);
}
}

View File

@@ -83,6 +83,8 @@ $string['infostartofwarning'] = 'start of warning';
$string['infopagestaticgenerated'] = 'This warning was generated on {$a->time}.';
$string['menudefaults'] = 'Default Settings';
$string['menumanage'] = 'Manage';
$string['messageoutagebackonline'] = 'We are back online!';
$string['messageoutagebackonlinedescription'] = 'You may resume browsing safely.';
$string['messageoutageongoing'] = 'Back online at {$a->stop}.';
$string['messageoutagewarning'] = 'Shutting down in {{countdown}}';
$string['na'] = 'n/a';

View File

@@ -14,206 +14,16 @@
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
use auth_outage\local\outage;
use auth_outage\local\output\manage\history_table;
use auth_outage\local\output\manage\planned_table;
defined('MOODLE_INTERNAL') || die();
/**
* auth_outage auth_outage_renderer
* auth_outage auth_outage_renderer should just extend our renderer class in the classes directory.
* This is done to keep code organized and make easier to run tests and check coverage.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
class auth_outage_renderer extends plugin_renderer_base {
/**
* Renders the subtitle of the page.
* @param string $subtitlekey Key to be used and localized.
* @return string HTML for the subtitle.
*/
public function rendersubtitle($subtitlekey) {
if (!is_string($subtitlekey)) {
throw new coding_exception('$subtitlekeym is not a string.', $subtitlekey);
}
return html_writer::tag('h2', get_string($subtitlekey, 'auth_outage'));
}
/**
* Renders a confirmation to delete an outage.
* @param outage $outage Outage to be deleted.
* @return string HTML for the page.
*/
public function renderdeleteconfirmation(outage $outage) {
return $this->rendersubtitle('outagedelete').
html_writer::tag('p', get_string('outagedeletewarning', 'auth_outage')).
$this->renderoutage($outage, false);
}
/**
* Renders a confirmation to finish an outage.
* @param outage $outage Outage to be finished.
* @return string HTML for the page.
*/
public function renderfinishconfirmation(outage $outage) {
return $this->rendersubtitle('outagefinish').
html_writer::tag('p', get_string('outagefinishwarning', 'auth_outage')).
$this->renderoutage($outage, false);
}
/**
* Outputs the HTML data listing all given outages.
* @param outage[] $future Outages to list as planned.
* @param outage[] $past Outages to list as history.
*/
public function renderoutagelist(array $future, array $past) {
global $OUTPUT;
// Add 'add' button.
$url = new moodle_url('/auth/outage/new.php');
$img = html_writer::empty_tag('img',
['src' => $OUTPUT->pix_url('t/add'), 'alt' => get_string('create'), 'class' => 'iconsmall']);
echo html_writer::tag('p',
html_writer::link(
$url,
$img.' '.get_string('outagecreate', 'auth_outage'),
['title' => get_string('delete')]
)
);
echo $this->rendersubtitle('outageslistfuture');
if (empty($future)) {
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
} else {
$table = new planned_table();
$table->set_data($future);
$table->finish_output();
}
echo $this->rendersubtitle('outageslistpast');
if (empty($past)) {
echo html_writer::tag('p', html_writer::tag('small', get_string('notfound', 'auth_outage')));
} else {
$table = new history_table();
$table->set_data($past);
$table->finish_output();
}
}
/**
* Renders the warning bar.
* @param outage $outage The outage to show in the warning bar.
* @param int|null $time Timestamp to send to the outage bar in order to render the outage. Null for current time.
* @return string HTML of the warning bar.
* @SuppressWarnings("unused") because $countdown is used inside require()
*/
public function renderoutagebar(outage $outage, $time = null) {
global $CFG;
if (is_null($time)) {
$time = time();
}
if (!is_int($time) || ($time <= 0)) {
throw new coding_exception('$time is not an positive int or null.', $time);
}
$start = userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'));
$stop = userdate($outage->stoptime, get_string('datetimeformat', 'auth_outage'));
$countdown = get_string(
$outage->is_ongoing($time) ? 'messageoutageongoing' : 'messageoutagewarning',
'auth_outage',
['start' => $start, 'stop' => $stop]
);
ob_start();
require($CFG->dirroot.'/auth/outage/views/warningbar.php');
$html = ob_get_contents();
ob_end_clean();
return $html;
}
/**
* Returns the HTML for displaying and outage information.
* @param outage $outage Outage to display.
* @param bool $buttons If should display management buttons (edit, delete, etc).
* @return string The formatted HTML.
*/
private function renderoutage(outage $outage, $buttons) {
global $OUTPUT;
if ($outage->createdby == 0) {
$created = get_string('na', 'auth_outage');
} else {
$created = core_user::get_user($outage->createdby, 'firstname,lastname', MUST_EXIST);
$created = html_writer::link(
new moodle_url('/user/profile.php', ['id' => $outage->createdby]),
trim($created->firstname.' '.$created->lastname)
);
}
if ($outage->modifiedby == 0) {
$modified = get_string('na', 'auth_outage');
} else {
$modified = core_user::get_user($outage->modifiedby, 'firstname,lastname', MUST_EXIST);
$modified = html_writer::link(
new moodle_url('/user/profile.php', ['id' => $outage->modifiedby]),
trim($modified->firstname.' '.$modified->lastname)
);
}
$url = new moodle_url('/auth/outage/edit.php', ['id' => $outage->id]);
$img = html_writer::empty_tag(
'img',
['src' => $OUTPUT->pix_url('t/edit'), 'alt' => get_string('edit'), 'class' => 'iconsmall']
);
$linkedit = html_writer::link($url, $img, ['title' => get_string('edit')]);
$url = new moodle_url('/auth/outage/delete.php', ['id' => $outage->id]);
$img = html_writer::empty_tag(
'img',
['src' => $OUTPUT->pix_url('t/delete'), 'alt' => get_string('delete'), 'class' => 'iconsmall']
);
$linkdelete = html_writer::link($url, $img, ['title' => get_string('delete')]);
$finished = $outage->finished;
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',
html_writer::div(html_writer::tag('b', $outage->get_title(), ['data-id' => $outage->id])).
html_writer::div(html_writer::tag('i', $outage->get_description())).
html_writer::div(
html_writer::tag('b', get_string('tableheaderwarnbefore', 'auth_outage').': ').
format_time($outage->get_warning_duration())
).
html_writer::div(
html_writer::tag('b', get_string('tableheaderstarttime', 'auth_outage').': ').
userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'))
).
html_writer::div(
html_writer::tag('b', get_string('tableheaderdurationplanned', 'auth_outage').': ').
format_time($outage->get_duration_planned())
).
html_writer::div(
html_writer::tag('b', get_string('tableheaderdurationactual', 'auth_outage').': ').
$finished
).
html_writer::div(
html_writer::tag('small',
'Created by '.$created.
', modified by '.$modified.' on '.
userdate($outage->lastmodified, get_string('datetimeformat', 'auth_outage'))
)
).
($buttons ? html_writer::div($linkedit.$linkdelete) : '')
)
);
}
class auth_outage_renderer extends auth_outage\output\renderer {
}

View File

@@ -25,20 +25,20 @@
defined('MOODLE_INTERNAL') || die();
if ($this->has_admin_options()) {
if ($viewbag['admin']) {
$adminlinks = [];
foreach ([
'startofwarning' => -$this->outage->get_warning_duration(),
'startofwarning' => -$viewbag['outage']->get_warning_duration(),
'15secondsbefore' => -15,
'start' => 0,
'endofoutage' => $this->outage->get_duration_planned(),
'endofoutage' => $viewbag['outage']->get_duration_planned() - 1,
] as $title => $delta) {
$adminlinks[] = html_writer::link(
new moodle_url(
'/auth/outage/info.php',
[
'id' => $this->outage->id,
'auth_outage_preview' => $this->outage->id,
'id' => $viewbag['outage']->id,
'auth_outage_preview' => $viewbag['outage']->id,
'auth_outage_delta' => $delta,
]
),
@@ -47,7 +47,7 @@ if ($this->has_admin_options()) {
}
$admineditlink = html_writer::link(
new moodle_url('/auth/outage/edit.php', ['id' => $this->outage->id]),
new moodle_url('/auth/outage/edit.php', ['id' => $viewbag['outage']->id]),
get_string('outageedit', 'auth_outage')
);
}
@@ -57,15 +57,15 @@ if ($this->has_admin_options()) {
<div>
<b><?php echo get_string('infofrom', 'auth_outage'); ?></b>
<?php echo userdate($this->outage->starttime, get_string('datetimeformat', 'auth_outage')); ?>
<?php echo userdate($viewbag['outage']->starttime, get_string('datetimeformat', 'auth_outage')); ?>
</div>
<div>
<b><?php echo get_string('infountil', 'auth_outage'); ?></b>
<?php echo userdate($this->outage->stoptime, get_string('datetimeformat', 'auth_outage')); ?>
<?php echo userdate($viewbag['outage']->stoptime, get_string('datetimeformat', 'auth_outage')); ?>
</div>
<div class="auth_outage_info_description"><?php echo $this->outage->get_description(); ?></div>
<div class="auth_outage_info_description"><?php echo $viewbag['outage']->get_description(); ?></div>
<?php if ($this->has_admin_options()): ?>
<?php if ($viewbag['admin']): ?>
<div class="auth_outage_info_adminlinks">
<b><?php echo get_string('preview'); ?>:</b>
<?php echo implode(' | ', $adminlinks); ?><br/>

View File

@@ -23,14 +23,19 @@
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\output\renderer;
defined('MOODLE_INTERNAL') || die();
global $SITE;
// The Meta Refresh will ensure the page keeps refreshing every 5 minutes until outage is over.
?>
<!DOCTYPE html>
<html data-outage-id="<?php echo $this->outage->id; ?>">
<html data-outage-id="<?php echo $viewbag['outage']->id; ?>">
<head>
<title><?php echo strip_tags($SITE->fullname); ?></title>
<meta http-equiv="refresh" content="<?php echo (5 * 60); ?>">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
@@ -42,12 +47,8 @@ global $SITE;
<body>
<?php
// TODO refactor warning bar to not require this.
// The static page always shows as if outage has started.
$outage = $this->outage;
$static = true;
require($CFG->dirroot.'/auth/outage/views/warningbar.php');
// Static page is rendered as if outage started. It is never rendered as admin or preview mode.
echo renderer::get()->render_warningbar($viewbag['outage'], $viewbag['outage']->starttime, false, false);
?>
<header>
@@ -55,8 +56,8 @@ require($CFG->dirroot.'/auth/outage/views/warningbar.php');
</header>
<section>
<h2><?php echo $this->outage->get_title(); ?></h2>
<?php require(__DIR__.'/content.php'); ?>
<h2><?php echo $viewbag['outage']->get_title(); ?></h2>
<?php echo renderer::get()->render_view('info/content.php', $viewbag); ?>
</section>
<!-- <?php echo

View File

@@ -1,51 +0,0 @@
var auth_outage_countdown = {
timer: 0,
clienttime: Date.now(),
siteadmin: false,
init: function (countdown, siteadmin, redirectto) {
this.countdown = countdown;
this.siteadmin = siteadmin;
this.redirectto = redirectto;
this.divtext = document.getElementById('auth_outage_warningbar_countdown');
this.divblock = document.getElementById('auth_outage_warningbar_box');
this.text = this.divtext.innerHTML;
var $this = this;
this.timer = setInterval(function () {
$this.tick();
}, 1000);
this.tick();
},
tick: function () {
var elapsed = Math.round((Date.now() - this.clienttime) / 1000);
var missing = this.countdown - elapsed;
if (!this.siteadmin && (missing === 10)) {
this.divblock.className += ' imminent';
this.divblock.style.height = window.innerHeight + 'px';
}
if (missing <= 0) {
missing = 0;
clearInterval(this.timer);
if (!this.siteadmin) {
window.location = this.redirectto;
}
}
this.divtext.innerHTML = this.text.replace('{{countdown}}', this.seconds2hms(missing));
},
seconds2hms: function (seconds) {
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
seconds %= 60;
minutes %= 60;
// Cross-browser simple solution for padding zeroes.
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
return hours + ':' + minutes + ':' + seconds;
}
};
// auth_outage_countdown is used outside this js file.
/* jshint unused:false */

View File

@@ -1,91 +0,0 @@
<?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/>.
/**
* View included by the renderer to output the outage warning bar.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die();
global $OUTPUT;
if (!isset($static)) {
$static = false;
}
if ($static) {
$start = userdate($outage->starttime, get_string('datetimeformat', 'auth_outage'));
$stop = userdate($outage->stoptime, get_string('datetimeformat', 'auth_outage'));
$countdown = get_string('messageoutageongoing', 'auth_outage', ['start' => $start, 'stop' => $stop]);
} else {
$infolink = new moodle_url('/auth/outage/info.php', ['id' => $outage->id]);
}
echo html_writer::tag('style', outagelib::get_config()->css);
?>
<div id="auth_outage_warningbar_box">
<div class="auth_outage_warningbar_center">
<div id="auth_outage_warningbar_countdown"><?php echo $countdown; ?></div>
<div>
<?php
if ($static) {
echo $outage->get_title();
} else {
echo html_writer::link(
$infolink,
$outage->get_title(),
['target' => '_blank', 'class' => 'auth_outage_warningbar_box_title']
);
}
if (!$static && is_siteadmin() && $outage->is_ongoing()) {
$url = new moodle_url('/auth/outage/finish.php', ['id' => $outage->id]);
$text = html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/check'),
'alt' => get_string('finish', 'auth_outage'),
'class' => 'iconsmall',
]).' '.get_string('finish', 'auth_outage');
$attr = [
'title' => get_string('finish', 'auth_outage'),
'class' => 'auth_outage_warningbar_box_finish',
];
echo html_writer::link($url, $text, $attr);
}
?>
</div>
</div>
</div>
<?php if (!$static && !$outage->is_ongoing($time)): ?>
<script>
<?php require($CFG->dirroot.'/auth/outage/views/warningbar.js'); ?>
auth_outage_countdown.init(
<?php echo($outage->starttime - $time); ?>,
<?php echo(is_siteadmin() ? 'true' : 'false'); ?>,
'<?php echo $infolink; ?>'
);
</script>
<?php endif; ?>
<div class="auth_outage_warningbar_spacer">&nbsp;</div>

View File

@@ -13,13 +13,53 @@ If you need to make changes here, remember to update your settings inside Moodle
position: fixed;
text-align: center;
top: 0;
transition: height 10s linear;
transition: background 3s ease-out;
width: 100%;
z-index: 9999;
}
#auth_outage_warningbar_box.imminent {
background: purple;
#auth_outage_warningbar_box.auth_outage_warning_period {
background: repeating-linear-gradient(
-45deg,
#ff7c00,
#ff7c00 10px,
#ff6c00 10px,
#ff6c00 20px
);
background-color: #ff7c00;
}
#auth_outage_warningbar_box.auth_outage_imminent_period {
background: repeating-linear-gradient(
-45deg,
#a000a0,
#a000a0 10px,
#800080 10px,
#800080 20px
);
background-color: #800080;
}
#auth_outage_warningbar_box.auth_outage_ongoing_period {
background: repeating-linear-gradient(
-45deg,
#ee0000,
#ee0000 10px,
#cc0000 10px,
#cc0000 20px
);
background-color: #ee0000;
}
#auth_outage_warningbar_box.auth_outage_finished_period {
background: repeating-linear-gradient(
-45deg,
#00aa00,
#00aa00 10px,
#009900 10px,
#009900 20px
);
background-color: #009900;
}
.auth_outage_warningbar_center {
@@ -28,7 +68,7 @@ If you need to make changes here, remember to update your settings inside Moodle
top: 50%;
}
#auth_outage_warningbar_countdown {
#auth_outage_warningbar_message {
font-size: 200%;
font-weight: bold;
margin: 10px 0;

View File

@@ -0,0 +1,122 @@
var auth_outage_warningbar = {
init: function (params) {
this.preview = params.preview;
this.countdown = params.countdown;
this.ongoing = params.ongoing;
this.backonline = params.backonline;
this.backonlinedescription = params.backonlinedescription;
this.servertime = params.servertime;
this.checkfinishedurl = params.checkfinishedurl;
this.starts = params.starts;
this.stops = params.stops;
this.clienttime = Date.now();
this.finished = false;
this.divtext = document.getElementById('auth_outage_warningbar_message');
this.divtitle = document.getElementById('auth_outage_warningbar_title');
this.divblock = document.getElementById('auth_outage_warningbar_box');
this.finishbutton = document.getElementById('auth_outage_warningbar_button');
this.startWarning();
},
startWarning: function () {
if (this.finishbutton) {
this.finishbutton.style.display = 'none';
}
this.divblock.className = 'auth_outage_warning_period';
this.tickWarning();
},
tickWarning: function () {
var elapsed = Math.round((Date.now() - this.clienttime) / 1000);
var missing = (this.starts - this.servertime) - elapsed;
if (missing <= 0) {
this.startOngoing();
} else {
if (missing <= 10) {
this.divblock.className = 'auth_outage_imminent_period';
}
this.divtext.innerHTML = this.countdown.replace('{{countdown}}', this.seconds2hms(missing));
var $this = this;
setTimeout(function () {
$this.tickWarning();
}, 1000);
}
},
startOngoing: function () {
this.divblock.className = 'auth_outage_ongoing_period';
if (this.finishbutton) {
this.finishbutton.style.display = '';
}
this.divtext.innerHTML = this.ongoing;
this.tickOngoing();
},
tickOngoing: function () {
if (this.finished) {
return;
}
if (this.preview) {
// If one second before finish time, enfore finish. Otherwise, never finish it.
if (this.servertime == this.stops - 1) {
this.finish();
}
else {
return;
}
}
var $this = this;
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function () {
$this.ajaxCheckFinished(this);
};
xmlhttp.open("GET", this.checkfinishedurl, true);
xmlhttp.send();
setTimeout(function () {
$this.tickOngoing();
}, (5 * 60 * 1000)); // Check every 5 minutes.
},
ajaxCheckFinished: function (ajax) {
if (ajax.readyState == XMLHttpRequest.DONE) {
if (ajax.status == 200) {
if (ajax.responseText.trim() === 'finished') {
this.finish();
}
}
}
},
finish: function () {
this.divblock.className = 'auth_outage_finished_period';
if (this.finishbutton) {
this.finishbutton.style.display = 'none';
}
this.divtext.innerHTML = this.backonline;
this.divtitle.innerHTML = this.backonlinedescription;
},
seconds2hms: function (seconds) {
var minutes = Math.floor(seconds / 60);
var hours = Math.floor(minutes / 60);
seconds %= 60;
minutes %= 60;
// Cross-browser simple solution for padding zeroes.
if (minutes < 10) {
minutes = "0" + minutes;
}
if (seconds < 10) {
seconds = "0" + seconds;
}
return hours + ':' + minutes + ':' + seconds;
}
};
// auth_outage_countdown is used outside this js file.
/* jshint unused:false */

View File

@@ -0,0 +1,93 @@
<?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/>.
/**
* View included by the renderer to output the outage warning bar.
*
* @package auth_outage
* @author Daniel Thee Roperto <daniel.roperto@catalyst-au.net>
* @copyright 2016 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
use auth_outage\local\outagelib;
defined('MOODLE_INTERNAL') || die();
global $OUTPUT;
$start = userdate($viewbag['outage']->starttime, get_string('datetimeformat', 'auth_outage'));
$stop = userdate($viewbag['outage']->stoptime, get_string('datetimeformat', 'auth_outage'));
$countdown = get_string('messageoutagewarning', 'auth_outage', ['start' => $start, 'stop' => $stop]);
$ongoing = get_string('messageoutageongoing', 'auth_outage', ['start' => $start, 'stop' => $stop]);
$message = $viewbag['outage']->is_ongoing($viewbag['time']) ? $ongoing : '';
$infolink = new moodle_url('/auth/outage/info.php', ['id' => $viewbag['outage']->id]);
$title = $viewbag['outage']->get_title();
if (!$viewbag['static']) {
$title = html_writer::link(
$infolink,
$title,
['target' => '_blank', 'class' => 'auth_outage_warningbar_box_title']
);
if (is_siteadmin()) {
$url = new moodle_url('/auth/outage/finish.php', ['id' => $viewbag['outage']->id]);
$text = html_writer::empty_tag('img', [
'src' => $OUTPUT->pix_url('t/check'),
'alt' => get_string('finish', 'auth_outage'),
'class' => 'iconsmall',
]).' '.get_string('finish', 'auth_outage');
$attr = [
'title' => get_string('finish', 'auth_outage'),
'class' => 'auth_outage_warningbar_box_finish',
];
$title .= ' '.html_writer::span(html_writer::link($url, $text, $attr), '', ['id' => 'auth_outage_warningbar_button']);
}
}
echo html_writer::tag('style', outagelib::get_config()->css);
?>
<div id="auth_outage_warningbar_box">
<div class="auth_outage_warningbar_center">
<div id="auth_outage_warningbar_message"><?php echo $message; ?></div>
<div id="auth_outage_warningbar_title"><?php echo $title; ?></div>
</div>
</div>
<div class="auth_outage_warningbar_spacer">&nbsp;</div>
<?php if (!$viewbag['static']): ?>
<script>
<?php
require(__DIR__.'/warningbar.js');
$json = json_encode([
'countdown' => $countdown,
'ongoing' => $ongoing,
'backonline' => get_string('messageoutagebackonline', 'auth_outage'),
'backonlinedescription' => get_string('messageoutagebackonlinedescription', 'auth_outage'),
'servertime' => $viewbag['time'],
'starts' => $viewbag['outage']->starttime,
'stops' => $viewbag['outage']->stoptime,
'preview' => $viewbag['preview'],
'checkfinishedurl' => (string)(new moodle_url('/auth/outage/checkfinished.php')),
]);
echo 'auth_outage_warningbar.init('.$json.');';
?>
</script>
<?php endif;