Skip to content

Commit

Permalink
Move requirement stuff into its own class and add db configuration form
Browse files Browse the repository at this point in the history
Moved all the requirement stuff from the IndexController and the
RequirementsForm into its own class, added the basic database
configuration form and restructured some parts of the code, the
layout as well as the overall "flow".

refs #3761
  • Loading branch information
Johannes Meyer committed Oct 7, 2013
1 parent 943cb44 commit 7c6d8b4
Show file tree
Hide file tree
Showing 8 changed files with 786 additions and 290 deletions.
419 changes: 419 additions & 0 deletions install/Application/Report.php

Large diffs are not rendered by default.

346 changes: 121 additions & 225 deletions install/Application/controllers/IndexController.php

Large diffs are not rendered by default.

148 changes: 148 additions & 0 deletions install/Application/forms/DbConfigForm.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
<?php
// {{{ICINGA_LICENSE_HEADER}}}
/**
* This file is part of Icinga 2 Web.
*
* Icinga 2 Web - Head for multiple monitoring backends.
* Copyright (C) 2013 Icinga Development Team
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
* @copyright 2013 Icinga Development Team <info@icinga.org>
* @license http://www.gnu.org/licenses/gpl-2.0.txt GPL, version 2
* @author Icinga Development Team <info@icinga.org>
*/
// {{{ICINGA_LICENSE_HEADER}}}

namespace Icinga\Installer\Pages;

require_once realpath(__DIR__ . '/WizardForm.php');

/**
* Wizard-Page that prompts the user for database configuration details
*/
class DbConfigForm extends WizardForm
{
public function create()
{
$this->addNote('Database configuration', 1);

$this->addNote('Primary database store to use', 2);

$this->addElement(
'text',
'resource_name',
array(
'label' => 'Resource name',
'helptext' => 'This is the name internally used by Icinga 2 Web to identify this database store.',
'required' => true,
'allowEmpty' => false,
'value' => 'icinga2web'
)
);

$this->addElement(
'select',
'db_provider',
array(
'label' => 'Database provider',
'helptext' => 'Specifies the type or vendor of this database.',
'required' => true,
'allowEmpty' => false,
'multiOptions' => $this->getAvailableProviders()
)
);

$this->addElement(
'text',
'db_host',
array(
'label' => 'Hostname',
'helptext' => 'The host of this database.',
'required' => true,
'allowEmpty' => false,
'value' => 'localhost'
)
);

$this->addElement(
'text',
'db_port',
array(
'label' => 'Port',
'helptext' => 'The port of this database. (Leave blank to use the default.)',
'allowEmpty' => true
)
);

$this->addElement(
'text',
'db_name',
array(
'label' => 'Database name',
'helptext' => 'The name of this database.',
'required' => true,
'allowEmpty' => false,
'value' => 'icinga2web'
)
);

$this->addElement(
'text',
'db_username',
array(
'label' => 'Username',
'helptext' => 'The username to use for authentication with this database.',
'required' => true,
'allowEmpty' => false,
'value' => 'icinga2web'
)
);

$this->addElement(
'text',
'db_password',
array(
'label' => 'Password',
'helptext' => 'The password to use for authentication with this database.',
'required' => true,
'allowEmpty' => false,
'value' => 'icinga'
)
);

$this->setSubmitLabel('Continue');
}

/**
* Return a list of available database providers
*
* @return array
*/
private function getAvailableProviders()
{
$reportInfo = $this->getReport()->toArray();
$providers = array();

if ($reportInfo['hasMysqlExtension'] && $reportInfo['hasMysqlAdapter']) {
array_push($providers, 'mysql');
}
if ($reportInfo['hasPgsqlExtension'] && $reportInfo['hasPgsqlAdapter']) {
array_push($providers, 'pgsql');
}

return $providers;
}
}
59 changes: 5 additions & 54 deletions install/Application/forms/RequirementsForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,78 +28,29 @@

namespace Icinga\Installer\Pages;

require_once realpath(__DIR__ . '/WizardForm.php');

