Skip to content

Commit

Permalink
Merge pull request #1510 from emoncms/master
Browse files Browse the repository at this point in the history
Merge master to stable
  • Loading branch information
TrystanLea committed Jan 22, 2020
2 parents 90f3915 + 28021d0 commit d2e08a9
Show file tree
Hide file tree
Showing 44 changed files with 634 additions and 438 deletions.
11 changes: 9 additions & 2 deletions Lib/misc/nav_functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -363,8 +363,15 @@ function sortMenu (&$menus) {
}
}
// get next sort (max_order) for a menu
$next_order = !empty($orders) ? max($orders)+1: 0;

try {
$sortedOrders = array_values($orders);
if(empty($sortedOrders)) $sortedOrders[] = 0;
asort($sortedOrders, SORT_NATURAL); // sort like this: 2, 11, a, a1, b
preg_match_all('!\d+!', array_slice($sortedOrders, -1)[0], $matches);
$next_order = implode(array_column($matches,0));
} catch (Exception $e) {
$next_order = 0;
}
// set order field for un-ordered menu items
foreach($unordered as $index) {
// sort by title if available
Expand Down
40 changes: 19 additions & 21 deletions Lib/misc/sidebar.css
Original file line number Diff line number Diff line change
Expand Up @@ -35,28 +35,28 @@ Top nav
font-size: 1.25rem;
}
#emoncms-navbar .navbar-inner .nav a span{
font-size: 1rem;
padding-top: .1rem;
font-size: 1rem;
padding-top: .1rem;
}
#emoncms-navbar .navbar-inner .nav a[data-hide-narrow] span {
display: none;
display: none;
}
@media (min-width: 768px) {
#emoncms-navbar .navbar-inner .nav a[data-hide-narrow] span {
display: inline-block;
}
#emoncms-navbar .navbar-inner .nav a[data-hide-narrow] span {
display: inline-block;
}
}

d-none d-md-block
.navbar .nav > li > a {
padding: .6em;
}
.navbar .nav {
float: none;
float: none;
}
.navbar .navbar-inner:before,
.navbar .navbar-inner:after {
content: none;
content: none;
}
@media screen and (min-width: 380px) {
#emoncms-navbar .navbar-inner .nav {
Expand All @@ -68,7 +68,7 @@ d-none d-md-block
}

#emoncms-navbar .navbar-inner .nav ul li{
font-size: 1.1rem;
font-size: 1.1rem;
}
#emoncms-navbar .navbar-inner .nav ul li a{
padding: .5em 1em;
Expand All @@ -81,11 +81,9 @@ site-wide overriding css

/* eof site css changes */



/* -------------------------------------------------------------------
Sidebar sub menus----------------------------------------------------*/

Sidebar sub menus
--------------------------------------------------------------------*/
#sidebar {
position: fixed;
display: none;
Expand Down Expand Up @@ -115,7 +113,7 @@ Sidebar sub menus----------------------------------------------------*/
text-transform: capitalize;
}
#sidebar .close:hover {
text-decoration: none;
text-decoration: none;
}

@media screen and (min-width: 380px) {
Expand All @@ -124,8 +122,10 @@ Sidebar sub menus----------------------------------------------------*/
height: calc(100vh - 2.7rem);
}
}


/* -------------------------------------------------------------------
gravitar icon in toolbar
Gravatar icon in toolbar
--------------------------------------------------------------------*/
ul#right-nav li.menu-user{
padding-right: .125em;
Expand Down Expand Up @@ -200,8 +200,6 @@ top navbar override
#sidebar .include-container.in,
#sidebar .collapse.in{display:block}



#sidebar-toggle {
display: none !important;
}
Expand Down Expand Up @@ -281,7 +279,7 @@ top navbar override
background: #212121;
}
#footer_nav #sidebar_bookmarks li {
border-bottom: 1px solid #444;
border-bottom: 1px solid #444;
}
#footer_nav #sidebar_bookmarks li a {
padding: 0.67em 0.94em;
Expand All @@ -290,9 +288,9 @@ top navbar override
content: attr(data-edit)
}
#edit_bookmarks {
padding: .7em!important;
color: #545454!important;
transition: color .3s ease-out;
padding: .7em !important;
color: #545454!important;
transition: color .3s ease-out;
}
#edit_bookmarks:hover,
#edit_bookmarks:focus {
Expand Down
7 changes: 4 additions & 3 deletions Lib/misc/sidebar.js
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ $(function(){
document.body.classList.add('has-animation');
}, 500);
}

