Commit 8a45f85d authored by jackie / Andrea Ida Malkah Klaura's avatar jackie / Andrea Ida Malkah Klaura
Browse files

FIX #21 show update modals use minimal required show object

parent a5ec7564
...@@ -502,203 +502,218 @@ export default { ...@@ -502,203 +502,218 @@ 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 through the API Functions to update certain infos about a show should first check out a
The API always takes the full show object, so even if we only change one new show object with getUpdateShowObject and then modify / add those
single item in a show we have to send the whole show. properties that actually get changed
This also means we could use just one save function. Here we could think TODO: think about refactoring all those function to one or few functions
about refactoring. It is important than to check which of the items have
changed and to restore those items in case the update fails.
For now we have single function for every modal to save only the bits
regarding this modal.
*/ */
saveName (event) { saveName (event) {
if (this.string !== this.show.name) { if (this.string !== this.show.name) {
event.preventDefault() event.preventDefault()
this.backupstring = this.show.name let updatedShow = this.getUpdateShowObject()
this.show.name = this.string updatedShow.name = this.string
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.name = this.string
this.$refs.modalShowName.hide() this.$refs.modalShowName.hide()
}).catch(error => { }).catch(error => {
this.show.name = this.backupstring
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show name. See console for details.') alert('Error: could not save the show name. See console for details.')
}) })
} }
}, },
saveShortDescription (event) { saveShortDescription (event) {
if (this.string !== this.show.short_description) { if (this.string !== this.show.short_description) {
event.preventDefault() event.preventDefault()
this.backupstring = this.show.short_description let updatedShow = this.getUpdateShowObject()
this.show.short_description = this.string updatedShow.short_description = this.string
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.short_description = this.string
this.$refs.modalShowShortDescription.hide() this.$refs.modalShowShortDescription.hide()
}).catch(error => { }).catch(error => {
this.show.short_description = this.backupstring
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show\'s short description. See console for details.') alert('Error: could not save the show\'s short description. See console for details.')
}) })
} }
}, },
saveDescription (event) { saveDescription (event) {
if (this.string !== this.show.description) { if (this.string !== this.show.description) {
event.preventDefault() event.preventDefault()
this.backupstring = this.show.description let updatedShow = this.getUpdateShowObject()
this.show.description = this.string updatedShow.description = this.string
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.description = this.string
this.$refs.modalShowDescription.hide() this.$refs.modalShowDescription.hide()
}).catch(error => { }).catch(error => {
this.show.description = this.backupstring
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show description. See console for details.') alert('Error: could not save the show description. See console for details.')
}) })
} }
}, },
saveEmail (event) { saveEmail (event) {
if (this.string !== this.show.email) { if (this.string !== this.show.email) {
event.preventDefault() event.preventDefault()
this.backupstring = this.show.email let updatedShow = this.getUpdateShowObject()
this.show.email = this.string updatedShow.email = this.string
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.email = this.string
this.$refs.modalShowEmail.hide() this.$refs.modalShowEmail.hide()
}).catch(error => { }).catch(error => {
this.show.email = this.backupstring
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show e-mail contact. See console for details.') alert('Error: could not save the show e-mail contact. See console for details.')
}) })
} }
}, },
saveWebsite (event) { saveWebsite (event) {
if (this.string !== this.show.website) { if (this.string !== this.show.website) {
event.preventDefault() event.preventDefault()
this.backupstring = this.show.website let updatedShow = this.getUpdateShowObject()
this.show.website = this.string updatedShow.website = this.string
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.website = this.string
this.$refs.modalShowWebsite.hide() this.$refs.modalShowWebsite.hide()
}).catch(error => { }).catch(error => {
this.show.website = this.backupstring
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show website. See console for details.') alert('Error: could not save the show website. See console for details.')
}) })
} }
}, },
saveCBAid (event) { saveCBAid (event) {
if (this.id !== this.show.cba_series_id) { if (this.id !== this.show.cba_series_id) {
event.preventDefault() event.preventDefault()
this.backupid = this.show.cba_series_id let updatedShow = this.getUpdateShowObject()
this.show.cba_series_id = this.id updatedShow.cba_series_id = this.string
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.cba_series_id = this.id
this.$refs.modalShowCBAid.hide() this.$refs.modalShowCBAid.hide()
}).catch(error => { }).catch(error => {
this.show.cba_series_id = this.backupid
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the CBA show id. See console for details.') alert('Error: could not save the CBA show id. See console for details.')
}) })
} }
}, },
saveShowType (event) { saveShowType (event) {
if (this.id !== this.show.type) { if (this.id !== this.show.type) {
event.preventDefault() event.preventDefault()
this.backupid = this.show.type let updatedShow = this.getUpdateShowObject()
this.show.type = this.id updatedShow.type = this.id
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.type = this.id
this.$parent.getType() this.$parent.getType()
this.$refs.modalShowType.hide() this.$refs.modalShowType.hide()
}).catch(error => { }).catch(error => {
this.show.type = this.backupid
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show type. See console for details.') alert('Error: could not save the show type. See console for details.')
}) })
} }
}, },
savePredecessor (event) { savePredecessor (event) {
if (this.id !== this.show.predecessor) { if (this.id !== this.show.predecessor) {
event.preventDefault() event.preventDefault()
this.backupid = this.show.predecessor_id let updatedShow = this.getUpdateShowObject()
this.show.predecessor_id = this.id updatedShow.predecessor_id = this.id
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.predecessor_id = this.id
this.$refs.modalShowPredecessor.hide() this.$refs.modalShowPredecessor.hide()
}).catch(error => { }).catch(error => {
this.show.predecessor = this.backupid
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show predecessor. See console for details.') alert('Error: could not save the show predecessor. See console for details.')
}) })
} }
}, },
saveFundingCategory (event) { saveFundingCategory (event) {
if (this.id !== this.show.fundingcategory) { if (this.id !== this.show.fundingcategory) {
event.preventDefault() event.preventDefault()
this.backupid = this.show.fundingcategory let updatedShow = this.getUpdateShowObject()
this.show.fundingcategory = this.id updatedShow.fundingcategory = this.id
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.fundingcategory = this.id
this.$parent.getFundingCategory() this.$parent.getFundingCategory()
this.$refs.modalShowType.hide() this.$refs.modalShowType.hide()
}).catch(error => { }).catch(error => {
this.show.fundingcategory = this.backupid
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show\' funding category. See console for details.') alert('Error: could not save the show\' funding category. See console for details.')
}) })
} }
}, },
saveCategories (event) { saveCategories (event) {
this.$log.debug('saveCategories', this.array, this.show.category) this.$log.debug('saveCategories', this.array, this.show.category)
if (this.array.length !== this.show.category.length || !this.array.every((value, index) => value === this.show.category[index])) { if (this.array.length !== this.show.category.length || !this.array.every((value, index) => value === this.show.category[index])) {
event.preventDefault() event.preventDefault()
let updatedShow = { let updatedShow = this.getUpdateShowObject()
name: this.show.name,
slug: this.show.slug,
short_description: this.show.short_description,
fundingcategory: this.show.fundingcategory,
type: this.show.type,
hosts: this.show.hosts,
language: this.show.language,
musicfocus: this.show.musicfocus,
owners: this.show.owners,
topic: this.show.topic,
}
updatedShow.category = this.array updatedShow.category = this.array
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, updatedShow, { 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(() => {
this.$parent.shows[this.$parent.currentShow].category = updatedShow.category this.$parent.shows[this.$parent.currentShow].category = this.array
this.$parent.getCategories() this.$parent.getCategories()
this.$refs.modalShowCategories.hide() this.$refs.modalShowCategories.hide()
}).catch(error => { }).catch(error => {
...@@ -708,38 +723,40 @@ export default { ...@@ -708,38 +723,40 @@ export default {
}) })
} }
}, },
saveTopics (event) { saveTopics (event) {
if (this.array.length !== this.show.topic.length || !this.array.every((value, index) => value === this.show.topic[index])) { if (this.array.length !== this.show.topic.length || !this.array.every((value, index) => value === this.show.topic[index])) {
event.preventDefault() event.preventDefault()
this.backuparray = this.show.topic let updatedShow = this.getUpdateShowObject()
this.show.topic = this.array updatedShow.topic = this.array
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.topic = this.array
this.$parent.getTopics() this.$parent.getTopics()
this.$refs.modalShowTopics.hide() this.$refs.modalShowTopics.hide()
}).catch(error => { }).catch(error => {
this.show.topic = this.backuparray
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show\'s topics. See console for details.') alert('Error: could not save the show\'s topics. See console for details.')
}) })
} }
}, },
saveMusicFocus (event) { saveMusicFocus (event) {
if (this.array.length !== this.show.musicfocus.length || !this.array.every((value, index) => value === this.show.musicfocus[index])) { if (this.array.length !== this.show.musicfocus.length || !this.array.every((value, index) => value === this.show.musicfocus[index])) {
event.preventDefault() event.preventDefault()
this.backuparray = this.show.musicfocus let updatedShow = this.getUpdateShowObject()
this.show.musicfocus = this.array updatedShow.musicfocus = this.array
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.musicfocus = this.array
this.$parent.getMusicfocus() this.$parent.getMusicfocus()
this.$refs.modalShowMusicFocus.hide() this.$refs.modalShowMusicFocus.hide()
}).catch(error => { }).catch(error => {
this.show.musicfocus = this.backuparray
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show\'s music focus. See console for details.') alert('Error: could not save the show\'s music focus. See console for details.')
...@@ -749,16 +766,16 @@ export default { ...@@ -749,16 +766,16 @@ export default {
saveLanguages (event) { saveLanguages (event) {
if (this.array.length !== this.show.language.length || !this.array.every((value, index) => value === this.show.language[index])) { if (this.array.length !== this.show.language.length || !this.array.every((value, index) => value === this.show.language[index])) {
event.preventDefault() event.preventDefault()
this.backuparray = this.show.language let updatedShow = this.getUpdateShowObject()
this.show.language = this.array updatedShow.language = this.array
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.language = this.array
this.$parent.getLanguages() this.$parent.getLanguages()
this.$refs.modalShowLanguages.hide() this.$refs.modalShowLanguages.hide()
}).catch(error => { }).catch(error => {
this.show.language = this.backuparray
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show\'s languages. See console for details.') alert('Error: could not save the show\'s languages. See console for details.')
...@@ -768,16 +785,16 @@ export default { ...@@ -768,16 +785,16 @@ export default {
saveHosts (event) { saveHosts (event) {
if (this.array.length !== this.show.hosts.length || !this.array.every((value, index) => value === this.show.hosts[index])) { if (this.array.length !== this.show.hosts.length || !this.array.every((value, index) => value === this.show.hosts[index])) {
event.preventDefault() event.preventDefault()
this.backuparray = this.show.hosts let updatedShow = this.getUpdateShowObject()
this.show.hosts = this.array updatedShow.hosts = this.array
axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', this.show, { axios.put(process.env.VUE_APP_API_STEERING_SHOWS + this.show.id + '/', 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(() => {
this.show.hosts = this.array
this.$parent.getHosts() this.$parent.getHosts()
this.$refs.modalShowHosts.hide() this.$refs.modalShowHosts.hide()
}).catch(error => { }).catch(error => {
this.show.hosts = this.backuparray
this.$log.error(error.response.status + ' ' + error.response.statusText) this.$log.error(error.response.status + ' ' + error.response.statusText)
this.$log.error(error.response) this.$log.error(error.response)
alert('Error: could not save the show\'s hosts. See console for details.') alert('Error: could not save the show\'s hosts. See console for details.')
......
Supports Markdown
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