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

Add Filters to the Products under View Product Type #11321

Merged
merged 6 commits into from
Dec 4, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
18 changes: 14 additions & 4 deletions dojo/product_type/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from dojo.authorization.authorization import user_has_permission
from dojo.authorization.authorization_decorators import user_has_global_permission, user_is_authorized
from dojo.authorization.roles_permissions import Permissions
from dojo.filters import ProductTypeFilter
from dojo.filters import ProductFilter, ProductFilterWithoutObjectLookups, ProductTypeFilter
from dojo.forms import (
Add_Product_Type_GroupForm,
Add_Product_Type_MemberForm,
Expand All @@ -38,6 +38,7 @@
async_delete,
get_page_items,
get_setting,
get_system_setting,
is_title_in_breadcrumbs,
)

Expand All @@ -51,7 +52,6 @@


def product_type(request):

prod_types = get_authorized_product_types(Permissions.Product_Type_View)
name_words = prod_types.values_list("name", flat=True)

Expand Down Expand Up @@ -116,23 +116,33 @@ def add_product_type(request):

@user_is_authorized(Product_Type, Permissions.Product_Type_View, "ptid")
def view_product_type(request, ptid):
msg = f"\n\n\n\n\n\nName: {request.GET}\n\n\n\n\n\n"
logger.info(msg)

page_name = _("View Product Type")
pt = get_object_or_404(Product_Type, pk=ptid)
members = get_authorized_members_for_product_type(pt, Permissions.Product_Type_View)
global_members = get_authorized_global_members_for_product_type(pt, Permissions.Product_Type_View)
groups = get_authorized_groups_for_product_type(pt, Permissions.Product_Type_View)
global_groups = get_authorized_global_groups_for_product_type(pt, Permissions.Product_Type_View)
products = get_authorized_products(Permissions.Product_View).filter(prod_type=pt)
products = get_page_items(request, products, 25)
filter_string_matching = get_system_setting("filter_string_matching", False)
filter_class = ProductFilterWithoutObjectLookups if filter_string_matching else ProductFilter
prod_filter = filter_class(request.GET, queryset=products, user=request.user)
name_words = products.values_list("name", flat=True)

add_breadcrumb(title=page_name, top_level=False, request=request)
return render(request, "dojo/view_product_type.html", {
"name": page_name,
"pt": pt,
"products": products,
"prod_list": products,
"groups": groups,
"members": members,
"global_groups": global_groups,
"global_members": global_members,
"prod_filter": prod_filter,
"name_words": sorted(set(name_words)),
"enable_table_filtering": get_system_setting("enable_ui_table_based_searching"),
})


Expand Down
73 changes: 53 additions & 20 deletions dojo/templates/dojo/view_product_type.html
Original file line number Diff line number Diff line change
Expand Up @@ -53,31 +53,39 @@ <h3 class="pull-left">{% trans "Description" %}</h3>
<div class="panel panel-default">
<div class="panel-heading">
<div class="clearfix">
<h4 class="pull-left">{% trans "Products" %}</h4>
{% if pt|has_object_permission:"Product_Type_Add_Product" %}
<div class="dropdown pull-right">
<div class="btn-group">
<button class="btn btn-primary dropdown-toggle" type="button" label="Actions" id="dropdownMenu1" data-toggle="dropdown" aria-expanded="true">
<span class="fa-solid fa-bars"></span>
<span class="caret"></span>
<h3 class="has-filters">
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
<h4 class="pull-left">{% trans "Products" %}</h4>

<div class="dropdown pull-right">
<button id="show-filters" data-toggle="collapse" data-target="#the-filters" class="btn btn-primary toggle-filters"> <i class="fa-solid fa-filter"></i> <i class="caret"></i> </button>
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
<button class="btn btn-primary dropdown-toggle" type="button" id="dropdownMenu1"
hblankenship marked this conversation as resolved.
Show resolved Hide resolved
data-toggle="dropdown" aria-expanded="true">
<span class="fa-solid fa-screwdriver-wrench"></span>
<span class="caret"></span>
</button>
<ul class="dropdown-menu dropdown-menu-right" role="menu" aria-labelledby="dropdownMenu1">
<li>
<a class="" href="{% url 'add_product_to_product_type' pt.id %}">
<i class="fa-solid fa-plus"></i> {% trans "Add Product" %}</a>
</li>
{% if pt|has_object_permission:"Product_Type_Add_Product" %}
<ul class="dropdown-menu dropdown-menu-right" role="menu"
aria-labelledby="dropdownMenu1">
<li role="presentation">
<a href="{% url 'new_product' %}">
<i class="fa-solid fa-plus"></i> {% trans "Add Product" %}
</a>
</li>
</ul>
{% endif %}
</div>
</div>
{% endif %}
</h3>
</div>
</div>
{% if products %}
<div id="the-filters" class="is-filters panel-body collapse {% if prod_filter.form.has_changed %}in{% endif %}">
{% include "dojo/filter_snippet.html" with form=prod_filter.form %}
</div>
{% if prod_list %}
<div class="clearfix pagination-in-panel">
{% include "dojo/paging_snippet.html" with page=products page_size=True %}
{% include "dojo/paging_snippet.html" with page=prod_list page_size=True %}
</div>
<div class="table-responsive">
<table class="tablesorter-bootstrap table table-condensed table-striped">
<table id="products" class="tablesorter-bootstrap table table-condensed table-striped">
<thead>
<tr>
<th>Name</th>
Expand All @@ -88,12 +96,12 @@ <h4 class="pull-left">{% trans "Products" %}</h4>
</tr>
</thead>
<tbody>
{% for product in products %}
{% for product in prod_list %}
<tr>
<td><a href="{% url 'view_product' product.id %}">{{ product.name }}</a></td>
<!-- Tags column -->
<td class="text-center">
{% include "dojo/snippets/tags.html" with tags=product.tags.all %}
{% include "dojo/snippets/tags.html" with tags=product.tags.all %}
</td>
<!-- End of Tags Column -->
<td class="text-center">{{ product.business_criticality|business_criticality_icon }}</td>
Expand All @@ -118,7 +126,7 @@ <h4 class="pull-left">{% trans "Products" %}</h4>
</table>
</div>
<div class="clearfix pagination-in-panel">
{% include "dojo/paging_snippet.html" with page=products page_size=True %}
{% include "dojo/paging_snippet.html" with page=prod_list page_size=True %}
</div>
{% else %}
<div class="panel-body">
Expand Down Expand Up @@ -325,3 +333,28 @@ <h3 class="panel-title"><span class="fa-solid fa-circle-info fa-fw" aria-hidden=
</div>
</div>
{% endblock %}
{% block postscript %}
{{ block.super }}
<script>
$(function () {
//Ensures dropdown has proper zindex
$('.table-responsive').on('show.bs.dropdown', function () {
$('.table-responsive').css( "overflow", "inherit" );
});

$('.table-responsive').on('hide.bs.dropdown', function () {
$('.table-responsive').css( "overflow", "auto" );
})
var availableTags = [
{% for word in name_words %}
"{{word}}",
{% endfor %}
];
$("#id_name").autocomplete({
source: availableTags
});
});
</script>

{% include "dojo/filter_js_snippet.html" %}
{% endblock %}