Skip to content

Commit

Permalink
Merge branch '5.1-dev' of https://github.com/joomla/joomla-cms into m…
Browse files Browse the repository at this point in the history
…od_frontend
  • Loading branch information
joomlaweby committed Feb 8, 2024
2 parents da32214 + ef8bc6a commit a5bf710
Show file tree
Hide file tree
Showing 10 changed files with 182 additions and 134 deletions.
25 changes: 7 additions & 18 deletions administrator/components/com_scheduler/tmpl/tasks/default.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
/** @var HtmlView $this*/

/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa = $this->getDocument()->getWebAssetManager();
$wa->useScript('table.columns')
->useScript('multiselect')
->useScript('com_scheduler.test-task')
Expand All @@ -42,6 +42,7 @@
Text::script('JLIB_JS_AJAX_ERROR_TIMEOUT');
Text::script('JLIB_JS_AJAX_ERROR_NO_CONTENT');
Text::script('JLIB_JS_AJAX_ERROR_PARSE');
Text::script('JCLOSE');

try {
/** @var CMSWebApplicationInterface $app */
Expand All @@ -62,8 +63,6 @@
$saveOrderingUrl = 'index.php?option=com_scheduler&task=tasks.saveOrderAjax&tmpl=component&' . Session::getFormToken() . '=1';
HTMLHelper::_('draggablelist.draggable');
}

$this->document->addScriptOptions('com_scheduler.test-task.token', Session::getFormToken());
?>

<form action="<?php echo Route::_('index.php?option=com_scheduler&view=tasks'); ?>" method="post" name="adminForm"
Expand Down Expand Up @@ -242,7 +241,10 @@ class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="

<!-- Test task -->
<td class="small d-none d-md-table-cell">
<button type="button" class="btn btn-sm btn-warning" <?php echo $item->state < 0 ? 'disabled' : ''; ?> data-id="<?php echo (int) $item->id; ?>" data-title="<?php echo htmlspecialchars($item->title); ?>" data-bs-toggle="modal" data-bs-backdrop="static" data-bs-target="#scheduler-test-modal">
<button type="button" class="btn btn-sm btn-warning" <?php echo $item->state < 0 ? 'disabled' : ''; ?>
data-scheduler-run
data-id="<?php echo (int) $item->id; ?>" data-title="<?php echo htmlspecialchars($item->title); ?>"
data-url="<?php echo Route::_('index.php?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=' . (int) $item->id); ?>">
<span class="fa fa-play fa-sm me-2"></span>
<?php echo Text::_('COM_SCHEDULER_TEST_RUN'); ?>
</button>
Expand All @@ -268,20 +270,7 @@ class="js-draggable" data-url="<?php echo $saveOrderingUrl; ?>" data-direction="
</tbody>
</table>

<?php
// Load the pagination. (@todo: testing)
echo $this->pagination->getListFooter();

// Modal for test runs
$modalparams = [
'title' => '',
];

$modalbody = '<div class="p-3"></div>';

echo HTMLHelper::_('bootstrap.renderModal', 'scheduler-test-modal', $modalparams, $modalbody);

?>
<?php echo $this->pagination->getListFooter(); ?>

<?php endif; ?>

Expand Down
42 changes: 29 additions & 13 deletions administrator/components/com_templates/tmpl/style/edit.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
$user = $this->getCurrentUser();
?>

<form action="<?php echo Route::_('index.php?option=com_templates&layout=edit&id=' . (int) $this->item->id); ?>" method="post" name="adminForm" id="style-form" aria-label="<?php echo Text::_('COM_TEMPLATES_STYLE_FORM_EDIT'); ?>" class="form-validate">
<form action="<?php echo Route::_('index.php?option=com_templates&layout=edit&id=' . (int) $this->item->id); ?>"
method="post" name="adminForm" id="style-form" aria-label="<?php echo Text::_('COM_TEMPLATES_STYLE_FORM_EDIT'); ?>"
class="form-validate">

<?php echo LayoutHelper::render('joomla.edit.title_alias', $this); ?>

