forked from SolidOS/solid-ui
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest.html
More file actions
237 lines (206 loc) Β· 7.13 KB
/
test.html
File metadata and controls
237 lines (206 loc) Β· 7.13 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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Solid-UI Test - Load and Display RDF Data</title>
<style>
body {
font-family: Arial, sans-serif;
max-width: 800px;
margin: 50px auto;
padding: 20px;
background-color: #f5f5f5;
}
h1 {
color: #333;
}
#app {
background: white;
padding: 20px;
border-radius: 8px;
box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}
.button-container {
margin: 20px 0;
}
button {
background-color: #7c4dff;
color: white;
border: none;
padding: 12px 24px;
font-size: 16px;
border-radius: 4px;
cursor: pointer;
margin-right: 10px;
}
button:hover {
background-color: #6a3de8;
}
button:disabled {
background-color: #ccc;
cursor: not-allowed;
}
#output {
margin-top: 20px;
padding: 15px;
background-color: #f9f9f9;
border: 1px solid #ddd;
border-radius: 4px;
min-height: 100px;
white-space: pre-wrap;
font-family: monospace;
font-size: 14px;
}
.loading {
color: #666;
font-style: italic;
}
.error {
color: #d32f2f;
font-weight: bold;
}
.success {
color: #388e3c;
}
.data-item {
margin: 10px 0;
padding: 10px;
background: white;
border-left: 3px solid #7c4dff;
}
</style>
</head>
<body>
<div id="app">
<h1>π― Solid-UI Test Page</h1>
<p>This page demonstrates loading RDF data into an RDF store and displaying it using solid-ui widgets.</p>
<div class="button-container">
<button id="loadDataBtn">Load RDF Data</button>
<button id="displayDataBtn" disabled>Display Data</button>
<button id="clearBtn">Clear Output</button>
</div>
<div id="output">Click "Load RDF Data" to begin...</div>
</div>
<!-- Load dependencies -->
<script src="https://cdn.jsdelivr.net/npm/rdflib/dist/rdflib.min.js"></script>
<script src="./solid-logic.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/solid-ui/dist/solid-ui.min.js"></script>
<script>
// Access global variables
const $rdf = window.$rdf
const SolidLogic = window.SolidLogic
const UI = window.UI
// Use SolidLogic's global store (no need to create a new one)
const store = SolidLogic.store
// Sample RDF data in Turtle format
const turtleData = `
@prefix foaf: <http://xmlns.com/foaf/0.1/> .
@prefix ex: <http://example.org/> .
ex:alice a foaf:Person ;
foaf:name "Alice Smith" ;
foaf:mbox <mailto:alice@example.org> ;
foaf:knows ex:bob .
ex:bob a foaf:Person ;
foaf:name "Bob Johnson" ;
foaf:mbox <mailto:bob@example.org> ;
foaf:knows ex:alice, ex:carol .
ex:carol a foaf:Person ;
foaf:name "Carol Williams" ;
foaf:mbox <mailto:carol@example.org> .
`
// Get DOM elements
const loadDataBtn = document.getElementById('loadDataBtn')
const displayDataBtn = document.getElementById('displayDataBtn')
const clearBtn = document.getElementById('clearBtn')
const output = document.getElementById('output')
let dataLoaded = false
// Load RDF data into store
loadDataBtn.addEventListener('click', async () => {
output.innerHTML = '<span class="loading">Loading RDF data...</span>'
loadDataBtn.disabled = true
try {
// Parse Turtle data into the store
const baseURI = 'http://example.org/'
$rdf.parse(turtleData, store, baseURI, 'text/turtle')
output.innerHTML = '<span class="success">β RDF data loaded successfully!</span>\n\n'
output.innerHTML += `Store now contains ${store.statements.length} triples.\n\n`
output.innerHTML += 'Click "Display Data" to see the parsed information.'
dataLoaded = true
displayDataBtn.disabled = false
loadDataBtn.textContent = 'Reload Data'
} catch (error) {
output.innerHTML = `<span class="error">β Error loading data: ${error.message}</span>`
console.error('Error:', error)
} finally {
loadDataBtn.disabled = false
}
})
// Display the loaded data
displayDataBtn.addEventListener('click', () => {
if (!dataLoaded) {
output.innerHTML = '<span class="error">Please load data first!</span>'
return
}
output.innerHTML = '<h3>π Loaded RDF Data:</h3>\n\n'
// Query for all people
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/')
const EX = $rdf.Namespace('http://example.org/')
// Find all persons
const people = store.each(null, $rdf.sym('http://www.w3.org/1999/02/22-rdf-syntax-ns#type'), FOAF('Person'))
if (people.length === 0) {
output.innerHTML += '<span class="error">No people found in the data.</span>'
return
}
output.innerHTML += `Found ${people.length} person(s):\n\n`
people.forEach((person, index) => {
const name = store.any(person, FOAF('name'))
const email = store.any(person, FOAF('mbox'))
const knows = store.each(person, FOAF('knows'))
const personDiv = document.createElement('div')
personDiv.className = 'data-item'
let personInfo = `<strong>Person ${index + 1}:</strong> ${person.value}\n`
if (name) personInfo += ` Name: ${name.value}\n`
if (email) personInfo += ` Email: ${email.value}\n`
if (knows.length > 0) {
personInfo += ` Knows: ${knows.length} person(s)\n`
knows.forEach(friend => {
const friendName = store.any(friend, FOAF('name'))
personInfo += ` - ${friendName ? friendName.value : friend.value}\n`
})
}
personDiv.innerHTML = `<pre>${personInfo}</pre>`
output.appendChild(personDiv)
})
// Add a button using solid-ui widgets
output.innerHTML += '\n<h3>π¨ Solid-UI Widget Demo:</h3>\n'
const buttonContainer = document.createElement('div')
buttonContainer.style.margin = '10px 0'
const solidButton = UI.widgets.button(
document,
'https://solidproject.org/assets/img/solid-emblem.svg',
'View All Triples',
() => {
alert(`Store contains ${store.statements.length} triples:\n\n` +
store.statements.slice(0, 5).map(st =>
`${st.subject.value} β ${st.predicate.value} β ${st.object.value}`
).join('\n') +
(store.statements.length > 5 ? '\n...' : ''))
}
)
buttonContainer.appendChild(solidButton)
output.appendChild(buttonContainer)
})
// Clear output
clearBtn.addEventListener('click', () => {
output.innerHTML = 'Output cleared. Click "Load RDF Data" to begin...'
displayDataBtn.disabled = !dataLoaded
})
// Log success message
console.log('β All dependencies loaded successfully!')
console.log('- $rdf (rdflib):', typeof $rdf)
console.log('- SolidLogic:', typeof SolidLogic)
console.log('- UI (solid-ui):', typeof UI)
</script>
</body>
</html>