diff --git a/administrator/components/com_patchtester/src/Controller/StartfetchController.php b/administrator/components/com_patchtester/src/Controller/StartfetchController.php index bd8d79e..e106948 100644 --- a/administrator/components/com_patchtester/src/Controller/StartfetchController.php +++ b/administrator/components/com_patchtester/src/Controller/StartfetchController.php @@ -70,7 +70,7 @@ class StartfetchController extends BaseController $testsModel = Factory::getApplication()->bootComponent('com_patchtester')->getMVCFactory()->createModel('Tests', 'Administrator', ['ignore_request' => true]); try { - // Sanity check, ensure there aren't any applied patches + // Sanity check, ensure there aren't any applied patches if (count($testsModel->getAppliedPatches()) >= 1) { $response = new JsonResponse(new \Exception(Text::_('COM_PATCHTESTER_ERROR_APPLIED_PATCHES'), 500)); $this->app->sendHeaders(); diff --git a/administrator/components/com_patchtester/tmpl/fetch/default.php b/administrator/components/com_patchtester/tmpl/fetch/default.php index 7a26b00..ab5c686 100644 --- a/administrator/components/com_patchtester/tmpl/fetch/default.php +++ b/administrator/components/com_patchtester/tmpl/fetch/default.php @@ -10,14 +10,18 @@ use Joomla\CMS\Factory; use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; +use Joomla\CMS\WebAsset\WebAssetManager; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects -HTMLHelper::_('jquery.framework'); +/** @var WebAssetManager $wa */ +$wa = $this->document->getWebAssetManager(); +$wa->useScript('com_patchtester.admin-fetcher-modal'); + HTMLHelper::_('behavior.core'); -HTMLHelper::_('script', 'com_patchtester/fetcher.js', ['version' => 'auto', 'relative' => true]); +//HTMLHelper::_('script', 'com_patchtester/fetcher.js', ['version' => 'auto', 'relative' => true]); Text::script('COM_PATCHTESTER_FETCH_AN_ERROR_HAS_OCCURRED'); ?> diff --git a/administrator/components/com_patchtester/tmpl/pulls/default.php b/administrator/components/com_patchtester/tmpl/pulls/default.php index 6b5085d..ff6dd0f 100644 --- a/administrator/components/com_patchtester/tmpl/pulls/default.php +++ b/administrator/components/com_patchtester/tmpl/pulls/default.php @@ -11,15 +11,17 @@ use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\Language\Text; use Joomla\CMS\Layout\LayoutHelper; use Joomla\CMS\Router\Route; +use Joomla\CMS\WebAsset\WebAssetManager; // phpcs:disable PSR1.Files.SideEffects \defined('_JEXEC') or die; // phpcs:enable PSR1.Files.SideEffects -/** @var \Joomla\Component\Patchtester\Administrator\View\Pulls\PullsHtmlView $this */ +/** @var \Joomla\Component\Patchtester\Administrator\View\Pulls\HtmlView $this */ -HTMLHelper::_('stylesheet', 'com_patchtester/octicons.css', ['version' => '3.5.0', 'relative' => true]); -HTMLHelper::_('script', 'com_patchtester/patchtester.js', ['version' => 'auto', 'relative' => true]); +/** @var WebAssetManager $wa */ +$wa = $this->document->getWebAssetManager(); +$wa->usePreset('com_patchtester.patchtester'); $listOrder = $this->escape($this->state->get('list.ordering')); $listDirn = $this->escape($this->state->get('list.direction')); diff --git a/media/com_patchtester/joomla.asset.json b/media/com_patchtester/joomla.asset.json new file mode 100644 index 0000000..522b6a0 --- /dev/null +++ b/media/com_patchtester/joomla.asset.json @@ -0,0 +1,40 @@ +{ + "$schema": "https://developer.joomla.org/schemas/json-schema/web_assets.json", + "name": "com_patchtester", + "version": "4.3.2", + "description": "Joomla CMS", + "license": "GPL-2.0-or-later", + "assets": [ + { + "name": "com_patchtester.admin-fetcher-modal", + "type": "script", + "uri": "com_patchtester/fetcher.js", + "attributes": { + "type": "module", + "defer": true + } + }, + { + "name": "com_patchtester.patchtester", + "type": "script", + "uri": "com_patchtester/patchtester.js", + "attributes": { + "type": "module", + "defer": true + } + }, + { + "name": "com_patchtester.octicons", + "type": "style", + "uri": "com_patchtester/octicons.css" + }, + { + "name": "com_patchtester.patchtester", + "type": "preset", + "dependencies": [ + "com_patchtester.patchtester#script", + "com_patchtester.octicons#style" + ] + } + ] +} diff --git a/media/com_patchtester/js/fetcher.js b/media/com_patchtester/js/fetcher.js index d92a53b..8512d11 100644 --- a/media/com_patchtester/js/fetcher.js +++ b/media/com_patchtester/js/fetcher.js @@ -10,41 +10,38 @@ if (typeof Joomla === 'undefined') { } const defaultSettings = { - offset: 0, - progress: 0, + progress: null, lastPage: null, baseURL: `${Joomla.getOptions('system.paths').baseFull}index.php?option=com_patchtester&tmpl=component&format=json`, - lastPage: null, }; class PatchFetcher { constructor(settings = defaultSettings) { this.url = new URL(settings.baseURL); - this.offset = settings.offset; this.progress = settings.progress; this.lastPage = settings.lastPage; this.progressBar = document.getElementById('progress-bar'); - - this.url.searchParams.append(document.querySelector('#patchtester-token').getAttribute('name'), 1); - this.url.searchParams.append('task', `${task}.${task}`); + this.url.searchParams.append(document.getElementById('patchtester-token').getAttribute('name'), 1); this.request('startfetch'); } - request() { - Joomla.request({ - url: path.toString(), - method: 'GET', - perform: true, - data: `task=${task}.${task}`, + request(task) { + this.url.searchParams.append('task', `${task}.${task}`); + Joomla.request({ + url: this.url.toString(), + method: 'GET', + headers: { 'Content-Type': 'application/json' }, + perform: true, onSuccess: (response) => { + response = JSON.parse(response) try { if (response === null || response.error || response.success === false) { throw response; } - + // {"success":true,"message":"Processing page 1 of GitHub data","messages":null,"data":{"complete":false,"header":"Processing data from GitHub"}} // Store the last page if it is part of this request and not a boolean false if (typeof response.data.lastPage !== 'undefined' && response.data.lastPage !== false) { this.lastPage = response.data.lastPage; @@ -54,17 +51,17 @@ class PatchFetcher { if (typeof response.data.page !== 'undefined') { this.progress = (response.data.page / this.lastPage) * 100; - if (progress < 100) { - this.progressBar.style.width = `${progress}%`; - this.progressBar.setAttribute('aria-valuenow', progress); + if (this.progress < 100) { + this.progressBar.style.width = `${this.progress}%`; + this.progressBar.setAttribute('aria-valuenow', this.progress); } else { // Both BS2 and BS4 classes are targeted to keep this script simple this.progressBar.classList.remove(['bar-success', 'bg-success']); this.progressBar.classList.remove(['bar-warning', 'bg-warning']); - this.progressBar.style.width = `${progress}%`; + this.progressBar.style.width = `${this.progress}%`; this.progressBar.setAttribute('aria-valuemin', 100); this.progressBar.setAttribute('aria-valuemax', 200); - this.progressBar.setAttribute('aria-valuenow', progress); + this.progressBar.setAttribute('aria-valuenow', this.progress); } } @@ -75,11 +72,12 @@ class PatchFetcher { } if (!response.data.complete) { - // Send another request + this.url.searchParams.append(document.querySelector('#patchtester-token').getAttribute('name'), 1); + this.url.searchParams.append('task', `${task}.${task}`); this.request('fetch'); } else { document.getElementById('progress').remove(); - document.getElementById('modal-sync button.btn-close', window.parent.document).click(); + window.parent.document.querySelector('#modal-sync button.btn-close').click(); } } catch (error) { try {