Issue #15 - Added countdown to navbar, redirect to info.php when ended.

This commit is contained in:
Daniel Thee Roperto
2016-09-09 15:57:24 +10:00
parent 64d09721cf
commit 4c4df53402
5 changed files with 114 additions and 21 deletions

View File

@@ -40,7 +40,7 @@ $string['description'] = 'Public Description';
$string['menudefaults'] = 'Default Settings';
$string['menumanage'] = 'Manage';
$string['messageoutageongoing'] = 'Our system will be under maintenance until {$a->stop}.';
$string['messageoutagewarning'] = 'There is an scheduled downtime from {$a->start} until {$a->stop}.';
$string['messageoutagewarning'] = 'Shutting down in {{countdown}} ...';
$string['outageedit'] = 'Edit Outage';
$string['outagecreate'] = 'Create Outage';
$string['outagedelete'] = 'Delete Outage';
@@ -49,6 +49,7 @@ $string['outageduration'] = 'Outage Duration';
$string['outagedurationerrorinvalid'] = 'Outage duration must be positive.';
$string['outageslist'] = 'Outages List';
$string['pluginname'] = 'Outage manager';
$string['readmore'] = 'Read More';
$string['starttime'] = 'Start 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.';

View File

@@ -152,6 +152,8 @@ class auth_outage_renderer extends plugin_renderer_base {
}
public function renderoutagebar(outage $outage) {
global $CFG;
$start = userdate($outage->starttime, get_string('strftimedatetimeshort'));
$stop = userdate($outage->stoptime, get_string('strftimedatetimeshort'));
@@ -161,24 +163,10 @@ class auth_outage_renderer extends plugin_renderer_base {
['start' => $start, 'stop' => $stop]
);
return
html_writer::tag('style', get_config('auth_outage', 'css'))
. html_writer::div(
html_writer::div(
html_writer::div($outage->get_title(), 'auth_outage_warningbar_box_title')
. html_writer::div(
$message . ' '
. html_writer::tag('small',
'[' . html_writer::link(
new moodle_url('/auth/outage/info.php'), 'more', ['target' => 'outage']
) . ']'
),
'auth_outage_warningbar_box_message'
),
'auth_outage_warningbar_box'
),
'auth_outage_warningbar'
)
. html_writer::div(' ', 'auth_outage_warningbar_spacer');
ob_start();
require($CFG->dirroot . '/auth/outage/views/warningbar.php');
$html = ob_get_contents();
ob_end_clean();
return $html;
}
}

View File

@@ -55,7 +55,7 @@ if ($hassiteconfig && is_enabled_auth('outage')) {
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'),
file_get_contents($CFG->dirroot . '/auth/outage/views/warningbar.css'),
PARAM_TEXT)
);
// Create category for Outage.

104
views/warningbar.php Normal file
View File

@@ -0,0 +1,104 @@
<?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 Catalyst IT
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
if (!defined('MOODLE_INTERNAL')) {
die('Direct access to this script is forbidden.'); // It must be included from a Moodle page.
}
// If debugging include directly from file, otherwise use plugin settings.
echo html_writer::tag('style',
debugging() ? file_get_contents($CFG->dirroot . '/auth/outage/views/warningbar.css') : get_config('auth_outage', 'css')
);
?>
<div class="auth_outage_warningbar">
<div class="auth_outage_warningbar_box">
<div class="auth_outage_warningbar_box_title"><?php echo $outage->get_title(); ?></div>
<div class="auth_outage_warningbar_box_message">
<span id="auth_outage_warningbar_countdown"><?php echo $message; ?></span>
<small>
[<?php echo html_writer::link(
new moodle_url('/auth/outage/info.php'),
get_string('readmore', 'auth_outage'),
['target' => 'outage']
); ?>]
</small>
</div>
</div>
</div>
<script>
// Internet Explorer 8 fix.
if (!Date.now) {
Date.now = function () {
return new Date().getTime();
}
}
// Define outage object.
var auth_outage_countdown = {
timer: null
, countdown: <?php echo($outage->starttime - time()); ?>
, clienttime: Date.now()
, init: function () {
this.span = document.getElementById('auth_outage_warningbar_countdown');
this.text = this.span.innerHTML;
this.tick();
var $this = this;
this.timer = setInterval(function () {
$this.tick();
}, 1000);
}
, tick: function () {
var elapsed = Math.round((Date.now() - this.clienttime) / 1000);
var missing = this.countdown - elapsed;
if (missing <= 0) {
clearInterval(this.timer);
location.href = '<?php echo new \moodle_url('/auth/outage/info.php'); ?>';
}
else {
this.span.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.init();
</script>
<div class="auth_outage_warningbar_spacer">&nbsp;</div>