1
0
Fork 0

Merge pull request #8 from sharpshark28/enhancement/jsonquerychain

[ENHANCEMENT]: using json-query-chain
This commit is contained in:
Joe L Wroten 2017-05-26 13:43:30 -05:00 committed by GitHub
commit 8d4aae4997
3 changed files with 2 additions and 41 deletions

View file

@ -13,6 +13,7 @@
"dependencies": { "dependencies": {
"babel-runtime": "^6.0.0", "babel-runtime": "^6.0.0",
"fastclick": "^1.0.6", "fastclick": "^1.0.6",
"json-query-chain": "^1.0.0",
"marked": "^0.3.6", "marked": "^0.3.6",
"material-design-icons": "^3.0.1", "material-design-icons": "^3.0.1",
"moment": "^2.15.0", "moment": "^2.15.0",

View file

@ -21,7 +21,7 @@
<script> <script>
import Vue from 'vue' import Vue from 'vue'
import { Utils } from 'quasar' import { Utils } from 'quasar'
import Query from '../query' import Query from 'json-query-chain'
import Filter from './Filter' import Filter from './Filter'
import SpellItem from './Spellitem' import SpellItem from './Spellitem'
import { state } from '../store' import { state } from '../store'

View file

@ -1,40 +0,0 @@
export default class Query {
constructor (data) {
this.data = data.map(item => {
item.sortScore = 0
return item
})
}
get results () {
return this.data
}
search (key, term = '', score = 0) {
if (term.length >= 3) {
this.data = this.data.filter(item => {
let regFind = new RegExp(term, 'gi')
let termMatches = (item[key].match(regFind) || []).length
item.sortScore += termMatches
return termMatches
})
}
return this
}
sort (key = 'sortScore') {
this.data = this.data.sort((a, b) => {
if (a[key] < b[key]) return -1
if (a[key] > b[key]) return 1
return 0
})
return this
}
paginate (page = 1, perPage = 10) {
let min = page * perPage - perPage
let max = min + perPage
this.data = this.data.slice(min, max)
return this
}
}