Skip to content

Commit

Permalink
Add some navigation counts in Dependencies UI #138
Browse files Browse the repository at this point in the history
Signed-off-by: tdruez <[email protected]>
  • Loading branch information
tdruez committed Jul 25, 2024
1 parent 6d3f4ce commit 0d5592c
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@
<button type="button" data-bs-toggle="tooltip" title="Edit" class="btn btn-link p-0" aria-label="Edit object"><i class="far fa-edit fa-sm"></i></button>
</span>
{% endif %}
{% if relation.package_id and relation.package.declared_dependencies.exists %}
<a href="{{ product.get_absolute_url }}?dependencies-for_package__uuid={{ relation.package.uuid }}#dependencies" class="ms-1" data-bs-toggle="tooltip" title="Dependencies" aria-label="Dependencies"><i class="fa-solid fa-share-nodes"></i></a>
{% if relation.package_id and relation.package.declared_dependencies.all %}
<a class="btn badge text-bg-primary rounded-pill ms-1"
href="{{ product.get_absolute_url }}?dependencies-for_package__uuid={{ relation.package.uuid }}#dependencies" class="ms-1" data-bs-toggle="tooltip" title="Dependencies" aria-label="Dependencies">
{{ relation.package.declared_dependencies.all|length }}<i class="fa-solid fa-share-nodes ms-1"></i>
</a>
{% endif %}
{% elif instance.is_active or is_product %}
<a href="{{ instance.get_absolute_url }}#hierarchy">{{ instance }}</a>
Expand Down
11 changes: 10 additions & 1 deletion product_portfolio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,6 +1318,15 @@ def notify(self, verb, description):
)


class ProductDependencyQuerySet(ProductSecuredQuerySet):
def with_resolved_to_dependencies_count(self):
return self.annotate(
resolved_to_dependencies_count=models.Count(
"resolved_to_package__declared_dependencies"
)
)


class ProductDependency(HistoryFieldsMixin, DataspacedModel):
product = models.ForeignKey(
to="product_portfolio.Product",
Expand Down Expand Up @@ -1384,7 +1393,7 @@ class ProductDependency(HistoryFieldsMixin, DataspacedModel):
help_text=_("True if this is a direct, first-level dependency relationship for a package."),
)

objects = DataspacedManager.from_queryset(ProductSecuredQuerySet)()
objects = DataspacedManager.from_queryset(ProductDependencyQuerySet)()

class Meta:
unique_together = (("product", "dependency_uid"), ("dataspace", "uuid"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,10 @@
<button type="button" data-bs-toggle="tooltip" title="Edit" class="btn btn-link p-0" aria-label="Edit object"><i class="far fa-edit fa-sm"></i></button>
</span>
{% endif %}
{% if relation.package_id and relation.package.declared_dependencies.exists %}
<a href="{{ product.get_absolute_url }}?dependencies-for_package__uuid={{ relation.package.uuid }}#dependencies" class="ms-1" data-bs-toggle="tooltip" title="Dependencies" aria-label="Dependencies"><i class="fa-solid fa-share-nodes"></i></a>
{% if relation.package_id and relation.package.declared_dependencies.all %}
<a class="btn badge text-bg-primary rounded-pill ms-1"
href="{{ product.get_absolute_url }}?dependencies-for_package__uuid={{ relation.package.uuid }}#dependencies" class="ms-1" data-bs-toggle="tooltip" title="Dependencies" aria-label="Dependencies">
{{ relation.package.declared_dependencies.all|length }}<i class="fa-solid fa-share-nodes ms-1"></i>
</a>
{% endif %}
{% endspaceless %}
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
</thead>
<tbody class="text-break">
{% for dependency in page_obj.object_list %}
<tr class="{% cycle 'odd' '' %}" title="{{ dependency.dependency_uid }}">
<tr class="{% cycle 'odd' '' %}">
<td>
{% if dependency.for_package %}
<strong>
Expand All @@ -110,6 +110,12 @@
{% if dependency.resolved_to_package %}
<strong>
<a href="{{ dependency.resolved_to_package.get_absolute_url }}" target="_blank">{{ dependency.resolved_to_package }}</a>
{% if dependency.resolved_to_dependencies_count %}
<a class="btn badge text-bg-primary rounded-pill ms-1"
href="{{ product.get_absolute_url }}?dependencies-for_package__uuid={{ dependency.resolved_to_package.uuid }}#dependencies" class="ms-1" data-bs-toggle="tooltip" title="Dependencies" aria-label="Dependencies">
{{ dependency.resolved_to_dependencies_count }}<i class="fa-solid fa-share-nodes ms-1"></i>
</a>
{% endif %}
</strong>
<div class="license-expression">
{{ dependency.resolved_to_package.license_expression_html|default_if_none:"" }}
Expand Down
14 changes: 13 additions & 1 deletion product_portfolio/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -409,12 +409,17 @@ def tab_hierarchy(self):
)
)

declared_dependencies_prefetch = models.Prefetch(
"package__declared_dependencies", ProductDependency.objects.all()
)

productpackage_qs = (
self.object.productpackages.select_related(
"package",
)
.prefetch_related(
"package__licenses",
declared_dependencies_prefetch,
)
.order_by(
"feature",
Expand Down Expand Up @@ -642,6 +647,9 @@ def get_context_data(self, **kwargs):
licenses_prefetch = models.Prefetch(
"licenses", License.objects.select_related("usage_policy")
)
declared_dependencies_prefetch = models.Prefetch(
"package__declared_dependencies", ProductDependency.objects.all()
)

productpackage_qs = (
self.object.productpackages.select_related(
Expand All @@ -652,6 +660,7 @@ def get_context_data(self, **kwargs):
)
.prefetch_related(
licenses_prefetch,
declared_dependencies_prefetch,
)
.order_by(
"feature",
Expand Down Expand Up @@ -967,7 +976,10 @@ def get_context_data(self, **kwargs):
prefix="dependencies",
)

paginator = Paginator(filter_dependency.qs, self.paginate_by)
# Annotate the filtered queryset with the count of declared_dependencies
filtered_and_annotated_qs = filter_dependency.qs.with_resolved_to_dependencies_count()

paginator = Paginator(filtered_and_annotated_qs, self.paginate_by)
page_number = self.request.GET.get(self.query_dict_page_param)
page_obj = paginator.get_page(page_number)

Expand Down

0 comments on commit 0d5592c

Please sign in to comment.