basic metadata support added, still needs lots of work...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2016-01-15 05:19:42 +03:00
parent 4b1a73e30b
commit 8dacec8a26
3 changed files with 102 additions and 25 deletions

View File

@ -79,6 +79,7 @@ module.Metadata = core.ImageGridFeatures.Feature({
// XXX add Metadata writer... // XXX add Metadata writer...
// XXX need a way to trigger read-metadata...
var MetadataReaderActions = actions.Actions({ var MetadataReaderActions = actions.Actions({
// XXX should this be sync??? // XXX should this be sync???
// XXX should this process multiple images??? // XXX should this process multiple images???
@ -91,7 +92,12 @@ var MetadataReaderActions = actions.Actions({
var that = this var that = this
var gid = this.data.getImage(image) var gid = this.data.getImage(image)
var img = this.images[gid] var img = this.images && this.images[gid]
if(!image){
return
}
var full_path = path.normalize(img.base_path +'/'+ img.path) var full_path = path.normalize(img.base_path +'/'+ img.path)
return new promise(function(resolve, reject){ return new promise(function(resolve, reject){
@ -119,6 +125,8 @@ var MetadataReaderActions = actions.Actions({
resolve(data) resolve(data)
} }
resolve(data)
}) })
}) })
}) })
@ -145,6 +153,20 @@ module.MetadataReader = core.ImageGridFeatures.Feature({
return this.runtime == 'nw' || this.runtime == 'node' }, return this.runtime == 'nw' || this.runtime == 'node' },
actions: MetadataReaderActions, actions: MetadataReaderActions,
handlers: [
// XXX STUB: need a better strategy to read metadata...
['focusImage',
function(){
var gid = this.current
metadata = this.images && this.images[gid] && this.images[gid].metadata
metadata = metadata && (Object.keys(metadata).length > 0)
if(!metadata){
this.readMetadata(gid)
}
}]
],
}) })
@ -169,48 +191,91 @@ module.MetadataReader = core.ImageGridFeatures.Feature({
// XXX add a way to sort fields... // XXX add a way to sort fields...
// XXX this should basically be platform independent... // XXX this should basically be platform independent...
// XXX add ability to sort fields -- moving a field up/down edits .config...
// ...not sure how to go about this yet...
// XXX add combined fields...
// 'Make' + 'Camera Model Name'
// XXX add identical fields -- show first available and hide the rest...
// 'Shutter Speed', 'Exposure Time',
// 'Lens ID', 'Lens'
var MetadataUIActions = actions.Actions({ var MetadataUIActions = actions.Actions({
config: { config: {
'metadata-field-order': [ 'metadata-field-order': [
'Make', 'Camera Model Name', 'Lens ID', 'Lens', 'Lens Profile Name', 'Focal Length',
'Metering Mode', 'Exposure Program', 'Exposure Compensation',
'Shutter Speed Value', 'Aperture Value', 'Iso',
'Artist', 'Copyright',
'Date/time Original', 'Create Date', 'Modify Date',
'Mime Type',
// NOTE: this is here so as not to hide the 'metadata: unavailable'
// message when not metadata is present and .showMetadata(..)
// is called in 'short' mode...
'Metadata',
], ],
}, },
showMetadata: ['Image/Show metadata', showMetadata: ['Image/Show metadata',
function(image, force){ function(image, mode){
image = this.data.getImage(image) image = this.data.getImage(image)
// XXX make a list with two .text elements per list item: mode = mode || 'short'
// .text.field - metadata field name
// .text.value - metadata field value
// Add CSS:
// .metadata-browser .list>div .text {
// display: inline-block;
// width: 50%;
// }
// .metadata-browser .list>div .text:first-child {
// text-align: right;
// }
// .metadata-browser .list>div .text:first-child:after {
// content: ": ";
// }
// .metadata-browser .list>div .text:last-child {
// }
var field_order = this.config['metadata-field-order'] || []
var x = field_order.length + 1
// get image metadata...
var metadata = (this.images
&& this.images[image]
&& this.images[image].metadata)
|| { metadata: 'unavailable.' }
// build fields...
var fields = []
Object.keys(metadata).forEach(function(k){
var n = k
// convert camel-case to human-case ;)
.replace(/([A-Z]+)/g, ' $1')
.capitalize()
// skip metadata stuff in short mode...
if(mode == 'short'
&& field_order.indexOf(n) == -1){
return
}
fields.push([ n + ': ',
metadata[k] ])
})
// sort fields...
fields.sort(function(a, b){
a = field_order.indexOf(a[0].replace(/: $/, ''))
a = a == -1 ? x : a
b = field_order.indexOf(b[0].replace(/: $/, ''))
b = b == -1 ? x : b
return a - b
})
// XXX replace field names with pretty names...
// XXX do two types of fields:
// - base
// - other (browse.Browse + sub-directory???)
var o = overlay.Overlay(this.ribbons.viewer, var o = overlay.Overlay(this.ribbons.viewer,
browse.makeList( browse.makeList(
null, null,
[ fields)
['aaa', 'bbb'],
['bbb', 'ccc'],
['ccc', 'ddd'],
])
// path selected... // path selected...
.open(function(evt, path){ .open(function(evt, path){
console.log('!!!!!', path) //o.close()
o.close()
})) }))
.close(function(){ .close(function(){
}) })
o.client.dom.addClass('metadata-view')
return o return o
}] }]

View File

@ -123,6 +123,15 @@ body {
} }
/* Metadata viewer */
.browse-widget.metadata-view .list>div .text:first-child {
width: 50%;
font-weight: bold;
}
.browse-widget.metadata-view .list>div .text:nth-child(2) {
font-style: italic;
}
/* External Editor List */ /* External Editor List */
.browse-widget.editor-list .list>div:first-child .text:after { .browse-widget.editor-list .list>div:first-child .text:after {

View File

@ -218,6 +218,9 @@ module.GLOBAL_KEYBOARD = {
ctrl: 'toggleMark!: "ribbon" "off"', ctrl: 'toggleMark!: "ribbon" "off"',
}, },
I: { I: {
default: 'showMetadata',
shift: 'showMetadata: "current" "full"',
ctrl: 'toggleMark!: "ribbon"', ctrl: 'toggleMark!: "ribbon"',
'meta+alt': 'showDevTools', 'meta+alt': 'showDevTools',