-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
569 lines (544 loc) · 22.5 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
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>Christopher Hansteen’s correspondence</title>
<script type="application/ld+json">
{
"@context": {
"rdf": "http://www.w3.org/1999/02/22-rdf-syntax-ns#",
"rdfa": "http://www.w3.org/ns/rdfa#",
"rdfs": "http://www.w3.org/2000/01/rdf-schema#",
"schema": "https://schema.org/",
"xsd": "http://www.w3.org/2001/XMLSchema#"
},
"@graph": [
{
"@id": "https://uio-library.github.io/hansteen-brev/",
"@type": "schema:Collection",
"schema:creator": {
"@type": "schema:Organization",
"name": "University of Oslo Library",
"@id": "http://www.wikidata.org/entity/Q3354774"
},
"schema:about": {
"@type": "schema:Person",
"name": "Christopher Hansteen",
"@id": "http://www.wikidata.org/entity/Q705048"
},
"schema:name": "Christopher Hansteen’s correspondence"
}
]
}
</script>
<!-- development version, includes helpful console warnings-->
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.min.js" integrity="sha256-ui3vFTgbIIvd9ePh+wF+ju05O3jympV4FyFlpNMV2cw=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/axios.min.js" integrity="sha256-mpnrJ5DpEZZkwkE1ZgkEQQJW/46CSEh/STrZKOB/qoM=" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/lodash.min.js" integrity="sha256-7/yoZS3548fXSRXqc/xYzjsmuW3sFKzuvOCHd06Pmps=" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.6.1/css/all.css" integrity="sha384-gfdkjb5BdAXd+lj+gudLWI+BXq4IuLW5IT+brZEZsLFm++aCMlF1V92rMkPaX4PP" crossorigin="anonymous">
<style type="text/css">
th button.btn {
padding: 0 !important;
}
th button.btn span {
display: inline-block;
width: 20px;
}
.error {
background: red;
color: white;
padding: 10px;
margin: 10px;
}
h1, p {
margin: 8px 20px;
}
#popup p {
margin: 8px 0;
}
#popup {
position: absolute;
top: 5px;
left: 5px;
background: white;
padding: 10px;
box-shadow: 1px 1px 2px #aaa;
width: 450px;
}
#popup h3 {
font-weight: 500;
font-size: 115%;
margin: 8px 0;
}
#popup .small {
font-size: 70%;
}
</style>
</head>
<body>
<div id="app"></div>
<script>
// Very simple in-memory cache adapter for the popups
class Http {
constructor() {
this.cache = {};
}
get(url) {
if (!this.cache[url]) {
return axios.get(url).then(resp => {
this.cache[url] = resp;
return resp;
})
}
return new Promise((resolve, reject) => {
resolve(this.cache[url]);
});
}
}
let http = new Http();
class BibsysEntity {
constructor(id) {
this.type = 'Bibsys:';
this.id = id;
this.link = 'https://tools.wmflabs.org/bsaut/show/' + id;
this.label = '';
this.description = '';
this.thumb = {};
this.coords = {};
this.dates = {};
this.links = [
// {
//link: `https://bibsys-almaprimo.hosted.exlibrisgroup.com/primo-explore/search?query=any,contains,${id}&tab=default_tab&search_scope=default_scope&vid=UIO&lang=no_NO&offset=0`,
// name: 'Oria',
//}
];
}
get() {
return http.get(`https://tools.wmflabs.org/bsaut/api.php?origin=*&id=${this.id}`)
.then(resp => {
let rec = _.get(resp.data, 'records.0')
this.label = {value: rec.label};
this.dates.birth = rec.birth;
this.dates.death = rec.death;
})
.then(_ => this.fetchPubs());
}
fetchPubs() {
return http.get(`https://tools.wmflabs.org/bsaut/api.php?origin=*&pub=${this.id}`)
.then(resp => {
this.numberOfRecords = resp.data.numberOfRecords;
return this;
})
}
}
class WikidataEntity {
constructor(id) {
this.type = 'Wikidata:';
this.id = id;
this.link = 'https://wikidata.org/wiki/' + id;
this.langChain = ['fr', 'de', 'en', 'sv', 'da', 'nn', 'nb']; // most-preferred last
this.services = [
{
prop: 'P214',
link: 'https://viaf.org/viaf/%s',
name: 'VIAF',
},
{
prop: 'P1015',
link: 'https://tools.wmflabs.org/bsaut/show/%s',
name: 'Bibsys',
},
];
this.data = {};
this.label = '';
this.description = '';
this.thumb = {};
this.coords = {};
this.dates = {};
this.links = [{
link: 'https://tools.wmflabs.org/reasonator/?lang=nb&q=' + id,
name: 'Reasonator',
}];
}
getBestValue(obj) {
let values = _.sortBy(Object.values(obj), [x => {
return this.langChain.length - this.langChain.indexOf(x.language);
}]);
if (!values.length) {
return {value: '', language: ''};
}
return values[0];
}
get() {
return http.get(`https://www.wikidata.org/wiki/Special:EntityData/${this.id}.json`)
.then(resp => {
this.data = _.get(resp.data, `entities.${this.id}`);
this.label = this.getBestValue(this.data.labels)
this.description = this.getBestValue(this.data.descriptions)
this.coords = _.get(this.data.claims, 'P625.0.mainsnak.datavalue.value') || {};
this.dates.birth = _.get(this.data.claims, 'P569.0.mainsnak.datavalue.value.time');
if (this.dates.birth) {
this.dates.birth = this.dates.birth.substring(1, 5);
}
this.dates.death = _.get(this.data.claims, 'P570.0.mainsnak.datavalue.value.time');
if (this.dates.death) {
this.dates.death = this.dates.death.substring(1, 5);
}
this.services.forEach(service => {
let aut = _.get(this.data.claims, `${service.prop}.0.mainsnak.datavalue.value`);
if (aut) {
this.links.push({
link: service.link.replace('%s', aut),
name: service.name,
});
}
});
if (this.data.sitelinks.nowiki) {
this.links.push({
link: this.data.sitelinks.nowiki.url,
name: 'Wikipedia på bokmål',
});
}
if (this.data.sitelinks.nnwiki) {
this.links.push({
link: this.data.sitelinks.nnwiki.url,
name: 'Wikipedia på nynorsk',
});
}
if (this.data.sitelinks.enwiki) {
this.links.push({
link: this.data.sitelinks.enwiki.url,
name: 'Wikipedia på engelsk',
});
}
})
.then(_ => this.fetchCommonsThumb());
}
fetchCommonsThumb() {
let title = _.get(this.data.claims, 'P18.0.mainsnak.datavalue.value');
if (!title) {
return this;
}
title = encodeURIComponent('File:' + title)
return http.get(`https://commons.wikimedia.org/w/api.php?action=query&titles=${title}&prop=imageinfo&iiurlwidth=260&iiurlheight=400&iiprop=url|size&format=json&origin=*`)
.then(resp => {
resp = Object.values(resp.data.query.pages)[0];
if (resp.imageinfo) {
this.thumb = _.get(resp, 'imageinfo.0');
}
return this;
});
}
}
var app = new Vue({
el: '#app',
template: `
<div>
<h1>Christopher Hansteen’s correspondence : overview</h1>
<p>
The table below provides an overview of the letters
from Christopher Hansteen's correspondence
that have been digitized and described,
using data from the <a href="https://github.com/uio-library/hansteen-brev">Git repo</a>.
The letters are also available in <a href="https://bibsys-almaprimo.hosted.exlibrisgroup.com/primo-explore/collectionDiscovery?vid=UIO&lang=en_US">Oria Digital Collections</a>.
See <a href="https://github.com/uio-library/hansteen-brev#christopher-hansteens-correspondence">the README</a>
for more info about the collection.
</p>
<p>
Note that not all records have been quality controlled.
Please report metadata errors in our
<a href="https://github.com/uio-library/hansteen-brev/issues">issue tracker</a>
or by e-mail to <a href="mailto:[email protected]">[email protected]</a>.
</p>
<p v-if="loading">
Loading data…
</p>
<p v-if="error" class="error">
{{ error }}
</p>
<div id="popup" v-show="popup.visible" :style="{top: popup.top, left: popup.left}" @mouseenter.stop="popupOver()" @mouseleave.stop="popupOut()">
<div v-if="popup.loading">
Fetching...
</div>
<div v-else>
<div class="small">{{popup.entity.type}}</div>
<h3>{{popup.entity.label.value}} (<a target="_blank" :href="popup.entity.link">{{popup.entity.id}}</a>)</h3>
<p v-show="popup.entity.thumb" style="float:right;">
<img :src="popup.entity.thumb.thumburl" style="width:150px;">
</p>
<p v-show="popup.entity.description.value">
{{popup.entity.description.value}}
<span v-show="popup.entity.description.language">({{popup.entity.description.language}})</span>
</p>
<p v-show="popup.entity.dates.birth">
<span>{{popup.entity.dates.birth}}</span><span v-show="popup.entity.dates.death">–{{popup.entity.dates.death}}</span>
</p>
<p v-show="popup.entity.numberOfRecords">
<a target="_blank" :href="popup.entity.link">{{ popup.entity.numberOfRecords }} katalogposter</a>
</p>
<p v-show="popup.entity.coords.longitude">
<a target="_blank" :href="'https://maps.wikimedia.org/#9/' + popup.entity.coords.latitude + '/' + popup.entity.coords.longitude">Kart</a>
/
<a target="_blank" :href="'https://tools.wmflabs.org/wikidata-todo/around.html?lat=' + popup.entity.coords.latitude + '&lon=' + popup.entity.coords.longitude + '&radius=15&lang=en'">Kart</a>
</p>
<p>
<span v-for="link in popup.entity.links">
<a target="_blank" :href="link.link">» {{ link.name}}</a>
</span>
</p>
</div>
</div>
<table class="table table-striped" v-if="!loading">
<thead>
<tr>
<th scope="col">Permalink</th>
<th scope="col" style="width: 160px;">
<button class="btn btn-link" @click="setSortKey('id')">
<span>
<i class="fas fa-sort-alpha-down" v-show="sortKey == 'id' && sortOrder == 'asc'"></i>
<i class="fas fa-sort-alpha-up" v-show="sortKey == 'id' && sortOrder == 'desc'"></i>
</span>
Identifier
</button>
</th>
<th scope="col" style="width: 220px;">
<button class="btn btn-link" @click="setSortKey('date')">
<span style="width:20px;">
<i class="fas fa-sort-alpha-down" v-show="sortKey == 'date' && sortOrder == 'asc'"></i>
<i class="fas fa-sort-alpha-up" v-show="sortKey == 'date' && sortOrder == 'desc'"></i>
</span>
Date
</button>
</th>
<th scope="col" style="width: 220px;">
<button class="btn btn-link" @click="setSortKey('sender')">
<span style="width:20px;">
<i class="fas fa-sort-alpha-down" v-show="sortKey == 'sender' && sortOrder == 'asc'"></i>
<i class="fas fa-sort-alpha-up" v-show="sortKey == 'sender' && sortOrder == 'desc'"></i>
</span>
Correspondent
</button>
</th>
<th scope="col" style="width: 220px;">
<button class="btn btn-link" @click="setSortKey('place')">
<span style="width:20px;">
<i class="fas fa-sort-alpha-down" v-show="sortKey == 'place' && sortOrder == 'asc'"></i>
<i class="fas fa-sort-alpha-up" v-show="sortKey == 'place' && sortOrder == 'desc'"></i>
</span>
Sent from
</button>
</th>
<th scope="col">Files</th>
</tr>
<tr>
<th scope="col"> </th>
<th scope="col"><input placeholder="Søk" v-model="filters.id" style="width:100%"></th>
<th scope="col"><input placeholder="Søk" v-model="filters.date" style="width:100%"></th>
<th scope="col"><input placeholder="Søk" v-model="filters.sender" style="width:100%"></th>
<th scope="col"><input placeholder="Søk" v-model="filters.place" style="width:100%"></th>
</tr>
</thead>
<tbody>
<tr v-for="row in rows" ref="rows">
<td><a :href="'https://urn.nb.no/' + row.urn">{{ row.urn }}</a></td>
<td>{{ row.id }}</td>
<td>{{ row.date }}</td>
<td>
{{ row.sender }}
<a v-if="row.sender_bibsys_id" target="_blank" :href="'https://tools.wmflabs.org/bsaut/show/' + row.sender_bibsys_id" @mouseenter="showBibsysPopup($event, row.sender_bibsys_id)" @mouseleave="linkOut">
<i class="fas fa-user-check"></i>
</a>
<a v-if="row.sender_wd_id" target="_blank" :href="'https://tools.wmflabs.org/reasonator/?lang=nb&q=' + row.sender_wd_id" @mouseenter="showWikidataPopup($event, row.sender_wd_id)" @mouseleave="linkOut">
<i class="fab fa-wikipedia-w"></i>
</a>
</td>
<td>
{{ row.place }}
<a v-if="row.place_wd_id" target="_blank" :href="'https://tools.wmflabs.org/reasonator/?lang=nb&q=' + row.place_wd_id" @mouseenter="showWikidataPopup($event, row.place_wd_id)" @mouseleave="linkOut">
<i class="fab fa-wikipedia-w"></i>
</a>
</td>
<td style="display:flex; justify-content: flex-start; align-items: center; flex-wrap: wrap;">
<div v-if="row.showThumbs" style="flex: 0 0 auto; padding: .4em;" v-for="page in row.files">
<a target="_blank" :href="page.link">
<img style="max-width:90px;" :src="page.thumbnail" alt=""><br>
{{ page.label }}</a>
</div>
</td>
</tr>
</tbody>
</table>
</div>
`,
components: {
octicon: window.VueOcticon,
},
data: {
loading: true,
error: null,
allRows: [],
sortKey: 'id',
sortOrder: 'asc',
filters: {
id: '',
sender: '',
date: '',
place: '',
},
popup: {
loading: true,
visible: false,
entity: null,
top: '',
left: '',
},
},
methods: {
setSortKey: function(key) {
if (this.sortKey == key) {
this.sortOrder = (this.sortOrder == 'asc') ? 'desc' : 'asc';
} else {
this.sortKey = key;
}
},
updateQueryString: function() {
// Update the query string from the current data
let qs = []
Object.keys(this.filters).forEach(key => {
if (this.filters[key]) {
qs.push(key + '=' + encodeURIComponent(this.filters[key]));
}
});
qs.push(`sort=${this.sortKey}:${this.sortOrder}`)
window.history.replaceState(null, null, window.location.pathname + '?' + qs.join('&'));
},
checkRowVisibility: function() {
// Show thumbnails for rows that are currently visible (within the viewport).
// It's not a problem that we load a few extra rows, so we don't bother taking
// into account the fact that rows expand when thumbs are added.
let viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
for (let i = 0; i < this.rows.length; i++) {
let rect = this.$refs.rows[i].getBoundingClientRect();
if (!(rect.bottom < 0 || rect.top - viewHeight >= 0)) {
this.rows[i].showThumbs = true;
}
}
},
popupOver: function () {
this.popup.visible = true;
},
popupOut: function() {
this.popup.visible = false;
},
showPopup: function(evt, entity) {
this.popup.loading = true;
this.popup.visible = true;
this.popup.top = `${evt.pageY-20}px`,
this.popup.left = `${evt.pageX}px`,
this.popup.entity = {id: entity.id};
entity.get().then(entity => {
if (this.popup.entity.id == entity.id) {
this.popup.loading = false;
this.popup.entity = entity;
}
});
},
showBibsysPopup: function(evt, id) {
this.showPopup(evt, new BibsysEntity(id));
},
showWikidataPopup: function(evt, id) {
this.showPopup(evt, new WikidataEntity(id));
},
linkOut: function(evt) {
if (evt.relatedTarget.id != 'popup') {
this.popup.visible = false;
}
},
},
computed: {
rows: function() {
// Define filters
let filters = [];
Object.keys(this.filters).forEach(columnName => {
if (this.filters[columnName].length) {
let v = this.filters[columnName].toLowerCase();
filters.push(x => x[columnName] && x[columnName].toLowerCase().indexOf(v) !== -1);
}
});
// Filter rows
let rows = this.allRows.filter(row => {
for (var i = filters.length - 1; i >= 0; i--) {
if (!filters[i](row)) return false;
}
return true;
});
// Return sorted rows
return _.orderBy(rows, row => (row[this.sortKey] + '').toLowerCase(), [this.sortOrder]);
},
},
watch: {
'filters.id': function() { this.updateQueryString() },
'filters.sender': function() { this.updateQueryString() },
'filters.date': function() { this.updateQueryString() },
'filters.place': function() { this.updateQueryString() },
'sortKey': function() { this.updateQueryString() },
'sortOrder': function() { this.updateQueryString() },
'rows': function() { Vue.nextTick(_ => this.checkRowVisibility()) }
},
mounted: function() {
window.addEventListener('scroll', _.throttle(_ => {
this.checkRowVisibility();
}, 300));
// Set filter values from query string params
let uri = window.location.search.substring(1);
let params = new URLSearchParams(uri);
Object.keys(this.filters).forEach(key => {
this.filters[key] = params.get(key) || '';
});
let sortParams = (params.get('sort') || 'id:asc').split(':');
this.sortKey = sortParams[0];
this.sortOrder = sortParams[1];
// Get data
http.get('https://uio-library.github.io/hansteen-brev/src/hansteen.json').then(resp => {
this.loading = false;
this.error = 'Failed to process data!'; // Set error in case processing fails
let processed = resp.data.members.map(function(row) {
let place = _.get(row, 'descriptive.places.0');
if (place) {
place = _.get(place, 'place') + ', ' + _.get(place, 'country');
}
return {
id: _.get(row, 'id'),
urn: _.get(row, 'urn'),
sender: _.get(row, 'descriptive.agents.correspondent.name'),
sender_bibsys_id: _.get(row, 'descriptive.agents.correspondent.bibsys_id'),
sender_wd_id: _.get(row, 'descriptive.agents.correspondent.wikidata_id'),
place_wd_id: _.get(row, 'descriptive.places.0.wikidata_id'),
date: _.get(row, 'descriptive.date'),
place: place,
files: _.get(row, 'structure').map(page => {
let pageNo = row.structure.indexOf(page);
return {
label: page.label,
// Local thumbnail: 'http://ub-media.uio.no/arkiv/hansteen/files/' + page.filename.replace('.tif', '_thumb.jpg')
thumbnail: `https://bibsys.alma.exlibrisgroup.com/view/delivery/thumbnail/47BIBSYS_UBO/${page.alma_id}`,
// Local link: `http://ub-media.uio.no/arkiv/hansteen/files/${page.filename}`,
link: `https://bibsys-k.alma.exlibrisgroup.com/view/UniversalViewer/47BIBSYS_UBO/${row.alma_representation_id}#?cv=${pageNo}`
}
}),
showThumbs: false,
};
});
this.allRows = processed;
this.error = null; // Reset error
}, resp => {
this.loading = false;
this.error = 'Failed to fetch data!';
});
}
})
</script>
</body>
</html>