From 8420d8aab1be052379e47815d02e0877be873c08 Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Tue, 2 Oct 2018 17:54:04 +0200 Subject: [PATCH] upload documents in user assignment --- .../content-blocks/assignment/Assignment.vue | 42 ++++++++++++------- .../graphql/gql/fragments/assignmentParts.gql | 1 + server/assignments/schema/inputs.py | 1 + server/assignments/schema/mutations.py | 5 ++- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/client/src/components/content-blocks/assignment/Assignment.vue b/client/src/components/content-blocks/assignment/Assignment.vue index 60316b30..915999ee 100644 --- a/client/src/components/content-blocks/assignment/Assignment.vue +++ b/client/src/components/content-blocks/assignment/Assignment.vue @@ -34,7 +34,8 @@
- File Input goes here +

{{assignment.submission.document}}

+
@@ -51,7 +52,8 @@ import ASSIGNMENT_QUERY from '@/graphql/gql/assignmentQuery.gql'; import UPDATE_ASSIGNMENT_MUTATION from '@/graphql/gql/mutations/updateAssignmentMutation.gql'; import UPDATE_ASSIGNMENT_MUTATION_WITH_SUCCESS from '@/graphql/gql/mutations/updateAssignmentMutationWithSuccess.gql'; - import debounce from 'debounce'; + import debounce from 'lodash/debounce'; + import cloneDeep from 'lodash/cloneDeep' import FinalSubmission from '@/components/content-blocks/assignment/FinalSubmission'; import SubmissionForm from '@/components/content-blocks/assignment/SubmissionForm'; @@ -74,14 +76,15 @@ }, methods: { - _save: debounce(function (answer) { + _save: debounce(function () { this.$apollo.mutate({ mutation: UPDATE_ASSIGNMENT_MUTATION_WITH_SUCCESS, variables: { input: { assignment: { id: this.assignment.id, - answer: answer + answer: this.assignment.submission.text, + document: this.assignment.submission.document, } } } @@ -95,13 +98,12 @@ We update the assignment on this component, so the changes are reflected on it. The server does not return the updated entity, to prevent the UI to update when the user is entering his input */ - this.assignment = Object.assign({}, this.assignment, { - submission: { - ...this.submission, - text: answer - } - }); - this._save(answer); + this.assignment.submission.text = answer; + this._save(); + }, + documentTestClick() { + this.assignment.submission.document = 'https://google.ch'; + this._save(); }, turnIn() { this.$apollo.mutate({ @@ -116,6 +118,13 @@ } } }); + }, + initialSubmission() { + return { + text: '', + document: '', + final: false, + } } }, @@ -127,21 +136,22 @@ id: this.value.id } }, + result ({ data }) { + this.assignment = cloneDeep(data.assignment); + this.assignment.submission = Object.assign(this.initialSubmission(), this.assignment.submission); + } }, }, data() { return { assignment: { - submission: { - text: '', - final: false - } + submission: this.initialSubmission(), }, inputType: 'text', unsaved: false } - } + }, } diff --git a/client/src/graphql/gql/fragments/assignmentParts.gql b/client/src/graphql/gql/fragments/assignmentParts.gql index de821f19..5bce3806 100644 --- a/client/src/graphql/gql/fragments/assignmentParts.gql +++ b/client/src/graphql/gql/fragments/assignmentParts.gql @@ -6,5 +6,6 @@ fragment AssignmentParts on AssignmentNode { id text final + document } } diff --git a/server/assignments/schema/inputs.py b/server/assignments/schema/inputs.py index 7e4338bd..85ae96c3 100644 --- a/server/assignments/schema/inputs.py +++ b/server/assignments/schema/inputs.py @@ -5,4 +5,5 @@ from graphene import InputObjectType class AssignmentInput(InputObjectType): id = graphene.ID(required=True) answer = graphene.String(required=True) + document = graphene.String() final = graphene.Boolean() diff --git a/server/assignments/schema/mutations.py b/server/assignments/schema/mutations.py index cbd54f5c..91163f11 100644 --- a/server/assignments/schema/mutations.py +++ b/server/assignments/schema/mutations.py @@ -1,5 +1,5 @@ -from graphene import relay import graphene +from graphene import relay from api.utils import get_object from assignments.models import Assignment @@ -20,7 +20,8 @@ class UpdateAssignment(relay.ClientIDMutation): assignment_data = kwargs.get('assignment') assignment = get_object(Assignment, assignment_data.get('id')) (submission, created) = assignment.submissions.get_or_create(student=info.context.user) - submission.text = assignment_data.get('answer') + submission.text = assignment_data.get('answer', '') + submission.document = assignment_data.get('document', '') final = assignment_data.get('final') if final is not None: submission.final = final