Add spell check component
This commit is contained in:
parent
ff7a6b93b3
commit
cfde20c67c
|
|
@ -23,7 +23,7 @@
|
||||||
>
|
>
|
||||||
</submission-form>
|
</submission-form>
|
||||||
|
|
||||||
<div v-html="corrections"></div>
|
<spell-check :corrections="corrections" :text="submission.text"></spell-check>
|
||||||
|
|
||||||
<div v-if="this.assignment.submission.submissionFeedback" class="assignment__feedback">
|
<div v-if="this.assignment.submission.submissionFeedback" class="assignment__feedback">
|
||||||
<p>{{feedbackText}}</p>
|
<p>{{feedbackText}}</p>
|
||||||
|
|
@ -54,6 +54,7 @@
|
||||||
import DocumentBlock from '@/components/content-blocks/DocumentBlock';
|
import DocumentBlock from '@/components/content-blocks/DocumentBlock';
|
||||||
import Solution from '@/components/content-blocks/Solution';
|
import Solution from '@/components/content-blocks/Solution';
|
||||||
import SimpleFileUpload from '@/components/SimpleFileUpload';
|
import SimpleFileUpload from '@/components/SimpleFileUpload';
|
||||||
|
import SpellCheck from '@/components/content-blocks/assignment/SpellCheck';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['value'],
|
props: ['value'],
|
||||||
|
|
@ -65,7 +66,8 @@
|
||||||
FinalSubmission,
|
FinalSubmission,
|
||||||
Solution,
|
Solution,
|
||||||
SimpleFileUpload,
|
SimpleFileUpload,
|
||||||
SubmissionForm
|
SubmissionForm,
|
||||||
|
SpellCheck
|
||||||
},
|
},
|
||||||
|
|
||||||
computed: {
|
computed: {
|
||||||
|
|
@ -190,22 +192,12 @@
|
||||||
mutation: SPELL_CHECK_MUTATION,
|
mutation: SPELL_CHECK_MUTATION,
|
||||||
variables: {
|
variables: {
|
||||||
input: {
|
input: {
|
||||||
assignment: 'Hallo',
|
assignment: this.assignment.id,
|
||||||
text: this.assignment.submission.text
|
text: this.assignment.submission.text
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
update(store, {data: {spellCheck: {correct, results}}}) {
|
update(store, {data: {spellCheck: {results}}}) {
|
||||||
console.log(results);
|
self.corrections = results;
|
||||||
console.log(correct);
|
|
||||||
let corrections = results.map(result => {
|
|
||||||
let first, middle, last;
|
|
||||||
first = result.sentence.substring(0, result.offset);
|
|
||||||
middle = result.sentence.substring(result.offset, result.offset + result.length);
|
|
||||||
last = result.sentence.substring(result.offset + result.length);
|
|
||||||
|
|
||||||
return `<p>${first}<span class="taskbase__correction">${middle}</span>${last}</p>`;
|
|
||||||
});
|
|
||||||
self.corrections = corrections.join('');
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,54 @@
|
||||||
|
<template>
|
||||||
|
<div class="spellcheck" v-if="corrections">
|
||||||
|
<p v-html="highlightedText"></p>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script>
|
||||||
|
export default {
|
||||||
|
props: ['corrections', 'text'],
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
highlightedText() {
|
||||||
|
if (!this.corrections) {
|
||||||
|
return ''
|
||||||
|
}
|
||||||
|
let parts = [];
|
||||||
|
let index = 0;
|
||||||
|
this.corrections.forEach(current => {
|
||||||
|
parts.push({
|
||||||
|
correct: true,
|
||||||
|
text: this.text.substring(index, current.offset)
|
||||||
|
});
|
||||||
|
parts.push({
|
||||||
|
correct: false,
|
||||||
|
text: this.text.substring(current.offset, current.offset + current.length)
|
||||||
|
});
|
||||||
|
index = current.offset + current.length
|
||||||
|
});
|
||||||
|
parts.push({
|
||||||
|
correct: true,
|
||||||
|
text: this.text.substring(index, this.text.length + 1)
|
||||||
|
});
|
||||||
|
return parts
|
||||||
|
.filter(part => part.text.length)
|
||||||
|
.reduce((previous, part) => {
|
||||||
|
if(part.correct) {
|
||||||
|
return `${previous}${part.text}`;
|
||||||
|
} else {
|
||||||
|
return `${previous}<span class="spellcheck__correction">${part.text}</span>`;
|
||||||
|
}
|
||||||
|
}, '');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped lang="scss">
|
||||||
|
.spellcheck {
|
||||||
|
&__correction {
|
||||||
|
background: yellow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
</style>
|
||||||
|
|
@ -16,7 +16,7 @@
|
||||||
@click="$emit('turnIn')"
|
@click="$emit('turnIn')"
|
||||||
>{{action}}
|
>{{action}}
|
||||||
</button>
|
</button>
|
||||||
<button class="submission-form-container__submit button button--primary button--white-bg"
|
<button class="submission-form-container__submit submission-form-container__spellcheck button button--primary button--white-bg"
|
||||||
v-if="spellcheck"
|
v-if="spellcheck"
|
||||||
@click="$emit('spellcheck')"
|
@click="$emit('spellcheck')"
|
||||||
>Rechtschreibung prüfen
|
>Rechtschreibung prüfen
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue