Skip to content

Commit

Permalink
build: use webpack for JS code (#2492)
Browse files Browse the repository at this point in the history
  • Loading branch information
thorsten committed Jul 11, 2023
1 parent 6b8d2b6 commit 0b36539
Show file tree
Hide file tree
Showing 7 changed files with 76 additions and 67 deletions.
36 changes: 18 additions & 18 deletions phpmyfaq/admin/api/updates.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,7 @@
*/

switch ($ajaxAction) {
// GET /updates: Returns a list of available updates.
default:
$client = HttpClient::create();
try {
$versions = $client->request(
'GET',
'https://api.phpmyfaq.de/versions'
);
$response->setStatusCode(Response::HTTP_OK);
$response->setContent($versions->getContent());
$response->send();
} catch (TransportExceptionInterface $e) {
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
$response->setData($e->getMessage());
$response->send();
}
break;

case 'check-updates':
$json = file_get_contents('php://input', true);
$postData = json_decode($json);
Expand All @@ -89,5 +73,21 @@

$response->send();
break;
}
// GET /updates: Returns a list of available updates.
default:
$client = HttpClient::create();
try {
$versions = $client->request(
'GET',
'https://api.phpmyfaq.de/versions'
);
$response->setStatusCode(Response::HTTP_OK);
$response->setContent($versions->getContent());
$response->send();
} catch (TransportExceptionInterface $e) {
$response->setStatusCode(Response::HTTP_BAD_REQUEST);
$response->setData($e->getMessage());
$response->send();
}
break;
}
47 changes: 0 additions & 47 deletions phpmyfaq/admin/assets/js/upgrade.js

This file was deleted.

1 change: 1 addition & 0 deletions phpmyfaq/admin/assets/src/configuration/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './elasticsearch';
export * from './instance';
export * from './stopwords';
export * from './template-meta-data';
export * from './upgrade';
52 changes: 52 additions & 0 deletions phpmyfaq/admin/assets/src/configuration/upgrade.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/**
* Upgrade related code.
*
* - Code for checking for updates.
*
* 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
* @author Jan Harms <[email protected]>
* @copyright 2022-2023 phpMyFAQ Team
* @license https://www.mozilla.org/MPL/2.0/ Mozilla Public License Version 2.0
* @link https://www.phpmyfaq.de
* @since 2023-07-11
*/
import { addElement } from '../../../../assets/src/utils';

export const handleCheckForUpdates = () => {
const button = document.getElementById('pmf-button-check-updates');
if (button) {
button.addEventListener('click', (event) => {
event.preventDefault();
fetch('index.php?action=ajax&ajax=updates&ajaxaction=check-updates', {
method: 'POST',
headers: {
Accept: 'application/json, text/plain, */*',
'Content-Type': 'application/json',
},
})
.then(async (response) => {
if (response.ok) {
return response.json();
}
throw new Error('Network response was not ok: ', { cause: { response } });
})
.then((response) => {
if (response.version === 'current') {
const element = addElement('p', { innerText: response.message });
button.after(element);
} else {
const element = addElement('p', { innerText: response.message });
button.after(element);
}
})
.catch((error) => {
console.error(error);
});
});
}
};
4 changes: 4 additions & 0 deletions phpmyfaq/admin/assets/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
handleStopWords,
handleTemplateMetaData,
handleElasticsearch,
handleCheckForUpdates,
} from './configuration';
import { handleStatistics } from './statistics';
import {
Expand Down Expand Up @@ -96,6 +97,9 @@ document.addEventListener('DOMContentLoaded', async () => {
// Configuration -> Template Meta data
handleTemplateMetaData();

// Configuration -> Online Update
handleCheckForUpdates();

// Configuration -> Elasticsearch configuration
handleElasticsearch();
});
2 changes: 1 addition & 1 deletion phpmyfaq/admin/assets/templates/configuration/upgrade.twig
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

<p>
Last check for updates: <output>{{ dateLastChecked }}</output>
<button type="button" class="btn btn-sm btn-primary" onclick="checkForUpdates()">Check for new version</button>
</p>
<button type="button" class="btn btn-sm btn-primary mb-2" id="pmf-button-check-updates">Check for new version</button>

<p>
Release-Environment: {{ releaseEnvironment }}
Expand Down
1 change: 0 additions & 1 deletion phpmyfaq/admin/header.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@

<script src="../assets/dist/backend.js?<?= time(); ?>"></script>
<script src="assets/js/configuration.js"></script>
<script src="assets/js/upgrade.js"></script>
<link rel="shortcut icon" href="../assets/themes/<?= Template::getTplSetName(); ?>/img/favicon.ico">
</head>
<body dir="<?= Translation::get('dir'); ?>" id="page-top">
Expand Down

0 comments on commit 0b36539

Please sign in to comment.