mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
dev: fix paginating true list
This commit is contained in:
parent
a123eea52f
commit
ffeb77ec86
@ -44,8 +44,14 @@ from plane.db.models import (
|
|||||||
IssueLink,
|
IssueLink,
|
||||||
IssueAttachment,
|
IssueAttachment,
|
||||||
)
|
)
|
||||||
|
from plane.utils.grouper import (
|
||||||
|
issue_queryset_grouper,
|
||||||
|
issue_on_results,
|
||||||
|
issue_group_values,
|
||||||
|
)
|
||||||
from plane.utils.issue_filters import issue_filters
|
from plane.utils.issue_filters import issue_filters
|
||||||
from plane.utils.order_queryset import order_issue_queryset
|
from plane.utils.order_queryset import order_issue_queryset
|
||||||
|
from plane.utils.paginator import GroupedOffsetPaginator
|
||||||
|
|
||||||
|
|
||||||
class GlobalViewViewSet(BaseViewSet):
|
class GlobalViewViewSet(BaseViewSet):
|
||||||
@ -158,49 +164,44 @@ class GlobalViewIssuesViewSet(BaseViewSet):
|
|||||||
issue_queryset=issue_queryset, order_by_param=order_by_param
|
issue_queryset=issue_queryset, order_by_param=order_by_param
|
||||||
)
|
)
|
||||||
|
|
||||||
def on_results(issues):
|
# Group by
|
||||||
if self.expand or self.fields:
|
group_by = request.GET.get("group_by", False)
|
||||||
return IssueSerializer(
|
issue_queryset = issue_queryset_grouper(
|
||||||
issues, many=True, expand=self.expand, fields=self.fields
|
queryset=issue_queryset, field=group_by
|
||||||
).data
|
)
|
||||||
return issues.values(
|
|
||||||
"id",
|
|
||||||
"name",
|
|
||||||
"state_id",
|
|
||||||
"sort_order",
|
|
||||||
"completed_at",
|
|
||||||
"estimate_point",
|
|
||||||
"priority",
|
|
||||||
"start_date",
|
|
||||||
"target_date",
|
|
||||||
"sequence_id",
|
|
||||||
"project_id",
|
|
||||||
"parent_id",
|
|
||||||
"cycle_id",
|
|
||||||
"module_ids",
|
|
||||||
"label_ids",
|
|
||||||
"assignee_ids",
|
|
||||||
"sub_issues_count",
|
|
||||||
"created_at",
|
|
||||||
"updated_at",
|
|
||||||
"created_by",
|
|
||||||
"updated_by",
|
|
||||||
"attachment_count",
|
|
||||||
"link_count",
|
|
||||||
"is_draft",
|
|
||||||
"archived_at",
|
|
||||||
)
|
|
||||||
|
|
||||||
if request.GET.get("layout", "spreadsheet") in [
|
# List Paginate
|
||||||
"layout",
|
if not group_by:
|
||||||
"spreadsheet",
|
|
||||||
]:
|
|
||||||
return self.paginate(
|
return self.paginate(
|
||||||
request=request,
|
request=request,
|
||||||
queryset=issue_queryset,
|
queryset=issue_queryset,
|
||||||
on_results=on_results
|
on_results=lambda issues: issue_on_results(
|
||||||
|
group_by=group_by, issues=issues
|
||||||
|
),
|
||||||
)
|
)
|
||||||
return on_results(issues=issue_queryset)
|
|
||||||
|
# Group paginate
|
||||||
|
return self.paginate(
|
||||||
|
request=request,
|
||||||
|
queryset=issue_queryset,
|
||||||
|
on_results=lambda issues: issue_on_results(
|
||||||
|
group_by=group_by, issues=issues
|
||||||
|
),
|
||||||
|
group_by_fields=issue_group_values(
|
||||||
|
field=group_by,
|
||||||
|
slug=slug,
|
||||||
|
),
|
||||||
|
paginator_cls=GroupedOffsetPaginator,
|
||||||
|
group_by_field_name=group_by,
|
||||||
|
count_filter=Q(
|
||||||
|
Q(issue_inbox__status=1)
|
||||||
|
| Q(issue_inbox__status=-1)
|
||||||
|
| Q(issue_inbox__status=2)
|
||||||
|
| Q(issue_inbox__isnull=True),
|
||||||
|
archived_at__isnull=False,
|
||||||
|
is_draft=True,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class IssueViewViewSet(BaseViewSet):
|
class IssueViewViewSet(BaseViewSet):
|
||||||
|
@ -1,12 +1,19 @@
|
|||||||
# Django imports
|
# Django imports
|
||||||
from django.db.models import Q, F, QuerySet
|
from django.db.models import Q, F
|
||||||
from django.contrib.postgres.aggregates import ArrayAgg
|
from django.contrib.postgres.aggregates import ArrayAgg
|
||||||
from django.contrib.postgres.fields import ArrayField
|
from django.contrib.postgres.fields import ArrayField
|
||||||
from django.db.models import Value, UUIDField
|
from django.db.models import Value, UUIDField
|
||||||
from django.db.models.functions import Coalesce
|
from django.db.models.functions import Coalesce
|
||||||
|
|
||||||
# Module imports
|
# Module imports
|
||||||
from plane.db.models import State, Label, ProjectMember, Cycle, Module
|
from plane.db.models import (
|
||||||
|
State,
|
||||||
|
Label,
|
||||||
|
ProjectMember,
|
||||||
|
Cycle,
|
||||||
|
Module,
|
||||||
|
WorkspaceMember,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
def issue_queryset_grouper(field, queryset):
|
def issue_queryset_grouper(field, queryset):
|
||||||
@ -136,26 +143,53 @@ def issue_on_results(issues, group_by):
|
|||||||
return issues.values(*required_fields)
|
return issues.values(*required_fields)
|
||||||
|
|
||||||
|
|
||||||
def issue_group_values(field, slug, project_id):
|
def issue_group_values(field, slug, project_id=None):
|
||||||
if field == "state_id":
|
if field == "state_id":
|
||||||
return list(State.objects.filter( workspace__slug=slug, project_id=project_id
|
queryset = State.objects.filter(
|
||||||
).values_list("id", flat=True))
|
~Q(name="Triage"),
|
||||||
|
workspace__slug=slug,
|
||||||
|
).values_list("id", flat=True)
|
||||||
|
if project_id:
|
||||||
|
return list(queryset.filter(project_id=project_id))
|
||||||
|
else:
|
||||||
|
return list(queryset)
|
||||||
if field == "labels__id":
|
if field == "labels__id":
|
||||||
return list(Label.objects.filter(
|
queryset = Label.objects.filter(workspace__slug=slug).values_list(
|
||||||
workspace__slug=slug, project_id=project_id
|
"id", flat=True
|
||||||
).values_list("id", flat=True)) + ["None"]
|
)
|
||||||
|
if project_id:
|
||||||
|
return list(queryset.filter(project_id=project_id)) + ["None"]
|
||||||
|
else:
|
||||||
|
return list(queryset) + ["None"]
|
||||||
if field == "assignees__id":
|
if field == "assignees__id":
|
||||||
return list(ProjectMember.objects.filter(
|
if project_id:
|
||||||
workspace__slug=slug, project_id=project_id, is_active=True,
|
return ProjectMember.objects.filter(
|
||||||
).values_list("member_id", flat=True)) + ["None"]
|
workspace__slug=slug,
|
||||||
|
project_id=project_id,
|
||||||
|
is_active=True,
|
||||||
|
).values_list("member_id", flat=True)
|
||||||
|
else:
|
||||||
|
return list(
|
||||||
|
WorkspaceMember.objects.filter(
|
||||||
|
workspace__slug=slug, is_active=True
|
||||||
|
).values_list("member_id", flat=True)
|
||||||
|
)
|
||||||
if field == "modules__id":
|
if field == "modules__id":
|
||||||
return list(Module.objects.filter(
|
queryset = Module.objects.filter(
|
||||||
workspace__slug=slug, project_id=project_id
|
workspace__slug=slug,
|
||||||
).values_list("id", flat=True)) + ["None"]
|
).values_list("id", flat=True)
|
||||||
|
if project_id:
|
||||||
|
return list(queryset.filter(project_id=project_id)) + ["None"]
|
||||||
|
else:
|
||||||
|
return list(queryset) + ["None"]
|
||||||
if field == "cycle_id":
|
if field == "cycle_id":
|
||||||
return list(Cycle.objects.filter(
|
queryset = Cycle.objects.filter(
|
||||||
workspace__slug=slug, project_id=project_id
|
workspace__slug=slug,
|
||||||
).values_list("id", flat=True)) + ["None"]
|
).values_list("id", flat=True)
|
||||||
|
if project_id:
|
||||||
|
return list(queryset.filter(project_id=project_id)) + ["None"]
|
||||||
|
else:
|
||||||
|
return list(queryset) + ["None"]
|
||||||
if field == "priority":
|
if field == "priority":
|
||||||
return ["low", "medium", "high", "urgent", "none"]
|
return ["low", "medium", "high", "urgent", "none"]
|
||||||
return []
|
return []
|
||||||
|
@ -327,7 +327,8 @@ class GroupedOffsetPaginator(OffsetPaginator):
|
|||||||
processed_results = self.__get_field_dict()
|
processed_results = self.__get_field_dict()
|
||||||
for result in results:
|
for result in results:
|
||||||
group_value = str(result.get(self.group_by_field_name))
|
group_value = str(result.get(self.group_by_field_name))
|
||||||
processed_results[str(group_value)]["results"].append(result)
|
if group_value in processed_results:
|
||||||
|
processed_results[str(group_value)]["results"].append(result)
|
||||||
return processed_results
|
return processed_results
|
||||||
|
|
||||||
def process_results(self, results):
|
def process_results(self, results):
|
||||||
|
Loading…
Reference in New Issue
Block a user