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

NDEV-32 Changes in "Manage Analyses" from "Analysis Request" view without effect #175

Merged
merged 4 commits into from
Jul 20, 2017
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
10 changes: 3 additions & 7 deletions bika/lims/browser/analysisrequest/manage_analyses.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ def __init__(self, context, request):
'Price': {'title': _('Price'),
'sortable': False, },
'Partition': {'title': _('Partition'),
'sortable': False, },
'sortable': False,
'type': 'choices'},
'min': {'title': _('Min')},
'max': {'title': _('Max')},
'error': {'title': _('Permitted Error %')},
Expand Down Expand Up @@ -171,13 +172,8 @@ def folderitems(self):
self.expand_all_categories = False

wf = getToolByName(self.context, 'portal_workflow')
mtool = getToolByName(self.context, 'portal_membership')

self.allow_edit = mtool.checkPermission('Modify portal content',
self.context)

items = BikaListingView.folderitems(self)
analyses = self.context.getAnalyses(full_objects=True)

parts = self.context.getSample().objectValues('SamplePartition')
partitions = [{'ResultValue': o.Title(),
Expand Down Expand Up @@ -280,7 +276,7 @@ def folderitems(self):

# Display analyses for this Analysis Service in results?
ser = self.context.getAnalysisServiceSettings(obj.UID())
items[x]['allow_edit'] = ['Hidden', ]
items[x]['allow_edit'].append('Hidden')
items[x]['Hidden'] = ser.get('hidden', obj.getHidden())

self.categories.sort()
Expand Down
4 changes: 2 additions & 2 deletions bika/lims/browser/analysisrequest/workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def workflow_action_save_analyses_button(self):
specs = {}
if form.get("min", None):
for service_uid in Analyses:
service = bsc(UID=service_uid)[0].getObject()
service = objects[service_uid]
keyword = service.getKeyword()
specs[service_uid] = {
"min": form["min"][0][service_uid],
Expand All @@ -154,7 +154,7 @@ def workflow_action_save_analyses_button(self):
}
else:
for service_uid in Analyses:
service = bsc(UID=service_uid)[0].getObject()
service = objects[service_uid]
keyword = service.getKeyword()
specs[service_uid] = {"min": "", "max": "", "error": "",
"keyword": keyword, "uid": service_uid}
Expand Down
61 changes: 40 additions & 21 deletions bika/lims/browser/js/bika.lims.analysisrequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,7 @@ function AnalysisRequestAnalysesView() {
////////////////////////////////////////
// checkboxes in services list
$("[name='uids:list']").live("click", function(){
calcdependencies([this]);
calcdependencies([this], true);
var service_uid = $(this).val();
if ($(this).prop("checked")){
check_service(service_uid);
Expand All @@ -497,12 +497,12 @@ function AnalysisRequestAnalysesView() {
});

}

/**
* This function validates specification inputs
* @param {element} The input field from specifications (min, max, err)
*/
function validate_spec_field_entry(element) {
var uid = $(element).attr("uid");
// no spec selector here yet!
// $("[name^='ar\\."+sb_col+"\\.Specification']").val("");
// $("[name^='ar\\."+sb_col+"\\.Specification_uid']").val("");
var min_element = $("[name='min\\."+uid+"\\:records']");
var max_element = $("[name='max\\."+uid+"\\:records']");
var error_element = $("[name='error\\."+uid+"\\:records']");
Expand All @@ -528,7 +528,11 @@ function AnalysisRequestAnalysesView() {
}
}
}

/**
* This functions runs the logic needed after setting the checkbox of a
* service.
* @param {service_uid} the service uid checked.
*/
function check_service(service_uid){
var new_element, element;

Expand Down Expand Up @@ -573,7 +577,11 @@ function AnalysisRequestAnalysesView() {
}

}

/**
* This functions runs the logic needed after unsetting the checkbox of a
* service.
* @param {service_uid} the service uid unchecked.
*/
function uncheck_service(service_uid){
var new_element, element;

Expand Down Expand Up @@ -604,26 +612,37 @@ function AnalysisRequestAnalysesView() {
}

function add_Yes(dlg, element, dep_services){
var service_uid;
for(var i = 0; i<dep_services.length; i++){
var service_uid = dep_services[i].Service_uid;
service_uid = dep_services[i];
if(! $("#list_cb_"+service_uid).prop("checked") ){
check_service(service_uid);
$("#list_cb_"+service_uid).prop("checked",true);
}
}
$(dlg).dialog("close");
$("#messagebox").remove();
if(dlg !== false){
$(dlg).dialog("close");
$("#messagebox").remove();
}
}

function add_No(dlg, element){
if($(element).prop("checked") ){
uncheck_service($(element).attr("value"));
$(element).prop("checked",false);
}
$(dlg).dialog("close");
$("#messagebox").remove();
if(dlg !== false){
$(dlg).dialog("close");
$("#messagebox").remove();
};
}

/**
* Once a checkbox has been selected, this functions finds out which are
* the dependencies and dependants related to it.
* @param {elements} The selected element, a checkbox.
* @param {auto_yes} A boolean. If 'true', the dependants and dependencies
* will be automatically selected/unselected.
*/
function calcdependencies(elements, auto_yes) {
/*jshint validthis:true */
auto_yes = auto_yes || false;
Expand Down Expand Up @@ -653,7 +672,7 @@ function AnalysisRequestAnalysesView() {
}
if (dep_services.length > 0) {
if (auto_yes) {
add_Yes(this, element, dep_services);
add_Yes(false, element, dep_services);
} else {
var html = "<div id='messagebox' style='display:none' title='" + _("Service dependencies") + "'>";
html = html + _("<p>${service} requires the following services to be selected:</p>"+
Expand Down Expand Up @@ -685,7 +704,7 @@ function AnalysisRequestAnalysesView() {
var Dependants = lims.AnalysisService.Dependants(service_uid);
for (i=0; i<Dependants.length; i++){
dep = Dependants[i];
cb = $("#list_cb_" + dep.Service_uid);
cb = $("#list_cb_" + dep);
if (cb.prop("checked")){
dep_titles.push(dep.Service);
dep_services.push(dep);
Expand All @@ -695,9 +714,9 @@ function AnalysisRequestAnalysesView() {
if (auto_yes) {
for(i=0; i<dep_services.length; i+=1) {
dep = dep_services[i];
service_uid = dep.Service_uid;
cb = $("#list_cb_" + dep.Service_uid);
uncheck_service(dep.Service_uid);
service_uid = dep;
cb = $("#list_cb_" + service_uid);
uncheck_service(service_uid);
$(cb).prop("checked", false);
}
} else {
Expand All @@ -714,10 +733,10 @@ function AnalysisRequestAnalysesView() {
yes: function(){
for(i=0; i<dep_services.length; i+=1) {
dep = dep_services[i];
service_uid = dep.Service_uid;
cb = $("#list_cb_" + dep.Service_uid);
service_uid = dep;
cb = $("#list_cb_" + dep);
$(cb).prop("checked", false);
uncheck_service(dep.Service_uid);
uncheck_service(dep);
}
$(this).dialog("close");
$("#messagebox").remove();
Expand Down
4 changes: 2 additions & 2 deletions bika/lims/browser/js/bika.lims.bikalisting.js
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,8 @@ function BikaListingTableView() {
event.preventDefault()
}
// check the item's checkbox
form_id = $(this).parents("form").attr("id")
uid = $(this).attr("uid")
var form_id = $(this).parents("form").attr("id")
var uid = $(this).attr("uid")
if (!($("#" + form_id + "_cb_" + uid).prop("checked"))) {
$("#" + form_id + "_cb_" + uid).prop("checked", true)
}
Expand Down
10 changes: 6 additions & 4 deletions bika/lims/browser/js/bika.lims.common.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,14 @@ function CommonUtils() {
Dependants: function(service_uid){
var request_data = {
catalog_name: "bika_setup_catalog",
UID: service_uid
UID: service_uid,
include_methods: 'getServiceDependantsUIDs',
};
var deps = {};
$.ajaxSetup({async:false});
window.bika.lims.jsonapi_read(request_data, function(data){
if (data.objects != null && data.objects.length > 0) {
deps = data.objects[0].ServiceDependants;
deps = data.objects[0].getServiceDependantsUIDs;
} else {
deps = [];
}
Expand All @@ -39,13 +40,14 @@ function CommonUtils() {
Dependencies: function(service_uid){
var request_data = {
catalog_name: "bika_setup_catalog",
UID: service_uid
UID: service_uid,
include_methods: 'getServiceDependenciesUIDs',
};
var deps = {};
$.ajaxSetup({async:false});
window.bika.lims.jsonapi_read(request_data, function(data){
if (data.objects != null && data.objects.length > 0) {
deps = data.objects[0].ServiceDependencies;
deps = data.objects[0].getServiceDependenciesUIDs;
} else {
deps = [];
}
Expand Down
43 changes: 43 additions & 0 deletions bika/lims/content/analysisservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,49 @@ def _getAvailableInstrumentsDisplayList(self):
items.sort(lambda x, y: cmp(x[1], y[1]))
return DisplayList(list(items))

@security.public
def getServiceDependencies(self):
"""
This methods returns a list with the analyses services dependencies.
:return: a list of analysis services objects.
"""
calc = self.getCalculation()
if calc:
return calc.getCalculationDependencies(flat=True)
return []

@security.public
def getServiceDependenciesUIDs(self):
"""
This methods returns a list with the service dependencies UIDs
:return: a list of uids
"""
deps = self.getServiceDependencies()
deps_uids = [service.UID() for service in deps]
return deps_uids

@security.public
def getServiceDependants(self):
bsc = getToolByName(self, 'bika_setup_catalog')
active_calcs = bsc(portal_type='Calculation', inactive_state="active")
calculations = [c.getObject() for c in active_calcs]
dependants = []
for calc in calculations:
calc_dependants = calc.getDependentServices()
if self in calc_dependants:
calc_dependencies = calc.getCalculationDependants()
dependants = dependants + calc_dependencies
dependants = list(set(dependants))
if self in dependants:
dependants.remove(self)
return dependants

@security.public
def getServiceDependantsUIDs(self):
deps = self.getServiceDependants()
deps_uids = [service.UID() for service in deps]
return deps_uids

def workflow_script_activate(self):
workflow = getToolByName(self, 'portal_workflow')
pu = getToolByName(self, 'plone_utils')
Expand Down
11 changes: 7 additions & 4 deletions bika/lims/content/calculation.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,11 +175,14 @@ def getCalculationDependencies(self, flat=False, deps=None):
def getCalculationDependants(self):
"""Return a flat list of services who's calculations depend on this."""
deps = []
for service in self.getBackReferences('AnalysisServiceCalculation'):
bsc = getToolByName(self, 'bika_setup_catalog')
services_b = bsc(
portal_type='AnalysisService', inactive_state="active")
for service_b in services_b:
service = service_b.getObject()
calc = service.getCalculation()
if calc and calc.UID() != self.UID():
calc.getCalculationDependants(deps)
deps.append(service)
if calc and calc.UID() == self.UID():
deps.append(service)
return deps

def workflow_script_activate(self):
Expand Down
18 changes: 18 additions & 0 deletions bika/lims/jsonapi/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,24 @@ def load_field_values(instance, include_fields):
return ret


def get_include_methods(request):
"""Retrieve include_methods values from the request
"""
methods = request.get("include_methods", "")
include_methods = [
x.strip() for x in methods.split(",") if x.strip()]
return include_methods


def load_method_values(instance, include_methods):
ret = {}
for method in include_methods:
if hasattr(instance, method):
val = getattr(instance, method)()
ret[method] = val
return ret


def resolve_request_lookup(context, request, fieldname):
if fieldname not in request:
return []
Expand Down
6 changes: 6 additions & 0 deletions bika/lims/jsonapi/read.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
from plone.protect.authenticator import AuthenticatorView
from bika.lims.jsonapi import load_brain_metadata
from bika.lims.jsonapi import load_field_values
from bika.lims.jsonapi import get_include_methods
from bika.lims.jsonapi import load_method_values
from Products.CMFCore.utils import getToolByName
from zope import interface
from zope.component import getAdapters
Expand Down Expand Up @@ -71,6 +73,8 @@ def read(context, request):

include_fields = get_include_fields(request)

include_methods = get_include_methods(request)

# Get matching objects from catalog
proxies = catalog(**contentFilter)

Expand Down Expand Up @@ -108,6 +112,8 @@ def read(context, request):
# Place all schema fields ino the result.
obj = proxy.getObject()
obj_data.update(load_field_values(obj, include_fields))
# Add methods results
obj_data.update(load_method_values(obj, include_methods))

obj_data['path'] = "/".join(obj.getPhysicalPath())

Expand Down