From 8b60c62cf08da2fff92dca95e12e680ae7bd11f8 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Tue, 28 Nov 2017 22:58:24 +0100
Subject: [PATCH] More work on submission-notes

Started work on structuring the vuex store into modules
---
 frontend/config/index.js                      |  2 +-
 .../submission_notes/AnnotatedSubmission.vue  | 15 +++++++++------
 .../src/store/modules/submission_notes.js     |  7 +++++++
 frontend/src/store/store.js                   | 19 +++++++++----------
 4 files changed, 26 insertions(+), 17 deletions(-)

diff --git a/frontend/config/index.js b/frontend/config/index.js
index 2c458f66..91cda89e 100644
--- a/frontend/config/index.js
+++ b/frontend/config/index.js
@@ -17,7 +17,7 @@ module.exports = {
     // Surge or Netlify already gzip all static assets for you.
     // Before setting to `true`, make sure to:
     // npm install --save-dev compression-webpack-plugin
-    productionGzip: false,
+    productionGzip: true,
     productionGzipExtensions: ['js', 'css'],
     // Run the build command with an extra argument to
     // View the bundle analyzer report after build finishes:
diff --git a/frontend/src/components/submission_notes/AnnotatedSubmission.vue b/frontend/src/components/submission_notes/AnnotatedSubmission.vue
index e0af89e5..5ecb1262 100644
--- a/frontend/src/components/submission_notes/AnnotatedSubmission.vue
+++ b/frontend/src/components/submission_notes/AnnotatedSubmission.vue
@@ -1,16 +1,16 @@
 <template>
   <table>
-    <tr v-for="line in submission">
+    <tr v-for="(code, index) in submission" :key="index">
       <td class="line-number-cell">
         <v-tooltip left close-delay="20" color="transparent" content-class="comment-icon">
-          <v-btn block class="line-number-btn" slot="activator" @click="toggleEditorOnLine(line[1])">{{ line[1] }}</v-btn>
+          <v-btn block class="line-number-btn" slot="activator" @click="toggleEditorOnLine(index)">{{ index }}</v-btn>
           <v-icon small color="indigo accent-3" class="comment-icon">fa-comment</v-icon>
         </v-tooltip>
       </td>
       <td>
-        <pre class="prettyprint"><code class="lang-c"> {{ line[0] }}</code></pre>
-        <feedback-comment v-if="feedback[line[1]] && !showEditorOnLine[line[1]]" :feedback="feedback[line[1]]"></feedback-comment>
-        <comment-form v-if="showEditorOnLine[line[1]]" :feedback="feedback[line[1]]"></comment-form>
+        <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>
       </td>
     </tr>
   </table>
@@ -28,7 +28,10 @@
     name: 'annotated-submission',
     computed: {
       submission () {
-        return this.source.split('\n').map((line, i) => { return [line, i + 1] })
+        return this.source.split('\n').reduce((acc, cur, index) => {
+          acc[index + 1] = cur
+          return acc
+        }, {})
       }
     },
     data: function () {
diff --git a/frontend/src/store/modules/submission_notes.js b/frontend/src/store/modules/submission_notes.js
index e69de29b..3212a56a 100644
--- a/frontend/src/store/modules/submission_notes.js
+++ b/frontend/src/store/modules/submission_notes.js
@@ -0,0 +1,7 @@
+const submission = {
+  state: {
+    submission: ''
+  }
+}
+
+export default submission
diff --git a/frontend/src/store/store.js b/frontend/src/store/store.js
index 150521a0..d2119b94 100644
--- a/frontend/src/store/store.js
+++ b/frontend/src/store/store.js
@@ -11,10 +11,13 @@ const store = new Vuex.Store({
     username: ''
   },
   mutations: {
-    'LOGIN': function (state, creds) {
-      state.token = creds.token
+    'SET_JWT_TOKEN': function (state, token) {
+      state.token = token
+      ax.defaults.headers.common['Authorization'] = 'JWT ' + state.token
+    },
+    'LOGIN': function (state, credentials) {
+      state.username = credentials.username
       state.loggedIn = true
-      state.username = creds.username
     },
     'LOGOUT': function (state) {
       state.token = ''
@@ -22,16 +25,12 @@ const store = new Vuex.Store({
     }
   },
   actions: {
-    async getToken (store, credentials) {
+    async getToken (context, credentials) {
       const response = await ax.post('api-token-auth/', credentials)
-      store.commit('LOGIN', {
-        token: response.data.token,
+      context.commit('LOGIN', {
         username: credentials.username
       })
-      ax.defaults.headers.common['Authorization'] = 'JWT ' + response.data.token
-    },
-    logout (store) {
-      store.commit('LOGOUT')
+      context.commit('SET_JWT_TOKEN', response.data.token)
     }
   }
 })
-- 
GitLab