Skip to content

Commit

Permalink
Merge pull request #1041 from rdmorganiser/dev-2.2.0-section-progress
Browse files Browse the repository at this point in the history
Dev 2.2.0 section progress
  • Loading branch information
jochenklar authored Jul 11, 2024
2 parents 57896f7 + 2d5e230 commit 0ca7a28
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
25 changes: 16 additions & 9 deletions rdmo/projects/progress.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,21 +54,28 @@ def compute_navigation(section, project, snapshot=None):
'id': catalog_section.id,
'uri': catalog_section.uri,
'title': markdown2html(catalog_section.short_title or catalog_section.title),
'first': catalog_section.elements[0].id if catalog_section.elements else None
'first': catalog_section.elements[0].id if catalog_section.elements else None,
'count': 0,
'total': 0
}
if catalog_section.id == section.id:
navigation_section['pages'] = []
for page in catalog_section.elements:
pages_conditions = {page.id for page in page.conditions.all()}
show = bool(not pages_conditions or pages_conditions.intersection(conditions))

# count the total number of questions, taking sets and conditions into account
counts = count_questions(page, sets, conditions)
for page in catalog_section.elements:
pages_conditions = {page.id for page in page.conditions.all()}
show = bool(not pages_conditions or pages_conditions.intersection(conditions))

# filter the values_list for the attributes, and compute the total sum of counts
count = len(tuple(filter(lambda value: value[0] in counts.keys(), values_list)))
total = sum(counts.values())
# count the total number of questions, taking sets and conditions into account
counts = count_questions(page, sets, conditions)

# filter the values_list for the attributes, and compute the total sum of counts
count = len(tuple(filter(lambda value: value[0] in counts.keys(), values_list)))
total = sum(counts.values())

navigation_section['count'] += count
navigation_section['total'] += total

if 'pages' in navigation_section:
navigation_section['pages'].append({
'id': page.id,
'uri': page.uri,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@
<li ng-repeat="section in service.navigation">
<a href="" ng-click="service.jump(section)">
<span ng-bind-html="section.title"></span>
<span ng-show="section.count > 0 && section.count == section.total">
<i class="fa fa-check" aria-hidden="true"></i>
</span>
<span ng-show="section.count > 0 && section.count != section.total">
{% blocktrans with section_count='{$ section.count $}' section_total='{$ section.total $}' trimmed %}
({{ section_count }} of {{ section_total }})
{% endblocktrans %}
</span>
</a>

<ul class="list-unstyled"
Expand All @@ -25,7 +33,7 @@
{% endblocktrans %}
</span>
</a>
<span class="text-muted" ng-hide="page.show">{$ page.title $}<span>
<span class="text-muted" ng-hide="page.show">{$ page.title $}</span>
</li>
</ul>
</li>
Expand Down
26 changes: 20 additions & 6 deletions rdmo/projects/tests/test_navigation.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,18 @@

# (count, total, show) for each page or section (as default fallback)
result_map = {
'http://example.com/terms/questions/catalog/individual': (1, 1, True),
'http://example.com/terms/questions/catalog/individual': (8, 9),
'http://example.com/terms/questions/catalog/individual/*': (1, 1, True),
'http://example.com/terms/questions/catalog/individual/autocomplete': (0, 1, True),
'http://example.com/terms/questions/catalog/collections': (1, 1, True),
'http://example.com/terms/questions/catalog/collections': (9, 10),
'http://example.com/terms/questions/catalog/collections/*': (1, 1, True),
'http://example.com/terms/questions/catalog/collections/autocomplete': (0, 1, True),
'http://example.com/terms/questions/catalog/set': (47, 57),
'http://example.com/terms/questions/catalog/set/individual-single': (8, 9, True),
'http://example.com/terms/questions/catalog/set/individual-collection': (9, 10, True),
'http://example.com/terms/questions/catalog/set/collection-single': (14, 18, True),
'http://example.com/terms/questions/catalog/set/collection-collection': (16, 20, True),
'http://example.com/terms/questions/catalog/conditions': (15, 23),
'http://example.com/terms/questions/catalog/conditions/input': (2, 2, True),
'http://example.com/terms/questions/catalog/conditions/text_contains': (1, 1, True),
'http://example.com/terms/questions/catalog/conditions/text_empty': (1, 1, False),
Expand All @@ -39,6 +43,7 @@
'http://example.com/terms/questions/catalog/conditions/set_set': (0, 2, True),
'http://example.com/terms/questions/catalog/conditions/optionset': (0, 2, True),
'http://example.com/terms/questions/catalog/conditions/text_set': (0, 2, True),
'http://example.com/terms/questions/catalog/blocks': (9, 12),
'http://example.com/terms/questions/catalog/blocks/set': (9, 12, True),
}

Expand All @@ -54,14 +59,23 @@ def test_compute_navigation(db, section_uri):
assert [item['id'] for item in navigation] == [element.id for element in project.catalog.elements]

for section in navigation:
if section['uri'] in result_map:
count, total = result_map[section['uri']]
assert section['count'] == count, section['uri']
assert section['total'] == total, section['uri']

if 'pages' in section:
for page in section['pages']:
if page['uri'] in result_map:
count, total, show = result_map[page['uri']]
elif section['uri'] in result_map:
count, total, show = result_map[section['uri']]
uri = page['uri']
wildcard_uri = section['uri'] + '/*'

if uri in result_map:
count, total, show = result_map[uri]
elif wildcard_uri in result_map:
count, total, show = result_map[wildcard_uri]
else:
raise AssertionError('{uri} not in result_map'.format(**page))

assert page['count'] == count, page['uri']
assert page['total'] == total, page['uri']
assert page['show'] == show, page['uri']

0 comments on commit 0ca7a28

Please sign in to comment.