|
@ -1,5 +1,37 @@ |
|
|
import HTTP from './http'; |
|
|
import HTTP from './http'; |
|
|
|
|
|
|
|
|
|
|
|
const getOffsetFromUrl = function(url) { |
|
|
|
|
|
const offsetMatch = url.match(/[?#].*offset=(\d+)/); |
|
|
|
|
|
if (offsetMatch == null) { |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
return parseInt(offsetMatch[1], 10); |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
const storeOffsetInUrl = function(offset) { |
|
|
|
|
|
let href = window.location.href; |
|
|
|
|
|
|
|
|
|
|
|
const fragmentStart = href.indexOf('#') + 1; |
|
|
|
|
|
if (fragmentStart === 0) { |
|
|
|
|
|
href += '#offset=' + offset; |
|
|
|
|
|
} else { |
|
|
|
|
|
const prefix = href.substring(0, fragmentStart); |
|
|
|
|
|
const fragment = href.substring(fragmentStart); |
|
|
|
|
|
|
|
|
|
|
|
const newFragment = fragment.split('&').map(function(fragmentPart) { |
|
|
|
|
|
const keyValue = fragmentPart.split('='); |
|
|
|
|
|
return keyValue[0] === 'offset' |
|
|
|
|
|
? 'offset=' + offset |
|
|
|
|
|
: fragmentPart; |
|
|
|
|
|
}).join('&'); |
|
|
|
|
|
|
|
|
|
|
|
href = prefix + newFragment; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.location.href = href; |
|
|
|
|
|
}; |
|
|
|
|
|
|
|
|
const annotationMixin = { |
|
|
const annotationMixin = { |
|
|
data() { |
|
|
data() { |
|
|
return { |
|
|
return { |
|
@ -12,6 +44,7 @@ const annotationMixin = { |
|
|
remaining: 0, |
|
|
remaining: 0, |
|
|
searchQuery: '', |
|
|
searchQuery: '', |
|
|
url: '', |
|
|
url: '', |
|
|
|
|
|
offset: getOffsetFromUrl(window.location.href), |
|
|
picked: 'all', |
|
|
picked: 'all', |
|
|
count: 0, |
|
|
count: 0, |
|
|
isActive: false, |
|
|
isActive: false, |
|
@ -56,6 +89,7 @@ const annotationMixin = { |
|
|
const doc = this.docs[i]; |
|
|
const doc = this.docs[i]; |
|
|
this.annotations.push(doc.annotations); |
|
|
this.annotations.push(doc.annotations); |
|
|
} |
|
|
} |
|
|
|
|
|
this.offset = getOffsetFromUrl(this.url); |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
@ -71,7 +105,7 @@ const annotationMixin = { |
|
|
|
|
|
|
|
|
async submit() { |
|
|
async submit() { |
|
|
const state = this.getState(); |
|
|
const state = this.getState(); |
|
|
this.url = `docs/?q=${this.searchQuery}&is_checked=${state}`; |
|
|
|
|
|
|
|
|
this.url = `docs/?q=${this.searchQuery}&is_checked=${state}&offset=${this.offset}`; |
|
|
await this.search(); |
|
|
await this.search(); |
|
|
this.pageNumber = 0; |
|
|
this.pageNumber = 0; |
|
|
}, |
|
|
}, |
|
@ -97,6 +131,10 @@ const annotationMixin = { |
|
|
this.remaining = response.data.remaining; |
|
|
this.remaining = response.data.remaining; |
|
|
}); |
|
|
}); |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
|
|
|
offset() { |
|
|
|
|
|
storeOffsetInUrl(this.offset); |
|
|
|
|
|
}, |
|
|
}, |
|
|
}, |
|
|
|
|
|
|
|
|
created() { |
|
|
created() { |
|
|