Skip to content

Commit

Permalink
Fix the menu not closing
Browse files Browse the repository at this point in the history
Add code page settings
  • Loading branch information
austinwbest committed Jan 31, 2024
1 parent 946d705 commit 8f59ce0
Show file tree
Hide file tree
Showing 9 changed files with 182 additions and 34 deletions.
3 changes: 3 additions & 0 deletions root/app/www/public/ajax/code.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

$labels = $dataFiles = $dataLines = $colors = '';
$usedColors = [];
array_sort_by_key($fileTypes, 'lines', 'desc');
$fileTypes = array_slice($fileTypes, 0, ($settings['pages']['code']['limit'] ? $settings['pages']['code']['limit'] : 20));

foreach ($fileTypes as $fileType => $fileTypeData) {
$randomColor = randomColor($usedColors);
$usedColors[] = $randomColor;
Expand Down
21 changes: 17 additions & 4 deletions root/app/www/public/ajax/settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,30 @@
?>
<table class="table table-bordered">
<thead>
<tr><td colspan="3"><h5>Global</h5></td></tr>
<tr>
<th>Setting</th>
<th>Value</th>
<th>Description</th>
</tr>
</thead>
<tbody>
<tr><td colspan="3"><h5>Global</h5></td></tr>
<tr>
<td>Repository location</td>
<td><input type="text" class="form-control setting" id="global-repositoryPath" value="<?= REPOSITORY_PATH ?>"></td>
<td>This is the location of all git repositories to load and use</td>
</tr>
<tr><td colspan="3"><h5>Page: Code</h5></td></tr>
<tr>
<td>Limit</td>
<td><input type="number" class="form-control setting" id="pages-code-limit" value="<?= ($settings['pages']['code']['limit'] ? $settings['pages']['code']['limit'] : 20) ?>"></td>
<td>How many different file types to show</td>
</tr>
<tr>
<td>Ignore</td>
<td><input type="text" class="form-control setting" id="pages-code-ignoreExtension" value="<?= implode(', ', $ignoreCodePageExtensions) ?>"></td>
<td>Ignore these file types when generating the graphs</td>
</tr>
</tbody>
<tfoot>
<tr><td colspan="3" align="center"><button class="btn btn-outline-success" onclick="saveSettings()">Save Settings</button></td></tr>
Expand All @@ -44,11 +55,13 @@

$field = $key;
if (str_contains($field, '-')) {
list($cat, $field) = explode('-', $key);
$keyParts = explode('-', $key);
}

if ($cat) {
$settings[$cat][$field] = $val;
if (count($keyParts) == 3) {
$settings[$keyParts[0]][$keyParts[1]][$keyParts[2]] = $val;
} elseif (count($keyParts) == 2) {
$settings[$keyParts[0]][$keyParts[1]] = $val;
} else {
$settings[$field] = $val;
}
Expand Down
61 changes: 32 additions & 29 deletions root/app/www/public/ajax/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,38 @@
}
require ABSOLUTE_PATH . 'loader.php';

$repository = $_POST['repository'];
$git = new Git($repository);
$repoSize = $git->size();
$overview = $git->log();
$branches = $git->branches();
$contributors = $git->contributors();
$totalFiles = $git->totalFiles();
$totalCommits = $git->totalCommits();
$totalLines = $git->totalLines();
$branchHeads = $git->branchHeads();
$linesOfCode = 0;
$fileTypes = [];
$repository = $_POST['repository'];
$git = new Git($repository);

list($objects, $size) = explode(',', $repoSize['shell'][0]);
$repoObjects = preg_replace("/[^0-9]/", '', $objects);
$repoSize = trim($size);

foreach ($totalLines['shell'] as $file) {
$fileParts = array_filter(explode(' ', $file));
sort($fileParts, SORT_NUMERIC);
$linesOfCode += intval($fileParts[1]);

if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) {
$filePathParts = explode('.', $fileParts[0]);
$extension = trim(end($filePathParts));

if (!str_contains($extension, '/') && $extension) {
$fileTypes[$extension]['files']++;
$fileTypes[$extension]['lines'] += intval($fileParts[1]);
if ($_POST['page'] != 'settings') {
$repoSize = $git->size();
$overview = $git->log();
$branches = $git->branches();
$contributors = $git->contributors();
$totalFiles = $git->totalFiles();
$totalCommits = $git->totalCommits();
$totalLines = $git->totalLines();
$branchHeads = $git->branchHeads();
$linesOfCode = 0;
$fileTypes = [];

list($objects, $size) = explode(',', $repoSize['shell'][0]);
$repoObjects = preg_replace("/[^0-9]/", '', $objects);
$repoSize = trim($size);

foreach ($totalLines['shell'] as $file) {
$fileParts = array_filter(explode(' ', $file));
sort($fileParts, SORT_NUMERIC);
$linesOfCode += intval($fileParts[1]);

if (str_contains($fileParts[0], '.') && $fileParts[0][0] != '.' && !is_dir(ABSOLUTE_PATH . $repository . '.' . $fileParts[0][0])) {
$filePathParts = explode('.', $fileParts[0]);
$extension = trim(end($filePathParts));

if (!in_array($extension, $ignoreCodePageExtensions) && !str_contains($extension, '/') && $extension) {
$fileTypes[$extension]['files']++;
$fileTypes[$extension]['lines'] += intval($fileParts[1]);
}
}
}
}
}
110 changes: 110 additions & 0 deletions root/app/www/public/assets/js/misc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
(function($) {
'use strict';
$(function() {
var body = $('body');
var contentWrapper = $('.content-wrapper');
var scroller = $('.container-scroller');
var footer = $('.footer');
var sidebar = $('.sidebar');

//Add active class to nav-link based on url dynamically
//Active class can be hard coded directly in html file also as required

function addActiveClass(element) {
if (current === "") {
//for root url
if (element.attr('href').indexOf("index.html") !== -1) {
element.parents('.nav-item').last().addClass('active');
if (element.parents('.sub-menu').length) {
element.closest('.collapse').addClass('show');
element.addClass('active');
}
}
} else {
//for other url
if (element.attr('href').indexOf(current) !== -1) {
element.parents('.nav-item').last().addClass('active');
if (element.parents('.sub-menu').length) {
element.closest('.collapse').addClass('show');
element.addClass('active');
}
if (element.parents('.submenu-item').length) {
element.addClass('active');
}
}
}
}

var current = location.pathname.split("/").slice(-1)[0].replace(/^\/|\/$/g, '');
$('.nav li a', sidebar).each(function() {
var $this = $(this);
addActiveClass($this);
})

$('.horizontal-menu .nav li a').each(function() {
var $this = $(this);
addActiveClass($this);
})

//Close other submenu in sidebar on opening any

sidebar.on('show.bs.collapse', '.collapse', function() {
sidebar.find('.collapse.show').collapse('hide');
});


//Change sidebar and content-wrapper height
applyStyles();

function applyStyles() {
//Applying perfect scrollbar
if (!body.hasClass("rtl")) {
if ($('.settings-panel .tab-content .tab-pane.scroll-wrapper').length) {
const settingsPanelScroll = new PerfectScrollbar('.settings-panel .tab-content .tab-pane.scroll-wrapper');
}
if ($('.chats').length) {
const chatsScroll = new PerfectScrollbar('.chats');
}
if (body.hasClass("sidebar-fixed")) {
var fixedSidebarScroll = new PerfectScrollbar('#sidebar .nav');
}
}
}

$('[data-toggle="minimize"]').on("click", function() {
if ((body.hasClass('sidebar-toggle-display')) || (body.hasClass('sidebar-absolute'))) {
body.toggleClass('sidebar-hidden');
} else {
body.toggleClass('sidebar-icon-only');
}
});

//checkbox and radios
$(".form-check label,.form-radio label").append('<i class="input-helper"></i>');

//fullscreen
$("#fullscreen-button").on("click", function toggleFullScreen() {
if ((document.fullScreenElement !== undefined && document.fullScreenElement === null) || (document.msFullscreenElement !== undefined && document.msFullscreenElement === null) || (document.mozFullScreen !== undefined && !document.mozFullScreen) || (document.webkitIsFullScreen !== undefined && !document.webkitIsFullScreen)) {
if (document.documentElement.requestFullScreen) {
document.documentElement.requestFullScreen();
} else if (document.documentElement.mozRequestFullScreen) {
document.documentElement.mozRequestFullScreen();
} else if (document.documentElement.webkitRequestFullScreen) {
document.documentElement.webkitRequestFullScreen(Element.ALLOW_KEYBOARD_INPUT);
} else if (document.documentElement.msRequestFullscreen) {
document.documentElement.msRequestFullscreen();
}
} else {
if (document.cancelFullScreen) {
document.cancelFullScreen();
} else if (document.mozCancelFullScreen) {
document.mozCancelFullScreen();
} else if (document.webkitCancelFullScreen) {
document.webkitCancelFullScreen();
} else if (document.msExitFullscreen) {
document.msExitFullscreen();
}
}
})
});
})(jQuery);
15 changes: 15 additions & 0 deletions root/app/www/public/functions/common.php
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,18 @@ function byteConversion($bytes, $measurement = false, $dec = 2)
return round($bytes / pow(1024, 4), $dec);
}
}

