diff options
author | (quasar) nebula <qznebula@protonmail.com> | 2025-02-22 13:38:20 -0400 |
---|---|---|
committer | (quasar) nebula <qznebula@protonmail.com> | 2025-02-22 13:38:20 -0400 |
commit | f886fbe24de02cdafa80e8d7f32fed0845dfa46d (patch) | |
tree | 5387c8cdb130d8cac9a1f385fa3ee339349246a1 | |
parent | bd58ecd5a73e1cc67b73e3fcb664011a02c06087 (diff) |
data: ThingSortingRule
-rw-r--r-- | src/data/things/sorting-rule.js | 75 |
1 files changed, 46 insertions, 29 deletions
diff --git a/src/data/things/sorting-rule.js b/src/data/things/sorting-rule.js index 88f37719..8d1c61b9 100644 --- a/src/data/things/sorting-rule.js +++ b/src/data/things/sorting-rule.js @@ -46,18 +46,10 @@ export class SortingRule extends Thing { }); } -export class DocumentSortingRule extends SortingRule { +export class ThingSortingRule extends SortingRule { static [Thing.getPropertyDescriptors] = () => ({ // Update & expose - // TODO: glob :plead: - filename: { - flags: {update: true, expose: true}, - update: { - validate: isStringNonEmpty, - }, - }, - properties: { flags: {update: true, expose: true}, update: { @@ -68,30 +60,11 @@ export class DocumentSortingRule extends SortingRule { static [Thing.yamlDocumentSpec] = Thing.extendDocumentSpec(SortingRule, { fields: { - 'Sort Documents': {property: 'filename'}, 'By Properties': {property: 'properties'}, }, }); - apply(layout) { - const fresh = {...layout}; - - let sortable = null; - switch (fresh.documentMode) { - case documentModes.headerAndEntries: - sortable = fresh.entryThings = - fresh.entryThings.slice(); - break; - - case documentModes.allInOne: - sortable = fresh.things = - fresh.things.slice(); - break; - - default: - throw new Error(`Invalid document type for sorting`); - } - + sort(sortable) { if (this.properties) { for (const property of this.properties.slice().reverse()) { const get = thing => thing[property]; @@ -134,6 +107,50 @@ export class DocumentSortingRule extends SortingRule { } } + return sortable; + } +} + +export class DocumentSortingRule extends ThingSortingRule { + static [Thing.getPropertyDescriptors] = () => ({ + // Update & expose + + // TODO: glob :plead: + filename: { + flags: {update: true, expose: true}, + update: { + validate: isStringNonEmpty, + }, + }, + }); + + static [Thing.yamlDocumentSpec] = Thing.extendDocumentSpec(ThingSortingRule, { + fields: { + 'Sort Documents': {property: 'filename'}, + }, + }); + + apply(layout) { + const fresh = {...layout}; + + let sortable = null; + switch (fresh.documentMode) { + case documentModes.headerAndEntries: + sortable = fresh.entryThings = + fresh.entryThings.slice(); + break; + + case documentModes.allInOne: + sortable = fresh.things = + fresh.things.slice(); + break; + + default: + throw new Error(`Invalid document type for sorting`); + } + + this.sort(sortable); + return fresh; } } |