Skip to content

Commit

Permalink
feat: now only the fields requested for changes are available and the…
Browse files Browse the repository at this point in the history
… rest are disabled in edit page
  • Loading branch information
sriramkanakam87 committed Oct 2, 2024
1 parent b28d1fa commit 206dc4b
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 5 deletions.
34 changes: 32 additions & 2 deletions app/Filament/Dashboard/Resources/ReportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,17 @@ public static function form(Form $form): Form

return $geo_locations;
})
->disabled(function (Get $get) {
return ! $get('show_geo_location_existing');
})
->columnSpan(4),
TagsInput::make('new_geo_locations')
->label('New')
->separator(',')
->splitKeys([','])
->disabled(function (Get $get) {
return ! $get('show_geo_location_new');
})
->columnSpan(4),
])
->columns(9),
Expand All @@ -191,11 +197,17 @@ public static function form(Form $form): Form

return $synonyms;
})
->disabled(function (Get $get) {
return ! $get('show_synonym_existing');
})
->columnSpan(4),
TagsInput::make('new_synonyms')
->label('New')
->separator(',')
->splitKeys([','])
->disabled(function (Get $get) {
return ! $get('show_synonym_new');
})
->columnSpan(4),
])
->columns(9),
Expand All @@ -214,6 +226,9 @@ public static function form(Form $form): Form
return self::$molecule->name;
}
})
->disabled(function (Get $get) {
return ! $get('show_name_change');
})
->columnSpan(4),
])
->columns(9),
Expand All @@ -234,11 +249,17 @@ public static function form(Form $form): Form
return self::$molecule->cas;
}
})
->disabled(function (Get $get) {
return ! $get('show_cas_existing');
})
->columnSpan(4),
TagsInput::make('new_cas')
->label('New')
->separator(',')
->splitKeys([','])
->disabled(function (Get $get) {
return ! $get('show_cas_new');
})
->columnSpan(4),
])
->columns(9),
Expand All @@ -262,8 +283,8 @@ public static function form(Form $form): Form
return self::$molecule->organisms->pluck('name', 'id')->toArray();
}
})
->hidden(function (Get $get) {
return $get('operation') == 'add';
->disabled(function (Get $get) {
return ! $get('show_organism_existing');
})
->columnSpan(9),
])
Expand All @@ -285,6 +306,9 @@ public static function form(Form $form): Form
->reorderable(false)
->addActionLabel('Add New Organism')
->defaultItems(0)
->disabled(function (Get $get) {
return ! $get('show_organism_new');
})
->columns(9),

]),
Expand All @@ -307,6 +331,9 @@ public static function form(Form $form): Form
return self::$molecule->citations->where('title', '!=', null)->pluck('title', 'id')->toArray();
}
})
->disabled(function (Get $get) {
return ! $get('show_citation_existing');
})
->columnSpan(9),
])
->columns(9),
Expand All @@ -325,6 +352,9 @@ public static function form(Form $form): Form
->reorderable(false)
->addActionLabel('Add New Citation')
->defaultItems(0)
->disabled(function (Get $get) {
return ! $get('show_citation_new');
})
->columns(9),

]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,12 @@ protected function mutateFormDataBeforeCreate(array $data): array

$suggested_changes['new_citations'] = $data['new_citations'];

$suggested_changes['overall_changes'] = getOverallChanges($data);

// seperate copy for Curators
$suggested_changes['curator'] = $suggested_changes;

// Overall Changes suggested
$suggested_changes['overall_changes'] = getOverallChanges($data);

$data['suggested_changes'] = $suggested_changes;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,32 @@ class EditReport extends EditRecord
protected function mutateFormDataBeforeFill(array $data): array
{
if ($data['is_change'] == true) {
// initiate the flags to show only the fields that need to be shown
$data['show_geo_location_existing'] = $data['suggested_changes']['overall_changes']['geo_location_changes']['delete'] ? true : false;
if (array_key_exists('geo_location_changes', $data['suggested_changes']['overall_changes'])) {
$data['show_geo_location_existing'] = $data['suggested_changes']['overall_changes']['geo_location_changes']['delete'] ? true : false;
$data['show_geo_location_new'] = $data['suggested_changes']['overall_changes']['geo_location_changes']['add'] ? true : false;
}
if (array_key_exists('synonym_changes', $data['suggested_changes']['overall_changes'])) {
$data['show_synonym_existing'] = $data['suggested_changes']['overall_changes']['synonym_changes']['delete'] ? true : false;
$data['show_synonym_new'] = $data['suggested_changes']['overall_changes']['synonym_changes']['add'] ? true : false;
}
if (array_key_exists('name_change', $data['suggested_changes']['overall_changes'])) {
$data['show_name_change'] = $data['suggested_changes']['overall_changes']['name_change'] ? true : false;
}
if (array_key_exists('cas_changes', $data['suggested_changes']['overall_changes'])) {
$data['show_cas_existing'] = $data['suggested_changes']['overall_changes']['cas_changes']['delete'] ? true : false;
$data['show_cas_new'] = $data['suggested_changes']['overall_changes']['cas_changes']['add'] ? true : false;
}
if (array_key_exists('organism_changes', $data['suggested_changes']['overall_changes'])) {
$data['show_organism_existing'] = $data['suggested_changes']['overall_changes']['organism_changes']['delete'] ? true : false;
$data['show_organism_new'] = $data['suggested_changes']['overall_changes']['organism_changes']['add'] ? true : false;
}
if (array_key_exists('citation_changes', $data['suggested_changes']['overall_changes'])) {
$data['show_citation_existing'] = $data['suggested_changes']['overall_changes']['citation_changes']['delete'] ? true : false;
$data['show_citation_new'] = $data['suggested_changes']['overall_changes']['citation_changes']['add'] ? true : false;
}

$curators_copy_changes = $data['suggested_changes']['curator'];
$data['existing_geo_locations'] = $curators_copy_changes['existing_geo_locations'];
$data['new_geo_locations'] = $curators_copy_changes['new_geo_locations'];
Expand Down Expand Up @@ -70,7 +96,6 @@ protected function mutateFormDataBeforeSave(array $data): array
$data['suggested_changes']['curator']['approve_existing_citations'] = $data['approve_existing_citations'];

$data['suggested_changes']['curator']['new_citations'] = $data['new_citations'];

}

return $data;
Expand Down

0 comments on commit 206dc4b

Please sign in to comment.