mirror of https://github.com/statping/statping
building
parent
d8add289e2
commit
dc3ae74070
|
@ -101,6 +101,10 @@ class Api {
|
|||
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) {
|
||||
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))
|
||||
}
|
||||
|
||||
async incident_create(data) {
|
||||
return axios.post('/api/incidents', data).then(response => (response.data))
|
||||
async incident_create(service, data) {
|
||||
return axios.post('/api/services/'+service.id+'/incidents', data).then(response => (response.data))
|
||||
}
|
||||
|
||||
async incident_delete(incident) {
|
||||
|
|
|
@ -76,20 +76,26 @@
|
|||
}
|
||||
},
|
||||
async mounted () {
|
||||
this.incidents = await Api.incidents_service(this.service)
|
||||
await this.loadIncidents()
|
||||
},
|
||||
methods: {
|
||||
async loadIncidents() {
|
||||
this.incidents = await Api.incidents_service(this.service)
|
||||
},
|
||||
async createIncident() {
|
||||
await Api.incident_create(this.incident)
|
||||
const incidents = await Api.incidents()
|
||||
this.$store.commit('setIncidents', incidents)
|
||||
this.incident = {}
|
||||
await Api.incident_create(this.service, this.incident)
|
||||
await this.loadIncidents()
|
||||
this.incident = {
|
||||
title: "",
|
||||
description: "",
|
||||
service: this.service.id,
|
||||
}
|
||||
},
|
||||
async deleteIncident(incident) {
|
||||
let c = confirm(`Are you sure you want to delete '${incident.title}'?`)
|
||||
if (c) {
|
||||
await Api.incident_delete(incident)
|
||||
this.incidents = await Api.incidents_service(this.service)
|
||||
await this.loadIncidents()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,21 +71,29 @@
|
|||
},
|
||||
data () {
|
||||
return {
|
||||
updates: this.incident.updates,
|
||||
updates: [],
|
||||
incident_update: {
|
||||
incident: this.incident,
|
||||
incident: this.incident.id,
|
||||
message: "",
|
||||
type: ""
|
||||
}
|
||||
}
|
||||
},
|
||||
async mounted () {
|
||||
this.updates = await Api.incident_updates(this.incident)
|
||||
await this.loadUpdates()
|
||||
},
|
||||
methods: {
|
||||
async createIncidentUpdate(incident) {
|
||||
await Api.incident_update_create(incident, this.incident_update)
|
||||
const updates = await Api.incident_updates()
|
||||
async loadUpdates() {
|
||||
this.updates = await Api.incident_updates(this.incident)
|
||||
},
|
||||
async createIncidentUpdate() {
|
||||
await Api.incident_update_create(this.incident, this.incident_update)
|
||||
await this.loadUpdates()
|
||||
this.incident_update = {
|
||||
incident: this.incident.id,
|
||||
message: "",
|
||||
type: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -101,9 +101,6 @@ export default new Vuex.Store({
|
|||
setMessages (state, messages) {
|
||||
state.messages = messages
|
||||
},
|
||||
setIncidents (state, incidents) {
|
||||
state.incidents = incidents
|
||||
},
|
||||
setUsers (state, users) {
|
||||
state.users = users
|
||||
},
|
||||
|
@ -125,8 +122,6 @@ export default new Vuex.Store({
|
|||
context.commit("setServices", services);
|
||||
const messages = await Api.messages()
|
||||
context.commit("setMessages", messages)
|
||||
const incidents = await Api.incidents()
|
||||
context.commit("setIncidents", incidents)
|
||||
context.commit("setHasPublicData", true)
|
||||
// if (core.logged_in) {
|
||||
// const notifiers = await Api.notifiers()
|
||||
|
|
|
@ -19,6 +19,16 @@ func apiServiceIncidentsHandler(w http.ResponseWriter, r *http.Request) {
|
|||
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) {
|
||||
vars := mux.Vars(r)
|
||||
var update *incidents.IncidentUpdate
|
||||
|
|
|
@ -137,6 +137,7 @@ func Router() *mux.Router {
|
|||
api.Handle("/api/incidents/{id}", authenticated(apiDeleteIncidentHandler, false)).Methods("DELETE")
|
||||
|
||||
// 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/{uid}", authenticated(apiDeleteIncidentUpdateHandler, false)).Methods("DELETE")
|
||||
|
||||
|
|
|
@ -12,18 +12,18 @@ func SetDB(database database.Database) {
|
|||
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) {
|
||||
var incident Incident
|
||||
q := db.Where("id = ?", id).Find(&incident)
|
||||
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 {
|
||||
var incidents []*Incident
|
||||
db.Where("service = ?", id).Find(&incidents)
|
||||
|
|
Loading…
Reference in New Issue