Skip to content

Commit

Permalink
TVB-2757: Add correctly dynamic filters for each field when rebuildin…
Browse files Browse the repository at this point in the history
…g the user defined filters + add runtime filters for Surface Viewer, RM Viewer and TSVolume Viewer
  • Loading branch information
VinczeRobert committed Jan 22, 2021
1 parent dd6e5ac commit cc87b1c
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 16 deletions.
6 changes: 3 additions & 3 deletions framework_tvb/tvb/adapters/visualizers/annotations_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,13 +75,13 @@ class ConnectivityAnnotationsViewForm(ABCAdapterForm):
def __init__(self):
super(ConnectivityAnnotationsViewForm, self).__init__()
# Used for filtering
annotations_index_filter = FilterChain(fields=[FilterChain.datatype + '.number_of_regions'], operations=["=="],
values=['fk_connectivity_gid'])
connectivity_index_filter = FilterChain(fields=[FilterChain.datatype + '.number_of_regions'], operations=["=="],
values=['fk_connectivity_gid'])

self.connectivity_index = TraitDataTypeSelectField(ConnectivityAnnotationsViewModel.connectivity_index,
'connectivity_index',
runtime_conditions=('annotations_index',
annotations_index_filter))
connectivity_index_filter))

self.annotations_index = TraitDataTypeSelectField(ConnectivityAnnotationsViewModel.annotations_index,
'annotations_index', conditions=self.get_filters())
Expand Down
14 changes: 12 additions & 2 deletions framework_tvb/tvb/adapters/visualizers/surface_view.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,12 +159,18 @@ class BaseSurfaceViewerForm(ABCAdapterForm):

def __init__(self):
super(BaseSurfaceViewerForm, self).__init__()

self.region_map = TraitDataTypeSelectField(BaseSurfaceViewerModel.region_map, name='region_map')

conn_filter = FilterChain(
fields=[FilterChain.datatype + '.ndim', FilterChain.datatype + '.has_surface_mapping'],
operations=["==", "=="], values=[1, True])
operations=["==", "=="], values=[1, "1"])
cm_runtime_filter = FilterChain(fields=[FilterChain.datatype + '.gid'], operations=["=="],
values=['fk_connectivity_gid:fk_connectivity_gid'])
self.connectivity_measure = TraitDataTypeSelectField(BaseSurfaceViewerModel.connectivity_measure,
name='connectivity_measure', conditions=conn_filter)
name='connectivity_measure', conditions=conn_filter,
runtime_conditions=('region_map', cm_runtime_filter))

self.shell_surface = TraitDataTypeSelectField(BaseSurfaceViewerModel.shell_surface, name='shell_surface')

@staticmethod
Expand All @@ -184,6 +190,10 @@ class SurfaceViewerModel(BaseSurfaceViewerModel):
class SurfaceViewerForm(BaseSurfaceViewerForm):
def __init__(self):
super(SurfaceViewerForm, self).__init__()
rm_runtime_condition = FilterChain(fields=[FilterChain.datatype + '.fk_surface_gid'], operations=["=="],
values=[FilterChain.DEFAULT_RUNTIME_VALUE])
self.region_map.runtime_conditions = ('surface', rm_runtime_condition)

self.surface = TraitDataTypeSelectField(SurfaceViewerModel.surface, name='surface')

@staticmethod
Expand Down
6 changes: 5 additions & 1 deletion framework_tvb/tvb/adapters/visualizers/time_series_volume.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,11 @@ def __init__(self):
super(TimeSeriesVolumeVisualiserForm, self).__init__()
self.time_series = TraitDataTypeSelectField(TimeSeriesVolumeVisualiserModel.time_series, name='time_series',
conditions=self.get_filters())
self.background = TraitDataTypeSelectField(TimeSeriesVolumeVisualiserModel.background, name='background')

volume_index_filter = FilterChain(fields=[FilterChain.datatype + '.voxel_size'], operations=["=="],
values=['fk_volume_gid'])
self.background = TraitDataTypeSelectField(TimeSeriesVolumeVisualiserModel.background, name='background',
runtime_conditions=('time_series', volume_index_filter))

