commit
26ec0b6edb
|
@ -51,7 +51,9 @@ class CRUDComponent extends Component
|
|||
$options['filters'][] = 'filteringTags';
|
||||
}
|
||||
$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) {
|
||||
$optionFilters[] = "{$filter} !=";
|
||||
$optionFilters[] = "{$filter} >=";
|
||||
|
@ -90,14 +92,17 @@ class CRUDComponent extends Component
|
|||
if ($this->_validOrderFields($sort) && ($direction === 'asc' || $direction === 'desc')) {
|
||||
$sort = explode('.', $sort);
|
||||
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);
|
||||
$query->order($sort . ' ' . $direction);
|
||||
}
|
||||
}
|
||||
$isRestOrCSV = $this->Controller->ParamHandler->isRest() || $this->request->is('csv');
|
||||
if ($this->metaFieldsSupported()) {
|
||||
$query = $this->includeRequestedMetaFields($query);
|
||||
$query = $this->includeRequestedMetaFields($query, $isRestOrCSV);
|
||||
}
|
||||
|
||||
if (!$this->Controller->ParamHandler->isRest()) {
|
||||
|
@ -107,7 +112,7 @@ class CRUDComponent extends Component
|
|||
}
|
||||
$data = $this->Controller->paginate($query, $this->Controller->paginate ?? []);
|
||||
$totalCount = $this->Controller->getRequest()->getAttribute('paging')[$this->TableAlias]['count'];
|
||||
if ($this->Controller->ParamHandler->isRest() || $this->request->is('csv')) {
|
||||
if ($isRestOrCSV) {
|
||||
if (isset($options['hidden'])) {
|
||||
$data->each(function($value, $key) use ($options) {
|
||||
$hidden = is_array($options['hidden']) ? $options['hidden'] : [$options['hidden']];
|
||||
|
@ -256,6 +261,13 @@ class CRUDComponent extends Component
|
|||
foreach ($filtersConfigRaw as $fieldConfig) {
|
||||
if (is_array($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 {
|
||||
$filtersConfig[$fieldConfig] = ['name' => $fieldConfig];
|
||||
}
|
||||
|
@ -777,8 +789,11 @@ class CRUDComponent extends Component
|
|||
return $data;
|
||||
}
|
||||
|
||||
protected function includeRequestedMetaFields($query)
|
||||
protected function includeRequestedMetaFields($query, $isREST=false)
|
||||
{
|
||||
if (!empty($isREST)) {
|
||||
return $query->contain(['MetaFields']);
|
||||
}
|
||||
$user = $this->Controller->ACL->getUser();
|
||||
$tableSettings = IndexSetting::getTableSetting($user, $this->Table);
|
||||
if (empty($tableSettings['visible_meta_column'])) {
|
||||
|
@ -1362,7 +1377,12 @@ class CRUDComponent extends Component
|
|||
protected function setRelatedCondition($query, $modelName, $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
|
||||
{
|
||||
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 $containFields = ['Users'];
|
||||
|
||||
public $paginate = [
|
||||
'order' => [
|
||||
'Inbox.created' => 'desc'
|
||||
]
|
||||
],
|
||||
];
|
||||
|
||||
public function beforeFilter(EventInterface $event)
|
||||
|
|
|
@ -73,7 +73,10 @@ class NotifyAdminsBehavior extends Behavior
|
|||
public function isNotificationAllowed(EventInterface $event, EntityInterface $entity, ArrayObject $options): bool
|
||||
{
|
||||
$loggedUser = Configure::read('loggedUser');
|
||||
if (empty($loggedUser) || !empty($loggedUser['role']['perm_admin']) || !empty($loggedUser['role']['perm_sync'])) {
|
||||
if (
|
||||
empty(Configure::read('inbox.data_change_notify_for_all', false)) &&
|
||||
(empty($loggedUser) || !empty($loggedUser['role']['perm_admin']) || !empty($loggedUser['role']['perm_sync']))
|
||||
) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
|
@ -322,7 +325,7 @@ class NotifyAdminsBehavior extends Behavior
|
|||
} else if (is_object($fieldValue)) {
|
||||
switch (get_class($fieldValue)) {
|
||||
case 'Cake\I18n\FrozenTime':
|
||||
return $fieldValue->i18nFormat('yyyy-mm-dd HH:mm:ss');
|
||||
return $fieldValue->i18nFormat('yyyy-MM-dd HH:mm:ss');
|
||||
}
|
||||
} else {
|
||||
return strval($fieldValue);
|
||||
|
|
|
@ -78,7 +78,7 @@ class AppModel extends Entity
|
|||
$this->meta_fields[$i]['template_namespace'] = $templates[$templateDirectoryId]['namespace'];
|
||||
}
|
||||
}
|
||||
if (!empty($options['smartFlattenMetafields'])) {
|
||||
if (!empty($this->meta_fields) && !empty($options['smartFlattenMetafields'])) {
|
||||
$smartFlatten = [];
|
||||
foreach ($this->meta_fields as $metafield) {
|
||||
$key = "{$metafield['template_name']}_v{$metafield['template_version']}:{$metafield['field']}";
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
namespace App\Model\Table;
|
||||
|
||||
use App\Model\Table\AppTable;
|
||||
use Cake\Utility\Hash;
|
||||
use Cake\Database\Schema\TableSchemaInterface;
|
||||
use Cake\Database\Type;
|
||||
use Cake\ORM\Table;
|
||||
|
@ -72,6 +73,17 @@ class InboxTable extends AppTable
|
|||
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) {
|
||||
$this->Broods = \Cake\ORM\TableRegistry::getTableLocator()->get('Broods');
|
||||
$this->Individuals = \Cake\ORM\TableRegistry::getTableLocator()->get('Individuals');
|
||||
|
|
|
@ -57,7 +57,7 @@ class IndividualsTable extends AppTable
|
|||
public function validationDefault(Validator $validator): Validator
|
||||
{
|
||||
$validator
|
||||
->notEmptyString('email')
|
||||
->email('email')
|
||||
->requirePresence(['email'], 'create');
|
||||
return $validator;
|
||||
}
|
||||
|
|
|
@ -351,7 +351,20 @@ class CerebrateSettingsProvider extends BaseSettingsProvider
|
|||
],
|
||||
]
|
||||
]
|
||||
]
|
||||
],
|
||||
'Inbox' => [
|
||||
'Data change notification' => [
|
||||
'Data change notification' => [
|
||||
'inbox.data_change_notify_for_all' => [
|
||||
'name' => __('Notify data modification for all Users'),
|
||||
'type' => 'boolean',
|
||||
'description' => __('Turning this option ON will alert administrators whenever data is modified, irrespective of the user\'s role responsible for the modification.'),
|
||||
'default' => false,
|
||||
'severity' => 'warning',
|
||||
],
|
||||
],
|
||||
],
|
||||
],
|
||||
/*
|
||||
'Features' => [
|
||||
'Demo Settings' => [
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
{
|
||||
"version": "1.17",
|
||||
"version": "1.18",
|
||||
"application": "Cerebrate"
|
||||
}
|
||||
|
|
|
@ -44,12 +44,12 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
'fields' => [
|
||||
[
|
||||
'name' => '#',
|
||||
'sort' => 'id',
|
||||
'sort' => 'Inbox.id',
|
||||
'data_path' => 'id',
|
||||
],
|
||||
[
|
||||
'name' => 'created',
|
||||
'sort' => 'created',
|
||||
'sort' => 'Inbox.created',
|
||||
'data_path' => 'created',
|
||||
'element' => 'datetime'
|
||||
],
|
||||
|
@ -87,7 +87,7 @@ echo $this->element('genericElements/IndexTable/index_table', [
|
|||
],
|
||||
[
|
||||
'name' => 'user',
|
||||
'sort' => 'user_id',
|
||||
'sort' => 'Inbox.user_id',
|
||||
'data_path' => 'user',
|
||||
'element' => 'user'
|
||||
],
|
||||
|
|
|
@ -56,13 +56,22 @@ $filteringForm = $this->Bootstrap->table(
|
|||
'label' => '',
|
||||
'class' => 'fieldValue form-control-sm'
|
||||
];
|
||||
if (!empty($filtersConfig[$fieldName]['multiple'])) {
|
||||
$fieldData['type'] = 'dropdown';
|
||||
$fieldData['multiple'] = true;
|
||||
$fieldData['select2'] = [
|
||||
'tags' => true,
|
||||
'tokenSeparators' => [',', ' '],
|
||||
];
|
||||
if (!empty($filtersConfig[$fieldName])) {
|
||||
if (!empty($filtersConfig[$fieldName]['options'])) {
|
||||
$fieldData['options'] = $filtersConfig[$fieldName]['options'];
|
||||
}
|
||||
if (!empty($filtersConfig[$fieldName]['select2'])) {
|
||||
$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([
|
||||
'formGroup' => '<div class="col-sm-10">{{input}}</div>',
|
||||
|
@ -187,6 +196,7 @@ echo $this->Bootstrap->modal([
|
|||
$row = $filteringTable.find('td > span.fieldName').filter(function() {
|
||||
return $(this).data('fieldname') == field
|
||||
}).closest('tr')
|
||||
$row.addClass('table-warning')
|
||||
$row.find('.fieldOperator').val(operator)
|
||||
const $formElement = $row.find('.fieldValue');
|
||||
if ($formElement.attr('type') === 'datetime-local') {
|
||||
|
@ -195,7 +205,10 @@ echo $this->Bootstrap->modal([
|
|||
let newOptions = [];
|
||||
value.forEach(aValue => {
|
||||
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) {
|
||||
newOptions.push(new Option(aValue, aValue, true, true))
|
||||
|
|
Loading…
Reference in New Issue