Commit 5b5af28a authored by Eliot Berriot's avatar Eliot Berriot

Merge branch 'release/0.3.2'

parents 3142243c 49e4d62a
Pipeline #206 passed with stages
in 40 seconds
raw.json
data.json
src/assets/data.json
src/assets/data.*
.DS_Store
node_modules/
dist/
......
......@@ -80,6 +80,7 @@ pages:
image: node:8
script:
- npm install
- npm run compress
- npm run build
- cp data.json dist/
- mv dist public
......
......@@ -59,6 +59,14 @@ module.exports = {
name: utils.assetsPath('img/[name].[hash:7].[ext]')
}
},
{
test: /\.(lzs)(\?.*)?$/,
loader: 'url-loader',
options: {
limit: 10000,
name: utils.assetsPath('data/[name].[hash:7].[ext]')
}
},
{
test: /\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/,
loader: 'url-loader',
......
......@@ -19,7 +19,8 @@ const webpackConfig = merge(baseWebpackConfig, {
rules: utils.styleLoaders({
sourceMap: config.build.productionSourceMap,
extract: true
})
}),
noParse: /node_modules\/compressjs/
},
devtool: config.build.productionSourceMap ? '#source-map' : false,
output: {
......
......@@ -121,8 +121,7 @@
"amdefine": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/amdefine/-/amdefine-1.0.1.tgz",
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU=",
"dev": true
"integrity": "sha1-SlKCrBZHKek2Gbz9OtFR+BfOkfU="
},
"ansi-escapes": {
"version": "1.4.0",
......@@ -1850,6 +1849,25 @@
"integrity": "sha1-ZF/ErfWLcrZJ1crmUTVhnbJv8UM=",
"dev": true
},
"compressjs": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/compressjs/-/compressjs-1.0.3.tgz",
"integrity": "sha1-ldt03VuQOM+AvKMhqw7eJxtJWbY=",
"requires": {
"amdefine": "1.0.1",
"commander": "2.8.1"
},
"dependencies": {
"commander": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/commander/-/commander-2.8.1.tgz",
"integrity": "sha1-Br42f+v9oMMwqh4qBy09yXYkJdQ=",
"requires": {
"graceful-readlink": "1.0.1"
}
}
}
},
"concat-map": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/concat-map/-/concat-map-0.0.1.tgz",
......@@ -3934,11 +3952,6 @@
"integrity": "sha512-yIovAzMX49sF8Yl58fSCWJ5svSLuaibPxXQJFLmBObTuCr0Mf1KiPopGM9NiFjiYBCbfaa2Fh6breQ6ANVTI0A==",
"dev": true
},
"fuzzysearch": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/fuzzysearch/-/fuzzysearch-1.0.3.tgz",
"integrity": "sha1-3/yA9tawQiPyImqnndGUIxCW0Ag="
},
"generate-function": {
"version": "2.0.0",
"resolved": "https://registry.npmjs.org/generate-function/-/generate-function-2.0.0.tgz",
......@@ -4063,8 +4076,7 @@
"graceful-readlink": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/graceful-readlink/-/graceful-readlink-1.0.1.tgz",
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU=",
"dev": true
"integrity": "sha1-TK+tdrxi8C+gObL5Tpo906ORpyU="
},
"growl": {
"version": "1.9.2",
......
......@@ -5,6 +5,7 @@
"author": "Eliot Berriot <contact@eliotberriot.com>",
"private": true,
"scripts": {
"compress": "node scripts/compress.js",
"dev": "node build/dev-server.js",
"start": "npm run dev",
"build": "node build/build.js",
......@@ -14,15 +15,13 @@
"lint": "eslint --ext .js,.vue src test/unit/specs test/e2e/specs"
},
"dependencies": {
"fuzzysearch": "^1.0.3",
"compressjs": "^1.0.3",
"jquery": "^3.2.1",
"lz-string": "^1.4.4",
"semantic-ui-css": "^2.2.12",
"vue": "^2.4.2",
"vue-lazyload": "^1.1.3",
"vue-router": "^2.7.0",
"vue-worker": "^1.2.1",
"worker-loader": "^1.0.0"
"vue-router": "^2.7.0"
},
"devDependencies": {
"autoprefixer": "^7.1.2",
......
......@@ -75,8 +75,7 @@
#{{ scp.id }} - {{ scp.name }}
</div>
<div class="meta">
<span>
<i :class="['ui', 'warning circle', scpData.getObjectClassColor(scp.object_class), 'icon']"></i>
<span :class="['ui', scpData.getObjectClassColor(scp.object_class), 'tiny', 'label']">
{{ scpData.data.object_classes[scp.object_class].label }}
</span>
<span>
......
<template>
<div v-if="loading" class="ui active inverted page dimmer">
<div class="ui center text loader">
<p>Downloading SCP data (this should take &lt;30s depending on your internet connection)...</p>
<p>We will cache the data to ensure you don't see this step ever again.</p>
<p>Downloading SCP data (this should take &lt;10s depending on your internet connection)...</p>
<p>Many D-class were harmed during this page load.</p>
</div>
</div>
......
......@@ -63,13 +63,13 @@
<div class="eight wide column">
<div class="ui fluid text container">
<h1>SCP #{{ scp.id }} - {{ scp.name }}</h1>
<template v-if="getField('procedures')">
<template v-if="scpData.getTextField(scp, 'procedures')">
<h2 class="ui header">Special Containment Procedure</h2>
<p v-for="paragraph in getField('procedures')">{{ paragraph }}</p>
<p v-for="paragraph in scpData.getTextField(scp, 'procedures')">{{ paragraph }}</p>
</template>
<template v-if="getField('description')">
<template v-if="scpData.getTextField(scp, 'description')">
<h2 class="ui header">Description</h2>
<p v-for="paragraph in getField('description')">{{ paragraph }}</p>
<p v-for="paragraph in scpData.getTextField(scp, 'description')">{{ paragraph }}</p>
</template>
</div>
</div>
......@@ -112,14 +112,6 @@ export default {
browse: function (filterData) {
this.scpData.initFilters(filterData)
this.$router.push('/browse')
},
getField: function (name) {
let candidates = this.scp.text_fields.filter(e => {
return e.code === name
})
if (candidates.length > 0) {
return candidates[0].paragraphs
}
}
},
computed: {
......
import $ from 'jquery'
import Vue from 'vue'
import LZString from 'lz-string'
import Worker from 'worker-loader!./worker.js'
import fuzzysearch from 'fuzzysearch'
const cacheWorker = new Worker()
cacheWorker.onmessage = (event) => {
try {
localStorage.setItem('scpData', JSON.stringify({'data': event.data.data}))
console.log('Localstorage updated!')
} catch (e) {
console.error('Cannot store data in local storage', e)
}
}
var scpData = {
loading: false,
......@@ -21,6 +9,7 @@ var scpData = {
object_classes: {}
},
searchQuery: '',
searchIndex: null,
sortAscending: true,
sortField: 'id',
sortFields: [
......@@ -127,24 +116,33 @@ var scpData = {
}
let length = this.searchFields.length
for (var i = 0; i < length; i++) {
let f = this.searchFields[i]
if (fuzzysearch(this.query, scp[f].toLowerCase())) {
let f = this.searchFields[i].toLowerCase()
let result = scp[f].toLowerCase().indexOf(this.query) > -1
if (result) {
return true
}
}
}
}
],
toCache: function () {
cacheWorker.postMessage({ action: 'cache', data: this.data })
uncompress: function (data) {
return JSON.parse(LZString.decompressFromUTF16(data))
},
restoreCache: function () {
let compressed = localStorage.getItem('scpData')
let dataRow = JSON.parse(compressed).data
var restored = JSON.parse(LZString.decompress(dataRow))
return restored
loaded (data, callback) {
this.data = data
this.loading = false
this.initFilters()
callback()
},
getTextField: function (scp, name) {
let candidates = scp.text_fields.filter(e => {
return e.code === name
})
if (candidates.length > 0) {
return candidates[0].paragraphs
}
return []
},
load (callback) {
let self = this
if (!callback) {
......@@ -153,33 +151,16 @@ var scpData = {
if (this.alreadyLoaded()) {
return callback()
}
let url = 'https://scp.eliotberriot.com/data.json'
let url = require('./assets/data.lzs')
console.log('fetching data (this may take some time)...')
this.loading = true
try {
this.data = this.restoreCache()
this.loading = false
console.log('restored from cache')
this.initFilters()
return callback()
} catch (e) {
console.log('Cannot restore from cache', e)
}
$.ajax({
url,
type: 'OPTIONS',
headers: {
'If-Range': 'nope' // disable partial resource (206)
},
type: 'GET',
success: response => {
// get body data
console.log('Data fetched!')
let r = JSON.parse(response)
self.data = r
self.loading = false
self.initFilters()
callback()
self.toCache()
self.loaded(self.uncompress(response), callback)
},
error: response => {
console.error('Error while fetching data!')
......
import LZString from 'lz-string'
function compress (data) {
var LZString = require('lz-string')
console.log('Compressing data before caching...')
let compressed = LZString.compress(JSON.stringify(data))
self.postMessage({data: compressed})
}
self.addEventListener('message', (event) => {
if (event.data.action === 'cache') {
compress(event.data.data)
}
})
Markdown is supported
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