@staticmethod
def get_view_model():
Expand Down
10 changes: 8 additions & 2 deletions framework_tvb/tvb/interfaces/web/controllers/flow_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,11 +256,16 @@ def _fill_reversed_filter_value(runtime_filters, i):
datatype_index = dao.get_datatype_by_gid(runtime_filters['runtime_reverse_filtering_values'][i])
if datatype_index:
linked_datatype_field = runtime_filters['runtime_values'][i]
linked_datatype_gid = getattr(datatype_index, linked_datatype_field)
split_linked_datatype_field = linked_datatype_field.split(':')
linked_datatype_gid = getattr(datatype_index, split_linked_datatype_field[0])
linked_datatype_index = dao.get_datatype_by_gid(linked_datatype_gid)
filter_field = runtime_filters['runtime_fields'][i].replace(FilterChain.datatype + '.', '')

filter_value = getattr(linked_datatype_index, filter_field)
runtime_filters['runtime_values'][i] = filter_value
runtime_filters['runtime_fields'][i] = FilterChain.datatype + '.' + (split_linked_datatype_field[1] if
len(split_linked_datatype_field) > 1
else filter_field)

@expose_fragment('form_fields/options_field')
@settings
Expand Down Expand Up @@ -327,7 +332,7 @@ def get_runtime_filtered_form(self, algorithm_id, default_filters, user_filters,
values=user_filters['user_values'])
runtime_filters = runtime_filter_dict[key]
runtime_filter_values_copy = runtime_filters['runtime_values'].copy()

runtime_filter_fields_copy = runtime_filters['runtime_fields'].copy()
for i in range(len(runtime_filters['runtime_fields'])):
if (len(runtime_filters['runtime_reverse_filtering_values'][i])) > 0:
self._fill_reversed_filter_value(runtime_filters, i)
Expand All @@ -345,6 +350,7 @@ def get_runtime_filtered_form(self, algorithm_id, default_filters, user_filters,

if select_field_attr.runtime_conditions:
select_field_attr.runtime_conditions[1].values = runtime_filter_values_copy
select_field_attr.runtime_conditions[1].fields = runtime_filter_fields_copy

return {'adapter_form': form}

Expand Down
11 changes: 4 additions & 7 deletions framework_tvb/tvb/interfaces/web/static/js/filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,11 +103,7 @@ function _FIL_gatherData(divId, uiValue){
if (children[i].className.endsWith('runtime_trigger')) {
let value_from_field = $('#' + children[i].className.replace('_runtime_trigger', '')).val();
if(value === "default_runtime_value"){
if (!uiValue) {
value = value_from_field;
} else {
value = uiValue;
}
value = value_from_field;
runtime_reverse_filtering_values.push('');
}else{
runtime_reverse_filtering_values.push(value_from_field);
Expand Down Expand Up @@ -192,7 +188,7 @@ function applyUserFilters(datatypeIndex, divId, name, gatheredData) {
});
}

function applyRuntimeFilters(name, selected_value, dynamic_filters){
function applyRuntimeFilters(name, selected_value){

if($('.' + name + '_runtime_trigger').length === 0){
return;
Expand Down Expand Up @@ -241,7 +237,8 @@ function applyRuntimeFilters(name, selected_value, dynamic_filters){
for(var key in fields_and_user_filters){
const divId = key + 'data_select';
for(var i=0; i<fields_and_user_filters[key]['user_fields'].length; i++) {
addFilter(divId, dynamic_filters);
let field_df = JSON.parse($('#' + key + '_df').val());
addFilter(divId, field_df);
var children = $('#'+divId).children('div');
var elem = children[children.length - 1].children;
elem[1].value = fields_and_user_filters[key]['user_fields'][i];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<p class="field-data">
<select name="{{ field.name }}" id="{{ field.name }}" class="dataset-selector" tabindex="1" title="Fully Loaded!"
onchange="applyRuntimeFilters('{{ field.name }}', this.value, {{ field.get_dynamic_filters }})">
onchange="applyRuntimeFilters('{{ field.name }}', this.value)">
{% for option in field.options() %}
<option value="{{ option.value }}" {{ 'selected' if option.checked }} class="form-control">{{ option.label }}</option>
{% endfor %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
{% for field in adapter_form.fields %}
<dt {% if field.label_classes %} class="{{ field.label_classes|join(' ') }}" {% endif %}>
<label for="{{ field.name }}">{{ field.label }}</label>
<input id="{{ field.name }}_df" type="hidden" value='{{ field.get_dynamic_filters }}'>
{{ ght.generate_help_tooltip(field) }}
</dt>
<dd>
Expand Down

0 comments on commit cc87b1c

Please sign in to comment.