Skip to content

Commit 2da552c

Browse files
delete exercise
1 parent 81e2078 commit 2da552c

File tree

7 files changed

+94
-29
lines changed

7 files changed

+94
-29
lines changed

src/api/endpoints.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const endpoints = {
2727
detail: '/classroom/reading-exercises/<pk>/',
2828
create: '/classroom/reading-exercises/',
2929
update: '/classroom/reading-exercises/<pk>/',
30+
delete: '/classroom/reading-exercises/<pk>/',
3031
uploadImage: '/classroom/reading-exercises/upload-image/',
3132
submitAnswers: '/classroom/reading-exercises/<pk>/submit-answers/'
3233
},

src/api/reading-exercise.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ export const readingExercise = {
2626
return res.data
2727
},
2828

29+
async delete (pk: ReadingExercise['pk']): Promise<void> {
30+
const endpoint = replacePk(endpoints.readingExercise.delete, pk)
31+
await Vue.axios.delete(endpoint)
32+
},
33+
2934
async submitAnswers (pk: ReadingExercise['pk'], payload: ReadingExerciseSubmitAnswersReq[]): Promise<void> {
3035
const endpoint = replacePk(endpoints.readingExercise.submitAnswers, pk)
3136
await Vue.axios.post(endpoint, payload)

src/store/reading-exercises.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ export const readingExercise: Module<ReadingExerciseState, RootState> = {
4343
state.readingExercises.splice(0, 0, readingExercise)
4444
},
4545

46+
REMOVE_READING_EXERCISE (state, deletedPk) {
47+
state.readingExercises = state.readingExercises.filter(ex => ex.pk !== deletedPk)
48+
},
49+
4650
SET_CURRENT_QUESTIONS (state, questions) {
4751
state.currentQuestions = questions
4852
},
@@ -99,6 +103,11 @@ export const readingExercise: Module<ReadingExerciseState, RootState> = {
99103
return data.pk
100104
},
101105

106+
async delete ({ commit }, pk: ReadingExercise['pk']): Promise<void> {
107+
await Api.readingExercise.delete(pk)
108+
commit('REMOVE_READING_EXERCISE', pk)
109+
},
110+
102111
async getQuestions ({ state, commit }): Promise<void> {
103112
if (state.currentReadingExercise === undefined) return
104113
const exercisePk = state.currentReadingExercise.pk

src/views/reading-exercise/ReadingExerciseCreate.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-container>
2+
<v-container class="container-sm">
33
<v-breadcrumbs :items="breadcrumbs"></v-breadcrumbs>
44

55
<v-card class="mx-auto">

src/views/reading-exercise/ReadingExerciseDetail.vue

Lines changed: 76 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,22 @@
99
></v-progress-circular>
1010

1111
<div v-if="exercise !== undefined">
12-
<h1>{{ exercise.identifier }}</h1>
12+
<v-row
13+
justify="space-between"
14+
align="center"
15+
>
16+
<v-col cols="auto">
17+
<h1>{{ exercise.identifier }}</h1>
18+
</v-col>
19+
<v-col cols="auto">
20+
<v-btn
21+
icon
22+
@click="confirmDelete = true"
23+
>
24+
<v-icon>mdi-delete-outline</v-icon>
25+
</v-btn>
26+
</v-col>
27+
</v-row>
1328
<v-divider></v-divider>
1429

1530
<v-row class="mt-0">
@@ -96,13 +111,53 @@
96111
</v-col>
97112
</v-row>
98113
</div>
114+
115+
<v-dialog
116+
v-model="confirmDelete"
117+
width="500"
118+
>
119+
<v-card>
120+
<v-card-title>
121+
Please confirm
122+
</v-card-title>
123+
<v-card-text>
124+
<p>
125+
You are deleting exercise <strong>{{ exercise.identifier }}</strong>.
126+
</p>
127+
<div class="error--text">
128+
<v-icon color="error">
129+
mdi-alert-outline
130+
</v-icon>
131+
This cannot be undone!
132+
</div>
133+
</v-card-text>
134+
<v-card-actions>
135+
<v-spacer></v-spacer>
136+
<v-btn
137+
text
138+
@click="confirmDelete = false"
139+
>
140+
Cancel
141+
</v-btn>
142+
<v-btn
143+
color="primary"
144+
depressed
145+
:loading="deleting"
146+
@click="deleteExercise"
147+
>
148+
Confirm
149+
</v-btn>
150+
</v-card-actions>
151+
</v-card>
152+
</v-dialog>
99153
</v-container>
100154
</template>
101155

102156
<script lang="ts">
103157
import { ReadingQuestion } from '@/interfaces/reading-question'
104158
import { Mixins, Component } from 'vue-property-decorator'
105159
import { ReadingExerciseMixin } from '@/mixins/reading-exercise-mixin'
160+
import { unexpectedExc } from '@/utils'
106161
107162
@Component
108163
export default class ReadingExerciseDetail extends Mixins(ReadingExerciseMixin) {
@@ -115,16 +170,6 @@ export default class ReadingExerciseDetail extends Mixins(ReadingExerciseMixin)
115170
]
116171
}
117172
118-
expand = false
119-
120-
get exerciseContentHeight (): string {
121-
if (!this.expand) {
122-
return '50vh'
123-
} else {
124-
return 'unset'
125-
}
126-
}
127-
128173
get passage1Questions (): ReadingQuestion[] {
129174
return this.questions.filter(question => question.passage === 1)
130175
}
@@ -140,6 +185,26 @@ export default class ReadingExerciseDetail extends Mixins(ReadingExerciseMixin)
140185
formatAnswers (answers: ReadingQuestion['answers']): string {
141186
return answers.join(' / ')
142187
}
188+
189+
/**
190+
* Delete exercise
191+
*/
192+
confirmDelete = false
193+
deleting = false
194+
195+
deleteExercise (): void {
196+
if (this.deleting) return
197+
this.deleting = true
198+
199+
this.$store.dispatch('readingExercise/delete', this.exercise.pk)
200+
.then(() => {
201+
this.$router.push({ name: 'ReadingExerciseList' })
202+
})
203+
.catch(unexpectedExc)
204+
.finally(() => {
205+
this.deleting = false
206+
})
207+
}
143208
}
144209
</script>
145210

src/views/reading-exercise/ReadingExerciseEditAnswers.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-container>
2+
<v-container class="container-sm">
33
<v-breadcrumbs :items="breadcrumbs"></v-breadcrumbs>
44

55
<v-progress-linear

src/views/reading-exercise/ReadingExerciseUpdate.vue

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<template>
2-
<v-container>
2+
<v-container class="container-sm">
33
<v-breadcrumbs :items="breadcrumbs"></v-breadcrumbs>
44

55
<v-progress-circular
@@ -42,21 +42,6 @@
4242
</v-btn>
4343
</v-card-actions>
4444
</v-card>
45-
46-
<!--
47-
<v-btn
48-
fab
49-
color="primary"
50-
bottom
51-
right
52-
fixed
53-
large
54-
>
55-
<v-icon>
56-
mdi-content-save-outline
57-
</v-icon>
58-
</v-btn>
59-
-->
6045
</v-container>
6146
</template>
6247

0 commit comments

Comments
 (0)