From 1e127b6757ed929be2d051cf15d8cb0815f7a305 Mon Sep 17 00:00:00 2001 From: Eudyptula Date: Mon, 22 Jun 2009 12:03:38 -0400 Subject: Added pagination to frontend log viewer; updated todo --- frontend/pages/logview.php | 49 +++++++++++++++++++++++++++++++++------------- frontend/routing.csv | 1 + shared/config.php | 1 + todo | 4 +--- 4 files changed, 38 insertions(+), 17 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 '[running]'; } echo ''; - 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 '
'; - while ($entry=$s->fetch(PDO::FETCH_ASSOC)) { - $entry=new sql_buildlog_entry($entry); - $text=str_replace(array("\n", "\t"), array("
\n", str_repeat(' ', 4)), htmlentities($entry->text)); - echo 'stream=='stderr'?' style="color: red" ':'').' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' @ '.date('D j M Y @ H:i:s', $entry->timestamp).' UTC">'.$text.''; - } - echo ' '; - echo '
'; + $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='
Page: '; + if ($page > 1) { + $pager.=' '."\n"; + } + $pager.=' '; + if ($page*$conf['logview_max']<$count) { + $pager.=' '."\n"; + } + $pager.='
'; + 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 '
'; + while ($entry=$r->fetch(PDO::FETCH_ASSOC)) { + $entry=new sql_buildlog_entry($entry); + $text=str_replace(array("\n", "\t"), array("
\n", str_repeat(' ', 4)), htmlentities($entry->text)); + echo 'stream=='stderr'?' style="color: red" ':'').' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' @ '.date('D j M Y @ H:i:s', $entry->timestamp).' UTC">'.$text.''; + } + echo '
'; + echo $pager; + } else { + if ($count) { + echo print_error("There aren't $page pages. Try an id)."\">earlier page."); } else { - echo 'No output'; + 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 'Task #'.++$i.': '.htmlentities($task->command).'
'; + echo 'Task #'.++$i.': '.htmlentities($task->command).'
'; } } else { $r=$S['pdo']->query('SELECT * FROM `builds` ORDER BY `ctime` ASC'); diff --git a/frontend/routing.csv b/frontend/routing.csv index e5cc44c..3d21751 100644 --- a/frontend/routing.csv +++ b/frontend/routing.csv @@ -15,6 +15,7 @@ ^logs$ logview ^logs/build([a-z0-9]{6})$ logview build ^logs/task([0-9]+)$ logview task +^logs/task([0-9]+)/([0-9]+)$ logview task page # Build creation ^create$ wizard ^create/([a-zA-Z0-9]{6})$ wizard build diff --git a/shared/config.php b/shared/config.php index 1eeb4ee..3b62b3f 100644 --- a/shared/config.php +++ b/shared/config.php @@ -14,4 +14,5 @@ $conf['check_email_dns']=true; // Use DNS to check the domain of submitted email $conf['pkgdir_root']='/home/eitan/soc/tinderbox'; // The directory to recursively search for pkgdirs in $conf['emerge_default_opts']='-t -K --color=n --root-deps=rdeps'; // DON'T CHANGE UNLESS YOU KNOW WHAT YOU'RE DOING $conf['portdir']='/usr/portage'; // The directory conatining the portage tree to use (/usr/portage unless you have a reason to think otherwise) +$conf['logview_max']=1000; ?> diff --git a/todo b/todo index 3b98fc7..e6df73c 100644 --- a/todo +++ b/todo @@ -5,8 +5,6 @@ Move more functions into corresponding classes Give profiles an auto_increment ID so they can have their directories moved without breaking the db Have backend handle builds that it finds to already be running Add a PID file so backend can't start twice -Add pagination to log viewer Add extra package adding in frontend Implement extra packages in backend -Move the wizard steps into their own directory and just leave pages/wizard.php to handle everything (this will be a step towards backend modularity) -Plan out how the frontend should handle different distro modules +Plan out how the backend should handle different distro modules -- cgit v1.2.3-65-gdbad