Skip to content

Commit

Permalink
Storage: Label media
Browse files Browse the repository at this point in the history
Provides a dialog to label barcodes.

- Select one of the defined scratch pools where labeled media goes
- Select the drive to use for labeling
  • Loading branch information
fbergkemper committed Jul 28, 2016
1 parent d524ff1 commit 6073640
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 35 deletions.
2 changes: 1 addition & 1 deletion install/bareos/bareos-dir.d/profile/admin.conf
Expand Up @@ -3,7 +3,7 @@
#
Profile {
Name = admin
CommandACL = *all*
CommandACL = *all*, !configure
Job ACL = *all*
Schedule ACL = *all*
Catalog ACL = *all*
Expand Down
78 changes: 56 additions & 22 deletions module/Storage/src/Storage/Controller/StorageController.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -28,6 +28,8 @@
use Zend\Mvc\Controller\AbstractActionController;
use Zend\View\Model\ViewModel;
use Zend\Json\Json;
use Storage\Form\StorageForm;
use Storage\Model\Storage;

class StorageController extends AbstractActionController
{
Expand Down Expand Up @@ -59,19 +61,43 @@ public function detailsAction()
$action = $this->params()->fromQuery('action');
$storagename = $this->params()->fromRoute('id');

try {
$this->bsock = $this->getServiceLocator()->get('director');
}
catch(Exception $e) {
echo $e->getMessage();
}

try {
$pools = $this->getStorageModel()->getPools($this->bsock, 'scratch');
}
catch(Exception $e) {
echo $e->getMessage();
}

try {
$slots = $this->getStorageModel()->getSlots($this->bsock, $storagename);
$drives = array();
foreach($slots as $slot) {
if($slot['type'] == 'drive') {
array_push($drives, $slot['slotnr']);
}
}
}
catch(Exception $e) {
echo $e->getMessage();
}

$form = new StorageForm($storagename, $pools, $drives);
$form->setAttribute('method','post');

if(empty($action)) {
return new ViewModel(array(
'storagename' => $storagename
'storagename' => $storagename,
'form' => $form
));
}
else {
try {
$this->bsock = $this->getServiceLocator()->get('director');
}
catch(Exception $e) {
echo $e->getMessage();
}

if($action == "import") {
$storage = $this->params()->fromQuery('storage');
$srcslots = $this->params()->fromQuery('srcslots');
Expand Down Expand Up @@ -130,16 +156,25 @@ public function detailsAction()
}
}
elseif($action == "label") {
$storage = $this->params()->fromQuery('storage');
$pool = $this->params()->fromQuery('label');
$drive = $this->params()->fromQuery('drive');
$slots = $this->params()->fromQuery('slots');

try {
$result = $this->getStorageModel()->label($this->bsock, $storage, $pool, $drive, $slots);
}
catch(Exception $e) {
echo $e->getMessage();
$request = $this->getRequest();
if($request->isPost()) {
$s = new Storage();
$form->setInputFilter($s->getInputFilter());
$form->setData( $request->getPost() );
if($form->isValid()) {
$storage = $form->getInputFilter()->getValue('storage');
$pool = $form->getInputFilter()->getValue('pool');
$drive = $form->getInputFilter()->getValue('drive');
try {
$result = $this->getStorageModel()->label($this->bsock, $storage, $pool, $drive);
}
catch(Exception $e) {
echo $e->getMessage();
}
}
else {
// Form data not valid
}
}
}
elseif($action == "updateslots") {
Expand All @@ -153,8 +188,6 @@ public function detailsAction()
}

}
elseif($action == "labelbarcodes") {
}

try {
$this->bsock->disconnect();
Expand All @@ -165,7 +198,8 @@ public function detailsAction()

return new ViewModel(array(
'storagename' => $storagename,
'result' => $result
'result' => $result,
'form' => $form
));
}
}
Expand Down
122 changes: 122 additions & 0 deletions module/Storage/src/Storage/Form/StorageForm.php
@@ -0,0 +1,122 @@
<?php

/**
*
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2016 dass-IT GmbH (http://www.dass-it.de/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*
*/

namespace Storage\Form;

use Zend\Form\Form;
use Zend\Form\Element;

class StorageForm extends Form
{
protected $storage = null;
protected $pools = null;
protected $drives = null;

public function __construct($storage=null, $pools=null, $drives=null)
{

parent::__construct('storage');

$this->storage = $storage;
$this->pools = $pools;
$this->drives = $drives;

// storage
$this->add(array(
'name' => 'storage',
'type' => 'Zend\Form\Element\Hidden',
'attributes' => array(
'value' => $this->storage,
'id' => 'storage'
)
));

// pool
$this->add(array(
'name' => 'pool',
'type' => 'select',
'options' => array(
'label' => _('Pool'),
//'empty_option' => _('Please choose a pool'),
'value_options' => $this->getPoolList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'pool'
)
));

// drive
$this->add(array(
'name' => 'drive',
'type' => 'select',
'options' => array(
'label' => _('Drive'),
//'empty_option' => _('Please choose a drive'),
'value_options' => $this->getDriveList()
),
'attributes' => array(
'class' => 'form-control selectpicker show-tick',
'data-live-search' => 'true',
'id' => 'drive'
)
));

// submit button
$this->add(array(
'name' => 'submit',
'type' => 'submit',
'attributes' => array(
'value' => _('Submit'),
'id' => 'submit'
)
));

}

private function getPoolList()
{
$selectData = array();
if(!empty($this->pools)) {
foreach($this->pools as $pool) {
$selectData[$pool['name']] = $pool['name'];
}
}
return $selectData;
}

private function getDriveList()
{
$selectData = array();
if(!empty($this->drives)) {
foreach($this->drives as $drive) {
$selectData[$drive] = $drive;
}
}
return $selectData;
}

}
85 changes: 82 additions & 3 deletions module/Storage/src/Storage/Model/Storage.php
Expand Up @@ -5,7 +5,7 @@
* bareos-webui - Bareos Web-Frontend
*
* @link https://github.com/bareos/bareos-webui for the canonical source repository
* @copyright Copyright (c) 2013-2015 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @copyright Copyright (c) 2013-2016 Bareos GmbH & Co. KG (http://www.bareos.org/)
* @license GNU Affero General Public License (http://www.gnu.org/licenses/)
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -25,7 +25,86 @@

namespace Storage\Model;

class Storage
use Zend\InputFilter\InputFilter;
use Zend\InputFilter\InputFilterAwareInterface;
use Zend\InputFilter\InputFilterInterface;

class Storage implements InputFilterAwareInterface
{
}

protected $storage = null;
protected $pool = null;
protected $drive = null;

protected $inputFilter = null;

public function setInputFilter(InputFilterInterface $inputFilter)
{
throw new \Exception("setInputFiler() not used");
}

public function getInputFilter()
{
if(!$this->inputFilter) {
$inputFilter = new InputFilter();

$inputFilter->add(array(
'name' => 'pool',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 64
)
)
)
));

$inputFilter->add(array(
'name' => 'drive',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8',
'min' => 1,
'max' => 64
)
)
)
));

$inputFilter->add(array(
'name' => 'storage',
'required' => true,
'filters' => array(
array('name' => 'StripTags'),
array('name' => 'StringTrim'),
),
'validators' => array(
array(
'name' => 'StringLength',
'options' => array(
'encoding' => 'UTF-8'
)
)
)
));

$this->inputFilter = $inputFilter;
}
return $inputFilter;
}
}

0 comments on commit 6073640

Please sign in to comment.