sort mostly done...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2022-11-24 01:14:38 +03:00
parent 23c3c3ad4f
commit 85b0962277
3 changed files with 28 additions and 10 deletions

View File

@ -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(<name>)
// .sortAs([<path>, .. ])
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(<name>)
// .saveSortAs(<name>, [<path>, .. ])
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){

View File

@ -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') ?

View File

@ -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