Skip to content

Commit

Permalink
Move admin menus from frontend code into menu generatng backend code …
Browse files Browse the repository at this point in the history
…which is used by modules (so we dont do the same thing twice and need to sort the list on the client)

Remove list-link function which added an icon, could not find a single usage.
Remove calls to addMenuItem in munkireport.js, do it server side
Remove addTabe/removeTab from munkireport.js, no usages detected.
Removed loadHash/updateHash from munkireport.js, we will need to reimplement this (clicking a client detail tab adds browser history)
Rewrote function in client detail never deactivating dropdown active class.
Fix popper positioning for client detail tab dropdown
Fix responsive image class in machine_detail_widget1.php
admin menu nav respects custom css class
  • Loading branch information
mosen committed Jan 3, 2024
1 parent 5a91942 commit db6ce50
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 173 deletions.
17 changes: 16 additions & 1 deletion app/lib/munkireport/Modules.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,18 @@ protected function addCoreModules()
'core' => true,
];

// These listings/menus were client side only for no real reason, they have been
// consolidated into the Module Manager so that the sorting only needs to happen once.
$this->moduleList['core'] = [
'core' => true,
'path' => realpath(__DIR__ . '../'),
'admin_pages' => [
'systemstatus' => ['i18n' => 'systemstatus.menu_link', 'url' => url('/system/status')],
'system.database' => ['i18n' => 'system.database.menu_link', 'url' => url('/system/database')],
'widget.gallery' => ['i18n' => 'widget.gallery', 'url' => url('/system/widgets')],
'module_marketplace' => ['i18n' => 'module_marketplace.module_marketplace', 'url' => url('/module_marketplace')],
]
];
}

