summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEudyptula <eitan@mosenkis.net>2009-07-24 11:09:15 -0400
committerEudyptula <eitan@mosenkis.net>2009-07-24 11:09:15 -0400
commitb006cfcdd1245105f9e22b104ca8527229b17ae4 (patch)
tree9e6f43bdb614bdd079c6da58392bd95633279cdd /frontend
parentClean up backend API (diff)
downloadingenue-b006cfcdd1245105f9e22b104ca8527229b17ae4.tar.gz
ingenue-b006cfcdd1245105f9e22b104ca8527229b17ae4.tar.bz2
ingenue-b006cfcdd1245105f9e22b104ca8527229b17ae4.zip
Broke log viewer into segments, added build deletion
Diffstat (limited to 'frontend')
-rw-r--r--frontend/pages/builds/delete.php20
-rw-r--r--frontend/pages/builds/index.php18
-rw-r--r--frontend/pages/builds/log.php29
-rw-r--r--frontend/pages/builds/task.php56
-rw-r--r--frontend/pages/logview.php87
-rw-r--r--frontend/routing.csv18
6 files changed, 132 insertions, 96 deletions
diff --git a/frontend/pages/builds/delete.php b/frontend/pages/builds/delete.php
new file mode 100644
index 0000000..cf6c6d4
--- /dev/null
+++ b/frontend/pages/builds/delete.php
@@ -0,0 +1,20 @@
+<?php
+function init_builds_delete() {
+ global $S, $request;
+ if (!isset($S['user'])) return 'login';
+ if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) return '404';
+ $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"');
+ if ($r->rowCount() == 0) return '404';
+ $S['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ if (!owner_or_admin($S['build']->id)) return '404';
+ return array('title' => 'Delete Build');
+}
+function body_builds_delete() {
+ global $S;
+ if ($S['build']->status >= 0 || $S['build']->status == -128) {
+ $S['build']->delete();
+ echo print_success('Build deleted.');
+ } else
+ echo print_error('Cannot delete build while it is being built.');
+}
+?>
diff --git a/frontend/pages/builds/index.php b/frontend/pages/builds/index.php
new file mode 100644
index 0000000..4b6b7c8
--- /dev/null
+++ b/frontend/pages/builds/index.php
@@ -0,0 +1,18 @@
+<?php
+function init_builds_index() {
+ global $S;
+ if (!isset($S['user'])) return 'login';
+ return array('title' => 'My Builds');
+}
+function body_builds_index() {
+ global $S;
+ $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC');
+ if ($r->rowCount() == 0) {
+ echo print_warning('No builds found.');
+ }
+ while ($build=$r->fetch(PDO::FETCH_ASSOC)) {
+ $build=new sql_build($build);
+ echo $build->display();
+ }
+}
+?>
diff --git a/frontend/pages/builds/log.php b/frontend/pages/builds/log.php
new file mode 100644
index 0000000..ee652f3
--- /dev/null
+++ b/frontend/pages/builds/log.php
@@ -0,0 +1,29 @@
+<?php
+function init_builds_log() {
+ global $S, $request;
+ $S['title']='Log Viewer';
+ if (!isset($S['user'])) return 'login';
+ if (!(isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build']))) return '404';
+ $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"');
+ if ($r->rowCount()) {
+ $S['builds_log']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
+ if (!owner_or_admin($S['builds_log']->owner)) return '404'; // TODO permission denied
+ } else
+ return '404';
+ if (isset($request['task']) && is_numeric($request['task']))
+ return 'builds/task';
+}
+function body_builds_log() {
+ global $S;
+ $build=&$S['builds_log'];
+ echo $build->display();
+ $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$build->id.'" ORDER BY `order` ASC');
+ if ($r->rowCount() == 0) {
+ echo '<b>No tasks found.</b>';
+ }
+ while ($task=$r->fetch(PDO::FETCH_ASSOC)) {
+ $task=new sql_task($task);
+ echo $task->display();
+ }
+}
+?>
diff --git a/frontend/pages/builds/task.php b/frontend/pages/builds/task.php
new file mode 100644
index 0000000..8724857
--- /dev/null
+++ b/frontend/pages/builds/task.php
@@ -0,0 +1,56 @@
+<?php
+function init_builds_task() {
+ global $S, $request;
+ if (!isset($S['user'])) return 'login';
+ if (!(isset($S['builds_log']) && isset($request['task']) && is_numeric($request['task']))) return 'builds/log';
+ $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$S['builds_log']->id.'" AND `order`='.$request['task']);
+ if ($r->rowCount()) {
+ $S['builds_task']=new sql_task($r->fetch(PDO::FETCH_ASSOC));
+ } else
+ return '404';
+}
+function body_builds_task() {
+ global $S, $request, $conf;
+ $task=&$S['builds_task'];
+ echo '<div style="font-size: 130%">'.$task->display().'</div>';
+ echo '<a href="'.url("build/$task->build/log").'">Back</a><br/>';
+ $page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1;
+ $count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN);
+ $pager='';
+ if ($count > $conf['logview_max']) {
+ $pager='<form action="'.url("build/$task->build/log/$task->order").'" method="post" onsubmit="window.location.href=\''.url("build/$task->build/log/$task->order").'/\'+this.page.value; return false">Page: ';
+ if ($page > 1) {
+ $pager.='<input type="button" value="&lt;&lt;" 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="&gt;&gt;" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n";
+ }
+ $pager.='</form>';
+ echo $pager;
+ }
+ $r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']);
+ if ($r->rowCount()) {
+ echo '<div style="font-family: monospace">';
+ $ansi=new ansi_to_html();
+ while ($entry=$r->fetch(PDO::FETCH_ASSOC)) {
+ $entry=new sql_buildlog_entry($entry);
+ echo '<'.($t=($entry->stream=='stderr'?'b':'span')).' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' '.date('D j M Y @ H:i:s T', $entry->timestamp).'">'.$ansi->process($entry->text)."</$t>";
+ }
+ echo $ansi->reset(); // Clear any leftover <span>s
+ echo '</div>';
+ echo $pager;
+ echo '<a href="'.url("build/$task->build/log").'">Back</a><br/>';
+ } else {
+ if ($count) {
+ echo print_error("There aren't $page pages. Try an <a href=\"".url("build/$task->build/log/$task->order")."\">earlier page</a>.");
+ } else {
+ echo print_warning('No output');
+ }
+ }
+}
+?>
diff --git a/frontend/pages/logview.php b/frontend/pages/logview.php
deleted file mode 100644
index ac41c5d..0000000
--- a/frontend/pages/logview.php
+++ /dev/null
@@ -1,87 +0,0 @@
-<?php
-function init_logview() {
- global $S, $request;
- $S['title']='Log Viewer';
- if (!isset($S['user'])) return 'login';
- if (isset($request['build']) && strlen($request['build']) == 6 && ctype_alnum($request['build'])) {
- $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `id`="'.$request['build'].'"');
- if ($r->rowCount()) {
- $S['logview']['build']=new sql_build($r->fetch(PDO::FETCH_ASSOC));
- if (!owner_or_admin($S['logview']['build']->owner)) return '404'; // TODO permission denied
- } else
- return '404';
- if (isset($request['task']) && is_numeric($request['task'])) {
- $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$request['build'].'" AND `order`='.$request['task']);
- if ($r->rowCount()) {
- $S['logview']['task']=new sql_task($r->fetch(PDO::FETCH_ASSOC));
- } // else return '404'; // Just goes to the build if task is missing
- }
- }
-}
-function body_logview() {
- global $S, $request, $conf;
- if (isset($S['logview']['task'])) {
- $task=&$S['logview']['task'];
- echo '<div style="font-size: 130%">'.$task->display().'</div>';
- echo '<a href="'.url('logs/'.$task->build).'">Back</a><br/>';
- $page=isset($request['page']) && is_numeric($request['page'])?$request['page']:1;
- $count=$S['pdo']->query('SELECT COUNT(*) FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order)->fetch(PDO::FETCH_COLUMN);
- $pager='';
- if ($count > $conf['logview_max']) {
- $pager='<form action="'.url('logs/'.$task->build.'/'.$task->order).'" method="post" onsubmit="window.location.href=\''.url('logs/'.$task->build.'/'.$task->order).'/\'+this.page.value; return false">Page: ';
- if ($page > 1) {
- $pager.='<input type="button" value="&lt;&lt;" 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="&gt;&gt;" onclick="this.form.page.value='.($page+1).'; this.form.onsubmit()" />'."\n";
- }
- $pager.='</form>';
- echo $pager;
- }
- $r=$S['pdo']->query('SELECT * FROM `buildlogs` WHERE `build`=\''.$task->build.'\' AND `task`='.$task->order.' ORDER BY `order` ASC LIMIT '.$conf['logview_max'].' OFFSET '.($page-1)*$conf['logview_max']);
- if ($r->rowCount()) {
- echo '<div style="font-family: monospace">';
- $ansi=new ansi_to_html();
- while ($entry=$r->fetch(PDO::FETCH_ASSOC)) {
- $entry=new sql_buildlog_entry($entry);
- echo '<'.($t=($entry->stream=='stderr'?'b':'span')).' title="'.strtoupper($entry->stream).', entry #'.$entry->order.' '.date('D j M Y @ H:i:s T', $entry->timestamp).'">'.$ansi->process($entry->text)."</$t>";
- }
- echo $ansi->reset(); // Clear any leftover <span>s
- echo '</div>';
- echo $pager;
- echo '<a href="'.url('logs/'.$task->build).'">Back</a><br/>';
- } else {
- if ($count) {
- echo print_error("There aren't $page pages. Try an <a href=\"".url('logs/'.$task->build.'/'.$task->order)."\">earlier page</a>.");
- } else {
- echo print_warning('No output');
- }
- }
- } elseif (isset($S['logview']['build'])) {
- $build=&$S['logview']['build'];
- echo $build->display();
- $r=$S['pdo']->query('SELECT * FROM `tasks` WHERE `build`="'.$request['build'].'" ORDER BY `order` ASC');
- if ($r->rowCount() == 0) {
- echo '<b>No tasks found.</b>';
- }
- while ($task=$r->fetch(PDO::FETCH_ASSOC)) {
- $task=new sql_task($task);
- echo $task->display();
- }
- } else {
- $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' ORDER BY `ctime` IS NULL ASC, `ctime` ASC, `status` DESC');
- if ($r->rowCount() == 0) {
- echo print_warning('No builds found.');
- }
- while ($build=$r->fetch(PDO::FETCH_ASSOC)) {
- $build=new sql_build($build);
- echo $build->display();
- }
- }
-}
-?>
diff --git a/frontend/routing.csv b/frontend/routing.csv
index 3a93c19..a0bf3c2 100644
--- a/frontend/routing.csv
+++ b/frontend/routing.csv
@@ -11,21 +11,21 @@
# Home
^$ welcome
-# Logs
-^builds$ logview
-^logs/([a-z0-9]{6})$ logview build
-^logs/([a-z0-9]{6})/([0-9]+)$ logview build task
-^logs/([a-z0-9]{6})/([0-9]+)/([0-9]+)$ logview build task page
-#^logs/([a-z0-9]{6})/live$ livelog build
+# Builds
+^builds$ builds/index
+^build/([a-z0-9]{6})/log$ builds/log build
+^build/([a-z0-9]{6})/log/([0-9]+)$ builds/task build task
+^build/([a-z0-9]{6})/log/([0-9]+)/([0-9]+)$ builds/task build task page
+^build/([a-zA-Z0-9]{6})/download$ builds/download build
+^build/([a-zA-Z0-9]{6})/history$ builds/history build
+^build/([a-zA-Z0-9]{6})/delete$ builds/delete build
+#^build/([a-z0-9]{6})/live$ builds/live build
# Configurations
^create$ configurations/wizard
^config/([a-zA-Z0-9]{6})$ configurations/wizard configuration
^config/([a-zA-Z0-9]{6})/([0-9]+)$ configurations/wizard configuration step
^config/([a-zA-Z0-9]{6})/status$ configurations/status configuration
^configurations$ configurations/manager
-# Download finished image
-^download/([a-zA-Z0-9]{6})$ builds/download build
-^download/([a-zA-Z0-9]{6})/history$ builds/history build
# Session
^login$ login
^login/(.+)$ login go