Commit 8457bee8 authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

META: refactor getUpdateShowObject & change show delete to deactivate

parent 1e3d3357
...@@ -74,17 +74,36 @@ ...@@ -74,17 +74,36 @@
<p v-html="sanitizedShowDescription" /> <p v-html="sanitizedShowDescription" />
<!-- TODO: add image and logo here? --> <!-- TODO: add image and logo here? -->
</div> </div>
</div>
<div align="center"> <div
<b-button
v-if="$parent.user.steeringUser.is_superuser" v-if="$parent.user.steeringUser.is_superuser"
variant="danger" align="center"
size="sm"
@click="$refs.appModalSuperuser.showModalDeleteShow(shows[currentShow].id, shows[currentShow].name)"
> >
Delete show <div v-if="shows[currentShow].is_active">
</b-button> <b-button
variant="danger"
size="sm"
@click="$refs.appModalSuperuser.showModalDeactivateShow(shows[currentShow].id, shows[currentShow].name)"
>
Deactivate show
</b-button>
</div>
<div v-else>
<b-alert
variant="danger"
show
>
This show is currently not active!<br><br>
<b-button
variant="success"
size="sm"
@click="notYetImplemented()"
>
Activate!
</b-button>
</b-alert>
</div>
</div>
</div> </div>
</b-jumbotron> </b-jumbotron>
......
...@@ -397,8 +397,10 @@ ...@@ -397,8 +397,10 @@
<script> <script>
import axios from 'axios' import axios from 'axios'
import showUpdates from '../mixins/showUpdates.js'
export default { export default {
mixins: [ showUpdates ],
props: { props: {
show: { type: Object, required: true } show: { type: Object, required: true }
}, },
...@@ -502,27 +504,6 @@ export default { ...@@ -502,27 +504,6 @@ export default {
the info set through the modal. the info set through the modal.
*/ */
methods: { methods: {
/* returns a new minimal object from the current show object with all
properties needed for a PUT request to the /show/ endpoint */
getUpdateShowObject () {
let s = {}
s.name = this.show.name
s.slug = this.show.slug
s.short_description = this.show.short_description
s.fundingcategory = this.show.fundingcategory
s.type = this.show.type
// we do not want the arrays do be passed as references, because the
// current show object should not get modified when the update object
// gets modified, therefore we use slice to clone the arrays
s.category = this.show.category.slice()
s.hosts = this.show.hosts.slice()
s.owners = this.show.owners.slice()
s.language = this.show.language.slice()
s.topic = this.show.topic.slice()
s.musicfocus = this.show.musicfocus.slice()
return s
},
/* /*
Functions to update certain infos about a show should first check out a Functions to update certain infos about a show should first check out a
new show object with getUpdateShowObject and then modify / add those new show object with getUpdateShowObject and then modify / add those
......
...@@ -82,18 +82,18 @@ ...@@ -82,18 +82,18 @@
</b-container> </b-container>
</b-modal> </b-modal>
<!-- Modal to confirm and delete a show --> <!-- Modal to confirm and deactivate a show -->
<b-modal <b-modal
ref="modalDeleteShow" ref="modalDeactivateShow"
title="Delete a show" title="Deactivate a show"
size="lg" size="lg"
@ok="deleteShow" @ok="deactivateShow"
> >
<b-alert <b-alert
variant="danger" variant="danger"
show show
> >
You are about to delete the show <b>{{ deletedShow.name }}</b>! You are about to deactivate the show <b>{{ deactivatedShow.name }}</b>!
</b-alert> </b-alert>
<div align="center"> <div align="center">
Are you sure you want to continue? Are you sure you want to continue?
...@@ -199,9 +199,10 @@ ...@@ -199,9 +199,10 @@
<script> <script>
import axios from 'axios' import axios from 'axios'
import slugify from '../mixins/slugify.js' import slugify from '../mixins/slugify.js'
import showUpdates from '../mixins/showUpdates.js'
export default { export default {
mixins: [ slugify ], mixins: [ slugify, showUpdates ],
data () { data () {
return { return {
newShow: { newShow: {
...@@ -217,7 +218,7 @@ export default { ...@@ -217,7 +218,7 @@ export default {
topic: [], topic: [],
musicfocus: [], musicfocus: [],
}, },
deletedShow: { deactivatedShow: {
id: null, id: null,
name: '', name: '',
}, },
...@@ -311,16 +312,16 @@ export default { ...@@ -311,16 +312,16 @@ export default {
}) })
}, },
// delete a show by sending a DELETE to the steering API // deactivate a show by updating the is_active flag to false
deleteShow (event) { deactivateShow (event) {
// prevent the modal from closing automatically on click // prevent the modal from closing automatically on click
event.preventDefault() event.preventDefault()
let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.deletedShow.id let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.deactivatedShow.id
axios.delete(uri, { axios.delete(uri, {
withCredentials: true, withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token } headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
}).then(() => { }).then(() => {
this.$refs.modalDeleteShow.hide() this.$refs.modalDeactivateShow.hide()
this.$parent.loadAndSwitch(null) this.$parent.loadAndSwitch(null)
}).catch(error => { }).catch(error => {
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
...@@ -354,13 +355,14 @@ export default { ...@@ -354,13 +355,14 @@ export default {
// prevent the modal from closing automatically on click // prevent the modal from closing automatically on click
event.preventDefault() event.preventDefault()
// now we have to fill the show's owner list anew with the selected owners // now we have to fill the show's owner list anew with the selected owners
this.show.owners = [] let updatedShow = this.getUpdateShowObject()
updatedShow.owners = []
for (let i in this.owners) { for (let i in this.owners) {
this.show.owners.push(this.owners[i].id) updatedShow.owners.push(this.owners[i].id)
} }
// ready to update the show // ready to update the show
let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/' let uri = process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/'
axios.put(uri, this.show, { axios.put(uri, updatedShow, {
withCredentials: true, withCredentials: true,
headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token } headers: { 'Authorization': 'Bearer ' + this.$parent.$parent.user.access_token }
}).then(() => { }).then(() => {
...@@ -384,11 +386,12 @@ export default { ...@@ -384,11 +386,12 @@ export default {
this.$refs.modalAddShow.show() this.$refs.modalAddShow.show()
}, },
// open the deletion confirmation modal // open the deactivation confirmation modal
showModalDeleteShow (id, name) { showModalDeactivateShow (show) {
this.deletedShow.id = id this.deactivatedShow.id = show.id
this.deletedShow.name = name this.deactivatedShow.name = show.name
this.$refs.modalDeleteShow.show() this.show = show
this.$refs.modalDeactivateShow.show()
}, },
// open the modal to edit a show's owners // open the modal to edit a show's owners
......
export default {
methods: {
/* returns a new minimal object from the current show object with all
properties needed for a PUT request to the /show/ endpoint */
getUpdateShowObject () {
let s = {}
s.name = this.show.name
s.slug = this.show.slug
s.short_description = this.show.short_description
s.fundingcategory = this.show.fundingcategory
s.type = this.show.type
// we do not want the arrays do be passed as references, because the
// current show object should not get modified when the update object
// gets modified, therefore we use slice to clone the arrays
s.category = this.show.category.slice()
s.hosts = this.show.hosts.slice()
s.owners = this.show.owners.slice()
s.language = this.show.language.slice()
s.topic = this.show.topic.slice()
s.musicfocus = this.show.musicfocus.slice()
return s
},
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment