diff --git a/Civi/Api4/Action/ContactCategory/GetFlows.php b/Civi/Api4/Action/ContactCategory/GetFlows.php index bc3f5cd..d86445d 100644 --- a/Civi/Api4/Action/ContactCategory/GetFlows.php +++ b/Civi/Api4/Action/ContactCategory/GetFlows.php @@ -3,6 +3,7 @@ namespace Civi\Api4\Action\ContactCategory; use CRM_Contactcats_ExtensionUtil as E; use Civi; +use Civi\Api4\ContactCategoryDefinition; use Civi\Api4\Generic\Result; use CRM_Core_DAO; use CRM_Core_Exception; @@ -296,10 +297,16 @@ class GetFlows extends \Civi\Api4\Generic\AbstractAction { 2 => [$endDateYmd, 'Int'], ])->fetchAll(); + // It's possible to end up with NULLs at the startSide. + // These should be replaced with our default category. + $defaultCategoryId = ContactCategoryDefinition::get() + ->addWhere('search_type:name', '=', 'default') + ->execute()->first()['id']; + // Don't use exchange array so as not to gazump non-array data(?) foreach ($data as $row) { $result[] = [ - 'from_category_id' => (int) $row['from_category_id'], + 'from_category_id' => (int) (($row['from_category_id']) ?: $defaultCategoryId), 'to_category_id' => (int) $row['to_category_id'], 'contact_count' => (int) $row['contact_count'], ]; @@ -313,8 +320,8 @@ class GetFlows extends \Civi\Api4\Generic\AbstractAction { try { $data = CRM_Core_DAO::executeQuery($sql, $params)->fetchAll(); } - catch (\Exception $e) { - print $e->getCause()->userinfo; + catch (\CRM_Core_Exception $e) { + if (method_exists('getClause', $e)) print $e->getCause()->userinfo; } print "\n$msg (" . count($data) . ") records ===============================\n"; foreach ($data as $row) { diff --git a/ang/crmContactcats.js b/ang/crmContactcats.js index f1a534b..9fb8e4a 100644 --- a/ang/crmContactcats.js +++ b/ang/crmContactcats.js @@ -47,6 +47,7 @@ } // Ensure we have the minimum of what we need. if (!catDefs.find(c => c.search_type === 'default')) { + console.log("Adding default category as was missing"); // There's no default one. catDefs.push(Object.assign({}, blankDefn, { execution_order: catDefs.length, @@ -67,8 +68,11 @@ ctrl[orderField] = catDefs.slice(); ctrl[orderField].sort((a, b) => { // console.log({orderField, aST: a.search_type, bST: b.search_type, aOrd:a[orderField], bOrd:b[orderField], aLab:a.label, bLab:b.label}); - if (a.search_type === 'default' && b.search_type !== 'default') return 1; - if (b.search_type === 'default' && a.search_type !== 'default') return -1; + if (orderField === 'execution_order') { + // Enforce default at end for assignment order + if (a.search_type === 'default' && b.search_type !== 'default') return 1; + if (b.search_type === 'default' && a.search_type !== 'default') return -1; + } if (a[orderField] > b[orderField]) return 1; if (a[orderField] < b[orderField]) return -1; if (a.label < b.label) return 1; @@ -162,6 +166,16 @@ ctrl.view = 'list'; } + ctrl.canMoveBelow = function(row, idx) { + // Only show move buttons when moving. + if (ctrl.moveIdx === null) return false; + + if (ctrl.uxOrderField === 'execution_order') { + // The default MUST be the last item in execution_order. + if (row.search_type === 'default') return false; + } + return (idx + 1 < ctrl.moveIdx || idx > ctrl.moveIdx); + }; /** * Move a category within the currently selected order. */ diff --git a/ang/crmContactcats/crmContactCategoryFlows.html b/ang/crmContactcats/crmContactCategoryFlows.html index da07896..8c19be2 100644 --- a/ang/crmContactcats/crmContactCategoryFlows.html +++ b/ang/crmContactcats/crmContactCategoryFlows.html @@ -2,20 +2,29 @@