diff --git a/application/Espo/Controllers/EntityManager.php b/application/Espo/Controllers/EntityManager.php index 4faa98ba45..e4b98b7a36 100644 --- a/application/Espo/Controllers/EntityManager.php +++ b/application/Espo/Controllers/EntityManager.php @@ -130,10 +130,6 @@ class EntityManager extends \Espo\Core\Controllers\Base $name = $data['name']; $name = filter_var($name, \FILTER_SANITIZE_STRING); - if (!empty($data['sortDirection'])) { - $data['asc'] = $data['sortDirection'] === 'asc'; - } - $result = $this->getContainer()->get('entityManagerUtil')->update($name, $data); if ($result) { diff --git a/application/Espo/Core/Controllers/Record.php b/application/Espo/Core/Controllers/Record.php index 2edd006b68..24cb9f2f57 100644 --- a/application/Espo/Core/Controllers/Record.php +++ b/application/Espo/Core/Controllers/Record.php @@ -125,34 +125,17 @@ class Record extends Base throw new Forbidden(); } - $where = $request->get('where'); - $offset = $request->get('offset'); - $maxSize = $request->get('maxSize'); - $asc = $request->get('asc', 'true') === 'true'; - $sortBy = $request->get('sortBy'); - $q = $request->get('q'); - $textFilter = $request->get('textFilter'); + $params = []; + $this->fetchListParamsFromRequest($params, $request, $data); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT); - if (empty($maxSize)) { - $maxSize = $maxSizeLimit; + if (empty($params['maxSize'])) { + $params['maxSize'] = $maxSizeLimit; } - if (!empty($maxSize) && $maxSize > $maxSizeLimit) { + if (!empty($params['maxSize']) && $params['maxSize'] > $maxSizeLimit) { throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit."); } - $params = array( - 'where' => $where, - 'offset' => $offset, - 'maxSize' => $maxSize, - 'asc' => $asc, - 'sortBy' => $sortBy, - 'q' => $q, - 'textFilter' => $textFilter - ); - - $this->fetchListParamsFromRequest($params, $request, $data); - $result = $this->getRecordService()->findEntities($params); return array( @@ -167,34 +150,17 @@ class Record extends Base throw new Forbidden(); } - $where = $request->get('where'); - $offset = $request->get('offset'); - $maxSize = $request->get('maxSize'); - $asc = $request->get('asc', 'true') === 'true'; - $sortBy = $request->get('sortBy'); - $q = $request->get('q'); - $textFilter = $request->get('textFilter'); + $params = []; + $this->fetchListParamsFromRequest($params, $request, $data); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT); - if (empty($maxSize)) { - $maxSize = $maxSizeLimit; + if (empty($params['maxSize'])) { + $params['maxSize'] = $maxSizeLimit; } - if (!empty($maxSize) && $maxSize > $maxSizeLimit) { + if (!empty($params['maxSize']) && $params['maxSize'] > $maxSizeLimit) { throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit."); } - $params = array( - 'where' => $where, - 'offset' => $offset, - 'maxSize' => $maxSize, - 'asc' => $asc, - 'sortBy' => $sortBy, - 'q' => $q, - 'textFilter' => $textFilter - ); - - $this->fetchListParamsFromRequest($params, $request, $data); - $result = $this->getRecordService()->getListKanban($params); return (object) [ @@ -214,34 +180,17 @@ class Record extends Base $id = $params['id']; $link = $params['link']; - $where = $request->get('where'); - $offset = $request->get('offset'); - $maxSize = $request->get('maxSize'); - $asc = $request->get('asc', 'true') === 'true'; - $sortBy = $request->get('sortBy'); - $q = $request->get('q'); - $textFilter = $request->get('textFilter'); + $params = []; + $this->fetchListParamsFromRequest($params, $request, $data); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT); - if (empty($maxSize)) { - $maxSize = $maxSizeLimit; + if (empty($params['maxSize'])) { + $params['maxSize'] = $maxSizeLimit; } - if (!empty($maxSize) && $maxSize > $maxSizeLimit) { + if (!empty($params['maxSize']) && $params['maxSize'] > $maxSizeLimit) { throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit."); } - $params = array( - 'where' => $where, - 'offset' => $offset, - 'maxSize' => $maxSize, - 'asc' => $asc, - 'sortBy' => $sortBy, - 'q' => $q, - 'textFilter' => $textFilter - ); - - $this->fetchListParamsFromRequest($params, $request, $data); - $result = $this->getRecordService()->findLinkedEntities($id, $link, $params); return array( diff --git a/application/Espo/Core/SelectManagers/Base.php b/application/Espo/Core/SelectManagers/Base.php index 3b7e32f82b..f033d674ca 100644 --- a/application/Espo/Core/SelectManagers/Base.php +++ b/application/Espo/Core/SelectManagers/Base.php @@ -136,8 +136,11 @@ class Base protected function order($sortBy, $desc = false, &$result) { - if (!empty($sortBy)) { + if (is_string($desc)) { + $desc = $desc === strtolower('desc'); + } + if (!empty($sortBy)) { $result['orderBy'] = $sortBy; $type = $this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'fields', $sortBy, 'type']); if (in_array($type, ['link', 'file', 'image'])) { @@ -423,7 +426,7 @@ class Base protected function prepareResult(&$result) { if (empty($result)) { - $result = array(); + $result = []; } if (empty($result['joins'])) { $result['joins'] = []; @@ -699,14 +702,26 @@ class Base public function getSelectParams(array $params, $withAcl = false, $checkWherePermission = false) { - $result = array(); + $result = []; $this->prepareResult($result); - if (!empty($params['sortBy'])) { - if (!array_key_exists('asc', $params)) { - $params['asc'] = true; + if (!empty($params['orderBy'])) { + $isDesc = false; + if (isset($params['order'])) { + $isDesc = $params['order'] === 'desc'; } - $this->order($params['sortBy'], !$params['asc'], $result); + $this->order($params['orderBy'], $isDesc, $result); + } else if (!empty($params['sortBy'])) { + if (isset($params['order'])) { + $isDesc = $params['order'] === 'desc'; + } else if (isset($params['asc'])) { + $isDesc = $params['asc'] !== true; + } + $this->order($params['sortBy'], $isDesc, $result); + } else if (!empty($params['order'])) { + $orderBy = $this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'collection', 'orderBy']); + $isDesc = $params['order'] === 'desc'; + $this->order($orderBy, $isDesc, $result); } if (!isset($params['offset'])) { diff --git a/application/Espo/Core/Templates/Metadata/Base/entityDefs.json b/application/Espo/Core/Templates/Metadata/Base/entityDefs.json index c6a5a99f3c..329f6b9144 100644 --- a/application/Espo/Core/Templates/Metadata/Base/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/Base/entityDefs.json @@ -57,8 +57,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "name": { diff --git a/application/Espo/Core/Templates/Metadata/BasePlus/entityDefs.json b/application/Espo/Core/Templates/Metadata/BasePlus/entityDefs.json index 6c903bf6b6..0c3fc28031 100644 --- a/application/Espo/Core/Templates/Metadata/BasePlus/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/BasePlus/entityDefs.json @@ -75,8 +75,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "name": { diff --git a/application/Espo/Core/Templates/Metadata/CategoryTree/entityDefs.json b/application/Espo/Core/Templates/Metadata/CategoryTree/entityDefs.json index 9921dd46d6..3f87b31298 100644 --- a/application/Espo/Core/Templates/Metadata/CategoryTree/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/CategoryTree/entityDefs.json @@ -72,8 +72,8 @@ } }, "collection": { - "sortBy": "parent", - "asc": true + "orderBy": "parent", + "order": "asc" }, "indexes": { "name": { diff --git a/application/Espo/Core/Templates/Metadata/Company/entityDefs.json b/application/Espo/Core/Templates/Metadata/Company/entityDefs.json index c6223d0d18..1e96c174f3 100644 --- a/application/Espo/Core/Templates/Metadata/Company/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/Company/entityDefs.json @@ -136,8 +136,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "name": { diff --git a/application/Espo/Core/Templates/Metadata/Event/entityDefs.json b/application/Espo/Core/Templates/Metadata/Event/entityDefs.json index d2e5830212..e499bd3c5e 100644 --- a/application/Espo/Core/Templates/Metadata/Event/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/Event/entityDefs.json @@ -101,8 +101,8 @@ } }, "collection": { - "sortBy": "dateStart", - "asc": false + "orderBy": "dateStart", + "order": "desc" }, "indexes": { "dateStartStatus": { diff --git a/application/Espo/Core/Templates/Metadata/Person/entityDefs.json b/application/Espo/Core/Templates/Metadata/Person/entityDefs.json index 7ccdf8c90e..2db654eacf 100644 --- a/application/Espo/Core/Templates/Metadata/Person/entityDefs.json +++ b/application/Espo/Core/Templates/Metadata/Person/entityDefs.json @@ -126,8 +126,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "firstName": { diff --git a/application/Espo/Core/Utils/ControllerUtil.php b/application/Espo/Core/Utils/ControllerUtil.php index 5e9c527096..bc22c17d42 100644 --- a/application/Espo/Core/Utils/ControllerUtil.php +++ b/application/Espo/Core/Utils/ControllerUtil.php @@ -33,6 +33,28 @@ class ControllerUtil { public static function fetchListParamsFromRequest(&$params, $request, $data) { + $params['where'] = $request->get('where'); + $params['maxSize'] = $request->get('maxSize'); + $params['offset'] = $request->get('offset'); + + if ($request->get('orderBy')) { + $params['orderBy'] = $request->get('orderBy'); + } else if ($request->get('sortBy')) { + $params['orderBy'] = $request->get('sortBy'); + } + + if ($request->get('order')) { + $params['order'] = $request->get('order'); + } else if ($request->get('asc')) { + $params['order'] = $request->get('asc') === 'true' ? 'asc' : 'desc'; + } + + if ($request->get('q')) { + $params['q'] = $request->get('q'); + } + if ($request->get('textFilter')) { + $params['textFilter'] = $request->get('textFilter'); + } if ($request->get('primaryFilter')) { $params['primaryFilter'] = $request->get('primaryFilter'); } diff --git a/application/Espo/Core/Utils/Database/Orm/Converter.php b/application/Espo/Core/Utils/Database/Orm/Converter.php index 2cfdbaf650..64e0f77ba6 100644 --- a/application/Espo/Core/Utils/Database/Orm/Converter.php +++ b/application/Espo/Core/Utils/Database/Orm/Converter.php @@ -213,16 +213,16 @@ class Converter $collectionDefs = $entityMetadata['collection']; $ormMetadata[$entityName]['collection'] = array(); - if (array_key_exists('sortByByColumn', $collectionDefs)) { - $ormMetadata[$entityName]['collection']['orderBy'] = $collectionDefs['sortByByColumn']; - } else if (array_key_exists('sortBy', $collectionDefs)) { - if (array_key_exists($collectionDefs['sortBy'], $ormMetadata[$entityName]['fields'])) { - $ormMetadata[$entityName]['collection']['orderBy'] = $collectionDefs['sortBy']; + if (array_key_exists('orderByColumn', $collectionDefs)) { + $ormMetadata[$entityName]['collection']['orderBy'] = $collectionDefs['orderByColumn']; + } else if (array_key_exists('orderBy', $collectionDefs)) { + if (array_key_exists($collectionDefs['orderBy'], $ormMetadata[$entityName]['fields'])) { + $ormMetadata[$entityName]['collection']['orderBy'] = $collectionDefs['orderBy']; } } $ormMetadata[$entityName]['collection']['order'] = 'ASC'; - if (array_key_exists('asc', $collectionDefs)) { - $ormMetadata[$entityName]['collection']['order'] = $collectionDefs['asc'] ? 'ASC' : 'DESC'; + if (array_key_exists('order', $collectionDefs)) { + $ormMetadata[$entityName]['collection']['order'] = strtoupper($collectionDefs['order']); } } diff --git a/application/Espo/Core/Utils/EntityManager.php b/application/Espo/Core/Utils/EntityManager.php index 2130720622..4b7fb1ac95 100644 --- a/application/Espo/Core/Utils/EntityManager.php +++ b/application/Espo/Core/Utils/EntityManager.php @@ -413,12 +413,15 @@ class EntityManager } if (isset($data['sortBy'])) { - $entityDefsData = array( - 'collection' => array( - 'sortBy' => $data['sortBy'], - 'asc' => !empty($data['asc']) - ) - ); + $entityDefsData = [ + 'collection' => [ + 'orderBy' => $data['sortBy'] + ] + ]; + if (isset($data['sortDirection'])) { + $entityDefsData['collection']['order'] = $data['sortDirection']; + } + $this->getMetadata()->set('entityDefs', $name, $entityDefsData); } @@ -1060,6 +1063,8 @@ class EntityManager $this->getMetadata()->delete('entityDefs', $scope, [ 'collection.sortBy', 'collection.asc', + 'collection.orderBy', + 'collection.order', 'collection.textFilterFields' ]); $this->getMetadata()->save(); diff --git a/application/Espo/Core/Utils/Metadata.php b/application/Espo/Core/Utils/Metadata.php index 95772e8fd4..10b14e3632 100644 --- a/application/Espo/Core/Utils/Metadata.php +++ b/application/Espo/Core/Utils/Metadata.php @@ -309,6 +309,24 @@ class Metadata $fieldDefinitionList = Util::objectToArray($data->fields); foreach (get_object_vars($data->entityDefs) as $entityType => $entityDefsItem) { + + if (isset($data->entityDefs->$entityType->collection)) { + + $collectionItem = $data->entityDefs->$entityType->collection; + + if (isset($collectionItem->orderBy)) { + $collectionItem->sortBy = $collectionItem->orderBy; + } else if (isset($collectionItem->sortBy)) { + $collectionItem->orderBy = $collectionItem->sortBy; + } + + if (isset($collectionItem->order)) { + $collectionItem->asc = $collectionItem->order === 'asc' ? true : false; + } else if (isset($collectionItem->asc)) { + $collectionItem->order = $collectionItem->asc === true ? 'asc' : 'desc'; + } + } + if (!isset($entityDefsItem->fields)) continue; foreach (get_object_vars($entityDefsItem->fields) as $field => $fieldDefsItem) { $additionalFields = $this->getMetadataHelper()->getAdditionalFieldList($field, Util::objectToArray($fieldDefsItem), $fieldDefinitionList); diff --git a/application/Espo/Modules/Crm/Controllers/Activities.php b/application/Espo/Modules/Crm/Controllers/Activities.php index cea7c8f8ed..8a9e46cad5 100644 --- a/application/Espo/Modules/Crm/Controllers/Activities.php +++ b/application/Espo/Modules/Crm/Controllers/Activities.php @@ -172,8 +172,8 @@ class Activities extends \Espo\Core\Controllers\Base $offset = intval($request->get('offset')); $maxSize = intval($request->get('maxSize')); - $asc = $request->get('asc') === 'true'; - $sortBy = $request->get('sortBy'); + $order = $request->get('order'); + $orderBy = $request->get('orderBy'); $where = $request->get('where'); $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', self::MAX_SIZE_LIMIT); @@ -193,13 +193,13 @@ class Activities extends \Espo\Core\Controllers\Base $methodName = 'get' . ucfirst($name); - return $service->$methodName($entityType, $id, array( + return $service->$methodName($entityType, $id, [ 'scope' => $scope, 'offset' => $offset, 'maxSize' => $maxSize, - 'asc' => $asc, - 'sortBy' => $sortBy, - )); + 'order' => $order, + 'orderBy' => $orderBy, + ]); } public function getActionEntityTypeList($params, $data, $request) @@ -222,33 +222,18 @@ class Activities extends \Espo\Core\Controllers\Base throw new BadRequest(); } - $where = $request->get('where'); - $offset = $request->get('offset'); - $maxSize = $request->get('maxSize'); - $asc = $request->get('asc', 'true') === 'true'; - $sortBy = $request->get('sortBy'); - $q = $request->get('q'); - $textFilter = $request->get('textFilter'); - - $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', 200); - if (empty($maxSize)) { - $maxSize = $maxSizeLimit; - } - if (!empty($maxSize) && $maxSize > $maxSizeLimit) { - throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit."); - } - - $params = [ - 'where' => $where, - 'offset' => $offset, - 'maxSize' => $maxSize, - 'asc' => $asc, - 'sortBy' => $sortBy, - 'textFilter' => $textFilter - ]; + $params = []; \Espo\Core\Utils\ControllerUtil::fetchListParamsFromRequest($params, $request, $data); + $maxSizeLimit = $this->getConfig()->get('recordListMaxSizeLimit', 200); + if (empty($params['maxSize'])) { + $params['maxSize'] = $maxSizeLimit; + } + if (!empty($params['maxSize']) && $params['maxSize'] > $maxSizeLimit) { + throw new Forbidden("Max size should should not exceed " . $maxSizeLimit . ". Use offset and limit."); + } + $service = $this->getService('Activities'); $result = $service->findActivitiyEntityType($scope, $id, $entityType, $isHistory, $params); diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Calls.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Calls.json index 55834d0cab..51de615d55 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Calls.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Calls.json @@ -22,8 +22,8 @@ } }, "defaults": { - "sortBy": "dateStart", - "asc": true, + "orderBy": "dateStart", + "order": "desc", "displayRecords": 5, "populateAssignedUser": true, "expandedLayout": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Cases.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Cases.json index a9b7c33ee8..7b70ec528d 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Cases.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Cases.json @@ -22,8 +22,8 @@ } }, "defaults": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "number", + "order": "desc", "displayRecords": 5, "populateAssignedUser": true, "expandedLayout": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Leads.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Leads.json index 7bb5732220..c07fa151ae 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Leads.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Leads.json @@ -22,8 +22,8 @@ } }, "defaults": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "createdAt", + "order": "desc", "displayRecords": 5, "populateAssignedUser": true, "expandedLayout": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Meetings.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Meetings.json index df14f110ba..f326de8b26 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Meetings.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Meetings.json @@ -22,8 +22,8 @@ } }, "defaults": { - "sortBy": "dateStart", - "asc": true, + "orderBy": "dateStart", + "order": "desc", "displayRecords": 5, "populateAssignedUser": true, "expandedLayout": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Opportunities.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Opportunities.json index ec6d07d4bb..99eabb576f 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Opportunities.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Opportunities.json @@ -22,8 +22,8 @@ } }, "defaults": { - "sortBy": "closeDate", - "asc": true, + "orderBy": "closeDate", + "order": "asc", "displayRecords": 5, "populateAssignedUser": true, "expandedLayout": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Tasks.json b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Tasks.json index 89e9d6b67d..bcdbf7e5b2 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/dashlets/Tasks.json +++ b/application/Espo/Modules/Crm/Resources/metadata/dashlets/Tasks.json @@ -22,8 +22,8 @@ } }, "defaults": { - "sortBy": "dateEnd", - "asc": true, + "orderBy": "dateEnd", + "order": "asc", "displayRecords": 5, "expandedLayout": { "rows": [ diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json index a5a1e44f9d..66051b352f 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Account.json @@ -334,8 +334,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "createdAt", + "order": "desc", "textFilterFields": ["name", "emailAddress"] }, "indexes": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Call.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Call.json index be44977417..8f8f473078 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Call.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Call.json @@ -214,8 +214,8 @@ } }, "collection": { - "sortBy": "dateStart", - "asc": false + "orderBy": "dateStart", + "order": "desc" }, "indexes": { "dateStartStatus": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json index 7bf5100a67..371d4b907d 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Campaign.json @@ -262,8 +262,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "createdAt": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignLogRecord.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignLogRecord.json index 06be97d32c..3b2888ef2c 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignLogRecord.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignLogRecord.json @@ -78,8 +78,8 @@ } }, "collection": { - "sortBy": "actionDate", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "actionDate": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignTrackingUrl.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignTrackingUrl.json index 3b3fe8189a..2634569cf8 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignTrackingUrl.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/CampaignTrackingUrl.json @@ -51,7 +51,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Case.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Case.json index d722ba0fe3..90f992aeec 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Case.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Case.json @@ -164,8 +164,8 @@ } }, "collection": { - "sortBy": "number", - "asc": false, + "orderBy": "number", + "order": "desc", "textFilterFields": ["name", "number"] }, "indexes": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json index e4d1946e37..a3df4b5de8 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Contact.json @@ -421,8 +421,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "createdAt", + "order": "desc", "textFilterFields": ["name", "emailAddress"] }, "indexes": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Document.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Document.json index ae706432c3..13fc9a67da 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Document.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Document.json @@ -121,7 +121,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/DocumentFolder.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/DocumentFolder.json index b158ef1379..6ffd65a136 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/DocumentFolder.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/DocumentFolder.json @@ -68,8 +68,8 @@ } }, "collection": { - "sortBy": "parent", - "asc": true + "orderBy": "parent", + "order": "asc" }, "additionalTables": { "DocumentFolderPath": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/EmailQueueItem.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/EmailQueueItem.json index eb16f67cc8..d0695f2629 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/EmailQueueItem.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/EmailQueueItem.json @@ -45,7 +45,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } \ No newline at end of file diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json index d39e5ae514..9831a2491c 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseArticle.json @@ -111,7 +111,7 @@ } }, "collection": { - "sortBy": "order", - "asc": true + "orderBy": "order", + "order": "asc" } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseCategory.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseCategory.json index 3cf73c84f6..4a51f72f00 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseCategory.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/KnowledgeBaseCategory.json @@ -74,9 +74,9 @@ } }, "collection": { - "sortBy": "parent", - "sortByByColumn": "parentId", - "asc": true + "orderBy": "parent", + "orderByColumn": "parentId", + "order": "asc" }, "additionalTables": { "KnowledgeBaseCategoryPath": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json index 76b392efb8..6e5c0eeb91 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Lead.json @@ -318,8 +318,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "createdAt", + "order": "desc", "textFilterFields": ["name", "accountName", "emailAddress"] }, "indexes": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/MassEmail.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/MassEmail.json index b6c6f95900..0be4a63e8f 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/MassEmail.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/MassEmail.json @@ -121,7 +121,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Meeting.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Meeting.json index 7ae2aa74a9..38f6b07c62 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Meeting.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Meeting.json @@ -204,8 +204,8 @@ } }, "collection": { - "sortBy": "dateStart", - "asc": false + "orderBy": "dateStart", + "order": "desc" }, "indexes": { "dateStartStatus": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json index a2f35ea5ed..052328a6f3 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Opportunity.json @@ -248,8 +248,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "stage": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Reminder.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Reminder.json index b9ec90e44c..ca162afe59 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Reminder.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Reminder.json @@ -34,7 +34,7 @@ } }, "collection": { - "sortBy": "remindAt", - "asc": false + "orderBy": "remindAt", + "order": "desc" } } diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Target.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Target.json index 29376388e5..26c023290b 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Target.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Target.json @@ -111,8 +111,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "firstName": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/TargetList.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/TargetList.json index 63ebf29a69..6ac10ccb3d 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/TargetList.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/TargetList.json @@ -175,8 +175,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "createdAt": { diff --git a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Task.json b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Task.json index 5a39f70b5f..f57bf45d65 100644 --- a/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Task.json +++ b/application/Espo/Modules/Crm/Resources/metadata/entityDefs/Task.json @@ -136,8 +136,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" }, "indexes": { "dateStartStatus": { diff --git a/application/Espo/Modules/Crm/Services/Activities.php b/application/Espo/Modules/Crm/Services/Activities.php index 31bd55ca4e..5272f35959 100644 --- a/application/Espo/Modules/Crm/Services/Activities.php +++ b/application/Espo/Modules/Crm/Services/Activities.php @@ -726,8 +726,12 @@ class Activities extends \Espo\Core\Services\Base $offset = $selectParams['offset']; $limit = $selectParams['limit']; - $order = $selectParams['order']; - $orderBy = $selectParams['orderBy']; + $orderBy = null; + $order = null; + if (!empty($selectParams['orderBy'])) { + $order = $selectParams['order']; + $orderBy = $selectParams['orderBy']; + } unset($selectParams['offset']); unset($selectParams['limit']); @@ -737,6 +741,7 @@ class Activities extends \Espo\Core\Services\Base if ($entityType === 'Email') { if ($orderBy === 'dateStart') { $orderBy = 'dateSent'; + $order = 'desc'; } } @@ -748,7 +753,9 @@ class Activities extends \Espo\Core\Services\Base $sqlBase = $sql; - $sql = $query->order($sql, $seed, $orderBy, $order, true); + if ($orderBy) { + $sql = $query->order($sql, $seed, $orderBy, $order, true); + } $sql = $query->limit($sql, $offset, $limit); diff --git a/application/Espo/Resources/metadata/dashlets/Emails.json b/application/Espo/Resources/metadata/dashlets/Emails.json index 8ff7b1c613..f9f53cfa28 100644 --- a/application/Espo/Resources/metadata/dashlets/Emails.json +++ b/application/Espo/Resources/metadata/dashlets/Emails.json @@ -18,8 +18,8 @@ } }, "defaults": { - "sortBy": "dateSent", - "asc": false, + "orderBy": "dateSent", + "order": "desc", "displayRecords": 5, "expandedLayout": { "rows": [ diff --git a/application/Espo/Resources/metadata/entityDefs/AuthToken.json b/application/Espo/Resources/metadata/entityDefs/AuthToken.json index 5eca726fbf..395cad03df 100644 --- a/application/Espo/Resources/metadata/entityDefs/AuthToken.json +++ b/application/Espo/Resources/metadata/entityDefs/AuthToken.json @@ -63,8 +63,8 @@ } }, "collection": { - "sortBy": "lastAccess", - "asc": false, + "orderBy": "lastAccess", + "order": "desc", "textFilterFields": ["ipAddress", "userName"] }, "indexes": { diff --git a/application/Espo/Resources/metadata/entityDefs/Email.json b/application/Espo/Resources/metadata/entityDefs/Email.json index ce300c1deb..611d1e082b 100644 --- a/application/Espo/Resources/metadata/entityDefs/Email.json +++ b/application/Espo/Resources/metadata/entityDefs/Email.json @@ -440,8 +440,8 @@ } }, "collection": { - "sortBy": "dateSent", - "asc": false, + "orderBy": "dateSent", + "order": "desc", "textFilterFields": ["name", "bodyPlain", "body"], "fullTextSearch": true }, diff --git a/application/Espo/Resources/metadata/entityDefs/EmailAccount.json b/application/Espo/Resources/metadata/entityDefs/EmailAccount.json index 30847ae41a..af69d12796 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailAccount.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailAccount.json @@ -152,7 +152,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailAddress.json b/application/Espo/Resources/metadata/entityDefs/EmailAddress.json index 1404e27e9c..385e1c445e 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailAddress.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailAddress.json @@ -19,7 +19,7 @@ "links": { }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailFilter.json b/application/Espo/Resources/metadata/entityDefs/EmailFilter.json index 87124efc16..f05a877613 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailFilter.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailFilter.json @@ -81,7 +81,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailFolder.json b/application/Espo/Resources/metadata/entityDefs/EmailFolder.json index def9eca36e..08e7e27ba2 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailFolder.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailFolder.json @@ -48,7 +48,7 @@ } }, "collection": { - "sortBy": "order", - "asc": true + "orderBy": "order", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailTemplate.json b/application/Espo/Resources/metadata/entityDefs/EmailTemplate.json index 791a6035a7..4539229082 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailTemplate.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailTemplate.json @@ -84,8 +84,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "createdAt", + "order": "desc", "textFilterFields": ["name", "bodyPlain", "body", "subject"] } } diff --git a/application/Espo/Resources/metadata/entityDefs/EmailTemplateCategory.json b/application/Espo/Resources/metadata/entityDefs/EmailTemplateCategory.json index d4d996e41c..74714d9bb0 100644 --- a/application/Espo/Resources/metadata/entityDefs/EmailTemplateCategory.json +++ b/application/Espo/Resources/metadata/entityDefs/EmailTemplateCategory.json @@ -73,8 +73,8 @@ } }, "collection": { - "sortBy": "parent", - "asc": true + "orderBy": "parent", + "order": "asc" }, "additionalTables": { "EmailTemplateCategoryPath": { diff --git a/application/Espo/Resources/metadata/entityDefs/Extension.json b/application/Espo/Resources/metadata/entityDefs/Extension.json index 34cc851a92..0a1db00ed3 100644 --- a/application/Espo/Resources/metadata/entityDefs/Extension.json +++ b/application/Espo/Resources/metadata/entityDefs/Extension.json @@ -38,7 +38,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Import.json b/application/Espo/Resources/metadata/entityDefs/Import.json index 210e1c9312..b6c26e2077 100644 --- a/application/Espo/Resources/metadata/entityDefs/Import.json +++ b/application/Espo/Resources/metadata/entityDefs/Import.json @@ -52,7 +52,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/InboundEmail.json b/application/Espo/Resources/metadata/entityDefs/InboundEmail.json index 0af85c2ad1..bba0107058 100644 --- a/application/Espo/Resources/metadata/entityDefs/InboundEmail.json +++ b/application/Espo/Resources/metadata/entityDefs/InboundEmail.json @@ -205,7 +205,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Job.json b/application/Espo/Resources/metadata/entityDefs/Job.json index 843aac66bc..41a904c975 100644 --- a/application/Espo/Resources/metadata/entityDefs/Job.json +++ b/application/Espo/Resources/metadata/entityDefs/Job.json @@ -72,8 +72,8 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false, + "orderBy": "createdAt", + "order": "desc", "textFilterFields": ["name", "methodName", "serviceName", "scheduledJobName"] }, "indexes": { diff --git a/application/Espo/Resources/metadata/entityDefs/LeadCapture.json b/application/Espo/Resources/metadata/entityDefs/LeadCapture.json index a33aeb7b59..945755566d 100644 --- a/application/Espo/Resources/metadata/entityDefs/LeadCapture.json +++ b/application/Espo/Resources/metadata/entityDefs/LeadCapture.json @@ -140,7 +140,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/LeadCaptureLogRecord.json b/application/Espo/Resources/metadata/entityDefs/LeadCaptureLogRecord.json index 67a73d7a49..914f70e5d5 100644 --- a/application/Espo/Resources/metadata/entityDefs/LeadCaptureLogRecord.json +++ b/application/Espo/Resources/metadata/entityDefs/LeadCaptureLogRecord.json @@ -37,7 +37,7 @@ } }, "collection": { - "sortBy": "number", - "asc": false + "orderBy": "number", + "order": "desc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Note.json b/application/Espo/Resources/metadata/entityDefs/Note.json index afc6815b84..3f1b33fa77 100644 --- a/application/Espo/Resources/metadata/entityDefs/Note.json +++ b/application/Espo/Resources/metadata/entityDefs/Note.json @@ -121,8 +121,8 @@ } }, "collection": { - "sortBy": "number", - "asc": false, + "orderBy": "number", + "order": "desc", "textFilterFields": ["post"] }, "statusStyles": { diff --git a/application/Espo/Resources/metadata/entityDefs/Notification.json b/application/Espo/Resources/metadata/entityDefs/Notification.json index f45659bb45..b96fd87730 100644 --- a/application/Espo/Resources/metadata/entityDefs/Notification.json +++ b/application/Espo/Resources/metadata/entityDefs/Notification.json @@ -52,8 +52,8 @@ } }, "collection": { - "sortBy": "number", - "asc": false + "orderBy": "number", + "order": "desc" }, "indexes": { "createdAt": { diff --git a/application/Espo/Resources/metadata/entityDefs/PhoneNumber.json b/application/Espo/Resources/metadata/entityDefs/PhoneNumber.json index 0843521ad6..b598006034 100644 --- a/application/Espo/Resources/metadata/entityDefs/PhoneNumber.json +++ b/application/Espo/Resources/metadata/entityDefs/PhoneNumber.json @@ -18,7 +18,7 @@ "links": { }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Portal.json b/application/Espo/Resources/metadata/entityDefs/Portal.json index 4f9e8919d2..02632096d2 100644 --- a/application/Espo/Resources/metadata/entityDefs/Portal.json +++ b/application/Espo/Resources/metadata/entityDefs/Portal.json @@ -139,7 +139,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/PortalRole.json b/application/Espo/Resources/metadata/entityDefs/PortalRole.json index 507f5ade5a..bc3c7217ac 100644 --- a/application/Espo/Resources/metadata/entityDefs/PortalRole.json +++ b/application/Espo/Resources/metadata/entityDefs/PortalRole.json @@ -40,7 +40,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Role.json b/application/Espo/Resources/metadata/entityDefs/Role.json index fdce066408..0f1553d385 100644 --- a/application/Espo/Resources/metadata/entityDefs/Role.json +++ b/application/Espo/Resources/metadata/entityDefs/Role.json @@ -75,7 +75,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json b/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json index 4208346ef9..c36caafbcf 100644 --- a/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json +++ b/application/Espo/Resources/metadata/entityDefs/ScheduledJob.json @@ -64,8 +64,8 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" }, "jobSchedulingMap": { "CheckInboundEmails": "*/2 * * * *", diff --git a/application/Espo/Resources/metadata/entityDefs/ScheduledJobLogRecord.json b/application/Espo/Resources/metadata/entityDefs/ScheduledJobLogRecord.json index 3bcf03bc5c..b1253b7033 100644 --- a/application/Espo/Resources/metadata/entityDefs/ScheduledJobLogRecord.json +++ b/application/Espo/Resources/metadata/entityDefs/ScheduledJobLogRecord.json @@ -31,7 +31,7 @@ } }, "collection": { - "sortBy": "executionTime", - "asc": false + "orderBy": "executionTime", + "order": "desc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Team.json b/application/Espo/Resources/metadata/entityDefs/Team.json index 119796c1bf..4539f451e0 100644 --- a/application/Espo/Resources/metadata/entityDefs/Team.json +++ b/application/Espo/Resources/metadata/entityDefs/Team.json @@ -46,7 +46,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/Template.json b/application/Espo/Resources/metadata/entityDefs/Template.json index 8b740ce6e8..6b8d990ef9 100644 --- a/application/Espo/Resources/metadata/entityDefs/Template.json +++ b/application/Espo/Resources/metadata/entityDefs/Template.json @@ -133,7 +133,7 @@ } }, "collection": { - "sortBy": "name", - "asc": true + "orderBy": "name", + "order": "asc" } } \ No newline at end of file diff --git a/application/Espo/Resources/metadata/entityDefs/UniqueId.json b/application/Espo/Resources/metadata/entityDefs/UniqueId.json index 633466a69b..09aca8d580 100644 --- a/application/Espo/Resources/metadata/entityDefs/UniqueId.json +++ b/application/Espo/Resources/metadata/entityDefs/UniqueId.json @@ -33,7 +33,7 @@ } }, "collection": { - "sortBy": "createdAt", - "asc": false + "orderBy": "createdAt", + "order": "desc" } } diff --git a/application/Espo/Resources/metadata/entityDefs/User.json b/application/Espo/Resources/metadata/entityDefs/User.json index 28e83a1f8d..9429877ca5 100644 --- a/application/Espo/Resources/metadata/entityDefs/User.json +++ b/application/Espo/Resources/metadata/entityDefs/User.json @@ -322,8 +322,8 @@ } }, "collection": { - "sortBy": "userName", - "asc": true, + "orderBy": "userName", + "order": "asc", "textFilterFields": ["name", "userName"] } } diff --git a/application/Espo/Services/Record.php b/application/Espo/Services/Record.php index ddf5b446d7..09ffa7f568 100644 --- a/application/Espo/Services/Record.php +++ b/application/Espo/Services/Record.php @@ -1664,10 +1664,11 @@ class Record extends \Espo\Core\Services\Base throw new BadRequest(); } - $orderBy = $this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'collection', 'sortBy']); - $desc = !$this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'collection', 'asc']); + $orderBy = $this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'collection', 'orderBy']); + $order = $this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'collection', 'order']); + if ($orderBy) { - $selectManager->applyOrder($orderBy, $desc, $selectParams); + $selectManager->applyOrder($orderBy, $order, $selectParams); } $this->getEntityManager()->getRepository($this->getEntityType())->handleSelectParams($selectParams); @@ -2228,8 +2229,8 @@ class Record extends \Espo\Core\Services\Base } } - if (!empty($params['sortBy'])) { - $sortByField = $params['sortBy']; + if (!empty($params['orderBy'])) { + $sortByField = $params['orderBy']; $sortByFieldType = $this->getMetadata()->get(['entityDefs', $this->getEntityType(), 'fields', $sortByField, 'type']); if ($sortByFieldType === 'currency') { diff --git a/client/modules/crm/src/views/knowledge-base-article/record/row-actions/default.js b/client/modules/crm/src/views/knowledge-base-article/record/row-actions/default.js index 7ffef39fa1..b9a10007f6 100644 --- a/client/modules/crm/src/views/knowledge-base-article/record/row-actions/default.js +++ b/client/modules/crm/src/views/knowledge-base-article/record/row-actions/default.js @@ -33,7 +33,7 @@ Espo.define('crm:views/knowledge-base-article/record/row-actions/default', 'view getActionList: function () { var actionList = Dep.prototype.getActionList.call(this); - if (this.options.acl.edit && this.model.collection && this.model.collection.sortBy == 'order' && this.model.collection.asc) { + if (this.options.acl.edit && this.model.collection && this.model.collection.orderBy == 'order' && this.model.collection.order === 'asc') { actionList.push({ action: 'moveToTop', label: 'Move to Top', diff --git a/client/modules/crm/src/views/record/panels/activities.js b/client/modules/crm/src/views/record/panels/activities.js index 3a86c186f1..5887007767 100644 --- a/client/modules/crm/src/views/record/panels/activities.js +++ b/client/modules/crm/src/views/record/panels/activities.js @@ -32,11 +32,11 @@ Espo.define('crm:views/record/panels/activities', ['views/record/panels/relation name: 'activities', - sortBy: 'dateStart', + orderBy: 'dateStart', serviceName: 'Activities', - asc: false, + order: 'desc', rowActionsView: 'crm:views/record/row-actions/activities', @@ -141,8 +141,8 @@ Espo.define('crm:views/record/panels/activities', ['views/record/panels/relation this.collection = new MultiCollection(); this.collection.seeds = this.seeds; this.collection.url = this.url; - this.collection.sortBy = this.sortBy; - this.collection.asc = this.asc; + this.collection.orderBy = this.orderBy; + this.collection.order = this.order; this.collection.maxSize = this.getConfig().get('recordsPerPageSmall') || 5; this.setFilter(this.filter); diff --git a/client/modules/crm/src/views/record/panels/history.js b/client/modules/crm/src/views/record/panels/history.js index 3b67732c52..e1cb2270a3 100644 --- a/client/modules/crm/src/views/record/panels/history.js +++ b/client/modules/crm/src/views/record/panels/history.js @@ -32,9 +32,9 @@ Espo.define('crm:views/record/panels/history', 'crm:views/record/panels/activiti name: 'history', - sortBy: 'dateStart', + orderBy: 'dateStart', - asc: false, + orderDirection: 'desc', rowActionsView: 'crm:views/record/row-actions/history', diff --git a/client/modules/crm/src/views/record/panels/tasks.js b/client/modules/crm/src/views/record/panels/tasks.js index 97392a8a6b..c6e3597d2b 100644 --- a/client/modules/crm/src/views/record/panels/tasks.js +++ b/client/modules/crm/src/views/record/panels/tasks.js @@ -38,9 +38,9 @@ Espo.define('crm:views/record/panels/tasks', 'views/record/panels/relationship', defaultTab: 'actual', - sortBy: 'createdAt', + orderBy: 'createdAt', - asc: false, + orderDirection: 'desc', rowActionsView: 'crm:views/record/row-actions/tasks', @@ -110,8 +110,8 @@ Espo.define('crm:views/record/panels/tasks', 'views/record/panels/relationship', this.collection = collection; collection.seeds = this.seeds; collection.url = this.url; - collection.sortBy = this.defaultSortBy; - collection.asc = this.defaultAsc; + collection.orderBy = this.defaultOrderBy; + collection.order = this.defaultOrder; collection.maxSize = this.getConfig().get('recordsPerPageSmall') || 5; this.setFilter(this.filter); diff --git a/client/src/collection-factory.js b/client/src/collection-factory.js index 765c63c5d6..0bc89dde24 100644 --- a/client/src/collection-factory.js +++ b/client/src/collection-factory.js @@ -43,17 +43,16 @@ context = context || this; this.modelFactory.getSeed(name, function (seed) { + var orderBy = this.modelFactory.metadata.get(['entityDefs', name, 'collection', 'orderBy']); + var order = this.modelFactory.metadata.get(['entityDefs', name, 'collection', 'order']); - var asc = this.modelFactory.metadata.get('entityDefs.' + name + '.collection.asc'); - var sortBy = this.modelFactory.metadata.get('entityDefs.' + name + '.collection.sortBy'); - - var className = this.modelFactory.metadata.get('clientDefs.' + name + '.collection') || 'collection'; + var className = this.modelFactory.metadata.get(['clientDefs', name, 'collection']) || 'collection'; Espo.loader.require(className, function (collectionClass) { var collection = new collectionClass(null, { name: name, - asc: asc, - sortBy: sortBy + orderBy: orderBy, + order: order }); collection.model = seed; collection._user = this.modelFactory.user; @@ -67,4 +66,3 @@ return CollectionFactory; }); - diff --git a/client/src/collection.js b/client/src/collection.js index 2d214a707e..091d6fedae 100644 --- a/client/src/collection.js +++ b/client/src/collection.js @@ -38,9 +38,11 @@ Espo.define('collection', [], function () { maxSize: 20, - sortBy: 'id', + asc: null, // TODO remove in 5.7 - asc: false, + order: null, + + orderBy: null, where: null, @@ -56,10 +58,15 @@ Espo.define('collection', [], function () { this.urlRoot = this.urlRoot || this.name; this.url = this.url || this.urlRoot; - this.sortBy = options.sortBy || this.sortBy; - this.defaultSortBy = this.sortBy; - this.asc = ('asc' in options) ? options.asc : this.asc; - this.defaultAsc = this.asc; + this.orderBy = this.sortBy = options.orderBy || options.sortBy || this.orderBy || this.sortBy; + this.order = options.order || this.order; + + this.asc = ('asc' in options) ? options.asc : this.asc; // TODO remove in 5.7 + + this.defaultOrder = this.order; + this.defaultOrderBy = this.orderBy; + + this.data = {}; Backbone.Collection.prototype.initialize.call(this); @@ -75,9 +82,16 @@ Espo.define('collection', [], function () { Backbone.Collection.prototype.reset.call(this, models, options); }, - sort: function (field, asc) { - this.sortBy = field; - this.asc = asc; + sort: function (orderBy, order) { + this.orderBy = orderBy; + + if (order === true) { + order = 'desc'; + } else if (order === false) { + order = 'asc'; + } + this.order = order || 'asc'; + this.fetch(); }, @@ -127,9 +141,18 @@ Espo.define('collection', [], function () { var options = options || {}; options.data = _.extend(options.data || {}, this.data); + if (this.asc === true || this.asc === false) { // TODO remove in 5.7 + this.order = this.asc ? 'asc' : 'desc'; + } + this.offset = options.offset || this.offset; - this.sortBy = options.sortBy || this.sortBy; - this.asc = options.asc || this.asc; + this.orderBy = options.orderBy || options.sortBy || this.orderBy; + this.order = options.order || this.order; + + if (options.asc) { // TODO remove in 5.7 + this.order = 'asc'; + } + this.where = options.where || this.where; if (!('maxSize' in options)) { @@ -139,8 +162,8 @@ Espo.define('collection', [], function () { } options.data.offset = options.more ? this.length + this.lengthCorrection : this.offset; - options.data.sortBy = this.sortBy; - options.data.asc = this.asc; + options.data.orderBy = this.orderBy; + options.data.order = this.order; options.data.where = this.getWhere(); this.lastXhr = Backbone.Collection.prototype.fetch.call(this, options); diff --git a/client/src/multi-collection.js b/client/src/multi-collection.js index c0d44b7633..d22e4d6ef9 100644 --- a/client/src/multi-collection.js +++ b/client/src/multi-collection.js @@ -26,7 +26,8 @@ * these Appropriate Legal Notices must retain the display of the "EspoCRM" word. ************************************************************************/ -Espo.define('MultiCollection', 'Collection', function (Collection) { +Espo.define('multi-collection', 'collection', function (Collection) { + var MultiCollection = Collection.extend({ /** @@ -37,9 +38,6 @@ Espo.define('MultiCollection', 'Collection', function (Collection) { initialize: function (models, options) { options = options || {}; - this.sortBy = options.sortBy || this.sortBy; - this.asc = ('asc' in options) ? options.asc : this.asc; - this.data = {}; Backbone.Collection.prototype.initialize.call(this); @@ -57,5 +55,4 @@ Espo.define('MultiCollection', 'Collection', function (Collection) { }); return MultiCollection; - }); diff --git a/client/src/views/admin/entity-manager/modals/edit-entity.js b/client/src/views/admin/entity-manager/modals/edit-entity.js index 31f5991274..21005ba545 100644 --- a/client/src/views/admin/entity-manager/modals/edit-entity.js +++ b/client/src/views/admin/entity-manager/modals/edit-entity.js @@ -61,8 +61,8 @@ Espo.define('views/admin/entity-manager/modals/edit-entity', ['views/modal', 'mo this.model.set('stream', this.getMetadata().get('scopes.' + scope + '.stream') || false); this.model.set('disabled', this.getMetadata().get('scopes.' + scope + '.disabled') || false); - this.model.set('sortBy', this.getMetadata().get('entityDefs.' + scope + '.collection.sortBy')); - this.model.set('sortDirection', this.getMetadata().get('entityDefs.' + scope + '.collection.asc') ? 'asc' : 'desc'); + this.model.set('sortBy', this.getMetadata().get('entityDefs.' + scope + '.collection.orderBy')); + this.model.set('sortDirection', this.getMetadata().get('entityDefs.' + scope + '.collection.order')); this.model.set('textFilterFields', this.getMetadata().get(['entityDefs', scope, 'collection', 'textFilterFields']) || ['name']); this.model.set('fullTextSearch', this.getMetadata().get(['entityDefs', scope, 'collection', 'fullTextSearch']) || false); diff --git a/client/src/views/dashlets/abstract/base.js b/client/src/views/dashlets/abstract/base.js index 08005a7745..eb6de2dbb8 100644 --- a/client/src/views/dashlets/abstract/base.js +++ b/client/src/views/dashlets/abstract/base.js @@ -144,11 +144,13 @@ Espo.define('views/dashlets/abstract/base', 'view', function (Dep) { setupButtonList: function () {}, + hasOption: function (key) { + return key in this.optionsData; + }, + getOption: function (key) { return this.optionsData[key]; } }); }); - - diff --git a/client/src/views/dashlets/abstract/record-list.js b/client/src/views/dashlets/abstract/record-list.js index 697b30e29c..83cfa6ad81 100644 --- a/client/src/views/dashlets/abstract/record-list.js +++ b/client/src/views/dashlets/abstract/record-list.js @@ -85,13 +85,27 @@ Espo.define('views/dashlets/abstract/record-list', ['views/dashlets/abstract/bas } this.collection = collection; - collection.sortBy = this.getOption('sortBy') || this.collection.sortBy; - collection.asc = this.getOption('asc') || this.collection.asc; + + collection.orderBy = this.getOption('orderBy') || this.getOption('sortBy') || this.collection.orderBy; + + if (this.getOption('orderBy')) { + collection.order = 'asc'; + } + + if (this.hasOption('asc')) { + collection.order = this.getOption('asc') ? 'asc' : false; + } if (this.getOption('sortDirection') === 'asc') { - collection.asc = true; + collection.order = 'asc'; } else if (this.getOption('sortDirection') === 'desc') { - collection.asc = false; + collection.order = 'desc'; + } + + if (this.getOption('order') === 'asc') { + collection.order = 'order'; + } else if (this.getOption('order') === 'desc') { + collection.order = 'desc'; } collection.maxSize = this.getOption('displayRecords'); diff --git a/client/src/views/dashlets/fields/records/entity-type.js b/client/src/views/dashlets/fields/records/entity-type.js index c7558657e4..e0eb920d0c 100644 --- a/client/src/views/dashlets/fields/records/entity-type.js +++ b/client/src/views/dashlets/fields/records/entity-type.js @@ -46,12 +46,12 @@ Espo.define('views/dashlets/fields/records/entity-type', 'views/fields/enum', fu var entityType = this.model.get('entityType'); if (entityType) { o.title = this.translate(entityType, 'scopeNamesPlural'); - o.sortBy = this.getMetadata().get(['entityDefs', entityType, 'collection', 'sortBy']); - var asc = this.getMetadata().get(['entityDefs', entityType, 'collection', 'asc']); - if (asc) { - o.sortDirection = 'asc'; + o.sortBy = this.getMetadata().get(['entityDefs', entityType, 'collection', 'orderBy']); + var order = this.getMetadata().get(['entityDefs', entityType, 'collection', 'order']); + if (order) { + o.sortDirection = order; } else { - o.sortDirection = 'desc'; + o.sortDirection = 'asc'; } o.expandedLayout = { rows: [[{name: "name", link: true, scope: entityType}]] diff --git a/client/src/views/fields/link-multiple.js b/client/src/views/fields/link-multiple.js index ef3b6552fc..2244f5966b 100644 --- a/client/src/views/fields/link-multiple.js +++ b/client/src/views/fields/link-multiple.js @@ -169,7 +169,7 @@ Espo.define('views/fields/link-multiple', 'views/fields/base', function (Dep) { }, getAutocompleteUrl: function () { - var url = this.foreignScope + '?sortBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; + var url = this.foreignScope + '?orderBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; var boolList = this.getSelectBoolFilterList(); var where = []; if (boolList) { diff --git a/client/src/views/fields/link-parent.js b/client/src/views/fields/link-parent.js index f40202c525..fc0c05979c 100644 --- a/client/src/views/fields/link-parent.js +++ b/client/src/views/fields/link-parent.js @@ -192,7 +192,7 @@ Espo.define('views/fields/link-parent', 'views/fields/base', function (Dep) { }, getAutocompleteUrl: function () { - var url = this.foreignScope + '?sortBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; + var url = this.foreignScope + '?orderBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; var boolList = this.getSelectBoolFilterList(); var where = []; if (boolList) { diff --git a/client/src/views/fields/link.js b/client/src/views/fields/link.js index e564cd1be7..0d14a23678 100644 --- a/client/src/views/fields/link.js +++ b/client/src/views/fields/link.js @@ -213,7 +213,7 @@ Espo.define('views/fields/link', 'views/fields/base', function (Dep) { }, getAutocompleteUrl: function () { - var url = this.foreignScope + '?sortBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; + var url = this.foreignScope + '?orderBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; var boolList = this.getSelectBoolFilterList(); var where = []; if (boolList) { diff --git a/client/src/views/fields/user.js b/client/src/views/fields/user.js index ab89f8a50b..b7a15be0b7 100644 --- a/client/src/views/fields/user.js +++ b/client/src/views/fields/user.js @@ -92,7 +92,7 @@ Espo.define('views/fields/user', 'views/fields/link', function (Dep) { var $elemeneTeams = this.$el.find('input.element-teams'); $elemeneTeams.autocomplete({ serviceUrl: function (q) { - return 'Team?sortBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; + return 'Team?orderBy=name&maxCount=' + this.AUTOCOMPLETE_RESULT_MAX_COUNT; }.bind(this), minChars: 1, paramName: 'q', diff --git a/client/src/views/list.js b/client/src/views/list.js index d048f4faa0..61bad52ff6 100644 --- a/client/src/views/list.js +++ b/client/src/views/list.js @@ -96,8 +96,8 @@ Espo.define('views/list', ['views/main', 'search-manager'], function (Dep, Searc this.setupSearchManager(); } - this.defaultSortBy = this.collection.sortBy; - this.defaultAsc = this.collection.asc; + this.defaultOrderBy = this.collection.orderBy; + this.defaultOrder = this.collection.order; this.setupSorting(); @@ -233,13 +233,13 @@ Espo.define('views/list', ['views/main', 'search-manager'], function (Dep, Searc this.collection.url = this.scope + '/action/listKanban'; this.collection.maxSize = this.getConfig().get('recordsPerPageSmall'); - this.collection.sortBy = this.collection.defaultSortBy; - this.collection.asc = this.collection.defaultAsc; + this.collection.orderBy = this.collection.defaultOrderBy; + this.collection.order = this.collection.defaultOrder; }, resetSorting: function () { - this.collection.sortBy = this.defaultSortBy; - this.collection.asc = this.defaultAsc; + this.collection.orderBy = this.defaultOrderBy; + this.collection.order = this.defaultOrder; this.getStorage().clear('listSorting', this.collection.name); }, @@ -265,12 +265,13 @@ Espo.define('views/list', ['views/main', 'search-manager'], function (Dep, Searc }, applyStoredSorting: function () { - var sortingParams = this.getStorage().get('listSorting', this.collection.name) || {}; - if ('sortBy' in sortingParams) { - this.collection.sortBy = sortingParams.sortBy; + var sortingParams = this.getStorage().get('listSorting', this.collection.entityType) || {}; + + if ('orderBy' in sortingParams) { + this.collection.orderBy = sortingParams.orderBy; } - if ('asc' in sortingParams) { - this.collection.asc = sortingParams.asc; + if ('order' in sortingParams) { + this.collection.order = sortingParams.order; } }, diff --git a/client/src/views/modals/related-list.js b/client/src/views/modals/related-list.js index 8d1d68e77e..efa8c304d3 100644 --- a/client/src/views/modals/related-list.js +++ b/client/src/views/modals/related-list.js @@ -72,8 +72,8 @@ Espo.define('views/modals/related-list', ['views/modal', 'search-manager'], func this.scope = this.options.scope || this.scope; - this.defaultSortBy = this.options.defaultSortBy; - this.defaultAsc = this.options.defaultAsc; + this.defaultOrderBy = this.options.defaultOrderBy; + this.defaultOrder = this.options.defaultOrder; this.panelName = this.options.panelName; this.link = this.options.link; @@ -147,8 +147,8 @@ Espo.define('views/modals/related-list', ['views/modal', 'search-manager'], func this.collection = collection; - collection.sortBy = this.defaultSortBy; - collection.asc = this.defaultAsc; + collection.orderBy = this.defaultOrderBy; + collection.order = this.defaultOrder; this.listenTo(collection, 'change', function (model) { var panelModel = this.panelCollection.get(model.id); @@ -210,8 +210,8 @@ Espo.define('views/modals/related-list', ['views/modal', 'search-manager'], func filterList: filterList }, function (view) { this.listenTo(view, 'reset', function () { - this.collection.sortBy = this.defaultSortBy; - this.collection.asc = this.defaultAsc; + this.collection.orderBy = this.defaultOrderBy; + this.collection.order = this.defaultOrder; }, this); }); } diff --git a/client/src/views/modals/select-records.js b/client/src/views/modals/select-records.js index cedfe082f8..a207de052d 100644 --- a/client/src/views/modals/select-records.js +++ b/client/src/views/modals/select-records.js @@ -143,8 +143,8 @@ Espo.define('views/modals/select-records', ['views/modal', 'search-manager'], fu collection.maxSize = this.getConfig().get('recordsPerPageSmall') || 5; this.collection = collection; - this.defaultSortBy = collection.sortBy; - this.defaultAsc = collection.asc; + this.defaultOrderBy = collection.orderBy; + this.defaultOrder = collection.defaultOrder; this.loadSearch(); this.wait(true); @@ -183,8 +183,8 @@ Espo.define('views/modals/select-records', ['views/modal', 'search-manager'], fu disableSavePreset: true, }, function (view) { this.listenTo(view, 'reset', function () { - this.collection.sortBy = this.defaultSortBy; - this.collection.asc = this.defaultAsc; + this.collection.orderBy = this.defaultOrderBy; + this.collection.order = this.defaultOrder; }, this); }); } diff --git a/client/src/views/record/kanban.js b/client/src/views/record/kanban.js index e40600c3ef..ebdfc5b290 100644 --- a/client/src/views/record/kanban.js +++ b/client/src/views/record/kanban.js @@ -193,8 +193,8 @@ Espo.define('views/record/kanban', ['views/record/list'], function (Dep) { this.seedCollection.url = this.scope; this.seedCollection.maxSize = this.collection.maxSize; this.seedCollection.name = this.collection.name; - this.seedCollection.sortBy = this.collection.defaultSortBy; - this.seedCollection.asc = this.collection.defaultAsc; + this.seedCollection.orderBy = this.collection.defaultOrderBy; + this.seedCollection.order = this.collection.defaultOrder; this.listenTo(this.collection, 'sync', function (c, r, options) { if (this.hasView('modal') && this.getView('modal').isRendered()) return; @@ -429,8 +429,8 @@ Espo.define('views/record/kanban', ['views/record/list'], function (Dep) { collection.where = this.collection.where; collection.name = this.seedCollection.name; collection.maxSize = this.seedCollection.maxSize; - collection.sortBy = this.seedCollection.sortBy; - collection.asc = this.seedCollection.asc; + collection.orderBy = this.seedCollection.orderBy; + collection.order = this.seedCollection.order; collection.whereAdditional = [ { field: this.statusField, diff --git a/client/src/views/record/list.js b/client/src/views/record/list.js index c2256bb098..c5107e3350 100644 --- a/client/src/views/record/list.js +++ b/client/src/views/record/list.js @@ -160,21 +160,24 @@ Espo.define('views/record/list', 'view', function (Dep) { } }, - toggleSort: function (field) { + toggleSort: function (orderBy) { var asc = true; - if (field === this.collection.sortBy && this.collection.asc) { + if (orderBy === this.collection.orderBy && this.collection.order === 'asc') { asc = false; } + var order = asc ? 'asc' : 'desc'; + this.notify('Please wait...'); this.collection.once('sync', function () { this.notify(false); - this.trigger('sort', {sortBy: field, asc: asc}); + this.trigger('sort', {orderBy: orderBy, order: order}); }, this); + var maxSizeLimit = this.getConfig().get('recordListMaxSizeLimit') || 200; while (this.collection.length > maxSizeLimit) { this.collection.pop(); } - this.collection.sort(field, asc); + this.collection.sort(orderBy, order); this.deactivate(); }, @@ -993,9 +996,9 @@ Espo.define('views/record/list', 'view', function (Dep) { item.hasCustomLabel = true; } if (item.sortable) { - item.sorted = this.collection.sortBy === this.listLayout[i].name; + item.sorted = this.collection.orderBy === this.listLayout[i].name; if (item.sorted) { - item.asc = this.collection.asc; + item.asc = this.collection.order === 'asc' ; } } defs.push(item); diff --git a/client/src/views/record/panels/relationship.js b/client/src/views/record/panels/relationship.js index 64a0ed5bbd..14b6abe950 100644 --- a/client/src/views/record/panels/relationship.js +++ b/client/src/views/record/panels/relationship.js @@ -170,11 +170,11 @@ Espo.define('views/record/panels/relationship', ['views/record/panels/bottom', ' } collection.url = collection.urlRoot = url; - if (this.defaultSortBy) { - collection.sortBy = this.defaultSortBy; + if (this.defaultOrderBy) { + collection.orderBy = this.defaultOrderBy; } - if (this.defaultAsc) { - collection.asc = this.defaultAsc; + if (this.defaultOrder) { + collection.order = this.defaultOrder; } this.collection = collection; @@ -248,21 +248,19 @@ Espo.define('views/record/panels/relationship', ['views/record/panels/bottom', ' }, setupSorting: function () { - var sortBy = this.defs.sortBy || this.sortBy; - var asc = this.defs.asc || this.asc; + var orderBy = this.defs.orderBy || this.defs.sortBy || this.orderBy; + var order = this.defs.orderDirection || this.orderDirection || this.order; - if (this.defs.orderBy) { - sortBy = this.defs.orderBy; - asc = true; - if (this.defs.orderDirection) { - if (this.defs.orderDirection && (this.defs.orderDirection === true || this.defs.orderDirection.toLowerCase() === 'DESC')) { - asc = false; - } - } + if ('asc' in this.defs) { // TODO remove in 5.8 + order = this.defs.asc ? 'asc' : 'desc'; } - this.defaultSortBy = sortBy; - this.defaultAsc = asc; + if (orderBy && !order) { + order = 'asc'; + } + + this.defaultOrderBy = orderBy; + this.defaultOrder = order; }, setupListLayout: function () {}, @@ -374,8 +372,8 @@ Espo.define('views/record/panels/relationship', ['views/record/panels/bottom', ' filterList: this.filterList, filter: filter, layoutName: this.layoutName, - defaultAsc: this.defaultAsc, - defaultSortBy: this.defaultSortBy, + defaultOrder: this.defaultOrder, + defaultOrderBy: this.defaultOrderBy, url: data.url || this.url, listViewName: this.listViewName, createDisabled: !this.isCreateAvailable(scope),