pull/429/head
hunterlong 2020-03-16 11:28:45 -07:00
parent d8add289e2
commit dc3ae74070
7 changed files with 49 additions and 25 deletions

View File

@ -101,6 +101,10 @@ class Api {
return axios.delete('/api/users/' + id).then(response => (response.data)) return axios.delete('/api/users/' + id).then(response => (response.data))
} }
async incident_updates(incident) {
return axios.post('/api/incidents/'+incident.id+'/updates', data).then(response => (response.data))
}
async incident_update_create(incident, data) { async incident_update_create(incident, data) {
return axios.post('/api/incidents/'+incident.id+'/updates', data).then(response => (response.data)) return axios.post('/api/incidents/'+incident.id+'/updates', data).then(response => (response.data))
} }
@ -109,8 +113,8 @@ class Api {
return axios.get('/api/services/'+service.id+'/incidents').then(response => (response.data)) return axios.get('/api/services/'+service.id+'/incidents').then(response => (response.data))
} }
async incident_create(data) { async incident_create(service, data) {
return axios.post('/api/incidents', data).then(response => (response.data)) return axios.post('/api/services/'+service.id+'/incidents', data).then(response => (response.data))
} }
async incident_delete(incident) { async incident_delete(incident) {

View File

@ -76,20 +76,26 @@
} }
}, },
async mounted () { async mounted () {
this.incidents = await Api.incidents_service(this.service) await this.loadIncidents()
}, },
methods: { methods: {
async loadIncidents() {
this.incidents = await Api.incidents_service(this.service)
},
async createIncident() { async createIncident() {
await Api.incident_create(this.incident) await Api.incident_create(this.service, this.incident)
const incidents = await Api.incidents() await this.loadIncidents()
this.$store.commit('setIncidents', incidents) this.incident = {
this.incident = {} title: "",
description: "",
service: this.service.id,
}
}, },
async deleteIncident(incident) { async deleteIncident(incident) {
let c = confirm(`Are you sure you want to delete '${incident.title}'?`) let c = confirm(`Are you sure you want to delete '${incident.title}'?`)
if (c) { if (c) {
await Api.incident_delete(incident) await Api.incident_delete(incident)
this.incidents = await Api.incidents_service(this.service) await this.loadIncidents()
} }
} }
} }

View File

@ -71,21 +71,29 @@
}, },
data () { data () {
return { return {
updates: this.incident.updates, updates: [],
incident_update: { incident_update: {
incident: this.incident, incident: this.incident.id,
message: "", message: "",
type: "" type: ""
} }
} }
}, },
async mounted () { async mounted () {
this.updates = await Api.incident_updates(this.incident) await this.loadUpdates()
}, },
methods: { methods: {
async createIncidentUpdate(incident) { async loadUpdates() {
await Api.incident_update_create(incident, this.incident_update) this.updates = await Api.incident_updates(this.incident)
const updates = await Api.incident_updates() },
async createIncidentUpdate() {
await Api.incident_update_create(this.incident, this.incident_update)
await this.loadUpdates()
this.incident_update = {
incident: this.incident.id,
message: "",
type: ""
}
} }
} }
} }

View File

@ -101,9 +101,6 @@ export default new Vuex.Store({
setMessages (state, messages) { setMessages (state, messages) {
state.messages = messages state.messages = messages
}, },
setIncidents (state, incidents) {
state.incidents = incidents
},
setUsers (state, users) { setUsers (state, users) {
state.users = users state.users = users
}, },
@ -125,8 +122,6 @@ export default new Vuex.Store({
context.commit("setServices", services); context.commit("setServices", services);
const messages = await Api.messages() const messages = await Api.messages()
context.commit("setMessages", messages) context.commit("setMessages", messages)
const incidents = await Api.incidents()
context.commit("setIncidents", incidents)
context.commit("setHasPublicData", true) context.commit("setHasPublicData", true)
// if (core.logged_in) { // if (core.logged_in) {
// const notifiers = await Api.notifiers() // const notifiers = await Api.notifiers()

View File

@ -19,6 +19,16 @@ func apiServiceIncidentsHandler(w http.ResponseWriter, r *http.Request) {
returnJson(incids, w, r) returnJson(incids, w, r)
} }
func apiIncidentUpdatesHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
incid, err := incidents.Find(utils.ToInt(vars["id"]))
if err != nil {
sendErrorJson(err, w, r)
return
}
returnJson(incid.Updates(), w, r)
}
func apiCreateIncidentUpdateHandler(w http.ResponseWriter, r *http.Request) { func apiCreateIncidentUpdateHandler(w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r) vars := mux.Vars(r)
var update *incidents.IncidentUpdate var update *incidents.IncidentUpdate

View File

@ -137,6 +137,7 @@ func Router() *mux.Router {
api.Handle("/api/incidents/{id}", authenticated(apiDeleteIncidentHandler, false)).Methods("DELETE") api.Handle("/api/incidents/{id}", authenticated(apiDeleteIncidentHandler, false)).Methods("DELETE")
// API INCIDENTS UPDATES Routes // API INCIDENTS UPDATES Routes
api.Handle("/api/incidents/{id}/updates", authenticated(apiIncidentUpdatesHandler, false)).Methods("GET")
api.Handle("/api/incidents/{id}/updates", authenticated(apiCreateIncidentUpdateHandler, false)).Methods("POST") api.Handle("/api/incidents/{id}/updates", authenticated(apiCreateIncidentUpdateHandler, false)).Methods("POST")
api.Handle("/api/incidents/{id}/updates/{uid}", authenticated(apiDeleteIncidentUpdateHandler, false)).Methods("DELETE") api.Handle("/api/incidents/{id}/updates/{uid}", authenticated(apiDeleteIncidentUpdateHandler, false)).Methods("DELETE")

View File

@ -12,18 +12,18 @@ func SetDB(database database.Database) {
dbUpdate = database.Model(&IncidentUpdate{}) dbUpdate = database.Model(&IncidentUpdate{})
} }
func FindUpdate(uid int64) (*IncidentUpdate, error) {
var update IncidentUpdate
q := dbUpdate.Where("id = ?", uid).Find(&update)
return &update, q.Error()
}
func Find(id int64) (*Incident, error) { func Find(id int64) (*Incident, error) {
var incident Incident var incident Incident
q := db.Where("id = ?", id).Find(&incident) q := db.Where("id = ?", id).Find(&incident)
return &incident, q.Error() return &incident, q.Error()
} }
func FindUpdate(id int64) (*IncidentUpdate, error) {
var update IncidentUpdate
q := dbUpdate.Where("id = ?", id).Find(&update)
return &update, q.Error()
}
func FindByService(id int64) []*Incident { func FindByService(id int64) []*Incident {
var incidents []*Incident var incidents []*Incident
db.Where("service = ?", id).Find(&incidents) db.Where("service = ?", id).Find(&incidents)