Skip to content

Commit

Permalink
Merge pull request #31 from emrysr/dark-sidebar
Browse files Browse the repository at this point in the history
Dark sidebar
  • Loading branch information
glynhudson authored May 1, 2019
2 parents f9ef2c6 + 527ff9a commit a1e7cb5
Show file tree
Hide file tree
Showing 3 changed files with 129 additions and 98 deletions.
3 changes: 1 addition & 2 deletions backup-module/backup_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,9 @@ function backup_controller()
{
global $route, $session, $path, $redis, $homedir;
$result = false;

// This module is only to be ran by the admin user
if (!$session['write'] && !$session['admin']) {
$route->format = "text";
$route->format = "html";
return "<br><div class='alert alert-error'><b>Error:</b> backup module requires admin access</div>";
}
if (file_exists("$homedir/backup/config.cfg")) {
Expand Down
48 changes: 26 additions & 22 deletions backup-module/backup_menu.php
Original file line number Diff line number Diff line change
@@ -1,26 +1,30 @@
<?php
$domain = "messages";
bindtextdomain($domain, "Modules/admin/locale");
bind_textdomain_codeset($domain, 'UTF-8');
// $domain = "messages";
// bindtextdomain($domain, "Modules/admin/locale");
// bind_textdomain_codeset($domain, 'UTF-8');

$menu_left[] = array(
'id'=>"backup_menu",
'name'=>dgettext($domain, "Backup"),
'path'=>"backup" ,
'session'=>"write",
'order' => 0,
'icon'=>'icon-circle-arrow-down icon-white',
'hideinactive'=>1
);
// $menu_left[] = array(
// 'id'=>"backup_menu",
// 'name'=>dgettext($domain, "Backup"),
// 'path'=>"backup" ,
// 'session'=>"write",
// 'order' => 0,
// 'icon'=>'icon-circle-arrow-down icon-white',
// 'hideinactive'=>1
// );

$menu_dropdown_config[] = array(
'id'=>"backup_menu_extras",
'name'=>dgettext($domain, "Backup"),
'path'=>"backup" ,
'session'=>"write",
'order' => 55,
'icon'=>'icon-circle-arrow-down'
);
// $menu_dropdown_config[] = array(
// 'id'=>"backup_menu_extras",
// 'name'=>dgettext($domain, "Backup"),
// 'path'=>"backup" ,
// 'session'=>"write",
// 'order' => 55,
// 'icon'=>'icon-circle-arrow-down'
// );



$menu['setup'][] = array(
'text' => _("Backup"),
'path' => 'backup',
'icon' => 'box-add',
'order' => 1
);
176 changes: 102 additions & 74 deletions backup-module/backup_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,89 +26,116 @@
padding-left:20px;
padding-top:20px;
}
.nav-tabs > li > a {
color: #999!important;
}
.nav-tabs > li.active > a {
color: #EFEFEF!important;
}
.nav-tabs > li > a:hover {
color: #FFF!important;
}
</style>
<link rel="stylesheet" href="<?php echo $path; ?>Lib/misc/sidebar.css">

<div id="wrapper">
<div class="sidenav">
<div class="sidenav-inner">
<ul class="sidenav-menu">
<li><a href="#export">Export</a></li>
<li><a href="#import">Import</a></li>
</ul>



<ul class="nav nav-tabs mb-0 mt-3" id="backup-tabs">
<li class="active"><a href="#view-import">Import</a></li>
<li><a href="#view-export">Export</a></li>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="view-import">
<h3>Import</h3>
<p>Import an emoncms backup archive.</p>
<span style="color:red;font-weight:bold;">CAUTION ALL EMONCMS ACCOUNT DATA WILL BE OVERWRITTEN BY THE IMPORTED DATA</span><br><br>
<p><i>Note: Before import update to latest version of Emoncms & emonHub.</i></p>
<form action="<?php echo $path; ?>backup/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"><br><br>
<input class="btn btn-danger" type="submit" name="submit" value="Import Backup">
</form>
<br><br>
<p><i>Note: If browser upload fails for large backup files <a href="http://github.com/emoncms/backup">follow manual import instructions.</a></i></p>
<pre id="import-log-bound"><div id="import-log"></div></pre>
<br>
<p><i>Refresh page if log window does not update.</i></p>
<p><i>After import is complete logout then login using the new imported account login details.</i></p>
</div>
</div>

<div style="height:20px"></div>
<div class="tab-pane" id="view-export">
<h3>Export</h3>
<p>Export a compressed archive containing:</p>
<ul>
<li>Emoncms MYSQL database</li>
<li>PHPFina data files</li>
<li>PHPTimeSeries data files</li>
<li>EmonHub Config</li>
</ul>
<p>These files contain all Emoncms data including:</p>
<ul>
<li>Input processes</li>
<li>Feed data</li>
<li>Dashboards</li>
<li>EmonHub Config</li>
</ul>
<p>The compressed archive can be used to migrate data to another emonPi / emonBase.</p>
<button id="emonpi-backup" class="btn btn-info"><?php echo _('Create backup'); ?></button>
<br><br>
<pre id="export-log-bound"><div id="export-log"></div></pre>
<?php
$backup_filename="emoncms-backup-".date("Y-m-d").".tar.gz";
if (file_exists($parsed_ini['backup_location']."/".$backup_filename) && !file_exists("/tmp/backuplock")) {
echo '<br><br><b>Right Click > Download:</b><br><a href="'.$path.'backup/download">'.$backup_filename.'</a>';
}
?>
<br><br>
<p>Once export is complete refresh page to see download link.</p>
<p><i>Note: Export can take a long some time, please be patient.</i></p>
</div>
</div>

<script>
$(function () {
// trigger tab open on click (adding hash to location)
$('#backup-tabs a').click(function (e) {
e.preventDefault();
var href = $(e.target).attr('href');
selectTab(href.replace('view-',''));
// show tab
$(this).tab('show');
// change hash
location.hash = href.replace('view-','');
})
// pre-select tab on load
// @todo: fix slight delay from ajax calls
selectTab();

// on hash change
$(window).on('hashchange', function(event) {
selectTab(location.hash);
})
/**
* loop through all tabs and highlight one if given [hash] is a match
*/
function selectTab(hash) {
hash = hash || location.hash;

$.each($('#backup-tabs a'), function(i,elem) {
var $tab = $(elem);
if($tab.attr('href') == hash.replace('#','#view-')) {
$tab.tab('show');
}
});
}
})
</script>

<?php
if (empty($servicerunnerproc)) {
echo "<div class='alert alert-error'><b>Warning:</b> service-runner is not running and is required. To install service-runner see <a href='https://github.com/emoncms/emoncms/blob/master/scripts/services/install-service-runner-update.md'>service-runner installation</a></div>";
}
?>
<div id="view-export">
<h3>Export</h3>
<p>Export a compressed archive containing:</p>
<ul>
<li>Emoncms MYSQL database</li>
<li>PHPFina data files</li>
<li>PHPTimeSeries data files</li>
<li>EmonHub Config</li>
</ul>
<p>These files contain all Emoncms data including:</p>
<ul>
<li>Input processes</li>
<li>Feed data</li>
<li>Dashboards</li>
<li>EmonHub Config</li>
</ul>
<p>The compressed archive can be used to migrate data to another emonPi / emonBase.</p>
<button id="emonpi-backup" class="btn btn-info"><?php echo _('Create backup'); ?></button>
<br><br>
<pre id="export-log-bound"><div id="export-log"></div></pre>
<?php
$backup_filename="emoncms-backup-".date("Y-m-d").".tar.gz";
if (file_exists($parsed_ini['backup_location']."/".$backup_filename) && !file_exists("/tmp/backuplock")) {
echo '<br><br><b>Right Click > Download:</b><br><a href="'.$path.'backup/download">'.$backup_filename.'</a>';
}
?>
<br><br>
<p>Once export is complete refresh page to see download link.</p>
<p><i>Note: Export can take a long some time, please be patient.</i></p>
</div>

<div id="view-import">
<h3>Import</h3>
<p>Import an emoncms backup archive.</p>
<span style="color:red;font-weight:bold;">CAUTION ALL EMONCMS ACCOUNT DATA WILL BE OVERWRITTEN BY THE IMPORTED DATA</span><br><br>
<p><i>Note: Before import update to latest version of Emoncms & emonHub.</i></p>
<form action="<?php echo $path; ?>backup/upload" method="post" enctype="multipart/form-data">
<input type="file" name="file" id="file"><br><br>
<input class="btn btn-danger" type="submit" name="submit" value="Import Backup">
</form>
<br><br>
<p><i>Note: If browser upload fails for large backup files <a href="http://github.com/emoncms/backup">follow manual import instructions.</a></i></p>
<pre id="import-log-bound"><div id="import-log"></div></pre>
<br>
<p><i>Refresh page if log window does not update.</i></p>
<p><i>After import is complete logout then login using the new imported account login details.</i></p>
</div>
</div>
<script type="text/javascript" src="<?php echo $path; ?>Lib/misc/sidebar.js"></script>

<script>
init_sidebar({menu_element:"#backup_menu"});
var path = "<?php echo $path; ?>";

$("#view-import").hide();
if (location.hash=="#export") { $("#view-import").hide(); $("#view-export").show(); }
if (location.hash=="#import") { $("#view-import").show(); $("#view-export").hide(); }

$(window).on('hashchange', function() {
if (location.hash=="#export") { $("#view-import").hide(); $("#view-export").show(); }
if (location.hash=="#import") { $("#view-import").show(); $("#view-export").hide(); }
});

export_log_update();
import_log_update();
var export_updater = false;
Expand Down Expand Up @@ -145,11 +172,12 @@ function import_log_update() {
$("#import-log").html(result);
document.getElementById("import-log-bound").scrollTop = document.getElementById("import-log-bound").scrollHeight


if (result.indexOf("=== Emoncms import complete! ===")!=-1) {
clearInterval(import_updater);
}
}
});
}


</script>

0 comments on commit a1e7cb5

Please sign in to comment.