Skip to content

Commit

Permalink
move filter and pagination to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
michnhokn committed Nov 12, 2021
1 parent c71f75d commit 8e3b35c
Show file tree
Hide file tree
Showing 7 changed files with 458 additions and 71 deletions.
2 changes: 1 addition & 1 deletion index.css
Original file line number Diff line number Diff line change
@@ -1 +1 @@
table{width:100%;border-collapse:collapse}table td,table th{padding:6px 12px;text-align:left;border:1px solid var(--color-border)}
table{width:100%;border-collapse:collapse}table td,table th{padding:6px 12px;text-align:left;border:1px solid var(--color-border)}.selected{font-weight:bold}
12 changes: 1 addition & 11 deletions index.js

Large diffs are not rendered by default.

20 changes: 16 additions & 4 deletions index.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,23 @@
Logger::log($event);
},
],
'api' => [
'routes' => [
[
'pattern' => 'logs.json',
'method' => 'POST',
'action' => function () {
return Logger::logs(
$this->requestBody('page', 1),
$this->requestBody('limit', 10),
$this->requestBody('filter', [])
);
},
],
],
],
'areas' => [
'kirby3-logger' => function ($kirby) {
'kirby3-logger' => function () {
return [
'label' => 'Logger',
'icon' => 'table',
Expand All @@ -25,9 +40,6 @@
return [
'component' => 'k-logger-area',
'title' => 'Logs',
'props' => [
'logs' => Logger::logs(),
],
];
},
],
Expand Down
6 changes: 4 additions & 2 deletions logs-schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ CREATE TABLE IF NOT EXISTS logs
type TEXT NOT NULL,
action TEXT NOT NULL,
user TEXT NULL,
old TEXT NOT NULL,
new TEXT NOT NULL,
slug TEXT NOT NULL,
language TEXT NOT NULL,
oldData TEXT NULL,
newData TEXT NOT NULL,
timestamp TEXT NOT NULL DEFAULT current_timestamp
);
146 changes: 146 additions & 0 deletions src/Log.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
<?php

class Log
{
private ?string $type;
private ?string $action;
private ?string $user;
private ?string $slug;
private ?string $language;
private $oldData;
private $newData;

public function __construct(array $parameter = null)
{
$this->type = $parameter['type'] ?? null;
$this->action = $parameter['action'] ?? null;
$this->user = $parameter['user'] ?? null;
$this->slug = $parameter['slug'] ?? null;
$this->language = $parameter['language'] ?? null;
}

public function toArray(): array
{
return [
'type' => $this->type,
'action' => $this->action,
'user' => $this->user,
'slug' => $this->slug,
'language' => $this->language,
'oldData' => $this->oldData,
'newData' => $this->newData,
];
}

/**
* @return string
*/
public function getType(): string
{
return $this->type;
}

/**
* @return string
*/
public function getAction(): string
{
return $this->action;
}

/**
* @param string $action
*/
public function setAction(string $action): void
{
$this->action = $action;
}

/**
* @return string
*/
public function getUser(): string
{
return $this->user;
}

/**
* @param string $user
*/
public function setUser(string $user): void
{
$this->user = $user;
}

/**
* @return string
*/
public function getSlug(): string
{
return $this->slug;
}

/**
* @param string $slug
*/
public function setSlug(string $slug): void
{
$this->slug = $slug;
}

/**
* @return string
*/
public function getLanguage(): string
{
return $this->language;
}

/**
* @param string $language
*/
public function setLanguage(string $language): void
{
$this->language = $language;
}

/**
* @return
*/
public function getOldData()
{
return $this->oldData;
}

/**
* @param $oldData
*/
public function setOldData($oldData = null)
{
$this->oldData = $oldData;
}

/**
* @return
*/
public function getNewData()
{
return $this->newData;
}

/**
* @param $newData
*/
public function setNewData($newData): void
{
$this->newData = $newData;
}

/**
* @param string $type
*/
public function setType(string $type): void
{
$this->type = $type;
}
}
Loading

0 comments on commit 8e3b35c

Please sign in to comment.