Compare commits
6 Commits
338386729f
...
eefe6b22cc
Author | SHA1 | Date |
---|---|---|
Sami Mokaddem | eefe6b22cc | |
Sami Mokaddem | cadb56eb07 | |
Sami Mokaddem | d823190624 | |
Sami Mokaddem | 2274fff424 | |
Sami Mokaddem | 42a5bd03c6 | |
Sami Mokaddem | 96e4aceb28 |
|
@ -51,7 +51,9 @@ class CRUDComponent extends Component
|
||||||
$options['filters'][] = 'filteringTags';
|
$options['filters'][] = 'filteringTags';
|
||||||
}
|
}
|
||||||
$optionFilters = [];
|
$optionFilters = [];
|
||||||
$optionFilters += empty($options['filters']) ? [] : $options['filters'];
|
$optionFilters += array_map(function($filter) {
|
||||||
|
return is_array($filter) ? $filter['name'] : $filter;
|
||||||
|
}, empty($options['filters']) ? [] : $options['filters']);
|
||||||
foreach ($optionFilters as $i => $filter) {
|
foreach ($optionFilters as $i => $filter) {
|
||||||
$optionFilters[] = "{$filter} !=";
|
$optionFilters[] = "{$filter} !=";
|
||||||
$optionFilters[] = "{$filter} >=";
|
$optionFilters[] = "{$filter} >=";
|
||||||
|
@ -90,7 +92,9 @@ class CRUDComponent extends Component
|
||||||
if ($this->_validOrderFields($sort) && ($direction === 'asc' || $direction === 'desc')) {
|
if ($this->_validOrderFields($sort) && ($direction === 'asc' || $direction === 'desc')) {
|
||||||
$sort = explode('.', $sort);
|
$sort = explode('.', $sort);
|
||||||
if (count($sort) > 1) {
|
if (count($sort) > 1) {
|
||||||
$sort[0] = Inflector::camelize(Inflector::pluralize($sort[0]));
|
if ($sort[0] != $this->Table->getAlias()) {
|
||||||
|
$sort[0] = Inflector::camelize(Inflector::pluralize($sort[0]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$sort = implode('.', $sort);
|
$sort = implode('.', $sort);
|
||||||
$query->order($sort . ' ' . $direction);
|
$query->order($sort . ' ' . $direction);
|
||||||
|
@ -257,6 +261,13 @@ class CRUDComponent extends Component
|
||||||
foreach ($filtersConfigRaw as $fieldConfig) {
|
foreach ($filtersConfigRaw as $fieldConfig) {
|
||||||
if (is_array($fieldConfig)) {
|
if (is_array($fieldConfig)) {
|
||||||
$filtersConfig[$fieldConfig['name']] = $fieldConfig;
|
$filtersConfig[$fieldConfig['name']] = $fieldConfig;
|
||||||
|
if (!empty($fieldConfig['options'])) {
|
||||||
|
if (is_string($fieldConfig['options'])) {
|
||||||
|
$filtersConfig[$fieldConfig['name']]['options'] = $this->Table->{$fieldConfig['options']}($this->Controller->ACL->getUser());
|
||||||
|
} else {
|
||||||
|
$filtersConfig[$fieldConfig['name']]['options'] = $fieldConfig['options'];
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
$filtersConfig[$fieldConfig] = ['name' => $fieldConfig];
|
$filtersConfig[$fieldConfig] = ['name' => $fieldConfig];
|
||||||
}
|
}
|
||||||
|
@ -1366,7 +1377,12 @@ class CRUDComponent extends Component
|
||||||
protected function setRelatedCondition($query, $modelName, $fieldName, $filterValue)
|
protected function setRelatedCondition($query, $modelName, $fieldName, $filterValue)
|
||||||
{
|
{
|
||||||
return $query->matching($modelName, function (\Cake\ORM\Query $q) use ($fieldName, $filterValue) {
|
return $query->matching($modelName, function (\Cake\ORM\Query $q) use ($fieldName, $filterValue) {
|
||||||
return $this->setValueCondition($q, $fieldName, $filterValue);
|
if (is_array($filterValue)) {
|
||||||
|
$query = $this->setInCondition($q, $fieldName, $filterValue);
|
||||||
|
} else {
|
||||||
|
$query = $this->setValueCondition($q, $fieldName, $filterValue);
|
||||||
|
}
|
||||||
|
return $query;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -16,14 +16,14 @@ use Cake\Http\Exception\ForbiddenException;
|
||||||
|
|
||||||
class InboxController extends AppController
|
class InboxController extends AppController
|
||||||
{
|
{
|
||||||
public $filterFields = ['scope', 'action', 'Inbox.created', 'severity', 'title', 'origin', 'message', 'Users.id', 'Users.username',];
|
public $filterFields = ['scope', 'action', 'Inbox.created', 'severity', 'title', 'origin', 'message', 'Users.id', ['name' => 'Users.username', 'multiple' => true, 'options' => 'getAllUsername', 'select2' => true],];
|
||||||
public $quickFilterFields = ['scope', 'action', ['title' => true], ['message' => true], 'origin'];
|
public $quickFilterFields = ['scope', 'action', ['title' => true], ['message' => true], 'origin'];
|
||||||
public $containFields = ['Users'];
|
public $containFields = ['Users'];
|
||||||
|
|
||||||
public $paginate = [
|
public $paginate = [
|
||||||
'order' => [
|
'order' => [
|
||||||
'Inbox.created' => 'desc'
|
'Inbox.created' => 'desc'
|
||||||
]
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
public function beforeFilter(EventInterface $event)
|
public function beforeFilter(EventInterface $event)
|
||||||
|
|
|
@ -322,7 +322,7 @@ class NotifyAdminsBehavior extends Behavior
|
||||||
} else if (is_object($fieldValue)) {
|
} else if (is_object($fieldValue)) {
|
||||||
switch (get_class($fieldValue)) {
|
switch (get_class($fieldValue)) {
|
||||||
case 'Cake\I18n\FrozenTime':
|
case 'Cake\I18n\FrozenTime':
|
||||||
return $fieldValue->i18nFormat('yyyy-mm-dd HH:mm:ss');
|
return $fieldValue->i18nFormat('yyyy-MM-dd HH:mm:ss');
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
return strval($fieldValue);
|
return strval($fieldValue);
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
namespace App\Model\Table;
|
namespace App\Model\Table;
|
||||||
|
|
||||||
use App\Model\Table\AppTable;
|
use App\Model\Table\AppTable;
|
||||||
|
use Cake\Utility\Hash;
|
||||||
use Cake\Database\Schema\TableSchemaInterface;
|
use Cake\Database\Schema\TableSchemaInterface;
|
||||||
use Cake\Database\Type;
|
use Cake\Database\Type;
|
||||||
use Cake\ORM\Table;
|
use Cake\ORM\Table;
|
||||||
|
@ -72,6 +73,17 @@ class InboxTable extends AppTable
|
||||||
return $rules;
|
return $rules;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getAllUsername($currentUser): array
|
||||||
|
{
|
||||||
|
$this->Users = \Cake\ORM\TableRegistry::getTableLocator()->get('Users');
|
||||||
|
$conditions = [];
|
||||||
|
if (empty($currentUser['role']['perm_admin'])) {
|
||||||
|
$conditions['organisation_id IN'] = [$currentUser['organisation_id']];
|
||||||
|
}
|
||||||
|
$users = $this->Users->find()->where($conditions)->all()->extract('username')->toList();
|
||||||
|
return Hash::combine($users, '{n}', '{n}');
|
||||||
|
}
|
||||||
|
|
||||||
public function checkUserBelongsToBroodOwnerOrg($user, $entryData) {
|
public function checkUserBelongsToBroodOwnerOrg($user, $entryData) {
|
||||||
$this->Broods = \Cake\ORM\TableRegistry::getTableLocator()->get('Broods');
|
$this->Broods = \Cake\ORM\TableRegistry::getTableLocator()->get('Broods');
|
||||||
$this->Individuals = \Cake\ORM\TableRegistry::getTableLocator()->get('Individuals');
|
$this->Individuals = \Cake\ORM\TableRegistry::getTableLocator()->get('Individuals');
|
||||||
|
|
|
@ -57,7 +57,7 @@ class IndividualsTable extends AppTable
|
||||||
public function validationDefault(Validator $validator): Validator
|
public function validationDefault(Validator $validator): Validator
|
||||||
{
|
{
|
||||||
$validator
|
$validator
|
||||||
->notEmptyString('email')
|
->email('email')
|
||||||
->requirePresence(['email'], 'create');
|
->requirePresence(['email'], 'create');
|
||||||
return $validator;
|
return $validator;
|
||||||
}
|
}
|
||||||
|
|
|
@ -44,12 +44,12 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
'fields' => [
|
'fields' => [
|
||||||
[
|
[
|
||||||
'name' => '#',
|
'name' => '#',
|
||||||
'sort' => 'id',
|
'sort' => 'Inbox.id',
|
||||||
'data_path' => 'id',
|
'data_path' => 'id',
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'created',
|
'name' => 'created',
|
||||||
'sort' => 'created',
|
'sort' => 'Inbox.created',
|
||||||
'data_path' => 'created',
|
'data_path' => 'created',
|
||||||
'element' => 'datetime'
|
'element' => 'datetime'
|
||||||
],
|
],
|
||||||
|
@ -87,7 +87,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'name' => 'user',
|
'name' => 'user',
|
||||||
'sort' => 'user_id',
|
'sort' => 'Inbox.user_id',
|
||||||
'data_path' => 'user',
|
'data_path' => 'user',
|
||||||
'element' => 'user'
|
'element' => 'user'
|
||||||
],
|
],
|
||||||
|
|
|
@ -56,13 +56,22 @@ $filteringForm = $this->Bootstrap->table(
|
||||||
'label' => '',
|
'label' => '',
|
||||||
'class' => 'fieldValue form-control-sm'
|
'class' => 'fieldValue form-control-sm'
|
||||||
];
|
];
|
||||||
if (!empty($filtersConfig[$fieldName]['multiple'])) {
|
if (!empty($filtersConfig[$fieldName])) {
|
||||||
$fieldData['type'] = 'dropdown';
|
if (!empty($filtersConfig[$fieldName]['options'])) {
|
||||||
$fieldData['multiple'] = true;
|
$fieldData['options'] = $filtersConfig[$fieldName]['options'];
|
||||||
$fieldData['select2'] = [
|
}
|
||||||
'tags' => true,
|
if (!empty($filtersConfig[$fieldName]['select2'])) {
|
||||||
'tokenSeparators' => [',', ' '],
|
$fieldData['type'] = 'dropdown';
|
||||||
];
|
$fieldData['select2'] = true;
|
||||||
|
}
|
||||||
|
if (!empty($filtersConfig[$fieldName]['multiple'])) {
|
||||||
|
$fieldData['type'] = 'dropdown';
|
||||||
|
$fieldData['multiple'] = true;
|
||||||
|
$fieldData['select2'] = [
|
||||||
|
'tags' => true,
|
||||||
|
'tokenSeparators' => [',', ' '],
|
||||||
|
];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
$this->Form->setTemplates([
|
$this->Form->setTemplates([
|
||||||
'formGroup' => '<div class="col-sm-10">{{input}}</div>',
|
'formGroup' => '<div class="col-sm-10">{{input}}</div>',
|
||||||
|
@ -187,6 +196,7 @@ echo $this->Bootstrap->modal([
|
||||||
$row = $filteringTable.find('td > span.fieldName').filter(function() {
|
$row = $filteringTable.find('td > span.fieldName').filter(function() {
|
||||||
return $(this).data('fieldname') == field
|
return $(this).data('fieldname') == field
|
||||||
}).closest('tr')
|
}).closest('tr')
|
||||||
|
$row.addClass('table-warning')
|
||||||
$row.find('.fieldOperator').val(operator)
|
$row.find('.fieldOperator').val(operator)
|
||||||
const $formElement = $row.find('.fieldValue');
|
const $formElement = $row.find('.fieldValue');
|
||||||
if ($formElement.attr('type') === 'datetime-local') {
|
if ($formElement.attr('type') === 'datetime-local') {
|
||||||
|
@ -195,7 +205,10 @@ echo $this->Bootstrap->modal([
|
||||||
let newOptions = [];
|
let newOptions = [];
|
||||||
value.forEach(aValue => {
|
value.forEach(aValue => {
|
||||||
const existingOption = $formElement.find('option').filter(function() {
|
const existingOption = $formElement.find('option').filter(function() {
|
||||||
return $(this).val() === aValue
|
if ($(this).val() === aValue) {
|
||||||
|
$(this).prop('selected', true)
|
||||||
|
return true
|
||||||
|
}
|
||||||
})
|
})
|
||||||
if (existingOption.length == 0) {
|
if (existingOption.length == 0) {
|
||||||
newOptions.push(new Option(aValue, aValue, true, true))
|
newOptions.push(new Option(aValue, aValue, true, true))
|
||||||
|
|
Loading…
Reference in New Issue