Skip to content

Commit 0058aac

Browse files
committed
refactor: migrated open questions page to controller (#3257)
1 parent 39cdf8d commit 0058aac

File tree

19 files changed

+292
-183
lines changed

19 files changed

+292
-183
lines changed

nginx.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ server {
129129
rewrite admin/api/(.*) /admin/api/index.php last;
130130

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

134134
# REST API v3.0 and v3.1
135135
rewrite ^api/v3\.[01]/(.*) /api/index.php last;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"type": "module",
2121
"scripts": {
2222
"build": "vite build",
23-
"build:watch": "vite build --watch -d",
23+
"build:watch": "vite build --watch",
2424
"build:prod": "vite build",
2525
"lint": "prettier --check .",
2626
"lint:fix": "prettier --write .",

phpmyfaq/.htaccess

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ Header set Access-Control-Allow-Headers "Content-Type, Authorization"
143143
# Administration API
144144
RewriteRule ^admin/api/(.*) admin/api/index.php [L,QSA]
145145
# Administration pages
146-
RewriteRule ^admin/(attachments|backup|comments|configuration|elasticsearch|export|glossary|group|import|instance|instances|password|news|session-keep-alive|statistics|stopwords|system|tags|update|user) admin/front.php [L,QSA]
146+
RewriteRule ^admin/(attachments|backup|comments|configuration|elasticsearch|export|glossary|group|import|instance|instances|news|password|questions|session-keep-alive|statistics|stopwords|system|tags|update|user) admin/front.php [L,QSA]
147147
# Private APIs
148148
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]
149149
# Setup APIs

phpmyfaq/admin/assets/src/api/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ export * from './faqs';
33
export * from './glossary';
44
export * from './group';
55
export * from './news';
6+
export * from './question';
67
export * from './statistics';
78
export * from './tags';
89
export * from './upgrade';
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/**
2+
* Fetch data for open questions management
3+
*
4+
* This Source Code Form is subject to the terms of the Mozilla Public License,
5+
* v. 2.0. If a copy of the MPL was not distributed with this file, You can
6+
* obtain one at https://mozilla.org/MPL/2.0/.
7+
*
8+
* @package phpMyFAQ
9+
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
10+
* @copyright 2024 phpMyFAQ Team
11+
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
12+
* @link https://www.phpmyfaq.de
13+
* @since 2024-12-02
14+
*/
15+
16+
export const toggleQuestionVisibility = async (questionId, visibility, csrfToken) => {
17+
try {
18+
const response = await fetch(`./api/question/visibility/toggle`, {
19+
method: 'PUT',
20+
headers: {
21+
'Content-Type': 'application/json',
22+
},
23+
body: JSON.stringify({
24+
questionId: questionId,
25+
visibility: visibility,
26+
csrfToken: csrfToken,
27+
}),
28+
});
29+
30+
return await response.json();
31+
} catch (error) {
32+
console.error(error);
33+
}
34+
};

phpmyfaq/admin/assets/src/content/question.js

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,10 @@
1212
* @link https://www.phpmyfaq.de
1313
* @since 2023-03-04
1414
*/
15+
1516
import { addElement, serialize } from '../../../../assets/src/utils';
17+
import { toggleQuestionVisibility } from '../api/index.js';
18+
import { pushErrorNotification } from '../utils/index.js';
1619

1720
export const handleOpenQuestions = () => {
1821
const deleteButton = document.getElementById('pmf-delete-questions');
@@ -62,3 +65,29 @@ export const handleOpenQuestions = () => {
6265
});
6366
}
6467
};
68+
69+
export const handleToggleVisibility = () => {
70+
const toggleVisibility = document.querySelectorAll('.pmf-toggle-visibility');
71+
72+
if (toggleVisibility) {
73+
toggleVisibility.forEach((element) => {
74+
element.addEventListener('click', async (event) => {
75+
event.preventDefault();
76+
77+
const questionId = element.getAttribute('data-pmf-question-id');
78+
const visibility = element.getAttribute('data-pmf-visibility');
79+
const csrfToken = element.getAttribute('data-pmf-csrf');
80+
81+
const response = await toggleQuestionVisibility(questionId, visibility, csrfToken);
82+
83+
if (response.success) {
84+
element.innerText = response.success;
85+
} else {
86+
pushErrorNotification(response.error);
87+
}
88+
89+
console.log(questionId, visibility, csrfToken);
90+
});
91+
});
92+
}
93+
};

phpmyfaq/admin/assets/src/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ import {
5959
handleSaveFaqData,
6060
handleUpdateQuestion,
6161
handleRefreshAttachments,
62+
handleToggleVisibility,
6263
} from './content';
6364
import { handleUserList, handleUsers } from './user';
6465
import { handleGroups } from './group';
@@ -111,6 +112,7 @@ document.addEventListener('DOMContentLoaded', async () => {
111112

112113
// Content → Open questions
113114
handleOpenQuestions();
115+
handleToggleVisibility();
114116

115117
// Content → Attachments
116118
handleDeleteAttachments();

phpmyfaq/admin/header.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@
7979
'stickyfaqs',
8080
'stickyRecordsHeader'
8181
);
82-
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delquestion', 'question', 'ad_menu_open');
82+
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delquestion', 'question', 'ad_menu_open', 'questions');
8383
$secLevelEntries['content'] .= $adminHelper->addMenuEntry('delcomment', 'comments', 'ad_menu_comments', 'comments');
8484
$secLevelEntries['content'] .= $adminHelper->addMenuEntry(
8585
'addattachment+editattachment+delattachment',

phpmyfaq/admin/index.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -267,9 +267,6 @@
267267
case 'copyentry':
268268
require 'faqs.editor.php';
269269
break;
270-
case 'question':
271-
require 'open-questions.php';
272-
break;
273270
case 'stickyfaqs':
274271
require 'stickyfaqs.php';
275272
break;

phpmyfaq/admin/open-questions.php

Lines changed: 0 additions & 88 deletions
This file was deleted.

0 commit comments

Comments
 (0)