-
-
Notifications
You must be signed in to change notification settings - Fork 146
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added ContentSectionViewletManager to allow dynamic addition of secti…
…ons (#1690) * Allow to add new sections in Sample via adapters * Ensure deepcopy interims * Use Viewlets approach instead of our own subscriber adapters * Refactored sample sections viewlets * Added viewlet render condition * Sample is the current context Co-authored-by: Ramon Bartl <rb@ridingbytes.com>
- Loading branch information
Showing
10 changed files
with
152 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
# -*- coding: utf-8 -*- | ||
# | ||
# This file is part of SENAITE.CORE. | ||
# | ||
# SENAITE.CORE is free software: you can redistribute it and/or modify it under | ||
# the terms of the GNU General Public License as published by the Free Software | ||
# Foundation, version 2. | ||
# | ||
# This program is distributed in the hope that it will be useful, but WITHOUT | ||
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS | ||
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more | ||
# details. | ||
# | ||
# You should have received a copy of the GNU General Public License along with | ||
# this program; if not, write to the Free Software Foundation, Inc., 51 | ||
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. | ||
# | ||
# Copyright 2018-2020 by it's authors. | ||
# Some rights reserved, see README and LICENSE. | ||
|
||
from bika.lims import api | ||
from bika.lims import senaiteMessageFactory as _ | ||
from plone.app.layout.viewlets import ViewletBase | ||
from Products.Five.browser.pagetemplatefile import ViewPageTemplateFile | ||
|
||
|
||
class LabAnalysesViewlet(ViewletBase): | ||
"""Laboratory analyses section viewlet for Sample view | ||
""" | ||
index = ViewPageTemplateFile("templates/sampleanalyses.pt") | ||
|
||
title = _("Analyses") | ||
icon_name = "analysisservice" | ||
capture = "lab" | ||
|
||
@property | ||
def sample(self): | ||
return self.context | ||
|
||
def available(self): | ||
"""Returns true if this sample contains at least one analysis for the | ||
point of capture (capture) | ||
""" | ||
analyses = self.sample.getAnalyses(getPointOfCapture=self.capture) | ||
return len(analyses) > 0 | ||
|
||
def get_listing_view(self): | ||
request = api.get_request() | ||
view_name = "table_{}_analyses".format(self.capture) | ||
view = api.get_view(view_name, context=self.sample, request=request) | ||
return view | ||
|
||
def contents_table(self): | ||
view = self.get_listing_view() | ||
view.update() | ||
view.before_render() | ||
return view.ajax_contents_table() | ||
|
||
|
||
class FieldAnalysesViewlet(LabAnalysesViewlet): | ||
"""Field analyses section viewlet for Sample view | ||
""" | ||
title = _("Field Analyses") | ||
capture = "field" | ||
|
||
|
||
class QCAnalysesViewlet(LabAnalysesViewlet): | ||
"""QC analyses section viewlet for Sample view | ||
""" | ||
title = _("QC Analyses") | ||
capture = "qc" | ||
|
||
def available(self): | ||
"""Returns true if this sample contains at least one qc analysis | ||
""" | ||
analyses = self.sample.getQCAnalyses() | ||
return len(analyses) > 0 |
20 changes: 20 additions & 0 deletions
20
src/senaite/core/browser/viewlets/templates/sampleanalyses.pt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<div class="analysis-listing-table" | ||
tal:condition="python:view.available()" | ||
i18n:domain="senaite.core"> | ||
<div class="row mb-4"> | ||
<div class="col-sm-12"> | ||
|
||
<!-- Analysis listing title and icon --> | ||
<h3 tal:define="icon view/icon_name|nothing; | ||
title view/title|nothing" | ||
tal:condition="title"> | ||
<img tal:condition="icon|nothing" tal:attributes="src string:senaite_theme/icon/${icon}"/> | ||
<span i18n:translate="" tal:content="title"/> | ||
</h3> | ||
|
||
<!-- Analyis listing table --> | ||
<span tal:replace="structure python:view.contents_table()"/> | ||
|
||
</div> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters