UPD version 0.9.12

This commit is contained in:
Thomas Kuschel 2023-11-12 22:56:20 +01:00
parent 616bf0ca31
commit f656fb70fa
15 changed files with 286 additions and 111 deletions

View File

@ -25,10 +25,12 @@
label="JGLOBAL_SORT_BY"
statuses="*,0,1,2,-2"
class="js-select-submit-on-change"
default="p.name ASC"
default=""
validate="options"
>
<option value="">JGLOBAL_SORT_BY</option>
<option value="p.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
<option value="p.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
<option value="p.state ASC">JSTATUS_ASC</option>
<option value="p.state DESC">JSTATUS_DESC</option>
<option value="p.name ASC">JGLOBAL_NAME_ASC</option>

View File

@ -78,5 +78,13 @@
class="readonly"
readonly="true"
/>
<field
name="ordering"
type="text"
label="JFIELD_ORDERING_LABEL"
class="readonly"
default="0"
readonly="true"
/>
</fieldset>
</form>

View File

@ -17,8 +17,7 @@ use Joomla\DI\Container;
use Joomla\DI\ServiceProviderInterface;
use KW4NZ\Component\Depot\Administrator\Extension\DepotComponent;
return new class implements ServiceProviderInterface
{
return new class implements ServiceProviderInterface {
public function register(Container $container)
{
$container->registerServiceProvider(new ComponentDispatcherFactory('\\KW4NZ\\Component\\Depot'));
@ -26,8 +25,7 @@ return new class implements ServiceProviderInterface
$container->set(
ComponentInterface::class,
function (Container $container)
{
function (Container $container) {
$component = new DepotComponent($container->get(ComponentDispatcherFactoryInterface::class));
$component->setMVCFactory($container->get(MVCFactoryInterface::class));

View File

@ -135,6 +135,9 @@ CREATE TABLE `#__depot_package` (
`created_by` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`checked_out` INT(11) NOT NULL DEFAULT 0,
`checked_out_time` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00',
`modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0,
`ordering` INT(11) NOT NULL DEFAULT 0,
PRIMARY KEY (`id`)
) ENGINE = InnoDB
AUTO_INCREMENT=0

View File

@ -0,0 +1,8 @@
-- @package Depot.SQL MariaDB -- UPDATE to 0.9.11
-- @subpackage com_depot
-- @author Thomas Kuschel <thomas@kuschel.at>
-- @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
-- @license GNU General Public License version 2 or later; see LICENSE.md
-- @since 0.9
ALTER TABLE `#__depot_package`
ADD COLUMN `ordering` INT(11) NOT NULL DEFAULT 0 AFTER `modified_by`;

View File

@ -0,0 +1,9 @@
-- @package Depot.SQL MariaDB -- UPDATE to 0.9.12
-- @subpackage com_depot
-- @author Thomas Kuschel <thomas@kuschel.at>
-- @copyright (C) 2023 KW4NZ, <https://www.kuschel.at>
-- @license GNU General Public License version 2 or later; see LICENSE.md
-- @since 0.9
ALTER TABLE `#__depot_package`
ADD COLUMN `modified` DATETIME NOT NULL DEFAULT '0000-00-00 00:00:00' AFTER `checked_out_time`,
ADD COLUMN `modified_by` INT(10) UNSIGNED NOT NULL DEFAULT 0 AFTER `modified`;

View File

@ -10,11 +10,14 @@
namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\Component\ComponentHelper;
use Joomla\CMS\MVC\Model\ListModel;
// use Joomla\CMS\Table\Table;
use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
class PackagesModel extends ListModel
{
@ -36,6 +39,10 @@ class PackagesModel extends ListModel
'mounting_style',
'description',
'p.description',
'ordering',
'p.ordering',
'checked_out',
'p.checked_out',
];
parent::__construct($config);
}
@ -73,6 +80,12 @@ class PackagesModel extends ListModel
$db->quoteName('p.description'),
$db->quoteName('p.image'),
$db->quoteName('p.state'),
$db->quoteName('p.ordering'),
$db->quoteName('p.checked_out'),
$db->quoteName('p.checked_out_time'),
$db->quoteName('p.modified'),
$db->quoteName('p.modified_by'),
$db->quoteName('p.mounting_style_id'),
]
)
)
@ -104,10 +117,27 @@ class PackagesModel extends ListModel
}
// add list ordering clause
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'asc');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
$query->order(
$db->quoteName($db->escape($this->getState('list.ordering', 'p.ordering'))) . ' ' .
$db->escape($this->getState('list.direction', 'ASC'))
);
return $query;
}
/**
* Returns a reference to the a Table object, always creating it.
*
* @param string $type The table type to instantiate
* @param string $prefix A prefix for the table class name. Optional.
* @param array $config Configuration array for model. Optional.
*
* @return Table A Table object
*
* @since 1.6
*/
public function getTable($type = 'Package', $prefix = 'Administrator', $config = [])
{
return parent::getTable($type, $prefix, $config);
}
}

