|
|
|
@ -5,18 +5,24 @@ import qs from "querystring";
|
|
|
|
|
function fillResult($modal, result) {
|
|
|
|
|
$modal.data('block-id', result.id)
|
|
|
|
|
$modal.data('block-original-text', result.line)
|
|
|
|
|
let visibleText = result.line.replace(/\s*#\S+/g, '').trim();
|
|
|
|
|
$modal.data('block-text-without-tags', visibleText)
|
|
|
|
|
$modal.find('.block-title').show().text(result.title)
|
|
|
|
|
$modal.find('.block-text').show().val(result.line)
|
|
|
|
|
$modal.find('.block-text').show().val(visibleText)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function replaceBlock(id, oldText) {
|
|
|
|
|
return fetch('/api/block/replace', {
|
|
|
|
|
async function replaceBlock(id, oldText) {
|
|
|
|
|
if (oldText === false) return false;
|
|
|
|
|
|
|
|
|
|
await fetch('/api/block/replace', {
|
|
|
|
|
method: 'post',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/x-www-form-urlencoded',
|
|
|
|
|
},
|
|
|
|
|
body: qs.encode({id, text: oldText}),
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return true
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function appendBlock(id, newText) {
|
|
|
|
@ -30,13 +36,12 @@ function appendBlock(id, newText) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function resetSRBox(text) {
|
|
|
|
|
let newText = text.replace(/#(?:\[\[)?sr\/(\d+)(?:\]\])?/, '#sr/1');
|
|
|
|
|
return newText;
|
|
|
|
|
return text + " #review #sr/1"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function processSRBox(review, originalText) {
|
|
|
|
|
let oldText = originalText
|
|
|
|
|
.replace(/#(?:\[\[)?sr\/(\d+)(?:\]\])?/, function (text, srCount) {
|
|
|
|
|
.replace(/#sr\/(\d+)/, function (text, srCount) {
|
|
|
|
|
if (review === 'never') return '';
|
|
|
|
|
let nextCount = 1;
|
|
|
|
|
const count = parseInt(srCount)
|
|
|
|
@ -45,15 +50,22 @@ function processSRBox(review, originalText) {
|
|
|
|
|
if (review === 'later') nextCount = count + 1
|
|
|
|
|
return '#sr/' + nextCount;
|
|
|
|
|
}).trim()
|
|
|
|
|
if (review === 'never') return oldText.replace(/#(?:\[\[)?review(?:\]\])?/, '')
|
|
|
|
|
if (review === 'never') return oldText.replace(/#review/, '')
|
|
|
|
|
if (oldText === originalText) return false
|
|
|
|
|
return oldText
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$(function () {
|
|
|
|
|
let reviewBlocks = [];
|
|
|
|
|
let isSR = false;
|
|
|
|
|
|
|
|
|
|
$('.start-review, .start-sr').on('click', function () {
|
|
|
|
|
isSR = $(this).hasClass('start-sr')
|
|
|
|
|
|
|
|
|
|
$('.start-review').on('click', function () {
|
|
|
|
|
search.startQuery('+tag:review +tag:sr/1', {internal: false}).then((results) => {
|
|
|
|
|
// Use different queries for different days
|
|
|
|
|
const query = isSR ? '+tag:sr tag:"sr/1" tag:"sr/2"' : '+tag:review tag:"sr/1"'
|
|
|
|
|
|
|
|
|
|
search.startQuery(query, {internal: false}).then((results) => {
|
|
|
|
|
reviewBlocks = results
|
|
|
|
|
|
|
|
|
|
$('.review-modal .end-of-review').hide();
|
|
|
|
@ -81,16 +93,21 @@ $(function () {
|
|
|
|
|
window.location.reload()
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal .show-answer').on('click', function () {
|
|
|
|
|
$('.review-modal .block-answer').show();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
$('.modal .review').on('click', function () {
|
|
|
|
|
const $modal = $(this).parents('.modal')
|
|
|
|
|
const review = $(this).data('review')
|
|
|
|
|
|
|
|
|
|
// NOTE: should we keep the review and sr/* tag in the editable text?
|
|
|
|
|
const originalText = $modal.data('block-original-text')
|
|
|
|
|
const originalTextWithoutTags = $modal.data('block-text-without-tags')
|
|
|
|
|
let text = $modal.find('.block-text').val()
|
|
|
|
|
let id = $modal.data('block-id')
|
|
|
|
|
|
|
|
|
|
processText(review, text, originalText, id)
|
|
|
|
|
processText(review, text, originalTextWithoutTags, originalText, id)
|
|
|
|
|
.then(() => {
|
|
|
|
|
if (reviewBlocks.length > 0) {
|
|
|
|
|
const first = reviewBlocks.shift()
|
|
|
|
@ -109,8 +126,8 @@ $(function () {
|
|
|
|
|
}).catch(e => console.log(e))
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function processText(review, text, originalText, id) {
|
|
|
|
|
if (text !== originalText) {
|
|
|
|
|
async function processText(review, text, originalTextWithoutTags, originalText, id) {
|
|
|
|
|
if (text !== originalTextWithoutTags) {
|
|
|
|
|
await appendBlock(id, resetSRBox(text))
|
|
|
|
|
}
|
|
|
|
|
await replaceBlock(id, processSRBox(review, originalText))
|
|
|
|
|