Add assignment queries and mutation to client
This commit is contained in:
parent
d35c151cfb
commit
ea9fa06634
|
|
@ -2736,6 +2736,11 @@
|
||||||
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
"resolved": "https://registry.npmjs.org/de-indent/-/de-indent-1.0.2.tgz",
|
||||||
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0="
|
"integrity": "sha1-sgOOhG3DO6pXlhKNCAS0VbjB4h0="
|
||||||
},
|
},
|
||||||
|
"debounce": {
|
||||||
|
"version": "1.2.0",
|
||||||
|
"resolved": "https://registry.npmjs.org/debounce/-/debounce-1.2.0.tgz",
|
||||||
|
"integrity": "sha512-mYtLl1xfZLi1m4RtQYlZgJUNQjl4ZxVnHzIR8nLLgi4q1YT8o/WM+MK/f8yfcc9s5Ir5zRaPZyZU6xs1Syoocg=="
|
||||||
|
},
|
||||||
"debug": {
|
"debug": {
|
||||||
"version": "3.1.0",
|
"version": "3.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/debug/-/debug-3.1.0.tgz",
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
"chalk": "^2.0.1",
|
"chalk": "^2.0.1",
|
||||||
"copy-webpack-plugin": "^4.0.1",
|
"copy-webpack-plugin": "^4.0.1",
|
||||||
"css-loader": "^0.28.0",
|
"css-loader": "^0.28.0",
|
||||||
|
"debounce": "^1.2.0",
|
||||||
"eslint": "^4.15.0",
|
"eslint": "^4.15.0",
|
||||||
"eslint-config-standard": "^10.2.1",
|
"eslint-config-standard": "^10.2.1",
|
||||||
"eslint-friendly-formatter": "^3.0.0",
|
"eslint-friendly-formatter": "^3.0.0",
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,66 @@
|
||||||
<template>
|
<template>
|
||||||
<div class="assignment">
|
<div class="assignment">
|
||||||
<p v-html="value.assignment"></p>
|
{{assignment.title}}
|
||||||
<textarea class="assignment__input" placeholder="Text schreiben"></textarea>
|
<p v-html="assignment.assignment"></p>
|
||||||
|
<textarea
|
||||||
|
class="assignment__input"
|
||||||
|
placeholder="Text schreiben"
|
||||||
|
:value="assignment.submission.text"
|
||||||
|
@input="saveInput"
|
||||||
|
></textarea>
|
||||||
<button class="assignment__submit button">Ergebnis teilen</button>
|
<button class="assignment__submit button">Ergebnis teilen</button>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
|
import ASSIGNMENT_QUERY from '@/graphql/gql/assignmentQuery.gql';
|
||||||
|
import UPDATE_ASSIGNMENT_MUTATION from '@/graphql/gql/mutations/updateAssignmentMutation.gql';
|
||||||
|
import debounce from 'debounce';
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
props: ['value'],
|
props: ['value'],
|
||||||
|
|
||||||
|
computed: {
|
||||||
|
loading() {
|
||||||
|
return this.$apollo.loading;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
methods: {
|
||||||
|
saveInput: debounce(function (event) {
|
||||||
|
this.$apollo.mutate({
|
||||||
|
mutation: UPDATE_ASSIGNMENT_MUTATION,
|
||||||
|
variables: {
|
||||||
|
input: {
|
||||||
|
assignment: {
|
||||||
|
id: this.assignment.id,
|
||||||
|
answer: event.target.value
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}, 500)
|
||||||
|
},
|
||||||
|
|
||||||
|
apollo: {
|
||||||
|
assignment: {
|
||||||
|
query: ASSIGNMENT_QUERY,
|
||||||
|
variables() {
|
||||||
|
return {
|
||||||
|
id: this.value.id
|
||||||
|
}
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
data() {
|
||||||
|
return {
|
||||||
|
assignment: {
|
||||||
|
submission: {
|
||||||
|
text: ''
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
|
||||||
|
|
@ -41,7 +41,8 @@ const composedLink = ApolloLink.from([createOmitTypenameLink, consoleLink, httpL
|
||||||
const cache = new InMemoryCache({
|
const cache = new InMemoryCache({
|
||||||
cacheRedirects: {
|
cacheRedirects: {
|
||||||
Query: {
|
Query: {
|
||||||
contentBlock: (_, args, {getCacheKey}) => getCacheKey({__typename: 'ContentBlockNode', id: args.id})
|
contentBlock: (_, args, {getCacheKey}) => getCacheKey({__typename: 'ContentBlockNode', id: args.id}),
|
||||||
|
assignment: (_, args, {getCacheKey}) => getCacheKey({__typename: 'AssignmentNode', id: args.id})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,6 @@
|
||||||
|
#import "./fragments/assignmentParts.gql"
|
||||||
|
query AssignmentQuery($id: ID!) {
|
||||||
|
assignment(id: $id) {
|
||||||
|
...AssignmentParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
#import "./fragments/assignmentParts.gql"
|
||||||
|
query AssignmentsQuery {
|
||||||
|
assignments {
|
||||||
|
edges {
|
||||||
|
node {
|
||||||
|
...AssignmentParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,10 @@
|
||||||
|
fragment AssignmentParts on AssignmentNode {
|
||||||
|
id
|
||||||
|
title
|
||||||
|
assignment
|
||||||
|
submission {
|
||||||
|
id
|
||||||
|
text
|
||||||
|
final
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,8 @@
|
||||||
|
#import "../fragments/assignmentParts.gql"
|
||||||
|
mutation UpdateAssignment($input: UpdateAssignmentInput!) {
|
||||||
|
updateAssignment(input: $input){
|
||||||
|
updatedAssignment {
|
||||||
|
...AssignmentParts
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -10,20 +10,20 @@ import router from './router'
|
||||||
import store from '@/store/index'
|
import store from '@/store/index'
|
||||||
import VueScrollTo from 'vue-scrollto';
|
import VueScrollTo from 'vue-scrollto';
|
||||||
|
|
||||||
Vue.config.productionTip = false
|
Vue.config.productionTip = false;
|
||||||
|
|
||||||
// TODO: Move into a separate project as a plugin
|
// TODO: Move into a separate project as a plugin
|
||||||
//
|
//
|
||||||
function getRidOfEdges(collection) {
|
function getRidOfEdges(collection) {
|
||||||
if (typeof collection === 'object' && collection && !Array.isArray(collection)) {
|
if (typeof collection === 'object' && collection && !Array.isArray(collection)) {
|
||||||
let newObj = {}
|
let newObj = {};
|
||||||
for (const k in collection) {
|
for (const k in collection) {
|
||||||
if (k === 'edges') {
|
if (k === 'edges') {
|
||||||
return collection.edges.map(edge => getRidOfEdges(edge.node));
|
return collection.edges.map(edge => getRidOfEdges(edge.node));
|
||||||
} else {
|
} else {
|
||||||
newObj[k] = getRidOfEdges(collection[k])
|
newObj[k] = getRidOfEdges(collection[k]);
|
||||||
if (newObj[k]) {
|
if (newObj[k]) {
|
||||||
delete newObj[k]['__typename']
|
// delete newObj[k]['__typename']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -33,21 +33,21 @@ function getRidOfEdges(collection) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Object.defineProperty(Vue.prototype, '$getRidOfEdges', {value: getRidOfEdges})
|
Object.defineProperty(Vue.prototype, '$getRidOfEdges', {value: getRidOfEdges});
|
||||||
|
|
||||||
Vue.use(VueApollo)
|
Vue.use(VueApollo);
|
||||||
Vue.use(VueAxios, axios)
|
Vue.use(VueAxios, axios);
|
||||||
Vue.use(VueVimeoPlayer)
|
Vue.use(VueVimeoPlayer);
|
||||||
|
|
||||||
Vue.use(VueScrollTo, {
|
Vue.use(VueScrollTo, {
|
||||||
duration: 500,
|
duration: 500,
|
||||||
easing: 'ease-out',
|
easing: 'ease-out',
|
||||||
offset: -50
|
offset: -50
|
||||||
})
|
});
|
||||||
|
|
||||||
const apolloProvider = new VueApollo({
|
const apolloProvider = new VueApollo({
|
||||||
defaultClient: apolloClient
|
defaultClient: apolloClient
|
||||||
})
|
});
|
||||||
|
|
||||||
/* eslint-disable no-new */
|
/* eslint-disable no-new */
|
||||||
new Vue({
|
new Vue({
|
||||||
|
|
@ -56,4 +56,4 @@ new Vue({
|
||||||
router,
|
router,
|
||||||
provide: apolloProvider.provide(),
|
provide: apolloProvider.provide(),
|
||||||
render: h => h(App)
|
render: h => h(App)
|
||||||
})
|
});
|
||||||
|
|
|
||||||
|
|
@ -9,6 +9,7 @@
|
||||||
import store from '@/store/index';
|
import store from '@/store/index';
|
||||||
|
|
||||||
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
|
import MODULE_DETAILS_QUERY from '@/graphql/gql/moduleDetailsQuery.gql';
|
||||||
|
import ASSIGNMENTS_QUERY from '@/graphql/gql/assignmentsQuery.gql';
|
||||||
|
|
||||||
import Module from '@/components/modules/Module.vue';
|
import Module from '@/components/modules/Module.vue';
|
||||||
import ModuleNavigation from '@/components/modules/ModuleNavigation.vue';
|
import ModuleNavigation from '@/components/modules/ModuleNavigation.vue';
|
||||||
|
|
@ -20,30 +21,25 @@
|
||||||
},
|
},
|
||||||
|
|
||||||
apollo: {
|
apollo: {
|
||||||
module() {
|
module: {
|
||||||
return {
|
query: MODULE_DETAILS_QUERY,
|
||||||
query: MODULE_DETAILS_QUERY,
|
variables: {
|
||||||
variables: {
|
slug: store.state.moduleSlug
|
||||||
slug: store.state.moduleSlug
|
},
|
||||||
},
|
update(data) {
|
||||||
update(data) {
|
const cleanedData = this.$getRidOfEdges(data);
|
||||||
const cleanedData = this.$getRidOfEdges(data);
|
return cleanedData.module || {};
|
||||||
return cleanedData.module || {};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
},
|
||||||
|
assignments: {
|
||||||
|
query: ASSIGNMENTS_QUERY
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
data() {
|
data() {
|
||||||
return {
|
return {
|
||||||
module: {
|
module: {},
|
||||||
objectiveGroups: {
|
assignments: []
|
||||||
edges: {}
|
|
||||||
},
|
|
||||||
chapters: {
|
|
||||||
edges: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue