progress / status / flush

Notice: This thread is very old.
richard
Member | 60
+
0
-

Hello.
Can someone please give me simple example on how to render template before the script ends and then re-write a snippet? I can not work it out. This is for long running process.

<?php
// in presenter:

public function renderSleep()
{
	// TODO render template
	sleep(10);
	// TODO re-render status snippet
}

// in template:
{snippet status}
I am sleeping...
{/snippet}
?>
pawouk
Member | 172
+
0
-

But why do you want to do that? You can render temlate simple by $this->template->render() but I don't think it is good way. Just try to explayn why you wont to do that, I'm sure there is a better way.

richard
Member | 60
+
0
-

I have tried that but it says: Template file name was not specified even I try $this->template->render(‘template.latte’); it gives the same error.

I am trying to print out status information about long running process i.e:
I am doing A,
I am doing B,
I am doing C,
FINISHED

Thanks for your effort.

Last edited by richard (2011-10-04 11:14)

mkoubik
Member | 728
+
0
-

If you need to do some time consuming computation and then show the result, send to the user a page without that information (with “I'm sleeping” instead of it) and then load it by a new AJAX request.

Mikulas Dite
Member | 756
+
0
-

If you want a failsafe solution, you should rather use a queue and store these long running operations. Pros: fluent user flow, possible to delay queue etc. Also, your implementation would allow user to press esc or abort the request in yet another way and thus abort the desired operation.

The only con is that you have to probe the server periodically to check the status. (Then ajax snippet update etc.).

richard
Member | 60
+
0
-

OK, thanks. How can I render and later on update snippet otherwise than with calling an action by click.
Do I need to render page with a javascript which does that (and how) or I can do it in presenter? Sorry, I am starting with ajax.
Thanks guys.
For now I have done it with displaying hidden div on submit saying “wait..” but in IE it even stops gif animation. It does the job but I do not like it.

Last edited by richard (2011-10-04 18:18)

Mikulas Dite
Member | 756
+
0
-

For one, you could use a periodical check as I mentioned:

setInterval(function() {
	$.ajax({
		url: {plink target}, // this is Latte, replace target with your desired check action
		success: function (payload) {
			if (payload.status == "done") {
				// replace some DOM node with payload.content or whatever
			}
		}
	});
}, 10000);
public function renderComputationStatus()
{
	$status = (bool) $we_done_yet;
	$this->sendResponse(new \Nette\Application\Responses\JsonResponse(
		array('status' => $status, /* whatever content you wanna send*/)
	);
}

I might have made a typo, but I guess you get the idea.