Skip to content

Commit

Permalink
Added lateststructure and helper functions to get annotation/structur…
Browse files Browse the repository at this point in the history
…e that was retrieved in the latest update round #41
  • Loading branch information
proycon committed Nov 24, 2016
1 parent 5e76dbd commit 504aec7
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions flat/style/flat.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ var selector = ""; //structural element to select when clicking/hovering: empty
var struction = {}; //structural items
var annotations = {}; //annotations per structure item
var latestannotations = {}; //latest annotations cache (annotationid -> true map), will be populated again by loadannotations()
var lateststructure = {}; //latest structure cache (structureid -> true map), will be populated again by loadstructure()
var declarations = {};
var docid = null;
var initialannotationlist = [];
Expand Down Expand Up @@ -89,6 +90,7 @@ function loadstructure(structureresponse) {
//update structure data
Object.keys(structureresponse).forEach(function(structureid){
structure[structureid] = structureresponse[structureid];
lateststructure[structureid] = true;
});
//old (deleted) structure may linger in memory but is no longer
//referenced by other structure or other updated annotations
Expand Down Expand Up @@ -135,6 +137,12 @@ function forstructure(callback) {
});
}

function forlateststructure(callback) {
Object.keys(lateststructure).forEach(function(structure_id){
callback(structure[structure_id]);
});
}

function forannotations(structure_id, callback) {
if ((structure[structure_id]) && (structure[structure_id].annotations)) {
structure[structure_id].annotations.forEach(function(annotation_id){
Expand All @@ -145,6 +153,16 @@ function forannotations(structure_id, callback) {
}
}

function forlatestannotations(structure_id, callback) {
if ((structure[structure_id]) && (structure[structure_id].annotations)) {
structure[structure_id].annotations.forEach(function(annotation_id){
if (latestannotations[annotation_id]) {
callback(annotations[annotation_id]);
}
});
}
}

function forallannotations(callback) {
Object.keys(structure).forEach(function(structure_id){
if (structure[structure_id].annotations) {
Expand All @@ -153,7 +171,18 @@ function forallannotations(callback) {
});
}
});
}

function foralllatestannotations(callback) {
Object.keys(lateststructure).forEach(function(structure_id){
if (structure[structure_id].annotations) {
structure[structure_id].annotations.forEach(function(annotation_id){
if (latestannotations[annotation_id]) {
callback(structure[structure_id],annotations[annotation_id]);
}
});
}
});
}

function rendertextclass() {
Expand Down Expand Up @@ -231,6 +260,8 @@ function shorten(s) {
function update(data, extracallback) {
//Process data response from the server, does a partial update, called through loadcontent() on initialisation
//

latststructure = {}; //reset latest structure cache (structureid -> true map), will be populated again by loadstructure()
latestannotations = {}; //reset latest annotations cache (annotationid -> true map), will be populated again by loadannotations()

if (data.error) {
Expand Down

0 comments on commit 504aec7

Please sign in to comment.