Skip to content

Commit

Permalink
feat: now users can suggest changes to the properties of molecules, c…
Browse files Browse the repository at this point in the history
…itations, collections and organisms
  • Loading branch information
sriramkanakam87 committed Aug 12, 2024
1 parent b0b86dc commit 313b736
Show file tree
Hide file tree
Showing 6 changed files with 101 additions and 23 deletions.
60 changes: 49 additions & 11 deletions app/Filament/Dashboard/Resources/ReportResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Str;
use Tapp\FilamentAuditing\RelationManagers\AuditsRelationManager;
use Filament\Forms\Components\KeyValue;
use Filament\Forms\Components\Toggle;

class ReportResource extends Resource
{
Expand All @@ -35,18 +37,24 @@ public static function form(Form $form): Form
{
return $form
->schema([
Toggle::make('is_change')
->live()
->label(function ($state) {
if ($state == true) {
return 'Request changes to data';
} else {
return 'Report false data';
}
}),
Select::make('report_type')
->label('You want to report:')
->label('Choose')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Select what you want to report. Ex: Molecule, Citation, Collection, Organism.')
->live()
->options([
'molecule' => 'Molecule',
'citation' => 'Citation',
'collection' => 'Collection',
'organism' => 'Organism',
])
->options(function () {
return getReportTypes();
})
->hidden(function (string $operation) {
if ($operation == 'create' && (! request()->has('collection_uuid') && ! request()->has('citation_id') && ! request()->has('compound_id') && ! request()->has('organism_id'))) {
if ($operation == 'create' ) {
return false;
} else {
return true;
Expand All @@ -57,7 +65,17 @@ public static function form(Form $form): Form
->required(),
Textarea::make('evidence')
->hintIcon('heroicon-m-question-mark-circle', tooltip: 'Please provide Evidence/Comment to support your claims in this report. This will help our Curators in reviewing your report.')
->label('Evidence/Comment'),
->label('Evidence/Comment')
->hidden(function (Get $get) {
return $get('is_change');
}),
KeyValue::make('suggested_changes')
->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'),
Expand All @@ -66,6 +84,11 @@ public static function form(Form $form): Form
->relationship('collections', 'title')
->multiple()
->preload()
->required(function (Get $get) {
if ($get('report_type') == 'collection') {
return true;
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($get('collections') == []) {
Expand All @@ -88,6 +111,11 @@ public static function form(Form $form): Form
return Citation::whereNotNull('title')->pluck('title', 'id');
})
->multiple()
->required(function (Get $get) {
if ($get('report_type') == 'citation') {
return true;
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($get('citations') == []) {
Expand All @@ -108,6 +136,11 @@ public static function form(Form $form): Form
->relationship('organisms', 'name')
->multiple()
->searchable()
->required(function (Get $get) {
if ($get('report_type') == 'organism') {
return true;
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if ($get('organisms') == []) {
Expand All @@ -126,6 +159,11 @@ public static function form(Form $form): Form
Textarea::make('mol_id_csv')
->label('Molecules')
->placeholder('Enter the Identifiers separated by commas')
->required(function (Get $get) {
if ($get('report_type') == 'molecule') {
return true;
}
})
->hidden(function (Get $get, string $operation) {
if ($operation == 'edit' || $operation == 'view') {
if (is_null($get('mol_id_csv'))) {
Expand Down Expand Up @@ -169,9 +207,9 @@ public static function table(Table $table): Table
return $table
->columns([
TextColumn::make('title')
->description(fn (Report $record): string => Str::of($record->evidence)->words(10)),
->description(fn(Report $record): string => Str::of($record->evidence)->words(10)),
TextColumn::make('url')
->url(fn (Report $record) => $record->url)
->url(fn(Report $record) => $record->url)
->openUrlInNewTab(),
TextColumn::make('status')
->badge()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,27 @@ class CreateReport extends CreateRecord
protected function afterFill(): void
{
$request = request();
if($request->type == 'change'){
$this->data['is_change'] = true;
}
if ($request->has('collection_uuid')) {
$collection = Collection::where('uuid', $request->collection_uuid)->get();
$id = $collection[0]->id;
array_push($this->data['collections'], $id);
$this->data['report_type'] = 'collection';
} elseif ($request->has('citation_id')) {
$citation = Citation::where('id', $request->citation_id)->get();
$id = $citation[0]->id;
array_push($this->data['citations'], $id);
$this->data['report_type'] = 'citation';
} elseif ($request->has('compound_id')) {
$this->data['mol_id_csv'] = $request->compound_id;
$this->data['report_type'] = 'molecule';
} elseif ($request->has('organism_id')) {
$citation = Organism::where('id', $request->organism_id)->get();
$id = $citation[0]->id;
array_push($this->data['organisms'], $id);
$this->data['report_type'] = 'organism';
}
}

Expand All @@ -54,16 +61,6 @@ protected function beforeCreate(): void
$this->data['citations'] = [];
$this->data['mol_id_csv'] = null;
}

if (! ($this->data['collections'] || $this->data['citations'] || $this->data['mol_id_csv'] || $this->data['organisms'])) {
Notification::make()
->danger()
->title('Select at least one Collection/Citation/Molecule/Organism')
->persistent()
->send();

$this->halt();
}
}

protected function mutateFormDataBeforeCreate(array $data): array
Expand Down
9 changes: 9 additions & 0 deletions app/Helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,15 @@ function npScore($old_value)
return ($old_value - $old_min) / ($old_max - $old_min) * ($new_max - $new_min) + $new_min;
}

function getReportTypes() {
return [
'molecule' => 'Molecule',
'citation' => 'Citation',
'collection' => 'Collection',
'organism' => 'Organism',
];
}

function doiRegxMatch($doi)
{
$doiRegex = '/\b(10[.][0-9]{4,}(?:[.][0-9]+)*)\b/';
Expand Down
5 changes: 5 additions & 0 deletions app/Models/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,12 @@ class Report extends Model implements Auditable
'status',
'comment',
'user_id',
'suggested_changes',
'is_change',
];

protected $casts = [
'suggested_changes' => 'array',
];

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('reports', function (Blueprint $table) {
$table->boolean('is_change')->nullable();
$table->json('suggested_changes')->nullable();
});
}

/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('reports', function (Blueprint $table) {
$table->dropColumn(['is_change','suggested_changes']);
});
}
};
4 changes: 2 additions & 2 deletions resources/views/livewire/molecule-details.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -787,10 +787,10 @@ class="font-medium text-gray-900"></a></p>
<dl class="mt-5 flex w-full">
<div class="text-center md:text-left">
<dd class="mt-1"><a class="text-base font-semibold text-text-dark hover:text-slate-600"
href="/dashboard/reports/create?compound_id={{ $molecule->identifier }}">
href="/dashboard/reports/create?compound_id={{ $molecule->identifier }}&type=report">
Report this compound <span aria-hidden="true">→</span></a></dd>
<dd class="mt-1"><a class="text-base font-semibold text-text-dark hover:text-slate-600"
href="/dashboard/reports/create?compound_id={{ $molecule->identifier }}">Request
href="/dashboard/reports/create?compound_id={{ $molecule->identifier }}&type=change">Request
changes to this page <span aria-hidden="true">→</span></a></dd>
</div>
</dl>
Expand Down

0 comments on commit 313b736

Please sign in to comment.