some refactorng + work on saving collections...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-09-18 18:32:34 +03:00
parent cabb03362a
commit af10366c22
7 changed files with 77 additions and 21 deletions

View File

@ -265,6 +265,18 @@ body {
opacity: 0.5; opacity: 0.5;
font-style: italic; font-style: italic;
} }
.browse-widget.collection-list .list .item .text[unsaved]:after {
content: "*";
margin-left: 0px;
opacity: 0.5;
font-style: italic;
}
.browse-widget.collection-list .list .item .text[unsaved][cropped]:after {
content: "* (cropped)";
margin-left: 0px;
opacity: 0.5;
font-style: italic;
}
/* External Editor List */ /* External Editor List */

View File

@ -320,20 +320,20 @@ actions.Actions({
null null
: this.images.getImagePath(gid, this.location.path) : this.images.getImagePath(gid, this.location.path)
}], }],
replaceGid: ['- System/Replace image gid', replaceGID: ['- System/Replace image gid',
{journal: true}, {journal: true},
function(from, to){ function(from, to){
from = this.data.getImage(from) from = this.data.getImage(from)
// data... // data...
var res = this.data.replaceGid(from, to) var res = this.data.replaceGID(from, to)
if(res == null){ if(res == null){
return return
} }
// images... // images...
this.images && this.images.replaceGid(from, to) this.images && this.images.replaceGID(from, to)
}], }],

View File

