-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrdf-cobweb-skos.js
155 lines (130 loc) · 5.74 KB
/
rdf-cobweb-skos.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
var COBWEB_SKOS = function () {
"use strict";
var loadCollection = function (control_object, collection, settings, previous) {
var object = previous;
if( !object ) {
console.log('Creating SKOS history');
object = {
current : null,
stack : [],
getCollection : function () {
return current.collection;
}
};
}
if(object.current) {
console.log('Stacking SKOS history');
object.stack.push(object.current);
}
var skos_content = control_object;
var handleCollection = function(graph, data) {
var content = Util.getElement('div');
object.current = {};
object.current.url = graph;
object.current.label = Util.getLabel(COBWEB.store, graph);
object.current.narrower = [];
object.current.content = content;
object.current.collection = {};
var narrower = Util.getNarrower(graph);
var title = Util.getElement('span', 'skos-title');
title.html('Collection: ' + object.current.label);
var narrowerBits = Util.getElement('div', 'narrower-group');
var collectionBits = Util.getElement('ul', 'collection-bits');
// Load narrower type.
for(var narr = 0; narr < narrower.length; narr++) {
(function() {
var narrow = narrower[narr];
var element = Util.getElement('div', 'narrower');
element.html(narrow);
element.click(function() {
console.log('Narrowing down collection', narrow);
loadCollection(skos_content, narrow, settings, object);
});
var updateLabel = function(graph, data) {
var label = Util.getLabel(COBWEB.store, narrow);
element.html(label);
};
COBWEB.getTurtle(narrow, updateLabel);
narrowerBits.append(element);
})();
}
var refine = Util.getElement('button');
var hideRefine = function() {
refine.html("Refine");
narrowerBits.hide();
refine.click(showRefine);
};
var showRefine = function() {
refine.html("Hide");
narrowerBits.show();
refine.click(hideRefine);
};
hideRefine();
narrowerBits.hide();
// Load labels of actual values. - identified by
if(settings) {
var collection = Util.getCollection(graph, settings);
for(var j = 0; j< collection.length; j++) {
(function() {
var item = {};
var display = Util.getElement('li','item');
item.url = collection[j];
item.type = settings.range;
object.current.collection[item.url] = item;
var updateLabel = function() {
var isType = Util.isType(item.url, item.type);
if( !isType ) {
console.log('Removing item from list', item.url);
delete object.current.collection[item.url];
display.remove();
return;
}
item.label = Util.getLabel(COBWEB.store, item.url);
display.html(item.label);
};
var label = Util.getLabel(COBWEB.store, item.url);
if( label === item.url ) {
COBWEB.getTurtle(item.url, updateLabel);
display.html(item.url);
} else {
item.label = label;
display.html(item.label);
}
collectionBits.append(display);
})();
}
}
content.append(title);
console.log('Evaluating history', object.stack);
if( object.stack.length > 0 ) {
console.log('Creating SKOS back button')
var control = Util.getElement('button');
control.html('Back Up Category');
control.click(function() {
var previous = object.stack.pop();
control.attr('enabled', false);
control.html('Loading');
console.log('Reverting SKOS', previous);
object.current = null;
loadCollection(skos_content, previous.url, settings, object);
//object.current = previous;
//skos_content.html(previous.content);
});
title.append( control );
}
if(narrower.length > 0) {
title.append(refine);
content.append(narrowerBits);
}
content.append(collectionBits);
skos_content.html(content);
};
COBWEB.getTurtle(collection, handleCollection);
return object;
};
return {
loadCollection : function(control_object, collection, settings) {
return loadCollection(control_object, collection, settings);
}
};
}();