Expand All @@ -45,17 +47,31 @@
</span>
</div>
<div>
<p><?php echo Text::_($this->item->xml->description); ?></p>
<?php
$this->fieldset = 'description';
$description = LayoutHelper::render('joomla.edit.fieldset', $this);
$this->fieldset = 'description';
$short_description = Text::_($this->item->xml->description);
$long_description = LayoutHelper::render('joomla.edit.fieldset', $this);

if (!$long_description) {
$truncated = HTMLHelper::_('string.truncate', $short_description, 550, true, false);

if (strlen($truncated) > 500) {
$long_description = $short_description;
$short_description = HTMLHelper::_('string.truncate', $truncated, 250);

if ($short_description == $long_description) {
$long_description = '';
}
}
}
?>
<?php if ($description) : ?>
<p class="readmore">
<a href="#" onclick="document.querySelector('#tab-description').click();">
<?php echo Text::_('JGLOBAL_SHOW_FULL_DESCRIPTION'); ?>
</a>
</p>
<p><?php echo $short_description; ?></p>
<?php if ($long_description) : ?>
<p class="readmore">
<a href="#" onclick="document.querySelector('[aria-controls=description]').click();">
<?php echo Text::_('JGLOBAL_SHOW_FULL_DESCRIPTION'); ?>
</a>
</p>
<?php endif; ?>
</div>
<?php
Expand All @@ -80,12 +96,12 @@
</div>
<?php echo HTMLHelper::_('uitab.endTab'); ?>

