From 6d18d708458bc0e65d5419dd9daa1297dd9408d0 Mon Sep 17 00:00:00 2001 From: Maximilian Krambach Date: Sat, 19 Jan 2019 17:06:23 +0100 Subject: [PATCH] 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';