Skip to content
Snippets Groups Projects
Commit 4991cd34 authored by robinwilliam.hundt's avatar robinwilliam.hundt
Browse files

Small bug fixes, including for #122

parent c2370d47
No related branches found
No related tags found
1 merge request!120Bug fixes
Pipeline #81449 failed
...@@ -13,10 +13,6 @@ import { ...@@ -13,10 +13,6 @@ import {
Tutor, UserAccount Tutor, UserAccount
} from '@/models' } from '@/models'
function addFieldsToUrl ({url, fields = []}: {url: string, fields?: string[]}): string {
return fields.length > 0 ? url + '?fields=pk,' + fields : url
}
function getInstanceBaseUrl (): string { function getInstanceBaseUrl (): string {
if (process.env.NODE_ENV === 'production') { if (process.env.NODE_ENV === 'production') {
return `https://${window.location.host}${window.location.pathname}` return `https://${window.location.host}${window.location.pathname}`
...@@ -46,7 +42,7 @@ export async function fetchJWT (credentials: Credentials): Promise<JSONWebToken> ...@@ -46,7 +42,7 @@ export async function fetchJWT (credentials: Credentials): Promise<JSONWebToken>
} }
export async function refreshJWT (oldToken: string): 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}` ax.defaults.headers['Authorization'] = `JWT ${token}`
return {token} return {token}
} }
...@@ -67,28 +63,19 @@ export async function fetchSubmissionFeedbackTests ({pk}: {pk: string}): Promise ...@@ -67,28 +63,19 @@ export async function fetchSubmissionFeedbackTests ({pk}: {pk: string}): Promise
return (await ax.get(`/api/submission/${pk}/`)).data return (await ax.get(`/api/submission/${pk}/`)).data
} }
export async function fetchAllStudents (fields: string[] = []): Promise<Array<StudentInfoForListView>> { export async function fetchAllStudents (): Promise<Array<StudentInfoForListView>> {
const url = addFieldsToUrl({ const url = '/api/student/'
url: '/api/student/',
fields
})
return (await ax.get(url)).data return (await ax.get(url)).data
} }
export async function fetchStudent ({pk, fields = []}: export async function fetchStudent ({pk, }:
{pk: string, fields?: string[]}): Promise<StudentInfoForListView> { {pk: string}): Promise<StudentInfoForListView> {
const url = addFieldsToUrl({ const url = `/api/student/${pk}/`
url: `/api/student/${pk}/`,
fields
})
return (await ax.get(url)).data return (await ax.get(url)).data
} }
export async function fetchAllTutors (fields: string[] = []): Promise<Array<Tutor>> { export async function fetchAllTutors (): Promise<Array<Tutor>> {
const url = addFieldsToUrl({ const url = '/api/tutor/'
url: '/api/tutor/',
fields
})
return (await ax.get(url)).data return (await ax.get(url)).data
} }
...@@ -105,11 +92,8 @@ export async function fetchSubscription (subscriptionPk: string): Promise<Subscr ...@@ -105,11 +92,8 @@ export async function fetchSubscription (subscriptionPk: string): Promise<Subscr
return (await ax.get(`/api/subscription/${subscriptionPk}/`)).data return (await ax.get(`/api/subscription/${subscriptionPk}/`)).data
} }
export async function fetchAllFeedback (fields: string[] = []): Promise<Array<Feedback>> { export async function fetchAllFeedback (): Promise<Array<Feedback>> {
const url = addFieldsToUrl({ const url = '/api/feedback/'
url: '/api/feedback/',
fields
})
return (await ax.get(url)).data return (await ax.get(url)).data
} }
...@@ -118,19 +102,13 @@ export async function fetchFeedback ({ofSubmission}: {ofSubmission: string}): Pr ...@@ -118,19 +102,13 @@ export async function fetchFeedback ({ofSubmission}: {ofSubmission: string}): Pr
return (await ax.get(url)).data return (await ax.get(url)).data
} }
export async function fetchExamTypes ({fields = []}: export async function fetchExamTypes (): Promise<Array<Exam>> {
{fields?: string[]}): Promise<Array<Exam>> { const url = `/api/examtype/`
const url = addFieldsToUrl({
url: `/api/examtype/`,
fields})
return (await ax.get(url)).data return (await ax.get(url)).data
} }
export async function fetchStatistics (opt = {fields: []}): Promise<Statistics> { export async function fetchStatistics (): Promise<Statistics> {
const url = addFieldsToUrl({ const url = '/api/statistics/'
url: '/api/statistics/',
fields: opt.fields
})
return (await ax.get(url)).data return (await ax.get(url)).data
} }
...@@ -174,16 +152,13 @@ export async function submitUpdatedFeedback ({feedback}: {feedback: Feedback}): ...@@ -174,16 +152,13 @@ export async function submitUpdatedFeedback ({feedback}: {feedback: Feedback}):
return (await ax.patch(`/api/feedback/${feedback.ofSubmission}/`, feedback)).data 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/' let url = '/api/submissiontype/'
if (fields.length > 0) {
url += '?fields=pk,' + fields
}
return (await ax.get(url)).data return (await ax.get(url)).data
} }
export async function fetchAllAssignments (fields = []): Promise<Array<Assignment>> { export async function fetchAllAssignments (): Promise<Array<Assignment>> {
const url = addFieldsToUrl({url: '/api/assignment/', fields}) const url = '/api/assignment/'
return (await ax.get(url)).data return (await ax.get(url)).data
} }
......
...@@ -189,7 +189,7 @@ export default { ...@@ -189,7 +189,7 @@ export default {
}, },
changeActiveStatus (student) { changeActiveStatus (student) {
changeActiveForUser(student.userPk, !student.isActive).then(() => { changeActiveForUser(student.userPk, !student.isActive).then(() => {
this.getStudents({studentPks: [student.pk], fields: ['isActive']}) this.getStudents({studentPks: [student.pk]})
}).catch(() => { }).catch(() => {
this.$notify({ this.$notify({
title: 'Error', title: 'Error',
......
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
<script> <script>
import {activateAllStudentAccess, import {activateAllStudentAccess,
deactivateAllStudentAccess} from '@/api' deactivateAllStudentAccess} from '@/api'
import { actions } from '@/store/actions';
export default { export default {
name: 'student-list-menu', name: 'student-list-menu',
...@@ -26,19 +27,16 @@ export default { ...@@ -26,19 +27,16 @@ export default {
return [ return [
{ {
title: this.studentsActive title: this.studentsActive
? 'Deactivate student access' ? 'Remove student access'
: 'Activate student access', : 'Grant student access',
action: this.changeStudentsAccess action: this.changeStudentsAccess
} }
] ]
} }
}, },
methods: { methods: {
updateStudentData (fields = []) { updateStudentData () {
this.$store.dispatch('getStudents', { actions.getStudents().catch(() => {
studentPks: Object.keys(this.$store.state.students),
fields
}).catch(() => {
this.$notify({ this.$notify({
title: 'ERROR', title: 'ERROR',
text: 'Unable to update student data!', text: 'Unable to update student data!',
......
...@@ -16,18 +16,16 @@ async function getExamTypes(context: BareActionContext<RootState, RootState>) { ...@@ -16,18 +16,16 @@ async function getExamTypes(context: BareActionContext<RootState, RootState>) {
} }
async function updateSubmissionTypes( async function updateSubmissionTypes(
context: BareActionContext<RootState, RootState>, context: BareActionContext<RootState, RootState>,
fields: Array<string> = []
) { ) {
const submissionTypes = await api.fetchSubmissionTypes(fields) const submissionTypes = await api.fetchSubmissionTypes()
submissionTypes.forEach(type => { submissionTypes.forEach(type => {
mut.UPDATE_SUBMISSION_TYPE(type) mut.UPDATE_SUBMISSION_TYPE(type)
}) })
} }
async function getStudents( async function getStudents(
context: BareActionContext<RootState, RootState>, context: BareActionContext<RootState, RootState>,
opt: { studentPks: Array<string>, fields: Array<string> } = { opt: { studentPks: Array<string>} = {
studentPks: [], studentPks: []
fields: []
} }
) { ) {
if (opt.studentPks.length === 0) { if (opt.studentPks.length === 0) {
...@@ -37,10 +35,7 @@ async function getStudents( ...@@ -37,10 +35,7 @@ async function getStudents(
} else { } else {
const students = await Promise.all( const students = await Promise.all(
opt.studentPks.map((pk: string) => opt.studentPks.map((pk: string) =>
api.fetchStudent({ api.fetchStudent({pk})
pk,
fields: opt.fields
})
) )
) )
students.forEach(student => mut.SET_STUDENT(student)) students.forEach(student => mut.SET_STUDENT(student))
......
...@@ -11,6 +11,8 @@ module.exports = { ...@@ -11,6 +11,8 @@ module.exports = {
configureWebpack: config => { configureWebpack: config => {
config.resolve.alias['@'] = `${projectRoot}/src` config.resolve.alias['@'] = `${projectRoot}/src`
// keep_fnames ist set to true because vuex-typex is dependant on the function names // 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
}
} }
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment