Skip to content

Commit

Permalink
Fix resource indexing bug
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnkoolen committed Feb 18, 2019
1 parent b97b320 commit eaf7c08
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/components/annotation/Annotation.jsx
Expand Up @@ -233,7 +233,7 @@ class Annotation extends React.Component {
}
} catch (error) {
// filter out annotation targets that result in errors;
console.log("ERROR in annotation target:", target)
//console.log("ERROR in annotation target:", target)
return undefined;
}
}).filter((target) => { return target !== undefined });
Expand Down
9 changes: 5 additions & 4 deletions src/components/resource/ResourceList.jsx
Expand Up @@ -2,7 +2,7 @@

import React from 'react';
import AppAnnotationStore from './../../flux/AnnotationStore';
import AnnotationActions from './../../flux/AnnotationActions';
import AnnotationStore from './../../flux/AnnotationStore';
import Resource from './Resource.jsx';

class ResourceList extends React.Component {
Expand All @@ -16,8 +16,9 @@ class ResourceList extends React.Component {
}

render() {
let resourceItems = Object.keys(AnnotationActions.resourceIndex).map((resourceId) => {
let resource = AnnotationActions.resourceIndex[resourceId];
//console.log(AnnotationStore.resourceIndex);
let resourceItems = Object.keys(AnnotationStore.resourceIndex).map((resourceId) => {
let resource = AnnotationStore.resourceIndex[resourceId];
return (
<Resource
data={resource}
Expand All @@ -29,7 +30,7 @@ class ResourceList extends React.Component {
return (
<div className="resourceList">
<h3>Annotatable Resources</h3>
<ul className="list-group">
<ul className="list-group annotation-list-scroll">
{resourceItems}
</ul>
</div>
Expand Down
33 changes: 28 additions & 5 deletions src/flux/AnnotationActions.js
Expand Up @@ -74,6 +74,9 @@ const AnnotationActions = {

lookupIdentifier(sourceId) {
var source = { type: null, data: null }; // for IDs to external resources
//console.log(AnnotationStore.annotationIndex);
//console.log(AnnotationStore.resourceIndex);
//console.log(AnnotationStore.externalResourceIndex);
if (AnnotationStore.annotationIndex.hasOwnProperty(sourceId))
source = { type: "annotation", data: AnnotationStore.annotationIndex[sourceId] };
else if (AnnotationStore.resourceIndex.hasOwnProperty(sourceId))
Expand Down Expand Up @@ -159,14 +162,17 @@ const AnnotationActions = {
},

loadAnnotations: (resourceIds) => {
//console.log("loadAnnotations - resourceIds:", resourceIds);
if (resourceIds === undefined)
resourceIds = AnnotationStore.topResources;
//console.log("loadAnnotations - AnnotationStore.resourceIds:", AnnotationStore.resourceIds);
let externalResources = AnnotationActions.getExternalResources(resourceIds);
//console.log("loadAnnotations - externalResources:", externalResources);
let externalIds = externalResources.map((res) => { return res.parentResource }).filter((externalId) => { return typeof externalId === "string"});

console.log("loadAnnotations - top externalIds:", externalIds);
//console.log("loadAnnotations - top externalIds:", externalIds);
resourceIds = resourceIds.concat(externalIds);
console.log("loadAnnotations - top RDFa resourceIds:", resourceIds);
//console.log("loadAnnotations - top RDFa resourceIds:", resourceIds);
AnnotationAPI.getAnnotationsByTargets(resourceIds, AnnotationActions.accessStatus, (error, annotations) => {
if (error) {
//console.error(resourceIds, error.toString());
Expand Down Expand Up @@ -217,9 +223,17 @@ const AnnotationActions = {

indexResources: (callback) => {
RDFaUtil.indexRDFa((error, index) => {
AnnotationStore.resourceIndex = index.resources;
AnnotationStore.relationIndex = index.relations;
return callback(error);
if (error) {
console.log("Error indexing resources");
console.log(error);
return callback(error);
} else {
//console.log("indexResources - index:", index);
AnnotationStore.resourceIndex = index.resources;
//console.log("indexResources - AnnotationStore.resourceIndex:", AnnotationStore.resourceIndex);
AnnotationStore.relationIndex = index.relations;
return callback(error);
}
}); // ... refresh index
},

Expand All @@ -230,6 +244,7 @@ const AnnotationActions = {
return callback(error);
} else if (store === null) {
// no vocabularies, skip reading external resources
//console.log("indexExternalResources - returning with undefined vocabularyStore");
return callback(null, false, null);
}
AnnotationStore.vocabularyStore = store;
Expand All @@ -239,8 +254,11 @@ const AnnotationActions = {
//console.log("AnnotationActions - vocabularyStore:", store);
FRBRooUtil.loadExternalResources(AnnotationStore.vocabularyStore, (error, doIndexing, store) => {
if (error) {
console.log("Error loading external resources using vocabularyStore");
console.log(error);
return callback(error);
} else if (!doIndexing) {
return callback(null);
} else {
AnnotationStore.resourceStore = store;
//console.log("AnnotationActions - resourceStore:", store);
Expand Down Expand Up @@ -310,14 +328,19 @@ const AnnotationActions = {

loadResources: () => {
AnnotationStore.topResources = RDFaUtil.getTopRDFaResources();
//console.log("loadResources - topResources:", AnnotationStore.topResources);
AnnotationActions.indexResources((error) => {
if (error) {
//console.error(error);
window.alert("Error indexing RDFa resources in this page\n" + error.toString());
return error;
}
//console.log("loadResources - indexResources done");
//console.log("loadResources - AnnotationStore.resourceIndex:", AnnotationStore.resourceIndex);
AnnotationStore.resourceMaps = RDFaUtil.buildResourcesMaps(); // .. rebuild maps
//console.log("loadResources - resourceMaps:", AnnotationStore.resourceMaps);
let resources = Object.keys(AnnotationStore.resourceIndex);
//console.log("loadResources - resources:", resources);
AnnotationActions.indexExternalResources(resources, (error) => {
if (error) {
console.log("error indexing external resources");
Expand Down
2 changes: 1 addition & 1 deletion src/util/TargetUtil.js
Expand Up @@ -457,7 +457,7 @@ const TargetUtil = {
if(Array.isArray(selector)) {
return selector.some((s) => { return s.type === "TextQuoteSelector"});
} else if (selector.hasOwnProperty("type")) {
console.log("selector:", selector);
//console.log("selector:", selector);
throw Error("Invalid selector:");
} else {
return selector.type === "TextQuoteSelector";
Expand Down

0 comments on commit eaf7c08

Please sign in to comment.