diff --git a/frontend/src/api.ts b/frontend/src/api.ts index 3d026051f6280622f3d4b1c7b830178da7580eae..fbc5f1d58555daf087f6a9c90a0d5a97a7dfac57 100644 --- a/frontend/src/api.ts +++ b/frontend/src/api.ts @@ -13,10 +13,6 @@ import { Tutor, UserAccount } from '@/models' -function addFieldsToUrl ({url, fields = []}: {url: string, fields?: string[]}): string { - return fields.length > 0 ? url + '?fields=pk,' + fields : url -} - function getInstanceBaseUrl (): string { if (process.env.NODE_ENV === 'production') { return `https://${window.location.host}${window.location.pathname}` @@ -46,7 +42,7 @@ export async function fetchJWT (credentials: Credentials): Promise<JSONWebToken> } export async function refreshJWT (oldToken: string): Promise<JSONWebToken> { - const token: string = (await ax.post('/api/refresh-token/', {oldToken})).data.token + const token: string = (await ax.post('/api/refresh-token/', {token: oldToken})).data.token ax.defaults.headers['Authorization'] = `JWT ${token}` return {token} } @@ -67,28 +63,19 @@ export async function fetchSubmissionFeedbackTests ({pk}: {pk: string}): Promise return (await ax.get(`/api/submission/${pk}/`)).data } -export async function fetchAllStudents (fields: string[] = []): Promise<Array<StudentInfoForListView>> { - const url = addFieldsToUrl({ - url: '/api/student/', - fields - }) +export async function fetchAllStudents (): Promise<Array<StudentInfoForListView>> { + const url = '/api/student/' return (await ax.get(url)).data } -export async function fetchStudent ({pk, fields = []}: -{pk: string, fields?: string[]}): Promise<StudentInfoForListView> { - const url = addFieldsToUrl({ - url: `/api/student/${pk}/`, - fields - }) +export async function fetchStudent ({pk, }: +{pk: string}): Promise<StudentInfoForListView> { + const url = `/api/student/${pk}/` return (await ax.get(url)).data } -export async function fetchAllTutors (fields: string[] = []): Promise<Array<Tutor>> { - const url = addFieldsToUrl({ - url: '/api/tutor/', - fields - }) +export async function fetchAllTutors (): Promise<Array<Tutor>> { + const url = '/api/tutor/' return (await ax.get(url)).data } @@ -105,11 +92,8 @@ export async function fetchSubscription (subscriptionPk: string): Promise<Subscr return (await ax.get(`/api/subscription/${subscriptionPk}/`)).data } -export async function fetchAllFeedback (fields: string[] = []): Promise<Array<Feedback>> { - const url = addFieldsToUrl({ - url: '/api/feedback/', - fields - }) +export async function fetchAllFeedback (): Promise<Array<Feedback>> { + const url = '/api/feedback/' return (await ax.get(url)).data } @@ -118,19 +102,13 @@ export async function fetchFeedback ({ofSubmission}: {ofSubmission: string}): Pr return (await ax.get(url)).data } -export async function fetchExamTypes ({fields = []}: -{fields?: string[]}): Promise<Array<Exam>> { - const url = addFieldsToUrl({ - url: `/api/examtype/`, - fields}) +export async function fetchExamTypes (): Promise<Array<Exam>> { + const url = `/api/examtype/` return (await ax.get(url)).data } -export async function fetchStatistics (opt = {fields: []}): Promise<Statistics> { - const url = addFieldsToUrl({ - url: '/api/statistics/', - fields: opt.fields - }) +export async function fetchStatistics (): Promise<Statistics> { + const url = '/api/statistics/' return (await ax.get(url)).data } @@ -174,16 +152,13 @@ export async function submitUpdatedFeedback ({feedback}: {feedback: Feedback}): return (await ax.patch(`/api/feedback/${feedback.ofSubmission}/`, feedback)).data } -export async function fetchSubmissionTypes (fields: Array<string> = []): Promise<Array<SubmissionType>> { +export async function fetchSubmissionTypes (): Promise<Array<SubmissionType>> { let url = '/api/submissiontype/' - if (fields.length > 0) { - url += '?fields=pk,' + fields - } return (await ax.get(url)).data } -export async function fetchAllAssignments (fields = []): Promise<Array<Assignment>> { - const url = addFieldsToUrl({url: '/api/assignment/', fields}) +export async function fetchAllAssignments (): Promise<Array<Assignment>> { + const url = '/api/assignment/' return (await ax.get(url)).data } diff --git a/frontend/src/components/student_list/StudentList.vue b/frontend/src/components/student_list/StudentList.vue index bf14a68425e228a3df4a25bfd90644d898a9b29d..ca6e326d7accf6dd76c154edaba0bf45496c3d45 100644 --- a/frontend/src/components/student_list/StudentList.vue +++ b/frontend/src/components/student_list/StudentList.vue @@ -189,7 +189,7 @@ export default { }, changeActiveStatus (student) { changeActiveForUser(student.userPk, !student.isActive).then(() => { - this.getStudents({studentPks: [student.pk], fields: ['isActive']}) + this.getStudents({studentPks: [student.pk]}) }).catch(() => { this.$notify({ title: 'Error', diff --git a/frontend/src/components/student_list/StudentListMenu.vue b/frontend/src/components/student_list/StudentListMenu.vue index ec0129b0e4825d47ee9697410ba52f92988ea616..616c7430afa922f6ff65f167e59ff738028c9167 100644 --- a/frontend/src/components/student_list/StudentListMenu.vue +++ b/frontend/src/components/student_list/StudentListMenu.vue @@ -14,6 +14,7 @@ <script> import {activateAllStudentAccess, deactivateAllStudentAccess} from '@/api' +import { actions } from '@/store/actions'; export default { name: 'student-list-menu', @@ -26,19 +27,16 @@ export default { return [ { title: this.studentsActive - ? 'Deactivate student access' - : 'Activate student access', + ? 'Remove student access' + : 'Grant student access', action: this.changeStudentsAccess } ] } }, methods: { - updateStudentData (fields = []) { - this.$store.dispatch('getStudents', { - studentPks: Object.keys(this.$store.state.students), - fields - }).catch(() => { + updateStudentData () { + actions.getStudents().catch(() => { this.$notify({ title: 'ERROR', text: 'Unable to update student data!', diff --git a/frontend/src/store/actions.ts b/frontend/src/store/actions.ts index 95a43c0387e043fa923b385011682f980d5b6678..f70fa39fe96f3f1541e3e907a2caa0fd9b15eac1 100644 --- a/frontend/src/store/actions.ts +++ b/frontend/src/store/actions.ts @@ -16,18 +16,16 @@ async function getExamTypes(context: BareActionContext<RootState, RootState>) { } async function updateSubmissionTypes( context: BareActionContext<RootState, RootState>, - fields: Array<string> = [] ) { - const submissionTypes = await api.fetchSubmissionTypes(fields) + const submissionTypes = await api.fetchSubmissionTypes() submissionTypes.forEach(type => { mut.UPDATE_SUBMISSION_TYPE(type) }) } async function getStudents( context: BareActionContext<RootState, RootState>, - opt: { studentPks: Array<string>, fields: Array<string> } = { - studentPks: [], - fields: [] + opt: { studentPks: Array<string>} = { + studentPks: [] } ) { if (opt.studentPks.length === 0) { @@ -37,10 +35,7 @@ async function getStudents( } else { const students = await Promise.all( opt.studentPks.map((pk: string) => - api.fetchStudent({ - pk, - fields: opt.fields - }) + api.fetchStudent({pk}) ) ) students.forEach(student => mut.SET_STUDENT(student)) diff --git a/frontend/vue.config.js b/frontend/vue.config.js index b6e65a96dbd66e91658033eb70dff4a20bc94650..d8e6fdce16961a5c5e48a7bcb872b808e3aaddae 100644 --- a/frontend/vue.config.js +++ b/frontend/vue.config.js @@ -11,6 +11,8 @@ module.exports = { configureWebpack: config => { config.resolve.alias['@'] = `${projectRoot}/src` // keep_fnames ist set to true because vuex-typex is dependant on the function names - config.optimization.minimizer[0].options.uglifyOptions.keep_fnames = true + if (process.env.NODE_ENV === 'production') { + config.optimization.minimizer[0].options.uglifyOptions.keep_fnames = true + } } }