digirati-annotation-bridge
Advanced tools
Comparing version
@@ -20,4 +20,4 @@ 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; }; | ||
var boxSelector = parseTarget(target, scale); | ||
if (typeof boxSelector.target === 'string') { | ||
return { type: WHOLE_CANVAS_SELECTOR }; | ||
if (!boxSelector || typeof boxSelector.target === 'string') { | ||
return { type: WHOLE_CANVAS_SELECTOR, target: boxSelector && boxSelector.target || '' }; | ||
} | ||
@@ -24,0 +24,0 @@ boxSelector.type = BOX_SELECTOR; |
@@ -11,2 +11,6 @@ import { ID, OMEKA_LABEL } from './vocab'; | ||
export function labelId(res) { | ||
if (Object.prototype.toString.call(res) === '[object Array]') { | ||
return res.map(labelId); | ||
} | ||
return { | ||
@@ -13,0 +17,0 @@ id: res[ID], |
@@ -6,3 +6,3 @@ import { addCaptureModel, addInteractiveResource, addResourceTemplate } from 'digirati-annotation-redux/es/actions/resourceTemplate'; | ||
import { BODY_TYPE, COMBINE, CONFORMS_TO, DESCRIPTION, EXTERNALISE, FORM_FIELDS, HAS_PART, HUMAN_READABLE, ID, INPUT_TYPE, MOTIVATED_BY, MULTIPLE, PURPOSE, RDFS_LABEL, SELECTOR, SERIALIZE, TITLE, TYPE, UI_CHOICE, UI_GROUP } from './vocab'; | ||
import { BODY_TYPE, COMBINE, CONFORMS_TO, DESCRIPTION, EXTERNALISE, FORM_FIELDS, HAS_PART, HUMAN_READABLE, ID, INPUT_TYPE, MOTIVATED_BY, MULTIPLE, PURPOSE, RDFS_LABEL, SELECTOR, SERIALIZE, TITLE, TYPE, UI_CHOICE, UI_GROUP, LABEL_PARTS } from './vocab'; | ||
@@ -54,8 +54,20 @@ import { castBool, labelId } from './helpers'; | ||
export function dataSetToAnnotation(body) { | ||
return { | ||
'type': ['TextualBody', 'Dataset'], | ||
'value': JSON.stringify(body), | ||
'format': 'text/plain' | ||
function getLabelFromResourceTemplate(template, data) { | ||
if (!(template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].labelParts && template.captureModels['madoc:form'].labelParts.label)) { | ||
return null; | ||
} | ||
var labelField = template.captureModels['madoc:form'].labelParts.label; | ||
return data[labelField] ? data[labelField] : null; | ||
} | ||
export function dataSetToAnnotation(template, dataset) { | ||
var body = { | ||
type: ['TextualBody', 'Dataset'], | ||
value: JSON.stringify(dataset), | ||
format: 'text/plain' | ||
}; | ||
var label = getLabelFromResourceTemplate(template, dataset); | ||
return { body: body, label: label }; | ||
} | ||
@@ -68,3 +80,3 @@ | ||
return dataSetToAnnotation(mapDraftToDataSet(captureModels, currentDraft.input)); | ||
return dataSetToAnnotation(resourceTemplate, mapDraftToDataSet(captureModels, currentDraft.input)); | ||
} | ||
@@ -114,3 +126,4 @@ | ||
selector: resourceTemplate[SELECTOR] ? resourceTemplate[SELECTOR][ID] : null, | ||
motivatedBy: motivationFromForm(labelId(resourceTemplate[MOTIVATED_BY])) | ||
motivatedBy: motivationFromForm(labelId(resourceTemplate[MOTIVATED_BY])), | ||
labelParts: labelId(resourceTemplate[LABEL_PARTS]) | ||
})); | ||
@@ -117,0 +130,0 @@ |
@@ -17,2 +17,3 @@ // DUBLIN CORE CONSTANTS | ||
export var COMBINE = 'crowds:derivedAnnoCombine'; | ||
export var LABEL_PARTS = 'crowds:derivedAnnoBodyLabelParts'; | ||
export var UI_GROUP = 'crowds:uiGroup'; | ||
@@ -19,0 +20,0 @@ export var EXTERNALISE = 'crowds:derivedAnnoExternalize'; |
@@ -43,4 +43,4 @@ 'use strict'; | ||
var boxSelector = parseTarget(target, scale); | ||
if (typeof boxSelector.target === 'string') { | ||
return { type: _vocab.WHOLE_CANVAS_SELECTOR }; | ||
if (!boxSelector || typeof boxSelector.target === 'string') { | ||
return { type: _vocab.WHOLE_CANVAS_SELECTOR, target: boxSelector && boxSelector.target || '' }; | ||
} | ||
@@ -47,0 +47,0 @@ boxSelector.type = _vocab.BOX_SELECTOR; |
@@ -18,2 +18,6 @@ 'use strict'; | ||
function labelId(res) { | ||
if (Object.prototype.toString.call(res) === '[object Array]') { | ||
return res.map(labelId); | ||
} | ||
return { | ||
@@ -20,0 +24,0 @@ id: res[_vocab.ID], |
@@ -69,8 +69,20 @@ 'use strict'; | ||
function dataSetToAnnotation(body) { | ||
return { | ||
'type': ['TextualBody', 'Dataset'], | ||
'value': JSON.stringify(body), | ||
'format': 'text/plain' | ||
function getLabelFromResourceTemplate(template, data) { | ||
if (!(template && template.captureModels && template.captureModels['madoc:form'] && template.captureModels['madoc:form'].labelParts && template.captureModels['madoc:form'].labelParts.label)) { | ||
return null; | ||
} | ||
var labelField = template.captureModels['madoc:form'].labelParts.label; | ||
return data[labelField] ? data[labelField] : null; | ||
} | ||
function dataSetToAnnotation(template, dataset) { | ||
var body = { | ||
type: ['TextualBody', 'Dataset'], | ||
value: JSON.stringify(dataset), | ||
format: 'text/plain' | ||
}; | ||
var label = getLabelFromResourceTemplate(template, dataset); | ||
return { body: body, label: label }; | ||
} | ||
@@ -83,3 +95,3 @@ | ||
return dataSetToAnnotation(mapDraftToDataSet(captureModels, currentDraft.input)); | ||
return dataSetToAnnotation(resourceTemplate, mapDraftToDataSet(captureModels, currentDraft.input)); | ||
} | ||
@@ -129,3 +141,4 @@ | ||
selector: resourceTemplate[_vocab.SELECTOR] ? resourceTemplate[_vocab.SELECTOR][_vocab.ID] : null, | ||
motivatedBy: motivationFromForm((0, _helpers.labelId)(resourceTemplate[_vocab.MOTIVATED_BY])) | ||
motivatedBy: motivationFromForm((0, _helpers.labelId)(resourceTemplate[_vocab.MOTIVATED_BY])), | ||
labelParts: (0, _helpers.labelId)(resourceTemplate[_vocab.LABEL_PARTS]) | ||
})); | ||
@@ -132,0 +145,0 @@ |
@@ -20,2 +20,3 @@ 'use strict'; | ||
var COMBINE = exports.COMBINE = 'crowds:derivedAnnoCombine'; | ||
var LABEL_PARTS = exports.LABEL_PARTS = 'crowds:derivedAnnoBodyLabelParts'; | ||
var UI_GROUP = exports.UI_GROUP = 'crowds:uiGroup'; | ||
@@ -22,0 +23,0 @@ var EXTERNALISE = exports.EXTERNALISE = 'crowds:derivedAnnoExternalize'; |
{ | ||
"name": "digirati-annotation-bridge", | ||
"version": "0.2.17", | ||
"version": "0.2.18", | ||
"description": "Describe annotation-bridge here", | ||
@@ -21,3 +21,3 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"digirati-annotation-redux": "^0.2.17" | ||
"digirati-annotation-redux": "^0.2.18" | ||
}, | ||
@@ -24,0 +24,0 @@ "devDependencies": { |
33168
5.38%761
3.82%