From 6d18d708458bc0e65d5419dd9daa1297dd9408d0 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Sat, 19 Jan 2019 17:06:23 +0100 Subject: [PATCH 1/2] sort by date in motion --- .../app/core/services/sort-list.service.ts | 6 +++++- .../src/app/shared/models/motions/motion.ts | 2 ++ .../app/site/motions/models/view-motion.ts | 20 +++++++++++++++++++ .../services/motion-sort-list.service.ts | 7 +++---- 4 files changed, 30 insertions(+), 5 deletions(-) diff --git a/client/src/app/core/services/sort-list.service.ts b/client/src/app/core/services/sort-list.service.ts index e25287a69..af1015094 100644 --- a/client/src/app/core/services/sort-list.service.ts +++ b/client/src/app/core/services/sort-list.service.ts @@ -241,7 +241,11 @@ export abstract class SortListService { const b = secondProperty(); return a.localeCompare(b, lang); case 'object': - return firstProperty.toString().localeCompare(secondProperty.toString(), lang); + if (firstProperty instanceof Date) { + return firstProperty > secondProperty ? 1 : -1; + } else { + return firstProperty.toString().localeCompare(secondProperty.toString(), lang); + } case 'undefined': return 1; default: diff --git a/client/src/app/shared/models/motions/motion.ts b/client/src/app/shared/models/motions/motion.ts index 4690acea8..48e96c726 100644 --- a/client/src/app/shared/models/motions/motion.ts +++ b/client/src/app/shared/models/motions/motion.ts @@ -41,6 +41,8 @@ export class Motion extends AgendaBaseModel { public log_messages: MotionLog[]; public weight: number; public sort_parent_id: number; + public created: string; + public last_modified: string; public constructor(input?: any) { super('motions/motion', 'Motion', input); diff --git a/client/src/app/site/motions/models/view-motion.ts b/client/src/app/site/motions/models/view-motion.ts index cdbbb87b4..d6efd3e2b 100644 --- a/client/src/app/site/motions/models/view-motion.ts +++ b/client/src/app/site/motions/models/view-motion.ts @@ -220,6 +220,26 @@ export class ViewMotion extends BaseViewModel { return this._attachments ? this._attachments : null; } + /** + * @returns the creation date as Date object + */ + public get creationDate(): Date { + if (!this.motion || !this.motion.created) { + return null; + } + return new Date(this.motion.created); + } + + /** + * @returns the date of the last change as Date object, null if empty + */ + public get lastChangeDate(): Date { + if (!this.motion || !this.motion.last_modified) { + return null; + } + return new Date(this.motion.last_modified); + } + /** * Gets the comments' section ids of a motion. Used in filter by motionComment * diff --git a/client/src/app/site/motions/services/motion-sort-list.service.ts b/client/src/app/site/motions/services/motion-sort-list.service.ts index 6b32bfa92..d3117450c 100644 --- a/client/src/app/site/motions/services/motion-sort-list.service.ts +++ b/client/src/app/site/motions/services/motion-sort-list.service.ts @@ -17,10 +17,9 @@ export class MotionSortListService extends SortListService { { property: 'submitters' }, { property: 'category' }, { property: 'motion_block_id', label: 'Motion block' }, - { property: 'state' } - // choices from 2.3: - // TODO creation date - // TODO last modified + { property: 'state' }, + { property: 'creationDate', label: 'Creation date' }, + { property: 'lastChangeDate', label: 'Last modified' } ] }; protected name = 'Motion'; From 030f610f2f3fd2e9ebbc25fda09268f9f5dc69f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Norman=20J=C3=A4ckel?= Date: Sat, 19 Jan 2019 22:11:40 +0100 Subject: [PATCH 2/2] Fixed last_modified saving. --- openslides/motions/views.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/openslides/motions/views.py b/openslides/motions/views.py index 289427317..1ef9237f1 100644 --- a/openslides/motions/views.py +++ b/openslides/motions/views.py @@ -576,7 +576,7 @@ class MotionViewSet(ModelViewSet): # Save motion. motion.save( - update_fields=["state", "identifier", "identifier_number"], + update_fields=["state", "identifier", "identifier_number", "last_modified"], skip_autoupdate=True, ) message = f"The state of the motion was set to {motion.state.name}." @@ -648,7 +648,7 @@ class MotionViewSet(ModelViewSet): motion.set_state(state_id) # Save motion. - motion.save(update_fields=["state"], skip_autoupdate=True) + motion.save(update_fields=["state", "last_modified"], skip_autoupdate=True) # Write the log message. motion.write_log( @@ -708,7 +708,7 @@ class MotionViewSet(ModelViewSet): motion.recommendation = None # Save motion. - motion.save(update_fields=["recommendation"], skip_autoupdate=True) + motion.save(update_fields=["recommendation", "last_modified"], skip_autoupdate=True) label = ( motion.recommendation.recommendation_label if motion.recommendation @@ -794,7 +794,7 @@ class MotionViewSet(ModelViewSet): motion.set_recommendation(recommendation_state_id) # Save motion. - motion.save(update_fields=["recommendation"], skip_autoupdate=True) + motion.save(update_fields=["recommendation", "last_modified"], skip_autoupdate=True) label = ( motion.recommendation.recommendation_label if motion.recommendation @@ -842,6 +842,7 @@ class MotionViewSet(ModelViewSet): "identifier", "identifier_number", "state_extension", + "last_modified", ], skip_autoupdate=True, )