From 85b096227760ab282db74f7cff04608b4b3c011a Mon Sep 17 00:00:00 2001 From: "Alex A. Naanou" Date: Thu, 24 Nov 2022 01:14:38 +0300 Subject: [PATCH] sort mostly done... Signed-off-by: Alex A. Naanou --- pwiki/page.js | 19 +++++++++++++++++++ pwiki/store/base.js | 12 +++++++++--- pwiki2.js | 7 ------- 3 files changed, 28 insertions(+), 10 deletions(-) diff --git a/pwiki/page.js b/pwiki/page.js index a0f008d..6c7ce80 100755 --- a/pwiki/page.js +++ b/pwiki/page.js @@ -563,6 +563,25 @@ object.Constructor('BasePage', { this.metadata = { order: await this.store.sort(this.path, ...cmp) } return this }, + + // XXX EXPERIMENTAL -- move this to store??? + // .sortAs() + // .sortAs([, .. ]) + sortAs: async function(order){ + this.metadata = + order instanceof Array ? + { order } + : { order: (await this.metadata)['order_'+ order] } + return this }, + // XXX EXPERIMENTAL -- move this to store??? + // .saveSortAs() + // .saveSortAs(, [, .. ]) + saveSortAs: async function(name, order=null){ + order = order + ?? (await this.metadata).order + this.metadata = {['order_'+ name]: order} + return this }, + reverse: async function(){ // not sorting single pages... if(this.length <= 1){ diff --git a/pwiki/store/base.js b/pwiki/store/base.js index e4186d4..6641471 100755 --- a/pwiki/store/base.js +++ b/pwiki/store/base.js @@ -692,8 +692,7 @@ module.BaseStore = { //*/ // XXX EXPERIMENTAL... - // XXX should we handle undefined attr values??? - // XXX BUG: chains still not working correctly... + // XXX add sort order saving??? sort: function(paths, ...by){ var that = this paths = @@ -710,7 +709,14 @@ module.BaseStore = { .map(function(p, i){ var d var res = [] - for(var cmp of by){ + // NOTE: this is the first and only instance so far where + // using let is simpler than doing this below: + // function(cmp){ + // return (d = d ?? that.get(p)) + // .then(function(data){ + // return data[cmp] }) }.bind(this, cmp) + // ..still not sure if this is worth the special case... + for(let cmp of by){ res.push( (cmp == 'path' || cmp == 'location') ? diff --git a/pwiki2.js b/pwiki2.js index fd52a2e..ef34ed5 100755 --- a/pwiki2.js +++ b/pwiki2.js @@ -36,12 +36,6 @@ * - * * -* XXX sort: define a generic sort path argument... DONE-ish -* XXX sort chains still not totally correct... -* This correctly shows Doc and WikiHome first -* await pwiki.store.sort('*', 'tags') -* This mixes them back up: -* await pwiki.store.sort('*', 'tags', 'ctime') * XXX macros: else/default macro args essentially mean the same thing, should we * unify them to use the same name??? * XXX parser: error handling: revise page quoting... @@ -74,7 +68,6 @@ * ...likely no... * ...would depend on where we iterate pages and on whether * we can/should reach that spot from within the parser... -* XXX ASAP revise/update sort... * XXX ASAP: MetaStore: need to correctly integrate the following store * methods: * .get(..) -- DONE