Skip to content

Commit

Permalink
refactor: migrated FAQs overview page to controller (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Dec 23, 2024
1 parent 3718072 commit b2fe121
Show file tree
Hide file tree
Showing 16 changed files with 196 additions and 159 deletions.
2 changes: 1 addition & 1 deletion nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ server {
rewrite admin/api/(.*) /admin/api/index.php last;

# Administration pages
rewrite admin/(attachments|backup|category|comments|configuration|elasticsearch|export|glossary|group|import|instance|instances|news|password|questions|session-keep-alive|statistics|sticky-faqs|stopwords|system|tags|update|user) /admin/front.php last;
rewrite admin/(attachments|backup|category|comments|configuration|elasticsearch|export|faq|faqs|glossary|group|import|instance|instances|news|password|questions|session-keep-alive|statistics|sticky-faqs|stopwords|system|tags|update|user) /admin/front.php last;

# REST API v3.0 and v3.1
rewrite ^api/v3\.[01]/(.*) /api/index.php last;
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/.htaccess
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
# Administration API
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
# Administration pages
RewriteRule ^admin/(attachments|backup|category|comments|configuration|elasticsearch|export|glossary|group|import|instance|instances|news|password|questions|session-keep-alive|statistics|sticky-faqs|stopwords|system|tags|update|user) admin/front.php [L,QSA]
RewriteRule ^admin/(attachments|backup|category|comments|configuration|elasticsearch|export|faq|faqs|glossary|group|import|instance|instances|news|password|questions|session-keep-alive|statistics|sticky-faqs|stopwords|system|tags|update|user) admin/front.php [L,QSA]
# Private APIs
RewriteRule ^api/(autocomplete|bookmark/delete|bookmark/create|user/data/update|user/password/update|user/request-removal|user/remove-twofactor|contact|voting|register|captcha|share|comment/create|faq/create|question/create|webauthn/prepare|webauthn/register|webauthn/prepare-login|webauthn/login) api/index.php [L,QSA]
# Setup APIs
Expand Down
63 changes: 0 additions & 63 deletions phpmyfaq/admin/faqs.overview.php

This file was deleted.

4 changes: 2 additions & 2 deletions phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,8 @@
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
'edit_faq+delete_faq',
'faqs-overview',
'msgHeaderFAQOverview'
'msgHeaderFAQOverview',
'faqs'
);
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
PermissionType::FAQ_EDIT->value,
Expand Down Expand Up @@ -180,7 +181,6 @@
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'system', 'ad_system_info', 'system');

