From 3c48ce0225c027497aebb5cea733b8b7437c65fe Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Sun, 20 Nov 2022 00:06:00 -0800 Subject: [PATCH 1/2] option to truncate content on /documents endpoint --- .../document-card-large.component.ts | 5 ++++- src-ui/src/app/services/document-list-view.service.ts | 3 ++- src/documents/serialisers.py | 11 +++++++++++ src/documents/views.py | 2 ++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts index de6b94032..4ce1ef705 100644 --- a/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts +++ b/src-ui/src/app/components/document-list/document-card-large/document-card-large.component.ts @@ -119,6 +119,9 @@ export class DocumentCardLargeComponent implements OnInit { } get contentTrimmed() { - return this.document.content.substr(0, 500) + return ( + this.document.content.substr(0, 500) + + (this.document.content.length > 500 ? '...' : '') + ) } } diff --git a/src-ui/src/app/services/document-list-view.service.ts b/src-ui/src/app/services/document-list-view.service.ts index 3eb036710..3c5dbca21 100644 --- a/src-ui/src/app/services/document-list-view.service.ts +++ b/src-ui/src/app/services/document-list-view.service.ts @@ -213,7 +213,8 @@ export class DocumentListViewService { this.currentPageSize, activeListViewState.sortField, activeListViewState.sortReverse, - activeListViewState.filterRules + activeListViewState.filterRules, + { truncate_content: true } ) .subscribe({ next: (result) => { diff --git a/src/documents/serialisers.py b/src/documents/serialisers.py index db282cacd..356dd0a69 100644 --- a/src/documents/serialisers.py +++ b/src/documents/serialisers.py @@ -234,6 +234,12 @@ class DocumentSerializer(DynamicFieldsModelSerializer): else: return None + def to_representation(self, instance): + doc = super().to_representation(instance) + if self.truncate_content: + doc["content"] = doc.get("content")[0:550] + return doc + def update(self, instance, validated_data): if "created_date" in validated_data and "created" not in validated_data: new_datetime = datetime.datetime.combine( @@ -247,6 +253,11 @@ class DocumentSerializer(DynamicFieldsModelSerializer): super().update(instance, validated_data) return instance + def __init__(self, *args, **kwargs): + self.truncate_content = kwargs.pop("truncate_content", False) + + super().__init__(*args, **kwargs) + class Meta: model = Document depth = 1 diff --git a/src/documents/views.py b/src/documents/views.py index 10225be6f..eb6f205c1 100644 --- a/src/documents/views.py +++ b/src/documents/views.py @@ -226,9 +226,11 @@ class DocumentViewSet( fields = fields_param.split(",") else: fields = None + truncate_content = self.request.query_params.get("truncate_content", "False") serializer_class = self.get_serializer_class() kwargs.setdefault("context", self.get_serializer_context()) kwargs.setdefault("fields", fields) + kwargs.setdefault("truncate_content", truncate_content.lower() in ["true", "1"]) return serializer_class(*args, **kwargs) def update(self, request, *args, **kwargs): From 2c1333a75f43fe807ca168dd4f093171175ee85e Mon Sep 17 00:00:00 2001 From: Michael Shamoon <4887959+shamoon@users.noreply.github.com> Date: Tue, 22 Nov 2022 15:25:27 -0800 Subject: [PATCH 2/2] Dont use document data from /documents API call for edit --- .../saved-view-widget.component.html | 6 ++--- .../saved-view-widget.component.scss | 2 +- .../saved-view-widget.component.ts | 4 +++- .../document-detail.component.ts | 2 +- .../document-card-large.component.html | 2 +- .../document-card-large.component.ts | 6 +---- .../document-card-small.component.html | 2 +- .../document-card-small.component.ts | 4 +--- .../document-list.component.html | 2 +- .../app/services/open-documents.service.ts | 23 ++++--------------- 10 files changed, 18 insertions(+), 35 deletions(-) diff --git a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html index 84ee1aabe..32ca3859e 100644 --- a/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html +++ b/src-ui/src/app/components/dashboard/widgets/saved-view-widget/saved-view-widget.component.html @@ -11,9 +11,9 @@
-