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

Rename state attribute/mutations/actions in 'transcriptions' store

parent b571ed97
......@@ -42,13 +42,13 @@ export const actions = {
async fetchDocument ({state, commit}) {
const resp = await api.retrieveDocument(state.documentId)
let data = resp.data
commit('transcriptions/setTranscriptions', data.transcriptions, {root: true})
commit('transcriptions/set', data.transcriptions, {root: true})
commit('setTypes', { 'regions': data.valid_block_types, 'lines': data.valid_line_types })
},
async fetchPart ({state, commit, dispatch, rootState}, pk) {
commit('setPartPk', pk)
if (!rootState.transcriptions.transcriptions.length) {
if (!rootState.transcriptions.all.length) {
await dispatch('fetchDocument', state.documentId)
}
const resp = await api.retrieveDocumentPart(state.documentId, pk)
......
......@@ -2,17 +2,17 @@ import { assign } from 'lodash'
import * as api from '../api'
export const initialState = () => ({
transcriptions: []
all: []
})
export const mutations = {
setTranscriptions (state, transcriptions) {
assign(state.transcriptions, transcriptions)
set (state, transcriptions) {
assign(state.all, transcriptions)
},
removeTranscription (state, pk) {
let index = state.transcriptions.findIndex(t=>t.pk==pk)
remove (state, pk) {
let index = state.all.findIndex(t=>t.pk==pk)
if (index < 0) return
Vue.delete(state.transcriptions, index)
Vue.delete(state.all, index)
},
reset (state) {
assign(state, initialState())
......@@ -20,7 +20,7 @@ export const mutations = {
}
export const actions = {
async bulkCreateLineTranscriptions({commit, rootState}, transcriptions) {
async bulkCreate({commit, rootState}, transcriptions) {
let data = transcriptions.map(l=>{
return {
line : l.line,
......@@ -38,7 +38,7 @@ export const actions = {
}
},
async bulkUpdateLineTranscriptions({rootState}, transcriptions) {
async bulkUpdate({rootState}, transcriptions) {
let data = transcriptions.map(l => {
return {
pk: l.pk,
......@@ -119,10 +119,10 @@ export const actions = {
}
},
async archiveTranscription({commit, rootState}, transPk) {
async archive({commit, rootState}, transPk) {
try {
await api.archiveTranscription(rootState.parts.documentId, transPk)
commit('removeTranscription', transPk)
commit('remove', transPk)
} catch (err) {
console.log('couldnt archive transcription #', transPk, err)
}
......
......@@ -291,13 +291,13 @@ export default BasePanel.extend({
async bulkUpdate() {
if(this.updatedLines.length){
await this.$store.dispatch('transcriptions/bulkUpdateLineTranscriptions', this.updatedLines);
await this.$store.dispatch('transcriptions/bulkUpdate', this.updatedLines);
this.updatedLines = [];
}
},
async bulkCreate() {
if(this.createdLines.length){
await this.$store.dispatch('transcriptions/bulkCreateLineTranscriptions', this.createdLines);
await this.$store.dispatch('transcriptions/bulkCreate', this.createdLines);
this.createdLines = [];
}
},
......
......@@ -112,7 +112,7 @@ export default {
await this.$store.dispatch('parts/fetchPart', this.partId);
let tr = userProfile.get('initialTranscriptions')
&& userProfile.get('initialTranscriptions')[this.$store.state.parts.documentId]
|| this.$store.state.transcriptions.transcriptions[0].pk;
|| this.$store.state.transcriptions.all[0].pk;
this.selectedTranscription = tr;
} catch (err) {
console.log('couldnt fetch part data!', err);
......@@ -155,7 +155,7 @@ export default {
let transcription = ev.target.dataset.trpk;
// I lied, it's only archived
if(confirm("Are you sure you want to delete the transcription?")) {
await this.$store.dispatch('transcriptions/archiveTranscription', 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)
......
......@@ -10,7 +10,7 @@
id="document-transcriptions"
title="Transcription"
class="form-control custom-select">
<option v-for="transcription in $store.state.transcriptions.transcriptions"
<option v-for="transcription in $store.state.transcriptions.all"
v-bind:key="transcription.pk"
v-bind:value="transcription.pk">{{ transcription.name }}</option>
</select>
......@@ -36,7 +36,7 @@
<span>Compare</span>
<span class="float-right">Delete</span>
</div>
<div v-for="trans in $store.state.transcriptions.transcriptions"
<div v-for="trans in $store.state.transcriptions.all"
v-bind="trans"
v-bind:key="trans.pk"
class="inline-form form-check mt-1">
......
......@@ -207,7 +207,7 @@ export default Vue.extend({
.includes(parseInt(pk)))
.map(pk=>{ return {
pk: pk,
name: this.$store.state.transcriptions.transcriptions.find(e=>e.pk==pk).name,
name: this.$store.state.transcriptions.all.find(e=>e.pk==pk).name,
content: this.line.transcriptions[pk].content
}; });
return a;
......
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