Commit f325e77e authored by Markus Opolka's avatar Markus Opolka
Browse files

Merge branch 'validation' into 'master'

Add XML Validation and fix regression

See merge request bi40resu/vue-letters!4
parents f9041967 76f88edb
...@@ -45,12 +45,17 @@ function inCacheFormat (docname, docobj) { ...@@ -45,12 +45,17 @@ function inCacheFormat (docname, docobj) {
collection: docobj.TEI.teiHeader.fileDesc.titleStmt.collection._text, collection: docobj.TEI.teiHeader.fileDesc.titleStmt.collection._text,
url: '/api/letters/' + docname.slice(0, -4), url: '/api/letters/' + docname.slice(0, -4),
name: docname.replace(/_/g, ' ').slice(0, -4), name: docname.replace(/_/g, ' ').slice(0, -4),
valid: true,
hash: hash, hash: hash,
object: docobj object: docobj
} }
} catch (err) { } catch (err) {
console.log(arguments.callee) // eslint-disable-line no-caller console.log(arguments.callee) // eslint-disable-line no-caller
console.error('>> Error while loading ' + docname) console.error('>> Error while loading ' + docname)
doc = {
name: docname.replace(/_/g, ' ').slice(0, -4),
valid: false
}
} }
return doc return doc
...@@ -147,11 +152,13 @@ app.get('/api/search', function (req, res) { ...@@ -147,11 +152,13 @@ app.get('/api/search', function (req, res) {
} }
let data = [] let data = []
for (let item of cache.keys()) { for (let name of cache.keys()) {
let obj = loadDocument(item) let obj = loadDocument(name)
let results = lib.search(obj, query) if (obj.valid) {
if (results !== null) { let results = lib.search(obj, query)
data.push(results) if (results !== null) {
data.push(results)
}
} }
} }
...@@ -176,18 +183,22 @@ app.get('/api/features/:letter?', function (req, res) { ...@@ -176,18 +183,22 @@ app.get('/api/features/:letter?', function (req, res) {
if (req.params.letter) { if (req.params.letter) {
console.time('> Search Features - Letter') console.time('> Search Features - Letter')
let obj = loadDocument(DOC) let obj = loadDocument(DOC)
let results = lib.features(obj, query) if (obj.valid) {
if (results !== null) { let results = lib.features(obj, query)
data.push(results) if (results !== null) {
data.push(results)
}
} }
console.timeEnd('> Search Features - Letter') console.timeEnd('> Search Features - Letter')
} else { } else {
console.time('> Search Features') console.time('> Search Features')
for (let item of cache.keys()) { for (let item of cache.keys()) {
let obj = loadDocument(item) let obj = loadDocument(item)
let results = lib.features(obj, query) if (obj.valid) {
if (results !== null) { let results = lib.features(obj, query)
data.push(results) if (results !== null) {
data.push(results)
}
} }
} }
console.timeEnd('> Search Features') console.timeEnd('> Search Features')
......
...@@ -151,8 +151,8 @@ function metadataTable (objs) { ...@@ -151,8 +151,8 @@ function metadataTable (objs) {
let items = [] let items = []
for (let item of objs) { for (let item of objs) {
let meta = item.object.TEI.teiHeader.fileDesc.titleStmt
try { try {
let meta = item.object.TEI.teiHeader.fileDesc.titleStmt
items.push({ items.push({
title: meta.title._text, title: meta.title._text,
name: item.name, name: item.name,
...@@ -163,11 +163,16 @@ function metadataTable (objs) { ...@@ -163,11 +163,16 @@ function metadataTable (objs) {
date: meta.date._text, date: meta.date._text,
place: meta.place._text, place: meta.place._text,
url: item.url, url: item.url,
link: item.link link: item.link,
valid: true
}) })
} catch (err) { } catch (err) {
console.log(arguments.callee) // eslint-disable-line no-caller console.log(arguments.callee) // eslint-disable-line no-caller
console.log('>> Error while table formating' + meta.title._text) console.log('>> Error while table formating' + item.name)
items.push({
name: item.name,
valid: false
})
} }
} }
......
{ {
"name": "cdbp", "name": "cdbp",
"version": "1.1", "version": "1.1.1",
"description": "FAU CDBP", "description": "FAU CDBP",
"author": "Markus Opolka <markus@martialblog.de>", "author": "Markus Opolka <markus@martialblog.de>",
"private": true, "private": true,
......
...@@ -142,7 +142,7 @@ export default { ...@@ -142,7 +142,7 @@ export default {
// Sums up all hits in all letters // Sums up all hits in all letters
let hits = 0 let hits = 0
for (let value of this.results) { for (let value of this.results) {
hits = hits + value.count hits = hits + value.hits
} }
return hits return hits
} }
......
...@@ -9,14 +9,23 @@ ...@@ -9,14 +9,23 @@
<v-flex xs12 v-if="letters"> <v-flex xs12 v-if="letters">
<v-list> <v-list>
<template v-for="letter in letters"> <template v-for="letter in letters">
<v-list-tile avatar v-bind:key="letter.url" :to="letter.link"> <v-list-tile avatar v-if="letter.valid" v-bind:key="letter.url" :to="letter.link">
<v-list-tile-avatar> <v-list-tile-avatar>
<v-icon grey lighten-1 white--text>mail</v-icon> <v-icon grey lighten-1>mail</v-icon>
</v-list-tile-avatar> </v-list-tile-avatar>
<v-list-tile-content> <v-list-tile-content>
<v-list-tile-title v-html="letter.name"></v-list-tile-title> <v-list-tile-title v-html="letter.name"></v-list-tile-title>
</v-list-tile-content> </v-list-tile-content>
</v-list-tile> </v-list-tile>
<v-list-tile avatar v-else v-bind:key="letter.name" class="red darken-4">
<v-list-tile-avatar>
<v-icon grey lighten-1 dark>error</v-icon>
</v-list-tile-avatar>
<v-list-tile-content>
<v-list-tile-title v-html="letter.name" class="white--text"></v-list-tile-title>
<span class="white--text caption">Error while loading file</span>
</v-list-tile-content>
</v-list-tile>
<v-divider></v-divider> <v-divider></v-divider>
</template> </template>
</v-list> </v-list>
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment