-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[5.3] [4.1 ScheduledTasks]Edits for run task #36725
Open
niharikamahajan02
wants to merge
29
commits into
joomla:5.3-dev
Choose a base branch
from
niharikamahajan02:c1
base: 5.3-dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
29 commits
Select commit
Hold shift + click to select a range
617bf20
edits for run task
niharikamahajan02 8388459
Merge branch '4.1-dev' into c1
niharikamahajan02 0312369
some edits and runTestCron replacement
niharikamahajan02 3e66014
onAjaxRunSchedulerTest to onAjaxRunSchedulerTask
niharikamahajan02 1326672
more edits
niharikamahajan02 42f7f89
more edits
niharikamahajan02 b37ca6b
Merge branch '4.1-dev' into c1
niharikamahajan02 46fdba4
edits for test-task
niharikamahajan02 714cc7e
Merge branch 'c1' of https://github.com/niharikamahajan02/joomla-cms …
niharikamahajan02 7ee422d
edits
niharikamahajan02 cff8ee8
test-task to run-task
niharikamahajan02 fd2f3a3
files
niharikamahajan02 6d1ce13
Merge branch '4.1-dev' of github.com:joomla/joomla-cms into 'c1'
ditsuke eab956b
Merge pull request #1 from ditsuke/#36725-task-test-to-task-run
niharikamahajan02 8b8b600
Merge branch '4.2-dev' into c1
richard67 aeef967
Merge branch '4.2-dev' into c1
richard67 17cee04
Phase 1 convert BRANCH to PSR-12
joomla-bot 4012f2d
Phase 2 convert BRANCH to PSR-12
joomla-bot 312dcad
Merge tag 'psr12final' into psr12/merge/36725
joomla-bot b4d1ff8
Merge branch '4.4-dev' into c1
HLeithner 05dffa0
Add back removed language strings and deprecate them
HLeithner 2cc618e
Merge branch '5.0-dev' into c1
laoneo 43d7b3a
Update access.xml
niharikamahajan02 e69218e
Update schedulerunner.php
niharikamahajan02 ecc1a1e
Update admin-view-run-task.es6.js
niharikamahajan02 c07f23b
Update joomla.asset.json
niharikamahajan02 eaf84c3
Update com_scheduler.ini
niharikamahajan02 7438382
Update default.php
niharikamahajan02 6880884
Update schedulerunner.php
niharikamahajan02 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
test-task to run-task
- Loading branch information
commit cff8ee86b94a8bd543c4d0dc3649dfab48e3117f
There are no files selected for viewing
93 changes: 93 additions & 0 deletions
93
build/media_source/com_scheduler/js/admin-view-run-test-task.es6.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @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. | ||
* | ||
* @package Joomla.Components | ||
* @subpackage Scheduler.Tasks | ||
* | ||
* @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.run-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, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, ''') | ||
.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); | ||
}); | ||
|
||
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>`; | ||
}, | ||
}); | ||
}; | ||
|
||
const reloadOnClose = () => { | ||
window.location.href = `${paths ? `${paths.base}/index.php` : window.location.pathname}?option=com_scheduler&view=tasks`; | ||
}; | ||
|
||
modal.addEventListener('show.bs.modal', triggerTaskAndShowOutput); | ||
modal.addEventListener('hidden.bs.modal', reloadOnClose); | ||
document.removeEventListener('DOMContentLoaded', initRunner); | ||
}; | ||
|
||
document.addEventListener('DOMContentLoaded', initRunner); |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.