room management skeleton

This commit is contained in:
Paolo Asperti 2016-09-14 09:06:55 +02:00
parent 52904028d6
commit e5aa2bcb71
6 changed files with 121 additions and 2 deletions

View File

@ -1,6 +1,6 @@
Summary: Helps client to join domain and maintain itself
Name: doraemon
Version: 1.3.0
Version: 2.0.0-alpha2
Release: 1.ns6
URL: https://github.com/bglug-it/doraemon/
License: GPLv2+
@ -11,7 +11,7 @@ Requires: httpd, php, sudo, php-xml, php-mcrypt
Requires: nethserver-base, nethserver-php
Requires: net-tools
Requires: upstart
Source0: doraemon-1.3.0.tar.gz
Source0: doraemon-2.0.0.tar.gz
BuildArch: noarch
%description
@ -82,6 +82,7 @@ if [ "$1" = 2 ]; then
fi
%post
/etc/e-smith/events/actions/initialize-default-databases
if [ "$1" = 1 ]; then
#installation
/sbin/e-smith/db configuration set %{name} service status enabled TCPPort 3000 access private DefaultRole client DomainFile /etc/domain.yml ManagementKeyFile /home/amgmt/.ssh/id_rsa.pub NamingBase lab NamingDigits 2 VaultPassFile /home/amgmt/.ansible/vault.txt

View File

@ -0,0 +1,7 @@
<?php
/* /usr/share/nethesis/NethServer/Language/en/NethServer_Module_Doraemon_Rooms.php */
$L['Rooms_Title'] = 'Rooms';
$L['Create_Room_Header'] = 'Create a new room';
$L['Update_Room_Header'] = 'Update room "${0}"';

View File

@ -0,0 +1,7 @@
<?php
/* /usr/share/nethesis/NethServer/Language/it/NethServer_Module_Doraemon_Rooms.php */
$L['Rooms_Title'] = 'Stanze';
$L['Create_Room_Header'] = 'Crea una nuova stanza';
$L['Update_Room_Header'] = 'Modifica il nome stanza "${0}"';

View File

@ -0,0 +1,28 @@
<?php
namespace NethServer\Module\Doraemon;
class Rooms extends \Nethgui\Controller\TableController
{
public function initialize()
{
$columns = array(
'Key',
'Actions',
);
$this
->setTableAdapter($this->getPlatform()->getTableAdapter('rooms', 'room'))
->setColumns($columns)
->addRowAction(new \NethServer\Module\Doraemon\Rooms\Modify('update'))
->addRowAction(new \NethServer\Module\Doraemon\Rooms\Modify('delete'))
->addTableAction(new \NethServer\Module\Doraemon\Rooms\Modify('create'))
->addTableAction(new \Nethgui\Controller\Table\Help('Help'))
;
parent::initialize();
}
}

View File

@ -0,0 +1,55 @@
<?php
namespace NethServer\Module\Doraemon\Rooms;
use Nethgui\System\PlatformInterface as Validate;
class Modify extends \Nethgui\Controller\Table\Modify
{
public function initialize()
{
$parameterSchema = array(
// was: Validate::HOSTNAME_FQDN, but we need hostname
array('Name', Validate::ANYTHING, \Nethgui\Controller\Table\Modify::KEY),
// array('MacAddress', Validate::MACADDRESS, \Nethgui\Controller\Table\Modify::FIELD),
// array('Role', Validate::ANYTHING, \Nethgui\Controller\Table\Modify::FIELD),
// array('Role', Validate::ROLES_COLLECTION ??? TODO!!!, \Nethgui\Controller\Table\Modify::FIELD),
);
$this->setSchema($parameterSchema);
parent::initialize();
}
public function validate(\Nethgui\Controller\ValidationReportInterface $report)
{
if ($this->getIdentifier() === 'delete') {
$v = $this->createValidator()->platform('room-delete');
if ( ! $v->evaluate($this->parameters['name'])) {
$report->addValidationError($this, 'Key', $v);
}
}
parent::validate($report);
}
protected function onParametersSaved($parameters)
{
$actionName = $this->getIdentifier();
if ($actionName === 'update') {
$actionName = 'modify';
}
$this->getPlatform()->signalEvent(sprintf('room-%s &', $actionName));
}
public function prepareView(\Nethgui\View\ViewInterface $view)
{
parent::prepareView($view);
$templates = array(
'create' => 'NethServer\Template\Doraemon\Rooms',
'update' => 'NethServer\Template\Doraemon\Rooms',
'delete' => 'Nethgui\Template\Table\Delete',
);
$view->setTemplate($templates[$this->getIdentifier()]);
}
}

View File

@ -0,0 +1,21 @@
<?php
/* @var $view \Nethgui\Renderer\Xhtml */
if ($view->getModule()->getIdentifier() == 'update') {
// disable updating of hostname
// the hostname is the key of the db item, if you change it, bad things happens
$keyFlags = $view::STATE_DISABLED;
$template = 'Update_Room_Header';
} else {
$keyFlags = 0;
$template = 'Create_Room_Header';
}
echo $view->header('hostname')->setAttribute('template', $T($template));
echo $view->panel()
->insert($view->textInput('Name'))
// ->insert($view->textInput('Name', $keyFlags))
;
echo $view->buttonList($view::BUTTON_SUBMIT | $view::BUTTON_CANCEL | $view::BUTTON_HELP);