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"
>
{
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) => {