diff options
Diffstat (limited to 'frontend/pages/logview.php')
-rw-r--r-- | frontend/pages/logview.php | 49 |
1 files changed, 35 insertions, 14 deletions
diff --git a/frontend/pages/logview.php b/frontend/pages/logview.php index 798bb85..176556a 100644 --- a/frontend/pages/logview.php +++ b/frontend/pages/logview.php @@ -5,7 +5,7 @@ function init_logview() { $S['title']='Log Viewer'; } function body_logview() { - global $S, $request; + global $S, $request, $conf; if (isset($request['task']) && is_numeric($request['task'])) { $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `id`='.$request['task']); if ($r->rowCount() == 0) { @@ -24,19 +24,40 @@ function body_logview() { echo '<span style="color: yellow">[running]</span>'; } echo '</h3>'; - if (isset($request['task']) && is_numeric($request['task'])) { - $s=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `task`='.$task->id.' ORDER BY `order` ASC'); - if ($s->rowCount()) { - echo '<div style="font-family: monospace">'; - while ($entry=$s->fetch(PDO::FETCH_ASSOC)) { - $entry=new sql_buildlog_entry($entry); - $text=str_replace(array("\n", "\t"), array("<br/>\n", str_repeat(' ', 4)), htmlentities($entry->text)); - echo '<a name="entry_'.$task->id.'_'.$entry->order.'"'.($entry->stream=='stderr'?' style="color: red" ':'').' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' @ '.date('D j M Y @ H:i:s', $entry->timestamp).' UTC">'.$text.'</a>'; - } - echo '<a name="end"> </a>'; - echo '</div>'; + $page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1; + $count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `task`='.$task->id)->fetch(PDO::FETCH_COLUMN); + $pager=''; + if ($count > $conf['logview_max']) { + $pager='<form action="'.url('logs/task'.$task->id).'" method="post" onsubmit="window.location.href=\''.url('logs/task'.$task->id).'/\'+this.page.value; return false">Page: '; + if ($page > 1) { + $pager.='<input type="button" value="<<" onclick="this.form.page.value='.($page-1).'; this.form.onsubmit()" /> '."\n"; + } + $pager.='<select name="page">'; + for ($i=1; ($i-1)*$conf['logview_max']<$count; $i++) { + $pager.="<option value=\"$i\"".($i==$page?'selected="selected"':'').">$i</option>\n"; + } + $pager.='</select> <input type="submit" value="Go" />'; + if ($page*$conf['logview_max']<$count) { + $pager.=' <input type="button" value=">>" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n"; + } + $pager.='</form>'; + echo $pager; + } + $r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `task`='.$task->id.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']); + if ($r->rowCount()) { + echo '<div style="font-family: monospace">'; + while ($entry=$r->fetch(PDO::FETCH_ASSOC)) { + $entry=new sql_buildlog_entry($entry); + $text=str_replace(array("\n", "\t"), array("<br/>\n", str_repeat(' ', 4)), htmlentities($entry->text)); + echo '<a name="entry_'.$task->id.'_'.$entry->order.'"'.($entry->stream=='stderr'?' style="color: red" ':'').' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' @ '.date('D j M Y @ H:i:s', $entry->timestamp).' UTC">'.$text.'</a>'; + } + echo '</div>'; + echo $pager; + } else { + if ($count) { + echo print_error("There aren't $page pages. Try an <a href=\"".url('logs/task'.$task->id)."\">earlier page</a>."); } else { - echo '<b>No output</b>'; + echo print_warning('No output'); } } } elseif (isset($request['build']) && preg_match('/[a-z0-9]{6}/', $request['build'])) { @@ -48,7 +69,7 @@ function body_logview() { $i=0; while ($task=$r->fetch(PDO::FETCH_ASSOC)) { $task=new sql_task($task); - echo '<a href="'.url('logs/task'.$task->id).'#end">Task #'.++$i.'</a>: '.htmlentities($task->command).'<br/>'; + echo '<a href="'.url('logs/task'.$task->id).'">Task #'.++$i.'</a>: '.htmlentities($task->command).'<br/>'; } } else { $r=$S['pdo']->query('SELECT * FROM `builds` ORDER BY `ctime` ASC'); |