From 9d520a3d5d39e834997d0ca647df86e1430c891c Mon Sep 17 00:00:00 2001 From: Venkata Chandra Sekhar Nainala Date: Wed, 11 Dec 2024 12:49:56 +0100 Subject: [PATCH] fix: added search history, collection url resolution bug fix, chemical classes issue fix --- app/Http/Controllers/CollectionController.php | 38 ++++ app/Models/Properties.php | 4 - .../views/livewire/structure-editor.blade.php | 189 +++++++++++------- routes/web.php | 4 + 4 files changed, 162 insertions(+), 73 deletions(-) create mode 100644 app/Http/Controllers/CollectionController.php diff --git a/app/Http/Controllers/CollectionController.php b/app/Http/Controllers/CollectionController.php new file mode 100644 index 00000000..4740e387 --- /dev/null +++ b/app/Http/Controllers/CollectionController.php @@ -0,0 +1,38 @@ +first(); + }); + + if (! $collection) { + abort(404); + } + + $query = [ + 'type' => 'tags', + 'q' => urlencode($collection->title), + 'tagType' => 'dataSource', + ]; + + $baseUrl = config('app.url'); + + return redirect()->to($baseUrl.'/search?'.http_build_query($query)); + } +} diff --git a/app/Models/Properties.php b/app/Models/Properties.php index 3218436d..43a48d05 100644 --- a/app/Models/Properties.php +++ b/app/Models/Properties.php @@ -60,10 +60,6 @@ class Properties extends Model implements Auditable * @var array */ protected $casts = [ - 'chemical_class' => 'array', - 'chemical_sub_class' => 'array', - 'chemical_super_class' => 'array', - 'direct_parent_classification' => 'array', 'pathway_results' => 'array', 'superclass_results' => 'array', 'class_results' => 'array', diff --git a/resources/views/livewire/structure-editor.blade.php b/resources/views/livewire/structure-editor.blade.php index 2110a343..36f8831c 100644 --- a/resources/views/livewire/structure-editor.blade.php +++ b/resources/views/livewire/structure-editor.blade.php @@ -5,6 +5,7 @@ smiles: @entangle('smiles'), type: @entangle('type'), draggedFile: null, + recentSearches: JSON.parse(localStorage.getItem('recentSearches') || '[]'), fetchClipboardText() { navigator.clipboard.readText().then(text => { window.editor.setSmiles(text); @@ -18,7 +19,7 @@ const allowedExtensions = ['.mol', '.sdf']; const fileExtension = '.' + file.name.split('.').pop().toLowerCase(); - + if (!allowedExtensions.includes(fileExtension)) { alert('Only .mol and .sdf files are allowed'); return; @@ -35,8 +36,28 @@ } }; reader.readAsText(file); + }, + performSearch() { + const smiles = window.getEditorSmiles(); + const query = { type: this.type, q: smiles }; + + this.recentSearches.push(query); + this.recentSearches = Array.from( + new Map(this.recentSearches.map(item => [item.q, item])).values() + ); + localStorage.setItem('recentSearches', JSON.stringify(this.recentSearches)); + + window.location.href = `/search?type=${this.type}&q=${encodeURIComponent(smiles)}`; + }, + deleteSearch(index) { + this.recentSearches.splice(index, 1); + localStorage.setItem('recentSearches', JSON.stringify(this.recentSearches)); + }, + loadSearch(search) { + this.type = search.type; + window.editor.setSmiles(search.q); } -}" > +}">