-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
283 lines (235 loc) · 7.79 KB
/
index.html
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
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Solid Profile</title>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bulma/0.7.1/css/bulma.min.css">
</head>
<body>
<nav class="navbar" role="navigation" aria-label="main navigation">
<div class="navbar-brand">
<a class="navbar-item" href="https://solid.mit.edu/">
Solid
</a>
<a role="button" class="navbar-burger burger" aria-label="menu" aria-expanded="false" data-target="navbarBasicExample">
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
<span aria-hidden="true"></span>
</a>
</div>
<div id="navbarBasicExample" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item">
Home
</a>
<a class="navbar-item">
Documentation
</a>
<div class="navbar-item has-dropdown is-hoverable">
<a class="navbar-link">
More
</a>
<div class="navbar-dropdown">
<a class="navbar-item">
About
</a>
<a class="navbar-item">
Contact
</a>
<hr class="navbar-divider">
<a class="navbar-item">
<a target="_blank" href="https://github.com/melvincarvalho/solid-profile/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc">Report an issue</a>
</a>
</div>
</div>
</div>
<div class="navbar-end">
<div class="navbar-item">
<div class="buttons">
<a id="register" href="https://solid.inrupt.com/get-a-solid-pod" target="_blank" class="button is-primary">
<strong>Sign up</strong>
</a>
<a id="login" class="button is-light">
Login
</a>
<a id="logout" class="button is-light" style="display:none">
Logout
</a>
</div>
</div>
</div>
</div>
</nav>
<section class="section">
<div class="container">
<h1 class="title">
Solid Profile
</h1>
<section id="app" style="display:none">
<div class="columns">
<div class="column">
<div class="card">
<div class="card-image">
<figure class="image is-4by3">
<img id="img" class="image is-128x128" src="https://melvincarvalho.github.io/solid-profile/images/profile.png" alt="Placeholder image">
</figure>
</div>
<div class="card-content">
<div class="media">
<div class="media-left">
<figure class="image is-48x48">
<img id="img" src="https://melvincarvalho.github.io/solid-profile/images/profile.png" alt="Placeholder image">
</figure>
</div>
<div class="media-content">
<p id="name" class="title is-4"></p>
<p class="subtitle is-6">@nick</p>
</div>
</div>
<div class="content">
<a id="user" target="_blank" href="#">
<a></a>
<br>
<time datetime="2018-10-10">11:09 PM - 1 Jan 2016</time>
</div>
</div>
</div>
</div>
<div class="column">
</div>
<div class="column">
</div>
<div class="column">
</div>
</div>
<div id="name"></div>
<div><img id="img" /></div>
</section>
</div>
</section>
<script src="https://melvincarvalho.github.io/helloworld/scripts/jquery.js"></script>
<script src="https://melvincarvalho.github.io/helloworld/scripts/solid-auth-client.bundle.js"></script>
<script src="https://melvincarvalho.github.io/helloworld/scripts/rdflib.min.js"></script>
<script>
// INIT
//
var template = {}
template.webId = null
template.loggedIn = false
function init () {
addListeners();
hamburgerHelper();
var webId = getQueryStringParam('webid')
if (webId) {
template.webId = webId
fetchProfile(webId)
}
}
// RENDER
//
function renderProfile(webId) {
let app = document.getElementById("app");
let user = document.getElementById("user");
app.style.display = "";
user.style.display = "";
user.textContent = webId;
user.setAttribute("href", webId);
}
function renderLogin(webId) {
let logout = document.getElementById("logout");
let login = document.getElementById("login");
let register = document.getElementById("register");
logout.style = '';
register.style.display = "none";
login.style.display = "none";
}
function renderLogout() {
let logout = document.getElementById("logout");
let login = document.getElementById("login");
let register = document.getElementById("register");
let app = document.getElementById("app");
logout.style.display = "none";
app.style.display = "none";
login.style.display = "";
register.style.display = "";
}
// HANDLERS
//
function addListeners() {
let login = document.getElementById("login");
let logout = document.getElementById("logout");
// login and logout buttons
const popupUri = "https://melvincarvalho.github.io/helloworld/popup.html";
login.addEventListener("click", () => solid.auth.popupLogin({
popupUri
}));
logout.addEventListener("click", () => solid.auth.logout());
handleLogin();
}
function handleLogin() {
// login event
solid.auth.trackSession(session => {
if (session && session.webId) {
template.loggedIn = true
renderLogin();
} else {
template.loggedIn = false
renderLogout();
}
if (template && template.webId) {
fetchProfile(template.webId);
} else if (session && session.webId) {
fetchProfile(session.webId);
}
});
}
// HELPERS
//
function hamburgerHelper() {
document.querySelector(".navbar-burger").addEventListener("click", toggleNav);
function toggleNav() {
var nav = document.querySelector(".navbar-menu");
if (nav.className == "navbar-menu") {
nav.className = "navbar-menu is-active";
} else {
nav.className = "navbar-menu";
}
}
}
function getQueryStringParam(param) {
var url = window.location.toString();
url.match(/\?(.+)$/);
var params = RegExp.$1;
params = params.split("&");
var queryStringList = {};
for (var i = 0; i < params.length; i++) {
var tmp = params[i].split("=");
queryStringList[tmp[0]] = unescape(tmp[1]);
}
return queryStringList[param];
}
// FETCH
async function fetchProfile(webId) {
const FOAF = $rdf.Namespace('http://xmlns.com/foaf/0.1/'); // Set up a local data store and associated data fetcher
const store = $rdf.graph();
const fetcher = new $rdf.Fetcher(store);
// Load the person's data into the store
await fetcher.load(webId);
// Display their details
const name = store.any($rdf.sym(webId), FOAF('name'));
const img = store.any($rdf.sym(webId), FOAF('img'));
console.log(img)
if (name && name.value) {
document.getElementById("name").textContent = name.value;
}
if (img && img.value) {
document.getElementById("img").setAttribute("src", img.value);
}
renderProfile(webId)
}
// MAIN
init()
</script>
</body>
</html>