mirror of
https://github.com/makeplane/plane
synced 2024-06-14 14:31:34 +00:00
chore: updated pages response
This commit is contained in:
parent
8123ee8d3a
commit
f743386150
@ -2,7 +2,7 @@
|
|||||||
import re
|
import re
|
||||||
|
|
||||||
# Django imports
|
# Django imports
|
||||||
from django.db.models import Q
|
from django.db.models import Q, OuterRef, Exists
|
||||||
|
|
||||||
# Third party imports
|
# Third party imports
|
||||||
from rest_framework import status
|
from rest_framework import status
|
||||||
@ -18,6 +18,7 @@ from plane.db.models import (
|
|||||||
Module,
|
Module,
|
||||||
Page,
|
Page,
|
||||||
IssueView,
|
IssueView,
|
||||||
|
ProjectPage,
|
||||||
)
|
)
|
||||||
from plane.utils.issue_search import search_issues
|
from plane.utils.issue_search import search_issues
|
||||||
|
|
||||||
@ -154,7 +155,14 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
)
|
)
|
||||||
|
|
||||||
if workspace_search == "false" and project_id:
|
if workspace_search == "false" and project_id:
|
||||||
pages = pages.filter(project_id=project_id)
|
pages = pages.annotate(
|
||||||
|
project=Exists(
|
||||||
|
ProjectPage.objects.filter(
|
||||||
|
page_id=OuterRef("id"),
|
||||||
|
project_id=self.kwargs.get("project_id"),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
).filter(project=True)
|
||||||
|
|
||||||
return pages.distinct().values(
|
return pages.distinct().values(
|
||||||
"name",
|
"name",
|
||||||
@ -228,76 +236,3 @@ class GlobalSearchEndpoint(BaseAPIView):
|
|||||||
func = MODELS_MAPPER.get(model, None)
|
func = MODELS_MAPPER.get(model, None)
|
||||||
results[model] = func(query, slug, project_id, workspace_search)
|
results[model] = func(query, slug, project_id, workspace_search)
|
||||||
return Response({"results": results}, status=status.HTTP_200_OK)
|
return Response({"results": results}, status=status.HTTP_200_OK)
|
||||||
|
|
||||||
|
|
||||||
class IssueSearchEndpoint(BaseAPIView):
|
|
||||||
def get(self, request, slug, project_id):
|
|
||||||
query = request.query_params.get("search", False)
|
|
||||||
workspace_search = request.query_params.get(
|
|
||||||
"workspace_search", "false"
|
|
||||||
)
|
|
||||||
parent = request.query_params.get("parent", "false")
|
|
||||||
issue_relation = request.query_params.get("issue_relation", "false")
|
|
||||||
cycle = request.query_params.get("cycle", "false")
|
|
||||||
module = request.query_params.get("module", False)
|
|
||||||
sub_issue = request.query_params.get("sub_issue", "false")
|
|
||||||
target_date = request.query_params.get("target_date", True)
|
|
||||||
|
|
||||||
issue_id = request.query_params.get("issue_id", False)
|
|
||||||
|
|
||||||
issues = Issue.issue_objects.filter(
|
|
||||||
workspace__slug=slug,
|
|
||||||
project__project_projectmember__member=self.request.user,
|
|
||||||
project__project_projectmember__is_active=True,
|
|
||||||
project__archived_at__isnull=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
if workspace_search == "false":
|
|
||||||
issues = issues.filter(project_id=project_id)
|
|
||||||
|
|
||||||
if query:
|
|
||||||
issues = search_issues(query, issues)
|
|
||||||
|
|
||||||
if parent == "true" and issue_id:
|
|
||||||
issue = Issue.issue_objects.get(pk=issue_id)
|
|
||||||
issues = issues.filter(
|
|
||||||
~Q(pk=issue_id), ~Q(pk=issue.parent_id), ~Q(parent_id=issue_id)
|
|
||||||
)
|
|
||||||
if issue_relation == "true" and issue_id:
|
|
||||||
issue = Issue.issue_objects.get(pk=issue_id)
|
|
||||||
issues = issues.filter(
|
|
||||||
~Q(pk=issue_id),
|
|
||||||
~Q(issue_related__issue=issue),
|
|
||||||
~Q(issue_relation__related_issue=issue),
|
|
||||||
)
|
|
||||||
if sub_issue == "true" and issue_id:
|
|
||||||
issue = Issue.issue_objects.get(pk=issue_id)
|
|
||||||
issues = issues.filter(~Q(pk=issue_id), parent__isnull=True)
|
|
||||||
if issue.parent:
|
|
||||||
issues = issues.filter(~Q(pk=issue.parent_id))
|
|
||||||
|
|
||||||
if cycle == "true":
|
|
||||||
issues = issues.exclude(issue_cycle__isnull=False)
|
|
||||||
|
|
||||||
if module:
|
|
||||||
issues = issues.exclude(issue_module__module=module)
|
|
||||||
|
|
||||||
if target_date == "none":
|
|
||||||
issues = issues.filter(target_date__isnull=True)
|
|
||||||
|
|
||||||
return Response(
|
|
||||||
issues.values(
|
|
||||||
"name",
|
|
||||||
"id",
|
|
||||||
"start_date",
|
|
||||||
"sequence_id",
|
|
||||||
"project__name",
|
|
||||||
"project__identifier",
|
|
||||||
"project_id",
|
|
||||||
"workspace__slug",
|
|
||||||
"state__name",
|
|
||||||
"state__group",
|
|
||||||
"state__color",
|
|
||||||
),
|
|
||||||
status=status.HTTP_200_OK,
|
|
||||||
)
|
|
95
apiserver/plane/app/views/search/issue.py
Normal file
95
apiserver/plane/app/views/search/issue.py
Normal file
@ -0,0 +1,95 @@
|
|||||||
|
# Python imports
|
||||||
|
import re
|
||||||
|
|
||||||
|
# Django imports
|
||||||
|
from django.db.models import Q
|
||||||
|
|
||||||
|
# Third party imports
|
||||||
|
from rest_framework import status
|
||||||
|
from rest_framework.response import Response
|
||||||
|
|
||||||
|
# Module imports
|
||||||
|
from .base import BaseAPIView
|
||||||
|
from plane.db.models import (
|
||||||
|
Workspace,
|
||||||
|
Project,
|
||||||
|
Issue,
|
||||||
|
Cycle,
|
||||||
|
Module,
|
||||||
|
Page,
|
||||||
|
IssueView,
|
||||||
|
)
|
||||||
|
from plane.utils.issue_search import search_issues
|
||||||
|
|
||||||
|
|
||||||
|
class IssueSearchEndpoint(BaseAPIView):
|
||||||
|
def get(self, request, slug, project_id):
|
||||||
|
query = request.query_params.get("search", False)
|
||||||
|
workspace_search = request.query_params.get(
|
||||||
|
"workspace_search", "false"
|
||||||
|
)
|
||||||
|
parent = request.query_params.get("parent", "false")
|
||||||
|
issue_relation = request.query_params.get("issue_relation", "false")
|
||||||
|
cycle = request.query_params.get("cycle", "false")
|
||||||
|
module = request.query_params.get("module", False)
|
||||||
|
sub_issue = request.query_params.get("sub_issue", "false")
|
||||||
|
target_date = request.query_params.get("target_date", True)
|
||||||
|
|
||||||
|
issue_id = request.query_params.get("issue_id", False)
|
||||||
|
|
||||||
|
issues = Issue.issue_objects.filter(
|
||||||
|
workspace__slug=slug,
|
||||||
|
project__project_projectmember__member=self.request.user,
|
||||||
|
project__project_projectmember__is_active=True,
|
||||||
|
project__archived_at__isnull=True,
|
||||||
|
)
|
||||||
|
|
||||||
|
if workspace_search == "false":
|
||||||
|
issues = issues.filter(project_id=project_id)
|
||||||
|
|
||||||
|
if query:
|
||||||
|
issues = search_issues(query, issues)
|
||||||
|
|
||||||
|
if parent == "true" and issue_id:
|
||||||
|
issue = Issue.issue_objects.get(pk=issue_id)
|
||||||
|
issues = issues.filter(
|
||||||
|
~Q(pk=issue_id), ~Q(pk=issue.parent_id), ~Q(parent_id=issue_id)
|
||||||
|
)
|
||||||
|
if issue_relation == "true" and issue_id:
|
||||||
|
issue = Issue.issue_objects.get(pk=issue_id)
|
||||||
|
issues = issues.filter(
|
||||||
|
~Q(pk=issue_id),
|
||||||
|
~Q(issue_related__issue=issue),
|
||||||
|
~Q(issue_relation__related_issue=issue),
|
||||||
|
)
|
||||||
|
if sub_issue == "true" and issue_id:
|
||||||
|
issue = Issue.issue_objects.get(pk=issue_id)
|
||||||
|
issues = issues.filter(~Q(pk=issue_id), parent__isnull=True)
|
||||||
|
if issue.parent:
|
||||||
|
issues = issues.filter(~Q(pk=issue.parent_id))
|
||||||
|
|
||||||
|
if cycle == "true":
|
||||||
|
issues = issues.exclude(issue_cycle__isnull=False)
|
||||||
|
|
||||||
|
if module:
|
||||||
|
issues = issues.exclude(issue_module__module=module)
|
||||||
|
|
||||||
|
if target_date == "none":
|
||||||
|
issues = issues.filter(target_date__isnull=True)
|
||||||
|
|
||||||
|
return Response(
|
||||||
|
issues.values(
|
||||||
|
"name",
|
||||||
|
"id",
|
||||||
|
"start_date",
|
||||||
|
"sequence_id",
|
||||||
|
"project__name",
|
||||||
|
"project__identifier",
|
||||||
|
"project_id",
|
||||||
|
"workspace__slug",
|
||||||
|
"state__name",
|
||||||
|
"state__group",
|
||||||
|
"state__color",
|
||||||
|
),
|
||||||
|
status=status.HTTP_200_OK,
|
||||||
|
)
|
4
packages/types/src/pages.d.ts
vendored
4
packages/types/src/pages.d.ts
vendored
@ -11,10 +11,10 @@ export type TPage = {
|
|||||||
id: string | undefined;
|
id: string | undefined;
|
||||||
is_favorite: boolean;
|
is_favorite: boolean;
|
||||||
is_locked: boolean;
|
is_locked: boolean;
|
||||||
labels: string[] | undefined;
|
label_ids: string[] | undefined;
|
||||||
name: string | undefined;
|
name: string | undefined;
|
||||||
owned_by: string | undefined;
|
owned_by: string | undefined;
|
||||||
project: string | undefined;
|
project_ids: string[] | undefined;
|
||||||
updated_at: Date | undefined;
|
updated_at: Date | undefined;
|
||||||
updated_by: string | undefined;
|
updated_by: string | undefined;
|
||||||
workspace: string | undefined;
|
workspace: string | undefined;
|
||||||
|
@ -53,14 +53,14 @@ export class Page implements IPage {
|
|||||||
logo_props: TLogoProps | undefined;
|
logo_props: TLogoProps | undefined;
|
||||||
description_html: string | undefined;
|
description_html: string | undefined;
|
||||||
color: string | undefined;
|
color: string | undefined;
|
||||||
labels: string[] | undefined;
|
label_ids: string[] | undefined;
|
||||||
owned_by: string | undefined;
|
owned_by: string | undefined;
|
||||||
access: EPageAccess | undefined;
|
access: EPageAccess | undefined;
|
||||||
is_favorite: boolean;
|
is_favorite: boolean;
|
||||||
is_locked: boolean;
|
is_locked: boolean;
|
||||||
archived_at: string | null | undefined;
|
archived_at: string | null | undefined;
|
||||||
workspace: string | undefined;
|
workspace: string | undefined;
|
||||||
project: string | undefined;
|
project_ids: string[] | undefined;
|
||||||
created_by: string | undefined;
|
created_by: string | undefined;
|
||||||
updated_by: string | undefined;
|
updated_by: string | undefined;
|
||||||
created_at: Date | undefined;
|
created_at: Date | undefined;
|
||||||
@ -81,14 +81,14 @@ export class Page implements IPage {
|
|||||||
this.logo_props = page?.logo_props || undefined;
|
this.logo_props = page?.logo_props || undefined;
|
||||||
this.description_html = page?.description_html || undefined;
|
this.description_html = page?.description_html || undefined;
|
||||||
this.color = page?.color || undefined;
|
this.color = page?.color || undefined;
|
||||||
this.labels = page?.labels || undefined;
|
this.label_ids = page?.label_ids || undefined;
|
||||||
this.owned_by = page?.owned_by || undefined;
|
this.owned_by = page?.owned_by || undefined;
|
||||||
this.access = page?.access || EPageAccess.PUBLIC;
|
this.access = page?.access || EPageAccess.PUBLIC;
|
||||||
this.is_favorite = page?.is_favorite || false;
|
this.is_favorite = page?.is_favorite || false;
|
||||||
this.is_locked = page?.is_locked || false;
|
this.is_locked = page?.is_locked || false;
|
||||||
this.archived_at = page?.archived_at || undefined;
|
this.archived_at = page?.archived_at || undefined;
|
||||||
this.workspace = page?.workspace || undefined;
|
this.workspace = page?.workspace || undefined;
|
||||||
this.project = page?.project || undefined;
|
this.project_ids = page?.project_ids || undefined;
|
||||||
this.created_by = page?.created_by || undefined;
|
this.created_by = page?.created_by || undefined;
|
||||||
this.updated_by = page?.updated_by || undefined;
|
this.updated_by = page?.updated_by || undefined;
|
||||||
this.created_at = page?.created_at || undefined;
|
this.created_at = page?.created_at || undefined;
|
||||||
@ -104,14 +104,14 @@ export class Page implements IPage {
|
|||||||
logo_props: observable.ref,
|
logo_props: observable.ref,
|
||||||
description_html: observable.ref,
|
description_html: observable.ref,
|
||||||
color: observable.ref,
|
color: observable.ref,
|
||||||
labels: observable,
|
label_ids: observable,
|
||||||
owned_by: observable.ref,
|
owned_by: observable.ref,
|
||||||
access: observable.ref,
|
access: observable.ref,
|
||||||
is_favorite: observable.ref,
|
is_favorite: observable.ref,
|
||||||
is_locked: observable.ref,
|
is_locked: observable.ref,
|
||||||
archived_at: observable.ref,
|
archived_at: observable.ref,
|
||||||
workspace: observable.ref,
|
workspace: observable.ref,
|
||||||
project: observable.ref,
|
project_ids: observable,
|
||||||
created_by: observable.ref,
|
created_by: observable.ref,
|
||||||
updated_by: observable.ref,
|
updated_by: observable.ref,
|
||||||
created_at: observable.ref,
|
created_at: observable.ref,
|
||||||
@ -181,7 +181,7 @@ export class Page implements IPage {
|
|||||||
name: this.name,
|
name: this.name,
|
||||||
description_html: this.description_html,
|
description_html: this.description_html,
|
||||||
color: this.color,
|
color: this.color,
|
||||||
labels: this.labels,
|
label_ids: this.label_ids,
|
||||||
owned_by: this.owned_by,
|
owned_by: this.owned_by,
|
||||||
access: this.access,
|
access: this.access,
|
||||||
logo_props: this.logo_props,
|
logo_props: this.logo_props,
|
||||||
@ -189,7 +189,7 @@ export class Page implements IPage {
|
|||||||
is_locked: this.is_locked,
|
is_locked: this.is_locked,
|
||||||
archived_at: this.archived_at,
|
archived_at: this.archived_at,
|
||||||
workspace: this.workspace,
|
workspace: this.workspace,
|
||||||
project: this.project,
|
project_ids: this.project_ids,
|
||||||
created_by: this.created_by,
|
created_by: this.created_by,
|
||||||
updated_by: this.updated_by,
|
updated_by: this.updated_by,
|
||||||
created_at: this.created_at,
|
created_at: this.created_at,
|
||||||
|
@ -96,7 +96,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
|||||||
if (!projectId) return undefined;
|
if (!projectId) return undefined;
|
||||||
// helps to filter pages based on the pageType
|
// helps to filter pages based on the pageType
|
||||||
let pagesByType = filterPagesByPageType(pageType, Object.values(this?.data || {}));
|
let pagesByType = filterPagesByPageType(pageType, Object.values(this?.data || {}));
|
||||||
pagesByType = pagesByType.filter((p) => p.project === projectId);
|
pagesByType = pagesByType.filter((p) => p.project_ids?.includes(projectId));
|
||||||
|
|
||||||
const pages = (pagesByType.map((page) => page.id) as string[]) || undefined;
|
const pages = (pagesByType.map((page) => page.id) as string[]) || undefined;
|
||||||
|
|
||||||
@ -115,7 +115,7 @@ export class ProjectPageStore implements IProjectPageStore {
|
|||||||
const pagesByType = filterPagesByPageType(pageType, Object.values(this?.data || {}));
|
const pagesByType = filterPagesByPageType(pageType, Object.values(this?.data || {}));
|
||||||
let filteredPages = pagesByType.filter(
|
let filteredPages = pagesByType.filter(
|
||||||
(p) =>
|
(p) =>
|
||||||
p.project === projectId &&
|
p.project_ids?.includes(projectId) &&
|
||||||
getPageName(p.name).toLowerCase().includes(this.filters.searchQuery.toLowerCase()) &&
|
getPageName(p.name).toLowerCase().includes(this.filters.searchQuery.toLowerCase()) &&
|
||||||
shouldFilterPage(p, this.filters.filters)
|
shouldFilterPage(p, this.filters.filters)
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user