/**
* If menu 3rd level menu shown shrink 2nd level entries
*
Expand Down Expand Up @@ -166,9 +167,11 @@ $(function(){
$menu.find('li').not('.active').toggleClass('in');
}
}

function getQueryStringValue (key) {
return decodeURIComponent(window.location.search.replace(new RegExp("^(?:.*[&\\?]" + encodeURIComponent(key).replace(/[\.\+\*]/g, "\\$&") + "(?:\\=([^&]*))?)?.*$", "i"), "$1"));
}

// add current page to user's bookmark list
$('#set-bookmark, #remove-bookmark').click(function(event) {
event.preventDefault();
Expand Down Expand Up @@ -296,18 +299,16 @@ function show_sidebar(options) {
$(".content-container").css("margin","2.7rem 0 0 15rem");
}
}

function hide_sidebar(options) {
$('#sidebar').trigger('hide.sidebar.collapse');
$('body').addClass('collapsed').removeClass('expanded');
$(".content-container").css("margin","2.7rem auto 0 auto");
}


// backward compatible empty function
if(typeof init_sidebar !== 'function') var init_sidebar = function(){}



// get/set document cookies
var docCookies = {
getItem: function (sKey) {
Expand Down
26 changes: 12 additions & 14 deletions Modules/admin/admin_controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ function admin_controller()
if(!$session['write']) {
$result = ''; // empty result shows login page (now redirects once logged in)
$message = _('Admin re-authentication required');
}
}

// Allow for special admin session if updatelogin property is set to true in settings.php
// Its important to use this with care and set updatelogin to false or remove from settings
Expand Down Expand Up @@ -51,10 +51,9 @@ function admin_controller()
3 =>'ERROR'
);

$path_to_config = 'settings.php';
// $path_to_config = 'settings.php';

if ($session['admin']) {

if ($route->format == 'html') {
if ($route->action == 'view') {
require "Modules/admin/admin_model.php";
Expand Down Expand Up @@ -120,13 +119,12 @@ function admin_controller()
'v' => 3,
'log_levels' => $log_levels,
'log_level'=>$settings['log']['level'],
'log_level_label' => $log_levels[$settings['log']['level']],
'path_to_config'=> $path_to_config
'log_level_label' => $log_levels[$settings['log']['level']]
// 'path_to_config'=> $path_to_config
);

return view("Modules/admin/admin_main_view.php", $view_data);
}

else if ($route->action == 'db')
{
$applychanges = get('apply');
Expand All @@ -149,15 +147,13 @@ function admin_controller()
{
return view("Modules/admin/userlist_view.php", array());
}

else if ($route->action == 'setuser' && $session['write'])
{
$_SESSION['userid'] = intval(get('id'));
header("Location: ../user/view");
// stop any other code from running once http header sent
exit();
}

else if ($route->action == 'downloadlog')
{
if ($settings['log']['enabled']) {
Expand All @@ -177,7 +173,6 @@ function admin_controller()
exit;
}
}

else if ($route->action == 'getlog')
{
$route->format = "text";
Expand Down Expand Up @@ -223,9 +218,8 @@ function read_file($file, $lines)
} //End PHP replacement for Tail
return trim(ob_get_clean());
}

else if (($settings['interface']['enable_update_ui'] || $settings['interface']['enable_admin_ui']) && $route->action == 'emonpi') {

if ($route->subaction == 'update' && $session['write'] && $session['admin']) {
$route->format = "text";
// Get update argument e.g. 'emonpi' or 'rfm69pi'
Expand All @@ -237,8 +231,12 @@ function read_file($file, $lines)
if (isset($_POST['type'])) $type = $_POST['type'];
if (!in_array($type,array("all","emoncms","firmware","emonhub"))) return "Invalid update type";

$redis->rpush("service-runner","$update_script $type $firmware>$update_logfile");
return "service-runner trigger sent";
if ($redis) {
$redis->rpush("service-runner","$update_script $type $firmware>$update_logfile");
return "service-runner trigger sent";
} else {
return "redis not running";
}
}

if ($route->subaction == 'getupdatelog' && $session['admin']) {
Expand Down Expand Up @@ -332,7 +330,7 @@ function read_file($file, $lines)
}
else if ($route->format == 'json')
{
if ($route->action == 'redisflush' && $session['write'])
if ($route->action == 'redisflush' && $session['write'] && $redis)
{
$redis->flushDB();
return array('used'=>$redis->info()['used_memory_human'], 'dbsize'=>$redis->dbSize());
Expand Down
23 changes: 0 additions & 23 deletions Modules/admin/admin_db_view.php

This file was deleted.

5 changes: 4 additions & 1 deletion Modules/admin/admin_main_view.php
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ function row($title, $value, $title_css = '', $value_css='') {
</div>
<a href="<?php echo $path; ?>admin/users" class="btn btn-info"><?php echo _('Users'); ?></a>
</section>

<?php
// UPDATES
// -------------------
Expand Down Expand Up @@ -223,6 +223,7 @@ function row($title, $value, $title_css = '', $value_css='') {
</div>
</section>

<?php /*
<section>
<pre id="logreply-bound"><div id="logreply"></div></pre>
<?php if(is_writable($path_to_config)) { ?>
Expand All @@ -245,6 +246,8 @@ function row($title, $value, $title_css = '', $value_css='') {
</span>
<?php } ?>
</section>
*/ ?>

<?php } ?>

<?php
Expand Down
5 changes: 5 additions & 0 deletions Modules/admin/admin_model.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,13 +311,18 @@ public static function get_rpi_info() {
* @return string
*/
public static function mqtt_version() {
global $log;
$v = '?';
if(strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
$v = "n/a";
} else {
set_error_handler(function($errno, $errstr, $errfile, $errline) use ($log) {
$log->warn(sprintf("%s:%s - %s", basename($errfile), $errline, $errstr));
});
if (file_exists('/usr/sbin/mosquitto')) {
$v = exec('/usr/sbin/mosquitto -h | grep -oP \'(?<=mosquitto\sversion\s)[0-9.]+(?=\s*)\'');
}
restore_error_handler();
}
return $v;
}
Expand Down

0 comments on commit d2e08a9

Please sign in to comment.