Let providers add extra views, options for includes config

This commit is contained in:
Lance Edgar 2022-03-06 19:03:08 -06:00
parent c4e872c94c
commit d18bade951
2 changed files with 77 additions and 29 deletions

View file

@ -7,21 +7,14 @@
NB.  Any changes made here will require an app restart!
</p>
<h3 class="block is-size-3">Tailbone Views</h3>
<h4 class="block is-size-4">People</h4>
% for key, label in view_settings['people']:
${self.simple_flag(key, label)}
% endfor
<h4 class="block is-size-4">Products</h4>
% for key, label in view_settings['products']:
${self.simple_flag(key, label)}
% endfor
<h4 class="block is-size-4">Other</h4>
% for key, label in view_settings['other']:
${self.simple_flag(key, label)}
% for topkey, topgroup in sorted(view_settings.items(), key=lambda itm: 'aaaa' if itm[0] == 'rattail' else itm[0]):
<h3 class="block is-size-3">Views for:&nbsp; ${topkey}</h3>
% for group_key, group in six.iteritems(topgroup):
<h4 class="block is-size-4">${group_key.capitalize()}</h4>
% for key, label in group:
${self.simple_flag(key, label)}
% endfor
% endfor
% endfor
</%def>
@ -32,7 +25,9 @@
v-model="simpleSettings['tailbone.includes.${key}']"
@input="settingsNeedSaved = true">
<option :value="null">(disabled)</option>
<option value="${key}">${key}</option>
% for option in view_options[key]:
<option value="${option}">${option}</option>
% endfor
</b-select>
</b-field>
</%def>

View file

@ -31,6 +31,7 @@ import six
import colander
from .master import PoserMasterView
from tailbone.providers import get_all_providers
class PoserViewView(PoserMasterView):
@ -94,7 +95,7 @@ class PoserViewView(PoserMasterView):
# TODO: this probably should be more dynamic? definitely need
# to let integration packages register some more options...
return {
everything = {'rattail': {
'people': {
@ -181,16 +182,59 @@ class PoserViewView(PoserMasterView):
'label': "Taxes",
},
},
}
}}
for key, views in six.iteritems(everything['rattail']):
for vkey, view in six.iteritems(views):
view['options'] = [vkey]
providers = get_all_providers(self.rattail_config)
for provider in six.itervalues(providers):
# loop thru provider top-level groups
for topkey, groups in six.iteritems(provider.get_provided_views()):
# get or create top group
topgroup = everything.setdefault(topkey, {})
# loop thru provider view groups
for key, views in six.iteritems(groups):
# add group to top group, if it's new
if key not in topgroup:
topgroup[key] = views
# also must init the options for group
for vkey, view in six.iteritems(views):
view['options'] = [vkey]
else: # otherwise must "update" existing group
# get ref to existing ("standard") group
stdgroup = topgroup[key]
# loop thru views within provider group
for vkey, view in six.iteritems(views):
# add view to group if it's new
if vkey not in stdgroup:
view['options'] = [vkey]
stdgroup[vkey] = view
else: # otherwise "update" existing view
stdgroup[vkey]['options'].append(view['spec'])
return everything
def configure_get_simple_settings(self):
settings = []
view_settings = self.collect_available_view_settings()
for view_section, section_settings in six.iteritems(view_settings):
for key in section_settings:
settings.append({'section': 'tailbone.includes',
'option': key})
for topgroup in six.itervalues(view_settings):
for view_section, section_settings in six.iteritems(topgroup):
for key in section_settings:
settings.append({'section': 'tailbone.includes',
'option': key})
return settings
@ -202,14 +246,23 @@ class PoserViewView(PoserMasterView):
simple_settings=simple_settings,
input_file_templates=input_file_templates)
# add available settings as sorted (key, label) options
# first add available options
view_settings = self.collect_available_view_settings()
for key in list(view_settings):
settings = view_settings[key]
settings = [(key, setting['label'])
for key, setting in six.iteritems(settings)]
settings.sort(key=lambda itm: itm[1])
view_settings[key] = settings
view_options = {}
for topgroup in six.itervalues(view_settings):
for key, views in six.iteritems(topgroup):
for vkey, view in six.iteritems(views):
view_options[vkey] = view['options']
context['view_options'] = view_options
# then add all available settings as sorted (key, label) options
for topkey, topgroup in six.iteritems(view_settings):
for key in list(topgroup):
settings = topgroup[key]
settings = [(key, setting['label'])
for key, setting in six.iteritems(settings)]
settings.sort(key=lambda itm: itm[1])
topgroup[key] = settings
context['view_settings'] = view_settings
return context