more progress.. got latest and counts working

This commit is contained in:
Andy Miller
2014-09-05 22:27:30 -06:00
parent 955f4c8db8
commit 05f7d1fd2e
12 changed files with 130 additions and 18 deletions

View File

@@ -78,6 +78,9 @@ class AdminPlugin extends Plugin
/** @var Pages $pages */
$pages = $this->grav['pages'];
$this->grav['admin']->routes = $pages->routes();
$pages->dispatch('/', true)->route($home);
}
@@ -91,8 +94,6 @@ class AdminPlugin extends Plugin
$this->template = $this->admin->user ? 'denied' : 'login';
}
// Make local copy of POST.
$post = !empty($_POST) ? $_POST : array();
@@ -148,9 +149,6 @@ class AdminPlugin extends Plugin
$twig->twig_vars['admin'] = $this->admin;
switch ($this->template) {
case 'plugins':
$twig->twig_vars['plugins'] = $this->grav['plugins']->all();
break;
case 'pages':
$twig->twig_vars['file'] = File\General::instance($this->admin->page(true)->filePath());
break;

View File

@@ -65,6 +65,7 @@ class Admin
*/
public $user;
/**
* Constructor.
*
@@ -294,6 +295,26 @@ class Admin
return $this->grav['themes']->all();
}
/**
* Get all routes.
*
* @return array
*/
public function routes()
{
return $this->grav['pages']->routes()->all();
}
/**
* Get all plugins.
*
* @return array
*/
public function plugins()
{
return $this->grav['plugins']->all();
}
/**
* Get log file for fatal errors.
*
@@ -301,11 +322,48 @@ class Admin
*/
public function logs()
{
$file = File\Log::instance(LOG_DIR . 'exception.log');
if (!isset($this->logs)) {
$file = File\Log::instance(LOG_DIR . 'exception.log');
$content = $file->content();
$content = $file->content();
return array_reverse($content);
$this->logs = array_reverse($content);
}
return $this->logs;
}
/**
* Used by the Dashboard in the admin to display the X latest pages
* that have been modified
*
* @param integer $count number of pages to pull back
* @return [type] [description]
*/
public function latestPages($count=10)
{
$latest = array();
foreach ($this->grav['pages']->routes() as $url => $path) {
$page = $this->grav['pages']->dispatch($url);
$latest[$page->route()] = ['modified'=>$page->modified(),'page'=>$page];
}
// sort based on modified
uasort($latest, function($a, $b) {
if ($a['modified'] == $b['modified']) {
return 0;
}
return ($a['modified'] > $b['modified']) ? -1 : 1;
});
// build new array with just pages in it
// TODO: Optimized this
$pages = array();
foreach ($latest as $item) {
$pages[] = $item['page'];
}
return array_slice($pages, 0, $count);
}
/**
@@ -379,4 +437,5 @@ class Admin
{
return dirname('/' . Grav::instance()['admin']->route);
}
}

View File

@@ -45,6 +45,16 @@ b, strong, label, th {
color: white;
font-size: 1.1rem; }
.badge {
font-size: 0.9rem;
font-family: "Lato", "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif;
font-weight: 700;
border-radius: 100%;
padding: 0px 6px;
min-width: 23px;
line-height: 23px;
text-align: center; }
.default-animation {
-webkit-transition: all 0.5s ease;
-moz-transition: all 0.5s ease;
@@ -269,7 +279,7 @@ td {
#admin-login {
background: #253a47;
max-width: 28rem;
max-width: 24rem;
margin: 0 auto; }
#admin-login h1 {
background: #20333e url(../images/logo.png) 50% 50% no-repeat;
@@ -347,6 +357,11 @@ td {
list-style: none; }
#admin-menu li {
font-family: "Montserrat", "Helvetica", "Tahoma", "Geneva", "Arial", sans-serif; }
#admin-menu li .badge {
background-color: #141f25;
color: #e5e5e5;
float: right;
margin-right: 1rem; }
#admin-menu li a {
-webkit-transition: all 0.2s ease;
-moz-transition: all 0.2s ease;

File diff suppressed because one or more lines are too long

View File

@@ -59,9 +59,17 @@ $topbar-height: 4.2rem;
list-style: none;
li {
font-family: $font-family-header;
.badge {
background-color: darken($accent-bg, 10%);
color: shade($accent-fg,10%);
float: right;
margin-right:1rem;
}
a {
@include transition(all 0.2s ease);

View File

@@ -31,3 +31,14 @@ b, strong {
font-size: 1.1rem;
}
.badge {
font-size: 0.9rem;
font-family: $font-family-default;
font-weight: 700;
border-radius: 100%;
padding: 0px 6px;
min-width: 23px;
line-height: 23px;
text-align: center;
}

View File

@@ -1,7 +1,7 @@
#admin-login {
@extend %vertical-align;
background: $accent-bg;
max-width: 28rem;
max-width: 24rem;
margin: 0 auto;
h1 {

View File

@@ -6,6 +6,14 @@
{% block content %}
<table>
{% for latest in admin.latestPages %}
<tr><td>{{ latest.title }}</td><td>{{ latest.url }}</td><td>{{ latest.modified|date }}</td></tr>
{% endfor %}
</table>
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod
tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam,
quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo

View File

@@ -17,7 +17,7 @@
{% endif %}
{% endfor %}
<div class="form-actions secondary-accent">
<button class="button secondary" name="task" value="forgot"><i class="fa fa-exclamation-circle"></i> Forgot Password</button>
<button class="button secondary" name="task" value="forgot"><i class="fa fa-exclamation-circle"></i> Forgot</button>
<button type="submit" class="button primary" name="task" value="login"><i class="fa fa-shield"></i> Login</button>
</div>
</form>

View File

@@ -21,13 +21,23 @@
<a href="{{ base_url_relative }}/configuration"><i class="fa fa-fw fa-wrench"></i> Configuration</a>
</li>
<li class="{{ (location == 'pages') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/pages"><i class="fa fa-fw fa-file-text-o"></i> Pages</a>
<a href="{{ base_url_relative }}/pages">
<i class="fa fa-fw fa-file-text-o"></i> Pages
<span class="badge">{{ admin.routes|length }}</span>
</a>
</li>
<li class="{{ (location == 'plugins') ? 'selected' : '' }} {{ plugins.count > 0 ? 'hasChildren' : '' }}">
<a href="{{ base_url_relative }}/plugins"><i class="fa fa-fw fa-puzzle-piece"></i> Plugins</a>
<a href="{{ base_url_relative }}/plugins">
<i class="fa fa-fw fa-puzzle-piece"></i> Plugins
<span class="badge">{{ admin.plugins|length }}</span>
</a>
</li>
<li class="{{ (location == 'themes') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/themes"><i class="fa fa-fw fa-tint"></i> Themes</a>
<a href="{{ base_url_relative }}/themes">
<i class="fa fa-fw fa-tint"></i> Themes
<span class="badge">{{ admin.themes|length }}</span>
</a>
</li>
<li class="{{ (location == 'installer') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/installer"><i class="fa fa-fw fa-cloud-download"></i> Installer</a>
@@ -36,7 +46,10 @@
<a href="{{ base_url_relative }}/users"><i class="fa fa-fw fa-child"></i> Users</a>
</li>
<li class="{{ (location == 'logs') ? 'selected' : '' }}">
<a href="{{ base_url_relative }}/logs"><i class="fa fa-fw fa-warning"></i> Error Logs</a>
<a href="{{ base_url_relative }}/logs">
<i class="fa fa-fw fa-warning"></i> Error Logs
<span class="badge">{{ admin.logs|length }}</span>
</a>
</li>
<li>
<a href="{{ base_url_relative }}/task:logout"><i class="fa fa-fw fa-power-off"></i> Logout</a>

View File

@@ -12,7 +12,7 @@
{% include 'partials/messages.html.twig' %}
<table>
{% for plugin in plugins %}
{% for plugin in admin.plugins %}
{% set blueprints = plugin.blueprints() %}
<tr>
@@ -32,7 +32,7 @@
{% endfor %}
</table>
{% else %}
{% set plugin = plugins[admin.route] %}
{% set plugin = admin.plugins[admin.route] %}
{% set blueprints = plugin.blueprints() %}
<h1>