Skip to content
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

Feature presidecms 2811 adhoc task summary option #1436

Open
wants to merge 2 commits into
base: stable
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
, $cancelBtn = $( '#task-cancel-button' )
, $resultBtn = $( '#view-result-button' )
, $logArea = $( '#taskmanager-log' )
, $taskLog = $( '#task-log' )
, $summaryArea = $( '#taskmanager-summary-area' )
, $summary = $( '#taskmanager-summary' )
, hasLogArea = $logArea.length
, logArea = hasLogArea ? $logArea.get(0) : null
, lineCount = cfrequest.adhocTaskLineCount || ""
Expand Down Expand Up @@ -61,8 +64,16 @@
$timeArea.parent().addClass( "red" );
}

if ( data.status == "succeeded" && data.resultUrl.length ) {
window.location = data.resultUrl;
if ( data.status == "succeeded" ){
if ( data.resultUrl.length ) {
window.location = data.resultUrl;
}

if ( data.summary.length ) {
$summary.html( data.summary );
$summaryArea.removeClass( "hide") ;
$taskLog.removeClass( "in" ).addClass( "collapse" );
}
}

if ( $cancelBtn.length ) {
Expand Down
7 changes: 7 additions & 0 deletions system/handlers/admin/AdHocTaskManager.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,13 @@ component extends="preside.system.base.AdminHandler" {
prc.taskProgress.timeTaken = renderContent( renderer="TaskTimeTaken", data=prc.taskProgress.timeTaken*1000, context=[ "accurate" ] );
}

if ( prc.task.status == "succeeded" && Len( prc.task.summary_handler ?: "" ) ) {
prc.summary = renderViewlet( event=prc.task.summary_handler, args={
taskId = prc.task.id
, result = prc.task.result
} );
}

prc.canCancel = prc.task.status == "running" || prc.task.status == "pending";
prc.canCancel = prc.canCancel && ( prc.task.admin_owner == event.getAdminUserId() || hasCmsPermission( "adhocTaskManager.canceltask" ) );

Expand Down
2 changes: 2 additions & 0 deletions system/i18n/cms.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2118,6 +2118,8 @@ adhoctaskmanager.progress.view.result.btn=View/download result
adhoctaskmanager.progress.cancel.task.btn=Cancel task
adhoctaskmanager.progress.cancel.task.prompt=Cancel the running of this task
adhoctaskmanager.progress.pending.log=[Warn]: Task is pending on available resources. Please wait...
adhoctaskmanager.progress.show.log=Show log
adhoctaskmanager.progress.hide.log=Hide log

cms.navigation.login=Login
cms.navigation.logout=Logout
21 changes: 11 additions & 10 deletions system/preside-objects/taskmanager/taskmanager_adhoc_task.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,17 @@
*
*/
component extends="preside.system.base.SystemPresideObject" {
property name="event" type="string" dbtype="varchar" maxlength=255 required=true;
property name="event_args" type="string" dbtype="longtext" required=false;
property name="retry_interval" type="string" dbtype="longtext" required=false;
property name="reference" type="string" dbtype="varchar" maxlength=100 required=false indexes="reference";
property name="title" type="string" dbtype="varchar" maxlength=255 required=false;
property name="title_args" type="string" dbtype="longtext" required=false;
property name="result" type="string" dbtype="longtext" required=false;
property name="result_url" type="string" dbtype="varchar" maxlength=255 required=false;
property name="return_url" type="string" dbtype="varchar" maxlength=255 required=false;
property name="log" type="string" dbtype="longtext" required=false;
property name="event" type="string" dbtype="varchar" maxlength=255 required=true;
property name="event_args" type="string" dbtype="longtext" required=false;
property name="retry_interval" type="string" dbtype="longtext" required=false;
property name="reference" type="string" dbtype="varchar" maxlength=100 required=false indexes="reference";
property name="title" type="string" dbtype="varchar" maxlength=255 required=false;
property name="title_args" type="string" dbtype="longtext" required=false;
property name="result" type="string" dbtype="longtext" required=false;
property name="result_url" type="string" dbtype="varchar" maxlength=255 required=false;
property name="return_url" type="string" dbtype="varchar" maxlength=255 required=false;
property name="summary_handler" type="string" dbtype="varchar" maxlength=255 required=false;
property name="log" type="string" dbtype="longtext" required=false;

property name="status" type="string" dbtype="varchar" maxlength=50 required=false default="pending" enum="adhocTaskStatus" indexes="status";
property name="progress_percentage" type="numeric" dbtype="int" required=false default=0;
Expand Down
47 changes: 38 additions & 9 deletions system/services/taskmanager/AdHocTaskManagerService.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ component displayName="Ad-hoc Task Manager Service" {
, array titleData = []
, string resultUrl = ""
, string returnUrl = ""
, string summaryHandler = ""
, string reference = ""
) {
var nextAttemptDate = "";
Expand All @@ -89,6 +90,7 @@ component displayName="Ad-hoc Task Manager Service" {
, title_data = SerializeJson( arguments.titleData )
, result_url = arguments.resultUrl
, return_url = arguments.returnUrl
, summary_handler = arguments.summaryHandler
, reference = arguments.reference
} );

Expand Down Expand Up @@ -395,6 +397,23 @@ component displayName="Ad-hoc Task Manager Service" {
);
}


/**
* Sets the summary handler for your task. Useful when wanting to a display a summary of the result after the log
* @taskId ID of the task
* See also [[taskmanager-adhoctasks]].
*
* @autodoc true
* @handler handler which will be use to render a summary on successful completion of task
*/
public void function setSummaryHandler( required required string taskId, string handler ) {
$getPresideObject( "taskmanager_adhoc_task" ).updateData(
id = arguments.taskId
, data = { summary_handler=arguments.handler }
);
}


/**
* Returns progress of the given task as a struct. Struct keys:
* [id, progress, status, result].
Expand Down Expand Up @@ -422,16 +441,26 @@ component displayName="Ad-hoc Task Manager Service" {
timeTaken = DateDiff( 's', t.started_on, t.finished_on );
break;
}

var summary = "";
if ( t.status=="succeeded" && Len( t.summary_handler ?: "" ) ) {
summary = $renderViewlet( event=t.summary_handler, args={
taskid = task.id
, result = task.result
} )
}

return {
id = t.id
, status = t.status
, progress = t.progress_percentage
, log = t.log
, resultUrl = t.result_url
, returnUrl = t.return_url
, result = IsJson( t.result ?: "" ) ? DeserializeJson( t.result ) : {}
, timeTaken = timeTaken
, timeRemaining = timeRemaining
id = t.id
, status = t.status
, progress = t.progress_percentage
, log = t.log
, resultUrl = t.result_url
, returnUrl = t.return_url
, summary = summary
, result = IsJson( t.result ?: "" ) ? DeserializeJson( t.result ) : {}
, timeTaken = timeTaken
, timeRemaining = timeRemaining
};
}

Expand Down
15 changes: 15 additions & 0 deletions system/services/taskmanager/AdHocTaskProgressReporter.cfc
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,21 @@ component {
);
}

/**
* Sets the result summary handler for your task. If using
* the built-in admin monitoring UI, this rendered result will be shown after the log on successful task completion.
* See also [[taskmanager-adhoctasks]].
*
* @autodoc true
* @resultUrl URL to which user will be redirected to on successful completion of task
*/
public void function setSummaryHandler( required string handler ) {
_getAdhocTaskManagerService().setSummaryHandler(
handler = arguments.handler
, taskId = _getTaskId()
);
}

/**
* Returns true if the task has been cancelled or
* is no longer valid. Call this from your task logic
Expand Down
12 changes: 10 additions & 2 deletions system/views/admin/adHocTaskManager/progress.cfm
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
log = taskProgress.log;
timeTaken = taskProgress.timeTaken;
lineCount = taskProgress.lineCount;
summary = prc.summary ?: "";

hideTaskLog = isTrue( rc.hideTaskLog ?: "" );
hideCancel = isTrue( rc.hideCancel ?: "" );
Expand Down Expand Up @@ -46,7 +47,9 @@
<div class="progress-bar progress-bar-#progressClass#" style="width:#progress#%;"></div>
</div>
<cfif !hideTaskLog>
<div class="task-log">

<div id="task-log" class="task-log <cfif Len( summary ) >collapse</cfif>">
<a data-toggle="collapse" data-target="##task-log">#translateResource( "cms:adhoctaskmanager.progress.hide.log" )#</a>
<pre id="taskmanager-log">#log#</pre>
</div>
</cfif>
Expand All @@ -64,7 +67,12 @@
</span>
</div>
</div>

<div id="taskmanager-summary-area" class="<cfif !Len( summary )>hide</cfif>">
<a data-toggle="collapse" data-target="##task-log">#translateResource( "cms:adhoctaskmanager.progress.show.log" )#</a>
<div id="taskmanager-summary">
#summary#
</div>
</div>
<div class="form-actions row">
<cfif hasReturnUrl>
<a href="#task.return_url#" class="btn btn-info">
Expand Down
Loading