Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hide method and instrument columns in analysis listing when not required #1951

Merged
merged 5 commits into from
Mar 22, 2022
Merged
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
1 change: 1 addition & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
2.2.0 (unreleased)
------------------

- #1951 Hide method and instrument columns in analysis listing when not required
- #1947 Fix worksheet attachments viewlet
- #1946 Fix conditions issue in Reference Analyses display view
- #1944 Add handler for "content_status_modify"-like requests
Expand Down
12 changes: 6 additions & 6 deletions buildout.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@ sources = sources
auto-checkout = *

[sources]
senaite.app.listing = git git://github.com/senaite/senaite.app.listing.git [email protected]:senaite/senaite.app.listing.git branch=2.x
senaite.app.spotlight = git git://github.com/senaite/senaite.app.spotlight.git [email protected]:senaite/senaite.app.spotlight.git branch=2.x
senaite.app.supermodel = git git://github.com/senaite/senaite.app.supermodel.git [email protected]:senaite/senaite.app.supermodel.git branch=2.x
senaite.impress = git git://github.com/senaite/senaite.impress.git [email protected]:senaite/senaite.impress.git branch=2.x
senaite.jsonapi = git git://github.com/senaite/senaite.jsonapi.git [email protected]:senaite/senaite.jsonapi.git branch=2.x
senaite.lims = git git://github.com/senaite/senaite.lims.git [email protected]:senaite/senaite.lims.git branch=2.x
senaite.app.listing = git https://github.com/senaite/senaite.app.listing.git [email protected]:senaite/senaite.app.listing.git branch=2.x
senaite.app.spotlight = git https://github.com/senaite/senaite.app.spotlight.git [email protected]:senaite/senaite.app.spotlight.git branch=2.x
senaite.app.supermodel = git https://github.com/senaite/senaite.app.supermodel.git [email protected]:senaite/senaite.app.supermodel.git branch=2.x
senaite.impress = git https://github.com/senaite/senaite.impress.git [email protected]:senaite/senaite.impress.git branch=2.x
senaite.jsonapi = git https://github.com/senaite/senaite.jsonapi.git [email protected]:senaite/senaite.jsonapi.git branch=2.x
senaite.lims = git https://github.com/senaite/senaite.lims.git [email protected]:senaite/senaite.lims.git branch=2.x

[instance]
recipe = plone.recipe.zope2instance
Expand Down
114 changes: 78 additions & 36 deletions src/bika/lims/browser/analyses/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -234,11 +234,6 @@ def __init__(self, context, request, **kwargs):
},
]

# This is used to display method and instrument columns if there is at
# least one analysis to be rendered that allows the assignment of
# method and/or instrument
self.show_methodinstr_columns = False

def update(self):
"""Update hook
"""
Expand Down Expand Up @@ -773,12 +768,10 @@ def folderitems(self):
self.json_interim_fields = json.dumps(self.interim_fields)
self.items = items

# Method and Instrument columns must be shown or hidden at the
# same time, because the value assigned to one causes
# a value reassignment to the other (one method can be performed
# by different instruments)
self.columns["Method"]["toggle"] = self.show_methodinstr_columns
self.columns["Instrument"]["toggle"] = self.show_methodinstr_columns
# Display method and instrument columns only if at least one of the
# analyses requires them to be displayed for selection
self.columns["Method"]["toggle"] = self.is_method_column_required()
self.columns["Instrument"]["toggle"] = self.is_instrument_column_required()

return items

