Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions backend/fpbase/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@
'proteinIndex': 'Protein_{{ algolia_suffix}}',
'organismIndex': 'Organism_{{ algolia_suffix}}',
'referenceIndex': 'Reference_{{ algolia_suffix}}',
'dyeIndex': 'Dye_{{ algolia_suffix}}',
'microscopeIndex': 'Microscope_{{ algolia_suffix}}',
};
{% if request.user.is_authenticated %}
window.FPBASE.user = {
Expand Down
32 changes: 31 additions & 1 deletion backend/proteins/index.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from algoliasearch_django import AlgoliaIndex
from algoliasearch_django.decorators import register

from .models import Organism, Protein
from .models import Dye, Microscope, Organism, Protein


@register(Protein)
Expand Down Expand Up @@ -43,3 +43,33 @@ class ProteinIndex(AlgoliaIndex):
@register(Organism)
class OrganismIndex(AlgoliaIndex):
fields = ("scientific_name", "division", "url")


@register(Dye)
class DyeIndex(AlgoliaIndex):
fields = (
"name",
"slug",
"url",
"ex_max",
"em_max",
"qy",
"ext_coeff",
"brightness",
"pka",
"manufacturer",
"part",
"created",
)


@register(Microscope)
class MicroscopeIndex(AlgoliaIndex):
fields = (
"name",
"description",
"id",
"url",
"created",
"owner_name",
)
12 changes: 12 additions & 0 deletions backend/proteins/models/microscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ def inverted_bs_set(self):
def get_absolute_url(self):
return reverse("proteins:microscope-detail", args=[self.id])

@property
def url(self):
"""Alias for get_absolute_url for consistency with other models."""
return self.get_absolute_url()

@property
def owner_name(self):
"""Return owner's display name for search indexing."""
if self.owner:
return self.owner.get_full_name() or self.owner.email
return ""

@cached_property
def lights(self):
oclights = Light.objects.filter(id__in=self.optical_configs.values("light"))
Expand Down
7 changes: 7 additions & 0 deletions backend/proteins/models/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,13 @@ class Dye(Fluorophore, Product):
objects = FluorophoreManager()
oc_eff = GenericRelation("OcFluorEff", related_query_name="dye")

@property
def url(self):
"""Return URL to spectra viewer showing this dye."""
from django.urls import reverse

return reverse("proteins:spectra", args=[self.slug])


class State(Fluorophore):
DEFAULT_NAME = "default"
Expand Down
Binary file added backend/proteins/static/images/dye_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added backend/proteins/static/images/microscope_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
43 changes: 43 additions & 0 deletions frontend/src/js/algolia.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@ function checkObject(val, prop, str) {
_excerpts: "Excerpt",
prot_primary: "Protein",
prot_secondary: "Protein",
manufacturer: "Manufacturer",
part: "Part #",
slug: "Slug",
owner_name: "Owner",
}
if (val.matchLevel === "full" || val.matchLevel === "partial") {
if (str.length > 0) {
Expand Down Expand Up @@ -172,6 +176,8 @@ export default async function initAutocomplete() {
var proteinIndex = algoliaClient.initIndex(window.FPBASE.ALGOLIA.proteinIndex)
var organismIndex = algoliaClient.initIndex(window.FPBASE.ALGOLIA.organismIndex)
var referenceIndex = algoliaClient.initIndex(window.FPBASE.ALGOLIA.referenceIndex)
var dyeIndex = algoliaClient.initIndex(window.FPBASE.ALGOLIA.dyeIndex)
var microscopeIndex = algoliaClient.initIndex(window.FPBASE.ALGOLIA.microscopeIndex)

function empty(context) {
if (Object.hasOwn(context, "query")) {
Expand Down Expand Up @@ -278,6 +284,43 @@ export default async function initAutocomplete() {
},
},
},
{
source: $.fn.autocomplete.sources.hits(dyeIndex, {
hitsPerPage: 3,
}),
displayKey: "name",
templates: {
suggestion: (suggestion) => {
var str = suggestion._highlightResult.name.value
str = str + "<img class='type dye' src='" + window.FPBASE.imageDir + "dye_icon.png'>"
str = str + highlightHits(suggestion._highlightResult)
var info = ""
if (suggestion.ex_max && suggestion.em_max) {
info = `${suggestion.ex_max}/${suggestion.em_max}`
}
str = `${str}<span class='info'>${info}</span>`
return `<a href='${suggestion.url}'><div>${str}</div></a>`
},
},
},
{
source: $.fn.autocomplete.sources.hits(microscopeIndex, {
hitsPerPage: 2,
}),
displayKey: "name",
templates: {
suggestion: (suggestion) => {
var str = suggestion._highlightResult.name.value
str =
str +
"<img class='type microscope' src='" +
window.FPBASE.imageDir +
"microscope_icon.png'>"
str = str + highlightHits(suggestion._highlightResult)
return `<a href='${suggestion.url}'><div>${str}</div></a>`
},
},
},
{
source: (query, callback) => {
callback([
Expand Down
Loading