mirror of
https://github.com/flynx/ImageGrid.git
synced 2025-10-28 18:00:09 +00:00
chnages not generic...
Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
parent
f5b9687d3f
commit
a3a633096c
@ -840,13 +840,16 @@ module.Base = core.ImageGridFeatures.Feature({
|
||||
title: 'ImageGrid base',
|
||||
|
||||
tag: 'base',
|
||||
/* XXX ???
|
||||
depends: [
|
||||
'changes',
|
||||
],
|
||||
/*
|
||||
suggested: [
|
||||
'tags',
|
||||
'sort',
|
||||
'tasks',
|
||||
],
|
||||
*/
|
||||
//*/
|
||||
|
||||
actions: BaseActions,
|
||||
|
||||
@ -859,6 +862,45 @@ module.Base = core.ImageGridFeatures.Feature({
|
||||
'shiftImageRight',
|
||||
],
|
||||
function(){ this.shiftImage.apply(this, [].slice(arguments, 1))}],
|
||||
|
||||
// manage changes...
|
||||
// everything changed...
|
||||
[[
|
||||
'claer',
|
||||
'loadURLs',
|
||||
],
|
||||
function(){ this.markChanged('all') }],
|
||||
|
||||
// data...
|
||||
[[
|
||||
//'load',
|
||||
|
||||
'setBaseRibbon',
|
||||
|
||||
'shiftImageTo',
|
||||
'shiftImageUp',
|
||||
'shiftImageDown',
|
||||
'shiftImageLeft',
|
||||
'shiftImageRight',
|
||||
'shiftRibbonUp',
|
||||
'shiftRibbonDown',
|
||||
|
||||
'reverseImages',
|
||||
'reverseRibbons',
|
||||
|
||||
'alignToRibbon',
|
||||
],
|
||||
function(_, target){ this.markChanged('data') }],
|
||||
|
||||
// image specific...
|
||||
[[
|
||||
'rotateCW',
|
||||
'rotateCCW',
|
||||
'flipHorizontal',
|
||||
'flipVertical',
|
||||
],
|
||||
function(_, target){ this.markChanged('images', [that.data.getImage(target)]) }],
|
||||
|
||||
],
|
||||
})
|
||||
|
||||
@ -1014,9 +1056,42 @@ module.Tags = core.ImageGridFeatures.Feature({
|
||||
tag: 'tags',
|
||||
depends: [
|
||||
'base',
|
||||
'changes',
|
||||
],
|
||||
|
||||
actions: TagsActions,
|
||||
|
||||
handlers: [
|
||||
// tags and images...
|
||||
// NOTE: tags are also stored in images...
|
||||
['tag untag',
|
||||
function(_, tags, gids){
|
||||
var that = this
|
||||
var changes = []
|
||||
|
||||
gids = gids || [this.data.getImage()]
|
||||
gids = gids.constructor !== Array ?
|
||||
[this.data.getImage(gids)]
|
||||
: gids
|
||||
.map(function(e){ return that.data.getImage(e) })
|
||||
|
||||
tags = tags || []
|
||||
tags = tags.constructor !== Array ? [tags] : tags
|
||||
|
||||
// tags...
|
||||
if(tags.length > 0){
|
||||
this.markChanged('tags')
|
||||
|
||||
tags.indexOf('selected') >= 0
|
||||
&& this.markChanged('selected')
|
||||
|
||||
tags.indexOf('bookmark') >= 0
|
||||
&& this.markChanged('bookmarked')
|
||||
}
|
||||
|
||||
this.markChanged('images', gids)
|
||||
}],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
@ -1366,9 +1441,20 @@ module.ImageGroup = core.ImageGridFeatures.Feature({
|
||||
tag: 'image-group',
|
||||
depends: [
|
||||
'base',
|
||||
'changes',
|
||||
],
|
||||
|
||||
actions: ImageGroupActions,
|
||||
|
||||
handlers: [
|
||||
[[
|
||||
'group',
|
||||
'ungroup',
|
||||
'expandGroup',
|
||||
'collapseGroup',
|
||||
],
|
||||
function(_, target){ this.markChanged('data') }],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
|
||||
@ -21,6 +21,8 @@
|
||||
* - journal
|
||||
* action journaling and undo/redo functionality
|
||||
* XXX needs revision...
|
||||
* - changes
|
||||
* change tracking
|
||||
* - workspace
|
||||
* XXX needs revision...
|
||||
* - tasks
|
||||
@ -29,6 +31,8 @@
|
||||
* basic framework for running test actions at startup...
|
||||
*
|
||||
*
|
||||
* XXX some actions use the .clone(..) action/protocol, should this be
|
||||
* defined here???
|
||||
*
|
||||
**********************************************************************/
|
||||
((typeof define)[0]=='u'?function(f){module.exports=f(require)}:define)
|
||||
@ -794,6 +798,129 @@ module.Journal = ImageGridFeatures.Feature({
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Changes API...
|
||||
|
||||
var ChangesActions = actions.Actions({
|
||||
// This can be:
|
||||
// - null/undefined - write all
|
||||
// - true - write all
|
||||
// - false - write nothing
|
||||
// - {
|
||||
// // write/skip data...
|
||||
// data: <bool>,
|
||||
//
|
||||
// // write/skip images or write a diff including the given
|
||||
// // <gid>s only...
|
||||
// images: <bool> | [ <gid>, ... ],
|
||||
//
|
||||
// // write/skip tags...
|
||||
// tags: <bool>,
|
||||
//
|
||||
// // write/skip bookmarks...
|
||||
// bookmarked: <bool>,
|
||||
//
|
||||
// // write/skip selected...
|
||||
// selected: <bool>,
|
||||
//
|
||||
// // feature specific custom flags...
|
||||
// ...
|
||||
// }
|
||||
//
|
||||
// NOTE: in the complex format all fields ar optional; if a field
|
||||
// is not included it is not written (same as when set to false)
|
||||
// NOTE: .current is written always.
|
||||
chages: null,
|
||||
|
||||
clone: [function(full){
|
||||
return function(res){
|
||||
res.changes = null
|
||||
if(full && this.hasOwnProperty('changes') && this.changes){
|
||||
res.changes = JSON.parse(JSON.stringify(this.changes))
|
||||
}
|
||||
}
|
||||
}],
|
||||
|
||||
markChanged: ['- System/',
|
||||
doc`Mark data sections as changed...
|
||||
|
||||
Mark everything changed...
|
||||
.markChanged('all')
|
||||
|
||||
Mark nothing changed...
|
||||
.markChanged('none')
|
||||
|
||||
Mark section(s) as changed...
|
||||
.markChanged(<section>)
|
||||
.markChanged(<section>, ..)
|
||||
.markChanged([<section>, ..])
|
||||
|
||||
Mark item(s) of section as changed...
|
||||
.markChanged(<section>, [<item>, .. ])
|
||||
|
||||
NOTE: when .changes is null (i.e. everything changed, marked via
|
||||
.markChanged('all')) then calling this with anything other
|
||||
than 'none' will have no effect.
|
||||
`,
|
||||
function(section, items){
|
||||
var that = this
|
||||
var args = section instanceof Array ?
|
||||
section
|
||||
: util.args2array(arguments)
|
||||
//var changes = this.changes =
|
||||
var changes =
|
||||
this.hasOwnProperty('changes') ?
|
||||
this.changes || {}
|
||||
: {}
|
||||
|
||||
// all...
|
||||
if(args.length == 1 && args[0] == 'all'){
|
||||
// NOTE: this is better than delete as it will shadow
|
||||
// the parent's changes in case we got cloned from
|
||||
// a live instance...
|
||||
//delete this.changes
|
||||
this.changes = null
|
||||
|
||||
// none...
|
||||
} else if(args.length == 1 && args[0] == 'none'){
|
||||
this.changes = false
|
||||
|
||||
// everything is marked changed, everything will be saved
|
||||
// anyway...
|
||||
// NOTE: to reset this use .markChanged('none') and then
|
||||
// manually add the desired changes...
|
||||
} else if(this.changes == null){
|
||||
return
|
||||
|
||||
// section items...
|
||||
} else if(items instanceof Array) {
|
||||
changes[section] = (changes[section] || []).concat(items)
|
||||
this.changes = changes
|
||||
|
||||
// section(s)...
|
||||
} else {
|
||||
args.forEach(function(arg){
|
||||
changes[arg] = true
|
||||
})
|
||||
this.changes = changes
|
||||
}
|
||||
}],
|
||||
})
|
||||
|
||||
|
||||
var Changes =
|
||||
module.Changes = ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
doc: '',
|
||||
|
||||
tag: 'changes',
|
||||
depends: [ ],
|
||||
|
||||
actions: ChangesActions,
|
||||
})
|
||||
|
||||
|
||||
|
||||
//---------------------------------------------------------------------
|
||||
// Workspace...
|
||||
//
|
||||
|
||||
@ -115,218 +115,6 @@ module.FileSystemInfo = core.ImageGridFeatures.Feature({
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
// Changes API...
|
||||
|
||||
var ChangesActions = actions.Actions({
|
||||
// This can be:
|
||||
// - null/undefined - write all
|
||||
// - true - write all
|
||||
// - false - write nothing
|
||||
// - {
|
||||
// // write/skip data...
|
||||
// data: <bool>,
|
||||
//
|
||||
// // write/skip images or write a diff including the given
|
||||
// // <gid>s only...
|
||||
// images: <bool> | [ <gid>, ... ],
|
||||
//
|
||||
// // write/skip tags...
|
||||
// tags: <bool>,
|
||||
//
|
||||
// // write/skip bookmarks...
|
||||
// bookmarked: <bool>,
|
||||
//
|
||||
// // write/skip selected...
|
||||
// selected: <bool>,
|
||||
// }
|
||||
//
|
||||
// NOTE: in the complex format all fields ar optional; if a field
|
||||
// is not included it is not written (same as when set to false)
|
||||
// NOTE: .current is written always.
|
||||
chages: null,
|
||||
|
||||
clone: [function(full){
|
||||
return function(res){
|
||||
res.changes = null
|
||||
if(full && this.hasOwnProperty('changes') && this.changes){
|
||||
res.changes = JSON.parse(JSON.stringify(this.changes))
|
||||
}
|
||||
}
|
||||
}],
|
||||
|
||||
// Mark data sections as changed...
|
||||
//
|
||||
// Mark everything changed...
|
||||
// .markChanged('all')
|
||||
//
|
||||
// Mark nothing changed...
|
||||
// .markChanged('none')
|
||||
//
|
||||
// Mark a section changed...
|
||||
// .markChanged('data')
|
||||
// .markChanged('tags')
|
||||
// .markChanged('selected')
|
||||
// .markChanged('bookmarked')
|
||||
//
|
||||
// Mark image changed...
|
||||
// .markChanged(<gid>, ...)
|
||||
// .markChanged([<gid>, ...])
|
||||
//
|
||||
//
|
||||
// NOTE: when .changes is null (i.e. everything changed, marked via
|
||||
// .markChanged('all')) then calling this with anything other
|
||||
// than 'none' will have no effect.
|
||||
markChanged: ['- System/',
|
||||
function(section){
|
||||
var that = this
|
||||
var args = section instanceof Array ? section : util.args2array(arguments)
|
||||
//var changes = this.changes =
|
||||
var changes =
|
||||
this.hasOwnProperty('changes') ?
|
||||
this.changes || {}
|
||||
: {}
|
||||
|
||||
//console.log('CHANGED:', args)
|
||||
|
||||
// all...
|
||||
if(args.length == 1 && args[0] == 'all'){
|
||||
// NOTE: this is better than delete as it will shadow
|
||||
// the parent's changes in case we got cloned from
|
||||
// a live instance...
|
||||
//delete this.changes
|
||||
this.changes = null
|
||||
|
||||
// none...
|
||||
} else if(args.length == 1 && args[0] == 'none'){
|
||||
this.changes = false
|
||||
|
||||
// everything is marked changed, everything will be saved
|
||||
// anyway...
|
||||
// NOTE: to reset this use .markChanged('none') and then
|
||||
// manually add the desired changes...
|
||||
} else if(this.changes == null){
|
||||
return
|
||||
|
||||
} else {
|
||||
var images = (changes.images || [])
|
||||
|
||||
args.forEach(function(arg){
|
||||
var gid = that.data.getImage(arg)
|
||||
|
||||
// special case: image gid...
|
||||
if(gid != -1 && gid != null){
|
||||
images.push(gid)
|
||||
images = images.unique()
|
||||
|
||||
changes.images = images
|
||||
that.changes = changes
|
||||
|
||||
// all other keywords...
|
||||
} else {
|
||||
changes[arg] = true
|
||||
that.changes = changes
|
||||
}
|
||||
})
|
||||
}
|
||||
}],
|
||||
})
|
||||
|
||||
|
||||
var Changes =
|
||||
module.Changes = core.ImageGridFeatures.Feature({
|
||||
title: '',
|
||||
doc: '',
|
||||
|
||||
tag: 'changes',
|
||||
depends: [ ],
|
||||
|
||||
actions: ChangesActions,
|
||||
|
||||
handlers: [
|
||||
// everything changed...
|
||||
[[
|
||||
'loadURLs',
|
||||
'clear',
|
||||
],
|
||||
function(){
|
||||
this.markChanged('all')
|
||||
}],
|
||||
|
||||
// data...
|
||||
[[
|
||||
//'clear',
|
||||
//'load',
|
||||
|
||||
'setBaseRibbon',
|
||||
|
||||
'shiftImageTo',
|
||||
'shiftImageUp',
|
||||
'shiftImageDown',
|
||||
'shiftImageLeft',
|
||||
'shiftImageRight',
|
||||
'shiftRibbonUp',
|
||||
'shiftRibbonDown',
|
||||
|
||||
'sortImages',
|
||||
'reverseImages',
|
||||
'reverseRibbons',
|
||||
|
||||
'alignToRibbon',
|
||||
|
||||
'group',
|
||||
'ungroup',
|
||||
'expandGroup',
|
||||
'collapseGroup',
|
||||
],
|
||||
function(_, target){ this.markChanged('data') }],
|
||||
|
||||
// image specific...
|
||||
[[
|
||||
'rotateCW',
|
||||
'rotateCCW',
|
||||
'flipHorizontal',
|
||||
'flipVertical',
|
||||
],
|
||||
function(_, target){ this.markChanged(target) }],
|
||||
|
||||
// tags and images...
|
||||
// NOTE: tags are also stored in images...
|
||||
['tag untag',
|
||||
function(_, tags, gids){
|
||||
var changes = []
|
||||
|
||||
gids = gids || [this.data.getImage()]
|
||||
gids = gids.constructor !== Array ? [this.data.getImage(gids)] : gids
|
||||
|
||||
tags = tags || []
|
||||
tags = tags.constructor !== Array ? [tags] : tags
|
||||
|
||||
// images...
|
||||
changes = changes.concat(gids)
|
||||
|
||||
// tags...
|
||||
if(tags.length > 0){
|
||||
changes.push('tags')
|
||||
|
||||
// selected...
|
||||
if(tags.indexOf('selected') >= 0){
|
||||
changes.push('selected')
|
||||
}
|
||||
|
||||
// bookmark...
|
||||
if(tags.indexOf('bookmark') >= 0){
|
||||
changes.push('bookmarked')
|
||||
}
|
||||
}
|
||||
|
||||
this.markChanged.apply(this, changes)
|
||||
}],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
|
||||
/*********************************************************************/
|
||||
// Loader...
|
||||
|
||||
|
||||
@ -157,7 +157,7 @@ var MetadataReaderActions = actions.Actions({
|
||||
that.images[gid].metadata = m
|
||||
|
||||
// XXX
|
||||
that.markChanged && that.markChanged(gid)
|
||||
that.markChanged && that.markChanged('images', [gid])
|
||||
}
|
||||
|
||||
resolve(data)
|
||||
|
||||
@ -202,7 +202,7 @@ var SharpActions = actions.Actions({
|
||||
img.orientation = o.orientation
|
||||
img.flipped = o.flipped
|
||||
|
||||
that.markChanged(data.gid)
|
||||
that.markChanged('images', [data.gid])
|
||||
}
|
||||
|
||||
logger && logger.emit(data.status, data.path)
|
||||
@ -287,7 +287,7 @@ module.Sharp = core.ImageGridFeatures.Feature({
|
||||
img.orientation = o.orientation || 0
|
||||
img.flipped = o.flipped
|
||||
|
||||
that.markChanged(gid)
|
||||
that.markChanged('images', [gid])
|
||||
|
||||
// update image to use the orientation...
|
||||
// XXX this might be a source for recursion
|
||||
|
||||
@ -350,8 +350,8 @@ module.SortActions = actions.Actions({
|
||||
this.data.sort_method = data.data.sort_method
|
||||
}
|
||||
|
||||
if(data.data && data.data.sort_cache){
|
||||
this.data.sort_cache = data.data.sort_cache
|
||||
if(data.data && data.sort_cache){
|
||||
this.data.sort_cache = data.sort_cache
|
||||
}
|
||||
}
|
||||
}],
|
||||
@ -363,11 +363,12 @@ module.SortActions = actions.Actions({
|
||||
}
|
||||
|
||||
if(this.data.sort_cache){
|
||||
res.data.sort_cache = this.data.sort_cache
|
||||
res.sort_cache = this.data.sort_cache
|
||||
}
|
||||
|
||||
} else if(this.toggleImageSort('?') == 'Manual'){
|
||||
res.data.sort_cache = res.data.sort_cache || {}
|
||||
res.data.sort_cache['Manual'] = this.data.order
|
||||
if(this.toggleImageSort('?') == 'Manual'){
|
||||
res.sort_cache = res.sort_cache || {}
|
||||
res.sort_cache['Manual'] = this.data.order.slice()
|
||||
}
|
||||
}
|
||||
}],
|
||||
@ -380,6 +381,7 @@ module.Sort = core.ImageGridFeatures.Feature({
|
||||
tag: 'sort',
|
||||
depends: [
|
||||
'base',
|
||||
'changes',
|
||||
],
|
||||
suggested: [
|
||||
'ui-sort',
|
||||
@ -392,6 +394,21 @@ module.Sort = core.ImageGridFeatures.Feature({
|
||||
function(){
|
||||
this.data.sort_method = 'Manual'
|
||||
}],
|
||||
|
||||
['prepareIndexForWrite',
|
||||
function(res){
|
||||
var changed = this.changes == null
|
||||
|| this.changes.sort_cache
|
||||
|
||||
if(changed && res.raw.sort_cache){
|
||||
res.index['sort_cache'] = res.raw.sort_cache
|
||||
}
|
||||
}],
|
||||
|
||||
// manage changes...
|
||||
// XXX also need to mark 'sort_cache'
|
||||
['sortImages',
|
||||
function(_, target){ this.markChanged('data') }],
|
||||
],
|
||||
})
|
||||
|
||||
|
||||
@ -248,10 +248,6 @@ var StatusBarActions = actions.Actions({
|
||||
return item
|
||||
},
|
||||
changes: function(item, gid, img){
|
||||
if(this.changes === undefined){
|
||||
return $()
|
||||
}
|
||||
|
||||
if(typeof(item) == typeof('str')){
|
||||
item = $('<span>')
|
||||
.addClass('changes')
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user