function array_sort_by_key(&$array, $field, $direction = 'asc')
{
if (!is_array($array)) {
return $array;
}

uasort($array, function ($a, $b) use ($field, $direction) {
if ($direction == 'asc') {
return $a[$field] <=> $b[$field];
} else {
return $b[$field] <=> $a[$field];
}
});
}
2 changes: 2 additions & 0 deletions root/app/www/public/includes/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,5 @@

define('APP_DATA_PATH', '/config/');
define('SETTINGS_FILE', APP_DATA_PATH . 'settings.json');

$ignoreCodePageExtensions = ['txt', 'json', 'yml', 'tgz', 'zip', 'sql'];
1 change: 1 addition & 0 deletions root/app/www/public/includes/footer.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
<script src="assets/vendors/progressbar.js/progressbar.min.js"></script>
<script src="assets/js/off-canvas.js"></script>
<script src="assets/js/hoverable-collapse.js"></script>
<script src="assets/js/misc.js"></script>
<script src="<?= ABSOLUTE_PATH ?>js/common.js?t=<?= filemtime(ABSOLUTE_PATH . 'js/common.js') ?>" type="text/javascript"></script>
<script src="<?= ABSOLUTE_PATH ?>js/git.js?t=<?= filemtime(ABSOLUTE_PATH . 'js/git.js') ?>" type="text/javascript"></script>
</body>
Expand Down
2 changes: 1 addition & 1 deletion root/app/www/public/js/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ function loadPage(page)
$.ajax({
type: 'POST',
url: 'ajax/' + page + '.php',
data: '&m=init&repository=' + repository,
data: '&m=init&repository=' + repository + '&page=' + page,
success: function (resultData) {
$('#page-content').html(resultData);
}
Expand Down
1 change: 1 addition & 0 deletions root/app/www/public/loader.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
}
}
define('REPOSITORY_PATH', ($settings['global']['repositoryPath'] ? $settings['global']['repositoryPath'] : '/config/repositories/'));
$ignoreCodePageExtensions = $settings['pages']['code']['ignoreExtension'] ? explode(',', str_replace(' ', '', $settings['pages']['code']['ignoreExtension'])) : $ignoreCodePageExtensions;

//-- INCLUDE FUNCTIONS
$dir = ABSOLUTE_PATH . 'functions';
Expand Down

0 comments on commit 8f59ce0

Please sign in to comment.