/**
* Wizard-Page that displays a report about required software and extensions
*/
class RequirementsForm extends WizardForm
{
/**
* The report that is shown to the user
*
* @var array
*/
private $report;

/**
* Set the report that should be shown to the user
*
* @param array $report The report to display
*/
public function setReport(array $report)
{
$this->report = $report;
}

public function create()
{
$canAdvance = true;
$tableContent = '';
foreach ($this->report as $requirementInfo) {
if ($requirementInfo['state'] === -1) {
$canAdvance = false;
$tableContent .= '<tr class="danger">';
} elseif ($requirementInfo['state'] === 0) {
$tableContent .= '<tr class="warning">';
} else {
$tableContent .= '<tr class="success">';
}

$helpText = '';
if (isset($requirementInfo['help']) && $requirementInfo['help']) {
$helpText = '<br /><span style="font-size:.8em">' . $requirementInfo['help'] . '</span>';
}
$tableContent .= '<td>' . $requirementInfo['description'] . $helpText . '</td>';
$tableContent .= '<td>' . $requirementInfo['note'] . '</td>';
$tableContent .= '</tr>';
}
$this->addNote('Requirements', 1);

$this->addNote(
'<table class="table">'
. ' <thead>'
. ' <tr>'
. ' <th>Requirement</th>'
. ' <th>State</th>'
. ' </tr>'
. ' </thead>'
. ' <tbody>'
. $tableContent
. ' </tbody>'
. '</table>'
);
$this->addNote($this->getReport()->render());

if ($canAdvance) {
if ($this->getReport()->isOk()) {
$this->addNote(
'<span style="font-weight:bold;">All required software and packages available.</span>'
. ' You can now start configuring your new Icinga 2 Web installation!'
);
$this->advance('Continue');
$this->setSubmitLabel('Continue');
} else {
$this->addNote(
'<span style="font-weight:bold;">Some mandatory requirements are not fulfilled!</span>'
. ' Please check your environment and install the appropriate software and packages.'
);
$this->setSubmitLabel('Restart');
}
}
}
6 changes: 3 additions & 3 deletions install/Application/forms/StartForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,19 @@

namespace Icinga\Installer\Pages;

require_once realpath(__DIR__ . '/WizardForm.php');

/**
* The starting page of the install wizard
*/
class StartForm extends WizardForm
{
public function create()
{
$this->addNote('Start', 1);

$this->addNote(
'Some descriptive words about Icinga 2 Web and possibly a few words about what the new features are.'
);

$this->advance('Install');
$this->setSubmitLabel('Install');
}
}
76 changes: 71 additions & 5 deletions install/Application/forms/WizardForm.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,93 @@
require_once realpath(__DIR__ . '/../../../library/Icinga/Web/Form/Decorator/BootstrapForm.php');

use \Icinga\Web\Form;
use \Icinga\Installer\Report;

/**
* Base form for every wizard page
*/
class WizardForm extends Form
{
/**
* Mark the current page as able to advance to the next one
* The system report
*
* @param string $submitLabel The submit label to display
* @var Report
*/
public function advance($submitLabel)
private $report;

/**
* Set the system report to use
*
* @param Report $report The report to use
*/
public function setReport(Report $report)
{
$this->report = $report;
}

/**
* Return the currently used system report
*
* @return Report The current system report
*/
public function getReport()
{
return $this->report;
}

/**
* Mark the current page to advance to the next one
*/
public function advanceToNextPage()
{
$this->setProgress($this->getRequest()->getPost('progress', 1) + 1);
}

/**
* Mark the current page to advance not to the next one
*/
public function stayOnPage()
{
$this->setProgress($this->getRequest()->getPost('progress', 1));
}

/**
* Mark the current page to restart the wizard on submit
*/
public function restartWizard()
{
$this->setProgress(1);
}

/**
* Set the progress of the wizard
*
* @param int $step The current wizard step
*/
public function setProgress($step)
{
$this->addElement(
'hidden',
'progress',
array(
'value' => $this->getRequest()->getPost('progress', 1) + 1
'value' => $step
)
);
}

$this->setSubmitLabel($submitLabel);
/**
* Get the current wizard step
*
* @return int
*/
public function getCurrentStep()
{
$step = $this->getValue('progress');
if ($step === null) {
$step = $this->getRequest()->getPost('progress', 1);
} else {
$step -= 1;
}
return $step;
}
}
2 changes: 1 addition & 1 deletion install/Application/layouts/scripts/body.phtml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<?php echo $this->render('menu.phtml') ?>

</div>
<div class="col-sm-11 col-xs-11 col-md-10 col-lg-10" style="padding: 50px 25px 0 25px;">
<div class="col-sm-11 col-xs-11 col-md-10 col-lg-10" style="padding: 0 25px 0 25px;">
<?php echo $this->layout()->content; ?>

</div>
Expand Down
20 changes: 18 additions & 2 deletions install/Application/layouts/scripts/menu.phtml
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
<?php $currentStep = isset($this->form) ? $this->form->getCurrentStep() : 0; ?>
<table class="table" style="margin: .7em;">
<tr class="<?php echo $this->currentStep == 1 ? 'active' : ($this->currentStep > 1 ? 'success' : '') ?>">
<tr class="<?php echo $currentStep == 1 ? 'active' : ($currentStep > 1 ? 'success' : '') ?>">
<td>Start</td>
</tr>
<tr class="<?php echo $this->currentStep == 2 ? 'active' : ($this->currentStep > 2 ? 'success' : '') ?>">
<tr class="<?php echo $currentStep == 2 ? 'active' : ($currentStep > 2 ? 'success' : '') ?>">
<td>Requirements</td>
</tr>
<tr class="<?php echo $currentStep == 3 ? 'active' : ($currentStep > 3 ? 'success' : '') ?>">
<td>Database configuration</td>
</tr>
<tr class="<?php echo $currentStep == 4 ? 'active' : ($currentStep > 4 ? 'success' : '') ?>">
<td>Authentication & Preferences</td>
</tr>
<tr class="<?php echo $currentStep == 5 ? 'active' : ($currentStep > 5 ? 'success' : '') ?>">
<td>Backend configuration</td>
</tr>
<tr class="<?php echo $currentStep == 6 ? 'active' : ($currentStep > 6 ? 'success' : '') ?>">
<td>Overview / Confirmation</td>
</tr>
<tr class="<?php echo $currentStep == 7 ? 'active' : ($currentStep > 7 ? 'success' : '') ?>">
<td>End</td>
</tr>
</table>

0 comments on commit 7c6d8b4

Please sign in to comment.