Skip to content

Commit

Permalink
Make Person List Columns Configurable (#7147)
Browse files Browse the repository at this point in the history
# Description & Issue number it closes 
#7021
I will make similar change for family list later.

## Screenshots (if appropriate)
### Before
<img width="1421" alt="Screenshot 2024-09-15 at 11 10 11 PM"
src="https://github.com/user-attachments/assets/441f0f44-eca1-4cad-a885-6e540f10f163">

### Config Change
Hide `Home Phone` and `Cell Phone`.
<img width="1313" alt="Screenshot 2024-09-15 at 11 11 18 PM"
src="https://github.com/user-attachments/assets/ea014948-f5b1-492e-84e9-281d0728452d">

### After
<img width="1421" alt="Screenshot 2024-09-15 at 11 23 49 PM"
src="https://github.com/user-attachments/assets/c8456322-c154-4452-bc48-8017ed775f07">

## How to test the changes?
See the above screenshots

Click View Active People after changing `Admin/ Edit General Settings /
People Setup / sPersonListColumns`

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)
- [X] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Docker

# Checklist:

- [X] My code follows the style guidelines of this project
- [X] I have performed a self-review of my code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [X] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [X] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
  • Loading branch information
DAcodedBEAT authored Sep 17, 2024
2 parents 3ba5a84 + 68ae160 commit 3e7c791
Show file tree
Hide file tree
Showing 3 changed files with 89 additions and 67 deletions.
19 changes: 19 additions & 0 deletions src/ChurchCRM/dto/ListColumn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace ChurchCRM\dto;

class ListColumn
{
public string $name;
public string $displayFunction;
public string $emptyOrUnassigned;
public string $visible;

public function __construct(string $name, string $displayFunction, string $emptyOrUnassigned, string $visible)
{
$this->name = $name;
$this->displayFunction = $displayFunction;
$this->emptyOrUnassigned = $emptyOrUnassigned;
$this->visible = $visible;
}
}
25 changes: 24 additions & 1 deletion src/ChurchCRM/dto/SystemConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,28 @@ public static function getInitialStyleChoices(): array
];
}

public static function getPersonListColumns(): array
{
return [
'Id' => new ListColumn('Id', 'getId', 'false', 'false'),
'Family Name' => new ListColumn('Family Name', 'getFamilyName', 'false', 'false'),
'Name' => new ListColumn('Name', 'getFullName', 'false', 'false'),
'Last Name' => new ListColumn('Last Name', 'getLastName', 'false', 'true'),
'First Name' => new ListColumn('First Name', 'getFirstName', 'false', 'true'),
'Birth Date' => new ListColumn('Birth Date', 'getFormattedBirthDate', 'false', 'false'),
'Address' => new ListColumn('Address', 'getAddress', 'false', 'false'),
'Home Phone' => new ListColumn('Home Phone', 'getHomePhone', 'false', 'true'),
'Cell Phone' => new ListColumn('Cell Phone', 'getCellPhone', 'false', 'true'),
'Email' => new ListColumn('Email', 'getEmail', 'false', 'true'),
'Gender' => new ListColumn('Gender', 'getGenderName', 'true', 'true'),
'Classification' => new ListColumn('Classification', 'getClassificationName', 'true', 'true'),
'Role' => new ListColumn('Role', 'getFamilyRoleName', 'true', 'true'),
'Properties' => new ListColumn('Properties', 'getPropertiesString', 'true', 'false'),
'Custom' => new ListColumn('Custom', 'getCustomFields', 'true', 'false'),
'Group' => new ListColumn('Group', 'getGroups', 'true', 'false'),
];
}

private static function buildConfigs(): array
{
return [
Expand Down Expand Up @@ -279,6 +301,7 @@ private static function buildConfigs(): array
'sGoogleMapsRenderKey' => new ConfigItem(2072, 'sGoogleMapsRenderKey', 'text', '', gettext('Google Maps API Key used for rendering maps in browser'), 'https://developers.google.com/maps/documentation/javascript/get-api-key'),
'sInactiveClassification' => new ConfigItem(2073, 'sInactiveClassification', 'text', '', gettext('Comma separated list of classifications that should appear as inactive')),
'sDefaultZip' => new ConfigItem(2074, 'sDefaultZip', 'text', '', gettext('Default Zip')),
'sPersonListColumns' => new ConfigItem(2075, 'sPersonListColumns', 'json', json_encode(SystemConfig::getPersonListColumns()), gettext('Person List Columns')),
];
}

Expand All @@ -288,7 +311,7 @@ private static function buildCategories(): array
gettext('Church Information') => ['sChurchName', 'sChurchAddress', 'sChurchCity', 'sChurchState', 'sChurchZip', 'sChurchCountry', 'sChurchPhone', 'sChurchEmail', 'sHomeAreaCode', 'sTimeZone', 'iChurchLatitude', 'iChurchLongitude', 'sChurchWebSite', 'sChurchFB', 'sChurchTwitter'],
gettext('User Setup') => ['iMinPasswordLength', 'iMinPasswordChange', 'iMaxFailedLogins', 'iSessionTimeout', 'aDisallowedPasswords', 'bEnableLostPassword', 'bEnable2FA', 'bRequire2FA', 's2FAApplicationName', 'bSendUserDeletedEmail'],
gettext('Email Setup') => ['sSMTPHost', 'bSMTPAuth', 'sSMTPUser', 'sSMTPPass', 'iSMTPTimeout', 'sToEmailAddress', 'bPHPMailerAutoTLS', 'sPHPMailerSMTPSecure'],
gettext('People Setup') => ['sDirClassifications', 'sDirRoleHead', 'sDirRoleSpouse', 'sDirRoleChild', 'sDefaultCity', 'sDefaultState', 'sDefaultZip', 'sDefaultCountry', 'bShowFamilyData', 'bHidePersonAddress', 'bHideFriendDate', 'bHideFamilyNewsletter', 'bHideWeddingDate', 'bHideLatLon', 'bForceUppercaseZip', 'bEnableSelfRegistration', 'bAllowEmptyLastName', 'iPersonNameStyle', 'iPersonInitialStyle', 'iProfilePictureListSize', 'sNewPersonNotificationRecipientIDs', 'IncludeDataInNewPersonNotifications', 'sGreeterCustomMsg1', 'sGreeterCustomMsg2', 'sInactiveClassification'],
gettext('People Setup') => ['sDirClassifications', 'sDirRoleHead', 'sDirRoleSpouse', 'sDirRoleChild', 'sDefaultCity', 'sDefaultState', 'sDefaultZip', 'sDefaultCountry', 'bShowFamilyData', 'bHidePersonAddress', 'bHideFriendDate', 'bHideFamilyNewsletter', 'bHideWeddingDate', 'bHideLatLon', 'bForceUppercaseZip', 'bEnableSelfRegistration', 'bAllowEmptyLastName', 'iPersonNameStyle', 'iPersonInitialStyle', 'iProfilePictureListSize', 'sNewPersonNotificationRecipientIDs', 'IncludeDataInNewPersonNotifications', 'sGreeterCustomMsg1', 'sGreeterCustomMsg2', 'sInactiveClassification', 'sPersonListColumns'],
gettext('Enabled Features') => ['bEnabledFinance', 'bEnabledSundaySchool', 'bEnabledEvents', 'bEnabledCalendar', 'bEnabledFundraiser', 'bEnabledEmail', 'bEnabledMenuLinks'],
gettext('Map Settings') => ['sGeoCoderProvider', 'sGoogleMapsGeocodeKey', 'sGoogleMapsRenderKey', 'sBingMapKey', 'sGMapIcons', 'iMapZoom'],
gettext('Report Settings') => ['sQBDTSettings', 'leftX', 'incrementY', 'sTaxReport1', 'sTaxReport2', 'sTaxReport3', 'sTaxSigner', 'sReminder1', 'sReminderSigner', 'sReminderNoPledge', 'sReminderNoPayments', 'sConfirm1', 'sConfirm2', 'sConfirm3', 'sConfirm4', 'sConfirm5', 'sConfirm6', 'sDear', 'sConfirmSincerely', 'sConfirmSigner', 'sPledgeSummary1', 'sPledgeSummary2', 'sDirectoryDisclaimer1', 'sDirectoryDisclaimer2', 'bDirLetterHead', 'sZeroGivers', 'sZeroGivers2', 'sZeroGivers3', 'iPDFOutputType'],
Expand Down
112 changes: 46 additions & 66 deletions src/v2/templates/people/person-list.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,20 +158,27 @@ function emptyOrUnassignedJSON($stuff): string
<?php
}
?>
<td><?= $person->getId() ?></td>
<td><?= $person->getLastName()?></td>
<td><?= $person->getFirstName()?></td>
<td><?= $person->getAddress() ?></td>
<td><?= $person->getHomePhone() ?></td>
<td><?= $person->getCellPhone() ?></td>
<td><?= $person->getEmail() ?></td>
<td><?= emptyOrUnassigned($person->getGenderName()) ?></td>
<td><?= emptyOrUnassigned($person->getClassificationName()) ?></td>
<td><?= emptyOrUnassigned($person->getFamilyRoleName()) ?></td>
<td><?= emptyOrUnassignedJSON($person->getPropertiesString()) ?></td>
<td><?= emptyOrUnassignedJSON($person->getCustomFields($allPersonCustomFields, $CustomMapping, $CustomList, $option_name)) ?></td>
<td><?= emptyOrUnassignedJSON($person->getGroups()) ?></td>

