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