/**
Expand Down Expand Up @@ -444,6 +456,9 @@ public function addWidgets(array &$widgetArray, ?array $detailWidgetList = [])
/**
* Get data to create dropdown nav
*
* Change in v6.0 beta to support item data key `url` which replaces the auto generated path with a specific, absolute
* URL.
*
* @param string $kind 'reports' or 'listings'
* @param string $baseUrl 'show/report' or 'show/listing'
* @param string $page current page url path
Expand All @@ -462,7 +477,7 @@ public function getDropdownData(string $kind, string $baseUrl, string $page): ar
}
$i18n = isset($itemData['i18n']) ? $itemData['i18n'] : 'nav.' . $kind . '.' . $itemName;
$out[] = (object) [
'url' => mr_url($baseUrl.'/'.$module.'/'.$itemName),
'url' => isset($itemData['url']) ? $itemData['url'] : mr_url($baseUrl.'/'.$module.'/'.$itemName),
'name' => $itemName,
'class' => $page == $baseUrl.'/'.$module.'/'.$itemName ? 'active' : '',
'i18n' => $i18n,
Expand Down
23 changes: 0 additions & 23 deletions public/assets/js/clients/client_detail.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,6 @@ $(document).on('appReady', function(e, lang) {
// Set h4 classes on headings
$('#summary h4').addClass('alert alert-info');

// Fix for using a regular dropdown for tabs
$('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {

// Remove 'active' class from all li's
$(e.target).closest('ul').children().removeClass('active');

// Add 'active' to current li
$(e.target).parent().addClass('active');

});

// Get client data
$.getJSON( appUrl + '/clients/get_data/' + serialNumber, function( data ) {

Expand Down Expand Up @@ -122,10 +111,6 @@ $(document).on('appReady', function(e, lang) {
});
});

// get archive status
var getArchiveStatus = function(){
return $
}
//set archive status
var setArchiveStatus = function(status){
if(status == 1){
Expand Down Expand Up @@ -187,12 +172,4 @@ $(document).on('appReady', function(e, lang) {
});

// ------------------------------------ End Hotkeys


loadHash();

// Update hash when changing tab
$('a[data-toggle="tab"]').on('shown.bs.tab', updateHash);


});
153 changes: 14 additions & 139 deletions public/assets/js/munkireport.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,51 +4,20 @@
mr.loadTheme();

$(document).on('appReady', function(e, lang) {

$('html.no-js').removeClass('no-js');

// addMenuItem({
// menu: 'admin',
// i18n: 'notification.menu_link',
// url: appUrl + '/module/notification/manage'
// });

addMenuItem({
menu: 'admin',
i18n: 'systemstatus.menu_link',
url: appUrl + '/system/status'
});

addMenuItem({
menu: 'admin',
i18n: 'system.database.menu_link',
url: appUrl + '/system/database'
});

addMenuItem({
menu: 'admin',
i18n: 'widget.gallery',
url: appUrl + '/system/widgets'
});

addMenuItem({
menu: 'admin',
i18n: 'module_marketplace.module_marketplace',
url: appUrl + '/module_marketplace'
});

// Sort admin menu, after other items are added
mr.sortMenu('ul.admin');

// Add list link
$('list-link').each(function( index ){
var url = appUrl + $(this).data('url');
$(this).after('<a href="'+url+'" class="btn btn-xs pull-right"><i class="fa fa-list"></i></a>');
$(this).remove();
});

});

$(function () {
// client_details tab
$('.client-tabs a.dropdown-item').on('click', function(e) {
e.preventDefault();
$(e.currentTarget).tab('show');
}).on('shown.bs.tab', function(e) {
// bs.tab is not keeping track of the active link correctly.
$('.client-tabs a.active').removeClass('active');
$(e.currentTarget).addClass('active');
});
});

$( document ).ready(function() {

Expand Down Expand Up @@ -138,79 +107,9 @@ $( document ).ready(function() {
});
});

$(window).on("hashchange", function (e) {
loadHash();
})

// Update hash in url
var updateHash = function(e){
var url = String(e.target)
if(url.indexOf("#") != -1)
{
var hash = url.substring(url.indexOf("#"));
// Save scroll position
var yScroll=document.body.scrollTop;
window.location.hash = '#tab_'+hash.slice(1);
document.body.scrollTop=yScroll;
}
},
loadHash = function(){
// Activate correct tab depending on hash
var hash = window.location.hash.slice(5);
if(hash){
$('.client-tabs a[href="#'+hash+'"]').tab('show');
}
else{
$('.client-tabs a[href="#summary"]').tab('show');
}
},
addMenuItem = function(conf){
// Add menu item
conf.menu = conf.menu || 'listing';
conf.name = conf.name || 'no_name';
conf.i18n = conf.i18n || '';
conf.url = conf.url || appUrl + '/show/' + conf.menu + '/' + conf.name;
$('.dropdown-menu.' + conf.menu)
.append($('<a>')
.attr('href', conf.url)
.addClass('dropdown-item')
.text(function(){
if(conf.i18n){
return i18n.t(conf.i18n);
}
return conf.name;
}));
},
addTab = function(conf){

// Add tab link
$('.client-tabs .divider')
.before($('<li>')
.append($('<a>')
.attr('href', '#'+conf.id)
.attr('data-toggle', 'tab')
.on('show.bs.tab', function(){
// We have to remove the active class from the
// previous tab manually, unfortunately
$('.client-tabs li').removeClass('active');
})
.on('shown.bs.tab', updateHash)
.text(conf.linkTitle)));

// Add tab
$('div.tab-content')
.append($('<div>')
.attr('id', conf.id)
.addClass('tab-pane')
.append($('<h2>')
.text(conf.tabTitle))
.append(conf.tabContent));
},
removeTab = function(id){
// remove tab
$('#'+id).remove();
$('.client-tabs [href=#'+id+']').parent().remove();
}
var loadHash = function() {
// Intentionally empty so older scripts don't throw an Exception
};

var showFilterModal = function(e) {
e.preventDefault();
Expand Down Expand Up @@ -449,30 +348,6 @@ function state(id, data)
}
}

// Debug function to dump js objects
function dumpj(obj)
{
type = typeof(obj)
if(type == 'object')
{
var out = {}
for (var key in obj) {
type = typeof(obj[key])
if ( type == 'object')
{
out[key] = 'object'
}
else{
out[key] = obj[key];
}
}
}
else{
out = obj
}
alert(JSON.stringify(out));
}

// Filesize formatter (uses 1000 as base)
function fileSize(size, decimals){
// Check if number
Expand Down
11 changes: 6 additions & 5 deletions resources/views/clients/detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
<div class="col">
<div class="input-group">
<div class="input-group-prepend">
<button class="btn btn-secondary dropdown-toggle" type="button" id="showTabMenuButton" data-toggle="dropdown" aria-expanded="false">
<button class="btn btn-secondary dropdown-toggle" type="button" id="showTabMenuButton" data-toggle="dropdown" data-display="static" aria-expanded="false">
<span data-i18n="show" class="hidden-sm hidden-xs"></span>
<i class="fa fa-list fa-fw"></i>
</button>
<div class="dropdown-menu client-tabs" role="tablist" aria-labelledby="showTabMenuButton">
@foreach($tab_list as $name => $data)
<a class="dropdown-item" href="#{{ $name }}" data-toggle="tab"><span data-i18n="{{ $data['i18n'] }}"></span>
@isset($data['badge'])
<span id="{{ $data['badge'] }}" class="badge badge-secondary">0</span>
@endisset
<a class="dropdown-item" href="#" data-target="#{{ $name }}" role="tab">
<span data-i18n="{{ $data['i18n'] }}"></span>
@isset($data['badge'])
<span id="{{ $data['badge'] }}" class="badge badge-secondary">0</span>
@endisset
</a>
@endforeach
</div>
Expand Down
8 changes: 6 additions & 2 deletions resources/views/machine/machine_detail_widget1.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div class="col">
<div class="row">
<div class="col">
<img id="apple_hardware_icon" class="img-responsive">
<img id="apple_hardware_icon" class="img-fluid" alt="An image of this hardware model">
</div>
<div class="col">
<span>macOS <span class="machine-os_version"></span></span><br>
Expand All @@ -10,7 +10,11 @@
<span><span class="reportdata-remote_ip"></span></span><br>
</div>
</div>
<span class="machine-machine_desc"></span> <a class="machine-refresh-desc" href=""><i class="fa fa-refresh"></i></a>
<div class="row">
<div class="col">
<span class="machine-machine_desc"></span> <a class="machine-refresh-desc" href=""><i class="fa fa-refresh"></i></a>
</div>
</div>
</div>

<script>
Expand Down
4 changes: 1 addition & 3 deletions resources/views/partials/head.php
Original file line number Diff line number Diff line change
Expand Up @@ -183,9 +183,7 @@
}
?>
<?php foreach($modules->getDropdownData('admin_pages', 'module', $page) as $item): ?>
<!-- <li class="<?=$item->class?>"> -->
<a class="dropdown-item" href="<?=$item->url?>" data-i18n="<?=$item->i18n?>"></a>
<!-- </li> -->
<a class="dropdown-item <?=$item->class?>" href="<?=$item->url?>" data-i18n="<?=$item->i18n?>"></a>
<?php endforeach; ?>
</div>
</li>
Expand Down

0 comments on commit db6ce50

Please sign in to comment.