Skip to content

Commit

Permalink
refactor: migrated forms page to controller (#3257)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Dec 27, 2024
1 parent b743c6f commit 430a4b3
Show file tree
Hide file tree
Showing 10 changed files with 192 additions and 179 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|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;
rewrite admin/(attachments|backup|category|comments|configuration|elasticsearch|export|faq|faqs|forms|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|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]
RewriteRule ^admin/(attachments|backup|category|comments|configuration|elasticsearch|export|faq|faqs|forms|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
61 changes: 0 additions & 61 deletions phpmyfaq/admin/forms.php

This file was deleted.

5 changes: 1 addition & 4 deletions phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@
'ad_menu_editconfig',
'configuration'
);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('forms_edit', 'forms', 'msgEditForms');
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('forms_edit', 'forms', 'msgEditForms', 'forms');
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
'editinstances+addinstances+delinstances',
'instances',
Expand All @@ -182,9 +182,6 @@
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('editconfig', 'system', 'ad_system_info', 'system');

switch ($action) {
case 'forms':
$configurationPage = true;
break;
default:
$dashboardPage = true;
break;
Expand Down
9 changes: 0 additions & 9 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,16 +256,7 @@
if (!is_null($action)) {
// the various sections of the admin area
switch ($action) {
// functions for content administration
case 'takequestion':
case 'editentry':
case 'copyentry':
require 'faqs.editor.php';
break;
// Config administration
case 'forms':
require 'forms.php';
break;
case 'forms-translations':
require 'forms.translations.php';
break;
Expand Down
194 changes: 100 additions & 94 deletions phpmyfaq/assets/templates/admin/configuration/forms.twig
Original file line number Diff line number Diff line change
@@ -1,112 +1,118 @@
<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-textarea-resize"></i> {{ msgEditForms }}
</h1>
</div>
{% extends '@admin/index.twig' %}

<div class="row mb-2">
<div class="col">
<ul class="nav nav-tabs" id="navigation" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="ask-question-tab" data-toggle="tab" href="#" role="tab"
aria-controls="home" aria-selected="true">{{ msgQuestion }}</a>
</li>
<li class="nav-item">
<a class="nav-link" id="add-content-tab" data-toggle="tab" href="#" role="tab"
aria-controls="profile" aria-selected="false">{{ msgAddContent }}</a>
</li>
</ul>
{% 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-textarea-resize"></i> {{ msgEditForms }}
</h1>
</div>

<div class="row mb-2">
<div class="col">
<ul class="nav nav-tabs" id="navigation" role="tablist">
<li class="nav-item">
<a class="nav-link active" id="ask-question-tab" data-toggle="tab" href="#" role="tab"
aria-controls="home" aria-selected="true">{{ msgQuestion }}</a>
</li>
<li class="nav-item">
<a class="nav-link" id="add-content-tab" data-toggle="tab" href="#" role="tab"
aria-controls="profile" aria-selected="false">{{ msgAddContent }}</a>
</li>
</ul>

<div class="tab-content" id="forms" data-pmf-formid="1">
<div class="tab-pane fade show active" id="ask-question" role="tabpanel" aria-labelledby="ask-question-tab">
<table class="table">
<thead>
<tr>
<th scope="col">{{ ad_entry_id }}</th>
<th scope="col">{{ msgInputLabel }}</th>
<th scope="col">{{ msgInputType }}</th>
<th scope="col">{{ ad_entry_active }}</th>
<th scope="col">{{ msgRequiredInputField }}</th>
<th scope="col">{{ ad_categ_translate }}</th>
</tr>
</thead>
<tbody>
{% for input in formDataAskQuestion %}
<div class="tab-content" id="forms" data-pmf-formid="1">
<div class="tab-pane fade show active" id="ask-question" role="tabpanel" aria-labelledby="ask-question-tab">
<table class="table">
<thead>
<tr>
<th>{{ input.input_id }}</th>
<td>{{ input.input_label }}</td>
<td>{{ input.input_type }}</td>
<td>
<input type="checkbox" data-pmf-inputid="{{ input.input_id }}" data-pmf-csrf-token="{{ csrfActivate }}"
data-pmf-formid="1"
id="active" {% if input.input_active %} checked {% endif %} {% if input.input_active == -1 %} disabled {% endif %} />
</td>
<td>
{% if input.input_type != 'title' and input.input_type != 'message' %}
<th scope="col">{{ ad_entry_id }}</th>
<th scope="col">{{ msgInputLabel }}</th>
<th scope="col">{{ msgInputType }}</th>
<th scope="col">{{ ad_entry_active }}</th>
<th scope="col">{{ msgRequiredInputField }}</th>
<th scope="col">{{ ad_categ_translate }}</th>
</tr>
</thead>
<tbody>
{% for input in formDataAskQuestion %}
<tr>
<th>{{ input.input_id }}</th>
<td>{{ input.input_label }}</td>
<td>{{ input.input_type }}</td>
<td>
<input type="checkbox" data-pmf-inputid="{{ input.input_id }}"
data-pmf-csrf-token="{{ csrfRequired }}"
data-pmf-csrf-token="{{ csrfActivate }}"
data-pmf-formid="1"
id="required" {% if input.input_required %} checked {% endif %} {% if input.input_required == -1 %} disabled {% endif %} />
{% endif %}
</td>
<td>
<a href="?action=forms-translations&formid={{ input.form_id }}&inputid={{ input.input_id }}">
id="active" {% if input.input_active %} checked {% endif %} {% if input.input_active == -1 %} disabled {% endif %} />
</td>
<td>
{% if input.input_type != 'title' and input.input_type != 'message' %}
<input type="checkbox" data-pmf-inputid="{{ input.input_id }}"
data-pmf-csrf-token="{{ csrfRequired }}"
data-pmf-formid="1"
id="required" {% if input.input_required %} checked {% endif %} {% if input.input_required == -1 %} disabled {% endif %} />
{% endif %}
</td>
<td>
<a href="?action=forms-translations&formid={{ input.form_id }}&inputid={{ input.input_id }}">
<span class="badge bg-primary">
<i aria-hidden="true" class="bi bi-globe bi-white"></i></span>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
<div class="tab-content" id="forms" data-pmf-formid="2">
<div class="tab-pane fade show" id="add-content" role="tabpanel" aria-labelledby="add-content-tab">
<table class="table">
<thead>
<tr>
<th scope="col">{{ ad_entry_id }}</th>
<th scope="col">{{ msgInputLabel }}</th>
<th scope="col">{{ msgInputType }}</th>
<th scope="col">{{ ad_entry_active }}</th>
<th scope="col">{{ msgRequiredInputField }}</th>
<th scope="col">{{ ad_categ_translate }}</th>
</tr>
</thead>
<tbody>
{% for input in formDataAddContent %}
<div class="tab-content" id="forms" data-pmf-formid="2">
<div class="tab-pane fade show" id="add-content" role="tabpanel" aria-labelledby="add-content-tab">
<table class="table">
<thead>
<tr>
<th>{{ input.input_id }}</th>
<td>{{ input.input_label }}</td>
<td>{{ input.input_type }}</td>
<td>
<input type="checkbox" data-pmf-inputid="{{ input.input_id }}" data-pmf-csrf-token="{{ csrfActivate }}"
data-pmf-formid="2"
id="active" {% if input.input_active %} checked {% endif %} {% if input.input_active == -1 %} disabled {% endif %} />
</td>
<td>
{% if input.input_type != 'title' and input.input_type != 'message' %}
<th scope="col">{{ ad_entry_id }}</th>
<th scope="col">{{ msgInputLabel }}</th>
<th scope="col">{{ msgInputType }}</th>
<th scope="col">{{ ad_entry_active }}</th>
<th scope="col">{{ msgRequiredInputField }}</th>
<th scope="col">{{ ad_categ_translate }}</th>
</tr>
</thead>
<tbody>
{% for input in formDataAddContent %}
<tr>
<th>{{ input.input_id }}</th>
<td>{{ input.input_label }}</td>
<td>{{ input.input_type }}</td>
<td>
<input type="checkbox" data-pmf-inputid="{{ input.input_id }}"
data-pmf-csrf-token="{{ csrfActivate }}"
data-pmf-formid="2"
id="active" {% if input.input_active %} checked {% endif %} {% if input.input_active == -1 %} disabled {% endif %} />
</td>
<td>
{% if input.input_type != 'title' and input.input_type != 'message' %}
<input type="checkbox" data-pmf-inputid="{{ input.input_id }}"
data-pmf-csrf-token="{{ csrfRequired }}"
data-pmf-formid="2"
id="required" {% if input.input_required %} checked {% endif %} {% if input.input_required == -1 %} disabled {% endif %}/>
{% endif %}
</td>
<td>
<a href="?action=forms-translations&formid={{ input.form_id }}&inputid={{ input.input_id }}">
{% endif %}
</td>
<td>
<a href="?action=forms-translations&formid={{ input.form_id }}&inputid={{ input.input_id }}">
<span class="badge bg-primary">
<i aria-hidden="true" class="bi bi-globe bi-white"></i></span>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</a>
</td>
</tr>
{% endfor %}
</tbody>
</table>
</div>
</div>
</div>
</div>
</div>
<div class="mt-4 alert alert-info" role="alert">
{{ msgHintDeactivateForms|raw }}
</div>
<div class="mt-4 alert alert-info" role="alert">
{{ msgHintDeactivateForms|raw }}
</div>
{% endblock %}
6 changes: 6 additions & 0 deletions phpmyfaq/src/admin-routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
use phpMyFAQ\Controller\Administration\ElasticsearchController;
use phpMyFAQ\Controller\Administration\ExportController;
use phpMyFAQ\Controller\Administration\FaqController;
use phpMyFAQ\Controller\Administration\FormsController;
use phpMyFAQ\Controller\Administration\GlossaryController;
use phpMyFAQ\Controller\Administration\GroupController;
use phpMyFAQ\Controller\Administration\ImportController;
Expand Down Expand Up @@ -153,6 +154,11 @@
'controller' => [FaqController::class, 'index'],
'methods' => 'GET'
],
'admin.forms' => [
'path' => '/forms',
'controller' => [FormsController::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 @@ -190,7 +190,12 @@ protected function getHeader(Request $request): array
'ad_menu_editconfig',
'configuration'
);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry('forms_edit', 'forms', 'msgEditForms');
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
'forms_edit',
'forms',
'msgEditForms',
'forms'
);
$secLevelEntries['config'] .= $adminHelper->addMenuEntry(
'editinstances+addinstances+delinstances',
'instances',
Expand Down Expand Up @@ -224,14 +229,6 @@ protected function getHeader(Request $request): array
'system'
);

switch ($action) {
case 'forms':
$configurationPage = true;
break;
default:
break;
}

switch ($request->attributes->get('_route')) {
case 'admin.group':
case 'admin.group.add':
Expand Down Expand Up @@ -293,6 +290,7 @@ protected function getHeader(Request $request): array
break;
case 'admin.configuration':
case 'admin.elasticsearch':
case 'admin.forms':
case 'admin.instance.edit':
case 'admin.instance.update':
case 'admin.instances':
Expand Down
Loading

0 comments on commit 430a4b3

Please sign in to comment.