View File

@ -23,6 +23,8 @@ class PartsModel extends ListModel
$config['filter_fields'] = [
'id',
'd.id',
'state',
'd.state',
'component_name',
'd.component_name',
'alias',
@ -65,6 +67,7 @@ class PartsModel extends ListModel
'list.select',
[
$db->quoteName('d.id'),
$db->quoteName('d.state'),
$db->quoteName('d.component_name'),
$db->quoteName('d.alias'),
$db->quoteName('d.description'),

View File

@ -97,10 +97,10 @@ class StocksModel extends ListModel
$query->where($db->quoteName('s.state') . ' IN (0, 1)');
}
// add list ordering clause
$orderCol = $this->state->get('list.ordering', 'id');
$orderDirn = $this->state->get('list.direction', 'asc');
$query->order($db->escape($orderCol) . ' ' . $db->escape($orderDirn));
// Add the list ordering clause.
$query->order(
$db->quoteName($db->escape($this->getState('list.ordering', 'id'))) . ' ' . $db->escape($this->getState('list.direction', 'ASC'))
);
return $query;
}

View File

@ -26,6 +26,41 @@ class PackageTable extends Table
$this->setColumnAlias('published', 'state');
}
public function check()
{
try {
parent::check();
} catch (\Exception $e) {
$this->setError($e->getMessage());
return false;
}
// Set created date if not set.
if (!(int) $this->created) {
$this->created = Factory::getDate()->toSql();
}
// Set ordering
if ($this->state < 0) {
// Set ordering to 0 if state is archived or trashed
$this->ordering = 0;
} elseif (empty($this->ordering)) {
// Set ordering to last if ordering was 0
$this->ordering = self::getNextOrder($this->_db->quoteName('state') . ' >= 0');
}
// Set modified to created if not set
if ($this->modified) {
$this->modified = $this->created;
}
// Set modified_by to created_by if not set
if (empty($this->modified_by)) {
$this->modified_by = $this->created_by;
}
return true;
}
public function store($updateNulls = true)
{
$app = Factory::getApplication();
@ -56,18 +91,20 @@ class PackageTable extends Table
}
}
// Verify that the alias is unique
$table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Package', 'Administrator');
if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) {
$this->setError('Alias is not unique.');
if ($table->state == -2) {
$this->setError('Alias is not unique. The item is in Trash.');
}
return false;
}
/***
if (!empty($this->alias)) {
// Verify that the alias is unique
$table = $app->bootComponent('com_depot')->getMVCFactory()->createTable('Package', 'Administrator');
if ($table->load(['alias' => $this->alias]) && ($table->id != $this->id || $this->id == 0)) {
$this->setError('Alias is not unique.');
if ($table->state == -2) {
$this->setError('Alias is not unique. The item is in Trash.');
}
return false;
}
}
*/
return parent::store($updateNulls);
}
}

View File

