mirror of
https://github.com/flynx/pWiki.git
synced 2025-12-17 08:31:38 +00:00
reworked .order(..)...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
bf250a5036
commit
def20580ad
211
pwiki.js
211
pwiki.js
@ -256,16 +256,30 @@ module.pWikiData = {
|
|||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
// Clear data at path...
|
// Clear a path...
|
||||||
//
|
//
|
||||||
clear: function(path){
|
clear: function(path){
|
||||||
if(this.__data == null){
|
if(this.__data == null){
|
||||||
return this
|
return this
|
||||||
}
|
}
|
||||||
var that = this
|
this.remove(this.match(path))
|
||||||
this.match(path).forEach(function(p){
|
return this
|
||||||
delete that.__data[p]
|
},
|
||||||
|
|
||||||
|
// explicitly remove path...
|
||||||
|
//
|
||||||
|
// NOTE: this is similar to .clear(..) but will not expand patterns,
|
||||||
|
// thus only one page is is removed per path.
|
||||||
|
remove: function(path){
|
||||||
|
path = arguments.length > 1 ? [].slice.call(arguments)
|
||||||
|
: path instanceof Array ? path
|
||||||
|
: [path]
|
||||||
|
var data = this.__data
|
||||||
|
|
||||||
|
path.forEach(function(p){
|
||||||
|
delete data[p]
|
||||||
})
|
})
|
||||||
|
|
||||||
return this
|
return this
|
||||||
},
|
},
|
||||||
|
|
||||||
@ -344,8 +358,7 @@ module.pWikiBase = actions.Actions({
|
|||||||
|
|
||||||
// refresh the cache...
|
// refresh the cache...
|
||||||
if(match == null || force){
|
if(match == null || force){
|
||||||
location.match = this.order()
|
this.order(force)
|
||||||
location.at = at
|
|
||||||
}
|
}
|
||||||
}],
|
}],
|
||||||
|
|
||||||
@ -492,12 +505,16 @@ module.pWikiBase = actions.Actions({
|
|||||||
|
|
||||||
// set location path...
|
// set location path...
|
||||||
} else if(typeof(value) == typeof('str')){
|
} else if(typeof(value) == typeof('str')){
|
||||||
location.path = this.resolve(value)
|
this.__location = {
|
||||||
location.at = 0
|
path: this.resolve(value),
|
||||||
|
at: 0,
|
||||||
|
}
|
||||||
|
|
||||||
// object...
|
// object...
|
||||||
} else {
|
} else {
|
||||||
this.__location = value
|
this.__location = value
|
||||||
|
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
this.refresh(true)
|
this.refresh(true)
|
||||||
@ -652,63 +669,82 @@ module.pWikiBase = actions.Actions({
|
|||||||
|
|
||||||
// Get/set sibling order...
|
// Get/set sibling order...
|
||||||
//
|
//
|
||||||
// Get order (title)...
|
// Get order...
|
||||||
// .order()
|
// .order()
|
||||||
// -> order
|
// -> order
|
||||||
//
|
//
|
||||||
// Save local order (.__order)...
|
// Force get order...
|
||||||
// .order('local')
|
// .order(true)
|
||||||
|
// .order('force')
|
||||||
|
// -> order
|
||||||
|
// NOTE: this will overwrite cache.
|
||||||
|
//
|
||||||
|
// Get saved order...
|
||||||
|
// .order('saved')
|
||||||
// -> order
|
// -> order
|
||||||
//
|
//
|
||||||
// Save current order...
|
// Save list of paths as order explicitly...
|
||||||
// .order('current')
|
|
||||||
// -> order
|
|
||||||
// NOTE: this is a shorthand for p.order(p.order())
|
|
||||||
//
|
|
||||||
// Save list of titles as order...
|
|
||||||
// .order([<title>, .. ])
|
// .order([<title>, .. ])
|
||||||
// -> order
|
// -> page
|
||||||
|
//
|
||||||
|
// Save order persistently...
|
||||||
|
// .order('save')
|
||||||
|
// -> page
|
||||||
|
//
|
||||||
|
// Remove set order, local if available else persistent...
|
||||||
|
// .order('clear')
|
||||||
|
// -> page
|
||||||
|
//
|
||||||
|
// Remove all ordering...
|
||||||
|
// .order('clear-all')
|
||||||
|
// -> page
|
||||||
|
//
|
||||||
|
//
|
||||||
|
// List of paths passed to .order(..) can contain a '*' to indicate
|
||||||
|
// the pages not specified by the list.
|
||||||
|
// By default all unspecified pages will get appended to the resulting
|
||||||
|
// list, same as appending a '*' to the tail of the list passed to
|
||||||
|
// .order(..)
|
||||||
|
//
|
||||||
//
|
//
|
||||||
// NOTE: saving order to data is supported ONLY for paths that contain
|
// NOTE: saving order to data is supported ONLY for paths that contain
|
||||||
// one and only one pattern and in the last path segment...
|
// one and only one pattern and in the last path segment...
|
||||||
|
// NOTE: clearing persistent ordering will remove a page (parent) from
|
||||||
|
// data if it contains nothing but the order...
|
||||||
|
// NOTE: this will also maintain page position within order (.at())
|
||||||
//
|
//
|
||||||
// XXX (LEAK?) not sure if the current location where order is stored
|
// XXX (LEAK?) not sure if the current location where order is stored
|
||||||
// is the right way to go...
|
// is the right way to go -- would be really hard to clean out...
|
||||||
// ...would be really hard to clean out...
|
// ...might be a good idea to clear pattern paths that match no
|
||||||
// XXX should this be pattern only or by default list the siblings...
|
// pages from data...
|
||||||
// XXX should the default be titles or full paths???
|
|
||||||
// XXX should we split order persistence into two?
|
// XXX should we split order persistence into two?
|
||||||
// - local .__order
|
// - local .__order
|
||||||
// - global
|
// - global
|
||||||
// ...and how should we move from one to the other???
|
// ...and how should we move from one to the other???
|
||||||
order: ['Page/Get or set sibling pages order',
|
order: ['Page/Get or set sibling pages order',
|
||||||
function(order){
|
function(order){
|
||||||
var path = this.location().path || ''
|
var location = this.location()
|
||||||
var full_paths = true
|
var path = location.path || ''
|
||||||
|
var page = (location.match || [])[location.at || 0]
|
||||||
|
|
||||||
|
// get order...
|
||||||
|
if(order == null || order == 'force' || order === true){
|
||||||
// no patterns in path -> no ordering...
|
// no patterns in path -> no ordering...
|
||||||
if(path.indexOf('*') < 0){
|
if(path.indexOf('*') < 0){
|
||||||
|
if(!location.match){
|
||||||
|
location.match = [ path ]
|
||||||
|
this.location(location)
|
||||||
|
}
|
||||||
return [ path ]
|
return [ path ]
|
||||||
}
|
}
|
||||||
|
|
||||||
// store order in a specific path pattern...
|
// get cached order if not forced...
|
||||||
// NOTE: each path pattern may have a different order...
|
if(location.match != null && order == null){
|
||||||
// XXX should we check if this returns a function???
|
return location.match
|
||||||
var parent = this.wiki.data(path) || {}
|
|
||||||
|
|
||||||
// save local order...
|
|
||||||
// XXX this is wrong!!!
|
|
||||||
if(order == 'local'){
|
|
||||||
order = this.__order
|
|
||||||
|
|
||||||
// save current order...
|
|
||||||
} else if(order == 'current'){
|
|
||||||
return this.order(this.order())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// get order...
|
// XXX should we check if this returns a function???
|
||||||
if(order == null){
|
var parent = this.wiki.data(path) || {}
|
||||||
//var pages = this.wiki.match(parent.path() + '/*')
|
|
||||||
var pages = this.wiki.match(path)
|
var pages = this.wiki.match(path)
|
||||||
// filter out paths containing '*'
|
// filter out paths containing '*'
|
||||||
.filter(function(p){ return p.indexOf('*') < 0 })
|
.filter(function(p){ return p.indexOf('*') < 0 })
|
||||||
@ -717,48 +753,91 @@ module.pWikiBase = actions.Actions({
|
|||||||
// NOTE: paths may not be visible because they are
|
// NOTE: paths may not be visible because they are
|
||||||
// filtered out by .location().path pattern...
|
// filtered out by .location().path pattern...
|
||||||
.filter(function(p){
|
.filter(function(p){
|
||||||
return pages.indexOf(p) >= 0 })
|
return pages.indexOf(p) >= 0 || p == '*' })
|
||||||
|
|
||||||
// sorted...
|
// order present...
|
||||||
if(order.length > 0){
|
if(order.length > 0){
|
||||||
// get unsorted_first config:
|
// get the spot where to place pages not in order...
|
||||||
// page || config || false
|
// NOTE: if '*' is not in order, then unsorted pages
|
||||||
var unsorted_first = parent['order-unsorted-first']
|
// will get appended to the end...
|
||||||
unsorted_first = unsorted_first == null ?
|
// NOTE: only one '*' is supported...
|
||||||
this.config['order-unsorted-first']
|
var i = order.indexOf('*')
|
||||||
: unsorted_first
|
i = i == -1 ? order.length : i
|
||||||
unsorted_first = unsorted_first == null ?
|
|
||||||
false
|
|
||||||
: unsorted_first
|
|
||||||
// get pages not in order...
|
// get pages not in order...
|
||||||
pages = pages
|
pages = pages
|
||||||
.filter(function(p){
|
.filter(function(p){
|
||||||
return order.indexOf(p) < 0 })
|
return order.indexOf(p) < 0 })
|
||||||
// build the list...
|
|
||||||
return unsorted_first ?
|
|
||||||
pages.concat(order)
|
|
||||||
: order.concat(pages)
|
|
||||||
|
|
||||||
// unsorted...
|
// build the list...
|
||||||
|
order.splice.apply(order, [i, 1].concat(pages))
|
||||||
|
|
||||||
|
// unsorted -- simply list the pages...
|
||||||
} else {
|
} else {
|
||||||
return pages
|
order = pages
|
||||||
}
|
}
|
||||||
|
|
||||||
// set persistent manual order...
|
// save cache...
|
||||||
// XXX ugly -- revise...
|
location.match = order
|
||||||
// check if we have a pattern...
|
location.at = page ? order.indexOf(page) : 0
|
||||||
//} else if(path2list(path).pop().indexOf('*') >= 0
|
this.location(location)
|
||||||
// // check if no patterns are in path other than the last elem...
|
|
||||||
// && path2list(path).slice(0, -1).join('/').match(/\*/g) == null) {
|
return order.slice()
|
||||||
} else if(path.indexOf('*') >= 0){
|
|
||||||
parent.order = order
|
// get saved order...
|
||||||
|
} else if(order == 'saved'){
|
||||||
|
return this.__order
|
||||||
|
// XXX should we check if this returns a function???
|
||||||
|
|| (this.wiki.data(path) || {}).order
|
||||||
|
|| []
|
||||||
|
|
||||||
|
// clear order...
|
||||||
|
// XXX should this:
|
||||||
|
// - clear all always
|
||||||
|
// - explicitly clear only local or persistent
|
||||||
|
// - progressively clear local then persistent (current)
|
||||||
|
} else if(order == 'clear' || order == 'clear-all'){
|
||||||
|
var local = !!this.__order
|
||||||
|
|
||||||
|
// local order...
|
||||||
|
delete this.__order
|
||||||
|
|
||||||
|
// clear persistent order...
|
||||||
|
if(!local || order == 'clear-all'){
|
||||||
|
// XXX should we check if this returns a function???
|
||||||
|
var parent = this.wiki.data(path)
|
||||||
|
|
||||||
|
// persistent order...
|
||||||
|
if(parent && parent.order){
|
||||||
|
delete parent.order
|
||||||
|
|
||||||
|
// remove if empty...
|
||||||
|
if(Object.keys(parent).length == 0){
|
||||||
|
this.wiki.remove(path)
|
||||||
|
|
||||||
|
// save...
|
||||||
|
} else {
|
||||||
|
this.wiki.data(path, parent)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} else if(order == 'save') {
|
||||||
|
// XXX should we check if this returns a function???
|
||||||
|
var parent = this.wiki.data(path) || {}
|
||||||
|
|
||||||
|
var order = parent.order = this.__order || this.order()
|
||||||
|
|
||||||
this.wiki.data(path, parent)
|
this.wiki.data(path, parent)
|
||||||
delete this.__order
|
delete this.__order
|
||||||
|
|
||||||
// set local manual order...
|
// set order...
|
||||||
} else {
|
} else {
|
||||||
this.__order = order
|
this.__order = order
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// save cache...
|
||||||
|
this.order(true)
|
||||||
}],
|
}],
|
||||||
|
|
||||||
__sort_methods__: {
|
__sort_methods__: {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user