switch ($action) {
case 'faqs-overview':
case 'editentry':
case 'copyentry':
case 'question':
Expand Down
5 changes: 0 additions & 5 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,6 @@
// the various sections of the admin area
switch ($action) {
// functions for content administration
case 'faqs-overview':
require 'faqs.overview.php';
break;
case 'viewinactive':
case 'viewactive':
case 'takequestion':
case 'editentry':
case 'copyentry':
Expand Down
164 changes: 84 additions & 80 deletions phpmyfaq/assets/templates/admin/content/faq.overview.twig
Original file line number Diff line number Diff line change
@@ -1,92 +1,96 @@
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">
<i aria-hidden="true" class="bi bi-list-alt"></i>
{{ 'msgHeaderFAQOverview' | translate }}
</h1>
<div class="pmf-faq-overview-search col-4">
<form name="pmf-faq-search-autocomplete" id="pmf-faq-search-autocomplete" action="?action=faq-overview"
method="post" role="form">
{{ csrfTokenSearch | raw }}
<div class="input-group">
<input type="text" class="form-control" placeholder="{{ 'msgAdminSearchFaqs' | translate }}"
id="pmf-faq-overview-search-input" autocomplete="off">
<button class="btn btn-primary" type="button" id="pmf-faq-overview-search-button">
<i class="bi bi-search" aria-hidden="true"></i>
</button>
</div>
</form>
</div>
</div>
{% extends '@admin/index.twig' %}

{% if categories is empty %}
<div class="alert alert-danger" role="alert">
{{ 'msgErrorNoRecords' | translate }}
{% block content %}
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">
<i aria-hidden="true" class="bi bi-list-alt"></i>
{{ 'msgHeaderFAQOverview' | translate }}
</h1>
<div class="pmf-faq-overview-search col-4">
<form name="pmf-faq-search-autocomplete" id="pmf-faq-search-autocomplete" action="?action=faq-overview"
method="post" role="form">
{{ csrfTokenSearch | raw }}
<div class="input-group">
<input type="text" class="form-control" placeholder="{{ 'msgAdminSearchFaqs' | translate }}"
id="pmf-faq-overview-search-input" autocomplete="off">
<button class="btn btn-primary" type="button" id="pmf-faq-overview-search-button">
<i class="bi bi-search" aria-hidden="true"></i>
</button>
</div>
</form>
</div>
</div>
{% endif %}

<div class="accordion shadow" id="pm-admin-faq-overview">
<div class="accordion-item d-flex justify-content-start flex-wrap flex-md-nowrap align-items-center p-3 bg-secondary-subtle">
<div class="col-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-inactive">
<label class="form-check-label" for="pmf-checkbox-filter-inactive">
{{ 'msgOnlyInactiveFAQs' | translate }}
</label>
</div>
{% if categories is empty %}
<div class="alert alert-danger" role="alert">
{{ 'msgErrorNoRecords' | translate }}
</div>
<div class="col-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-new">
<label class="form-check-label" for="pmf-checkbox-filter-new">
{{ 'msgOnlyNewFAQs' | translate }}
</label>
{% endif %}

<div class="accordion shadow" id="pm-admin-faq-overview">
<div class="accordion-item d-flex justify-content-start flex-wrap flex-md-nowrap align-items-center p-3 bg-secondary-subtle">
<div class="col-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-inactive">
<label class="form-check-label" for="pmf-checkbox-filter-inactive">
{{ 'msgOnlyInactiveFAQs' | translate }}
</label>
</div>
</div>
<div class="col-2">
<div class="form-check">
<input class="form-check-input" type="checkbox" value="" id="pmf-checkbox-filter-new">
<label class="form-check-label" for="pmf-checkbox-filter-new">
{{ 'msgOnlyNewFAQs' | translate }}
</label>
</div>
</div>
</div>
</div>
{% for category in categories %}
<div class="accordion-item">
<div class="accordion-header category-header-indent-{{ category.indent }}">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#category-id-{{ category.id }}">
{% for category in categories %}
<div class="accordion-item">
<div class="accordion-header category-header-indent-{{ category.indent }}">
<button class="accordion-button collapsed" type="button" data-bs-toggle="collapse"
data-bs-target="#category-id-{{ category.id }}">

<span class="lead">{{ category.name }}</span>
<span class="badge bg-primary mx-1">{{ numberOfRecords[category.id] ?? 0 }} {{ 'msgEntries' | translate }}</span>
<span class="badge bg-info mx-1">{{ numberOfComments[category.id] ?? 0 }} {{ msgComments }}</span>
<span class="lead">{{ category.name }}</span>
<span class="badge bg-primary mx-1">{{ numberOfRecords[category.id] ?? 0 }} {{ 'msgEntries' | translate }}</span>
<span class="badge bg-info mx-1">{{ numberOfComments[category.id] ?? 0 }} {{ msgComments }}</span>

</button>
</div>
<div id="category-id-{{ category.id }}" class="accordion-collapse collapse" data-pmf-language="{{ category.lang }}"
data-bs-parent="#category-id-{{ category.id }}" data-pmf-categoryId="{{ category.id }}">
<div class="accordion-body">
<table class="table table-hover table-sm align-middle">
<thead class="thead-light">
<tr>
<th colspan="3" class="align-middle">
ID
</th>
<th class="align-middle">
{{ msgQuestion }}
</th>
<th class="align-middle">
{{ msgDate }}
</th>
<th class="align-middle">
{{ msgSticky }}
</th>
<th class="align-middle">
{{ 'msgActive' | translate }}
</th>
<th colspan="4" class="align-middle">
Actions
</th>
</tr>
</thead>
<tbody id="tbody-category-id-{{ category.id }}" data-pmf-csrf="{{ csrfTokenOverview }}">
</button>
</div>
<div id="category-id-{{ category.id }}" class="accordion-collapse collapse" data-pmf-language="{{ category.lang }}"
data-bs-parent="#category-id-{{ category.id }}" data-pmf-categoryId="{{ category.id }}">
<div class="accordion-body">
<table class="table table-hover table-sm align-middle">
<thead class="thead-light">
<tr>
<th colspan="3" class="align-middle">
ID
</th>
<th class="align-middle">
{{ msgQuestion }}
</th>
<th class="align-middle">
{{ msgDate }}
</th>
<th class="align-middle">
{{ msgSticky }}
</th>
<th class="align-middle">
{{ 'msgActive' | translate }}
</th>
<th colspan="4" class="align-middle">
Actions
</th>
</tr>
</thead>
<tbody id="tbody-category-id-{{ category.id }}" data-pmf-csrf="{{ csrfTokenOverview }}">

</tbody>
</table>
</tbody>
</table>
</div>
</div>
</div>
{% endfor %}
</div>
{% endfor %}
</div>
{% endblock %}
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/admin/dashboard.twig
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@
<div class="row no-gutters align-items-center">
<div class="col mr-2">
<div class="text-xs font-weight-bold mb-1">
<a class="text-white" href="?action=faqs-overview">
<a class="text-white" href="./faqs">
{{ 'ad_start_articles' | translate }}
</a>
</div>
Expand Down
2 changes: 1 addition & 1 deletion phpmyfaq/assets/templates/admin/header.twig
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@

<!-- Content -->
{% if secondLevelEntries['content'] != '' %}
<a class="nav-link {{ contentPage ? '' : 'collapsed' }}" href="?action=faqs-overview" data-bs-toggle="collapse"
<a class="nav-link {{ contentPage ? '' : 'collapsed' }}" href="./faqs" data-bs-toggle="collapse"
data-bs-target="#collapseContent" aria-expanded="false" aria-controls="collapseContent">
<div class="pmf-admin-nav-link-icon"><i aria-hidden="true" class="bi bi-pencil-square h6"></i></div>
{{ menuContent }}
Expand Down
6 changes: 6 additions & 0 deletions phpmyfaq/src/admin-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
use phpMyFAQ\Controller\Administration\ConfigurationController;
use phpMyFAQ\Controller\Administration\ElasticsearchController;
use phpMyFAQ\Controller\Administration\ExportController;
use phpMyFAQ\Controller\Administration\FaqController;
use phpMyFAQ\Controller\Administration\GlossaryController;
use phpMyFAQ\Controller\Administration\GroupController;
use phpMyFAQ\Controller\Administration\ImportController;
Expand Down Expand Up @@ -122,6 +123,11 @@
'controller' => [ConfigurationController::class, 'index'],
'methods' => 'GET'
],
'admin.faqs' => [
'path' => '/faqs',
'controller' => [FaqController::class, 'index'],
'methods' => 'GET'
],
'admin.elasticsearch' => [
'path' => '/elasticsearch',
'controller' => [ElasticsearchController::class, 'index'],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ protected function getHeader(Request $request): array
case 'admin.category.update':
case 'admin.content.sticky-faqs':
case 'admin.comments':
case 'admin.faqs':
case 'admin.glossary':
case 'admin.news':
case 'admin.news.add':
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,25 @@
<?php

/**
* The Administration Category Controller
*
* This Source Code Form is subject to the terms of the Mozilla Public License,
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
* obtain one at https://mozilla.org/MPL/2.0/.
*
* @package phpMyFAQ
* @author Thorsten Rinne <[email protected]>
* @copyright 2024 phpMyFAQ Team
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2024-12-04
*/

declare(strict_types=1);

namespace phpMyFAQ\Controller\Administration;

use phpMyFAQ\Category;
use phpMyFAQ\Category\Image;
use phpMyFAQ\Category\Permission;
use phpMyFAQ\Core\Exception;
use phpMyFAQ\Database;
Expand Down
Loading

0 comments on commit b2fe121

Please sign in to comment.