Skip to content

Commit

Permalink
refactor: migrated admin log page to Twig (#2791)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Apr 21, 2024
1 parent 0cc1f88 commit cb2f0cc
Show file tree
Hide file tree
Showing 17 changed files with 2,377 additions and 249 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
"symfony/mailer": "^7.0",
"symfony/routing": "^7.0",
"tecnickcom/tcpdf": "~6.0",
"twig/intl-extra": "^3.9",
"twig/twig": "^3.6"
},
"require-dev": {
Expand Down
148 changes: 147 additions & 1 deletion composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion phpmyfaq/admin/assets/src/api/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*
* @package phpMyFAQ
* @author Thorsten Rinne <thorsten@phpmyfaq.de>
* @copyright 2023 phpMyFAQ Team
* @copyright 2023-2024 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2023-12-28
Expand Down
1 change: 1 addition & 0 deletions phpmyfaq/admin/assets/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ export * from './category';
export * from './faqs';
export * from './glossary';
export * from './group';
export * from './statistics';
export * from './tags';
export * from './user';
35 changes: 35 additions & 0 deletions phpmyfaq/admin/assets/src/api/statistics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Fetch data for statistics management
*
* 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 <thorsten@phpmyfaq.de>
* @copyright 2024 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2024-04-21
*/

export const deleteAdminLog = async (csrfToken) => {
try {
const response = await fetch(`./api/statistics/admin-log`, {
method: 'DELETE',
cache: 'no-cache',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
csrfToken: csrfToken,
}),
redirect: 'follow',
referrerPolicy: 'no-referrer',
});

return await response.json();
} catch (error) {
console.error(error);
}
};
3 changes: 2 additions & 1 deletion phpmyfaq/admin/assets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
*/

import { getLatestVersion, renderVisitorCharts, renderTopTenCharts } from './dashboard';
import { handleSessions, handleStatistics } from './statistics';
import { handleDeleteAdminLog, handleSessions, handleStatistics } from './statistics';
import {
handleConfiguration,
handleInstances,
Expand Down Expand Up @@ -106,6 +106,7 @@ document.addEventListener('DOMContentLoaded', async () => {
handleStickyFaqs();

// Statistics
handleDeleteAdminLog();
handleStatistics();

// Configuration -> FAQ configuration
Expand Down
35 changes: 35 additions & 0 deletions phpmyfaq/admin/assets/src/statistics/admin-log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* Handle admin log management
*
* 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 <thorsten@phpmyfaq.de>
* @copyright 2024 phpMyFAQ Team
* @license http://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2024-04-21
*/

import { deleteAdminLog } from '../api';
import { pushErrorNotification, pushNotification } from '../utils';

export const handleDeleteAdminLog = () => {
const buttonDeleteAdminLog = document.getElementById('pmf-delete-admin-log');

if (buttonDeleteAdminLog) {
buttonDeleteAdminLog.addEventListener('click', async (event) => {
event.preventDefault();
const csrf = event.target.getAttribute('data-pmf-csrf');
const response = await deleteAdminLog(csrf);

if (response.success) {
pushNotification(response.success);
} else {
pushErrorNotification(response.error);
}
});
}
};
1 change: 1 addition & 0 deletions phpmyfaq/admin/assets/src/statistics/index.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
export * from './admin-log';
export * from './sessions';
export * from './statistics';
3 changes: 1 addition & 2 deletions phpmyfaq/admin/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -327,8 +327,7 @@
break;
// functions for session administration
case 'adminlog':
case 'deleteadminlog':
require 'stat.adminlog.php';
require 'statistics.admin-log.php';
break;
case 'viewsessions':
case 'clear-visits':
Expand Down

0 comments on commit cb2f0cc

Please sign in to comment.