Commit 5d45c595 authored by Markus Opolka's avatar Markus Opolka
Browse files

Merge branch '1-1-2' into 'master'

Resolve "Fehler bei Feature Suche"

Closes #7

See merge request bi40resu/vue-letters!5
parents 2f9906c5 6679d439
......@@ -139,12 +139,16 @@ app.use(function (req, res, next) {
next()
})
// Load static site at this endpoint, so we don't a webserver
app.use('/', express.static('dist'))
app.get('/api/search', function (req, res) {
app.get('/api/search/:letter?', function (req, res, next) {
// Search Endpoint with query parameters
// <element attribute="value">content</element>
console.time('> Search All')
if (!req.query.element){
res.send({})
return next('No Query provided')
}
let query = {
element: req.query.element,
......@@ -152,7 +156,15 @@ app.get('/api/search', function (req, res) {
}
let data = []
for (let name of cache.keys()) {
let documents = []
if (req.params.letter) {
documents.push(req.params.letter + '.xml')
} else {
documents = cache.keys()
}
for (let name of documents) {
let obj = loadDocument(name)
if (obj.valid) {
let results = lib.search(obj, query)
......@@ -163,12 +175,15 @@ app.get('/api/search', function (req, res) {
}
res.send(data)
console.timeEnd('> Search All')
})
app.get('/api/features/:letter?', function (req, res) {
// Feature Search Endpoint with query parameters
// <feature category="diakritika" type="akut" subtype="akutstattgravis" ref="26">
if (!req.query.category){
res.send({})
return next('No Query provided')
}
let query = {
category: req.query.category,
......@@ -179,8 +194,6 @@ app.get('/api/features/:letter?', function (req, res) {
let data = []
let documents = []
console.time('> Search Features')
if (req.params.letter) {
documents.push(req.params.letter + '.xml')
} else {
......@@ -198,38 +211,38 @@ app.get('/api/features/:letter?', function (req, res) {
}
res.send(data.sort(lib.compare))
console.timeEnd('> Search Features')
})
app.get('/api/letters/:letter?', function (req, res) {
// Document Endpoint with optional Document name
// Lists either all or one given document
const DOC = req.params.letter + '.xml'
if (req.params.letter) {
console.time('> List Letter')
const DOC = req.params.letter + '.xml'
res.send(loadDocument(DOC).object)
console.timeEnd('> List Letter')
} else {
console.time('> List Letters')
res.send(loadDocuments(DIR))
console.timeEnd('> List Letters')
}
})
app.get('/api/metadata/table', function (req, res) {
// Document Metadata Endpoint in Table Format
console.time('> Table Letters')
res.send(lib.table(loadDocuments(DIR)))
console.timeEnd('> Table Letters')
})
app.get('/api/metadata/reload', function (req, res) {
// Document Metadata Endpoint in Table Format
try {
loadDocumentsToCache(DIR)
res.status(200).send({})
} catch (err) {
res.status(500).send({ error: 'Error while reloading cache' })
}
})
// Where the magic happens
// Loading all documents to cache
loadDocumentsToCache(DIR)
// Where the magic happens
app.listen(PORT, function () {
console.log('> Listening at http://localhost:' + PORT)
})
......@@ -2,7 +2,12 @@
<v-container grid-list-md>
<v-layout row wrap>
<v-flex xs12>
<h3>{{header}}</h3>
<h3>{{header}}
<v-btn flat icon color="green" @click="reload">
<v-progress-circular v-if="reloading" indeterminate color="grey" v-bind:size="20"></v-progress-circular>
<v-icon v-else>cached</v-icon>
</v-btn>
</h3>
</v-flex>
<!-- List of all Letters -->
......@@ -47,13 +52,28 @@ export default {
data () {
return {
header: 'Letters',
letters: null
letters: null,
reloading: false
}
},
methods: {
reload () {
// Trigger Backend to reload cache
this.reloading = true
this.$http.get('http://localhost:3000/api/metadata/reload').then(function (data) {
this.load()
})
},
load () {
// Initial load of metadata
this.$http.get('http://localhost:3000/api/metadata/table').then(function (data) {
this.letters = data.body
this.reloading = false
})
}
},
created () {
this.$http.get('http://localhost:3000/api/metadata/table').then(function (data) {
this.letters = data.body
})
this.load()
}
}
</script>
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