Minor improvements

This commit is contained in:
Roman Hergenreder 2020-04-04 15:11:38 +02:00
parent 8ce74edc38
commit 8fc0b4bb05
6 changed files with 60 additions and 28 deletions

@ -51,7 +51,7 @@ class Fetch extends Request {
}
$sql = $this->user->getSQL();
$res = $sql->select("User.uid as userId", "User.name", "User.email", "User.created_at",
$res = $sql->select("User.uid as userId", "User.name", "User.email", "User.registered_at",
"Group.uid as groupId", "Group.name as groupName")
->from("User")
->leftJoin("UserGroup", "User.uid", "UserGroup.user_id")
@ -76,7 +76,7 @@ class Fetch extends Request {
"uid" => $userId,
"name" => $row["name"],
"email" => $row["email"],
"created_at" => $row["created_at"],
"registered_at" => $row["registered_at"],
"groups" => array(),
);
}
@ -90,4 +90,4 @@ class Fetch extends Request {
return $this->success;
}
}
}

@ -243,7 +243,7 @@ namespace Documents\Install {
if(is_string($sql)) {
$msg = "Error connecting to database: $sql";
} else if(!$sql->isConnected()) {
if (!$sql->checkRequirements()["success"]) {
if (!$sql->checkRequirements()) {
$driverName = $sql->getDriverName();
$installLink = "https://www.php.net/manual/en/$driverName.setup.php";
$link = $this->createExternalLink($installLink);
@ -809,4 +809,4 @@ namespace Documents\Install {
}
}
}
}

@ -31,16 +31,6 @@ class AdminDashboardBody extends Body {
}
}
private function getUsers() : array {
$req = new \Api\User\Fetch($this->getDocument()->getUser());
if(!$req->execute()) {
$this->errorMessages[] = $req->getLastError();
return array();
} else {
return $req->getResult()['users'];
}
}
private function getHeader() {
// Locale
@ -75,7 +65,7 @@ class AdminDashboardBody extends Body {
<a href=\"/\" class=\"nav-link\">$home</a>
</li>
</ul>
<!-- SEARCH FORM -->
<form class=\"form-inline ml-3\">
<div class=\"input-group input-group-sm\">
@ -87,7 +77,7 @@ class AdminDashboardBody extends Body {
</div>
</div>
</form>
<!-- Right navbar links -->
<ul class=\"navbar-nav ml-auto\">
<!-- Notifications Dropdown Menu -->
@ -135,6 +125,9 @@ class AdminDashboardBody extends Body {
private function getSidebar() {
$logout = L("Logout");
$iconLogout = $this->createIcon("arrow-left", "fas", "nav-icon");
$menuEntries = array(
"dashboard" => array(
"name" => "Dashboard",
@ -169,10 +162,10 @@ class AdminDashboardBody extends Body {
style=\"opacity: .8\">
<span class=\"brand-text font-weight-light\">WebBase</span>
</a>
<!-- Sidebar -->
<div class=\"sidebar\">
<!-- Sidebar Menu -->
<nav class=\"mt-2\">
<ul class=\"nav nav-pills nav-sidebar flex-column\" data-widget=\"treeview\" role=\"menu\" data-accordion=\"false\">";
@ -189,15 +182,19 @@ class AdminDashboardBody extends Body {
}
$html .=
"<li class=\"nav-item\">
"<li class=\"nav-item\">
<a href=\"?view=$view\" class=\"nav-link$active\">
$icon<p>$name$badge</p>
</a>
</li>";
}
$html .=
"</ul>
$html .= "<li class=\"nav-item\">
<a href=\"#\" id=\"btnLogout\" class=\"nav-link\">
$iconLogout<p>$logout</p>
</a>
</li>
</ul>
</nav>
</div>
</aside>";
@ -241,8 +238,6 @@ class AdminDashboardBody extends Body {
private function getContent() {
$this->getUsers();
$view = $this->getView();
$html = "<div class=\"content-wrapper p-2\">";

@ -85,13 +85,12 @@ class UserOverview extends AdminView {
private function getUserRows() {
$dateFormat = L("Y/m/d");
$userRows = array();
foreach($this->users as $uid => $user) {
$name = $user["name"];
$email = $user["email"] ?? "";
$registeredAt = (new DateTime($user["created_at"]))->format($dateFormat);
$registeredAt = formatDate($user["registered_at"]);
$groups = $this->getGroups($user["groups"]);
$userRows[] =
@ -161,4 +160,4 @@ class UserOverview extends AdminView {
return $html;
}
}
}

@ -140,7 +140,13 @@ function dateFunction($str, $d = NULL) {
}
function getPeriodString($d) {
if(!is_a($d, "DateTime")) $d = new DateTime($d);
try {
$d = new DateTime($d);
} catch(Exception $e) {
return L("Unknown");
}
$diff = datetimeDiff(new DateTime(), $d);
$diff = abs($diff);
@ -161,3 +167,27 @@ function getPeriodString($d) {
return L(sprintf($str, $diff));
}
function formatDateTime($d) {
$format = L("Y/m/d H:i:s");
return apply_format($d, $format);
}
function formatTime($d) {
$format = L("H:i:s");
return apply_format($d, $format);
}
function formatDate($d) {
$format = L("Y/m/d");
return apply_format($d, $format);
}
function apply_format($d, $fmt) {
try {
$dt = new DateTime($d);
return $dt->format($fmt);
} catch(Exception $e) {
return L("Unknown");
}
}

@ -48,4 +48,12 @@ $(document).ready(function() {
alert(err);
});
});
$("#btnLogout").click(function() {
jsCore.apiCall("/user/logout", function(data) {
document.location = "/admin";
}, function(err) {
alert("err");
});
});
});