From 5ef606261364cbe2fd5f39d8eeeb57af383b18fa Mon Sep 17 00:00:00 2001 From: rlx Date: Tue, 9 Aug 2016 13:17:48 +0200 Subject: [PATCH] import media dialog --- pandora/config.pandora.jsonc | 13 +++++++++++ static/js/importMediaDialog.js | 40 +++++++++++++++++++++++++--------- 2 files changed, 43 insertions(+), 10 deletions(-) diff --git a/pandora/config.pandora.jsonc b/pandora/config.pandora.jsonc index 4bc20c764..aad507bf8 100644 --- a/pandora/config.pandora.jsonc +++ b/pandora/config.pandora.jsonc @@ -153,6 +153,19 @@ examples (config.SITENAME.jsonc) that are part of this pan.do/ra distribution. {"id": "embeds", "title": "Embeds"} ], /* + "importMetadata" defines what fields (as defined in "itemKeys") will get + populated with imported metadata. There is metadata for "title", + "description", "uploader", "date", "tags", "id", "url", and the value must + be a format string (like "{title} ({id})"). The type of the itemKeys must + be "string", ["string"], "text", "date" or "year". The last two only work + with "{date}". + */ + "importMetadata": { + "keywords": "{tags}", + "summary": "{description}", + "title": "{title}" + }, + /* "itemKeys" defines the metadata associated with each item. Required keys are "*", "id" and "title". Annotation layers can be referenced too, which makes them available in the find element. Adding a key with "annotations" diff --git a/static/js/importMediaDialog.js b/static/js/importMediaDialog.js index 699eabd88..cec2cde11 100644 --- a/static/js/importMediaDialog.js +++ b/static/js/importMediaDialog.js @@ -88,15 +88,36 @@ pandora.ui.importMediaDialog = function(options) { function addMedia(url, callback) { pandora.api.getMediaUrlInfo({url: url}, function(result) { result.data.items.forEach(function(info) { - pandora.api.add({title: info.title}, function(result) { - var edit = { - date: info.date, - director: info.uploader ? [info.uploader] : [], - id: result.data.id, - notes: info.url, - summary: info.description, - topic: info.tags - }; + var infoKeys = [ + "date", "description", "id", "tags", + "title", "uploader", "url" + ]; + var values = Ox.map(pandora.site.importMetadata, function(value, key) { + var type = pandora.site.itemKeys[key].type; + infoKeys.forEach(function(infoKey) { + infoValue = info[infoKey]; + if (key == 'year') { + infoValue = infoValue.substr(0, 4); + } + if (infoKey == 'tags' && Ox.isArray(type)) { + infoValue = infoValue.join(', '); + } + value = value.replace( + new RegExp('\{' + infoKey '\}', 'g'), infoValue + ); + }); + if (Ox.isArray(type)) { + value = [value]; + } + return value; + }); + pandora.api.add({title: values.title || info.title}, function(result) { + var edit = Ox.extend( + Ox.filter(values, function(value, key) { + return key != 'title' + }), + {'id': result.data.id} + ); pandora.api.edit(edit, function(result) { pandora.api.addMediaUrl({ url: info.url, @@ -104,7 +125,6 @@ pandora.ui.importMediaDialog = function(options) { }, function(result) { if (result.data.taskId) { pandora.wait(result.data.taskId, function(result) { - Ox.print('status?', result); callback(edit.id); }); } else {