From 7404fe71b1808dfd353169463d650f7db91c76ec Mon Sep 17 00:00:00 2001 From: Bavisetti Narayan <72156168+NarayanBavisetti@users.noreply.github.com> Date: Wed, 27 Sep 2023 17:30:52 +0530 Subject: [PATCH] chore: sort order and issue props for global views (#2283) --- ...er_workspacemember_issue_props_and_more.py | 24 +++++++++++++++++++ apiserver/plane/db/models/view.py | 11 +++++++++ apiserver/plane/db/models/workspace.py | 12 +++++++++- 3 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 apiserver/plane/db/migrations/0048_globalview_sort_order_workspacemember_issue_props_and_more.py diff --git a/apiserver/plane/db/migrations/0048_globalview_sort_order_workspacemember_issue_props_and_more.py b/apiserver/plane/db/migrations/0048_globalview_sort_order_workspacemember_issue_props_and_more.py new file mode 100644 index 000000000..3084ef637 --- /dev/null +++ b/apiserver/plane/db/migrations/0048_globalview_sort_order_workspacemember_issue_props_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 4.2.5 on 2023-09-27 11:18 + +from django.db import migrations, models +import plane.db.models.workspace + + +class Migration(migrations.Migration): + + dependencies = [ + ('db', '0047_auto_20230926_1029'), + ] + + operations = [ + migrations.AddField( + model_name='globalview', + name='sort_order', + field=models.FloatField(default=65535), + ), + migrations.AddField( + model_name='workspacemember', + name='issue_props', + field=models.JSONField(default=plane.db.models.workspace.get_issue_props), + ), + ] diff --git a/apiserver/plane/db/models/view.py b/apiserver/plane/db/models/view.py index 6e0a47105..c19e444b3 100644 --- a/apiserver/plane/db/models/view.py +++ b/apiserver/plane/db/models/view.py @@ -17,12 +17,23 @@ class GlobalView(BaseModel): default=1, choices=((0, "Private"), (1, "Public")) ) query_data = models.JSONField(default=dict) + sort_order = models.FloatField(default=65535) class Meta: verbose_name = "Global View" verbose_name_plural = "Global Views" db_table = "global_views" ordering = ("-created_at",) + + def save(self, *args, **kwargs): + if self._state.adding: + largest_sort_order = GlobalView.objects.filter( + project=self.project + ).aggregate(largest=models.Max("sort_order"))["largest"] + if largest_sort_order is not None: + self.sort_order = largest_sort_order + 10000 + + super(GlobalView, self).save(*args, **kwargs) def __str__(self): """Return name of the View""" diff --git a/apiserver/plane/db/models/workspace.py b/apiserver/plane/db/models/workspace.py index c85268435..d1012f549 100644 --- a/apiserver/plane/db/models/workspace.py +++ b/apiserver/plane/db/models/workspace.py @@ -29,7 +29,7 @@ def get_default_props(): }, "display_filters": { "group_by": None, - "order_by": '-created_at', + "order_by": "-created_at", "type": None, "sub_issue": True, "show_empty_groups": True, @@ -54,6 +54,15 @@ def get_default_props(): } +def get_issue_props(): + return { + "subscribed": True, + "assigned": True, + "created": True, + "all_issues": True, + } + + class Workspace(BaseModel): name = models.CharField(max_length=80, verbose_name="Workspace Name") logo = models.URLField(verbose_name="Logo", blank=True, null=True) @@ -89,6 +98,7 @@ class WorkspaceMember(BaseModel): company_role = models.TextField(null=True, blank=True) view_props = models.JSONField(default=get_default_props) default_props = models.JSONField(default=get_default_props) + issue_props = models.JSONField(default=get_issue_props) class Meta: unique_together = ["workspace", "member"]