Skip to content

Commit

Permalink
Merge pull request #49 from Steinbeck-Lab/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
CS76 authored Jun 3, 2024
2 parents 4d359e4 + 61606ad commit ae968dd
Show file tree
Hide file tree
Showing 23 changed files with 811 additions and 475 deletions.
47 changes: 47 additions & 0 deletions app/Livewire/CollectionList.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

namespace App\Livewire;

use App\Models\Collection;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;

#[Layout('layouts.guest')]
class CollectionList extends Component
{
use WithPagination;

#[Url(except: '', keep: true, history: true, as: 'q')]
public $query = '';

#[Url(as: 'limit')]
public $size = 20;

#[Url()]
public $sort = null;

#[Url()]
public $page = null;

public function updatingQuery()
{
$this->resetPage();
}

public function render()
{
$search = $this->query;
$collections = Collection::query()
->where(function ($query) use ($search) {
$query->whereRaw('LOWER(title) LIKE ?', ['%'.strtolower($search).'%'])
->orWhereRaw('LOWER(description) LIKE ?', ['%'.strtolower($search).'%']);
})
->orderByRaw('title LIKE ? DESC', [$search.'%'])
->orderByRaw('description LIKE ? DESC', [$search.'%'])
->paginate($this->size);

return view('livewire.collection-list', ['collections' => $collections]);
}
}
29 changes: 28 additions & 1 deletion app/Livewire/CompoundClasses.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,32 @@

class CompoundClasses extends Component
{
public $superClasses = [
'Acetylides',
'Alkaloids and derivatives',
'Allenes',
'Benzenoids',
'Hydrocarbon derivatives',
'Hydrocarbons',
'Lignans, neolignans and related compounds',
'Lipids and lipid-like molecules',
'Nucleosides, nucleotides, and analogues',
'Organoheterocyclic compounds',
'Organohalogen compounds',
'Organometallic compounds',
'Organophosphorus compounds',
'Organosulfur compounds',
'Organic 1,3-dipolar compounds',
'Organic Polymers',
'Organic acids and derivatives',
'Organic anions',
'Organic cations',
'Organic nitrogen compounds',
'Organic oxygen compounds',
'Organic salts',
'Phenylpropanoids and polyketides',
];

public $parentClasses = [
'Acenaphthylenes',
'Acetals',
Expand Down Expand Up @@ -985,7 +1011,8 @@ class CompoundClasses extends Component

public function mount()
{
$this->parentClasses = array_slice($this->parentClasses, 0, 50);
// $this->parentClasses = array_slice($this->parentClasses, 0, 50);
$this->superClasses = $this->superClasses;
}

public function render()
Expand Down
14 changes: 11 additions & 3 deletions app/Livewire/MoleculeDetails.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

use App\Models\Molecule;
use Cache;
use Livewire\Attributes\Layout;
use Livewire\Component;

class MoleculeDetails extends Component
Expand All @@ -18,11 +17,20 @@ public function mount($id)
});
}

#[Layout('layouts.guest')]
public function render()
{
return view('livewire.molecule-details', [
'molecule' => $this->molecule,
]);
])->layout('layouts.guest')
->layoutData([
'title' => $this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name,
'description' => $this->molecule->description ?? 'Molecule details for '.($this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name),
'keywords' => 'natural products, '.$this->molecule->name.', '.$this->molecule->iupac_name.', '.implode(',', $this->molecule->synonyms ?? []),
'author' => $this->molecule->author ?? 'COCONUT Team',
'ogTitle' => $this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name,
'ogDescription' => $this->molecule->description ?? 'Molecule details for '.($this->molecule->name ? $this->molecule->name : $this->molecule->iupac_name),
'ogImage' => env('CM_API').'depict/2D?smiles='.urlencode($this->molecule->canonical_smiles).'&height=200&width=200&toolkit=cdk' ?? asset('img/coconut-og-image.png'),
'ogSiteName' => 'Coconut 2.0',
]);
}
}
15 changes: 0 additions & 15 deletions app/Livewire/MoleculeEditor.php

This file was deleted.

48 changes: 39 additions & 9 deletions app/Livewire/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

namespace App\Livewire;

use App\Http\Resources\MoleculeResource;
use App\Models\Collection;
use App\Models\Molecule;
use App\Models\Organism;
use Illuminate\Pagination\LengthAwarePaginator;
use Illuminate\Support\Facades\DB;
use Livewire\Attributes\Layout;
use Livewire\Attributes\Url;
use Livewire\Component;
use Livewire\WithPagination;

