-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathtest-matrix.js
More file actions
188 lines (156 loc) · 5.51 KB
/
test-matrix.js
File metadata and controls
188 lines (156 loc) · 5.51 KB
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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
if (!window.UI) {
window.alert('Please run "npm install && npm run build" in your repo root first.')
}
window.$rdf = UI.rdf
document.addEventListener('DOMContentLoaded', function () {
/// ///////////////////////////////////////////
const kb = UI.store
const dom = document
const ICAL = $rdf.Namespace('http://www.w3.org/2002/12/cal/ical#')
const SCHED = $rdf.Namespace('http://www.w3.org/ns/pim/schedule#')
const DC = $rdf.Namespace('http://purl.org/dc/elements/1.1/')
const uri = window.location.href
const base = (window.document.title = uri.slice(0, uri.lastIndexOf('/') + 1))
const testDocURI = base + 'test.ttl' // imaginary doc - just use its URL
const testDoc = $rdf.sym(testDocURI)
const subjectURI = testDocURI + '#event1'
const meURI = testDocURI + '#a0'
const me = kb.sym(meURI)
// var forms_uri = window.document.title = base+ 'forms.ttl';
const subject = kb.sym(subjectURI)
const div = dom.getElementById('UITestArea')
const showResults = function () {
// Now the form for responsing to the poll
//
// div.appendChild(dom.createElement('hr'))
const invitation = subject
const query = new $rdf.Query('Responses')
const v = {}
;['time', 'author', 'value', 'resp', 'cell'].map(function (x) {
query.vars.push((v[x] = $rdf.variable(x)))
})
query.pat.add(invitation, SCHED('response'), v.resp)
query.pat.add(v.resp, DC('author'), v.author)
query.pat.add(v.resp, SCHED('cell'), v.cell)
query.pat.add(v.cell, SCHED('availabilty'), v.value)
query.pat.add(v.cell, ICAL('dtstart'), v.time)
/*
var prologue = " @prefix foaf: <http://xmlns.com/foaf/0.1/>.\n\
@prefix sched: <http://www.w3.org/ns/pim/schedule#>.\n\
@prefix ical: <http://www.w3.org/2002/12/cal/icaltzd#>.\n\
@prefix dc: <http://purl.org/dc/elements/1.1/>.\n";
*/
const prologue = dom.getElementById('Prologue').textContent
// var config = dom.getElementById('Config').textContent;
// $rdf.parse(prologue + config, kb, testDocURI, 'text/turtle') // str, kb, base, contentType
const tests = dom.getElementById('TestData').children
const inputText = function (tr) {
return tr.children[0].children[0].textContent
}
const output = function (tr) {
return tr.children[1]
}
let t = 0
$rdf.parse(prologue + inputText(tests[t]), kb, testDocURI, 'text/turtle') // str, kb, base, contentType
const options = {}
const setAxes = function () {
options.set_x = kb.each(subject, SCHED('option')) // @@@@@ option -> dtstart in future
options.set_x = options.set_x.map(function (opt) {
return kb.any(opt, ICAL('dtstart'))
})
options.set_y = kb.each(subject, SCHED('response'))
options.set_y = options.set_y.map(function (resp) {
return kb.any(resp, DC('author'))
})
}
setAxes()
// var possibleTimes = kb.each(invitation, SCHED('option'))
// .map(function (opt) { return kb.any(opt, ICAL('dtstart')) })
const displayTheMatrix = function () {
const matrix = div.appendChild(
UI.matrix.matrixForQuery(
dom,
query,
v.time,
v.author,
v.value,
options,
function () {}
)
)
matrix.setAttribute('class', 'matrix')
const refreshButton = dom.createElement('button')
refreshButton.textContent = 'refresh'
refreshButton.addEventListener(
'click',
function (_event) {
matrix.refresh()
},
false
)
return matrix
}
// @@ Give other combos too-- see schedule ontology
const possibleAvailabilities = [SCHED('No'), SCHED('Maybe'), SCHED('Yes')]
const dataPointForNT = []
// var doc = testDoc
options.set_y = options.set_y.filter(function (z) {
return !z.sameTerm(me)
})
options.set_y.push(me) // Put me on the end
options.cellFunction = function (cell, x, y, value) {
const refreshColor = function () {
const bg = kb.any(value, UI.ns.ui('backgroundColor'))
if (bg) {
cell.setAttribute(
'style',
'text-align: center; background-color: ' + bg + ';'
)
}
}
if (value !== null) {
refreshColor()
}
if (y.sameTerm(me)) {
const callback = function () {
refreshColor()
} // @@ may need that
const selectOptions = {}
const predicate = SCHED('availabilty')
const cellSubject = dataPointForNT[x.toNT()]
const selector = UI.widgets.makeSelectForOptions(
dom,
kb,
cellSubject,
predicate,
possibleAvailabilities,
selectOptions,
testDoc,
callback
)
cell.appendChild(selector)
} else if (value !== null) {
cell.textContent = UI.utils.label(value)
}
}
const matrix = displayTheMatrix()
const agenda = []
const nextTest = function nextTest () {
// First take a copy of the DOM the klast test produced
output(tests[t]).appendChild(matrix.cloneNode(true))
t += 1
const test = tests[t]
if (!test) return
kb.removeMany(undefined, undefined, undefined, testDoc) // Flush out previous test data
$rdf.parse(prologue + inputText(tests[t]), kb, testDocURI, 'text/turtle')
setAxes()
matrix.refresh()
setTimeout(nextTest, 2000)
}
agenda.push(nextTest)
setTimeout(function () {
agenda.shift()()
}, 2000)
} // showResults
showResults()
})