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
Add overview page settings
Graph adjustments
  • Loading branch information
austinwbest committed Jan 31, 2024
1 parent 946d705 commit 5fb6c49
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 79 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
82 changes: 45 additions & 37 deletions root/app/www/public/ajax/contributors.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
?><h3>Contributors <br><code><?= $repository ?></code></h3><hr><?php

?><div class="row"><?php

foreach ($contributors['shell'] as $contributor) {
$parts = explode("\t", $contributor);
$parts = array_filter($parts);
Expand All @@ -30,6 +31,7 @@
$newestCommit = $commitHistory['shell'][1];

$changed = $added = $removed = 0;

foreach ($authorStats['shell'] as $line) {
if (str_contains($line, 'change') || str_contains($line, '(+)') || str_contains($line, '(-)')) {
$lineParts = explode(',', trim($line));
Expand Down Expand Up @@ -79,57 +81,64 @@
}
$oldest = $timestamp;

$graphPoints[date('Y-m-d', $timestamp)]++;
if (count($graphPoints) <= 24) {
$graphPoints[date('Y-m', $timestamp)]++;
}
}
ksort($graphPoints);

$labels = $data = '';
foreach ($graphPoints as $graphPointDate => $graphPointCount) {
$labels .= ($labels ? ', ' : '') . '"' . $graphPointDate . '"';
$data .= ($data ? ', ' : '') . intval($graphPointCount);
$label = date('M. y', strtotime($graphPointDate . '-1 12:00:00'));

$labels .= ($labels ? ', ' : '') . '"' . $label . '"';
$data .= ($data ? ', ' : '') . intval($graphPointCount);
}
?>
<div class="col-sm-12 grid-margin stretch-card">
<div class="card">
<div class="card-body">
<h4><?= $author ?></h4>
<div class="bg-gray-dark d-flex d-md-block d-xl-flex flex-row py-3 px-4 px-md-3 px-xl-4 rounded mt-3">
<div class="col-xl-3 col-sm-6">
<div class="card">
<div class="card-body">
Commits: <span class="text-muted"><?= number_format($commits) ?>/<?= number_format($totalCommits['shell']) ?></span><br>
<?php if ($newest) { ?>
Newest: <span class="text-muted"><?= date('M. jS, Y', $newest) ?></span><br>
<?php } ?>
<?php if ($oldest) { ?>
Oldest: <span class="text-muted"><?= date('M. jS, Y', $oldest) ?></span><br>
<?php } ?>
Files changed: <span class="text-muted"><?= number_format($changed) ?></span><br>
Lines added: <span class="text-muted"><?= number_format($added) ?></span><br>
Lines removed: <span class="text-muted"><?= number_format($removed) ?></span><br>
<div class="bg-gray-dark rounded">
<div class="row">
<div class="col-lg-3 col-sm-12">
<div class="card ms-2 mt-2">
<div class="card-body">
Commits: <span class="text-muted"><?= number_format($commits) ?>/<?= number_format($totalCommits['shell']) ?></span><br>
<?php if ($newest) { ?>
Newest: <span class="text-muted"><?= date('M. jS, Y', $newest) ?></span><br>
<?php } ?>
<?php if ($oldest) { ?>
Oldest: <span class="text-muted"><?= date('M. jS, Y', $oldest) ?></span><br>
<?php } ?>
Files changed: <span class="text-muted"><?= number_format($changed) ?></span><br>
Lines added: <span class="text-muted"><?= number_format($added) ?></span><br>
Lines removed: <span class="text-muted"><?= number_format($removed) ?></span><br>
</div>
</div>
</div>
</div>
<div class="col-xl-4 col-sm-6">
<div class="card">
<div class="card-body">
<?php
if (!empty($newestCommit)) {
<div class="col-lg-4 col-sm-12">
<div class="card mt-2">
<div class="card-body">
<?php
if (!empty($newestCommit)) {
?>
Commit: <?= substr(trim(str_replace('commit', '', $newestCommit[0])), 0, 7) ?><br>
Date: <?= trim(str_replace('Date:', '', $newestCommit[2])) ?><br>
<ul><li><?= implode('</li><li>', array_slice($newestCommit, 3)) ?></li></ul>
<?php
} else {
?>No commit information found.<?php
}
?>
Commit: <?= substr(trim(str_replace('commit', '', $newestCommit[0])), 0, 7) ?><br>
Date: <?= trim(str_replace('Date:', '', $newestCommit[2])) ?><br>
<ul><li><?= implode('</li><li>', array_slice($newestCommit, 3)) ?></li></ul>
<?php
} else {
?>No commit information found.<?php
}
?>
</div>
</div>
</div>
</div>
<div class="col-xl-5 col-sm-6">
<div class="card">
<div class="card-body">
<canvas id="contributor-<?= $graphHash ?>"></canvas>
<div class="col-lg-5 col-sm-12">
<div class="card me-2 mb-2 mt-2">
<div class="card-body">
<canvas id="contributor-<?= $graphHash ?>"></canvas>
</div>
</div>
</div>
</div>
Expand Down Expand Up @@ -163,5 +172,4 @@
<?php
}
?></div><?php

}
44 changes: 40 additions & 4 deletions root/app/www/public/ajax/overview.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,32 @@
}
}