@ -10,35 +10,32 @@
namespace KW4NZ\Component\Depot\Administrator\View\Packages;
defined('_JEXEC') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Language\Text;
use Joomla\CMS\MVC\View\HtmlView as BaseHtmlView;
// use Joomla\CMS\Toolbar;
use Joomla\CMS\Toolbar\ToolbarHelper;
// use Joomla\CMS\Language\Text;
// phpcs:disable PSR1.Files.SideEffects
\defined('_JEXEC') or die;
// phpcs:enable PSR1.Files.SideEffects
class HtmlView extends BaseHtmlView
{
public function display($tpl = null)
{
// Get application
$app = Factory::getApplication();
/** @var PackagesModel $model */
$model = $this->getModel();
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->state = $model->getState();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
$this->items = $this->get('Items');
$this->state = $this->get('State');
// list order
$this->listOrder = $this->escape($this->state->get('list.ordering'));
$this->listDirn = $this->escape($this->state->get('list.direction'));
// add pagination
$this->pagination = $this->get('Pagination');
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
if (!\count($this->items) && $this->isEmptyState = $this->get('IsEmptyState')) {
$this->setLayout('emptystate');
}
// set the toolbar
$this->addToolbar();

View File

@ -25,19 +25,13 @@ class HtmlView extends BaseHtmlView
{
public function display($tpl = null)
{
// Get application
$app = Factory::getApplication();
$this->items = $this->get('Items');
$this->state = $this->get('State');
// list order
$this->listOrder = $this->escape($this->state->get('list.ordering'));
$this->listDirn = $this->escape($this->state->get('list.direction'));
// add pagination
$this->pagination = $this->get('Pagination');
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// Get model
$model = $this->getModel();
$this->items = $model->getItems();
$this->pagination = $model->getPagination();
$this->state = $model->getState();
$this->filterForm = $model->getFilterForm();
$this->activeFilters = $model->getActiveFilters();
// set the toolbar
$this->addToolbar();
@ -45,7 +39,7 @@ class HtmlView extends BaseHtmlView
parent::display($tpl);
}
protected function addToolbar()
protected function addToolbar(): void
{
ToolbarHelper::title(Text::_('COM_DEPOT_MANAGER_PARTS'));
ToolbarHelper::addNew('part.add');

View File

@ -12,7 +12,23 @@ use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Session\Session;
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('table.columns')
->useScript('multiselect');
$user = $this->getCurrentUser();
$userID = $user->get('id');
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'p.ordering';
if ($saveOrder && !empty($this->items)) {
$saveOrderingUrl = 'index.php?option=com_depot&task=packages.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable');
}
?>
<form action="<?= Route::_('index.php?option=com_depot&view=packages'); ?>" method="post" name="adminForm"
id="adminForm">
@ -26,29 +42,34 @@ use Joomla\CMS\Layout\LayoutHelper;
<?= Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else: ?>
<table class="table table-striped table-hover">
<table class="table table-striped table-hover" id="packageList">
<caption class="visually-hidden">
<?php echo Text::_('COM_DEPOT_PACKAGES_TABLE_CAPTION'); ?>,
<span id="orderedBy">
<?php echo Text::_('JGLOBAL_SORTED_BY'); ?>
</span>,
<span id="filteredBy">
<?php echo Text::_('JGLOBAL_FILTERED_BY'); ?>
</span>
</caption>
<thead>
<tr>
<th>
<td class="w-1 text-center">
<?= HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', '', 'p.ordering', $listDirn, $listOrder, null, 'asc', 'JGRID_HEADING_ORDERING', 'icon-sort'); ?>
</th>
<th>
<?= HTMLHelper::_(
'searchtools.sort',
'JGRID_HEADING_ID',
'p.id',
$this->listDirn,
$this->listOrder
); ?>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'p.state', $listDirn, $listOrder); ?>
</th>
<th>
<?= HTMLHelper::_(
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_PACKAGE_NAME',
'p.name',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th>
@ -56,8 +77,8 @@ use Joomla\CMS\Layout\LayoutHelper;
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_DESCRIPTION',
'p.description',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th>
@ -65,33 +86,72 @@ use Joomla\CMS\Layout\LayoutHelper;
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_MOUNTING_STYLE',
'p.mounting_style',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th>
<?= HTMLHelper::_(
'searchtools.sort',
'JGRID_HEADING_ID',
'p.id',
$listDirn,
$listOrder
); ?>
</th>
</tr>
</thead>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr>
<td>
<tbody <?php if ($saveOrder):
?> class="js-draggable" data-url="<?= $saveOrderingUrl; ?>"
data-direction="<?= strtolower($listDirn); ?>" data-nested="true" <?php
endif; ?>>
<?php foreach ($this->items as $i => $item):
$ordering = ($listOrder == 'ordering');
$canChange = true;
?>
<tr class="row<?= $i % 2; ?>" data-draggable-group="0" item-id="<?php echo $item->id; ?>">
<th>
<?= HTMLHelper::_('grid.id', $i, $item->id); ?>
</th>
<td class="text-center d-none d-md-table-cell">
<?php
$iconClass = '';
if (!$canChange) {
$iconClass = ' inactive';
} elseif (!$saveOrder) {
$iconClass = ' inactive" title="' . Text::_('JORDERINGDISABLED');
}
?>
<span class="sortable-handler <?php echo $iconClass ?>">
<span class="icon-ellipsis-v" aria-hidden="true"></span>
</span>
<?php if ($saveOrder): ?>
<input type="text" name="order[]" size="5" value="<?php echo $item->ordering; ?>"
class="width-20 text-area-order hidden">
<?php endif; ?>
<div class="small">
<?= $item->ordering; ?>
</div>
</td>
<td>
<?= $item->id ?>
<td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->state, $i, 'packages.', $canChange); ?>
</td>
<td>
<th>
<a href="<?= Route::_('index.php?option=com_depot&task=package.edit&id=' .
(int) $item->id) ?>" title="<?= Text::_('JACTION_EDIT') ?>">
<?= $this->escape($item->name); ?>
</a>
</td>
</th>
<td>
<?= $this->escape($item->description); ?>
</td>
<td>
<?= $this->escape($item->mounting_style); ?>
</td>
<td>
<?= $item->id ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>

View File

@ -10,11 +10,24 @@
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
/** @var \Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = $this->document->getWebAssetManager();
$wa->useScript('table.columns')
->useScript('multiselect');
$canChange = true;
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn = $this->escape($this->state->get('list.direction'));
$saveOrder = $listOrder == 'd.ordering';
if ($saveOrder && !empty($this->items)) {
$saveOrderingUrl = 'index.php?option=com_depot&task=parts.saveOrderAjax&tmpl=component';
HTMLHelper::_('draggablelist.draggable');
}
?>
<form action="<?= Route::_('index.php?option=com_depot&view=parts'); ?>" method="post" name="adminForm" id="adminForm">
<?= LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>
@ -26,28 +39,31 @@ use Joomla\CMS\Layout\LayoutHelper;
<?= Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div>
<?php else: ?>
<table class="table table-striped table-hover">
<table class="table table-striped table-hover" id="partsList">
<caption class="visually-hidden">
<?php echo Text::_('COM_BANNERS_CLIENTS_TABLE_CAPTION'); ?>,
<span id="orderedBy">
<?php echo Text::_('JGLOBAL_SORTED_BY'); ?>
</span>,
<span id="filteredBy">
<?php echo Text::_('JGLOBAL_FILTERED_BY'); ?>
</span>
</caption>
<thead>
<tr>
<th>
<td class="w-1 text-center">
<?= HTMLHelper::_('grid.checkall'); ?>
</td>
<th scope="col" class="w-1 text-center">
<?php echo HTMLHelper::_('searchtools.sort', 'JSTATUS', 'd.state', $listDirn, $listOrder); ?>
</th>
<th>
<?= HTMLHelper::_(
'searchtools.sort',
'JGRID_HEADING_ID',
'd.id',
$this->listDirn,
$this->listOrder
); ?>
</th>
<th>
<th scope="col">
<?= HTMLHelper::_(
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_NAME',
'd.component_name',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th>
@ -55,8 +71,8 @@ use Joomla\CMS\Layout\LayoutHelper;
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_QUANTITY',
'd.quantity',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th>
@ -67,8 +83,8 @@ use Joomla\CMS\Layout\LayoutHelper;
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_MANUFACTURER',
'manufacturer',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th>
@ -76,8 +92,17 @@ use Joomla\CMS\Layout\LayoutHelper;
'searchtools.sort',
'COM_DEPOT_TABLE_HEAD_STOCK',
'stock_name',
$this->listDirn,
$this->listOrder
$listDirn,
$listOrder
); ?>
</th>
<th scope="col" class="w-1 text-center">
<?= HTMLHelper::_(
'searchtools.sort',
'JGRID_HEADING_ID',
'd.id',
$listDirn,
$listOrder
); ?>
</th>
</tr>
@ -85,13 +110,13 @@ use Joomla\CMS\Layout\LayoutHelper;
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr>
<td>
<?= HTMLHelper::_('grid.id', $i, $item->id); ?>
<td class="text-center">
<?= HTMLHelper::_('grid.id', $i, $item->id, false, 'cid', 'cb', $item->component_name); ?>
</td>
<td>
<?= $item->id ?>
<td class="text-center">
<?php echo HTMLHelper::_('jgrid.published', $item->state, $i, 'parts.', $canChange); ?>
</td>
<td>
<th>
<div class="break-word">
<a href="<?= Route::_('index.php?option=com_depot&task=part.edit&id=' .
(int) $item->id) ?>" title="<?= Text::_('JACTION_EDIT') ?>">
@ -110,7 +135,7 @@ use Joomla\CMS\Layout\LayoutHelper;
</div>
<?php endif; ?>
</div>
</td>
</th>
<td>
<?= $this->escape($item->quantity); ?>
</td>
@ -124,7 +149,6 @@ use Joomla\CMS\Layout\LayoutHelper;
</a>
</td>
<td>
<a class="break-word" href="<?= Route::_('index.php?option=com_depot&task=stock.edit&id=' .
(int) $item->id) ?>" title="<?= Text::_('JACTION_EDIT') ?>">
<?= $this->escape($item->stock_name); ?>
@ -132,7 +156,9 @@ use Joomla\CMS\Layout\LayoutHelper;
<div class="small">
<?= $this->escape($item->owner); ?>
</div>
</td>
<td>
<?= $item->id ?>
</td>
</tr>
<?php endforeach; ?>

View File

@ -2,12 +2,12 @@
<extension type="component" method="upgrade">
<name>Depot</name>
<author>KW4NZ</author>
<creationDate>2023-11-01</creationDate>
<creationDate>2023-11-02</creationDate>
<copyright>(C) KW4NZ Thomas Kuschel</copyright>
<license>GPL v2 +; see LICENSE.md</license>
<authorEmail>thomas@kuschel.at</authorEmail>
<authorUrl>https://kuschel.at</authorUrl>
<version>0.9.10</version>
<version>0.9.12</version>
<description>COM_DEPOT_XML_DESCRIPTION</description>
<namespace path="src/">KW4NZ\Component\Depot</namespace>
<install> <!-- Runs on install -->