Skip to content

Commit

Permalink
Fixes #247 (PR #249)
Browse files Browse the repository at this point in the history
  • Loading branch information
ChristopherJennings authored Apr 26, 2019
1 parent f4c5e0c commit f99ec05
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 34 deletions.
4 changes: 2 additions & 2 deletions KenticoInspector.WebApplication/ClientApp/src/api/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ export default {
axios.post("/api/instances", instance)
.then(r => r.data)
.catch(reject)
.then(instances => {
resolve(instances)
.then(instance => {
resolve(instance)
})
})
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,19 @@ export default {
}
}),
methods: {
...mapActions([
'upsertInstance'
]),
...mapActions('instances', {
connectInstance: 'connect',
upsertInstance: 'upsertItem'
}),
submit () {
if (this.$refs.form.validate()) {
this.upsertInstance(this.instance)
this.upsertInstance(this.instance).then((newInstance) => {
this.connectInstance(newInstance.guid)
.then(() => {
this.$router.push('/reports')
})
})
//this.$refs.form.reset()
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import api from '../../api'
const state = {
items: {},
currentInstanceDetails: null,
upserting: false,
upsertingError: null,
connecting: false,
connectionError: null
}
Expand All @@ -27,40 +29,39 @@ const getters = {
}

const actions = {
getAll: ({ commit }) => {
api.getInstances()
.then(instances => {
commit('setItems', instances)
})
async getAll ({ commit }) {
commit('setItems', await api.getInstances())
},

upsertItem: ({ dispatch }, instance) => {
api.upsertInstance(instance)
.then(()=>{
dispatch('getAll')
})
async upsertItem ({ commit, dispatch }, instance) {
commit('setUpserting',true)
try {
const newInstance = await api.upsertInstance(instance)
dispatch('getAll')
return newInstance
} catch (error) {
commit('setUpsertingError', error)
}

commit('setUpserting',false)
},

deleteItem: ({ dispatch }, guid) => {
api.deleteInstance(guid)
.then(()=>{
dispatch('getAll')
})
async deleteItem ({ dispatch }, guid) {
await api.deleteInstance(guid)
await dispatch('getAll')
},

connect: ({ commit }, guid) => {
return new Promise((resolve) => {
commit('setConnecting',true)
api.getInstanceDetails(guid)
.then(instanceDetails => {
commit('setCurrentInstanceDetails', instanceDetails)
commit('setConnecting',false)
resolve()
})
.catch(reason => {
commit('setConnectionError', reason)
})
})
async connect ({ commit }, guid) {
commit('setConnecting',true)

try {
const instanceDetails = await api.getInstanceDetails(guid)
commit('setCurrentInstanceDetails', instanceDetails)
} catch (error) {
commit('setConnectionError', error)
}

commit('setConnecting',false)
},

cancelConnecting: ({ commit }) => {
Expand All @@ -82,6 +83,14 @@ const mutations = {
state.connectionError = reason
},

setUpserting (state, status) {
state.upserting = status
},

setUpsertingError (state, reason) {
state.upsertingError = reason
},

setCurrentInstanceDetails (state, instanceDetails) {
state.currentInstanceDetails = instanceDetails
},
Expand Down

0 comments on commit f99ec05

Please sign in to comment.