Commit deb8a6d0 authored by Eva Bardou's avatar Eva Bardou Committed by Bastien Abadie
Browse files

Move comparison attributes and functions from Editor to store

parent f1991f75
......@@ -82,6 +82,23 @@ export const actions = {
commit('setDocumentId', documentId)
await dispatch('fetchPart', pk)
},
async loadPart({state, commit, dispatch, rootState}, direction) {
if (!state.loaded || !state[direction]) return
let documentId = state.documentId
let part = state[direction]
commit('regions/reset', {}, {root: true})
commit('lines/reset', {}, {root: true})
commit('reset')
commit('setDocumentId', documentId)
try {
await dispatch('fetchPart', part)
await dispatch('transcriptions/getCurrentContent', rootState.transcriptions.selectedTranscription, {root: true})
await dispatch('transcriptions/getComparisonContent', {}, {root: true})
} catch (err) {
console.log('couldnt fetch part data!', err)
}
},
}
export default {
......
......@@ -2,7 +2,9 @@ import { assign } from 'lodash'
import * as api from '../api'
export const initialState = () => ({
all: []
all: [],
selectedTranscription: null,
comparedTranscriptions: []
})
export const mutations = {
......@@ -14,6 +16,14 @@ export const mutations = {
if (index < 0) return
Vue.delete(state.all, index)
},
setSelectedTranscription (state, pk) {
state.selectedTranscription = pk
},
removeComparedTranscription (state, pk) {
let index = state.comparedTranscriptions.findIndex(e=>e.pk == pk)
if (index < 0) return
Vue.delete(state.comparedTranscriptions, index)
},
reset (state) {
assign(state, initialState())
}
......@@ -127,6 +137,19 @@ export const actions = {
console.log('couldnt archive transcription #', transPk, err)
}
},
getComparisonContent({state, dispatch}) {
state.comparedTranscriptions.forEach(async function(tr, i) {
if (tr != state.selectedTranscription) {
await dispatch('fetchContent', tr)
}
})
},
async getCurrentContent({state, commit, dispatch}, transcription) {
await dispatch('fetchContent', transcription)
commit('lines/updateCurrentTrans', state.selectedTranscription, {root: true})
},
}
export default {
......
......@@ -16,9 +16,7 @@
:read-direction="readDirection"
:block-shortcuts="blockShortcuts"
:opened-panels="openedPanels"
:show="show"
@get-previous="getPrevious"
@get-next="getNext">
:show="show">
</tabcontent>
</div>
</template>
......@@ -47,8 +45,6 @@ export default {
diplomatic: userProfile.get('diplomatic-panel')
},
blockShortcuts: false,
selectedTranscription: null,
comparedTranscriptions: [],
};
},
computed: {
......@@ -80,13 +76,13 @@ export default {
$('#nav-img-tab').attr('href', tabUrl);
}
},
selectedTranscription: function(n, o) {
'$store.state.transcriptions.selectedTranscription': function(n, o) {
let itrans = userProfile.get('initialTranscriptions') || {};
itrans[this.documentId] = n;
userProfile.set('initialTranscriptions', itrans);
this.getCurrentContent(n);
this.$store.dispatch('transcriptions/getCurrentContent', n);
},
comparedTranscriptions: function(n, o) {
'$store.state.transcriptions.comparedTranscriptions': function(n, o) {
n.forEach(async function(tr, i) {
if (!o.find(e=>e==tr)) {
await this.$store.dispatch('transcriptions/fetchContent', tr);
......@@ -113,21 +109,21 @@ export default {
let tr = userProfile.get('initialTranscriptions')
&& userProfile.get('initialTranscriptions')[this.$store.state.parts.documentId]
|| this.$store.state.transcriptions.all[0].pk;
this.selectedTranscription = tr;
this.$store.commit('transcriptions/setSelectedTranscription', tr);
} catch (err) {
console.log('couldnt fetch part data!', err);
}
document.addEventListener('keydown', function(event) {
document.addEventListener('keydown', async function(event) {
if (this.blockShortcuts) return;
if (event.keyCode == 33 || // page up
(event.keyCode == (this.readDirection == 'rtl'?39:37) && event.ctrlKey)) { // arrow left
this.getPrevious();
await this.$store.dispatch('parts/loadPart', 'previous');
event.preventDefault();
} else if (event.keyCode == 34 || // page down
(event.keyCode == (this.readDirection == 'rtl'?37:39) && event.ctrlKey)) { // arrow right
this.getNext();
await this.$store.dispatch('parts/loadPart', 'next');
event.preventDefault();
}
}.bind(this));
......@@ -157,53 +153,7 @@ export default {
if(confirm("Are you sure you want to delete the transcription?")) {
await this.$store.dispatch('transcriptions/archive', transcription)
ev.target.parentNode.remove(); // meh
let compInd = this.comparedTranscriptions.findIndex(e=>e.pk == transcription);
if (compInd != -1) Vue.delete(this.comparedTranscriptions, compInd)
}
},
async getCurrentContent(transcription) {
await this.$store.dispatch('transcriptions/fetchContent', transcription);
this.$store.commit('lines/updateCurrentTrans', this.selectedTranscription);
},
getComparisonContent() {
this.comparedTranscriptions.forEach(async function(tr, i) {
if (tr != this.selectedTranscription) {
await this.$store.dispatch('transcriptions/fetchContent', tr);
}
}.bind(this));
},
async getPrevious(ev) {
if (this.$store.state.parts.loaded && this.$store.state.parts.previous) {
let documentId = this.$store.state.parts.documentId;
let previous = this.$store.state.parts.previous;
this.$store.commit('regions/reset');
this.$store.commit('lines/reset');
this.$store.commit('parts/reset');
this.$store.commit('parts/setDocumentId', documentId);
try {
await this.$store.dispatch('parts/fetchPart', previous);
this.getCurrentContent(this.selectedTranscription);
this.getComparisonContent();
} catch (err) {
console.log('couldnt fetch part data!', err);
}
}
},
async getNext(ev) {
if (this.$store.state.parts.loaded && this.$store.state.parts.next) {
let documentId = this.$store.state.parts.documentId;
let next = this.$store.state.parts.next;
this.$store.commit('regions/reset');
this.$store.commit('lines/reset');
this.$store.commit('parts/reset');
this.$store.commit('parts/setDocumentId', documentId);
try {
await this.$store.dispatch('parts/fetchPart', next);
this.getCurrentContent(this.selectedTranscription);
this.getComparisonContent();
} catch (err) {
console.log('couldnt fetch part data!', err);
}
this.$store.commit('transcriptions/removeComparedTranscription', transcription);
}
},
}
......
......@@ -6,7 +6,7 @@
<span class="loading" v-if="!$store.state.parts.loaded">Loading&#8230;</span>
</div>
<div v-if="$store.state.parts.loaded" class="nav-div nav-item form-inline ml-auto mr-auto">
<select v-model="$parent.selectedTranscription"
<select v-model="$store.state.transcriptions.selectedTranscription"
id="document-transcriptions"
title="Transcription"
class="form-control custom-select">
......@@ -42,11 +42,11 @@
class="inline-form form-check mt-1">
<input type="checkbox" class="form-check-input"
v-bind:id="'opt' + trans.pk"
v-model="$parent.comparedTranscriptions"
v-model="$store.state.transcriptions.comparedTranscriptions"
v-bind:value="trans.pk" />
<label v-bind:for="'opt'+trans.pk"
class="form-check-label col">{{ trans.name }}</label>
<button v-bind:disabled="trans.pk == $parent.selectedTranscription"
<button v-bind:disabled="trans.pk == $store.state.transcriptions.selectedTranscription"
v-bind:data-trPk="trans.pk"
@click="deleteTranscription"
class="btn btn-danger fas fa-trash"
......
......@@ -461,7 +461,7 @@ export default Vue.extend({
region: (l.region && l.region.context.pk) || null,
};
}),
transcription: this.$parent.$parent.selectedTranscription
transcription: this.$store.state.transcriptions.selectedTranscription
})
for (let i = 0; i < newLines.length; i++) {
let line = newLines[i];
......
......@@ -152,11 +152,11 @@ created() {
resetZoom() {
this.zoom.reset();
},
getPrevious(ev) {
this.$emit('get-previous', ev)
async getPrevious(ev) {
await this.$store.dispatch('parts/loadPart', 'previous');
},
getNext(ev) {
this.$emit('get-next', ev)
async getNext(ev) {
await this.$store.dispatch('parts/loadPart', 'next');
},
}
}
......
......@@ -87,7 +87,7 @@
</div>
<!-- transcription comparison -->
<div v-if="$parent.$parent.$parent.comparedTranscriptions.length"
<div v-if="$store.state.transcriptions.comparedTranscriptions.length"
class="card history-block mt-2">
<div class="card-header">
<a href="#"
......@@ -112,7 +112,7 @@
<div class="d-table-cell col" v-html="comparedContent(trans.content)"></div>
<div class="d-table-cell text-muted text-nowrap col" title="Transcription name"><small>
{{ trans.name }}
<span v-if="trans.pk == $parent.$parent.$parent.selectedTranscription">(current)</span></small>
<span v-if="trans.pk == $store.state.transcriptions.selectedTranscription">(current)</span></small>
</div>
</div>
</div>
......@@ -205,7 +205,7 @@ export default Vue.extend({
otherTranscriptions() {
let a = Object
.keys(this.line.transcriptions)
.filter(pk=>this.$parent.$parent.$parent.comparedTranscriptions
.filter(pk=>this.$store.state.transcriptions.comparedTranscriptions
.includes(parseInt(pk)))
.map(pk=>{ return {
pk: pk,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment