Skip to content

Commit

Permalink
Merge pull request #246 from Steinbeck-Lab/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
CS76 authored Sep 12, 2024
2 parents 8a35a45 + 5ba0554 commit 674b35a
Show file tree
Hide file tree
Showing 35 changed files with 1,477 additions and 491 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/release-please.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,5 @@ jobs:
with:
release-type: php
package-name: release-please-action
token: ${{ secrets.GITHUB_TOKEN }}
prerelease: true
token: ${{ secrets.RELEASE_PLEASE_TOKEN }}
prerelease: true
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,15 @@ class EditCollection extends EditRecord
{
protected static string $resource = CollectionResource::class;

protected function mutateFormDataBeforeCreate(array $data): array
{
if (! $data['image']) {
$data['image'] = $this->record->image;
}

return $data;
}

protected function getHeaderWidgets(): array
{
return [
Expand Down
21 changes: 2 additions & 19 deletions app/Filament/Dashboard/Resources/MoleculeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
use Filament\Tables\Columns\ImageColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Collection;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Cache;
use Illuminate\Support\Facades\Redirect;
use Illuminate\Support\HtmlString;
Expand Down Expand Up @@ -128,15 +127,7 @@ public static function table(Table $table): Table

$record->active = ! $record->active;

$reasons = json_decode($record->comment, true);
array_push($reasons, [
'changed_status_to' => $record['active'],
'changed_by' => Auth::user()->id,
'changed_at' => now(),
'reason' => $data['reason'],
'bulk_action' => false,
]);
$record->comment = json_encode($reasons);
$record->active ?: $record->comment = $data['reason'];

$record->save();
})
Expand All @@ -158,15 +149,7 @@ public static function table(Table $table): Table
foreach ($records as $record) {
$record->active = ! $record->active;

$reasons = json_decode($record->comment, true);
array_push($reasons, [
'changed_status_to' => $record['active'],
'changed_by' => Auth::user()->id,
'changed_at' => now(),
'reason' => $data['reason'],
'bulk_action' => true,
]);
$record->comment = json_encode($reasons);
$record->comment = $data['reason'];

$record->save();
}
Expand Down
189 changes: 139 additions & 50 deletions app/Filament/Dashboard/Resources/ReportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@

namespace App\Filament\Dashboard\Resources;

use App\Events\ReportStatusChanged;
use App\Filament\Dashboard\Resources\ReportResource\Pages;
use App\Filament\Dashboard\Resources\ReportResource\RelationManagers;
use App\Models\Citation;
use App\Models\Molecule;
use App\Models\Report;
use Archilex\AdvancedTables\Filters\AdvancedFilter;
use Filament\Forms\Components\Actions;
use Filament\Forms\Components\Actions\Action;
use Filament\Forms\Components\Grid;
use Filament\Forms\Components\KeyValue;
use Filament\Forms\Components\Select;
use Filament\Forms\Components\SpatieTagsInput;
Expand All @@ -16,10 +20,12 @@
use Filament\Forms\Form;
use Filament\Forms\Get;
use Filament\Resources\Resource;
use Filament\Support\Enums\VerticalAlignment;
use Filament\Tables;
use Filament\Tables\Columns\TextColumn;
use Filament\Tables\Table;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\HtmlString;
use Illuminate\Support\Str;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;

Expand All @@ -37,15 +43,65 @@ public static function form(Form $form): Form
{
return $form
->schema([
ToggleButtons::make('is_change')
->label('')
->live()
->default(false)
->options([
true => 'Request Changes to Data',
false => 'Report Synthetic Compound(s)',
Grid::make()
->schema([
ToggleButtons::make('is_change')
->label('')
->live()
->default(false)
->options([
false => 'Report Synthetic Compound(s)',
true => 'Request Changes to Data',
])
->inline()
->columnSpan(2),
Actions::make([
Action::make('approve')
->hidden(function (Get $get, string $operation) {
return ! auth()->user()->roles()->exists() || $get('status') == 'rejected' || $get('status') == 'approved' || $operation == 'create';
})
->form([
Textarea::make('reason'),
])
->action(function (array $data, Report $record, Molecule $molecule, $set): void {

$record['status'] = 'approved';
$record['reason'] = $data['reason'];
$record->save();

$set('status', 'rejected');

if ($record['mol_id_csv'] && ! $record['is_change']) {
$molecule_ids = explode(',', $record['mol_id_csv']);
$molecule = Molecule::whereIn('id', $molecule_ids)->get();
foreach ($molecule as $mol) {
$mol->active = false;
$mol->save();
}
}
}),
Action::make('reject')
->color('danger')
->hidden(function (Get $get, string $operation) {
return ! auth()->user()->roles()->exists() || $get('status') == 'rejected' || $get('status') == 'approved' || $operation == 'create';
})
->form([
Textarea::make('reason'),
])
->action(function (array $data, Report $record, $set): void {

$record['status'] = 'rejected';
$record['reason'] = $data['reason'];
$record->save();

$set('status', 'rejected');
}),
])
->verticalAlignment(VerticalAlignment::End)
->columnStart(4),
])
->inline(),
->columns(3),

Select::make('report_type')
->label('Choose')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Select what you want to report. Ex: Molecule, Citation, Collection, Organism.')
Expand All @@ -70,15 +126,25 @@ public static function form(Form $form): Form
return $get('is_change');
}),
KeyValue::make('suggested_changes')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Enter the property (in the left column) and suggested change (in the right column)')
->addActionLabel('Add property')
->keyLabel('Property')
->valueLabel('Suggested change')
->hidden(function (Get $get) {
return ! $get('is_change');
}),
TextInput::make('url')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Provide a link to the webpage that supports your claims.')
->label('URL'),
TextInput::make('doi')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Provide the DOI link to the resource you are reporting so as to help curators verify.')
->label('DOI')
->url()
->suffixAction(
fn (?string $state): Action => Action::make('visit')
->icon('heroicon-s-link')
->url(
$state,
shouldOpenInNewTab: true,
),
),
Select::make('collections')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Select the Collections you want to report. This will help our Curators in reviewing your report.')
->relationship('collections', 'title')
Expand All @@ -90,7 +156,7 @@ public static function form(Form $form): Form
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($operation != 'create') {
if ($get('collections') == []) {
return true;
}
Expand All @@ -117,7 +183,7 @@ public static function form(Form $form): Form
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($operation != 'create') {
if ($get('citations') == []) {
return true;
}
Expand All @@ -142,7 +208,7 @@ public static function form(Form $form): Form
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($operation != 'create') {
if ($get('organisms') == []) {
return true;
}
Expand All @@ -165,10 +231,8 @@ public static function form(Form $form): Form
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if (is_null($get('mol_id_csv'))) {
return true;
}
if ($operation != 'create') {
return true;
} elseif (! request()->has('compound_id') && $get('report_type') != 'molecule') {
return true;
}
Expand All @@ -178,22 +242,10 @@ public static function form(Form $form): Form
return true;
}
}),
SpatieTagsInput::make('tags')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Provide comma separated search terms that would help in finding your report when searched.')
->splitKeys(['Tab', ','])
->type('reports'),
Select::make('status')
->options([
'pending' => 'Pending',
'approved' => 'Approved',
'rejected' => 'Rejected',
])
->hidden(function () {
return ! auth()->user()->hasRole('curator');
})
->afterStateUpdated(function (?Report $record, ?string $state, ?string $old) {
ReportStatusChanged::dispatch($record, $state, $old);
}),
// SpatieTagsInput::make('tags')
// ->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Provide comma separated search terms that would help in finding your report when searched.')
// ->splitKeys(['Tab', ','])
// ->type('reports'),
Textarea::make('comment')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Provide your comments/observations on anything noteworthy in the Curation process.')
->hidden(function () {
Expand All @@ -209,26 +261,63 @@ public static function table(Table $table): Table
TextColumn::make('title')
->wrap()
->description(fn (Report $record): string => Str::of($record->evidence)->words(10)),
TextColumn::make('url')
->url(fn (Report $record) => $record->url)
->openUrlInNewTab(),
TextColumn::make('status')
->badge()
->color(function (Report $record) {
return match ($record->status) {
'pending' => 'info',
'approved' => 'success',
'rejected' => 'danger',
};
}),
TextColumn::make('comment')->wrap(),
Tables\Columns\TextColumn::make('name')->searchable()
->formatStateUsing(
fn (Report $record): HtmlString => new HtmlString("<strong>DOI:</strong> {$record->doi}")
)
->description(fn (Report $record): string => $record->comment ?? '')
->wrap(),
])
->defaultSort('created_at', 'desc')
->filters([
//
AdvancedFilter::make()
->includeColumns(),
])
->actions([
Tables\Actions\EditAction::make(),
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make()
->visible(function ($record) {
return auth()->user()->roles()->exists() && $record['status'] == 'submitted';
}),
Tables\Actions\Action::make('approve')
// ->button()
->hidden(function (Report $record) {
return ! auth()->user()->roles()->exists() || $record['status'] == 'draft' || $record['status'] == 'rejected' || $record['status'] == 'approved';
})
->form([
Textarea::make('reason'),
])
->action(function (array $data, Report $record, Molecule $molecule): void {

$record['status'] = 'approved';
$record['reason'] = $data['reason'];
$record->save();

if ($record['mol_id_csv'] && ! $record['is_change']) {
$molecule_ids = explode(',', $record['mol_id_csv']);
$molecule = Molecule::whereIn('id', $molecule_ids)->get();
foreach ($molecule as $mol) {
$mol->active = false;
$mol->save();
}
}
}),
Tables\Actions\Action::make('reject')
// ->button()
->color('danger')
->hidden(function (Report $record) {
return ! auth()->user()->roles()->exists() || $record['status'] == 'draft' || $record['status'] == 'rejected' || $record['status'] == 'approved';
})
->form([
Textarea::make('reason'),

])
->action(function (array $data, Report $record): void {

$record['status'] = 'rejected';
$record['reason'] = $data['reason'];
$record->save();
}),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function beforeCreate(): void
protected function mutateFormDataBeforeCreate(array $data): array
{
$data['user_id'] = auth()->id();
$data['status'] = 'pending';
$data['status'] = 'submitted';

return $data;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EditReport extends EditRecord
protected function getHeaderActions(): array
{
return [
Actions\DeleteAction::make(),
// Actions\DeleteAction::make(),
];
}
}
Loading

0 comments on commit 674b35a

Please sign in to comment.