ADD search and filtering to the component

This commit is contained in:
Thomas Kuschel 2023-10-26 12:58:58 +02:00
parent d5263e7405
commit e69f2af6b0
5 changed files with 97 additions and 5 deletions

View File

@ -0,0 +1,78 @@
<?xml version="1.0" encoding="UTF-8"?>
<form addfieldprefix="Joomla\Component\Depot\Administrator\Field">
<fields name="filter">
<field
name="search"
type="text"
inputmode="search"
label="COM_DEPOT_PARTS_FILTER_SEARCH_LABEL"
description="COM_DEPOT_PARTS_FILTER_SEARCH_DESC"
hint="JSEARCH_FILTER"
/>
<field
name="published"
type="status"
label="JSTATUS"
class="js-select-submit-on-change"
>
<option value="">JOPTION_SELECT_PUBLISHED</option>
</field>
<field
name="manufacturer_id"
type="depotmanufacturer"
label="COM_DEPOT_HEADING_MANUFACTURER"
extension="com_depot"
class="js-select-submit-on-change"
>
<option value="">COM_DEPOT_SELECT_MANUFACTURER</option>
</field>
<field
name="stock_id"
type="depotstock"
label="COM_DEPOT_HEADING_STOCK"
extension="com_depot"
class="js-select-submit-on-change"
>
<option value="">COM_DEPOT_SELECT_STOCK</option>
</field>
</fields>
<!-- ('d.id'),
$db->quoteName('d.component_name'),
$db->quoteName('d.alias'),
$db->quoteName('d.description'),
$db->quoteName('d.quantity'),
$db->quoteName('d.quantity_exp'),
$db->quoteName('d.ordering'),
-->
<fields name="list">
<field
name="fullordering"
type="list"
label="JGLOBAL_SORT_BY"
statuses="*,0,1,2,-2"
class="js-select-submit-on-change"
default="d.component_name ASC"
validate="options"
>
<option value="">JGLOBAL_SORT_BY</option>
<option value="d.ordering ASC">JGRID_HEADING_ORDERING_ASC</option>
<option value="d.ordering DESC">JGRID_HEADING_ORDERING_DESC</option>
<option value="d.state ASC">JSTATUS_ASC</option>
<option value="d.state DESC">JSTATUS_DESC</option>
<option value="d.component_name ASC">JGLOBAL_NAME_ASC</option>
<option value="d.component_name DESC">JGLOBAL_NAME_DESC</option>
<option value="d.quantity ASC">COM_DEPOT_QUANTITY_ASC</option>
<option value="d.quantity DESC">COM_DEPOT_QUANTITY_DESC</option>
<option value="d.id ASC">JGRID_HEADING_ID_ASC</option>
<option value="d.id DESC">JGRID_HEADING_ID_DESC</option>
</field>
<field
name="limit"
type="limitbox"
label="JGLOBAL_LIST_LIMIT"
default="25"
class="js-select-submit-on-change"
/>
</fields>
</form>

View File

@ -11,7 +11,8 @@
namespace KW4NZ\Component\Depot\Administrator\Model; namespace KW4NZ\Component\Depot\Administrator\Model;
use Joomla\CMS\MVC\Model\ListModel; use Joomla\CMS\MVC\Model\ListModel;
use Joomla\CMS\Table\Table; // use Joomla\CMS\Table\Table;
use Joomla\Database\ParameterType;
\defined('_JEXEC') or die; \defined('_JEXEC') or die;
@ -67,6 +68,12 @@ class PartsModel extends ListModel
->join('LEFT', $db->quoteName('#__depot_stock', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('d.stock_id')) ->join('LEFT', $db->quoteName('#__depot_stock', 's'), $db->quoteName('s.id') . ' = ' . $db->quoteName('d.stock_id'))
->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('d.checked_out')); ->join('LEFT', $db->quoteName('#__users', 'u'), $db->quoteName('u.id') . ' = ' . $db->quoteName('d.checked_out'));
// filter: like / search
$search = $this->getState('filter.search');
if (!empty($search)) {
$like = $db->quote('%' . $search . '%');
$query->where($db->quoteName('d.component_name') . ' LIKE ' . $like);
}
// Filter by published state // Filter by published state
$published = (string) $this->getState('filter.published'); $published = (string) $this->getState('filter.published');
if (is_numeric($published)) { if (is_numeric($published)) {
@ -74,7 +81,8 @@ class PartsModel extends ListModel
$query->where($db->quoteName('d.state') . ' = :published') $query->where($db->quoteName('d.state') . ' = :published')
->bind(':published', $published, ParameterType::INTEGER); ->bind(':published', $published, ParameterType::INTEGER);
} elseif ($published === '') { } elseif ($published === '') {
$query->where($db->quoteName('d.state') . ' IN (0, 1)'); //$query->where($db->quoteName('d.state') . ' IN (0, 1)');
$query->whereIn($db->quoteName('d.state'), [0, 1]);
} }
return $query; return $query;

View File

@ -30,6 +30,10 @@ class HtmlView extends BaseHtmlView
$this->items = $this->get('Items'); $this->items = $this->get('Items');
// adding filters
$this->filterForm = $this->get('FilterForm');
$this->activeFilters = $this->get('ActiveFilters');
// set the toolbar // set the toolbar
$this->addToolbar(); $this->addToolbar();

View File

@ -11,11 +11,14 @@
use Joomla\CMS\HTML\HTMLHelper; use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text; use Joomla\CMS\Language\Text;
use Joomla\CMS\Router\Route; use Joomla\CMS\Router\Route;
use Joomla\CMS\Layout\LayoutHelper;
?> ?>
<form action="<?= Route::_('index.php?option=com_depot&view=parts'); ?>" method="post" name="adminForm" id="adminForm"> <form action="<?= Route::_('index.php?option=com_depot&view=parts'); ?>" method="post" name="adminForm" id="adminForm">
<?= LayoutHelper::render('joomla.searchtools.default', ['view' => $this]); ?>
<?php if (empty($this->items)): ?> <?php if (empty($this->items)): ?>
<div class="alert alert-info"> <div class="alert alert-info">
<span class="icon-info-circle" aria-hidden="true"> <span class="icon-info-circle" aria-hidden="true">
@ -23,7 +26,6 @@ use Joomla\CMS\Router\Route;
<?= Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?> <?= Text::_('JGLOBAL_NO_MATCHING_RESULTS'); ?>
</div> </div>
<?php else: ?> <?php else: ?>
<table class="table table-striped table-hover"> <table class="table table-striped table-hover">
<thead> <thead>
<tr> <tr>

View File

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