Skip to content

Commit d82a80c

Browse files
committed
#171 - a PoC of the idea of metadata value extractors. Completed the sorting spec parser part.
1 parent 42a5f1f commit d82a80c

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/custom-sort/custom-sort-types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {MDataExtractor} from "./mdata-extractors";
2+
13
export enum CustomSortGroupType {
24
Outsiders, // Not belonging to any of other groups
35
MatchAll, // like a wildard *, used in connection with foldersOnly or filesOnly. The difference between the MatchAll and Outsiders is
@@ -51,8 +53,10 @@ export enum CustomSortOrder {
5153
export interface RecognizedOrderValue {
5254
order: CustomSortOrder
5355
applyToMetadataField?: string
56+
metadataValueExtractor?: MDataExtractor
5457
secondaryOrder?: CustomSortOrder
5558
secondaryApplyToMetadataField?: string
59+
secondaryMetadataValueExtractor?: MDataExtractor
5660
}
5761

5862
export type NormalizerFn = (s: string) => string | null

src/custom-sort/sorting-spec-processor.ts

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,7 @@ interface CustomSortOrderAscDescPair {
116116
interface CustomSortOrderSpec {
117117
order: CustomSortOrder
118118
byMetadataField?: string
119+
metadataFieldExtractor?: MDataExtractor
119120
}
120121

121122
const MAX_SORT_LEVEL: number = 1
@@ -1578,13 +1579,7 @@ export class SortingSpecProcessor {
15781579
sortOrderSpec[level] = {
15791580
order: order!,
15801581
byMetadataField: metadataName,
1581-
15821582
metadataFieldExtractor: metadataExtractor
1583-
1584-
... and the carry the metadataFieldExtractor attribute down the parser, handle correctly in the 4-levels mdata sorting options
1585-
and execute at runtime
1586-
1587-
Seems to be far too complex to be worth it.
15881583
}
15891584
}
15901585
return sortOrderSpec
@@ -1595,8 +1590,10 @@ export class SortingSpecProcessor {
15951590
return recognized ? (recognized instanceof AttrError ? recognized : {
15961591
order: recognized[0].order,
15971592
applyToMetadataField: recognized[0].byMetadataField,
1593+
metadataValueExtractor: recognized[0].metadataFieldExtractor,
15981594
secondaryOrder: recognized[1]?.order,
1599-
secondaryApplyToMetadataField: recognized[1]?.byMetadataField
1595+
secondaryApplyToMetadataField: recognized[1]?.byMetadataField,
1596+
secondaryMetadataValueExtractor: recognized[1]?.metadataFieldExtractor
16001597
}) : null;
16011598
}
16021599

0 commit comments

Comments
 (0)