From c7822341595a7a147619f07de9d52c2a5c90b5d0 Mon Sep 17 00:00:00 2001
From: "robinwilliam.hundt" <robinwilliam.hundt@stud.uni-goettingen.de>
Date: Wed, 15 Aug 2018 14:29:03 +0200
Subject: [PATCH] Fixed final typings/removed WelcomeJumbotron

---
 frontend/src/components/WelcomeJumbotron.vue  | 66 -------------------
 .../feedback_list/FeedbackSearchOptions.vue   |  2 +-
 .../src/pages/reviewer/ReviewerStartPage.vue  |  5 --
 frontend/src/pages/tutor/TutorStartPage.vue   |  5 --
 frontend/src/store/modules/authentication.ts  |  4 +-
 .../modules/feedback_list/feedback-table.ts   |  2 +-
 .../src/store/modules/submission-notes.ts     |  4 +-
 frontend/src/store/modules/subscriptions.ts   | 16 +++--
 frontend/src/store/mutations.ts               |  7 ++
 frontend/src/store/store.ts                   |  4 +-
 10 files changed, 25 insertions(+), 90 deletions(-)
 delete mode 100644 frontend/src/components/WelcomeJumbotron.vue

diff --git a/frontend/src/components/WelcomeJumbotron.vue b/frontend/src/components/WelcomeJumbotron.vue
deleted file mode 100644
index 687274a6..00000000
--- a/frontend/src/components/WelcomeJumbotron.vue
+++ /dev/null
@@ -1,66 +0,0 @@
-<template>
-    <v-jumbotron :gradient="gradient" dark class="elevation-10" v-if="showJumbotron">
-      <v-btn @click="hide" icon class="hide-btn" absolute>
-        <v-icon>
-          close
-        </v-icon>
-      </v-btn>
-      <v-container fill-height>
-        <v-layout align-center>
-          <v-flex>
-            <h1 class="display-2 mb-2 text-xs-center">Grady</h1>
-            <span class="subheading">
-              The intention of this tool is to simplify the exam correcting process at the
-              University of Goettingen. It is deployed as a
-              <a href="http://www.django-rest-framework.org/" target="_blank">Django Rest</a>
-              backend with a <a href="https://vuejs.org/" target="_blank">Vue.js</a> frontend
-              using the awesome <a href="https://next.vuetifyjs.com/en/" target="_blank">Vuetify</a> library.<br/><br/>
-              To get started with correcting just create a subscription by clicking one of the plus signs in the
-              <i>Your subscriptions</i> card.
-              Subscriptions are the mechanism by which the student submissions are distributed.
-            </span>
-            <v-divider class="my-5"></v-divider>
-            <span class="title mx-4">Check out our
-              <a href="https://gitlab.gwdg.de/j.michal/grady" target="_blank">Git!</a></span>
-            <span class="title mx-4">Why the name
-              <a href="https://www.youtube.com/watch?v=VjdgXqKjHvY" target="_blank">Grady?</a></span>
-          </v-flex>
-        </v-layout>
-      </v-container>
-    </v-jumbotron>
-</template>
-
-<script>
-import { createComputedGetterSetter } from '@/util/helpers'
-import { uiMut } from '@/store/modules/ui'
-
-export default {
-  name: 'welcome-jumbotron',
-  data () {
-    return {
-      gradient: 'to bottom, #1A237E, #5753DD'
-    }
-  },
-  computed: {
-    showJumbotron: createComputedGetterSetter({
-      path: 'ui.showJumbotron',
-      mutation: uiMut.SET_SHOW_JUMBOTRON
-    })
-  },
-  methods: {
-    hide () {
-      this.showJumbotron = false
-    }
-  }
-}
-</script>
-
-<style scoped>
-  a {
-    color: lightgrey;
-    text-decoration: none;
-  }
-  .hide-btn {
-    right: 0;
-  }
-</style>
diff --git a/frontend/src/components/feedback_list/FeedbackSearchOptions.vue b/frontend/src/components/feedback_list/FeedbackSearchOptions.vue
index c5ec661f..c2db7e9c 100644
--- a/frontend/src/components/feedback_list/FeedbackSearchOptions.vue
+++ b/frontend/src/components/feedback_list/FeedbackSearchOptions.vue
@@ -116,7 +116,7 @@ export default {
   },
   methods: {
     loadTutors () {
-      if (this.tutors.length === 0) {
+      if (this.tutors.length === 0 && this.isReviewer) {
         this.$store.dispatch('getTutors')
       }
     }
diff --git a/frontend/src/pages/reviewer/ReviewerStartPage.vue b/frontend/src/pages/reviewer/ReviewerStartPage.vue
index c049278d..ec560458 100644
--- a/frontend/src/pages/reviewer/ReviewerStartPage.vue
+++ b/frontend/src/pages/reviewer/ReviewerStartPage.vue
@@ -1,8 +1,5 @@
 <template>
   <div>
-    <v-flex lg6 md10 xs12 mx-auto class="mt-4">
-      <welcome-jumbotron></welcome-jumbotron>
-    </v-flex>
     <v-layout row wrap>
       <v-flex lg5 md9 xs12>
         <correction-statistics class="ma-4"></correction-statistics>
@@ -17,7 +14,6 @@
 
 <script>
 import CorrectionStatistics from '@/components/CorrectionStatistics'
-import WelcomeJumbotron from '@/components/WelcomeJumbotron'
 import SubscriptionList from '@/components/subscriptions/SubscriptionList'
 import SubmissionTypesOverview from '@/components/SubmissionTypesOverview'
 
@@ -25,7 +21,6 @@ export default {
   components: {
     SubmissionTypesOverview,
     SubscriptionList,
-    WelcomeJumbotron,
     CorrectionStatistics},
   name: 'reviewer-start-page'
 }
diff --git a/frontend/src/pages/tutor/TutorStartPage.vue b/frontend/src/pages/tutor/TutorStartPage.vue
index 3d57117c..b782282b 100644
--- a/frontend/src/pages/tutor/TutorStartPage.vue
+++ b/frontend/src/pages/tutor/TutorStartPage.vue
@@ -1,8 +1,5 @@
 <template>
   <div>
-    <v-flex lg6 md10 xs12 mx-auto class="mt-4">
-      <welcome-jumbotron></welcome-jumbotron>
-    </v-flex>
     <v-layout row wrap>
       <v-flex lg5 md9 xs12>
         <correction-statistics class="ma-4"></correction-statistics>
@@ -18,13 +15,11 @@
 <script>
 import SubscriptionList from '@/components/subscriptions/SubscriptionList'
 import CorrectionStatistics from '@/components/CorrectionStatistics'
-import WelcomeJumbotron from '@/components/WelcomeJumbotron'
 import SubmissionTypesOverview from '@/components/SubmissionTypesOverview'
 
 export default {
   components: {
     SubmissionTypesOverview,
-    WelcomeJumbotron,
     CorrectionStatistics,
     SubscriptionList},
   name: 'tutor-start-page'
diff --git a/frontend/src/store/modules/authentication.ts b/frontend/src/store/modules/authentication.ts
index 1b8381f5..34cb5c88 100644
--- a/frontend/src/store/modules/authentication.ts
+++ b/frontend/src/store/modules/authentication.ts
@@ -90,7 +90,7 @@ const authentication: Module<AuthState, any> = {
     async getJWT (context: ActionContext<AuthState, any>, credentials: Credentials) {
       try {
         const token = await api.fetchJWT(credentials)
-        context.commit(authMut.SET_JWT_TOKEN, token)
+        context.commit(authMut.SET_JWT_TOKEN, token.token)
       } catch (error) {
         let errorMsg
         if (!error.response) {
@@ -110,7 +110,7 @@ const authentication: Module<AuthState, any> = {
       commit(authMut.SET_REFRESHING_TOKEN, true)
       try {
         const token = await api.refreshJWT(state.token)
-        commit(authMut.SET_JWT_TOKEN, token)
+        commit(authMut.SET_JWT_TOKEN, token.token)
       } finally {
         commit(authMut.SET_REFRESHING_TOKEN, false)
         commit(authMut.SET_LAST_TOKEN_REFRESH_TRY)
diff --git a/frontend/src/store/modules/feedback_list/feedback-table.ts b/frontend/src/store/modules/feedback_list/feedback-table.ts
index f005582e..02337c19 100644
--- a/frontend/src/store/modules/feedback_list/feedback-table.ts
+++ b/frontend/src/store/modules/feedback_list/feedback-table.ts
@@ -66,7 +66,7 @@ const feedbackTable: Module<FeedbackTableState, RootState> = {
     },
     async getFeedbackHistory ({getters, commit, dispatch}) {
       let data: [Promise<Feedback[]>, Promise<Assignment[]> | undefined] =
-          [fetchAllFeedback(), getters.isReviewer() ? fetchAllAssignments() : undefined]
+          [fetchAllFeedback(), getters.isReviewer ? fetchAllAssignments() : undefined]
 
       Promise.all<Feedback[], Assignment[] | undefined>(data)
         .then(([feedbacks, assignments]: [Feedback[], Assignment[]?]) => {
diff --git a/frontend/src/store/modules/submission-notes.ts b/frontend/src/store/modules/submission-notes.ts
index 32a74341..9a4fe315 100644
--- a/frontend/src/store/modules/submission-notes.ts
+++ b/frontend/src/store/modules/submission-notes.ts
@@ -57,7 +57,7 @@ function initialState (): SubmissionNotesState {
     },
     updatedFeedback: {
       pk: 0,
-      score: 0,
+      score: undefined,
       feedbackLines: {}
     },
     commentsMarkedForDeletion: {}
@@ -86,7 +86,7 @@ const submissionNotes: Module<SubmissionNotesState, RootState> = {
       }, {})
     },
     score: state => {
-      return state.updatedFeedback.score !== null ? state.updatedFeedback.score : state.origFeedback.score
+      return state.updatedFeedback.score !== undefined ? state.updatedFeedback.score : state.origFeedback.score
     },
     workInProgress: state => {
       const openEditor = Object.values(state.ui.showEditorOnLine).reduce((acc, curr) => acc || curr, false)
diff --git a/frontend/src/store/modules/subscriptions.ts b/frontend/src/store/modules/subscriptions.ts
index dab0467f..4888efce 100644
--- a/frontend/src/store/modules/subscriptions.ts
+++ b/frontend/src/store/modules/subscriptions.ts
@@ -35,7 +35,7 @@ function initialState (): SubscriptionsState {
 const MAX_NUMBER_OF_ASSIGNMENTS = 2
 
 // noinspection JSCommentMatchesSignature
-const subscriptions: Module<SubscriptionsState, RootState> = {
+const subscriptionsModule: Module<SubscriptionsState, RootState> = {
   state: initialState(),
   getters: {
     availableTypes (state, getters) {
@@ -93,7 +93,8 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
           'submission_type': []
         }
       }
-      let subscriptionsByStage = getters.availableStages.reduce((acc, curr) => {
+      let subscriptionsByStage = getters.availableStages.reduce((acc: {[p: string]: {[k: string]: Subscription[]}},
+        curr: string) => {
         acc[curr] = subscriptionsByType()
         return acc
       }, {})
@@ -101,7 +102,7 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
         subscriptionsByStage[subscription.feedbackStage][subscription.queryType].push(subscription)
       })
       // sort the resulting arrays in subscriptions lexicographically by their query_keys
-      const sortSubscriptions = subscriptionsByType => Object.values(subscriptionsByType)
+      const sortSubscriptions = (subscriptionsByType: {[k: string]: Subscription[]}) => Object.values(subscriptionsByType)
         .forEach((arr: object[]) => {
           if (arr.length > 1 && arr[0].hasOwnProperty('queryKey')) {
             arr.sort((subA, subB) => {
@@ -117,7 +118,7 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
             })
           }
         })
-      Object.values(subscriptionsByStage).forEach(subscriptionsByType => {
+      Object.values(subscriptionsByStage).forEach((subscriptionsByType: any) => {
         sortSubscriptions(subscriptionsByType)
       })
       return subscriptionsByStage
@@ -166,7 +167,6 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
         commit(subscriptionMuts.SET_SUBSCRIPTION, subscription)
         return subscription
       } catch (err) {
-        console.log(err)
         handleError(err, dispatch, 'Subscribing unsuccessful')
       }
     },
@@ -176,7 +176,6 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
         commit(subscriptionMuts.SET_SUBSCRIPTIONS, subscriptions)
         return subscriptions
       } catch (err) {
-        console.log(err)
         handleError(err, dispatch, 'Unable to fetch subscriptions')
       }
     },
@@ -245,6 +244,7 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
         commit(subscriptionMuts.SET_ACTIVE_SUBSCRIPTION_PK, subscriptionPk)
         let assignmentsPromises = await dispatch('getAssignmentsForActiveSubscription', MAX_NUMBER_OF_ASSIGNMENTS)
         let createdAssignments = []
+        // TODO refactor this since it's very bad to await promises in for loops
         for (let promise of assignmentsPromises) {
           try {
             createdAssignments.push(await promise)
@@ -269,6 +269,7 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
           if (getters.isReviewer) {
             const stageKeyCartesian = cartesian(
               getters.availableStages, getters.availableExamTypeQueryKeys)
+            // @ts-ignore
             return stageKeyCartesian.map(([stage, key]: [string, string]) => {
               dispatch('subscribeTo', {stage, type, key})
             })
@@ -277,6 +278,7 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
         case Subscription.QueryTypeEnum.SubmissionType:
           const stageKeyCartesian = cartesian(
             getters.availableStages, getters.availableSubmissionTypeQueryKeys)
+          // @ts-ignore
           return stageKeyCartesian.map(([stage, key]: [string, string]) => {
             dispatch('subscribeTo', {stage, type, key})
           })
@@ -291,4 +293,4 @@ const subscriptions: Module<SubscriptionsState, RootState> = {
   }
 }
 
-export default subscriptions
+export default subscriptionsModule
diff --git a/frontend/src/store/mutations.ts b/frontend/src/store/mutations.ts
index 8c6f165e..252ead24 100644
--- a/frontend/src/store/mutations.ts
+++ b/frontend/src/store/mutations.ts
@@ -55,6 +55,13 @@ const mutations: MutationTree<RootState> = {
       ...statistics
     }
   },
+  [mut.SET_FEEDBACK] (state, feedback) {
+    Vue.set(state.feedback, feedback.pk, {
+      ...state.feedback[feedback.pk],
+      ...feedback,
+      ofSubmissionType: state.submissionTypes[feedback['ofSubmissionType']]
+    })
+  },
   [mut.UPDATE_SUBMISSION_TYPE] (state, submissionType: SubmissionType) {
     const updatedSubmissionType = {
       ...state.submissionTypes[submissionType.pk],
diff --git a/frontend/src/store/store.ts b/frontend/src/store/store.ts
index 6ab9578e..849519fc 100644
--- a/frontend/src/store/store.ts
+++ b/frontend/src/store/store.ts
@@ -15,7 +15,7 @@ import getters from './getters'
 import mutations from '@/store/mutations'
 import {lastInteraction} from '@/store/plugins/lastInteractionPlugin'
 import {
-  Exam,
+  Exam, Feedback,
   Statistics,
   StudentInfoForListView,
   SubmissionNoType,
@@ -27,6 +27,7 @@ Vue.use(Vuex)
 export interface RootState {
     lastAppInteraction: number
     examTypes: {[pk: string]: Exam}
+    feedback: {[pk: string]: Feedback}
     submissionTypes: {[pk: string]: SubmissionType}
     submissions: {[pk: string]: SubmissionNoType}
     students: {[pk: string]: StudentInfoForListView}
@@ -39,6 +40,7 @@ export function initialState (): RootState {
   return {
     lastAppInteraction: Date.now(),
     examTypes: {},
+    feedback: {},
     submissionTypes: {},
     submissions: {},
     students: {},
-- 
GitLab