Expand Down Expand Up @@ -994,20 +987,17 @@ def _folder_item_method(self, analysis_brain, item):
"""
obj = self.get_object(analysis_brain)
is_editable = self.is_analysis_edition_allowed(analysis_brain)
method = obj.getMethod()
method_title = method and api.get_title(method) or ""
item["Method"] = method_title or _("Manual")
if is_editable:
method_vocabulary = self.get_methods_vocabulary(analysis_brain)
if method_vocabulary:
item["Method"] = obj.getRawMethod()
item["choices"]["Method"] = method_vocabulary
item["allow_edit"].append("Method")
self.show_methodinstr_columns = True
elif method_title:
item["replace"]["Method"] = get_link(
api.get_url(method), method_title, tabindex="-1")
self.show_methodinstr_columns = True
item["Method"] = obj.getRawMethod()
item["choices"]["Method"] = method_vocabulary
item["allow_edit"].append("Method")
else:
item["Method"] = _("Manual")
method = obj.getMethod()
if method:
item["Method"] = api.get_title(method)
item["replace"]["Method"] = get_link_for(method, tabindex="-1")

def _on_method_change(self, uid=None, value=None, item=None, **kw):
"""Update instrument and calculation when the method changes
Expand Down Expand Up @@ -1040,27 +1030,21 @@ def _folder_item_instrument(self, analysis_brain, item):

# Instrument can be assigned to this analysis
is_editable = self.is_analysis_edition_allowed(analysis_brain)
self.show_methodinstr_columns = True
instrument = self.get_instrument(analysis_brain)

if is_editable:
# Edition allowed
voc = self.get_instruments_vocabulary(analysis_brain)
if voc:
# The service has at least one instrument available
item["Instrument"] = instrument.UID() if instrument else ""
item["choices"]["Instrument"] = voc
item["allow_edit"].append("Instrument")
return
item["Instrument"] = instrument.UID() if instrument else ""
item["choices"]["Instrument"] = voc
item["allow_edit"].append("Instrument")

if instrument:
elif instrument:
# Edition not allowed
instrument_title = instrument and instrument.Title() or ""
instrument_link = get_link(instrument.absolute_url(),
instrument_title, tabindex="-1")
item["Instrument"] = instrument_title
item["Instrument"] = api.get_title(instrument)
instrument_link = get_link_for(instrument, tabindex="-1")
item["replace"]["Instrument"] = instrument_link
return

else:
item["Instrument"] = _("Manual")

Expand Down Expand Up @@ -1454,3 +1438,61 @@ def _folder_item_conditions(self, analysis_brain, item):
conditions = "<br/>".join(conditions)
service = item["replace"].get("Service") or item["Service"]
item["replace"]["Service"] = "{}<br/>{}".format(service, conditions)

def is_method_required(self, analysis):
"""Returns whether the render of the selection list with methods is
required for the method passed-in, even if only option "None" is
displayed for selection
"""
# Always return true if the analysis has a method assigned
obj = self.get_object(analysis)
method = obj.getMethod()
if method:
return True

methods = obj.getAllowedMethods()
return len(methods) > 0

def is_instrument_required(self, analysis):
"""Returns whether the render of the selection list with instruments is
required for the analysis passed-in, even if only option "None" is
displayed for selection.
:param analysis: Brain or object that represents an analysis
"""
# If method selection list is required, the instrument selection too
if self.is_method_required(analysis):
return True

# Always return true if the analysis has an instrument assigned
if self.get_instrument(analysis):
return True

obj = self.get_object(analysis)
instruments = obj.getAllowedInstruments()
# There is no need to check for the instruments of the method assigned
# to # the analysis (if any), because the instruments rendered in the
# selection list are always a subset of the allowed instruments when
# a method is selected
return len(instruments) > 0

def is_method_column_required(self):
"""Returns whether the method column has to be rendered or not.
Returns True if at least one of the analyses from the listing requires
the list for method selection to be rendered
"""
for item in self.items:
obj = item.get("obj")
if self.is_method_required(obj):
return True
return False

def is_instrument_column_required(self):
"""Returns whether the instrument column has to be rendered or not.
Returns True if at least one of the analyses from the listing requires
the list for instrument selection to be rendered
"""
for item in self.items:
obj = item.get("obj")
if self.is_instrument_required(obj):
return True
return False