Skip to content

Commit

Permalink
Start work on article admin.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShaneMcC committed Mar 10, 2019
1 parent ee150ef commit 86686c1
Show file tree
Hide file tree
Showing 5 changed files with 167 additions and 1 deletion.
2 changes: 1 addition & 1 deletion mydnshost-php-api
3 changes: 3 additions & 0 deletions src/DisplayEngine.php
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,9 @@ public function showHeaderMenu() {
if ($this->hasPermission(['manage_domains'])) {
$menu[] = ['link' => $this->getURL('/admin/domains'), 'title' => 'Manage Domains', 'active' => ($this->pageID == '/admin/domains')];
}
if ($this->hasPermission(['manage_articles'])) {
$menu[] = ['link' => $this->getURL('/admin/articles'), 'title' => 'Manage Articles', 'active' => ($this->pageID == '/admin/aticles')];
}
if ($this->hasPermission(['system_stats'])) {
$menu[] = ['link' => $this->getURL('/admin/stats'), 'title' => 'System Statistics', 'active' => ($this->pageID == '/admin/stats')];
}
Expand Down
44 changes: 44 additions & 0 deletions src/routes/AdminRoutes.php
Original file line number Diff line number Diff line change
Expand Up @@ -195,5 +195,49 @@ public function addRoutes($router, $displayEngine, $api) {
return;
});
}


if ($displayEngine->hasPermission(['manage_articles'])) {
$router->get('/admin/articles', function() use ($displayEngine, $api) {
$displayEngine->setPageID('/admin/articles')->setTitle('Admin :: Articles');

$articles = $api->getAllArticles();
$displayEngine->setVar('articles', $articles);
$displayEngine->setVar('time', time());

$displayEngine->display('admin/articles.tpl');
});

$router->get('/admin/articles/(.*)', function($articleid) use ($displayEngine, $api) {
$displayEngine->setPageID('/admin/articles')->setTitle('Admin :: Articles :: ' . $articleid);

$article = $api->getArticle($articleid);
$displayEngine->setVar('article', $article);
$displayEngine->setVar('time', time());

$displayEngine->display('admin/article.tpl');
});

$router->post('/admin/articles/(.*)', function($articleid) use ($displayEngine, $api) {

});

$router->post('/admin/articles/(.*)/delete', function($articleid) use ($displayEngine, $api) {

});

$router->get('/admin/articles/create', function() use ($displayEngine, $api) {
$displayEngine->setPageID('/admin/articles')->setTitle('Admin :: Articles :: Create');
$displayEngine->setVar('create', true);
$displayEngine->setVar('time', time());
$displayEngine->display('admin/article.tpl');
});

$router->post('/admin/articles/create', function() use ($displayEngine, $api) {

});
}


}
}
58 changes: 58 additions & 0 deletions templates/default/admin/article.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
<H1>Article :: {{ article.id }}</H1>

<input type="hidden" id="csrftoken" value="{{csrftoken}}">

<table id="article" class="table table-striped table-bordered">
<tbody>
{% if not create %}
<tr>
<th>ID</th>
<td>
{{ article.id }}
</td>
</tr>
{% endif %}
<tr>
<th>Title</th>
<td>
<input type="text" name="title" value="{{ article.title }}" class="form-control form-control-sm">
</td>
</tr>
<tr>
<th>Content</th>
<td>
<textarea name="content" class="form-control form-control-sm">{{ article.content }}</textarea>
</td>
</tr>
<tr>
<th>Full Content</th>
<td>
<textarea name="contentfull" class="form-control form-control-sm">{{ article.contentfull }}</textarea>
</td>
</tr>
<tr>
<th>Created</th>
<td>
{% if not create %}
{{ article.created }} ({{ article.created | date }})
{% else %}
{{ time }} ({{ time | date }})
{% endif %}
</td>
</tr>
<tr>
<th>Visible From</th>
<td>
<input type="text" name="visiblefrom" value="{{ article.visiblefrom }}" class="form-control form-control-sm">
</td>
</tr>
<tr>
<th>Visible Until</th>
<td>
<input type="text" name="visibleuntil" value="{{ article.visibleuntil }}" class="form-control form-control-sm">
</td>
</tr>
</tbody>
</table>

<script src="{{ url('/assets/admin_article.js') }}"></script>
61 changes: 61 additions & 0 deletions templates/default/admin/articles.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<H1>Article List</H1>

<input type="hidden" id="csrftoken" value="{{csrftoken}}">
<input class="form-control" data-search-top="table#articlelist" value="" placeholder="Search..."><br>

<div class="float-right">
<a class="btn btn-block btn-success" href="{{ url('/admin/articles/create') }}">Add Article</a>
</div>
<br><br>

<table id="articlelist" class="table table-striped table-bordered">
<thead>
<tr>
<th class="id">ID</th>
<th class="title">Title</th>
<th class="content">Content</th>
<th class="visible">Visible</th>
<th class="actions">Actions</th>
</tr>
</thead>
<tbody>
{% for article in articles %}
<tr data-searchable-value="{{ article.title }}">
<td class="id">
{{ article.id }}
</td>
<td class="title">
{{ article.title }}
</td>
<td class="content">
{{ article.content }}
</td>
<td class="visible">
{% set visible = article.visiblefrom < time and (article.visibleuntil == -1 or article.visibleuntil > time) %}

<span class="value badge {% if visible %}badge-success{% else %}badge-danger{% endif %}">
{{ visible | yesno }}
</span>
</td>
<td class="actions">
{% if userinfo.email != user.email %}
<a href="{{ url('/admin/articles/' ~ article.id) }}" class="btn btn-sm btn-success">View/Edit</a>
<button data-action="deletearticle" data-id="{{ article.id }}" class="btn btn-sm btn-danger">Delete</a>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>

{% embed 'blocks/modal_confirm.tpl' with {'id': 'confirmDelete'} only %}
{% block title %}
Delete Article
{% endblock %}

{% block body %}
Are you sure you want to delete this Article?
{% endblock %}
{% endembed %}

<script src="{{ url('/assets/admin_articles.js') }}"></script>

0 comments on commit 86686c1

Please sign in to comment.