Skip to content

Commit

Permalink
#83 files table update -- add the branches and concession to display …
Browse files Browse the repository at this point in the history
…in the table
  • Loading branch information
SaintAngeLs committed Jul 18, 2024
1 parent b170626 commit 6e7b5a1
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 33 deletions.
82 changes: 50 additions & 32 deletions infohub2024/app/Http/Controllers/Admin/Menu/MenuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,12 @@ public function indexFiles()
public function create()
{
$menuItemsToSelect = $this->menuItemService->getMenuItemsToSelect();
$users = User::where('active', 1)->get();
return view('admin.menu.create', compact('menuItemsToSelect', 'users'));
$usersData = $this->menuItemService->getUsersWithOwners();

return view('admin.menu.create', array_merge(['menuItemsToSelect' => $menuItemsToSelect], $usersData));
}


public function edit(MenuItem $menuItem)
{
$menuItemsToSelect = $this->menuItemService->getMenuItemsToSelect($menuItem);
Expand Down Expand Up @@ -181,34 +183,41 @@ public function getMenuItemPermissions($groupId = null)


protected function formatForJsTree($menuItems)
{
$formatted = [];
foreach ($menuItems as $item) {
$status = $item->status ? 'Aktywny' : 'Nieaktywny';
$ownerNames = $item->owners->pluck('name')->implode('<br>');
$ownerNameDisplay = !empty($ownerNames) ? $ownerNames : 'N/A';
$visibilityTime = $item->start && $item->end
? $item->start->format('Y-m-d') . ' do ' . $item->end->format('Y-m-d')
: 'N/A';

$nodeContent = <<<HTML
<span class='js-tree-node-content' data-node-id="{$item->id}">
<span class='node-name'>{$item->name}</span>
<span class='node-details-status'>($status)</span>
<span class='node-details-ownerName'>{$ownerNameDisplay}</span>
<span class='node-details-visibilityTime'>{$visibilityTime}</span>
</span>
HTML;

$formattedItem = [
'id' => $item->id,
'text' => $nodeContent,
'children' => $item->children->isEmpty() ? [] : $this->formatForJsTree($item->children),
];
$formatted[] = $formattedItem;
}
return $formatted;
{
$formatted = [];
foreach ($menuItems as $item) {
$status = $item->status ? 'Aktywny' : 'Nieaktywny';

$ownerNames = $item->owners->map(function($owner) {
$userGroup = $owner->usersGroup ? $owner->usersGroup->name : 'N/A';
$branch = $owner->branch ? $owner->branch->name : 'N/A';
return "{$owner->name} {$owner->surname} ({$userGroup} - {$branch})";
})->implode('<br>');

$ownerNameDisplay = !empty($ownerNames) ? $ownerNames : 'N/A';
$visibilityTime = $item->start && $item->end
? $item->start->format('d.m.Y') . ' do ' . $item->end->format('d.m.Y')
: 'N/A';

$nodeContent = <<<HTML
<span class='js-tree-node-content' data-node-id="{$item->id}">
<span class='node-name'>{$item->name}</span>
<span class='node-details-status'>($status)</span>
<span class='node-details-ownerName'>{$ownerNameDisplay}</span>
<span class='node-details-visibilityTime'>{$visibilityTime}</span>
</span>
HTML;

$formattedItem = [
'id' => $item->id,
'text' => $nodeContent,
'children' => $item->children->isEmpty() ? [] : $this->formatForJsTree($item->children),
];
$formatted[] = $formattedItem;
}
return $formatted;
}


public function formatForJsTreeGroupPermissions($menuItems, $groupId = null)
{
Expand Down Expand Up @@ -344,11 +353,18 @@ protected function formatMenuItemsWithFilesForTable($menuItems)
$formatted = [];
foreach ($menuItems as $item) {
$status = $item->status ? 'Aktywny' : 'Nieaktywny';
$ownerNames = $item->owners->pluck('name')->implode(',');
$ownerNameDisplay = !empty($ownerNames) ? $ownerNames : 'N/A';

$ownerDetails = $item->owners->map(function($owner) {
$userGroup = $owner->usersGroup ? $owner->usersGroup->name : 'N/A';
$branch = $owner->branch ? $owner->branch->name : 'N/A';
return "{$owner->name} {$owner->surname} ({$userGroup} - {$branch})";
})->implode('<br>');

$ownerDisplay = !empty($ownerDetails) ? $ownerDetails : 'N/A';
$visibilityTime = $item->start && $item->end
? $item->start->format('Y-m-d') . ' do ' . $item->end->format('Y-m-d')
: 'N/A';

$files = $item->files;
$fileDetails = [];
foreach ($files as $file) {
Expand All @@ -369,11 +385,12 @@ protected function formatMenuItemsWithFilesForTable($menuItems)
'id' => $file->id,
];
}

$formatted[] = [
'id' => $item->id,
'name' => $item->name,
'status' => $status,
'owners' => $ownerNameDisplay,
'owners' => $ownerDisplay,
'visibility' => $visibilityTime,
'files' => $fileDetails,
'children' => $item->children->isEmpty() ? [] : $this->formatMenuItemsWithFilesForTable($item->children),
Expand All @@ -382,6 +399,7 @@ protected function formatMenuItemsWithFilesForTable($menuItems)
return $formatted;
}


protected function formatMenuItemsForPermissionsTable($menuItems, $permissions)
{
$formatted = [];
Expand Down
3 changes: 2 additions & 1 deletion infohub2024/app/Services/MenuItemService.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,13 @@ public function getMenuItemsToSelect(MenuItem $menuItem = null)
public function getUsersWithOwners(MenuItem $menuItem = null)
{
$users = User::where('active', 1)->get();
$currentOwners = optional($menuItem)->owners->pluck('id')->toArray() ?? [];
$currentOwners = $menuItem ? $menuItem->owners->pluck('id')->toArray() : [];
$nonOwners = $users->whereNotIn('id', $currentOwners);

return compact('users', 'currentOwners', 'nonOwners');
}


public function updateMenuItemOwners(MenuItem $menuItem, $ownerIds)
{
$ownerIds = json_decode($ownerIds, true);
Expand Down

0 comments on commit 6e7b5a1

Please sign in to comment.