Commit 25e429c7 authored by Côme Chilliet's avatar Côme Chilliet

🚜 feat(fai) Migrating FAI package list to selectManagement

Mostly working.
We may still want to add a real objectType for packages to avoid crashes
 in corner cases. (management instances are not made to handle
 ListingEntry instances with a non-existing object type)
Got rid of the session usage to pass the release to the dialog class.

issue #6007
parent 72ba4763
This diff is collapsed.
......@@ -65,7 +65,7 @@ class DiskEntryDialog extends GenericDialog
function handle_cancel ()
{
if ($this->initialDialogValue !== NULL) {
$this->attribute->addValue($this->initialDialogValue);
$this->attribute->addValue('', $this->initialDialogValue);
}
return FALSE;
}
......
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2017-2019 FusionDirectory
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
......@@ -19,39 +19,60 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class packageSelect extends simpleSelectManagement
class PackageSelectCustomFilterElement extends FilterElement
{
protected $objectTypes = [];
protected $autoFilter = FALSE;
protected $departmentBrowser = FALSE;
protected $departmentRootVisible = FALSE;
protected $baseMode = FALSE;
protected $customs;
function __construct ()
public function __construct (managementFilter $parent)
{
$this->filterXMLPath = get_template_path('selectPackage-filter.xml', TRUE, dirname(__FILE__));
$this->listXMLPath = get_template_path('selectPackage-list.xml', TRUE, dirname(__FILE__));
global $config;
parent::__construct($parent);
if (!session::global_is_set(get_class($this).'_filter')) {
$filter = new filterFAIcustoms($this->filterXMLPath);
session::global_set(get_class($this).'_filter', $filter);
$this->customs = [];
foreach ($this->parent->parent->getCustomReleases() as $custom) {
$this->customs[$custom] = [
'custom' => $custom,
'checked' => FALSE,
];
}
}
parent::__construct();
public function update ()
{
foreach ($this->customs as $key => &$custom) {
$custom['checked'] = isset($_POST['filter_custom_'.$key]);
}
unset($custom);
}
function save ()
public function render (): string
{
$act = $this->detectPostActions();
$headpage = $this->getHeadpage();
if (!isset($act['targets'])) {
return [];
if (empty($this->customs)) {
return '';
}
$inputs = [];
foreach ($this->customs as $key => $custom) {
$inputs['filter_custom_'.$key] = [
'name' => sprintf(_('Custom %s'), $custom['custom']),
'desc' => sprintf(_('Custom %s'), $custom['custom']),
'icon' => NULL,
'checked' => $custom['checked'],
];
}
$ret = [];
foreach ($act['targets'] as $dn) {
$ret[] = $headpage->getEntry($dn);
$smarty = get_smarty();
$smarty->assign('NAME', _('Customs'));
$smarty->assign('INPUTS', $inputs);
return $smarty->fetch(get_template_path('management/filter-element.tpl'));
}
public function getFilters (string $type, array &$filters): bool
{
foreach ($this->customs as $custom) {
if ($custom['checked']) {
$filters[] = $custom['custom'];
}
}
return $ret;
return FALSE;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2019 FusionDirectory
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
......@@ -18,45 +20,7 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class filterFAIcustoms extends filter
class PackageSelectManagementDialog extends GenericSelectManagementDialog
{
var $customs = [];
function __construct ($filename)
{
$release = session::get('packageSelect_Release');
$this->customs = serviceRepository::getCustomReleases($release);
parent::__construct($filename);
}
function load ($filename)
{
$res = parent::load($filename);
foreach ($this->customs as $custom) {
$this->elements[$custom] = [
'type' => 'checkbox',
'tag' => $custom,
'default' => 'false',
'set' => [],
'unset' => []
];
$this->elementValues[$custom] = '';
}
return $res;
}
function render ()
{
$smarty = get_smarty();
$customs = [];
foreach ($this->customs as $custom) {
$customs[$custom] = $this->getCheckbox($this->elements[$custom]);
}
$smarty->assign('customs', $customs);
return parent::render();
}
protected $dialogClass = 'packageSelectManagement';
}
This diff is collapsed.
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2018-2019 FusionDirectory
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 St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class packageSelectManagement extends selectManagement
{
/* Default columns */
public static $columns = [
//~ ['ObjectTypeColumn', []],
['LinkColumn', ['attributes' => 'PACKAGE', 'label' => 'Package']],
['LinkColumn', ['attributes' => 'VERSION', 'label' => 'Version']],
];
/* Disable and hide configuration system */
protected $skipConfiguration = TRUE;
protected $parentPlugin;
function __construct (
$parent,
$objectTypes = FALSE,
bool $multiSelect = TRUE,
array $neededAttrs = [],
array $blackList = [],
array $whiteList = [],
array $filterElementDefinitions = [])
{
$this->parentPlugin = $parent;
parent::__construct($objectTypes, $multiSelect, $neededAttrs, $blackList, $whiteList, $filterElementDefinitions);
}
protected function setUpListing ()
{
/* Set baseMode to FALSE */
$this->listing = new managementListing($this, FALSE, $this->multiSelect);
}
protected function setUpFilter (array $filterElementDefinitions)
{
$this->filter = new packageSelectManagementFilter($this, TRUE, $filterElementDefinitions);
}
public function getCustomReleases(): array
{
return serviceRepository::getCustomReleases($this->parentPlugin->FAIdebianRelease);
}
public function getRelease(): string
{
return $this->parentPlugin->FAIdebianRelease;
}
}
<?php
/*
This code is part of FusionDirectory (http://www.fusiondirectory.org/)
Copyright (C) 2003-2010 Cajus Pollmeier
Copyright (C) 2011-2016 FusionDirectory
Copyright (C) 2011-2019 FusionDirectory
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
......@@ -19,22 +19,27 @@
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
*/
class filterFAIPackages extends filterLDAPBlacklist
class packageSelectManagementFilter extends managementFilter
{
static function query ($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = '')
function __construct (management $parent, bool $fixedScope = NULL, array $filterElementDefinitions = [])
{
$filterElementDefinitions[] = ['PackageSelectCustomFilterElement', []];
parent::__construct ($parent, $fixedScope, $filterElementDefinitions);
}
function query (array $attrs, string $base): array
{
//~ static function query ($parent, $base, $scope, $filter, $attributes, $category, $objectStorage = '')
$customs = [];
foreach ($parent->customs as $custom) {
if ($parent->elementValues[$custom] == 'true') {
$customs[] = $custom;
}
}
$filter = preg_replace('/\*/', '', $filter);
$pkgs = [];
$this->filterElements[0]->getFilters('faiRepositoryPackage', $customs);
$entries = [];
$row = 0;
$q = new supportDaemon();
$filter = ["$filter"];
$filter = [$this->search];
$attrs = ['distribution', 'package', 'version', 'section', 'timestamp'];
$release = session::get('packageSelect_Release');
$release = $this->parent->getRelease();
$ret = $q->FAI_get_packages($release, $attrs, $filter, 0, 200);
if ($q->is_error()) {
msg_dialog::display(_('Infrastructure service'), msgPool::siError($q->get_error()), ERROR_DIALOG);
......@@ -48,34 +53,19 @@ class filterFAIPackages extends filterLDAPBlacklist
$ret = array_merge($ret, $ret2);
}
foreach ($ret as $attr) {
$attr['objectClass'] = 'FAKE_OC__FaiPackage';
if (in_array($attr['PACKAGE'], $this->parent->blackList['PACKAGE'])) {
continue;
}
$item = [];
$item['dn'] = 'dn='.$attr['PACKAGE'].','.$attr['DISTRIBUTION'].','.$base;
$item['count'] = 0;
foreach ($attr as $key => $value) {
$item['count']++;
$item[] = $key;
$item[$key] = ['count' => 1, $value];
$item[$key] = [$value];
}
$pkgs[] = $item;
$dn = 'dn='.$attr['PACKAGE'].','.$attr['DISTRIBUTION'].','.$base;
$entries[$dn] = new ListingEntry($this->parent->listing, 'faiRepositoryPackage', $dn, $item, $row++);
$entries[$dn]->aclBase = $base;
}
}
return static::filterByBlacklist($pkgs);
}
function save ()
{
$act = $this->detectPostActions();
$headpage = $this->getHeadpage();
if (!isset($act['targets'])) {
return [];
}
$ret = [];
foreach ($act['targets'] as $dn) {
$ret[] = $headpage->getEntry($dn);
}
return $ret;
return [$entries, ['faiRepositoryPackage' => count($entries)]];
}
}
<div class="contentboxh">
<p>{t}Filter{/t}</p>
</div>
<div class="contentboxb">
<p style="margin:0;padding:3px;">
{t}A maximum of 200 entries will be shown here.{/t}
</p>
{foreach from=$customs key=key item=value}
{$value}<label for="{$key}">&nbsp;custom {$key}</label><br/>
{/foreach}
<hr/>
<label for="NAME"><img src="geticon.php?context=actions&amp;icon=system-search&amp;size=16"/></label>{$NAME}
<div>
{$APPLY}
</div>
</div>
<?xml version="1.0" encoding="UTF-8"?>
<filterdef>
<definition>
<category>fai</category>
<template>../plugins/admin/fai/packageSelect/selectPackage-filter.tpl</template>
<initial>true</initial>
</definition>
<search>
<query>
<backend>FAIPackages</backend>
<filter>$NAME</filter>
<attribute>SECTION</attribute>
<attribute>VERSION</attribute>
<attribute>PACKAGE</attribute>
</query>
<scope>auto</scope>
</search>
<element>
<type>textfield</type>
<tag>NAME</tag>
<size>20</size>
<maxlength>60</maxlength>
<default></default>
<unset></unset>
<set>*$</set>
<alphabet>true</alphabet>
</element>
</filterdef>
<?xml version="1.0" encoding="UTF-8"?>
<list>
<definition>
<departmentBrowser>false</departmentBrowser>
<departmentRootVisible>false</departmentRootVisible>
<baseMode>false</baseMode>
<multiSelect>true</multiSelect>
<template>simple-select-list.tpl</template>
<module>simple</module>
<label>Please select the desired entries</label>
<defaultSortColumn>1</defaultSortColumn>
<objectType>
<label>Package</label>
<objectClass>FAKE_OC__FaiPackage</objectClass>
<category>faiPackage</category>
<class>faiPackage</class>
<image>geticon.php?context=applications&amp;icon=fai-packages&amp;size=16</image>
</objectType>
</definition>
<table>
<layout>|20px;c||180|</layout>
<department>
<value>%{filter:departmentType(row,dn)}</value>
</department>
<department>
<value>%{filter:departmentLink(row,dn,description)}</value>
<span>1</span>
</department>
<column>
<value>%{filter:objectType(row,dn)}</value>
</column>
<column>
<label>Name</label>
<sortAttribute>PACKAGE</sortAttribute>
<sortType>string</sortType>
<value>%{PACKAGE}</value>
<export>true</export>
</column>
<column>
<label>Version</label>
<sortAttribute>VERSION</sortAttribute>
<sortType>string</sortType>
<value>%{VERSION}</value>
<export>true</export>
</column>
</table>
<actionmenu>
</actionmenu>
<actiontriggers snapshot="false" copypaste="false">
</actiontriggers>
</list>
  • SonarQube analysis reported 1 issue

    • 1 major

    Watch the comments in this conversation to review them.

Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment