Skip to content

Commit

Permalink
feat: update test, setup styleguide, refactor getProfilesByGroupOrder…
Browse files Browse the repository at this point in the history
… to allow for consistent input for group_id while allowing for sites that used commas instead of pipe
  • Loading branch information
Fw7424 committed Dec 3, 2024
1 parent ac05fcb commit 02ff69c
Show file tree
Hide file tree
Showing 14 changed files with 153 additions and 98 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/ContactTableController.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ public function index(Request $request): View
// Determine what site to pull profiles from
$site_id = $this->profile->getSiteID($request->data['base']);

$profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.profile_group_id'));
$profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.group_id'));

// show table of contents if custom field 'table_of_contents' is not set to 'hide'
if (isset($request->data['base']['data']['table_of_contents']) && $request->data['base']['data']['table_of_contents'] === 'hide') {
if (config('profile.table_of_contents') === 'hide') {
$profiles['anchors'] = [];
}

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/DirectoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function index(Request $request): View
$site_id = $this->profile->getSiteID($request->data['base']);

if (!empty($request->data['base']['data']['profile_group_id'])) {
$profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.profile_group_id'));
$profiles = $this->profile->getProfilesByGroupOrder($site_id, config('profile.group_id'));
} else {
$profiles = $this->profile->getProfilesByGroup($site_id);
}
Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/ProfileController.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function index(Request $request): View
$site_id = $this->profile->getSiteID($request->data['base']);

// Determine if we are forcing the profiles from custom page data
$forced_profile_group_id = config('profile.profile_group_id');
$forced_profile_group_id = config('profile.group_id');

// Get the groups for the dropdown
$dropdown_groups = $this->profile->getDropdownOfGroups($site_id);
Expand Down
28 changes: 8 additions & 20 deletions app/Repositories/PeopleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function getProfilesByGroupOrder($site_id, $groups)
{
$profile_listing = $this->getProfiles($site_id);

$group_order = explode(',', $groups);
$group_order = preg_split('/[\s,|]+/', $groups);

$profiles['profiles'] = [];

Expand Down Expand Up @@ -193,7 +193,7 @@ public function getDropdownOfGroups(int $site_id): array
// Filter down the groups based on the parent group from the config
$profile_groups['data'] = collect($profile_groups['data'])
->filter(function ($item) {
return (int)$item['parent_id'] === config('profile.profile_parent_group_id');
return (int)$item['parent_id'] === config('profile.parent_group_id');
})
->toArray();

Expand Down Expand Up @@ -386,7 +386,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host =
|| $referer == $scheme.'://'.$host.$uri
|| strpos($referer, $host) === false
) {
return config('profile.profile_default_back_url');
return config('profile.default_back_url');
}

return $referer;
Expand All @@ -397,7 +397,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host =
*/
public function getSiteID($data)
{
return !empty(config('profile.profile_site_id')) ? config('profile.profile_site_id') : $data['site']['people']['site_id'];
return !empty(config('profile.site_id')) ? config('profile.site_id') : $data['site']['people']['site_id'];
}

/**
Expand All @@ -418,32 +418,20 @@ public function parseProfileConfig(array $data): void
if (Str::startsWith($value, '{')) {
$profile_config = json_decode($value, true);

if (!empty($profile_config['site_id'])) {
Config::set('profile.profile_site_id', $profile_config['site_id']);
}

if (!empty($profile_config['group_id'])) {
Config::set('profile.profile_group_id', $profile_config['group_id']);
}

if (!empty($profile_config['parent_group_id'])) {
Config::set('profile.profile_parent_group_id', $profile_config['parent_group_id']);
}

if (!empty($profile_config['default_back_url'])) {
Config::set('profile.profile_default_back_url', $profile_config['default_back_url']);
foreach ($profile_config as $key => $value) {
Config::set('profile.'.$key, $value);
}
}
}

// legacy support for profile_group_id
if (!empty($data['data']['profile_group_id'])) {
Config::set('profile.profile_group_id', $data['data']['profile_group_id']);
Config::set('profile.group_id', $data['data']['profile_group_id']);
}

// legacy support for profile_site_id
if (!empty($data['data']['profile_site_id'])) {
Config::set('profile.profile_site_id', $data['data']['profile_site_id']);
Config::set('profile.site_id', $data['data']['profile_site_id']);
}
}
}
28 changes: 8 additions & 20 deletions app/Repositories/ProfileRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function getProfilesByGroupOrder($site_id, $groups)
{
$profile_listing = $this->getProfiles($site_id);

$group_order = explode('|', $groups);
$group_order = preg_split('/[\s,|]+/', $groups);

$profiles = [];

Expand Down Expand Up @@ -196,7 +196,7 @@ public function getDropdownOfGroups(int $site_id): array
// Filter down the groups based on the parent group from the config
$profile_groups['results'] = collect($profile_groups['results'])
->filter(function ($item) {
return (int) $item['parent_id'] === config('profile.profile_parent_group_id');
return (int) $item['parent_id'] === config('profile.parent_group_id');
})
->toArray();

Expand Down Expand Up @@ -368,7 +368,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host =
|| $referer == $scheme.'://'.$host.$uri
|| strpos($referer, $host) === false
) {
return config('profile.profile_default_back_url');
return config('profile.default_back_url');
}

return $referer;
Expand All @@ -379,7 +379,7 @@ public function getBackToProfileListUrl($referer = null, $scheme = null, $host =
*/
public function getSiteID($data)
{
return !empty(config('profile.profile_site_id')) ? config('profile.profile_site_id') : $data['site']['id'];
return !empty(config('profile.site_id')) ? config('profile.site_id') : $data['site']['id'];
}

/**
Expand All @@ -400,32 +400,20 @@ public function parseProfileConfig(array $data): void
if (Str::startsWith($value, '{')) {
$profile_config = json_decode($value, true);

if (!empty($profile_config['site_id'])) {
Config::set('profile.profile_site_id', $profile_config['site_id']);
}

if (!empty($profile_config['group_id'])) {
Config::set('profile.profile_group_id', $profile_config['group_id']);
}

if (!empty($profile_config['parent_group_id'])) {
Config::set('profile.profile_parent_group_id', $profile_config['parent_group_id']);
}

if (!empty($profile_config['default_back_url'])) {
Config::set('profile.profile_default_back_url', $profile_config['default_back_url']);
foreach ($profile_config as $key => $value) {
Config::set('profile.'.$key, $value);
}
}
}

// legacy support for profile_group_id
if (!empty($data['data']['profile_group_id'])) {
Config::set('profile.profile_group_id', $data['data']['profile_group_id']);
Config::set('profile.group_id', $data['data']['profile_group_id']);
}

// legacy support for profile_site_id
if (!empty($data['data']['profile_site_id'])) {
Config::set('profile.profile_site_id', $data['data']['profile_site_id']);
Config::set('profile.site_id', $data['data']['profile_site_id']);
}
}
}
8 changes: 4 additions & 4 deletions config/profile.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
| "Return to Listing" link.
|
*/
'profile_default_back_url' => '/profiles',
'default_back_url' => '/profiles',

/*
|--------------------------------------------------------------------------
Expand All @@ -22,7 +22,7 @@
| groups are added to the root then leave this value as 0.
|
*/
'profile_parent_group_id' => 0,
'parent_group_id' => 0,

/*
|--------------------------------------------------------------------------
Expand All @@ -47,7 +47,7 @@
| This value is a pipe delimited string of group ids.
|
*/
'profile_group_id' => null,
'group_id' => null,

/*
|--------------------------------------------------------------------------
Expand All @@ -59,7 +59,7 @@
| this value as null.
|
*/
'profile_site_id' => null,
'site_id' => null,

/*
|--------------------------------------------------------------------------
Expand Down
4 changes: 4 additions & 0 deletions resources/views/profile-listing.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

@section('content')
@include('components.page-title', ['title' => $base['page']['title']])

<div class="content">
{!! $base['page']['content']['main'] !!}
</div>

@if($hide_filtering == false)
<form name="departments" method="get" class="filter formy mb-6">
Expand Down
31 changes: 25 additions & 6 deletions styleguide/Pages/ContactTables.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,31 @@ public function getPageData()
'controller' => 'ContactTableController',
'title' => 'Contact tables',
'id' => 101113,
'content' => ['main' => '<p>In order to choose which groups show:</p>
<ol>
<li>Add a custom field named "profile_group_id"</li>
<li>Add in the IDs of the groups separated by the "," character</li>
<li>Groups will be displayed in the order they are entered in the custom field</li>
</ol>'],
'content' => ['main' => '<p>In order to choose which groups show, "group_id" is required. Groups will be displayed in the order they are entered in the custom field</p>
<table class="mt-2">
<thead>
<tr>
<th>Page field</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><pre class="w-full">profile_data</pre></td>
<td>
<pre class="w-full" tabindex="0">
{
"site_id":000000,
"group_id":"1234|5678",
"parent_group_id":"1234",
"table_of_contents":"hide",
"default_back_url":"/profiles/",
}
</pre>
</td>
</tr>
</tbody>
</table>'],
],
]);
}
Expand Down
35 changes: 27 additions & 8 deletions styleguide/Pages/ContactTablesNoTOC.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,34 @@ public function getPageData()
'controller' => 'ContactTableController',
'title' => 'Contact tables, no table of contents',
'id' => 101114,
'content' => ['main' => '<p>In order to choose which groups show:</p>
<ol>
<li>Add a custom field named "profile_group_id"</li>
<li>Add in the IDs of the groups separated by the "," character</li>
<li>Groups will be displayed in the order they are entered in the custom field</li>
</ol>
<p>In order to hide the table of contents:</p>
'content' => ['main' => '<p>In order to choose which groups show, "group_id" is required. Groups will be displayed in the order they are entered in the custom field</p>
<table class="mt-2">
<thead>
<tr>
<th>Page field</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><pre class="w-full">profile_data</pre></td>
<td>
<pre class="w-full" tabindex="0">
{
"site_id":000000,
"group_id":"1234|5678",
"parent_group_id":"1234",
"table_of_contents":"hide",
"default_back_url":"/profiles/",
}
</pre>
</td>
</tr>
</tbody>
</table>
<p>In order to hide the table of contents:</p>
<ol>
<li>Add a custom field to the page named "table_of_contents"</li>
<li>Use variable named "table_of_contents"</li>
<li>Set the value to "hide"</li>
</ol>'],
],
Expand Down
34 changes: 25 additions & 9 deletions styleguide/Pages/DirectoryOrdered.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,35 @@ public function getPageData()
'site_id' => 1,
],
],
'data' => [
'profile_group_id' => '0,1',
],
'page' => [
'controller' => 'DirectoryController',
'title' => 'Directory ordered',
'id' => 101108,
'content' => ['main' => '<p>In order to choose which groups show:</p>
<ol>
<li>Add a custom field named "profile_group_id"</li>
<li>Add in the IDs of the groups separated by the "," character</li>
<li>Groups will be displayed in the order they are entered in the custom field</li>
</ol>'],
'content' => ['main' => '<p>In order to choose which groups show, "group_id" is required. Groups will be displayed in the order they are entered in the custom field</p>
<table class="mt-2">
<thead>
<tr>
<th>Page field</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><pre class="w-full">profile_data</pre></td>
<td>
<pre class="w-full" tabindex="0">
{
"site_id":000000,
"group_id":"1234|5678",
"parent_group_id":"1234",
"table_of_contents":"hide",
"default_back_url":"/profiles/",
}
</pre>
</td>
</tr>
</tbody>
</table>'],
],
]);
}
Expand Down
28 changes: 28 additions & 0 deletions styleguide/Pages/Profiles.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ public function getPageData()
'controller' => 'ProfileController',
'title' => 'Profile listing',
'id' => 101105,
'content' => [
'main' => '<p>Profiles are configurable with in the CMS page custom field. Using a custom field named "profile_data".</p>
<table class="mt-2">
<thead>
<tr>
<th>Page field</th>
<th>Data</th>
</tr>
</thead>
<tbody>
<tr>
<td><pre class="w-full">profile_data</pre></td>
<td>
<pre class="w-full" tabindex="0">
{
"site_id":000000,
"group_id":"1234|5678",
"parent_group_id":"1234",
"table_of_contents":"hide",
"default_back_url":"/profiles/",
}
</pre>
</td>
</tr>
</tbody>
</table>',
],
],
]);
}
Expand Down
8 changes: 0 additions & 8 deletions styleguide/Repositories/PeopleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,4 @@ public function sortGroupsByDisplayOrder($grouped, $groups)
// There is no need to sort the groups in the styleguide since the order is random
return $grouped;
}

/**
* {@inheritdoc}
*/
public function parseProfileConfig(array $data): void
{
// There is no need to parse the profile config in the styleguide
}
}
Loading

0 comments on commit 02ff69c

Please sign in to comment.