diff --git a/src/components/document/edition/DocumentEditionCommentaries.vue b/src/components/document/edition/DocumentEditionCommentaries.vue index 98fc4c2..322d12e 100644 --- a/src/components/document/edition/DocumentEditionCommentaries.vue +++ b/src/components/document/edition/DocumentEditionCommentaries.vue @@ -39,11 +39,12 @@ :key="com.label" >
- -
- -
- - - - - - \ No newline at end of file diff --git a/src/components/document/edition/DocumentEditionSpeechParts.vue b/src/components/document/edition/DocumentEditionSpeechParts.vue deleted file mode 100644 index bfd9d14..0000000 --- a/src/components/document/edition/DocumentEditionSpeechParts.vue +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - \ No newline at end of file diff --git a/src/components/document/edition/DocumentEditionTranscription.vue b/src/components/document/edition/DocumentEditionTranscription.vue index 6d7d92c..a1b712c 100644 --- a/src/components/document/edition/DocumentEditionTranscription.vue +++ b/src/components/document/edition/DocumentEditionTranscription.vue @@ -1,10 +1,13 @@ @@ -12,17 +15,20 @@ import { mapState, mapGetters } from 'vuex'; import TranscriptionEditor from "@/components/editors/TranscriptionEditor.vue" +import TranscriptionActionBar from "@/components/document/edition/actionbars/TranscriptionActionBar.vue"; export default { name: "DocumentEditionTranscription", components: { - TranscriptionEditor + TranscriptionEditor, TranscriptionActionBar }, props: { - transcriptionWithNotes: {type: String, default: ""} + section: {type: String, required: true} }, computed: { - ...mapState('transcription', ['transcriptionLoading']) + ...mapState('transcription', ['transcriptionContent', 'transcriptionLoading']), + ...mapGetters('document', ['documentOwner']), + ...mapState('user', ['currentUser']) }, async created() { }, diff --git a/src/components/document/edition/DocumentEditionTranslation.vue b/src/components/document/edition/DocumentEditionTranslation.vue index 4211a84..47fbafe 100644 --- a/src/components/document/edition/DocumentEditionTranslation.vue +++ b/src/components/document/edition/DocumentEditionTranslation.vue @@ -1,56 +1,37 @@ diff --git a/src/components/document/edition/actionbars/TranscriptionActionBar.vue b/src/components/document/edition/actionbars/TranscriptionActionBar.vue index 466cb04..4e9d128 100644 --- a/src/components/document/edition/actionbars/TranscriptionActionBar.vue +++ b/src/components/document/edition/actionbars/TranscriptionActionBar.vue @@ -12,21 +12,29 @@

+ +

+ +

+

-

-
-
-
- - -
- - - \ No newline at end of file diff --git a/src/components/editors/CommentaryEditor.vue b/src/components/editors/CommentaryEditor.vue deleted file mode 100644 index 07d7923..0000000 --- a/src/components/editors/CommentaryEditor.vue +++ /dev/null @@ -1,245 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/editors/SpeechpartsEditor.vue b/src/components/editors/SpeechpartsEditor.vue deleted file mode 100644 index 8c932c0..0000000 --- a/src/components/editors/SpeechpartsEditor.vue +++ /dev/null @@ -1,249 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/editors/TranscriptionEditor.vue b/src/components/editors/TranscriptionEditor.vue index 4936869..dfa95e7 100644 --- a/src/components/editors/TranscriptionEditor.vue +++ b/src/components/editors/TranscriptionEditor.vue @@ -1,11 +1,11 @@ diff --git a/src/components/editors/TranslationEditor.vue b/src/components/editors/TranslationEditor.vue deleted file mode 100644 index 8fa743a..0000000 --- a/src/components/editors/TranslationEditor.vue +++ /dev/null @@ -1,290 +0,0 @@ - - - \ No newline at end of file diff --git a/src/components/mirador-plugin/index.js b/src/components/mirador-plugin/index.js index c6c5120..fe22c3b 100644 --- a/src/components/mirador-plugin/index.js +++ b/src/components/mirador-plugin/index.js @@ -5,7 +5,6 @@ import { Point } from "openseadragon"; function cleanAnnoText(s) { s = s.replace(/persName/gi, 'persName-disabled') s = s.replace(/placeName/gi, 'placeName-disabled') - console.log(s) return s } diff --git a/src/mixins/EditorMixins.js b/src/mixins/EditorMixins.js index 43e5dc2..591944b 100644 --- a/src/mixins/EditorMixins.js +++ b/src/mixins/EditorMixins.js @@ -1,6 +1,6 @@ /* eslint-disable no-extra-boolean-cast */ import Quill, {getNewQuill, options} from '../modules/quill/AdeleQuill'; -import { getNewDelta } from '../modules/quill/DeltaUtils'; +import Delta from 'quill-delta'; import { trim } from '../modules/quill/MarkupUtils'; import _isEmpty from 'lodash/isEmpty'; @@ -28,20 +28,59 @@ var EditorMixin = { initEditor(editorElement, initialContent) { editorElement.innerHTML = trim(initialContent); this.editor = getNewQuill(editorElement); - this.activateEvents(); - this.editor.updateContents(getNewDelta().retain(this.editor.getLength(), 'api')) + this.editor.updateContents(new Delta().retain(this.editor.getLength(), 'api')) this.editorContentElement = editorElement.children[0]; this.editorInited = true; + this.activateEvents(); }, activateEvents () { //console.log("EditorMixins.activateEvents") - this.editor.on('selection-change', this.onSelection); - this.editor.on('selection-change', this.onFocus); + this.editor.on('selection-change', (range) => { + if (range === null || range.length === 0) { + this.updateButtons({}) + this.defineNewNote = false + if (this.editorHasFocus) + this.selectedSpeechpartId = null + } + if (range) { + this.setRangeBound(range); + let formats = this.editor.getFormat(range.index, range.length); + this.updateButtons(formats); + console.log("onSelection", range, formats) + if (!!formats.note) { + this.onNoteSelected(formats.note, range); + this.buttons.note = true; + } else { + this.selectedNoteId = null; + this.buttons.note = false; + } + + // speechparts + if (range.length > 0) { + if (formats.speechpart) { + this.onSpeechpartSelected(formats.speechpart, range); + const spId = formats.speechpart.split(',')[0] + const sp = this.speechparts.find(e => e.id === parseInt(spId)) + console.log("ID SP", sp) + this.currentSpeechpart = sp + //this.buttons.speechpart = false; + } else { + this.selectedSpeechpartId = range.index; + //this.buttons.speechpart = true; + } + } + + this.currentSelection = range + } + this.editorHasFocus = this.editor.hasFocus(); + }); + //this.editor.on('selection-change', this.onSelection); + //this.editor.on('selection-change', this.onFocus); this.editor.on('text-change', this.onTextChange); }, deactivateEvents () { - //console.log("EditorMixins.deactivateEvents") + console.log("EditorMixins.deactivateEvents") if (this.editor) { this.editor.off('selection-change', this.onSelection); this.editor.off('selection-change', this.onFocus); @@ -69,20 +108,7 @@ var EditorMixin = { } }, onSelection (range) { - if (range) { - this.setRangeBound(range); - let formats = this.editor.getFormat(range.index, range.length); - this.updateButtons(formats); - console.log("onSelection", range, formats) - if (!!formats.note) { - this.onNoteSelected(formats.note, range); - this.buttons.note = false; - } else { - this.selectedNoteId = null; - this.buttons.note = true; - } - this.currentSelection = range - } + }, onFocus () { this.editorHasFocus = this.editor.hasFocus(); @@ -99,7 +125,7 @@ var EditorMixin = { insertSegment () { let range = this.editor.getSelection(true); - this.editor.updateContents(getNewDelta().retain(range.index).insert({ segment: true }), Quill.sources.USER); + this.editor.updateContents(new Delta().retain(range.index).insert({ segment: true }), Quill.sources.USER); console.log('insert seg', this.editor.getContents()) this.editor.setSelection(range.index + 1, Quill.sources.SILENT); }, @@ -109,13 +135,13 @@ var EditorMixin = { insertColBreak () { let range = this.editor.getSelection(true); - this.editor.updateContents(getNewDelta().retain(range.index).delete(range.length).insert({ colbreak: true }), Quill.sources.USER); + this.editor.updateContents(new Delta().retain(range.index).delete(range.length).insert({ colbreak: true }), Quill.sources.USER); this.editor.setSelection(range.index + 1, Quill.sources.SILENT); }, updateButtons (formats) { - if (_isEmpty(formats)) formats = { paragraph: true } + if (_isEmpty(formats)) formats = { } for (let key in this.buttons) { this.buttons[key] = !!formats[key]; } @@ -207,10 +233,6 @@ var EditorMixin = { let top = this.actionsPositions.bottom + 5; let left = (this.actionsPositions.left+this.actionsPositions.right)/2; return `top:${top}px;left:${left}px`; - }, - isNoteButtonActive () { - const cond = this.editorHasFocus && this.buttons.note; - return cond; } } diff --git a/src/mixins/EditorNotesMixins.js b/src/mixins/EditorNotesMixins.js index 69e764a..ed4c66f 100644 --- a/src/mixins/EditorNotesMixins.js +++ b/src/mixins/EditorNotesMixins.js @@ -56,12 +56,15 @@ var EditorNotesMixin = { // TODO delete note this.editor.format('note', false); await this.$store.dispatch('transcription/saveTranscription') - await this.$store.dispatch('translation/saveTranslation') + await this.$store.dispatch('transcription/fetchTranscriptionContent') + + /* await this.$store.dispatch('translation/saveTranslation') await this.$store.dispatch('commentaries/saveCommentaries') await this.$store.dispatch('notes/deleteNote', this.selectedNoteId) await this.$store.dispatch('transcription/fetchTranscriptionContent') await this.$store.dispatch('translation/fetchTranslationContent') await this.$store.dispatch('commentaries/fetchCommentariesContent') + */ this.selectedNoteId = null; this.closeNoteEdit(); }, diff --git a/src/modules/quill/DeltaUtils.js b/src/modules/quill/DeltaUtils.js deleted file mode 100755 index fcb7a82..0000000 --- a/src/modules/quill/DeltaUtils.js +++ /dev/null @@ -1,143 +0,0 @@ -import _omit from 'lodash/omit'; -import _isEmpty from 'lodash/isEmpty'; -import _pick from 'lodash/pick'; -import _values from 'lodash/values'; -import Delta from 'quill-delta'; - - -const globalFilters = { - removeAttributes: ['color','background'], - keepFormats: ['bold', 'italic', 'smallcaps', 'underline', 'del', 'expan', 'superscript', 'location', 'person', 'cite'] -} -const deltaOperationsFilters = { - content: { - removeAttributes: ['note','speechpart', 'zone'].concat(globalFilters.removeAttributes), - keepFormats: [].concat(globalFilters.keepFormats), - }, - notes: { - removeAttributes: ['segment','speechpart', 'zone'].concat(globalFilters.removeAttributes), - keepFormats: ['note'].concat(globalFilters.keepFormats), - }, - speechparts: { - removeAttributes: ['segment', 'note', 'zone'].concat(globalFilters.removeAttributes), - keepFormats: ['speechpart'].concat(globalFilters.keepFormats), - }, - facsimile: { - removeAttributes: ['note', 'segment','speechpart'].concat(globalFilters.removeAttributes), - keepFormats: ['zone'].concat(globalFilters.keepFormats), - }, - "text-alignment": { - removeAttributes: ['note', 'speechpart', 'zone'].concat(globalFilters.removeAttributes), - keepFormats: ['segment'], - } -} - -//function get -const getNewDelta = () => new Delta(); - - -const filterDeltaForSpeechParts = (delta) => { - // TODO: cette fonction est chelou - let filteredDelta = new Delta(); - delta.forEach(function(op) { - if (op.retain) { - filteredDelta.retain(op.retain); - } - else if (op.insert) { - filteredDelta.insert(op.insert); - } - else if (op.delete) { - filteredDelta.delete(op.delete); - } - }); - return filteredDelta; -} -const filterDeltaOperations = (quillInstance, delta, mode) => { - - // Renvoie un nouveau delta filtré selon arrAttributesToRemove - - const ops = [...delta.ops] - - let filteredDelta = new Delta(); - let insertionIndex = 0; - - let firstOperation = Object.assign({}, ops[0]); - if (firstOperation.retain) { - insertionIndex = firstOperation.retain; - } - firstOperation = filterOperation(quillInstance, firstOperation, mode, 0); - filteredDelta.ops.push(firstOperation); - let restOperations = _values(_omit(ops, [0])) - - if (restOperations.length > 0) { - - restOperations.forEach(function (op) { - - filteredDelta.ops.push(filterOperation(quillInstance, op, mode, insertionIndex)); - - }); - - } - return filteredDelta; - -} -const filterOperation = (quillInstance, operation, mode, insertionIndex) => { - const filters = deltaOperationsFilters[mode] - let newOp = {}; - let type = getOperationType(operation) - - // Copie le type d'operation - if (operation[type] !== null && typeof operation[type] === 'object') { - newOp[type] = Object.assign({}, operation[type]); - } else { - newOp[type] = operation[type]; - } - - // Copie les formats de l'instance quill au point d'insertion - let formats = quillInstance.getFormat(insertionIndex); - if (type === 'insert') { - formats = _pick(formats, filters.keepFormats); - if (!_isEmpty(formats)) newOp.attributes = formats; - } - - // Copie les attributs (styles) si existent - if (operation.attributes) { - let attr = Object.assign({}, _omit(operation.attributes, filters.removeAttributes)); - newOp.attributes = Object.assign(newOp.attributes || {}, attr); - } - return newOp; -} -const getOperationType = operation => { - if (operation.retain) { - return 'retain'; - } else if (operation.insert) { - return 'insert'; - } else if (operation.delete) { - return 'delete'; - } -} -const operationToString = operation => { - const t = getOperationType(operation); - let attributes, attrString = ''; - if (operation.attributes) { - attributes = operation.attributes - attrString = Object.keys(attributes).map(attr => attr + ': '+attributes[attr]).join(', ') - } - return `${t} (${operation[t]}) { ${attrString} }` -} - -const removeNotesFromDelta = (delta) => { - let filteredDelta = new Delta(); - delta.ops.forEach(function (op) { - if (op.attributes && op.attributes.note) delete op.attributes.note; - filteredDelta.ops.push(op); - }) - return filteredDelta; -} - -export { - getNewDelta, - filterDeltaForSpeechParts, - filterDeltaOperations, - removeNotesFromDelta -} \ No newline at end of file diff --git a/src/pages/DocumentEditionPage.vue b/src/pages/DocumentEditionPage.vue index 09e5f5e..79b566b 100644 --- a/src/pages/DocumentEditionPage.vue +++ b/src/pages/DocumentEditionPage.vue @@ -181,11 +181,11 @@ :class="`${imageVisibility ? '' : 'fluid-content'}`" > - - +
+ + +
+
@@ -220,7 +220,7 @@
- +
- - +
@@ -336,6 +333,9 @@
+

+ {{documentOwner.username}} propose une transcription à traduire +

@@ -345,9 +345,7 @@ class="column" :class="transcriptionVisibility && imageVisibility ? 'is-one-third' :''" > - +
@@ -440,6 +438,9 @@ class="column" >
+

+ {{documentOwner.username}} propose une transcription à commenter. +

@@ -493,11 +494,12 @@
- - +

+ {{documentOwner.username}} propose une transcription dans laquelle les parties du discours peuvent être identifiées. +

+
+
{ vm.$store.dispatch("workflow/setCurrentSection", vm.$attrs.section); @@ -629,11 +629,6 @@ export default { beforeRouteLeave(to, from, next) { this.$store.dispatch("workflow/setCurrentSection", null); this.$store.dispatch("workflow/setEditionMode", false); - - if (to.params.section === "translation" || from.params.section === "translation") { - this.$store.dispatch('workflow/setTranscriptionAlignmentMode', false) - } - next(); }, data() { @@ -641,8 +636,6 @@ export default { isLoading: false, init: false, - transcriptionAlignmentError: null, - imageVisibility: true, noticeVisibility: true, transcriptionVisibility: true, @@ -662,11 +655,10 @@ export default { ]), ...mapState("workflow", ["selectedUserId"]), ...mapState("transcription", [ - "transcriptionWithNotes", - "transcriptionWithSpeechparts", + "transcriptionContent", "transcriptionError", ]), - ...mapState("translation", ["translationWithNotes", "translationError"]), + ...mapState("translation", ["translationContent", "translationError"]), ...mapState("commentaries", ["commentaries", "commentariesError"]), ...mapState("speechparts", ["speechPartsError"]), @@ -734,21 +726,24 @@ export default { }, watch: { async selectedUserId() { - if (this.init) { - await this.fetchContentFromUser(); - this.setupVisibilityWidget(this.$attrs.section) - } + await this.fetchContentFromUser(); + this.setupVisibilityWidget(this.$attrs.section) }, + async '$attrs.section'() { + await this.fetchContentFromUser(); + } }, async created() { this.isLoading = true; + // ² document (and notice infos) try { await this.fetchOne({ id: this.$attrs.docId }); } catch (error) { this.$router.push({ name: "error", params: { error: error } }); } - + // fetch content for all other tabs await this.fetchContentFromUser(); + this.init = true; this.isLoading = false; }, @@ -826,18 +821,11 @@ export default { } }, async fetchContentFromUser() { - await this.fetchSpeechPartsContent(); - await this.fetchTranscriptionContent(); - await this.fetchTranslationContent(); - - try { - this.transcriptionAlignmentError = null; - await this.fetchTranscriptionAlignmentView(); - } catch (error) { - this.transcriptionAlignmentError = error; - } - - await this.fetchCommentariesContent(); + return await Promise.all([ + this.fetchTranscriptionContent(), + this.fetchTranslationContent(), + this.fetchCommentariesContent() + ]) }, async addNewTranscription() { await this.createTranscription(); diff --git a/src/store/modules/commentaries/index.js b/src/store/modules/commentaries/index.js index dfc5341..40328f0 100644 --- a/src/store/modules/commentaries/index.js +++ b/src/store/modules/commentaries/index.js @@ -7,11 +7,7 @@ import { quillToTEI, convertLinebreakTEIToQuill, convertLinebreakQuillToTEI, - insertNotes, - stripNotes, - computeNotesPointers, } from '../../../modules/quill/MarkupUtils' -import {filterDeltaOperations} from '../../../modules/quill/DeltaUtils' let notesShadowQuillElements = {} @@ -30,60 +26,30 @@ const state = { }; async function saveCom(rootState, rootGetters, com) { - //console.log("saving", state.commentariesWithNotes, com) const contentWithNotes = quillToTEI(com.withNotes) - const content = stripNotes(contentWithNotes) - - // prepare notes - const teiWithNotes = contentWithNotes - let sanitizedWithNotes = convertLinebreakQuillToTEI(teiWithNotes) - - const notes = computeNotesPointers(sanitizedWithNotes) - - notes.forEach(note => { - const found = rootGetters['notes/getNoteById'](note.id) - - note.content = found.content - if (found.note_type) { - note.type_id = found.note_type.id - } - }) // put content & update notes await http.put(`documents/${rootState.document.document.id}/commentaries/from-user/${rootState.workflow.selectedUserId}`, { data: { type_id: com.type, - content: content, - notes: notes.filter(n => n.id !== null && n.id >= 0) + content: contentWithNotes, + //notes: notes.filter(n => n.id !== null && n.id >= 0) } }) - - // and post new notes - const new_notes = notes.filter(n => n.id === null || n.id < 0).map(n => { - delete n.id - return n - }) - - if (new_notes.length > 0){ - await http.post(`documents/${rootState.document.document.id}/commentaries/from-user/${rootState.workflow.selectedUserId}`, { - data: { - type_id: com.type, - notes: new_notes - } - }) - } + } const mutations = { INIT(state, data) { state.commentariesWithNotes = {} state.selectedCommentaryLabel = null + console.log("hello", data) data.forEach(commentary => { const t = commentary.typeLabel notesShadowQuillElements[t] = document.createElement('div') - notesShadowQuillElements[t].innerHTML = "

" + notesShadowQuillElements[t].innerHTML = "" notesShadowQuills[t] = new Quill(notesShadowQuillElements[t]); notesShadowQuillElements[t].children[0].innerHTML = commentary.withNotes || "" @@ -94,7 +60,6 @@ const mutations = { withNotes: notesShadowQuillElements[t].children[0].innerHTML }) }) - if (data.length > 0) { state.selectedCommentaryLabel = data[0].typeLabel } @@ -151,10 +116,8 @@ const mutations = { }, ADD_OPERATION (state, payload) { const t = state.selectedCommentaryLabel - - const deltaFilteredForNotes = filterDeltaOperations(notesShadowQuills[t], payload, 'notes') - notesShadowQuills[t].updateContents(deltaFilteredForNotes) + notesShadowQuills[t].updateContents(payload) Vue.set(state.commentariesWithNotes, t, { ...state.commentariesWithNotes[t], @@ -169,13 +132,13 @@ function parseComsFromResponse(response) { let commentariesFormatted = []; commentaries.forEach(comm => { let quillContent = TEIToQuill(comm.content); - let withNotes = insertNotes(quillContent, comm.notes); + //let withNotes = insertNotes(quillContent, comm.notes); //console.log("commentaries", comm, quillContent, withNotes) commentariesFormatted.push({ type: comm.type.id, typeLabel: comm.type.label, content: quillContent, - withNotes: withNotes, + withNotes: quillContent, notes: comm.notes }); hasTypes[comm.type.label] = true @@ -242,31 +205,6 @@ const actions = { commit('SELECT', label) }, - insertNote({commit, rootState, state}, newNote) { - const t = state.selectedCommentaryLabel - const quillContent = TEIToQuill(state.commentariesWithNotes[t].content) - const textWithNotes = insertNotes(quillContent, [newNote]) - - const payload = { - notes: state.commentariesWithNotes[t].notes.concat(newNote), - withNotes: convertLinebreakTEIToQuill(textWithNotes) - } - /* save the shadow content with notes */ - commit('UPDATE', payload) - return newNote - }, - updateNote({commit, rootState, state}, updatedNote) { - const t = state.selectedCommentaryLabel - const currentNotes = state.commentariesWithNotes[t].notes; - const payload = { - ...state.commentariesWithNotes[t], - notes: [...currentNotes.filter(n => n.id !== updatedNote.id), updatedNote] - } - /* save the note modification in the store */ - commit('SAVING_STATUS', 'tobesaved') - commit('UPDATE', payload) - return updatedNote - }, /* useful */ addNewCommentary({commit, state, dispatch, rootState}, {type}) { commit('LOADING_STATUS', true); @@ -275,7 +213,7 @@ const actions = { doc_id : rootState.document.document.id, user_id : rootState.workflow.selectedUserId, type_id: type, - content : '

' + content : '' } } const newLabel = state.selectedCommentaryLabel diff --git a/src/store/modules/transcription/index.js b/src/store/modules/transcription/index.js index dccd713..ed736d4 100644 --- a/src/store/modules/transcription/index.js +++ b/src/store/modules/transcription/index.js @@ -4,104 +4,42 @@ import {http} from '../../../modules/http-common'; import { TEIToQuill, quillToTEI, - convertLinebreakTEIToQuill, - convertLinebreakQuillToTEI, - insertSegments, - insertNotesAndSegments, - insertNotes, - insertSpeechparts, - insertFacsimileZones, - stripSegments, - computeNotesPointers, - computeSpeechpartsPointers, - computeAlignmentPointers + convertLinebreakTEIToQuill } from '../../../modules/quill/MarkupUtils' -import {filterDeltaOperations} from '../../../modules/quill/DeltaUtils' const transcriptionShadowQuillElement = document.createElement('div'); -const notesShadowQuillElement = document.createElement('div'); -const speechpartsShadowQuillElement = document.createElement('div'); -const transcriptionWithTextAlignmentShadowQuillElement = document.createElement('div'); -const facsimileShadowQuillElement = document.createElement('div'); let transcriptionShadowQuill; -let transcriptionWithTextAlignmentShadowQuill; -let notesShadowQuill; -let speechpartsShadowQuill; -let facsimileShadowQuill; const state = { - transcriptionLoading: true, - transcription: null, transcriptionContent: null, - transcriptionWithNotes: null, - transcriptionWithTextAlignment: null, - transcriptionWithSpeechparts: null, - transcriptionWithFacsimile: null, + transcriptionSaved: true, - translationAlignmentSaved: true, transcriptionError: null, - translationAlignmentError: null, - textAlignmentSegments: [], savingStatus: 'uptodate' }; const mutations = { - INIT(state, payload) { transcriptionShadowQuillElement.innerHTML = "

" transcriptionShadowQuill = new Quill(transcriptionShadowQuillElement); transcriptionShadowQuillElement.children[0].innerHTML = payload.content || ""; state.transcriptionContent = transcriptionShadowQuillElement.children[0].innerHTML; - //console.log("INIT with content", state.transcriptionContent); - - notesShadowQuillElement.innerHTML = "

" - notesShadowQuill = new Quill(notesShadowQuillElement); - notesShadowQuillElement.children[0].innerHTML = payload.withNotes || ""; - state.transcriptionWithNotes = notesShadowQuillElement.children[0].innerHTML; - //console.log("INIT with notes", state.transcriptionWithNotes); - - speechpartsShadowQuillElement.innerHTML = "

" - speechpartsShadowQuill = new Quill(speechpartsShadowQuillElement); - speechpartsShadowQuillElement.children[0].innerHTML = payload.withSpeechparts || ""; - state.transcriptionWithSpeechparts = speechpartsShadowQuillElement.children[0].innerHTML; - - transcriptionWithTextAlignmentShadowQuillElement.innerHTML = "

" - transcriptionWithTextAlignmentShadowQuill = new Quill(transcriptionWithTextAlignmentShadowQuillElement); - transcriptionWithTextAlignmentShadowQuillElement.children[0].innerHTML = payload.withTextAlignment || ""; - state.transcriptionWithTextAlignment = transcriptionWithTextAlignmentShadowQuillElement.children[0].innerHTML; - - facsimileShadowQuillElement.innerHTML = "

" - facsimileShadowQuill = new Quill(facsimileShadowQuillElement); - facsimileShadowQuillElement.children[0].innerHTML = payload.withFacsimile || ""; - state.transcriptionWithFacsimile = facsimileShadowQuillElement.children[0].innerHTML; + console.log("INIT with content", state.transcriptionContent); }, RESET(state) { - console.log("STORE MUTATION transcription/RESET"); - state.transcription = null; - state.textAlignmentSegments = []; state.transcriptionContent = null; - state.transcriptionWithNotes = null; - state.transcriptionWithTextAlignment = null; - state.transcriptionWithSpeechparts = null; - state.transcriptionWithFacsimile = null; - - if (transcriptionShadowQuillElement && transcriptionShadowQuillElement.children[0]) transcriptionShadowQuillElement.children[0].innerHTML = ""; - if (notesShadowQuillElement && notesShadowQuillElement.children[0]) notesShadowQuillElement.children[0].innerHTML = ""; - if (transcriptionWithTextAlignmentShadowQuillElement && transcriptionWithTextAlignmentShadowQuillElement.children[0]) transcriptionWithTextAlignmentShadowQuillElement.children[0].innerHTML = ""; - if (speechpartsShadowQuillElement && speechpartsShadowQuillElement.children[0]) speechpartsShadowQuillElement.children[0].innerHTML = ""; - if (facsimileShadowQuillElement && facsimileShadowQuillElement.children[0]) facsimileShadowQuillElement.children[0].innerHTML = ""; - + + if (transcriptionShadowQuillElement && transcriptionShadowQuillElement.children[0]) { + transcriptionShadowQuillElement.children[0].innerHTML = "" + } }, SET_ERROR(state, payload) { state.transcriptionError = payload }, - SET_TEXT_ALIGNMENT_ERROR(state, payload) { - state.translationAlignmentError = payload - }, LOADING_STATUS (state, payload) { state.transcriptionLoading = payload; }, @@ -109,59 +47,20 @@ const mutations = { //console.log("STORE MUTATION transcription/SAVING_STATUS", payload) state.savingStatus = payload; }, - STORE_ALIGNMENTS(state, payload) { - state.textAlignmentSegments = payload; - }, UPDATE (state, payload) { - if (payload.transcription) { - state.transcription = payload.transcription; - } - if (payload.withNotes) { - state.transcriptionWithNotes = payload.withNotes; - } - if (payload.withSpeechparts) { - state.transcriptionWithSpeechparts = payload.withSpeechparts; - } - if (payload.withTextAlignment) { - state.transcriptionWithTextAlignment = payload.withTextAlignment; - } - if (payload.withFacsimile) { - state.transcriptionWithFacsimile = payload.withFacsimile; - } //state.transcriptionSaved = true; }, CHANGED (state) { // transcription changed and needs to be saved state.transcriptionSaved = false; }, - ADD_TRANSLATION_ALIGNMENT_OPERATION (state, payload) { - const deltaFilteredForTextAlignment = filterDeltaOperations(transcriptionWithTextAlignmentShadowQuill, payload, 'text-alignment'); - transcriptionWithTextAlignmentShadowQuill.updateContents(deltaFilteredForTextAlignment); - state.transcriptionWithTextAlignment = transcriptionWithTextAlignmentShadowQuillElement.children[0].innerHTML; - }, ADD_OPERATION (state, payload) { - - const deltaFilteredForContent = filterDeltaOperations(transcriptionShadowQuill, payload, 'content'); - const deltaFilteredForNotes = filterDeltaOperations(notesShadowQuill, payload, 'notes'); - const deltaFilteredForSpeechparts = filterDeltaOperations(speechpartsShadowQuill, payload, 'speechparts'); - const deltaFilteredForFacsimile = filterDeltaOperations(facsimileShadowQuill, payload, 'facsimile'); - - transcriptionShadowQuill.updateContents(deltaFilteredForContent); - notesShadowQuill.updateContents(deltaFilteredForNotes); - speechpartsShadowQuill.updateContents(deltaFilteredForSpeechparts); - facsimileShadowQuill.updateContents(deltaFilteredForFacsimile); - + transcriptionShadowQuill.updateContents(payload); state.transcriptionContent = transcriptionShadowQuillElement.children[0].innerHTML; - state.transcriptionWithNotes = notesShadowQuillElement.children[0].innerHTML; - state.transcriptionWithSpeechparts = speechpartsShadowQuillElement.children[0].innerHTML; - state.transcriptionWithFacsimile = facsimileShadowQuillElement.children[0].innerHTML; }, SAVED (state) { // transcription saved state.transcriptionSaved = true; - }, - SAVING_TRANSLATION_ALIGNMENT_STATUS (state, v) { - state.translationAlignmentSaved = v; } }; @@ -171,29 +70,19 @@ const actions = { /* useful */ fetchTranscriptionFromUser ({dispatch, commit, state, getters, rootState}, {docId, userId}) { commit('RESET') + console.log('reset tr') commit('LOADING_STATUS', true); return http.get(`documents/${docId}/transcriptions/from-user/${userId}`).then(async response => { - let transcription = response.data.data; - let quillContent = TEIToQuill(transcription.content); - - const withNotes = insertNotesAndSegments(quillContent, transcription.notes, state.textAlignmentSegments, 'transcription') - const withSpeechparts = insertSpeechparts(quillContent, rootState.speechparts.speechparts); - const withFacsimile = insertFacsimileZones(quillContent, rootState.facsimile.alignments); - const withTextAlignment = TEIToQuill(insertSegments(transcription.content, state.textAlignmentSegments)); - + const data = { transcription: transcription, - content: convertLinebreakTEIToQuill(quillContent), - withTextAlignment: convertLinebreakTEIToQuill(withTextAlignment), - withNotes: convertLinebreakTEIToQuill(withNotes), - withSpeechparts: convertLinebreakTEIToQuill(withSpeechparts), - withFacsimile: convertLinebreakTEIToQuill(withFacsimile), + content: convertLinebreakTEIToQuill(quillContent) }; commit('INIT', data); - commit('UPDATE', data); + //commit('UPDATE', data); commit('SET_ERROR', null) commit('LOADING_STATUS', false); }).catch((error) => { @@ -204,32 +93,23 @@ const actions = { }, async fetchTranscriptionContent({dispatch, rootState, rootGetters}) { if (rootState.workflow.currentSection === "speech-parts") { - await dispatch('fetchTranscriptionFromUser', { + return await dispatch('fetchTranscriptionFromUser', { docId: rootState.document.document.id, userId: rootState.document.document.user_id }) } else { - await dispatch('fetchTranscriptionFromUser', { + return await dispatch('fetchTranscriptionFromUser', { docId: rootState.document.document.id, userId: rootState.workflow.selectedUserId }) } - await dispatch('document/fetchTranscriptionView', - rootGetters['user/currentUserIsTeacher'] ? rootState.workflow.selectedUserId : rootState.document.document.user_id, - {root: true}) - - }, - /* useful */ - async fetchTextAlignments ({commit, rootState}) { - const response = await http.get(`documents/${rootState.document.document.id}/transcriptions/alignments/from-user/${rootState.workflow.selectedUserId}`) - if (response.data.errors) { - commit('STORE_ALIGNMENTS', []); - return; - } - const alignments = response.data.data && Array.isArray(response.data.data[0]) ? response.data.data : [response.data.data]; - commit('STORE_ALIGNMENTS', alignments); + //await dispatch('document/fetchTranscriptionView', + //rootGetters['user/currentUserIsTeacher'] ? rootState.workflow.selectedUserId : rootState.document.document.user_id, + //{root: true}) }, + + /* useful */ addNewTranscription ({commit, dispatch, rootState}) { const emptyTranscription = { @@ -267,45 +147,14 @@ const actions = { commit('LOADING_STATUS', true) try { - // prepare notes const tei = quillToTEI(state.transcriptionContent) - const sanitizedContent = stripSegments(tei) - - const teiWithNotes = quillToTEI(state.transcriptionWithNotes) - let sanitizedWithNotes = stripSegments(teiWithNotes) - sanitizedWithNotes = convertLinebreakQuillToTEI(sanitizedWithNotes) - - const notes = computeNotesPointers(sanitizedWithNotes) - - notes.forEach(note => { - const found = rootGetters['notes/getNoteById'](note.id) - note.content = found.content - if (found.note_type) { - note.type_id = found.note_type.id - } - }) // put content && update notes await http.put(`documents/${rootState.document.document.id}/transcriptions/from-user/${rootState.workflow.selectedUserId}`, { data: { - content: sanitizedContent, - notes: notes.filter(n => n.id !== null && n.id >= 0) + content: tei, } }) - - // and post new notes - const new_notes = notes.filter(n => n.id === null || n.id < 0).map(n => { - delete n.id - return n - }) - if (new_notes.length > 0){ - await http.post(`documents/${rootState.document.document.id}/transcriptions/from-user/${rootState.workflow.selectedUserId}`, { - data: {notes: new_notes} - }) - } - // update & save the speechparts pointers before reloading the transcription - await dispatch('speechparts/saveSpeechParts', null, {root: true}) - // update the store content await dispatch('fetchTranscriptionContent') @@ -318,44 +167,6 @@ const actions = { commit('LOADING_STATUS', false) } }, - insertNote({commit, rootState, state}, newNote) { - const quillContent = TEIToQuill(state.transcriptionContent) - const textWithNotes = insertNotes(quillContent, [newNote]) - const data = { - transcription: { - ...state.transcription, - notes: state.transcription.notes.concat(newNote) - }, - withNotes: convertLinebreakTEIToQuill(textWithNotes), - } - /* save the shadow content with notes */ - commit('UPDATE', data) - return newNote - }, - insertSegments({commit, state}, segments) { - const TEIwithSegments = insertSegments(quillToTEI(state.transcriptionContent), segments); - const withTextAlignmentSegments = TEIToQuill(TEIwithSegments); - const data = { - withTextAlignment: convertLinebreakTEIToQuill(withTextAlignmentSegments) - }; - - transcriptionWithTextAlignmentShadowQuillElement.children[0].innerHTML = data.withTextAlignment; - - commit('UPDATE', data); - }, - updateNote({commit, rootState, state}, updatedNote) { - const currentNotes = state.transcription.notes; - const data = { - transcription: { - ...state.transcription, - notes: [...currentNotes.filter(n => n.id !== updatedNote.id), updatedNote] - } - } - /* save the note modification in the store */ - commit('SAVING_STATUS', 'tobesaved') - commit('UPDATE', data) - return updatedNote - }, async cloneContent({dispatch, rootState}) { const doc_id = rootState.document.document.id; const user_id = rootState.workflow.selectedUserId; @@ -367,49 +178,10 @@ const actions = { console.log(`%c error while cloning transcription ${e}`, 'color:red'); } }, - updateSpeechpartsPointers({state}) { - const TEIwithSpeechParts = quillToTEI(state.transcriptionWithSpeechparts) - - let sanitizedWithSpeechparts = stripSegments(TEIwithSpeechParts); - sanitizedWithSpeechparts = convertLinebreakQuillToTEI(sanitizedWithSpeechparts); - return computeSpeechpartsPointers(sanitizedWithSpeechparts); - }, - textAlignmentsNeedToBeSaved({commit}) { - commit('SAVING_TRANSLATION_ALIGNMENT_STATUS', false) - }, - async saveTranslationAlignment({commit, dispatch, state, rootGetters, rootState}) { - commit('SAVING_TRANSLATION_ALIGNMENT_STATUS', false) - commit('SET_TEXT_ALIGNMENT_ERROR', null) - try { - let data = [] - const transcription = rootGetters['transcription/transcriptionSegmentsFromQuill']; - const translation = rootGetters['translation/translationSegmentsFromQuill']; - - if (transcription.length !== translation.length) { - throw Error('Le nombre de segments doit être identique entre la transcription et la traduction') - } - - for(let i = 0; i < transcription.length; i++) { - data.push([...transcription[i], ...translation[i]]) - } - console.log('save translation alignment', data) - - const response = await http.post(`documents/${rootState.document.document.id}/transcriptions/alignments/from-user/${rootState.workflow.selectedUserId}`, { data: data }) - commit('SAVING_TRANSLATION_ALIGNMENT_STATUS', true) - - } catch(error) { - commit('SET_TEXT_ALIGNMENT_ERROR', error) - commit('SAVING_TRANSLATION_ALIGNMENT_STATUS', false) - } - }, changed ({ commit, rootState }, deltas) { - if (rootState.workflow.transcriptionAlignmentMode) { - commit('ADD_TRANSLATION_ALIGNMENT_OPERATION', deltas); - } else { - commit('ADD_OPERATION', deltas); - commit('CHANGED'); - commit('SAVING_STATUS', 'tobesaved') - } + commit('ADD_OPERATION', deltas); + commit('CHANGED'); + commit('SAVING_STATUS', 'tobesaved') }, reset({commit}) { commit('RESET') @@ -421,12 +193,6 @@ const getters = { isTranscriptionSaved(state) { return state.savingStatus === 'uptodate' }, - transcriptionSegmentsFromQuill(state) { - if (!state.transcriptionWithTextAlignment) return []; - - const text = quillToTEI(state.transcriptionWithTextAlignment) - return computeAlignmentPointers(text) - } }; const transcriptionModule = { diff --git a/src/store/modules/translation/index.js b/src/store/modules/translation/index.js index 1cecb7a..5b77573 100644 --- a/src/store/modules/translation/index.js +++ b/src/store/modules/translation/index.js @@ -1,144 +1,87 @@ -import axios from 'axios'; import Quill from '../../../modules/quill/AdeleQuill'; import {http} from '../../../modules/http-common'; import { - insertNotes, computeNotesPointers, TEIToQuill, - insertSegments, stripSegments, quillToTEI, convertLinebreakTEIToQuill, insertNotesAndSegments, - convertLinebreakQuillToTEI, computeAlignmentPointers + TEIToQuill, + quillToTEI, + convertLinebreakTEIToQuill } from '../../../modules/quill/MarkupUtils' -import {filterDeltaOperations} from "../../../modules/quill/DeltaUtils"; + const translationShadowQuillElement = document.createElement('div'); -const notesShadowQuillElement = document.createElement('div'); let translationShadowQuill; -let notesShadowQuill; - -const translationWithTextAlignmentShadowQuillElement = document.createElement('div'); -let translationWithTextAlignmentShadowQuill; const state = { translationLoading: true, - translation: null, - translationError: null, translationContent: null, - translationWithTextAlignment: null, - translationWithNotes: null, - translationSaved: true, - referenceTranslation: null, + translationSaved: true, + translationError: null, savingStatus: 'uptodate' }; const mutations = { INIT(state, payload) { - translationShadowQuillElement.innerHTML = "

"; + translationShadowQuillElement.innerHTML = "

" translationShadowQuill = new Quill(translationShadowQuillElement); - translationShadowQuillElement.children[0].innerHTML = payload.content; + translationShadowQuillElement.children[0].innerHTML = payload.content || ""; state.translationContent = translationShadowQuillElement.children[0].innerHTML; - - notesShadowQuillElement.innerHTML = "

" - notesShadowQuill = new Quill(notesShadowQuillElement); - notesShadowQuillElement.children[0].innerHTML = payload.withNotes; - state.translationWithNotes = notesShadowQuillElement.children[0].innerHTML; - - translationWithTextAlignmentShadowQuillElement.innerHTML = "

" - translationWithTextAlignmentShadowQuill = new Quill(translationWithTextAlignmentShadowQuillElement); - translationWithTextAlignmentShadowQuillElement.children[0].innerHTML = payload.withTextAlignment || ""; - state.translationWithTextAlignment = translationWithTextAlignmentShadowQuillElement.children[0].innerHTML; + //console.log("INIT with content", state.translationContent); }, - RESET (state) { - state.translation = null; + RESET(state) { + console.log("STORE MUTATION translation/RESET"); state.translationContent = null; - state.translationWithTextAlignment = null; - state.translationWithNotes = null; - - if (translationShadowQuillElement) translationShadowQuillElement.innerHTML = ""; - if (notesShadowQuillElement) notesShadowQuillElement.innerHTML = ""; - if (translationWithTextAlignmentShadowQuillElement && translationWithTextAlignmentShadowQuillElement.children[0]) translationWithTextAlignmentShadowQuillElement.children[0].innerHTML = ""; - + + if (translationShadowQuillElement && translationShadowQuillElement.children[0]) { + translationShadowQuillElement.children[0].innerHTML = "" + } }, SET_ERROR(state, payload) { state.translationError = payload }, - REFERENCE(state, payload) { - state.referenceTranslation = payload - }, LOADING_STATUS (state, payload) { state.translationLoading = payload; }, + SAVING_STATUS (state, payload) { + //console.log("STORE MUTATION translation/SAVING_STATUS", payload) + state.savingStatus = payload; + }, UPDATE (state, payload) { - if (payload.translation) { - state.translation = payload.translation; - } - if (payload.withNotes) { - state.translationWithNotes = payload.withNotes - } - if (payload.withSpeechparts) { - state.translationWithSpeechparts = payload.withSpeechparts; - } - if (payload.withFacsimile) { - state.translationWithFacsimile = payload.withFacsimile; - } - if (payload.withTextAlignment) { - state.translationWithTextAlignment = payload.withTextAlignment; - } //state.translationSaved = true; }, CHANGED (state) { // translation changed and needs to be saved state.translationSaved = false; }, - SAVING_STATUS (state, payload) { - //console.log("STORE MUTATION transcription/SAVING_STATUS", payload) - state.savingStatus = payload; - }, - ADD_TRANSLATION_ALIGNMENT_OPERATION (state, payload) { - const deltaFilteredForTextAlignment = filterDeltaOperations(translationWithTextAlignmentShadowQuill, payload, 'text-alignment'); - translationWithTextAlignmentShadowQuill.updateContents(deltaFilteredForTextAlignment); - state.translationWithTextAlignment = translationWithTextAlignmentShadowQuillElement.children[0].innerHTML; - }, ADD_OPERATION (state, payload) { - const deltaFilteredForContent = filterDeltaOperations(translationShadowQuill, payload, 'content'); - const deltaFilteredForNotes = filterDeltaOperations(notesShadowQuill, payload, 'notes'); - - translationShadowQuill.updateContents(deltaFilteredForContent); - notesShadowQuill.updateContents(deltaFilteredForNotes); - + translationShadowQuill.updateContents(payload); state.translationContent = translationShadowQuillElement.children[0].innerHTML; - state.translationWithNotes = notesShadowQuillElement.children[0].innerHTML; }, SAVED (state) { - // translation changed and needs to be saved + // translation saved state.translationSaved = true; - } + }, + }; const actions = { - + /* useful */ - fetchTranslationFromUser ({commit, state, rootState}, {docId, userId}) { + fetchTranslationFromUser ({dispatch, commit, state, getters, rootState}, {docId, userId}) { commit('RESET') - return http.get(`documents/${docId}/translations/from-user/${userId}`).then( response => { - commit('LOADING_STATUS', true); - + commit('LOADING_STATUS', true); + return http.get(`documents/${docId}/translations/from-user/${userId}`).then(async response => { let translation = response.data.data; - const alignments = rootState.transcription.transcriptionAlignments; - let quillContent = TEIToQuill(translation.content); - //let content = insertSegments(quillContent, alignments, 'translation'); - const withNotes = insertNotesAndSegments(quillContent, translation.notes, alignments, 'translation'); - + const data = { translation: translation, - content: convertLinebreakTEIToQuill(quillContent), - withTextAlignment: convertLinebreakTEIToQuill(quillContent), - withNotes: convertLinebreakTEIToQuill(withNotes), - } + content: convertLinebreakTEIToQuill(quillContent) + }; commit('INIT', data); - commit('UPDATE', data); + //commit('UPDATE', data); commit('SET_ERROR', null) commit('LOADING_STATUS', false); }).catch((error) => { @@ -147,23 +90,25 @@ const actions = { //throw error }) }, - /* useful */ - fetchTranslationContent({dispatch, rootState, rootGetters}) { - if (rootGetters['workflow/isTranslationReadOnly']) { - // when in readonly mode - // students see the reference content - // teacher and admins can see other ppl readonly views - return dispatch('document/fetchTranslationView', - rootGetters['user/currentUserIsTeacher'] ? rootState.workflow.selectedUserId : rootState.document.user_id, - {root: true}) - } else { - console.log("fetch translation from user") - return dispatch('fetchTranslationFromUser', { + async fetchTranslationContent({dispatch, rootState, rootGetters}) { + if (rootState.workflow.currentSection === "speech-parts") { + await dispatch('fetchTranslationFromUser', { docId: rootState.document.document.id, - userId: rootState.workflow.selectedUserId + userId: rootState.document.document.user_id }) } + else { + await dispatch('fetchTranslationFromUser', { + docId: rootState.document.document.id, + userId: rootState.workflow.selectedUserId + }) + } + //await dispatch('document/fetchTranslationView', + //rootGetters['user/currentUserIsTeacher'] ? rootState.workflow.selectedUserId : rootState.document.document.user_id, + //{root: true}) }, + + /* useful */ addNewTranslation ({commit, dispatch, rootState}) { const emptyTranslation = { @@ -182,7 +127,7 @@ const actions = { setError({commit}, payload) { commit('SET_ERROR', payload) }, - /* useful */ + /* useful */ async deleteTranslationFromUser({dispatch, commit}, {docId, userId}) { try { commit('SET_ERROR', null) @@ -195,7 +140,6 @@ const actions = { commit('SET_ERROR', error) } }, - /* useful */ async saveTranslation({dispatch, commit, state, rootState, rootGetters}) { commit('SAVING_STATUS', 'tobesaved') @@ -203,99 +147,25 @@ const actions = { try { const tei = quillToTEI(state.translationContent) - const sanitizedContent = stripSegments(tei) - - // prepare notes - const teiWithNotes = quillToTEI(state.translationWithNotes) - let sanitizedWithNotes = stripSegments(teiWithNotes) - sanitizedWithNotes = convertLinebreakQuillToTEI(sanitizedWithNotes) - const notes = computeNotesPointers(sanitizedWithNotes) - //console.log("preparing notes", state.translationWithNotes, computeNotesPointers(sanitizedWithNotes), notes) - - notes.forEach(note => { - const found = rootGetters['notes/getNoteById'](note.id) - note.content = found.content - if (found.note_type) { - note.type_id = found.note_type.id - } - }) // put content && update notes await http.put(`documents/${rootState.document.document.id}/translations/from-user/${rootState.workflow.selectedUserId}`, { data: { - content: sanitizedContent, - notes: notes.filter(n => n.id !== null && n.id >= 0) + content: tei, } }) - - // and post new notes - const new_notes = notes.filter(n => n.id === null || n.id < 0).map(n => { - delete n.id - return n - }) - if (new_notes.length > 0){ - await http.post(`documents/${rootState.document.document.id}/translations/from-user/${rootState.workflow.selectedUserId}`, { - data: {notes: new_notes} - }) - } - - // update the store content + await dispatch('fetchTranslationContent') commit('SAVING_STATUS', 'uptodate') commit('SET_ERROR', false) commit('LOADING_STATUS', false) } catch(error) { - // TODO: rollback to previous content and notes ? commit('SET_ERROR', error) commit('SAVING_STATUS', 'error') commit('LOADING_STATUS', false) } }, - - insertNote({commit, state}, newNote) { - /* build a new shadow content with notes */ - const quillContent = TEIToQuill(state.translationContent); - const textWithNotes = insertNotes(quillContent, [newNote]) - const data = { - translation: { - ...state.translation, - notes: state.translation.notes.concat(newNote) - }, - withNotes: convertLinebreakTEIToQuill(textWithNotes), - } - /* save the shadow content with notes */ - commit('UPDATE', data) - return newNote - }, - - insertSegments({commit, state}, segments) { - const TEIwithSegments = insertSegments(quillToTEI(state.translationContent), segments); - const withTextAlignmentSegments = TEIToQuill(TEIwithSegments); - const data = { - withTextAlignment: convertLinebreakTEIToQuill(withTextAlignmentSegments) - }; - translationWithTextAlignmentShadowQuillElement.children[0].innerHTML = data.withTextAlignment; - - commit('UPDATE', data); - //translationWithTextAlignmentShadowQuill.setText(state.translationWithTextAlignment) - //console.log(state.translationWithTextAlignment) - }, - - updateNote({commit, rootState, state}, updatedNote) { - const currentNotes = state.translation.notes; - const data = { - transcription: { - ...state.translation, - notes: [...currentNotes.filter(n => n.id !== updatedNote.id), updatedNote] - } - } - /* save the note modification in the store */ - commit('SAVING_STATUS', 'tobesaved') - commit('UPDATE', data) - return updatedNote - }, - async cloneContent({dispatch, rootState}) { const doc_id = rootState.document.document.id; const user_id = rootState.workflow.selectedUserId; @@ -307,32 +177,22 @@ const actions = { console.log(`%c error while cloning translation ${e}`, 'color:red'); } }, - + changed ({ commit, rootState }, deltas) { - if (rootState.workflow.transcriptionAlignmentMode) { - commit('ADD_TRANSLATION_ALIGNMENT_OPERATION', deltas); - } else { - commit('ADD_OPERATION', deltas); - commit('CHANGED', false); - commit('SAVING_STATUS', 'tobesaved') - } + commit('ADD_OPERATION', deltas); + commit('CHANGED'); + commit('SAVING_STATUS', 'tobesaved') }, - reset ({ commit }) { + reset({commit}) { commit('RESET') - }, + } }; - const getters = { isTranslationSaved(state) { return state.savingStatus === 'uptodate' }, - translationSegmentsFromQuill(state) { - if (!state.translationWithTextAlignment) return []; - const text = quillToTEI(state.translationWithTextAlignment) - return computeAlignmentPointers(text) - } }; const translationModule = { @@ -341,6 +201,6 @@ const translationModule = { mutations, actions, getters -} +}; export default translationModule; diff --git a/src/store/modules/workflow/index.js b/src/store/modules/workflow/index.js index 34ce8a3..b6cbc45 100644 --- a/src/store/modules/workflow/index.js +++ b/src/store/modules/workflow/index.js @@ -117,14 +117,14 @@ const getters = { if (getters.isTranscriptionReadOnly) { return rootState.document.transcriptionView !== null } else { - return rootState.transcription.transcription !== null + return rootState.transcription.transcriptionContent !== null } }, selectedUserHasTranslation: (state, getters, rootState) => { if (getters.isTranslationReadOnly) { return rootState.document.translationView !== null } else { - return rootState.translation.translation !== null + return rootState.translation.translationContent !== null } }, selectedUserHasCommentaries: (state, getters, rootState) => {