diff options
author | 2009-06-22 10:53:52 -0400 | |
---|---|---|
committer | 2009-06-22 10:53:52 -0400 | |
commit | 524182c5202e7fcf2c02e06e950e6e087d14b6d6 (patch) | |
tree | 901106910ec0be26b19e667752ff833e744da00c /frontend | |
parent | Little fixes to error handling and other minor things (diff) | |
download | ingenue-524182c5202e7fcf2c02e06e950e6e087d14b6d6.tar.gz ingenue-524182c5202e7fcf2c02e06e950e6e087d14b6d6.tar.bz2 ingenue-524182c5202e7fcf2c02e06e950e6e087d14b6d6.zip |
Finished frontend restructuring
Diffstat (limited to 'frontend')
-rw-r--r-- | frontend/pages/wizard.php | 113 | ||||
-rw-r--r-- | frontend/routing.csv | 3 | ||||
-rw-r--r-- | frontend/wizard/step1.php | 23 |
3 files changed, 82 insertions, 57 deletions
diff --git a/frontend/pages/wizard.php b/frontend/pages/wizard.php index 57e9d45..9f2af1d 100644 --- a/frontend/pages/wizard.php +++ b/frontend/pages/wizard.php @@ -4,87 +4,96 @@ function init_wizard() { if (!isset($S['user'])) { return 'login'; } - // TODO only create a table entry after you submit a name - // Move profile to step1, that's distro-dependent // Make it so you can just pop over to config build=x and it will go to the right step if (isset($request['build']) && preg_match('/^[a-zA-Z0-9]{6}$/', $request['build'])) { $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `id`="'.$request['build'].'"'); if ($r->rowCount()) { - $build=new sql_build($r->fetch(PDO::FETCH_ASSOC)); - $S['wizard.build']=&$build; + $S['wizard.build']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); + $build=&$S['wizard.build']; if (!preg_match('#^config/step([0-9]+)$#', $build->status, $match)) { - debug('wizard', 'build not in config stage - PANIC!'); - throw new Exception('We haven\'t implemented this yet.'); + debug('wizard', 'build not in config stage (status '.$build->status.') - PANIC!'); + throw_exception('We haven\'t implemented this yet.'); } - $step=$match[1]; - $S['wizard.step']=&$step; - if (isset($request['step'.$step.'submit'])) { + $S['wizard.step']=$match[1]; + $step=&$S['wizard.step']; + debug('wizard', 'Build '.$build->id." is at step $step"); + if (isset($request['wizard_submit'])) { + debug('wizard', "Processing step $step"); + if (!is_file(FRONTEND."/wizard/step$step.php")) { + throw_exception('wizard', "Step $step doesn't exist!"); + } require_once(FRONTEND."/wizard/step$step.php"); $proc='wizard_process_step'.$step; if (function_exists($proc)) { - $proc(); + if ($proc() === true) { + $build->status='build/ready'; + $build->ctime=time(); + $build->write(); + $S['wizard.done']=true; + return array('title' => 'Config Finished'); + } } else { debug('wizard', 'No processing function for step '.$step); } - $build->status='config/step'.++$step.'.php'; + $build->status='config/step'.++$step; $build->write(); - } - if (is_file(FRONTEND."/wizard/step$step.php")) { - require_once(FRONTEND.'/wizard/step'.$step.'.php'); - $S['title']='Create - Step '.$step; - $proc='wizard_init_step'.$step; - if (function_exists($proc)) { - return $proc(); - } else { - debug('wizard', 'No init function for step '.$step); - return; - } + debug('wizard', "Continuing to step $step"); } else { - throw new Exception("Step $step doesn't exist"); + debug('wizard', "Not ready for processing... staying at step $step"); } } else { - throw new Exception('Build not found'); + throw_exception('Build not found'); } -/* } else { - $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `status` LIKE "config/step0"'); + } elseif (isset($request['init'])) { + $r=$S['pdo']->query('SELECT * FROM `builds` WHERE `owner`='.$S['user']->id.' AND `status`="config/step1"'); if ($r->rowCount()) { $S['wizard.build']=new sql_build($r->fetch(PDO::FETCH_ASSOC)); } else { $S['wizard.build']=new sql_build(); $S['wizard.build']->init(); - }*/ + } + $S['wizard.build']->name=$request['name']; + $S['wizard.build']->write(); + $S['wizard.step']=1; + } + if (isset($S['wizard.build'], $S['wizard.step'])) { + $step=&$S['wizard.step']; + if (is_file(FRONTEND."/wizard/step$step.php")) { + require_once(FRONTEND.'/wizard/step'.$step.'.php'); + $S['title']='Create - Step '.$step; + $proc='wizard_init_step'.$step; + if (function_exists($proc)) { + return $proc(); + } else { + debug('wizard', 'No init function for step '.$step); + return; + } + } else { + throw_exception("Step $step doesn't exist"); + } } return array('title' => 'Create'); } function body_wizard() { global $S; if (isset($S['wizard.build'])) { - $build=&$S['wizard.build']; - $step=&$S['wizard.step']; - echo '<form action="'.url('create/'.$build->id).'" method="post">'; - require_once(FRONTEND."/wizard/step$step.php"); - $proc='wizard_body_step'.$step; - $proc(); - echo '<input type="submit" name="step'.$S['wizard.step'].'submit" /></form>'; - } else { - echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your build (optional): <input name="name" /><br/>Profile: <select name="pkgdir">'; - $r=$S['pdo']->query('SELECT * FROM `profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled - while ($profile=$r->fetch(PDO::FETCH_ASSOC)) { - $profile=new sql_profile($profile); - $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/'); - echo '<option value="'.htmlentities($profile->pkgdir).'">'.htmlentities($display).'</option>'; + if (isset($S['wizard.done'])) { + echo '<h3>Config finished!</h3><p>Check your build\'s status <a href="'.url('logs/build'.$S['wizard.build']->id).'">here</a></p>'; + } else { + $build=&$S['wizard.build']; + $step=&$S['wizard.step']; + echo '<form action="'.url('create/'.$build->id).'" method="post">'; + require_once(FRONTEND."/wizard/step$step.php"); + $proc='wizard_body_step'.$step; + if (!function_exists($proc)) { + throw_exception("Body function doesn't exist for wizard step $step"); + } + $proc(); + echo '<input type="submit" name="wizard_submit" value="Continue" /></form>'; } - echo '</select><br/><input type="submit" name="step[0]" value="Start" /></form>'; -// } else { -// echo '<h3>Config finished!</h3><p>Check your build\'s status <a href="'.url('logs/build'.$S['build']->id).'">here</a></p>'; + } else { + echo '<form action="'.url('create').'" method="post"><h3>Request an image built</h3>Name of your build (optional): <input name="name" /><br/>'; + echo '<input type="submit" name="init" value="Start" /></form>'; } } -function wizard_init() { - global $S, $request; - $S['build']->name=$request['name']; - $profile=new sql_profile($request['pkgdir']); - $profileopt=new sql_buildopt($S['build']->id, 'profile', $profile->pkgdir); // TODO pkgdir -> id - $profileopt->write(); - $S['build']->write(); -} ?> diff --git a/frontend/routing.csv b/frontend/routing.csv index ba0f7c1..e5cc44c 100644 --- a/frontend/routing.csv +++ b/frontend/routing.csv @@ -17,7 +17,8 @@ ^logs/task([0-9]+)$ logview task # Build creation ^create$ wizard -^create/[0-9]+$ wizard stage +^create/([a-zA-Z0-9]{6})$ wizard build +^create/([a-zA-Z0-9]{6})/([0-9]+)$ wizard build step # Session ^login$ login ^logout$ logout diff --git a/frontend/wizard/step1.php b/frontend/wizard/step1.php index baef871..ab3fea5 100644 --- a/frontend/wizard/step1.php +++ b/frontend/wizard/step1.php @@ -1,11 +1,26 @@ <?php -function init_wizard_step1() { +function wizard_init_step1() { return array('title' => 'Create - Step 1'); } -function body_wizard_step1() { +function wizard_body_step1() { global $S; - $build=&$S['build']; + $build=&$S['wizard.build']; $opts=$build->get_buildopts(); - echo '<h3>Step 1</h3><form action="'.url('create').'" method="post"><input type="submit" name="step[1]" value="Build!" /></form>'; + echo '<h3>Step 1</h3>'; + echo 'Profile: <select name="pkgdir">'; + $r=$S['pdo']->query('SELECT * FROM `profiles` WHERE `flags` NOT LIKE "%d%"'); // d for disabled + while ($profile=$r->fetch(PDO::FETCH_ASSOC)) { + $profile=new sql_profile($profile); + $display=$profile->name?$profile->name:($profile->pkgdir?$profile->pkgdir:'/'); + echo '<option value="'.htmlentities($profile->pkgdir).'">'.htmlentities($display).'</option>'; + } + echo '</select><br/>'; +} +function wizard_process_step1() { + global $S, $request; + $profile=new sql_profile($request['pkgdir']); + $profileopt=new sql_buildopt($S['wizard.build']->id, 'profile', $profile->pkgdir); + $profileopt->write(); + return true; } ?> |