@ -75,10 +75,24 @@ var CollectionActions = actions.Actions({
// } // }
collections: null, collections: null,
get collectionGIDs(){
var res = {}
var c = this.collections || {}
Object.keys(c)
.forEach(function(title){
res[c[title].gid || title] = title
})
return res
},
get collection(){ get collection(){
return this.location.collection }, return this.location.collection },
set collection(value){ set collection(value){
this.loadCollection(value) }, this.loadCollection(value) },
get collectionGID(){
return ((this.collections || {})[this.collection] || {}).gid },
set collectionGID(value){
this.collection = value },
// XXX should this check consistency??? // XXX should this check consistency???
get collection_order(){ get collection_order(){
@ -243,6 +257,8 @@ var CollectionActions = actions.Actions({
collection = collection == '!' ? collection = collection == '!' ?
this.collection this.collection
: collection : collection
// if collection is a gid, get the title...
collection = this.collectionGIDs[collection] || collection
if(collection == null if(collection == null
|| this.collections == null || this.collections == null
|| !(collection in this.collections)){ || !(collection in this.collections)){
@ -427,7 +443,7 @@ var CollectionActions = actions.Actions({
// save the data... // save the data...
var state = collections[collection] = collections[collection] || {} var state = collections[collection] = collections[collection] || {}
state.title = state.title || collection state.title = state.title || collection
state.gid = state.gid || this.data.newGid() state.gid = state.gid || this.data.newGID()
// NOTE: we do not need to care about tags here as they // NOTE: we do not need to care about tags here as they
// will get overwritten on load... // will get overwritten on load...
state.data = (mode == 'empty' ? state.data = (mode == 'empty' ?
@ -476,7 +492,7 @@ var CollectionActions = actions.Actions({
if(!this.collections || collection == MAIN_COLLECTION_TITLE){ if(!this.collections || collection == MAIN_COLLECTION_TITLE){
return return
} }
delete this.collections[collection] delete this.collections[this.collectionGIDs[collection] || collection]
}], }],
@ -526,6 +542,7 @@ var CollectionActions = actions.Actions({
function(gids, collection){ function(gids, collection){
var that = this var that = this
collection = collection || this.collection collection = collection || this.collection
collection = this.collectionGIDs[collection] || collection
if(collection == null || collection == MAIN_COLLECTION_TITLE){ if(collection == null || collection == MAIN_COLLECTION_TITLE){
return return
} }
@ -580,6 +597,7 @@ var CollectionActions = actions.Actions({
`, `,
function(align, collection, data){ function(align, collection, data){
collection = arguments.length == 1 ? align : collection collection = arguments.length == 1 ? align : collection
collection = this.collectionGIDs[collection] || collection
if(collection == null || collection == MAIN_COLLECTION_TITLE){ if(collection == null || collection == MAIN_COLLECTION_TITLE){
return return
} }
@ -625,6 +643,7 @@ var CollectionActions = actions.Actions({
{browseMode: function(){ return !this.collection && 'disabled' }}, {browseMode: function(){ return !this.collection && 'disabled' }},
function(gids, collection){ function(gids, collection){
collection = collection || this.collection collection = collection || this.collection
collection = this.collectionGIDs[collection] || collection
if(collection == null if(collection == null
|| collection == MAIN_COLLECTION_TITLE || collection == MAIN_COLLECTION_TITLE
|| !this.collections || !this.collections
@ -910,11 +929,25 @@ module.Collection = core.ImageGridFeatures.Feature({
// XXX do we need this??? // XXX do we need this???
['json.pre', ['json.pre',
function(){ this.saveCollection() }], function(){ this.saveCollection() }],
// changes...
//
// format:
// XXX we need:
// - mark collection list changes
// collection-list: true
// - mark whole collection change
// 'collection: <gid>': true
// - mark changes local to collection
// 'collection: <gid>': [<change>, ..]
//
// XXX maintain changes... // XXX maintain changes...
// - collection-level: mark collections as changed... // - collection-level: mark collections as changed...
// - in-collection: // - in-collection:
// - save/restore parent changes when loading/exiting collections // - save/restore parent changes when loading/exiting collections
// - move collection chnages to collections // - move collection chnages to collections
// XXX on sriwthicng collections, need to transfer changes + maintain
// global changes...
[[ [[
'collect', 'collect',
'joinCollect', 'joinCollect',
@ -1421,6 +1454,7 @@ module.AutoCollections = core.ImageGridFeatures.Feature({
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// XXX show collections in image metadata... (???) // XXX show collections in image metadata... (???)
// XXX mark unsaved (*) collections...
var UICollectionActions = actions.Actions({ var UICollectionActions = actions.Actions({
config: { config: {
// Global default collections... // Global default collections...
@ -1445,6 +1479,7 @@ var UICollectionActions = actions.Actions({
&& title != MAIN_COLLECTION_TITLE }, && title != MAIN_COLLECTION_TITLE },
})], })],
// XXX need .changes format...
browseCollections: ['Collections/$Collec$tions...', browseCollections: ['Collections/$Collec$tions...',
core.doc`Collection list... core.doc`Collection list...
@ -1479,7 +1514,16 @@ var UICollectionActions = actions.Actions({
that.focusImage(gid) that.focusImage(gid)
dialog.close() dialog.close()
} }
var setCroppedState = function(title){ var setItemState = function(title){
var text = this.find('.text').last()
// saved state...
// XXX need changes format...
var unsaved = this.changes === true
|| (this.changes || {})['collections: '+ JSON.stringify(title)]
unsaved
&& text.attr('unsaved', true)
// indicate collection crop... // indicate collection crop...
var cs = var cs =
title == (that.collection || MAIN_COLLECTION_TITLE) ? title == (that.collection || MAIN_COLLECTION_TITLE) ?
@ -1488,8 +1532,7 @@ var UICollectionActions = actions.Actions({
that.collections[title].crop_stack that.collections[title].crop_stack
: null : null
cs cs
&& this.find('.text').last() && text.attr('cropped', cs.length)
.attr('cropped', cs.length)
} }
//var collections = Object.keys(that.collections || {}) //var collections = Object.keys(that.collections || {})
@ -1514,7 +1557,7 @@ var UICollectionActions = actions.Actions({
.css('color', 'transparent') .css('color', 'transparent')
.addClass('sort-handle') .addClass('sort-handle')
.html('&#x2630;')) .html('&#x2630;'))
setCroppedState setItemState
.call($(this), title) .call($(this), title)
}, },
open: openHandler, open: openHandler,
@ -1534,7 +1577,7 @@ var UICollectionActions = actions.Actions({
check: function(title){ check: function(title){
return title.length > 0 }, return title.length > 0 },
each: setCroppedState, each: setItemState,
itemadded: function(title){ itemadded: function(title){
action ? action ?
@ -1554,6 +1597,7 @@ var UICollectionActions = actions.Actions({
}) })
}) })
})], })],
// XXX mark unsaved (*) collections...
browseImageCollections: ['Collections|Image/Image $collections...', browseImageCollections: ['Collections|Image/Image $collections...',
widgets.makeUIDialog(function(gid){ widgets.makeUIDialog(function(gid){
var that = this var that = this

View File

@ -1176,7 +1176,7 @@ var TaskActions = actions.Actions({
getJob: ['- Jobs/', getJob: ['- Jobs/',
function(name){ function(name){
name = name || this.data.newGid() name = name || this.data.newGID()
// get/init task dict... // get/init task dict...
var t = this.__jobs = this.__jobs || {} var t = this.__jobs = this.__jobs || {}

View File

@ -62,7 +62,7 @@ var Ribbons = {
noTransitions: null, noTransitions: null,
noTransitionsDeep: null, noTransitionsDeep: null,
elemGID: null, elemGID: null,
replaceGid: null, replaceGID: null,
makeShadow: null, makeShadow: null,

View File

@ -210,10 +210,10 @@ actions.Actions({
}], }],
replaceGid: [ replaceGID: [
function(from, to){ function(from, to){
return function(res){ return function(res){
res && this.ribbons.replaceGid(from, to) res && this.ribbons.replaceGID(from, to)
} }
}], }],

View File

@ -116,7 +116,7 @@ var DataClassPrototype = {
fromArray: function(list){ fromArray: function(list){
var res = new Data() var res = new Data()
// XXX make a real ribbon gid... // XXX make a real ribbon gid...
var gid = res.newGid() var gid = res.newGID()
res.order = list res.order = list
res.ribbon_order.push(gid) res.ribbon_order.push(gid)
res.ribbons[gid] = list.slice() res.ribbons[gid] = list.slice()
@ -447,7 +447,7 @@ var DataPrototype = {
// If no arguments are given then a unique gid will be generated. // If no arguments are given then a unique gid will be generated.
// //
// XXX revise... // XXX revise...
newGid: function(str, nohash){ newGID: function(str, nohash){
// prevent same gids from ever being created... // prevent same gids from ever being created...
// NOTE: this is here in case we are generating new gids fast // NOTE: this is here in case we are generating new gids fast
// enough that Date.now() produces identical results for 2+ // enough that Date.now() produces identical results for 2+
@ -658,7 +658,7 @@ var DataPrototype = {
// Replace image gid... // Replace image gid...
// //
// NOTE: if to exists then it will get overwritten. // NOTE: if to exists then it will get overwritten.
replaceGid: function(from, to){ replaceGID: function(from, to){
if(from in this.ribbons){ if(from in this.ribbons){
// ribbons... // ribbons...
var ribbon = this.ribbons[from] var ribbon = this.ribbons[from]
@ -1414,7 +1414,7 @@ var DataPrototype = {
// If mode is 'below' this will create a new ribbon below the target, // If mode is 'below' this will create a new ribbon below the target,
// otherwise the new ribbon will be created above. // otherwise the new ribbon will be created above.
newRibbon: function(target, mode){ newRibbon: function(target, mode){
var gid = this.newGid() var gid = this.newGID()
var i = this.getRibbonOrder(target) var i = this.getRibbonOrder(target)
i = mode == 'below' ? i+1 : i i = mode == 'below' ? i+1 : i
@ -1960,7 +1960,7 @@ var DataPrototype = {
gids = gids instanceof Array ? gids : [gids] gids = gids instanceof Array ? gids : [gids]
// XXX not safe -- fast enough and one can generate two identical // XXX not safe -- fast enough and one can generate two identical
// gids... // gids...
group = group == null ? this.newGid('G' + Date.now()) : group group = group == null ? this.newGID('G' + Date.now()) : group
if(this.groups == null){ if(this.groups == null){
this.groups = {} this.groups = {}
@ -2314,7 +2314,7 @@ var DataPrototype = {
if(d < 0){ if(d < 0){
// see if g is unique... // see if g is unique...
if(g in base.ribbons || base.order.indexOf(g) >= 0){ if(g in base.ribbons || base.order.indexOf(g) >= 0){
g = base.newGid() g = base.newGID()
} }
base.ribbon_order.splice(t, 0, g) base.ribbon_order.splice(t, 0, g)
base.ribbons[g] = r base.ribbons[g] = r
@ -2330,7 +2330,7 @@ var DataPrototype = {
} else { } else {
// see if g is unique... // see if g is unique...
if(g in base.ribbons || base.order.indexOf(g) >= 0){ if(g in base.ribbons || base.order.indexOf(g) >= 0){
g = base.newGid() g = base.newGID()
} }
base.ribbon_order.push(g) base.ribbon_order.push(g)
base.ribbons[g] = r base.ribbons[g] = r