Skip to content

Commit

Permalink
Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
RobiNN1 committed Jul 16, 2024
1 parent 991c522 commit 892b591
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
FileCache ([`robinn/cache`](https://github.com/RobiNN1/Cache)) dashboard
for [phpCacheAdmin](https://github.com/RobiNN1/phpCacheAdmin).

![Visitor Badge](https://visitor-badge.laobi.icu/badge?page_id=RobiNN1.FileCache-Dashboard)
<p align="center"><img alt="FileCache" src=".github/img/filecache.png" width="300px"></p>

![FileCache](.github/img/filecache.png)
![Visitor Badge](https://visitor-badge.laobi.icu/badge?page_id=RobiNN1.FileCache-Dashboard)

## Installation

Expand Down Expand Up @@ -34,4 +34,4 @@ the project or have access to folders outside of website root.
## Requirements

- PHP >= 8.2
- phpCacheAdmin >= 1.6.0
- phpCacheAdmin >= 2.0.0
20 changes: 19 additions & 1 deletion src/FileCacheDashboard.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
class FileCacheDashboard implements DashboardInterface {
use FileCacheTrait;

final public const VERSION = '1.4.0';
final public const VERSION = '1.5.0';

/**
* @var array<int, array<string, int|string>>
Expand All @@ -32,6 +32,11 @@ class FileCacheDashboard implements DashboardInterface {

private FileStorage $filecache;

/**
* @var array<int, string>
*/
private array $all_keys = [];

public function __construct(private readonly Template $template) {
$this->template->addPath('filecache', __DIR__.'/../templates');

Expand Down Expand Up @@ -100,6 +105,19 @@ public function dashboard(): string {

try {
$this->filecache = $this->connect($this->projects[$this->current_project]);
$this->all_keys = $this->filecache->keys();

$projects = [];

foreach ($this->projects as $id => $project) {
if (!isset($project['name'])) {
$projects[$id]['name'] = 'Project '.$id;
}
}

$select = Helpers::serverSelector($this->template, $projects, $this->current_project);

$this->template->addGlobal('side', $select.$this->panels());

if (isset($_GET['view'], $_GET['key'])) {
return $this->viewKey();
Expand Down
34 changes: 9 additions & 25 deletions src/FileCacheTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,23 +16,20 @@
use RobiNN\Pca\Value;

trait FileCacheTrait {
/**
* @param array<int, string> $all_keys
*/
private function panels(array $all_keys): string {
private function panels(): string {
$project = $this->projects[$this->current_project];

$panels = [
[
'title' => 'FileCache <span>v'.Cache::VERSION.'</span>',
'title' => 'FileCache v'.Cache::VERSION,
'data' => [
'Path' => is_dir((string) $project['path']) ? realpath((string) $project['path']) : $project['path'],
'Files' => count($all_keys),
'Files' => count($this->all_keys),
],
],
];

return $this->template->render('partials/info', ['panels' => $panels, 'thead' => false]);
return $this->template->render('partials/info', ['panels' => $panels, 'left' => true]);
}

private function viewKey(): string {
Expand Down Expand Up @@ -65,18 +62,16 @@ private function viewKey(): string {
}

/**
* @param array<int, string> $all_keys
*
* @return array<int, array<string, string|int>>
*/
private function getAllKeys(array $all_keys): array {
private function getAllKeys(): array {
static $keys = [];
$search = Http::get('s', '');

$this->template->addGlobal('search_value', $search);

foreach ($all_keys as $key) {
if (count($all_keys) < 1000) {
foreach ($this->all_keys as $key) {
if (count($this->all_keys) < 1000) {
$ttl = $this->filecache->ttl($key);
$ttl = $ttl === 0 ? 'Doesn\'t expire' : $ttl;
}
Expand All @@ -96,24 +91,13 @@ private function getAllKeys(array $all_keys): array {
}

private function mainDashboard(): string {
$all_keys = $this->filecache->keys();
$keys = $this->getAllKeys($all_keys);
$keys = $this->getAllKeys();

$paginator = new Paginator($this->template, $keys);

$projects = [];

foreach ($this->projects as $id => $project) {
if (!isset($project['name'])) {
$projects[$id]['name'] = 'Project '.$id;
}
}

return $this->template->render('@filecache/filecache', [
'select' => Helpers::serverSelector($this->template, $projects, $this->current_project),
'panels' => $this->panels($all_keys),
'keys' => $paginator->getPaginated(),
'all_keys' => count($all_keys),
'all_keys' => count($this->all_keys),
'new_key_url' => Http::queryString([], ['form' => 'new']),
'paginator' => $paginator->render(),
'view_key' => Http::queryString([], ['view' => 'key', 'key' => '__key__']),
Expand Down
4 changes: 1 addition & 3 deletions templates/filecache.twig
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
<div class="md:grid md:grid-cols-2 md:gap-4">{{ select|raw }}</div>
{{ panels|raw }}
<div class="mb-3 lg:grid lg:grid-cols-2 lg:gap-4">
<div class="mb-4 lg:grid lg:grid-cols-2 lg:gap-4">
<div class="mb-3 md:grid md:grid-cols-2 md:gap-2 lg:mb-0">
{% if all_keys != 0 %}
<div>{{ include('components/search_input.twig') }}</div>
Expand Down

0 comments on commit 892b591

Please sign in to comment.