@foreach ($formData as $formLabel => $fields)
@if($fields)
@php
$showSection = false;
foreach ($fields as $field) {
// For clients, check both visibility and is_visible_to_client
if ($isClientView) {
if ($field['visibility'] === true && ($field['is_visible_to_client'] ?? false)) {
$showSection = true;
break;
}
} else {
// For non-clients, just check visibility
if ($field['visibility'] === true) {
$showSection = true;
break;
}
}
}
@endphp
{{ $formLabel }}
@foreach ($fields as $field)
@php
// For clients, hide field if not visible to client
$hideField = !$field['visibility'];
if ($isClientView && !($field['is_visible_to_client'] ?? false)) {
$hideField = true;
}
@endphp
@foreach ($sublists as $sublist)
@php
// Assuming width is given in number of columns
$colSpan = $sublist['width'];
@endphp
{{-- /********************** UPDATE HERE *********************/ --}}
{{ $sublist['label'] }}
@if($sublist['label'] != 'Documents' && $sublist['label'] != 'Gantt' && $sublist['label'] != 'Comments' && $sublist['label'] != 'Forms')
@if(!empty($sublist['no_relationship']))
{{-- No relationship field exists between this sublist type and the parent record type --}}
No relationship established between
{{ $sublist['label'] }}
and
{{ $recordType->title }}.
Create a record field on {{ $sublist['label'] }} that references {{ $recordType->title }}.
@if($formSublists)
@foreach ($formSublists as $index => $sublist)
@if($sublist['label'] != 'Documents' && $sublist['label'] != 'Gantt' && $sublist['label'] != 'Comments' && $sublist['label'] != 'Roles' && $sublist['label'] != 'Forms' && $sublist['label'] != 'Kanban')
@if(!empty($sublist['no_relationship']))
{{-- No relationship field exists between this sublist type and the parent record type --}}
No relationship established between
{{ $sublist['label'] }}
and
{{ $recordType->title }}.
Create a record field on {{ $sublist['label'] }} that references {{ $recordType->title }}.
@elseif( $sublist['label'] != 'Assignee' || $sublist['label'] == 'Assignee' && !$record->isparent)
@if (auth()->user()->hasPermissionForRecordType('can_read', $sublist['recordtypestring']))
@php
$canViewTable = true;
$tableExistsButRestricted = false;
$useReactTable = true;
// Get the sublist record type — support both numeric ID and string scriptid/recordType
$sublistRecordType = is_numeric($sublist['recordtype'])
? \Domain\RecordTypes\Models\RecordType::find((int) $sublist['recordtype'])
: \Domain\RecordTypes\Models\RecordType::where('scriptid', $sublist['recordtype'])->orWhere('recordType', $sublist['recordtype'])->first();
// Check if this should use React Table
// React Table is disabled by default - enable only for specific record types as needed
// if ($sublistRecordType && in_array($sublistRecordType->recordType, ['projecttask'])) {
// $useReactTable = true;
// }
if ($isClientView && !empty($sublist['table'])) {
$clientRole = auth()->user()->currentRole;
// First check if table exists at all
$tableExists = \Domain\TableBuilders\Models\TableBuilder::where('id', $sublist['table'])->exists();
if ($tableExists) {
// Table exists, check if user has access
$tableBuilder = \Domain\TableBuilders\Models\TableBuilder::where('id', $sublist['table'])
->where(function($query) use ($clientRole) {
$query->whereDoesntHave('roles')
->orWhereHas('roles', function($roleQuery) use ($clientRole) {
$roleQuery->where('role_id', $clientRole->id);
});
})
->first();
if ($tableBuilder === null) {
// Table exists but user doesn't have access
$canViewTable = false;
$tableExistsButRestricted = true;
}
}
// If table doesn't exist, let it fall through - BuildTableData will use fallback
}
// Get all table builders for this sublist record type that the current user's role can access.
// This mirrors the query in RecordController and is required to populate the TableBuilderSelector dropdown.
$sublistUserRole = auth()->user()->currentRole->id;
$sublistAccessibleTableBuilders = \Domain\TableBuilders\Models\TableBuilder::where('recordtype', $sublistRecordType->id)
->where(function ($q) use ($sublistUserRole) {
$q->whereDoesntHave('roles')
->orWhereHas('roles', function ($rq) use ($sublistUserRole) {
$rq->where('role_id', $sublistUserRole);
});
})
->orderBy('isprimary', 'desc')
->orderBy('id', 'asc')
->get(['id', 'title', 'isprimary'])
->map(fn ($b) => [
'id' => $b->id,
'title' => $b->title,
'is_primary' => $b->isprimary,
])
->values()
->toArray();
// Resolve the effective table builder ID for the initial render.
// Priority: (1) explicitly configured on the sublist definition,
// (2) first accessible builder for this role (ordered primary-first).
// Without this, BuildTableData falls back to isprimary=true which may not
// match what TableBuilderSelector shows, leaving the table showing defaults.
$effectiveSublistTableBuilderId = !empty($sublist['table'])
? (int) $sublist['table']
: (isset($sublistAccessibleTableBuilders[0]) ? $sublistAccessibleTableBuilders[0]['id'] : null);
// Build table data for React Table if needed and accessible
$sublistTableData = null;
if ($useReactTable && ($canViewTable || !$tableExistsButRestricted)) {
$sublistTableData = \Domain\TableBuilders\Actions\BuildTableData::execute(
$sublistRecordType,
$effectiveSublistTableBuilderId,
[],
false,
null,
$sublist['filters'] ?? null,
true,
null,
$isClientView
);
// Prepare data for JSON encoding
if ($sublistTableData && isset($sublistTableData['tableFields'])) {
$sublistTableData['tableFields'] = collect($sublistTableData['tableFields'])->map(function ($field) {
if (isset($field['listoptions']) && $field['listoptions'] instanceof \Illuminate\Support\Collection) {
$field['listoptions'] = $field['listoptions']->toArray();
}
return $field;
})->toArray();
}
if ($sublistTableData && isset($sublistTableData['lists'])) {
$sublistTableData['lists'] = collect($sublistTableData['lists'])->map(function ($list) {
if (is_string($list)) {
return json_decode($list, true);
}
return $list instanceof \Illuminate\Support\Collection ? $list->toArray() : $list;
})->toArray();
}
if ($sublistTableData && isset($sublistTableData['filterbuilder'])) {
$sublistTableData['filterbuilder'] = collect($sublistTableData['filterbuilder'])->map(function ($filter) {
if (isset($filter['options']) && $filter['options'] instanceof \Illuminate\Support\Collection) {
$filter['options'] = $filter['options']->toArray();
}
return $filter;
})->toArray();
}
}
@endphp
@if($canViewTable || !$tableExistsButRestricted)
@if($useReactTable && $sublistTableData)
{{-- Use React Table Component --}}