<?php
$columns = json_decode(SystemConfig::getValue('sPersonListColumns'), null, 512, JSON_THROW_ON_ERROR);
foreach ($columns as $column) {
echo '<td>';
if ($column->displayFunction === 'getCustomFields') {
$columnData = [$person, $column->displayFunction]($allPersonCustomFields, $CustomMapping, $CustomList, $option_name);
} else {
$columnData = [$person, $column->displayFunction]();
}
if ($column->emptyOrUnassigned === 'true') {
if (is_array($columnData)) {
echo emptyOrUnassignedJSON($columnData);
} else {
echo emptyOrUnassigned($columnData);
}
} else {
echo $columnData;
}
echo '</td>';
}
}
//lets clean all the customs that don't have anyone associated.
foreach ($CustomList as $key => $value) {
Expand Down Expand Up @@ -201,62 +208,35 @@ function emptyOrUnassignedJSON($stuff): string

// setup datatables
'use strict';
var bVisible = parseInt("<?= SystemConfig::getValue('bHidePersonAddress') ? 0 : 1 ?>");

let dataTableConfig = {
deferRender: true,
search: { regex: true },
columns: [
{
title:i18next.t('Actions'),
},
{
title:i18next.t('Id'),
visible:false
},
{
title:i18next.t('Last Name'),
},
{
title:i18next.t('First Name'),
},
{
title:i18next.t('Address'),
visible:bVisible
},
{
title:i18next.t('Home Phone'),
},
{
title:i18next.t('Cell Phone'),
},
{
title:i18next.t('Email'),
},
{
title:i18next.t('Gender'),
},
{
title:i18next.t('Classification'),
},
{
title:i18next.t('Roles'),
},
{
title:i18next.t('Properties'),
visible:false
},
{
title:i18next.t('Custom'),
visible:false
},
{
title:i18next.t('Group'),
visible:false
<?php
$firstVisibleColumnId = PHP_INT_MAX;
$columnId = 0;
$columnIdMap = array();
$columns = json_decode(SystemConfig::getValue('sPersonListColumns'), null, 512, JSON_THROW_ON_ERROR);
foreach ($columns as $column) {
$columnId++;
$columnIdMap[$column->name] = $columnId;
$columnTitle = ['title' => "i18next.t('{$column->name}')"];
if ($column->visible === 'false') {
$columnTitle['visible'] = 'false';
} else {
if ($firstVisibleColumnId > $columnId) {
$firstVisibleColumnId = $columnId;
}
}
echo str_replace('"', '', json_encode($columnTitle)) . ",\n";
}
?>
],
// sortby name
order: [[ 2, "asc" ]]
// sort by first visible column
order: [[ <?php echo $firstVisibleColumnId ?> , "asc" ]]
}

$.extend(dataTableConfig, window.CRM.plugin.dataTable);
Expand Down Expand Up @@ -289,22 +269,22 @@ function emptyOrUnassignedJSON($stuff): string
});

$('.filter-Gender').on("change", function() {
filterColumn(8, $(this).select2('data'), true);
filterColumn(<?php echo $columnIdMap['Gender'] ?>, $(this).select2('data'), true);
});
$('.filter-Classification').on("change", function() {
filterColumn(9, $(this).select2('data'), true);
filterColumn(<?php echo $columnIdMap['Classification'] ?>, $(this).select2('data'), true);
});
$('.filter-Role').on("change", function() {
filterColumn(10, $(this).select2('data'), true);
filterColumn(<?php echo $columnIdMap['Role'] ?>, $(this).select2('data'), true);
});
$('.filter-Properties').on("change", function() {
filterColumn(11, $(this).select2('data'), false);
filterColumn(<?php echo $columnIdMap['Properties'] ?>, $(this).select2('data'), false);
});
$('.filter-Custom').on("change", function() {
filterColumn(12, $(this).select2('data'), false);
filterColumn(<?php echo $columnIdMap['Custom'] ?>, $(this).select2('data'), false);
});
$('.filter-Group').on("change", function() {
filterColumn(13, $(this).select2('data'), false);
filterColumn(<?php echo $columnIdMap['Group'] ?>, $(this).select2('data'), false);
});

function escapeRegExp(string) {
Expand Down

0 comments on commit 3e7c791

Please sign in to comment.