From bcb1db4f205d76f2b1fc5c8d7f3bc8608dc73c28 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Fri, 1 Dec 2017 22:05:14 +0100
Subject: [PATCH] Submitted feedback is now stored inside the store

---
 .../submission_notes/AnnotatedSubmission.vue  | 12 +++++++++--
 .../submission_notes/FeedbackComment.vue      |  5 ++---
 .../submission_notes/FeedbackForm.vue         | 21 +++++++++++++++----
 .../src/store/modules/submission-notes.js     |  4 ++--
 4 files changed, 31 insertions(+), 11 deletions(-)

diff --git a/frontend/src/components/submission_notes/AnnotatedSubmission.vue b/frontend/src/components/submission_notes/AnnotatedSubmission.vue
index ca41a231..6b7d35d8 100644
--- a/frontend/src/components/submission_notes/AnnotatedSubmission.vue
+++ b/frontend/src/components/submission_notes/AnnotatedSubmission.vue
@@ -9,8 +9,16 @@
       </td>
       <td>
         <pre class="prettyprint"><code class="lang-c"> {{ code }}</code></pre>
-        <feedback-comment v-if="feedback[index] && !showEditorOnLine[index]" :feedback="feedback[index]"></feedback-comment>
-        <comment-form v-if="showEditorOnLine[index]" :feedback="feedback[index]"></comment-form>
+        <feedback-comment
+          v-if="feedback[index] && !showEditorOnLine[index]"
+          @click="toggleEditorOnLine(index)">{{ feedback[index] }}
+        </feedback-comment>
+        <comment-form
+          v-if="showEditorOnLine[index]"
+          @collapseFeedbackForm="showEditorOnLine[index] = false"
+          :feedback="feedback[index]"
+          :index="index">
+        </comment-form>
       </td>
     </tr>
   </table>
diff --git a/frontend/src/components/submission_notes/FeedbackComment.vue b/frontend/src/components/submission_notes/FeedbackComment.vue
index 87d5da6a..a63b4de6 100644
--- a/frontend/src/components/submission_notes/FeedbackComment.vue
+++ b/frontend/src/components/submission_notes/FeedbackComment.vue
@@ -3,7 +3,7 @@
     <div class="body">
       <span class="tip tip-up"></span>
       <div class="message">
-        <span>{{ feedback }}</span>
+        <slot></slot>
       </div>
     </div>
   </div>
@@ -12,8 +12,7 @@
 
 <script>
   export default {
-    name: 'feedback-comment',
-    props: ['feedback']
+    name: 'feedback-comment'
   }
 </script>
 
diff --git a/frontend/src/components/submission_notes/FeedbackForm.vue b/frontend/src/components/submission_notes/FeedbackForm.vue
index f5daf4f7..7813c0be 100644
--- a/frontend/src/components/submission_notes/FeedbackForm.vue
+++ b/frontend/src/components/submission_notes/FeedbackForm.vue
@@ -4,14 +4,16 @@
       name="feedback-input"
       label="Please provide your feedback here"
       v-model="current_feedback"
+      @keyup.enter.ctrl.exact="submitFeedback"
+      @keyup.esc="collapseTextField"
       rows="2"
       textarea
       autofocus
       auto-grow
       hide-details
     ></v-text-field>
-    <v-btn color="success" @click="submitFeedback()">Submit</v-btn>
-    <v-btn>Discard</v-btn>
+    <v-btn color="success" @click="submitFeedback">Submit</v-btn>
+    <v-btn @click="discardFeedback">Discard changes</v-btn>
   </div>
 </template>
 
@@ -19,15 +21,26 @@
 <script>
   export default {
     name: 'comment-form',
-    props: ['feedback'],
+    props: ['feedback', 'index'],
     data () {
       return {
         current_feedback: this.feedback
       }
     },
     methods: {
+
+      collapseTextField () {
+        this.$emit('collapseFeedbackForm')
+      },
       submitFeedback () {
-        console.log(this.current_feedback)
+        this.$store.dispatch('updateFeedback', {
+          lineIndex: this.index,
+          content: this.current_feedback
+        })
+        this.collapseTextField()
+      },
+      discardFeedback () {
+        this.current_feedback = this.feedback
       }
     }
   }
diff --git a/frontend/src/store/modules/submission-notes.js b/frontend/src/store/modules/submission-notes.js
index 3c1e7633..cde09fa0 100644
--- a/frontend/src/store/modules/submission-notes.js
+++ b/frontend/src/store/modules/submission-notes.js
@@ -55,8 +55,8 @@ const submissionNotes = {
     'SET_FEEDBACK': function (state, feedback) {
       state.feedback = feedback
     },
-    'UPDATE_FEEDBACK': function (state, lineIndex, feedbackContent) {
-      Vue.set(state.feedback, lineIndex, feedbackContent)
+    'UPDATE_FEEDBACK': function (state, feedback) {
+      Vue.set(state.feedback, feedback.lineIndex, feedback.content)
     }
   },
   actions: {
-- 
GitLab