Fix contact summary search display

This commit is contained in:
Rich Lott / Artful Robot 2025-04-02 14:43:06 +01:00
parent e65d0dcf6c
commit ac8d415729
4 changed files with 45 additions and 78 deletions

View file

@ -18,10 +18,8 @@
totalCount: '=?'
},
controller: function($scope, $element, crmApi4, searchDisplayBaseTrait, searchDisplayTasksTrait) {
console.log('crmSearchDisplayContactCat controller called');
// Mix in required traits
ctrl = angular.extend(this, _.cloneDeep(searchDisplayBaseTrait), _.cloneDeep(searchDisplayTasksTrait));
console.log("hello display");
var ts = ($scope.ts = CRM.ts(null)),
ctrl = this;
@ -40,7 +38,7 @@
$scope.$watch('$ctrl.results', () => { ctrl.n++; }, true);
$scope.$watch('$ctrl.n', () => {
console.log("watch n running");
console.log("watch n running 2025-04-02 ");
if (!ctrl.catDefs || !ctrl.results?.count) {
console.log("...waiting for all the data we need");
ctrl.ourData = {
@ -50,17 +48,25 @@
return ctrl.n;
}
// Should do this at the php end but I don't know how.
ctrl.results.sort((a, b) => {
if (a.data.activity_date_time < b.data.activity_date_time) return 1;
if (a.data.activity_date_time > b.data.activity_date_time) return -1;
return a.data.id - b.data.id;
});
const rows = ctrl.results.map((row) => {
const d = (new Date(row.data.activity_date_time.replace(' ', 'T'))).toLocaleString('UTC', {
weekday: 'short',
day: 'numeric',
month: 'short',
year: 'numeric',
});
const d = (new Date(row.data.activity_date_time.replace(' ', 'T'))),
when = d.toLocaleString('UTC', {
weekday: 'short',
day: 'numeric',
month: 'short',
year: 'numeric',
});
return {
contact_id: row.data['Activity_ActivityContact_Contact_01.id'],
new: ctrl.catDefs[row.data['Category_changes.new_category_id']],
when: d,
when,
data: row.data,
};
});
ctrl.ourData = {rows, count:rows.length};

View file

@ -8,10 +8,10 @@
<!-- output the current category -->
<details class="">
<summary>
{{ts('Category')}}:
{{ts('Category')}}: &nbsp;
<span ng-if="!$ctrl.ourData.count" >{{ts('Loading')}}</span>
<span ng-if="$ctrl.ourData.count" style="color:{{$ctrl.ourData.rows[0].new.color}};">
<i class="crm-i {{$ctrl.ourData.rows[0].new.icon}}" ></i>
<i class="crm-i {{$ctrl.ourData.rows[0].new.icon}}" ></i>&nbsp;
{{$ctrl.ourData.rows[0].new.label}}
</span>
</summary>

View file

@ -1,66 +0,0 @@
<?php
use CRM_Contactcats_ExtensionUtil as E;
// This defines a search display type... I think.
return [
[
'name' => 'OptionValue_crm_search_display_contact_cat',
'entity' => 'OptionValue',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'option_group_id.name' => 'search_display_type',
'label' => E::ts('Category'),
'value' => 'contact-cat',
'name' => 'crm-search-display-contact-cat',
'weight' => 6,
'description' => E::ts('Shows the current and previous categories for this contact'),
'icon' => 'fa-tag',
],
'match' => [
'option_group_id',
'name',
],
],
],
// Weird, so this bit belongs elsewhere
[
'name' => 'OptionValue_crm_search_display_contact_cat_SearchDisplay_Category_by_contact_Category_1',
'entity' => 'SearchDisplay',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'name' => 'Category_by_contact_Category_1',
'label' => E::ts('Category Category'),
'saved_search_id.name' => 'Category_by_contact',
'type' => 'contact-cat',
'settings' => [
'something' => 'nothing',
'limit' => 50,
'sort' => [],
'pager' => [],
// not sure about the columns bit.
'columns' => [
[
'type' => 'field',
'key' => 'id',
'dataType' => 'Integer',
],
[
'type' => 'field',
'key' => 'category_definition_id:label',
'dataType' => 'Integer',
],
],
],
],
'match' => [
'name',
],
],
],
];

View file

@ -0,0 +1,27 @@
<?php
use CRM_Contactcats_ExtensionUtil as E;
// This defines a search display type... I think.
return [
[
'name' => 'OptionValue_crm_search_display_contact_cat',
'entity' => 'OptionValue',
'cleanup' => 'unused',
'update' => 'unmodified',
'params' => [
'version' => 4,
'values' => [
'option_group_id:name' => 'search_display_type',
'label' => E::ts('Category'),
'value' => 'contact-cat',
'name' => 'crm-search-display-contact-cat',
'description' => E::ts('Shows the current and previous categories for this contact'),
'icon' => 'fa-tag',
],
'match' => [
'option_group_id',
'name',
],
],
],
];