From 8e0124be919f464eaa5f21ff68eb91f78fef06d0 Mon Sep 17 00:00:00 2001 From: Nikhil <118773738+pablohashescobar@users.noreply.github.com> Date: Mon, 31 Jul 2023 10:41:25 +0530 Subject: [PATCH] feat: project ordering (#1701) * dev: project ordering * dev: add ordering for projects list --- apiserver/plane/api/views/project.py | 2 +- .../db/migrations/0039_auto_20230723_2203.py | 20 ++++++++++++++++++- apiserver/plane/db/models/project.py | 1 + 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/apiserver/plane/api/views/project.py b/apiserver/plane/api/views/project.py index 721212105..5af4cd425 100644 --- a/apiserver/plane/api/views/project.py +++ b/apiserver/plane/api/views/project.py @@ -123,7 +123,7 @@ class ProjectViewSet(BaseViewSet): projects = ( self.get_queryset() .annotate(is_favorite=Exists(subquery)) - .order_by("-is_favorite", "name") + .order_by("sort_order", "name") .annotate( total_members=ProjectMember.objects.filter( project_id=OuterRef("id") diff --git a/apiserver/plane/db/migrations/0039_auto_20230723_2203.py b/apiserver/plane/db/migrations/0039_auto_20230723_2203.py index 45cbedf7a..78b77521c 100644 --- a/apiserver/plane/db/migrations/0039_auto_20230723_2203.py +++ b/apiserver/plane/db/migrations/0039_auto_20230723_2203.py @@ -1,5 +1,5 @@ # Generated by Django 4.2.3 on 2023-07-23 16:33 - +import random from django.db import migrations, models import plane.db.models.workspace @@ -58,6 +58,18 @@ def update_workspace_member_props(apps, schema_editor): Model.objects.bulk_update(updated_workspace_member, ["view_props"], batch_size=100) +def update_project_sort_order(apps, schema_editor): + Model = apps.get_model("db", "Project") + + updated_projects = [] + + for obj in Model.objects.all(): + obj.sort_order = random.randint(1, 65536) + updated_projects.append(obj) + + Model.objects.bulk_update(updated_projects, ["sort_order"], batch_size=100) + + class Migration(migrations.Migration): dependencies = [ ("db", "0038_auto_20230720_1505"), @@ -76,4 +88,10 @@ class Migration(migrations.Migration): name='default_props', field=models.JSONField(default=plane.db.models.workspace.get_default_props), ), + migrations.AddField( + model_name='project', + name='sort_order', + field=models.FloatField(default=65535), + ), + migrations.RunPython(update_project_sort_order), ] diff --git a/apiserver/plane/db/models/project.py b/apiserver/plane/db/models/project.py index 637afdfa3..f95a8c2f0 100644 --- a/apiserver/plane/db/models/project.py +++ b/apiserver/plane/db/models/project.py @@ -91,6 +91,7 @@ class Project(BaseModel): default_state = models.ForeignKey( "db.State", on_delete=models.SET_NULL, null=True, related_name="default_state" ) + sort_order = models.FloatField(default=65535) def __str__(self): """Return name of the project"""