forked from github/plane
fix: analytic query params (#1035)
* fix: query params for analytics * fix: default analytics filters
This commit is contained in:
parent
f2a68874f1
commit
6e9235e5fe
@ -26,6 +26,7 @@ from plane.db.models import Issue, AnalyticView, Workspace, State, Label
|
|||||||
from plane.api.serializers import AnalyticViewSerializer
|
from plane.api.serializers import AnalyticViewSerializer
|
||||||
from plane.utils.analytics_plot import build_graph_plot
|
from plane.utils.analytics_plot import build_graph_plot
|
||||||
from plane.bgtasks.analytic_plot_export import analytic_export_task
|
from plane.bgtasks.analytic_plot_export import analytic_export_task
|
||||||
|
from plane.utils.issue_filters import issue_filters
|
||||||
|
|
||||||
|
|
||||||
class AnalyticsEndpoint(BaseAPIView):
|
class AnalyticsEndpoint(BaseAPIView):
|
||||||
@ -44,19 +45,10 @@ class AnalyticsEndpoint(BaseAPIView):
|
|||||||
status=status.HTTP_400_BAD_REQUEST,
|
status=status.HTTP_400_BAD_REQUEST,
|
||||||
)
|
)
|
||||||
|
|
||||||
project_ids = request.GET.getlist("project")
|
|
||||||
cycle_ids = request.GET.getlist("cycle")
|
|
||||||
module_ids = request.GET.getlist("module")
|
|
||||||
|
|
||||||
segment = request.GET.get("segment", False)
|
segment = request.GET.get("segment", False)
|
||||||
|
filters = issue_filters(request.GET, "GET")
|
||||||
|
|
||||||
queryset = Issue.objects.filter(workspace__slug=slug)
|
queryset = Issue.objects.filter(workspace__slug=slug, **filters)
|
||||||
if project_ids:
|
|
||||||
queryset = queryset.filter(project_id__in=project_ids)
|
|
||||||
if cycle_ids:
|
|
||||||
queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids)
|
|
||||||
if module_ids:
|
|
||||||
queryset = queryset.filter(issue_module__module_id__in=module_ids)
|
|
||||||
|
|
||||||
total_issues = queryset.count()
|
total_issues = queryset.count()
|
||||||
distribution = build_graph_plot(
|
distribution = build_graph_plot(
|
||||||
@ -75,18 +67,18 @@ class AnalyticsEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
colors = (
|
colors = (
|
||||||
State.objects.filter(
|
State.objects.filter(
|
||||||
workspace__slug=slug, project_id__in=project_ids
|
workspace__slug=slug, project_id__in=filters.get("project__in")
|
||||||
).values(key, "color")
|
).values(key, "color")
|
||||||
if project_ids
|
if filters.get("project__in", False)
|
||||||
else State.objects.filter(workspace__slug=slug).values(key, "color")
|
else State.objects.filter(workspace__slug=slug).values(key, "color")
|
||||||
)
|
)
|
||||||
|
|
||||||
if x_axis in ["labels__name"] or segment in ["labels__name"]:
|
if x_axis in ["labels__name"] or segment in ["labels__name"]:
|
||||||
colors = (
|
colors = (
|
||||||
Label.objects.filter(
|
Label.objects.filter(
|
||||||
workspace__slug=slug, project_id__in=project_ids
|
workspace__slug=slug, project_id__in=filters.get("project__in")
|
||||||
).values("name", "color")
|
).values("name", "color")
|
||||||
if project_ids
|
if filters.get("project__in", False)
|
||||||
else Label.objects.filter(workspace__slug=slug).values(
|
else Label.objects.filter(workspace__slug=slug).values(
|
||||||
"name", "color"
|
"name", "color"
|
||||||
)
|
)
|
||||||
@ -213,18 +205,9 @@ class DefaultAnalyticsEndpoint(BaseAPIView):
|
|||||||
|
|
||||||
def get(self, request, slug):
|
def get(self, request, slug):
|
||||||
try:
|
try:
|
||||||
queryset = Issue.objects.filter(workspace__slug=slug)
|
filters = issue_filters(request.GET, "GET")
|
||||||
|
|
||||||
project_ids = request.GET.getlist("project")
|
queryset = Issue.objects.filter(workspace__slug=slug, **filters)
|
||||||
cycle_ids = request.GET.getlist("cycle")
|
|
||||||
module_ids = request.GET.getlist("module")
|
|
||||||
|
|
||||||
if project_ids:
|
|
||||||
queryset = queryset.filter(project_id__in=project_ids)
|
|
||||||
if cycle_ids:
|
|
||||||
queryset = queryset.filter(issue_cycle__cycle_id__in=cycle_ids)
|
|
||||||
if module_ids:
|
|
||||||
queryset = queryset.filter(issue_module__module_id__in=module_ids)
|
|
||||||
|
|
||||||
total_issues = queryset.count()
|
total_issues = queryset.count()
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user