Add note to instruments
This commit is contained in:
parent
5200d2165d
commit
d4d2e9934e
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
methods: {
|
||||
hideModal() {
|
||||
this.$store.dispatch('resetCurrentContentBlock');
|
||||
this.$store.dispatch('resetCurrentNoteBlock');
|
||||
this.$store.dispatch('hideModal');
|
||||
},
|
||||
saveContentBlock(contentBlock) {
|
||||
|
|
@ -67,7 +67,7 @@
|
|||
return {
|
||||
query: CONTENT_BLOCK_QUERY,
|
||||
variables: {
|
||||
id: store.state.currentContentBlock
|
||||
id: store.state.currentNoteBlock
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -83,7 +83,8 @@
|
|||
addNote(id) {
|
||||
this.$store.dispatch('addNote', {
|
||||
content: id,
|
||||
contentBlock: this.root
|
||||
type: this.parent.__typename,
|
||||
block: this.root
|
||||
});
|
||||
},
|
||||
editNote() {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@
|
|||
|
||||
import UPDATE_NOTE_MUTATION from '@/graphql/gql/mutations/updateNote.gql';
|
||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
|
||||
import INSTRUMENT_QUERY from '@/graphql/gql/instrumentQuery.gql';
|
||||
|
||||
import {mapGetters} from 'vuex';
|
||||
|
||||
|
|
@ -21,6 +22,9 @@
|
|||
|
||||
methods: {
|
||||
editNote(note) {
|
||||
const slug = this.$route.params.slug;
|
||||
const routeName = this.$route.name;
|
||||
|
||||
this.$apollo.mutate({
|
||||
mutation: UPDATE_NOTE_MUTATION,
|
||||
variables: {
|
||||
|
|
@ -28,12 +32,25 @@
|
|||
note
|
||||
}
|
||||
},
|
||||
refetchQueries: [{
|
||||
query: MODULE_DETAILS_QUERY,
|
||||
variables: {
|
||||
slug: this.$route.params.slug
|
||||
refetchQueries() {
|
||||
let query;
|
||||
if (routeName === 'instrument') {
|
||||
query = {
|
||||
query: INSTRUMENT_QUERY,
|
||||
variables: {
|
||||
slug
|
||||
}
|
||||
}
|
||||
} else {
|
||||
query = {
|
||||
query: MODULE_DETAILS_QUERY,
|
||||
variables: {
|
||||
slug
|
||||
}
|
||||
}
|
||||
}
|
||||
}]
|
||||
return [query];
|
||||
}
|
||||
}).then(() => {
|
||||
this.$store.dispatch('hideModal');
|
||||
});
|
||||
|
|
|
|||
|
|
@ -20,21 +20,23 @@
|
|||
},
|
||||
|
||||
computed: {
|
||||
...mapGetters(['currentContent', 'currentContentBlock', 'currentNoteParent'])
|
||||
...mapGetters(['currentContent', 'currentNoteBlock', 'currentNoteParent', 'noteType'])
|
||||
},
|
||||
|
||||
methods: {
|
||||
addNote(n) {
|
||||
const content = this.currentContent;
|
||||
const contentBlock = this.currentContentBlock;
|
||||
const block = this.currentNoteBlock;
|
||||
const parent = this.currentNoteParent;
|
||||
const type = this.noteType;
|
||||
const text = n.text;
|
||||
let note = {};
|
||||
if (content > '') {
|
||||
note = {
|
||||
content,
|
||||
contentBlock,
|
||||
text
|
||||
block,
|
||||
text,
|
||||
type
|
||||
}
|
||||
} else {
|
||||
note = {
|
||||
|
|
|
|||
|
|
@ -2,41 +2,71 @@ import ADD_NOTE_MUTATION from '@/graphql/gql/mutations/addNote.gql';
|
|||
import CONTENT_BLOCK_QUERY from '@/graphql/gql/contentBlockQuery.gql';
|
||||
import CHAPTER_QUERY from '@/graphql/gql/chapterQuery.gql';
|
||||
import MODULE_QUERY from '@/graphql/gql/moduleByIdQuery.gql';
|
||||
import INSTRUMENT_FRAGMENT from '@/graphql/gql/fragments/instrumentParts.gql';
|
||||
|
||||
const getBlockType = id => atob(id).split(':')[0]
|
||||
const getBlockType = id => atob(id).split(':')[0];
|
||||
|
||||
export const constructNoteMutation = (n) => {
|
||||
let update = () => {
|
||||
};
|
||||
|
||||
if (n.contentBlock) { // has a content block, so it is a content block bookmark
|
||||
if (n.block) { // has a block, so it is a content block or instrument bookmark
|
||||
update = (store, {data: {addNote: {note}}}) => {
|
||||
const query = CONTENT_BLOCK_QUERY;
|
||||
const variables = {id: n.contentBlock};
|
||||
const data = store.readQuery({
|
||||
query,
|
||||
variables
|
||||
});
|
||||
if (n.type === 'ContentBlockNode') {
|
||||
const query = CONTENT_BLOCK_QUERY;
|
||||
const variables = {id: n.block};
|
||||
const data = store.readQuery({
|
||||
query,
|
||||
variables
|
||||
});
|
||||
|
||||
const bookmarks = data.contentBlock.bookmarks;
|
||||
const bookmarks = data.contentBlock.bookmarks;
|
||||
|
||||
let index = bookmarks.findIndex(element => {
|
||||
return element.uuid === n.content;
|
||||
});
|
||||
let index = bookmarks.findIndex(element => {
|
||||
return element.uuid === n.content;
|
||||
});
|
||||
|
||||
if (index > -1) {
|
||||
let el = bookmarks[index];
|
||||
el.note = note;
|
||||
bookmarks.splice(index, 1, el);
|
||||
if (index > -1) {
|
||||
let el = bookmarks[index];
|
||||
el.note = note;
|
||||
bookmarks.splice(index, 1, el);
|
||||
}
|
||||
|
||||
data.contentBlock.bookmarks = bookmarks;
|
||||
|
||||
store.writeQuery({
|
||||
data,
|
||||
query,
|
||||
variables
|
||||
});
|
||||
} else {
|
||||
const fragment = INSTRUMENT_FRAGMENT;
|
||||
const id = `InstrumentNode:${n.block}`;
|
||||
const data = store.readFragment({
|
||||
fragment,
|
||||
id
|
||||
});
|
||||
|
||||
const bookmarks = data.bookmarks;
|
||||
|
||||
let index = bookmarks.findIndex(element => {
|
||||
return element.uuid === n.content;
|
||||
});
|
||||
|
||||
if (index > -1) {
|
||||
let el = bookmarks[index];
|
||||
el.note = note;
|
||||
bookmarks.splice(index, 1, el);
|
||||
}
|
||||
|
||||
data.bookmarks = bookmarks;
|
||||
|
||||
store.writeFragment({
|
||||
data,
|
||||
fragment,
|
||||
id
|
||||
});
|
||||
}
|
||||
|
||||
data.contentBlock.bookmarks = bookmarks;
|
||||
|
||||
store.writeQuery({
|
||||
data,
|
||||
query,
|
||||
variables
|
||||
});
|
||||
};
|
||||
} else { // it's a chapter bookmark or a module bookmark
|
||||
update = (store, {data: {addNote: {note}}}) => {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,8 @@ export default new Vuex.Store({
|
|||
contentBlockPosition: {},
|
||||
scrollPosition: 0,
|
||||
currentContent: '',
|
||||
currentContentBlock: '',
|
||||
currentNoteBlock: '',
|
||||
noteType: '',
|
||||
currentRoomEntry: '',
|
||||
parentRoom: null,
|
||||
parentModule: '',
|
||||
|
|
@ -46,9 +47,10 @@ export default new Vuex.Store({
|
|||
editModule: state => state.editModule,
|
||||
currentObjectiveGroup: state => state.currentObjectiveGroup,
|
||||
currentContent: state => state.currentContent,
|
||||
currentContentBlock: state => state.currentContentBlock,
|
||||
currentNoteBlock: state => state.currentNoteBlock,
|
||||
currentNote: state => state.currentNote,
|
||||
currentNoteParent: state => state.currentNoteParent,
|
||||
noteType: state => state.noteType,
|
||||
},
|
||||
|
||||
actions: {
|
||||
|
|
@ -63,7 +65,7 @@ export default new Vuex.Store({
|
|||
resetModalState({commit}) {
|
||||
commit('setCurrentRoomEntry', '');
|
||||
commit('setCurrentContent', '');
|
||||
commit('setCurrentContentBlock', '');
|
||||
commit('setCurrentNoteBlock', '');
|
||||
commit('setCurrentNoteParent', '');
|
||||
commit('setContentBlockPosition', {});
|
||||
commit('setParentRoom', null);
|
||||
|
|
@ -80,15 +82,16 @@ export default new Vuex.Store({
|
|||
});
|
||||
commit('setVimeoId', null);
|
||||
commit('setCurrentNote', null);
|
||||
commit('setNoteType', '');
|
||||
},
|
||||
resetContentBlockPosition({commit}) {
|
||||
commit('setContentBlockPosition', {});
|
||||
},
|
||||
resetCurrentContentBlock({commit}) {
|
||||
commit('setCurrentContentBlock', '');
|
||||
resetCurrentNoteBlock({commit}) {
|
||||
commit('setCurrentNoteBlock', '');
|
||||
},
|
||||
editContentBlock({commit, dispatch}, payload) {
|
||||
commit('setCurrentContentBlock', payload);
|
||||
commit('setCurrentNoteBlock', payload);
|
||||
dispatch('showModal', 'edit-content-block-wizard');
|
||||
},
|
||||
addContentBlock({commit, dispatch}, payload) {
|
||||
|
|
@ -130,8 +133,9 @@ export default new Vuex.Store({
|
|||
dispatch('showModal', 'edit-project-entry-wizard');
|
||||
},
|
||||
addNote({commit, dispatch}, payload) {
|
||||
if (payload.contentBlock) {
|
||||
commit('setCurrentContentBlock', payload.contentBlock);
|
||||
if (payload.block) {
|
||||
commit('setCurrentNoteBlock', payload.block);
|
||||
commit('setNoteType', payload.type);
|
||||
commit('setCurrentContent', payload.content);
|
||||
} else {
|
||||
commit('setCurrentNoteParent', payload.parent);
|
||||
|
|
@ -197,8 +201,8 @@ export default new Vuex.Store({
|
|||
setCurrentContent(state, payload) {
|
||||
state.currentContent = payload;
|
||||
},
|
||||
setCurrentContentBlock(state, payload) {
|
||||
state.currentContentBlock = payload;
|
||||
setCurrentNoteBlock(state, payload) {
|
||||
state.currentNoteBlock = payload;
|
||||
},
|
||||
setParentRoom(state, payload) {
|
||||
state.parentRoom = payload;
|
||||
|
|
@ -251,6 +255,9 @@ export default new Vuex.Store({
|
|||
},
|
||||
setCurrentNoteParent(state, payload) {
|
||||
state.currentNoteParent = payload;
|
||||
},
|
||||
setNoteType(state, payload) {
|
||||
state.noteType = payload;
|
||||
}
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue