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,
|
||||
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.order_queryset import order_issue_queryset
|
||||
from plane.utils.paginator import GroupedOffsetPaginator
|
||||
|
||||
|
||||
class GlobalViewViewSet(BaseViewSet):
|
||||
@ -158,49 +164,44 @@ class GlobalViewIssuesViewSet(BaseViewSet):
|
||||
issue_queryset=issue_queryset, order_by_param=order_by_param
|
||||
)
|
||||
|
||||
def on_results(issues):
|
||||
if self.expand or self.fields:
|
||||
return IssueSerializer(
|
||||
issues, many=True, expand=self.expand, fields=self.fields
|
||||
).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",
|
||||
)
|
||||
# Group by
|
||||
group_by = request.GET.get("group_by", False)
|
||||
issue_queryset = issue_queryset_grouper(
|
||||
queryset=issue_queryset, field=group_by
|
||||
)
|
||||
|
||||
if request.GET.get("layout", "spreadsheet") in [
|
||||
"layout",
|
||||
"spreadsheet",
|
||||
]:
|
||||
# List Paginate
|
||||
if not group_by:
|
||||
return self.paginate(
|
||||
request=request,
|
||||
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):
|
||||
|
@ -1,12 +1,19 @@
|
||||
# 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.fields import ArrayField
|
||||
from django.db.models import Value, UUIDField
|
||||
from django.db.models.functions import Coalesce
|
||||
|
||||
# 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):
|
||||
@ -136,26 +143,53 @@ def issue_on_results(issues, group_by):
|
||||
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":
|
||||
return list(State.objects.filter( workspace__slug=slug, project_id=project_id
|
||||
).values_list("id", flat=True))
|
||||
queryset = State.objects.filter(
|
||||
~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":
|
||||
return list(Label.objects.filter(
|
||||
workspace__slug=slug, project_id=project_id
|
||||
).values_list("id", flat=True)) + ["None"]
|
||||
queryset = Label.objects.filter(workspace__slug=slug).values_list(
|
||||
"id", flat=True
|
||||
)
|
||||
if project_id:
|
||||
return list(queryset.filter(project_id=project_id)) + ["None"]
|
||||
else:
|
||||
return list(queryset) + ["None"]
|
||||
if field == "assignees__id":
|
||||
return list(ProjectMember.objects.filter(
|
||||
workspace__slug=slug, project_id=project_id, is_active=True,
|
||||
).values_list("member_id", flat=True)) + ["None"]
|
||||
if project_id:
|
||||
return ProjectMember.objects.filter(
|
||||
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":
|
||||
return list(Module.objects.filter(
|
||||
workspace__slug=slug, project_id=project_id
|
||||
).values_list("id", flat=True)) + ["None"]
|
||||
queryset = Module.objects.filter(
|
||||
workspace__slug=slug,
|
||||
).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":
|
||||
return list(Cycle.objects.filter(
|
||||
workspace__slug=slug, project_id=project_id
|
||||
).values_list("id", flat=True)) + ["None"]
|
||||
queryset = Cycle.objects.filter(
|
||||
workspace__slug=slug,
|
||||
).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":
|
||||
return ["low", "medium", "high", "urgent", "none"]
|
||||
return []
|
||||
|
@ -327,7 +327,8 @@ class GroupedOffsetPaginator(OffsetPaginator):
|
||||
processed_results = self.__get_field_dict()
|
||||
for result in results:
|
||||
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
|
||||
|
||||
def process_results(self, results):
|
||||
|
Loading…
Reference in New Issue
Block a user