digirati-annotation-bridge
Advanced tools
Comparing version 0.5.1 to 0.6.0
@@ -28,3 +28,3 @@ var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
export function resourceTemplateReverseTypeLookup(fields, key) { | ||
for (var _iterator = fields, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = Object.values(fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
@@ -154,3 +154,3 @@ | ||
if (!(resourceTemplate && resourceTemplate.captureModels && resourceTemplate.captureModels['madoc:form'] && resourceTemplate.captureModels['madoc:form'].interactiveResources)) { | ||
if (!(resourceTemplate && resourceTemplate.fields)) { | ||
return null; | ||
@@ -160,3 +160,3 @@ } | ||
id: annotation.id, | ||
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, getAnnotationBody(annotation)), | ||
input: mapAnnotationBody(resourceTemplate.fields, getAnnotationBody(annotation)), | ||
selector: mapTargetToSelector(mapTarget(annotation.target, scale)), | ||
@@ -163,0 +163,0 @@ isPublishing: true, |
@@ -10,2 +10,67 @@ import { ID, OMEKA_LABEL } from './vocab'; | ||
export function parseSelectorTarget(toParse) { | ||
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
if (!toParse) { | ||
return toParse; | ||
} | ||
var W3C_SELECTOR = /[#&?](xywh=)?(pixel:|percent:)?([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?)/; | ||
var match = W3C_SELECTOR.exec(toParse); | ||
if (match) { | ||
return { | ||
unit: match[2] === 'percent:' ? 'percent' : 'pixel', | ||
scale: scale, | ||
expanded: true, | ||
x: parseFloat(match[3]) * scale, | ||
y: parseFloat(match[5]) * scale, | ||
width: parseFloat(match[7]) * scale, | ||
height: parseFloat(match[9]) * scale, | ||
toString: function toString() { | ||
// @todo maybe something else? | ||
return toParse.split('#')[0]; | ||
} | ||
}; | ||
} | ||
return toParse; | ||
} | ||
export function castId(value, defaultValue) { | ||
return (value[ID] ? value[ID] : value) || defaultValue; | ||
} | ||
export function get(value) { | ||
return function (prop, defaultValue) { | ||
return value ? value[prop] : defaultValue; | ||
}; | ||
} | ||
export function getMotivationInstance(str) { | ||
var motive = str.toLowerCase(); | ||
// Remove the open annotation prefix. | ||
if (motive.indexOf('oa:') === 0) { | ||
return getMotivationInstance(motive.substr(3)); | ||
} | ||
if (['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning', 'replying', 'tagging'].indexOf(motive) !== -1) { | ||
return motive; | ||
} | ||
// This is the default to fallback to. | ||
return 'tagging'; | ||
} | ||
export function motivationFromForm(motivatedBy) { | ||
if (!motivatedBy) { | ||
return null; | ||
} | ||
if (!motivatedBy.id) { | ||
return null; | ||
} | ||
return { | ||
id: motivatedBy.id, | ||
label: motivatedBy.label ? motivatedBy.label : motivatedBy.id, | ||
instance: getMotivationInstance(motivatedBy.id) | ||
}; | ||
} | ||
export function labelId(res) { | ||
@@ -12,0 +77,0 @@ if (!res) { |
177
es/index.js
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; | ||
import { addCaptureModel, addInteractiveResource, addResourceTemplate } from 'digirati-annotation-redux/es/actions/resourceTemplate'; | ||
import { getCurrentResourceTemplate, getForm } from 'digirati-annotation-redux/es/query/resourceTemplateQuery'; | ||
import { getCurrentResourceTemplate, getForm } from 'digirati-annotation-redux/es/query/resourceQuery'; | ||
import { getCurrentDraft } from 'digirati-annotation-redux/es/query/draftQuery'; | ||
import { importResource, importResourceTree } from 'digirati-annotation-redux/es/actions/resources'; | ||
import { createDraftFromAnnotation, mapAnnotationBody, mapTarget, parseTarget, resourceTemplateReverseTypeLookup } from './annotations'; | ||
import { BODY_TYPE, COMBINE, CONFORMS_TO, DESCRIPTION, EXTERNALISE, FORM_FIELDS, HAS_PART, HUMAN_READABLE, ID, INPUT_TYPE, LABEL_PARTS, MOTIVATED_BY, MULTIPLE, PURPOSE, RDFS_LABEL, SELECTOR, SELECTOR_VALUE, SERIALIZE, TITLE, TYPE, UI_CHOICE, UI_GROUP } from './vocab'; | ||
import { motivationFromForm } from './helpers'; | ||
import Choice from './model/Choice'; | ||
import CaptureModel from './model/CaptureModel'; | ||
import { castBool, labelId } from './helpers'; | ||
export function getMotivationInstance(str) { | ||
var motive = str.toLowerCase(); | ||
// Remove the open annotation prefix. | ||
if (motive.indexOf('oa:') === 0) { | ||
return getMotivationInstance(motive.substr(3)); | ||
} | ||
if (['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning', 'replying', 'tagging'].indexOf(motive) !== -1) { | ||
return motive; | ||
} | ||
// This is the default to fallback to. | ||
return 'tagging'; | ||
} | ||
function motivationFromForm(motivatedBy) { | ||
if (!motivatedBy) { | ||
return null; | ||
} | ||
if (!motivatedBy.id) { | ||
return null; | ||
} | ||
return { | ||
id: motivatedBy.id, | ||
label: motivatedBy.label ? motivatedBy.label : motivatedBy.id, | ||
instance: getMotivationInstance(motivatedBy.id) | ||
}; | ||
} | ||
export function mapDraftToDataSet(captureModels, values) { | ||
export function mapDraftToDataSet(fields, values) { | ||
var contexts = {}; | ||
var body = {}; | ||
captureModels.forEach(function (model) { | ||
fields.forEach(function (model) { | ||
if (model.metaData.conformsTo && values[model.id]) { | ||
@@ -57,6 +30,6 @@ contexts[model.metaData.conformsTo.label] = model.metaData.conformsTo.id; | ||
function getLabelFromResourceTemplate(template, data) { | ||
if (!(template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].labelParts && template.captureModels['madoc:form'].labelParts.label)) { | ||
if (!(template.metaData.labelParts && template.metaData.labelParts.label)) { | ||
return null; | ||
} | ||
var labelField = template.captureModels['madoc:form'].labelParts.label; | ||
var labelField = template.metaData.labelParts.label; | ||
@@ -105,3 +78,3 @@ return data[labelField] ? data[labelField] : null; | ||
var resourceTemplate = getCurrentResourceTemplate(state); | ||
var captureModels = getForm(resourceTemplate).fields; | ||
var fields = Object.values(getForm(resourceTemplate).fields); | ||
@@ -113,3 +86,3 @@ var selectors = Object.keys(currentDraft.selectors || {}).map(function (key) { | ||
var capModel = captureModels.find(function (model) { | ||
var capModel = fields.find(function (model) { | ||
return model.id === selector.id; | ||
@@ -119,3 +92,3 @@ }); | ||
id: selector.id, | ||
annotation: dataSetToSingleAnnotation(capModel, mapDraftToDataSet(captureModels, (_mapDraftToDataSet = {}, _mapDraftToDataSet[selector.id] = currentDraft.input[selector.id], _mapDraftToDataSet))) | ||
annotation: dataSetToSingleAnnotation(capModel, mapDraftToDataSet(fields, (_mapDraftToDataSet = {}, _mapDraftToDataSet[selector.id] = currentDraft.input[selector.id], _mapDraftToDataSet))) | ||
}; | ||
@@ -147,5 +120,5 @@ }); | ||
var resourceTemplate = getCurrentResourceTemplate(state); | ||
var captureModels = getForm(resourceTemplate).fields; | ||
var fields = Object.values(getForm(resourceTemplate).fields); | ||
return dataSetToAnnotation(resourceTemplate, mapDraftToDataSet(captureModels, currentDraft.input)); | ||
return dataSetToAnnotation(resourceTemplate, mapDraftToDataSet(fields, currentDraft.input)); | ||
} | ||
@@ -155,3 +128,3 @@ | ||
return { | ||
motivation: motivationFromForm(template && template.captureModels && template.captureModels['madoc:form'] ? template.captureModels['madoc:form'].motivatedBy : { | ||
motivation: motivationFromForm(template ? template.motivatedBy : { | ||
id: null, | ||
@@ -167,3 +140,3 @@ label: 'Tagging', | ||
export function getDraftTemplateFromCaptureModel(template) { | ||
var resources = template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].interactiveResources; | ||
var resources = template.fields; | ||
return Object.keys(resources).reduce(function (obj, key) { | ||
@@ -176,3 +149,3 @@ obj[resources[key].id] = null; | ||
export function getDraftSelectorsFromCaptureModel(template) { | ||
var resources = template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].interactiveResources; | ||
var resources = template.fields; | ||
return Object.keys(resources).reduce(function (obj, key) { | ||
@@ -186,106 +159,32 @@ obj[resources[key].id] = _extends({ | ||
function get(value) { | ||
return function (prop, defaultValue) { | ||
return value ? value[prop] : defaultValue; | ||
}; | ||
} | ||
export function omekaImportResourceTemplate(dispatch, resourceTemplate) { | ||
var resourceTemplateValues = get(resourceTemplate); | ||
// Recurse all the things. | ||
if (resourceTemplateValues(UI_CHOICE) === 'True' && Array.isArray(resourceTemplateValues(HAS_PART))) { | ||
return resourceTemplateValues(HAS_PART).map(function (template) { | ||
return omekaImportResourceTemplate(dispatch, template); | ||
}); | ||
export function constructUnknownTemplate(resourceTemplate) { | ||
if (Choice.is(resourceTemplate)) { | ||
return Choice.fromJsonLD(resourceTemplate); | ||
} | ||
// Set the resource template | ||
dispatch(addResourceTemplate(resourceTemplateValues(ID), resourceTemplateValues(DESCRIPTION), resourceTemplateValues(TITLE), { | ||
type: resourceTemplateValues(TYPE), | ||
conformsTo: labelId(resourceTemplateValues(CONFORMS_TO)), | ||
selector: resourceTemplate[SELECTOR] ? ((resourceTemplate[SELECTOR][ID] ? resourceTemplate[SELECTOR][ID] : resourceTemplate[SELECTOR][ID]) || '').toLowerCase() : null, | ||
rdfsLabel: resourceTemplateValues(RDFS_LABEL) | ||
})); | ||
// Set the capture model | ||
if (resourceTemplate[UI_GROUP]) { | ||
var _resourceTemplateValu; | ||
dispatch(addCaptureModel(resourceTemplateValues(ID), resourceTemplateValues(UI_GROUP, (_resourceTemplateValu = {}, _resourceTemplateValu[ID] = null, _resourceTemplateValu))[ID], { | ||
combine: castBool(resourceTemplateValues(COMBINE, true)), | ||
externalise: castBool(resourceTemplateValues(EXTERNALISE, true)), | ||
humanReadable: castBool(resourceTemplateValues(HUMAN_READABLE, true)), | ||
serialize: castBool(resourceTemplateValues(SERIALIZE)), | ||
multiple: castBool(resourceTemplateValues(MULTIPLE)), | ||
selectorValue: resourceTemplateValues(), | ||
selector: resourceTemplateValues(SELECTOR) ? ((resourceTemplateValues(SELECTOR)[ID] ? resourceTemplateValues(SELECTOR)[ID] : resourceTemplateValues(SELECTOR)) || '').toLowerCase() : null, | ||
motivatedBy: motivationFromForm(labelId(resourceTemplateValues(MOTIVATED_BY))), | ||
labelParts: labelId(resourceTemplateValues(LABEL_PARTS)) | ||
})); | ||
if (resourceTemplateValues(FORM_FIELDS)) { | ||
resourceTemplateValues(FORM_FIELDS).map(function (field) { | ||
var _resourceTemplateValu2, _fieldValues; | ||
var fieldValues = get(field); | ||
dispatch(addInteractiveResource(resourceTemplateValues(ID), resourceTemplateValues(UI_GROUP, (_resourceTemplateValu2 = {}, _resourceTemplateValu2[ID] = null, _resourceTemplateValu2))[ID], fieldValues(ID), fieldValues(INPUT_TYPE, (_fieldValues = {}, _fieldValues[ID] = null, _fieldValues))[ID], { | ||
annotationMetaData: { | ||
options: fieldValues('crowds:uiInputOptions') | ||
}, | ||
omekaMetaData: { | ||
type: fieldValues(TYPE), | ||
bodyType: labelId(fieldValues(BODY_TYPE)), | ||
purpose: labelId(fieldValues(PURPOSE)) | ||
}, | ||
metaData: { | ||
title: fieldValues(RDFS_LABEL) || fieldValues(TITLE), | ||
description: fieldValues(DESCRIPTION), | ||
conformsTo: labelId(fieldValues(CONFORMS_TO)), | ||
selector: fieldValues(SELECTOR) ? fieldValues(SELECTOR)[ID] : null, | ||
selectorValue: parseSelectorTarget(fieldValues(SELECTOR_VALUE)) | ||
} | ||
})); | ||
}); | ||
} | ||
if (CaptureModel.is(resourceTemplate)) { | ||
return CaptureModel.fromJsonLD(resourceTemplate); | ||
} | ||
} | ||
function parseSelectorTarget(toParse) { | ||
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
export function importResourceTemplate(resourceTemplate) { | ||
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'canvas'; | ||
if (!toParse) { | ||
return toParse; | ||
} | ||
var W3C_SELECTOR = /[#&?](xywh=)?(pixel:|percent:)?([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?)/; | ||
var match = W3C_SELECTOR.exec(toParse); | ||
return function (dispatch) { | ||
var tree = constructUnknownTemplate(resourceTemplate); | ||
if (match) { | ||
return { | ||
unit: match[2] === 'percent:' ? 'percent' : 'pixel', | ||
scale: scale, | ||
expanded: true, | ||
x: parseFloat(match[3]) * scale, | ||
y: parseFloat(match[5]) * scale, | ||
width: parseFloat(match[7]) * scale, | ||
height: parseFloat(match[9]) * scale, | ||
toString: function toString() { | ||
// @todo maybe something else? | ||
return toParse.split('#')[0]; | ||
} | ||
}; | ||
} | ||
return toParse; | ||
} | ||
if (!tree) { | ||
return; | ||
} | ||
if (tree instanceof CaptureModel) { | ||
return dispatch(importResource(tree)); | ||
} | ||
export default function omekaCreateStore(createStore, reducers, resourceTemplate) { | ||
var middleware = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
dispatch(importResourceTree(tree.getTree(target))); | ||
// Create store. | ||
var store = createStore(reducers, middleware); | ||
// Import all resource templates provided. | ||
resourceTemplate.map(function (singleTemplate) { | ||
return omekaImportResourceTemplate(store.dispatch, singleTemplate); | ||
}); | ||
// return store. | ||
return store; | ||
tree.flatten().forEach(function (r) { | ||
return dispatch(importResource(r)); | ||
}); | ||
}; | ||
} | ||
export { createDraftFromAnnotation, mapAnnotationBody, mapTarget, parseTarget, resourceTemplateReverseTypeLookup }; |
@@ -33,4 +33,6 @@ // DUBLIN CORE CONSTANTS | ||
export var INPUT_TYPE = 'crowds:uiInputType'; | ||
export var INPUT_OPTIONS = 'crowds:uiInputOptions'; | ||
export var INPUT_AUTOCOMPLETE_URI = 'crowds:uiInputAutocomplete'; | ||
export var BOX_SELECTOR = 'madoc:boxdraw'; | ||
export var WHOLE_CANVAS_SELECTOR = 'WholeCanvasSelector'; // @todo change to madoc: ns |
@@ -51,3 +51,3 @@ 'use strict'; | ||
function resourceTemplateReverseTypeLookup(fields, key) { | ||
for (var _iterator = fields, _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
for (var _iterator = Object.values(fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) { | ||
var _ref; | ||
@@ -177,3 +177,3 @@ | ||
if (!(resourceTemplate && resourceTemplate.captureModels && resourceTemplate.captureModels['madoc:form'] && resourceTemplate.captureModels['madoc:form'].interactiveResources)) { | ||
if (!(resourceTemplate && resourceTemplate.fields)) { | ||
return null; | ||
@@ -183,3 +183,3 @@ } | ||
id: annotation.id, | ||
input: mapAnnotationBody(resourceTemplate.captureModels['madoc:form'].interactiveResources, getAnnotationBody(annotation)), | ||
input: mapAnnotationBody(resourceTemplate.fields, getAnnotationBody(annotation)), | ||
selector: mapTargetToSelector(mapTarget(annotation.target, scale)), | ||
@@ -186,0 +186,0 @@ isPublishing: true, |
@@ -5,2 +5,7 @@ 'use strict'; | ||
exports.castBool = castBool; | ||
exports.parseSelectorTarget = parseSelectorTarget; | ||
exports.castId = castId; | ||
exports.get = get; | ||
exports.getMotivationInstance = getMotivationInstance; | ||
exports.motivationFromForm = motivationFromForm; | ||
exports.labelId = labelId; | ||
@@ -18,2 +23,67 @@ exports.iteratorGenerator = iteratorGenerator; | ||
function parseSelectorTarget(toParse) { | ||
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
if (!toParse) { | ||
return toParse; | ||
} | ||
var W3C_SELECTOR = /[#&?](xywh=)?(pixel:|percent:)?([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?)/; | ||
var match = W3C_SELECTOR.exec(toParse); | ||
if (match) { | ||
return { | ||
unit: match[2] === 'percent:' ? 'percent' : 'pixel', | ||
scale: scale, | ||
expanded: true, | ||
x: parseFloat(match[3]) * scale, | ||
y: parseFloat(match[5]) * scale, | ||
width: parseFloat(match[7]) * scale, | ||
height: parseFloat(match[9]) * scale, | ||
toString: function toString() { | ||
// @todo maybe something else? | ||
return toParse.split('#')[0]; | ||
} | ||
}; | ||
} | ||
return toParse; | ||
} | ||
function castId(value, defaultValue) { | ||
return (value[_vocab.ID] ? value[_vocab.ID] : value) || defaultValue; | ||
} | ||
function get(value) { | ||
return function (prop, defaultValue) { | ||
return value ? value[prop] : defaultValue; | ||
}; | ||
} | ||
function getMotivationInstance(str) { | ||
var motive = str.toLowerCase(); | ||
// Remove the open annotation prefix. | ||
if (motive.indexOf('oa:') === 0) { | ||
return getMotivationInstance(motive.substr(3)); | ||
} | ||
if (['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning', 'replying', 'tagging'].indexOf(motive) !== -1) { | ||
return motive; | ||
} | ||
// This is the default to fallback to. | ||
return 'tagging'; | ||
} | ||
function motivationFromForm(motivatedBy) { | ||
if (!motivatedBy) { | ||
return null; | ||
} | ||
if (!motivatedBy.id) { | ||
return null; | ||
} | ||
return { | ||
id: motivatedBy.id, | ||
label: motivatedBy.label ? motivatedBy.label : motivatedBy.id, | ||
instance: getMotivationInstance(motivatedBy.id) | ||
}; | ||
} | ||
function labelId(res) { | ||
@@ -20,0 +90,0 @@ if (!res) { |
187
lib/index.js
@@ -8,3 +8,2 @@ 'use strict'; | ||
exports.getMotivationInstance = getMotivationInstance; | ||
exports.mapDraftToDataSet = mapDraftToDataSet; | ||
@@ -18,50 +17,30 @@ exports.dataSetToAnnotation = dataSetToAnnotation; | ||
exports.getDraftSelectorsFromCaptureModel = getDraftSelectorsFromCaptureModel; | ||
exports.omekaImportResourceTemplate = omekaImportResourceTemplate; | ||
exports.default = omekaCreateStore; | ||
exports.constructUnknownTemplate = constructUnknownTemplate; | ||
exports.importResourceTemplate = importResourceTemplate; | ||
var _resourceTemplate = require('digirati-annotation-redux/es/actions/resourceTemplate'); | ||
var _resourceQuery = require('digirati-annotation-redux/es/query/resourceQuery'); | ||
var _resourceTemplateQuery = require('digirati-annotation-redux/es/query/resourceTemplateQuery'); | ||
var _draftQuery = require('digirati-annotation-redux/es/query/draftQuery'); | ||
var _resources = require('digirati-annotation-redux/es/actions/resources'); | ||
var _annotations = require('./annotations'); | ||
var _vocab = require('./vocab'); | ||
var _helpers = require('./helpers'); | ||
function getMotivationInstance(str) { | ||
var motive = str.toLowerCase(); | ||
// Remove the open annotation prefix. | ||
if (motive.indexOf('oa:') === 0) { | ||
return getMotivationInstance(motive.substr(3)); | ||
} | ||
if (['assessing', 'bookmarking', 'classifying', 'commenting', 'describing', 'editing', 'highlighting', 'identifying', 'linking', 'moderating', 'questioning', 'replying', 'tagging'].indexOf(motive) !== -1) { | ||
return motive; | ||
} | ||
var _Choice = require('./model/Choice'); | ||
// This is the default to fallback to. | ||
return 'tagging'; | ||
} | ||
var _Choice2 = _interopRequireDefault(_Choice); | ||
function motivationFromForm(motivatedBy) { | ||
if (!motivatedBy) { | ||
return null; | ||
} | ||
if (!motivatedBy.id) { | ||
return null; | ||
} | ||
return { | ||
id: motivatedBy.id, | ||
label: motivatedBy.label ? motivatedBy.label : motivatedBy.id, | ||
instance: getMotivationInstance(motivatedBy.id) | ||
}; | ||
} | ||
var _CaptureModel = require('./model/CaptureModel'); | ||
function mapDraftToDataSet(captureModels, values) { | ||
var _CaptureModel2 = _interopRequireDefault(_CaptureModel); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function mapDraftToDataSet(fields, values) { | ||
var contexts = {}; | ||
var body = {}; | ||
captureModels.forEach(function (model) { | ||
fields.forEach(function (model) { | ||
if (model.metaData.conformsTo && values[model.id]) { | ||
@@ -79,6 +58,6 @@ contexts[model.metaData.conformsTo.label] = model.metaData.conformsTo.id; | ||
function getLabelFromResourceTemplate(template, data) { | ||
if (!(template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].labelParts && template.captureModels['madoc:form'].labelParts.label)) { | ||
if (!(template.metaData.labelParts && template.metaData.labelParts.label)) { | ||
return null; | ||
} | ||
var labelField = template.captureModels['madoc:form'].labelParts.label; | ||
var labelField = template.metaData.labelParts.label; | ||
@@ -126,4 +105,4 @@ return data[labelField] ? data[labelField] : null; | ||
var currentDraft = (0, _draftQuery.getCurrentDraft)(state); | ||
var resourceTemplate = (0, _resourceTemplateQuery.getCurrentResourceTemplate)(state); | ||
var captureModels = (0, _resourceTemplateQuery.getForm)(resourceTemplate).fields; | ||
var resourceTemplate = (0, _resourceQuery.getCurrentResourceTemplate)(state); | ||
var fields = Object.values((0, _resourceQuery.getForm)(resourceTemplate).fields); | ||
@@ -135,3 +114,3 @@ var selectors = Object.keys(currentDraft.selectors || {}).map(function (key) { | ||
var capModel = captureModels.find(function (model) { | ||
var capModel = fields.find(function (model) { | ||
return model.id === selector.id; | ||
@@ -141,3 +120,3 @@ }); | ||
id: selector.id, | ||
annotation: dataSetToSingleAnnotation(capModel, mapDraftToDataSet(captureModels, (_mapDraftToDataSet = {}, _mapDraftToDataSet[selector.id] = currentDraft.input[selector.id], _mapDraftToDataSet))) | ||
annotation: dataSetToSingleAnnotation(capModel, mapDraftToDataSet(fields, (_mapDraftToDataSet = {}, _mapDraftToDataSet[selector.id] = currentDraft.input[selector.id], _mapDraftToDataSet))) | ||
}; | ||
@@ -168,6 +147,6 @@ }); | ||
var currentDraft = (0, _draftQuery.getCurrentDraft)(state); | ||
var resourceTemplate = (0, _resourceTemplateQuery.getCurrentResourceTemplate)(state); | ||
var captureModels = (0, _resourceTemplateQuery.getForm)(resourceTemplate).fields; | ||
var resourceTemplate = (0, _resourceQuery.getCurrentResourceTemplate)(state); | ||
var fields = Object.values((0, _resourceQuery.getForm)(resourceTemplate).fields); | ||
return dataSetToAnnotation(resourceTemplate, mapDraftToDataSet(captureModels, currentDraft.input)); | ||
return dataSetToAnnotation(resourceTemplate, mapDraftToDataSet(fields, currentDraft.input)); | ||
} | ||
@@ -177,3 +156,3 @@ | ||
return { | ||
motivation: motivationFromForm(template && template.captureModels && template.captureModels['madoc:form'] ? template.captureModels['madoc:form'].motivatedBy : { | ||
motivation: (0, _helpers.motivationFromForm)(template ? template.motivatedBy : { | ||
id: null, | ||
@@ -189,3 +168,3 @@ label: 'Tagging', | ||
function getDraftTemplateFromCaptureModel(template) { | ||
var resources = template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].interactiveResources; | ||
var resources = template.fields; | ||
return Object.keys(resources).reduce(function (obj, key) { | ||
@@ -198,3 +177,3 @@ obj[resources[key].id] = null; | ||
function getDraftSelectorsFromCaptureModel(template) { | ||
var resources = template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].interactiveResources; | ||
var resources = template.fields; | ||
return Object.keys(resources).reduce(function (obj, key) { | ||
@@ -208,104 +187,30 @@ obj[resources[key].id] = _extends({ | ||
function get(value) { | ||
return function (prop, defaultValue) { | ||
return value ? value[prop] : defaultValue; | ||
}; | ||
} | ||
function omekaImportResourceTemplate(dispatch, resourceTemplate) { | ||
var resourceTemplateValues = get(resourceTemplate); | ||
// Recurse all the things. | ||
if (resourceTemplateValues(_vocab.UI_CHOICE) === 'True' && Array.isArray(resourceTemplateValues(_vocab.HAS_PART))) { | ||
return resourceTemplateValues(_vocab.HAS_PART).map(function (template) { | ||
return omekaImportResourceTemplate(dispatch, template); | ||
}); | ||
function constructUnknownTemplate(resourceTemplate) { | ||
if (_Choice2.default.is(resourceTemplate)) { | ||
return _Choice2.default.fromJsonLD(resourceTemplate); | ||
} | ||
// Set the resource template | ||
dispatch((0, _resourceTemplate.addResourceTemplate)(resourceTemplateValues(_vocab.ID), resourceTemplateValues(_vocab.DESCRIPTION), resourceTemplateValues(_vocab.TITLE), { | ||
type: resourceTemplateValues(_vocab.TYPE), | ||
conformsTo: (0, _helpers.labelId)(resourceTemplateValues(_vocab.CONFORMS_TO)), | ||
selector: resourceTemplate[_vocab.SELECTOR] ? ((resourceTemplate[_vocab.SELECTOR][_vocab.ID] ? resourceTemplate[_vocab.SELECTOR][_vocab.ID] : resourceTemplate[_vocab.SELECTOR][_vocab.ID]) || '').toLowerCase() : null, | ||
rdfsLabel: resourceTemplateValues(_vocab.RDFS_LABEL) | ||
})); | ||
// Set the capture model | ||
if (resourceTemplate[_vocab.UI_GROUP]) { | ||
var _resourceTemplateValu; | ||
dispatch((0, _resourceTemplate.addCaptureModel)(resourceTemplateValues(_vocab.ID), resourceTemplateValues(_vocab.UI_GROUP, (_resourceTemplateValu = {}, _resourceTemplateValu[_vocab.ID] = null, _resourceTemplateValu))[_vocab.ID], { | ||
combine: (0, _helpers.castBool)(resourceTemplateValues(_vocab.COMBINE, true)), | ||
externalise: (0, _helpers.castBool)(resourceTemplateValues(_vocab.EXTERNALISE, true)), | ||
humanReadable: (0, _helpers.castBool)(resourceTemplateValues(_vocab.HUMAN_READABLE, true)), | ||
serialize: (0, _helpers.castBool)(resourceTemplateValues(_vocab.SERIALIZE)), | ||
multiple: (0, _helpers.castBool)(resourceTemplateValues(_vocab.MULTIPLE)), | ||
selectorValue: resourceTemplateValues(), | ||
selector: resourceTemplateValues(_vocab.SELECTOR) ? ((resourceTemplateValues(_vocab.SELECTOR)[_vocab.ID] ? resourceTemplateValues(_vocab.SELECTOR)[_vocab.ID] : resourceTemplateValues(_vocab.SELECTOR)) || '').toLowerCase() : null, | ||
motivatedBy: motivationFromForm((0, _helpers.labelId)(resourceTemplateValues(_vocab.MOTIVATED_BY))), | ||
labelParts: (0, _helpers.labelId)(resourceTemplateValues(_vocab.LABEL_PARTS)) | ||
})); | ||
if (resourceTemplateValues(_vocab.FORM_FIELDS)) { | ||
resourceTemplateValues(_vocab.FORM_FIELDS).map(function (field) { | ||
var _resourceTemplateValu2, _fieldValues; | ||
var fieldValues = get(field); | ||
dispatch((0, _resourceTemplate.addInteractiveResource)(resourceTemplateValues(_vocab.ID), resourceTemplateValues(_vocab.UI_GROUP, (_resourceTemplateValu2 = {}, _resourceTemplateValu2[_vocab.ID] = null, _resourceTemplateValu2))[_vocab.ID], fieldValues(_vocab.ID), fieldValues(_vocab.INPUT_TYPE, (_fieldValues = {}, _fieldValues[_vocab.ID] = null, _fieldValues))[_vocab.ID], { | ||
annotationMetaData: { | ||
options: fieldValues('crowds:uiInputOptions') | ||
}, | ||
omekaMetaData: { | ||
type: fieldValues(_vocab.TYPE), | ||
bodyType: (0, _helpers.labelId)(fieldValues(_vocab.BODY_TYPE)), | ||
purpose: (0, _helpers.labelId)(fieldValues(_vocab.PURPOSE)) | ||
}, | ||
metaData: { | ||
title: fieldValues(_vocab.RDFS_LABEL) || fieldValues(_vocab.TITLE), | ||
description: fieldValues(_vocab.DESCRIPTION), | ||
conformsTo: (0, _helpers.labelId)(fieldValues(_vocab.CONFORMS_TO)), | ||
selector: fieldValues(_vocab.SELECTOR) ? fieldValues(_vocab.SELECTOR)[_vocab.ID] : null, | ||
selectorValue: parseSelectorTarget(fieldValues(_vocab.SELECTOR_VALUE)) | ||
} | ||
})); | ||
}); | ||
} | ||
if (_CaptureModel2.default.is(resourceTemplate)) { | ||
return _CaptureModel2.default.fromJsonLD(resourceTemplate); | ||
} | ||
} | ||
function parseSelectorTarget(toParse) { | ||
var scale = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 1; | ||
function importResourceTemplate(resourceTemplate) { | ||
var target = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'canvas'; | ||
if (!toParse) { | ||
return toParse; | ||
} | ||
var W3C_SELECTOR = /[#&?](xywh=)?(pixel:|percent:)?([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?),([0-9]+(\.[0-9]+)?)/; | ||
var match = W3C_SELECTOR.exec(toParse); | ||
return function (dispatch) { | ||
var tree = constructUnknownTemplate(resourceTemplate); | ||
if (match) { | ||
return { | ||
unit: match[2] === 'percent:' ? 'percent' : 'pixel', | ||
scale: scale, | ||
expanded: true, | ||
x: parseFloat(match[3]) * scale, | ||
y: parseFloat(match[5]) * scale, | ||
width: parseFloat(match[7]) * scale, | ||
height: parseFloat(match[9]) * scale, | ||
toString: function toString() { | ||
// @todo maybe something else? | ||
return toParse.split('#')[0]; | ||
} | ||
}; | ||
} | ||
return toParse; | ||
} | ||
if (!tree) { | ||
return; | ||
} | ||
if (tree instanceof _CaptureModel2.default) { | ||
return dispatch((0, _resources.importResource)(tree)); | ||
} | ||
function omekaCreateStore(createStore, reducers, resourceTemplate) { | ||
var middleware = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : []; | ||
dispatch((0, _resources.importResourceTree)(tree.getTree(target))); | ||
// Create store. | ||
var store = createStore(reducers, middleware); | ||
// Import all resource templates provided. | ||
resourceTemplate.map(function (singleTemplate) { | ||
return omekaImportResourceTemplate(store.dispatch, singleTemplate); | ||
}); | ||
// return store. | ||
return store; | ||
tree.flatten().forEach(function (r) { | ||
return dispatch((0, _resources.importResource)(r)); | ||
}); | ||
}; | ||
} | ||
@@ -312,0 +217,0 @@ |
@@ -36,4 +36,6 @@ 'use strict'; | ||
var INPUT_TYPE = exports.INPUT_TYPE = 'crowds:uiInputType'; | ||
var INPUT_OPTIONS = exports.INPUT_OPTIONS = 'crowds:uiInputOptions'; | ||
var INPUT_AUTOCOMPLETE_URI = exports.INPUT_AUTOCOMPLETE_URI = 'crowds:uiInputAutocomplete'; | ||
var BOX_SELECTOR = exports.BOX_SELECTOR = 'madoc:boxdraw'; | ||
var WHOLE_CANVAS_SELECTOR = exports.WHOLE_CANVAS_SELECTOR = 'WholeCanvasSelector'; // @todo change to madoc: ns |
{ | ||
"name": "digirati-annotation-bridge", | ||
"version": "0.5.1", | ||
"version": "0.6.0", | ||
"description": "Describe annotation-bridge here", | ||
@@ -22,3 +22,4 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"digirati-annotation-redux": "^0.5.1" | ||
"digirati-annotation-redux": "^0.6.0", | ||
"lodash.flatten": "^4.4.0" | ||
}, | ||
@@ -25,0 +26,0 @@ "devDependencies": { |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
56852
20
1392
2
+ Addedlodash.flatten@^4.4.0
+ Addeddigirati-annotation-redux@0.6.1(transitive)
+ Addedlodash.flatten@4.4.0(transitive)
- Removeddigirati-annotation-redux@0.5.1(transitive)