<?php if ($description) : ?>
<?php if (isset($long_description) && $long_description != '') : ?>
<?php echo HTMLHelper::_('uitab.addTab', 'myTab', 'description', Text::_('JGLOBAL_FIELDSET_DESCRIPTION')); ?>
<fieldset id="fieldset-description" class="options-form">
<legend><?php echo Text::_('JGLOBAL_FIELDSET_DESCRIPTION'); ?></legend>
<div>
<?php echo $description; ?>
<?php echo $long_description; ?>
</div>
</fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
Expand All @@ -102,7 +118,7 @@
<fieldset id="fieldset-assignment" class="options-form">
<legend><?php echo Text::_('COM_TEMPLATES_MENUS_ASSIGNMENT'); ?></legend>
<div>
<?php echo $this->loadTemplate('assignment'); ?>
<?php echo $this->loadTemplate('assignment'); ?>
</div>
</fieldset>
<?php echo HTMLHelper::_('uitab.endTab'); ?>
Expand Down
1 change: 1 addition & 0 deletions administrator/language/en-GB/plg_system_schemaorg.ini
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ PLG_SYSTEM_SCHEMAORG_BASETYPE_OPTION_PERSON="Person"
PLG_SYSTEM_SCHEMAORG_FIELD_SCHEMA_DESCRIPTION="Structured data is a standardised format for organising and representing information on the web. It provides a way to describe the content and meaning of data in a structured manner, making it easier for search engines and other applications to understand and process the information. <a href=\"https://schema.org\" target=\"_blank\" rel=\"noopener noreferrer\">More information on schema.org</a>."
PLG_SYSTEM_SCHEMAORG_FIELD_SCHEMA_DESCRIPTION_NOT_CONFIGURATED="To use the schema.org functionality, you have to configure the plugin first. Please contact an administrator of the page to get it configured."
PLG_SYSTEM_SCHEMAORG_FIELD_SCHEMA_DESCRIPTION_NOT_CONFIGURATED_ADMIN="To use the schema.org functionality, you have to configure the plugin first. Please select <a href=\"index.php?option=com_plugins&amp;task=plugin.edit&amp;extension_id=%s\" target=\"_blank\">this link to open the plugin</a>, configure and save."
PLG_SYSTEM_SCHEMAORG_FIELD_SCHEMA_EXTEND_JED_DESC="<strong>Need more Schema types?</strong> Extend with <a href=\"https://extensions.joomla.org/category/core-enhancements/schema-plugins\" target=\"_blank\" rel=\"noopener noreferrer\">Schema Plugins from Joomla! Extension Directory</a>."
PLG_SYSTEM_SCHEMAORG_FIELD_SCHEMA_LABEL="Schema"
PLG_SYSTEM_SCHEMAORG_FIELD_SCHEMA_TYPE_LABEL="Schema Type"
PLG_SYSTEM_SCHEMAORG_IMAGE_LABEL="Image"
Expand Down
3 changes: 2 additions & 1 deletion build/media_source/com_scheduler/joomla.asset.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,8 @@
"type": "script",
"uri": "com_scheduler/admin-view-run-test-task.js",
"dependencies": [
"core"
"core",
"joomla.dialog"
],
"attributes": {
"type" : "module"
Expand Down
190 changes: 112 additions & 78 deletions build/media_source/com_scheduler/js/admin-view-run-test-task.es6.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* @copyright (C) 2021 Open Source Matters, Inc. <https://www.joomla.org>
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/

/**
* Provides the manual-run functionality for tasks over the com_scheduler administrator backend.
*
Expand All @@ -11,85 +10,120 @@
*
* @since 4.1.0
*/
if (!window.Joomla) {
throw new Error('Joomla API was not properly initialised');
}

const initRunner = () => {
const paths = Joomla.getOptions('system.paths');
const token = Joomla.getOptions('com_scheduler.test-task.token');
const uri = `${paths ? `${paths.base}/index.php` : window.location.pathname}?option=com_ajax&format=json&plugin=RunSchedulerTest&group=system&id=%d${token ? `&${token}=1` : ''}`;
const modal = document.getElementById('scheduler-test-modal');

// Task output template
const template = `
<h4 class="scheduler-headline">${Joomla.Text._('COM_SCHEDULER_TEST_RUN_TASK')}</h4>
<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_STARTED')}</div>
<div class="mt-3 text-center"><span class="fa fa-spinner fa-spin fa-lg"></span></div>
`;

const sanitiseTaskOutput = (text) => text
.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;')
.replace(/'/g, '&#039;')
.replace(/([^>\r\n]?)(\r\n|\n\r|\r|\n)/g, '$1<br>$2');

// Trigger the task through a GET request, populate the modal with output on completion.
const triggerTaskAndShowOutput = (e) => {
const button = e.relatedTarget;
const id = parseInt(button.dataset.id, 10);
const { title } = button.dataset;

modal.querySelector('.modal-title').innerHTML = Joomla.Text._('COM_SCHEDULER_TEST_RUN_TITLE').replace('%d', id.toString());
modal.querySelector('.modal-body > div').innerHTML = template.replace('%s', title);

Joomla.request({
url: uri.replace('%d', id.toString()),
onSuccess: (data, xhr) => {
[].slice.call(modal.querySelectorAll('.modal-body > div > div')).forEach((el) => {
el.parentNode.removeChild(el);
});
// eslint-disable-next-line import/no-unresolved
import JoomlaDialog from 'joomla.dialog';

const output = JSON.parse(data);

if (output && output.success && output.data) {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED')}</div>`;

if (output.data.duration > 0) {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_DURATION').replace('%s', output.data.duration.toFixed(2))}</div>`;
}

if (output.data.output) {
const result = Joomla.sanitizeHtml((output.data.output), null, sanitiseTaskOutput);

// Can use an indication for non-0 exit codes
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', result)}</div>`;
}
} else {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED')}</div>`;
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', xhr.status))}</div>`;
}
},
onError: (xhr) => {
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED')}</div>`;

const msg = Joomla.ajaxErrorsMessages(xhr);
modal.querySelector('.modal-body > div').innerHTML += `<div>${Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', msg.error)}</div>`;
},
});
};
/**
* Helper to create an element
*
* @param {String} nodeName
* @param {String} text
* @param {Array} classList
* @returns {HTMLElement}
*/
const createEl = (nodeName, text = '', classList = []) => {
const el = document.createElement(nodeName);
el.textContent = text;
if (classList && classList.length) {
el.classList.add(...classList);
}
return el;
};

const reloadOnClose = () => {
window.location.href = `${paths ? `${paths.base}/index.php` : window.location.pathname}?option=com_scheduler&view=tasks`;
/**
* Trigger the task through a GET request
*
* @param {String} url
* @param {HTMLElement} resultContainer
*/
const runTheTask = (url, resultContainer) => {
const statusHolder = resultContainer.querySelector('.scheduler-status');
const progressBar = resultContainer.querySelector('.progress-bar');
const complete = (success) => {
progressBar.style.width = '100%';
progressBar.classList.add(success ? 'bg-success' : 'bg-danger');
setTimeout(() => progressBar.classList.remove('progress-bar-animated'), 500);
};

if (modal) {
modal.addEventListener('show.bs.modal', triggerTaskAndShowOutput);
modal.addEventListener('hidden.bs.modal', reloadOnClose);
}
document.removeEventListener('DOMContentLoaded', initRunner);
progressBar.style.width = '15%';

fetch(url, { headers: { 'X-CSRF-Token': Joomla.getOptions('csrf.token', '') } })
.then((response) => {
if (!response.ok) {
throw new Error(Joomla.Text._('JLIB_JS_AJAX_ERROR_OTHER').replace('%s', response.status).replace('%d', response.status));
}
return response.json();
})
.then((output) => {
if (!output.data) {
// The request was successful but the response is empty in some reason
throw new Error(Joomla.Text._('JLIB_JS_AJAX_ERROR_NO_CONTENT'));
}

statusHolder.textContent = Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_COMPLETED');

if (output.data.duration > 0) {
resultContainer.appendChild(createEl('div', Joomla.Text._('COM_SCHEDULER_TEST_RUN_DURATION').replace('%s', output.data.duration.toFixed(2))));
}

if (output.data.output) {
resultContainer.appendChild(createEl('div', Joomla.Text._('COM_SCHEDULER_TEST_RUN_OUTPUT').replace('%s', '').replace('<br>', '')));
resultContainer.appendChild(createEl('pre', output.data.output, ['bg-light', 'p-2']));
}

complete(true);
})
.catch((error) => {
complete(false);
statusHolder.textContent = Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_TERMINATED');
resultContainer.appendChild(createEl('div', error.message, ['text-danger']));
});
};

document.addEventListener('DOMContentLoaded', initRunner);
// Listen on click over a task button to run a task
document.addEventListener('click', (event) => {
const button = event.target.closest('button[data-scheduler-run]');
if (!button) return;
event.preventDefault();

// Get the task info from the button
const { id, title, url } = button.dataset;

// Prepare the initial popup content, by following template:
// <div class="p-3">
// <h4>Task: Task title</h4>
// <div class="mb-2 scheduler-status">Status: Task Status</div>
// <div class="progress mb-2"><div class="progress-bar progress-bar-striped bg-success"></div></div>
// </div>
const content = (() => {
const body = createEl('div', '', ['p-3']);
const progress = createEl('div', '', ['progress', 'mb-2']);
const progressBar = createEl('div', '', ['progress-bar', 'progress-bar-striped', 'progress-bar-animated']);
body.appendChild(createEl('h4', Joomla.Text._('COM_SCHEDULER_TEST_RUN_TASK').replace('%s', title)));
body.appendChild(createEl('div', Joomla.Text._('COM_SCHEDULER_TEST_RUN_STATUS_STARTED'), ['mb-2', 'scheduler-status']));
progress.appendChild(progressBar);
body.appendChild(progress);
progressBar.style.width = '0%';
return body;
})();

// Create dialog instance
const dialog = new JoomlaDialog({
popupType: 'inline',
textHeader: Joomla.Text._('COM_SCHEDULER_TEST_RUN_TITLE').replace('%d', id),
textClose: Joomla.Text._('JCLOSE'),
popupContent: content,
width: '800px',
height: 'fit-content',
});

// Run the task when dialog is ready
dialog.addEventListener('joomla-dialog:open', () => {
runTheTask(url, content);
});
// Reload the page when dialog is closed
dialog.addEventListener('joomla-dialog:close', () => {
window.location.reload();
});

dialog.show();
});
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class WebInstaller {
const jedContainer = document.getElementById('jed-container');
jedContainer.innerHTML = Joomla.sanitizeHtml(response.data.html, allowList);

document.getElementById('com-apps-searchbox').addEventListener('keypress', ({ which }) => {
if (which === 13) {
document.getElementById('com-apps-searchbox').addEventListener('keydown', ({ code }) => {
if (code === 'Enter') {
this.initiateSearch();
}
});
Expand Down

0 comments on commit a5bf710

Please sign in to comment.