From 68a7c103b72910ac904cbf72afaffcfe56af1e4f Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Mon, 5 Dec 2022 13:00:06 +0100 Subject: Added sorting of groups --- src/models/Group.ts | 4 +++- src/models/Trip.ts | 14 +++++++++++++- src/models/index.guard.ts | 7 +++++-- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'src/models') diff --git a/src/models/Group.ts b/src/models/Group.ts index 9b3aa6d..c0d281d 100644 --- a/src/models/Group.ts +++ b/src/models/Group.ts @@ -19,7 +19,7 @@ export default interface Group { description?: string; /** - * Medias in the group. + * Media in the group. */ media: MediaItem[]; @@ -32,4 +32,6 @@ export default interface Group { * Metadata that can be displayed in the description. */ metadata?: { [key: string]: string | number }; + + [key: string]: any; } diff --git a/src/models/Trip.ts b/src/models/Trip.ts index 7f92669..46c462d 100644 --- a/src/models/Trip.ts +++ b/src/models/Trip.ts @@ -19,10 +19,22 @@ export default interface Trip { /** * URL to a JSON file containing data for the trip. */ - url: string; + url?: string; /** * Property indicating if the trip data has been already downloaded. */ downloaded: boolean; + + /** + * A group property to use while sorting groups. + * Nested properties should be delimited with a dot. + * Default: name. + */ + sortProperty?: string; + + /** + * Sort order. true = descending, false = ascending. + */ + sortOrder?: boolean; } diff --git a/src/models/index.guard.ts b/src/models/index.guard.ts index d564ff9..6e9265f 100644 --- a/src/models/index.guard.ts +++ b/src/models/index.guard.ts @@ -47,8 +47,11 @@ export function isTrip(obj: unknown): obj is Trip { typeof typedObj.id === 'string' && typeof typedObj.name === 'string' && (typeof typedObj.groups === 'undefined' || - (Array.isArray(typedObj.groups) && typedObj.groups.every((e: any) => isGroup(e))) - ); + (Array.isArray(typedObj.groups) && typedObj.groups.every((e: any) => isGroup(e)))) && + (typeof typedObj.url === 'undefined' || typeof typedObj.url === 'string') && + (typeof typedObj.downloaded === 'undefined' || typeof typedObj.downloaded === 'boolean') && + (typeof typedObj.sortProperty === 'undefined' || typeof typedObj.sortProperty === 'string') && + (typeof typedObj.sortOrder === 'undefined' || typeof typedObj.sortOrder === 'boolean'); if (!isValid) { throw new Error(`Invalid object: ${JSON.stringify(obj)}`); -- cgit v1.2.3