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

41
views/warningbar.css Normal file
View File

@@ -0,0 +1,41 @@
/*
This file is used as default value for the 'auth_outage_css' settings.
If you need to make chances here, remember to update your settings inside Moodle.
*/
.auth_outage_warningbar {
background-color: white;
box-sizing: content-box;
height: 90px;
left: 0;
position: fixed;
text-align: center;
top: 0;
width: 100%;
z-index: 9999;
}
.auth_outage_warningbar_box {
background-color: #ffcccc;
border-bottom: 2px dashed #a00000;
border-top: 2px dashed #a00000;
color: #a00000;
}
.auth_outage_warningbar_box_title {
font-size: 200%;
font-weight: bold;
margin: 10px 0;
}
.auth_outage_warningbar_box_message {
margin-bottom: 5px;
}
.navbar.navbar-fixed-top {
top: 90px;
}
.auth_outage_warningbar_spacer {
height: 80px;
}

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>