#[Layout('layouts.guest')]
class Search extends Component
{
use WithPagination;
Expand All @@ -36,12 +37,21 @@ class Search extends Component

public $collection = null;

public $organisms = null;

public function gotoPage($page)
{
$this->page = $page;
}

#[Layout('layouts.guest')]
protected $listeners = ['updateSmiles' => 'setSmiles'];

public function setSmiles($smiles, $searchType)
{
$this->query = $smiles;
$this->type = $searchType;
}

public function render()
{

Expand Down Expand Up @@ -173,7 +183,31 @@ public function render()
} elseif ($queryType == 'tags') {
if ($this->tagType == 'dataSource') {
$this->collection = Collection::where('title', $this->query)->first();
$results = $this->collection->molecules()->orderBy('annotation_level', 'desc')->paginate($this->size);
if ($this->collection) {
$results = $this->collection->molecules()->orderBy('annotation_level', 'desc')->paginate($this->size);
} else {
$results = new LengthAwarePaginator(
[],
0,
$this->size,
$this->page
);
}
} elseif ($this->tagType == 'organisms') {
$this->organisms = array_map(function ($name) {
return strtolower(trim($name));
}, explode(',', $this->query));

$organismIds = Organism::where(function ($query) {
foreach ($this->organisms as $name) {
$query->orWhereRaw('LOWER(name) = ?', [$name]);
}
})->pluck('id');

$results = Molecule::whereHas('organisms', function ($query) use ($organismIds) {
$query->whereIn('organism_id', $organismIds);
})->orderBy('annotation_level', 'DESC')->paginate($this->size);

} else {
$results = Molecule::withAnyTags([$this->query], $this->tagType)->paginate($this->size);
}
Expand Down Expand Up @@ -235,11 +269,12 @@ public function render()
}
$statement =
$statement.
'('.$filterMap[$_filter[0]].'::TEXT ILIKE \'%'.$_filter[1].'%\')';
'(LOWER(REGEXP_REPLACE('.$filterMap[$_filter[0]].' , \'\s+\', \'-\', \'g\'))::TEXT ILIKE \'%'.$_filter[1].'%\')';
}
}
$statement = $statement.')';
}
// dd($statement);
$statement = $statement.' LIMIT '.$this->size;
} else {
if ($this->query) {
Expand Down Expand Up @@ -335,10 +370,5 @@ public function render()
500
);
}
// return view('livewire.search', [
// 'molecules' => MoleculeResource::collection(
// Molecule::where('active', true)->orderByDesc('updated_at')->paginate($this->size)
// ),
// ]);
}
}
30 changes: 30 additions & 0 deletions app/Livewire/StructureEditor.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

namespace App\Livewire;

use Livewire\Component;

class StructureEditor extends Component
{
public $isOpen = false;

public $smiles = '';

protected $listeners = ['openModal'];

public function openModal($smiles = '')
{
$this->smiles = $smiles;
$this->isOpen = true;
}

public function closeModal()
{
$this->isOpen = false;
}

public function render()
{
return view('livewire.structure-editor');
}
}
10 changes: 5 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@
"vitepress": "^1.2.2"
},
"dependencies": {
"openchemlib": "^8.9.0"
"openchemlib": "^8.13.0"
}
}
Binary file added public/img/coconut-og-image.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 8 additions & 0 deletions resources/css/app.css
Original file line number Diff line number Diff line change
Expand Up @@ -293,4 +293,12 @@
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}

.organism::first-letter {
text-transform: capitalize !important;
}

.organism {
font-style: italic;
}
2 changes: 1 addition & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "./bootstrap";

import OCL from "openchemlib/full";
window.OCL = OCL;
window.OCL = OCL;
13 changes: 13 additions & 0 deletions resources/views/layouts/guest.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,19 @@

<title>{{ config('app.name', 'Coconut') }}</title>

<!-- Meta Tags -->
<meta name="description" content="{{ $description ?? 'An aggregated dataset of elucidated and predicted natural products collected from open sources and a web interface to browse, search, and easily download NPs.' }}">
<meta name="keywords" content="{{ $keywords ?? 'natural products, COCONUT, open data, molecule database' }}">
<meta name="author" content="{{ $author ?? 'COCONUT Team' }}">
<meta property="og:title" content="{{ $ogTitle ?? 'COCONUT: Collection of Open Natural Products' }}">
<meta property="og:description" content="{{ $ogDescription ?? 'An aggregated dataset of elucidated and predicted natural products collected from open sources and a web interface to browse, search, and easily download NPs.' }}">
<meta property="og:type" content="website">
<meta property="og:url" content="{{ $ogUrl ?? url()->current() }}">
<meta property="og:image" content="{{ $ogImage ?? asset('img/coconut-og-image.png') }}">
<meta property="og:image:width" content="1200">
<meta property="og:image:height" content="630">
<meta property="og:site_name" content="{{ $ogSiteName ?? config('app.name', 'Coconut') }}">

<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
Expand Down
Loading

0 comments on commit ae968dd

Please sign in to comment.