$newest = $settings['pages']['overview']['displayNewest'] ? $settings['pages']['overview']['displayNewest'] : 100;
$oldest = $settings['pages']['overview']['displayOldest'] ? $settings['pages']['overview']['displayOldest'] : 100;
$hidden = 0;
$commits = $overview['shell'];

if (count($commits) > ($newest + $oldest)) {
$newestCommits = $oldestCommits = [];
$hidden = count($commits) - ($newest + $oldest);
$newestCommits = array_slice($commits, 0, $newest);
$oldestCommits = array_slice($commits, ($oldest * -1));

$commits = [];
foreach ($newestCommits as $newestCommit) {
$commits[] = $newestCommit;
}
foreach ($oldestCommits as $oldestCommit) {
$commits[] = $oldestCommit;
}
}

$display = '';
foreach ($overview['shell'] as $line) {
list($tree, $stuff) = explode('{', $line);
foreach ($commits as $commitIndex => $commit) {
list($tree, $stuff) = explode('{', $commit);
$display .= '<span>' . str_pad($tree, $treeSpacing, ' ', STR_PAD_RIGHT) . '</span>';

$details = str_replace($tree, '', $line);
$details = str_replace($tree, '', $commit);
$details = preg_match($regex, $details, $matches);
$hash = str_replace('hash:', '', $matches['hash']);
$date = str_replace('date:', '', $matches['date']);
Expand Down Expand Up @@ -76,6 +96,22 @@
$display .= str_pad($email, ($emailSpacing - strlen($author)), ' ', STR_PAD_RIGHT);
$display .= ' ' . trim($branch) . ' ' . str_replace('note:', '', $matches['note']);
$display .= '<br>';

if ($hidden > 0 && ($commitIndex + 1) == $newest) {
$hiddenLine = '~~~~~~~~~~~~~~~[ Truncated commits: ' . $hidden . ' ]~~~~~~~~~~~~~~~';

$display .= '<br>';
for ($x = 0; $x < strlen($hiddenLine) + 2; $x++) {
$display .= '~';
}

$display .= '<br> ' . $hiddenLine . ' <br>';

for ($x = 0; $x < strlen($hiddenLine) + 2; $x++) {
$display .= '~';
}
$display .= '<br><br>';
}
}

?>
Expand All @@ -96,7 +132,7 @@
</div>
<div class="text-md-center text-xl-left me-5">
<h6 class="mb-1">Objects</h6>
<p class="text-muted mb-0"><?= number_format($repoObjects) ?></p>
<p class="text-muted mb-0"><?= $repoObjects ?></p>
</div>
<div class="text-md-center text-xl-left me-5">
<h6 class="mb-1">Size</h6>
Expand Down
37 changes: 33 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,46 @@
?>
<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>Ignore</td>
<td><input type="text" class="form-control setting" id="global-ignoreDirectories" value="<?= implode(', ', $ignoreDirectories) ?>"></td>
<td>Ignore these directories for all calculations</td>
</tr>
<tr><td colspan="3"><h5>Page: Overview</h5></td></tr>
<tr>
<td>Display newest</td>
<td><input type="number" class="form-control setting" id="pages-overview-displayNewest" value="<?= ($settings['pages']['overview']['displayNewest'] ? $settings['pages']['overview']['displayNewest'] : 100) ?>"></td>
<td>Amount of commits (newest) to show</td>
</tr>
<tr>
<td>Display oldest</td>
<td><input type="number" class="form-control setting" id="pages-overview-displayOldest" value="<?= ($settings['pages']['overview']['displayOldest'] ? $settings['pages']['overview']['displayOldest'] : 100) ?>"></td>
<td>Amount of commits (oldest) to show</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 +71,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
62 changes: 36 additions & 26 deletions root/app/www/public/ajax/shared.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,45 @@
}
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);
if ($_POST['page'] != 'settings') {
$repoObjects = $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 = [];

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));
foreach ($repoObjects['shell'] as $repoSizeObject) {
if (str_contains($repoSizeObject, 'count') || str_contains($repoSizeObject, 'in-pack')) {
$repoObjectCount += preg_replace("/[^0-9]/", '', $repoSizeObject);
}
if (str_contains($repoSizeObject, 'size') || str_contains($repoSizeObject, 'size-pack')) {
$repoSizeTotal += preg_replace("/[^0-9]/", '', $repoSizeObject);
}
}
$repoObjects = number_format(intval($repoObjectCount));
$repoSize = byteConversion(intval($repoSizeTotal) * 1000);

if (!str_contains($extension, '/') && $extension) {
$fileTypes[$extension]['files']++;
$fileTypes[$extension]['lines'] += intval($fileParts[1]);
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]);
}
}
}
}
Loading

0 comments on commit 5fb6c49

Please sign in to comment.