From 036eb3db92f07c1acdeb48d523adb4221950072d Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Sat, 1 Jun 2024 01:06:42 +0200 Subject: [PATCH] feat: landing page updates --- .../Commands/ExportMoleculesWithOrganisms.php | 94 ++++++++++++ app/Livewire/Welcome.php | 22 ++- resources/views/layouts/guest.blade.php | 21 +++ resources/views/livewire/welcome.blade.php | 141 ++++++++++++++++++ tailwind.config.js | 2 +- 5 files changed, 278 insertions(+), 2 deletions(-) create mode 100644 app/Console/Commands/ExportMoleculesWithOrganisms.php diff --git a/app/Console/Commands/ExportMoleculesWithOrganisms.php b/app/Console/Commands/ExportMoleculesWithOrganisms.php new file mode 100644 index 00000000..30ac6638 --- /dev/null +++ b/app/Console/Commands/ExportMoleculesWithOrganisms.php @@ -0,0 +1,94 @@ +join('molecules', 'molecule_organism.molecule_id', '=', 'molecules.id') + ->join('organisms', 'molecule_organism.organism_id', '=', 'organisms.id') + ->select('molecule_organism.molecule_id', 'molecules.cas', 'molecules.canonical_smiles', 'molecules.identifier', + 'organisms.name as organism_name', 'organisms.iri as organism_iri', 'organisms.rank as organism_rank', + 'molecule_organism.*') + ->get(); + + // Group by molecule_id and concatenate values + $groupedData = $data->groupBy('molecule_id')->map(function ($rows) { + $firstRow = $rows->first(); + $moleculeId = $firstRow->molecule_id; + $moleculeCasArray = json_decode($firstRow->cas, true); + $moleculeCas = is_array($moleculeCasArray) && ! empty($moleculeCasArray) ? $moleculeCasArray[0] : null; + $canonicalSmiles = $firstRow->canonical_smiles; + $identifier = $firstRow->identifier; + + $organisms = $rows->map(function ($row) { + $organismDetail = $row->organism_name; + if (! empty($row->organism_iri)) { + $organismDetail .= ' ('.urldecode($row->organism_iri).'|'.$row->organism_rank.')'; + } + + return $organismDetail; + })->implode('|'); + + // Get pivot columns, assuming the pivot table has additional columns like 'attribute1' and 'attribute2' + $pivotColumns = ['attribute1', 'attribute2']; + $pivotData = []; + foreach ($pivotColumns as $column) { + $pivotData[$column] = $rows->pluck($column)->unique()->implode('|'); + } + + return array_merge([ + 'molecule_id' => $moleculeId, + 'identifier' => $identifier, + 'molecule_cas' => $moleculeCas, + 'canonical_smiles' => $canonicalSmiles, + 'organisms' => $organisms, + ], $pivotData); + }); + + // Convert to CSV format + $csvContent = $groupedData->map(function ($row) { + return implode(',', array_map(function ($value) { + return '"'.str_replace('"', '""', $value).'"'; + }, $row)); + })->prepend(implode(',', array_keys($groupedData->first())))->implode("\n"); + + // Save to a CSV file + // The file will be created in the storage/app directory + Storage::put('molecules_with_organisms.csv', $csvContent); + + // Alternatively, to save in the storage/app/public directory: + // Storage::put('public/molecules_with_organisms.csv', $csvContent); + + $this->info('Export completed successfully.'); + } +} diff --git a/app/Livewire/Welcome.php b/app/Livewire/Welcome.php index f933ff1a..85c42209 100644 --- a/app/Livewire/Welcome.php +++ b/app/Livewire/Welcome.php @@ -2,14 +2,34 @@ namespace App\Livewire; +use Cache; use Livewire\Attributes\Layout; use Livewire\Component; class Welcome extends Component { + public $totalMolecules; + + public $totalCollections; + + public $uniqueOrganisms; + + public $citationsMapped; + #[Layout('layouts.guest')] public function render() { - return view('livewire.welcome'); + // Assign values to the variables + $this->totalMolecules = Cache::get('stats.molecules', 0); + $this->totalCollections = Cache::get('stats.collections', 0); + $this->uniqueOrganisms = Cache::get('stats.organisms', 0); + $this->citationsMapped = Cache::get('stats.citations', 0); + + return view('livewire.welcome', [ + 'totalMolecules' => $this->totalMolecules, + 'totalCollections' => $this->totalCollections, + 'uniqueOrganisms' => $this->uniqueOrganisms, + 'citationsMapped' => $this->citationsMapped, + ]); } } diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php index 4455fa3f..b05fcc62 100644 --- a/resources/views/layouts/guest.blade.php +++ b/resources/views/layouts/guest.blade.php @@ -34,4 +34,25 @@ @livewireScripts @include('cookie-consent::index') + diff --git a/resources/views/livewire/welcome.blade.php b/resources/views/livewire/welcome.blade.php index 95eed7ee..ce003adf 100644 --- a/resources/views/livewire/welcome.blade.php +++ b/resources/views/livewire/welcome.blade.php @@ -27,6 +27,147 @@ class="absolute inset-0 -z-10 scale-75 rounded-lg bg-white/5 opacity-0 transitio + +
+
+
+ +
+

+ + + + + + + + Total Molecules +

+

+ +

+
+ +
+

+ + + + Total Collections +

+

+ +

+
+ +
+

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + Unique Organisms +

+

+ +

+
+ +
+

+ + + + + + Citations Mapped +

+

+ +

+
+
+
+
diff --git a/tailwind.config.js b/tailwind.config.js index e3937f0f..1fbf07ae 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -25,7 +25,7 @@ export default { light: '#92400e' }, secondary: { - dark: '#3ab449', + dark: '#99674d', light: '#22c55e' }, text: {