pull/429/head
hunterlong 2020-02-02 20:52:47 -08:00
parent 3fbf5b99f3
commit f4e2adc29c
9 changed files with 106 additions and 93 deletions

View File

@ -1,17 +1,25 @@
<template> <template>
<div class="alert alert-primary" role="alert"> <div class="alert alert-primary" role="alert">
<h3>Login as Admin!</h3> <h3>{{message.title}}</h3>
<span class="mb-3">This is the Demo Statping instance, the database gets reset every 30 minutes. Login as "admin" password is "admin".</span> <span class="mb-3">{{message.description}}</span>
<div class="d-block mt-2 mb-4"> <div class="d-block mt-2 mb-4">
<span class="float-left small">Starts on Tuesday January 8, 2019 at 08:00PM</span> <span class="float-left small">
<span class="float-right small">Ends on Thursday May 12, 2022 at 07:00PM</span> Starts on {{parseTime(message.start_on)}}
</span>
<span class="float-right small">
Ends on {{parseTime(message.end_on)}}</span>
</div> </div>
</div> </div>
</template> </template>
<script> <script>
export default { export default {
name: 'MessageBlock' name: 'MessageBlock',
props: {
message: {
type: Object
}
}
} }
</script> </script>

View File

@ -146,18 +146,11 @@
</div> </div>
</div> </div>
<div class="form-group row"> <div class="form-group row">
<div class="col-6"> <div class="col-12">
<button @click.prevent="saveService" type="submit" class="btn btn-success btn-block">Create Service</button> <button @click.prevent="saveService" type="submit" class="btn btn-success btn-block">Create Service</button>
</div> </div>
<div class="col-6">
<button @click.prevent="saveService" class="btn btn-secondary btn-block">Test</button>
</div>
</div> </div>
<div class="alert alert-danger d-none" id="alerter" role="alert"></div> <div class="alert alert-danger d-none" id="alerter" role="alert"></div>
{{JSON.stringify(service)}}
</form> </form>
</template> </template>

View File

@ -5,9 +5,26 @@ export default Vue.mixin({
now() { now() {
return Math.round(new Date().getTime() / 1000) return Math.round(new Date().getTime() / 1000)
}, },
current() {
return new Date()
},
ago(seconds) { ago(seconds) {
return this.now() - seconds return this.now() - seconds
}, },
niceDate(val) {
return this.parseTime(val).format('LLLL')
},
parseTime(val) {
return this.$moment(val, "YYYY-MM-DDTHH:mm:ssZ", true).local()
},
toUnix(val) {
return this.$moment(val).utc().format('MM-DD-YYYY')
},
isBetween(t1, t2) {
const now = this.$moment(t1).utc().valueOf()
const sub = this.$moment(t2).utc().valueOf()
return (now - sub) > 0
},
hour(){ return 3600 }, hour(){ return 3600 },
day() { return 3600 * 24 }, day() { return 3600 * 24 },
serviceLink(service) { serviceLink(service) {

View File

@ -1,32 +1,8 @@
<template> <template>
<div class="col-12 bg-white p-4">
Help
</div>
</template> </template>
<script> <script>
export default { export default {
name: 'Help', name: 'Help',
components: {
},
data () {
return {
}
},
created() {
},
mounted() {
},
methods: {
}
} }
</script> </script>
<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
</style>

View File

@ -7,8 +7,8 @@
<Group :group=group /> <Group :group=group />
</div> </div>
<div class="col-12"> <div v-for="(message, index) in $store.getters.messages" v-bind:key="index" v-if="inRange(message) && message.service === 0">
<MessageBlock/> <MessageBlock :message="message"/>
</div> </div>
<div class="col-12 full-col-12"> <div class="col-12 full-col-12">
@ -47,7 +47,11 @@ export default {
}, },
methods: { methods: {
inRange(message) {
const start = this.isBetween(new Date(), message.start_on)
const end = this.isBetween(message.end_on, new Date())
return start && end
},
} }
} }
</script> </script>

View File

@ -28,12 +28,16 @@
</div> </div>
</div> </div>
<div v-for="(message, index) in messages" v-if="messageInRange(message)">
<MessageBlock :message="message"/>
</div>
<div class="service-chart-container"> <div class="service-chart-container">
<apexchart width="100%" height="215" type="area" :options="chartOptions" :series="series"></apexchart> <apexchart width="100%" height="420" type="area" :options="chartOptions" :series="series"></apexchart>
</div> </div>
<div class="service-chart-heatmap"> <div class="service-chart-heatmap">
<div id="service_heatmap"></div> <apexchart width="100%" height="215" type="heatmap" :options="chartOptions" :series="series"></apexchart>
</div> </div>
<form id="service_date_form" class="col-12 mt-2 mb-3"> <form id="service_date_form" class="col-12 mt-2 mb-3">
@ -104,17 +108,18 @@
<script> <script>
import Api from "../components/API" import Api from "../components/API"
import MessageBlock from '../components/Index/MessageBlock';
import Checkin from "../forms/Checkin"; import Checkin from "../forms/Checkin";
const axisOptions = { const axisOptions = {
labels: { labels: {
show: false show: true
}, },
crosshairs: { crosshairs: {
show: false show: false
}, },
lines: { lines: {
show: false show: true
}, },
tooltip: { tooltip: {
enabled: false enabled: false
@ -133,6 +138,7 @@
export default { export default {
name: 'Service', name: 'Service',
components: { components: {
MessageBlock,
Checkin Checkin
}, },
data () { data () {
@ -143,6 +149,7 @@ export default {
authenticated: false, authenticated: false,
ready: false, ready: false,
data: null, data: null,
messages: [],
failures: [], failures: [],
chartOptions: { chartOptions: {
chart: { chart: {
@ -171,7 +178,7 @@ export default {
top: 0, top: 0,
right: 0, right: 0,
bottom: 0, bottom: 0,
left: -10, left: 0,
} }
}, },
xaxis: { xaxis: {
@ -221,19 +228,25 @@ export default {
} }
}, },
async created() { async created() {
this.id = this.$route.params.id await this.$store.dispatch('loadRequired')
},
async mounted() {
const id = this.$route.params.id
let service; let service;
if (this.isInt(this.id)) { if (this.isInt(id)) {
service = this.$store.getters.serviceById(this.id) service = await Api.service(id)
} else { } else {
service = this.$store.getters.serviceByPermalink(this.id) service = this.$store.getters.serviceByPermalink(this.id)
} }
await this.getService(service) await this.getService(service)
this.messages = this.$store.getters.serviceMessages(service.id)
}, },
mounted() {
},
methods: { methods: {
messageInRange(message) {
const start = this.isBetween(new Date(), message.start_on)
const end = this.isBetween(message.end_on, new Date())
return start && end
},
async getService(s) { async getService(s) {
this.service = await Api.service(s.id) this.service = await Api.service(s.id)
await this.chartHits() await this.chartHits()

View File

@ -89,7 +89,6 @@ router.beforeEach((to, from, next) => {
return return
} }
next() next()
return
} else { } else {
next() next()
} }

View File

@ -41,7 +41,7 @@ export default new Vuex.Store({
integrations: state => state.integrations, integrations: state => state.integrations,
servicesInOrder: state => state.services.sort((a, b) => a.order_id - b.order_id), servicesInOrder: state => state.services.sort((a, b) => a.order_id - b.order_id),
groupsInOrder: state => state.groups.sort((a, b) => a.order_id - b.order_id), groupsInOrder: state => state.groups.sort((a, b) => a.order_id - b.order_id),
groupsClean: state => state.groups.filter(g => g.name !== '').sort((a, b) => a.order_id - b.order_id), groupsClean: state => state.groups.filter(g => g.name !== '').sort((a, b) => a.order_id - b.order_id),
serviceById: (state) => (id) => { serviceById: (state) => (id) => {
@ -53,6 +53,9 @@ export default new Vuex.Store({
servicesInGroup: (state) => (id) => { servicesInGroup: (state) => (id) => {
return state.services.filter(s => s.group_id === id).sort((a, b) => a.order_id - b.order_id) return state.services.filter(s => s.group_id === id).sort((a, b) => a.order_id - b.order_id)
}, },
serviceMessages: (state) => (id) => {
return state.messages.filter(s => s.service === id)
},
onlineServices: (state) => (online) => { onlineServices: (state) => (online) => {
return state.services.filter(s => s.online === online) return state.services.filter(s => s.online === online)
}, },
@ -60,7 +63,7 @@ export default new Vuex.Store({
return state.groups.find(g => g.id === id) return state.groups.find(g => g.id === id)
}, },
cleanGroups: (state) => () => { cleanGroups: (state) => () => {
return state.groups.filter(g => g.name !== '').sort((a, b) => a.order_id - b.order_id) return state.groups.filter(g => g.name !== '').sort((a, b) => a.order_id - b.order_id)
}, },
userById: (state) => (id) => { userById: (state) => (id) => {
return state.users.find(u => u.id === id) return state.users.find(u => u.id === id)
@ -70,57 +73,57 @@ export default new Vuex.Store({
}, },
}, },
mutations: { mutations: {
setHasAllData(state, bool) { setHasAllData (state, bool) {
state.hasAllData = bool state.hasAllData = bool
}, },
setHasPublicData(state, bool) { setHasPublicData (state, bool) {
state.hasPublicData = bool state.hasPublicData = bool
}, },
setCore(state, core) { setCore (state, core) {
state.core = core state.core = core
}, },
setToken(state, token) { setToken (state, token) {
state.token = token state.token = token
}, },
setServices(state, services) { setServices (state, services) {
state.services = services state.services = services
}, },
setGroups(state, groups) { setGroups (state, groups) {
state.groups = groups state.groups = groups
}, },
setMessages(state, messages) { setMessages (state, messages) {
state.messages = messages state.messages = messages
}, },
setUsers(state, users) { setUsers (state, users) {
state.users = users state.users = users
}, },
setNotifiers(state, notifiers) { setNotifiers (state, notifiers) {
state.notifiers = notifiers state.notifiers = notifiers
}, },
setIntegrations(state, integrations) { setIntegrations (state, integrations) {
state.integrations = integrations state.integrations = integrations
} }
}, },
actions: { actions: {
async loadRequired(context) { async loadRequired (context) {
const core = await Api.core() const core = await Api.core()
context.commit("setCore", core); context.commit("setCore", core);
const services = await Api.services() const services = await Api.services()
context.commit("setServices", services); context.commit("setServices", services);
const groups = await Api.groups() const groups = await Api.groups()
context.commit("setGroups", groups); context.commit("setGroups", groups);
const messages = await Api.messages() const messages = await Api.messages()
context.commit("setMessages", messages) context.commit("setMessages", messages)
context.commit("setHasPublicData", true) context.commit("setHasPublicData", true)
}, },
async loadAdmin(context) { async loadAdmin (context) {
await context.dispatch('loadRequired') await context.dispatch('loadRequired')
const notifiers = await Api.notifiers() const notifiers = await Api.notifiers()
context.commit("setNotifiers", notifiers); context.commit("setNotifiers", notifiers);
const users = await Api.users() const users = await Api.users()
context.commit("setUsers", users); context.commit("setUsers", users);
const integrations = await Api.integrations() const integrations = await Api.integrations()
context.commit("setIntegrations", integrations); context.commit("setIntegrations", integrations);
} }
} }
}); });

View File

@ -57,7 +57,7 @@ func main() {
utils.DeleteDirectory("./statping.wiki") utils.DeleteDirectory("./statping.wiki")
utils.DeleteDirectory("./logs") utils.DeleteDirectory("./logs")
f, err := os.Create("wiki.go") f, err := os.Create("../frontend/src/pages/Help.vue")
die(err) die(err)
defer f.Close() defer f.Close()
@ -80,12 +80,12 @@ func die(err error) {
} }
} }
var packageTemplate = template.Must(template.New("").Parse(`// Code generated by go generate; DO NOT EDIT. var packageTemplate = template.Must(template.New("").Parse(`<template>
// This file was generated by robots at <div class="col-12 bg-white p-4" v-html={{printf "%q" .Compiled}}></div>
// {{ .Timestamp }} </template>
//
// This contains the most recently Markdown source for the Statping Wiki.
package source
// CompiledWiki contains all of the Statping Wiki pages from the Github Wiki repo. <script>
var CompiledWiki = []byte({{printf "%q" .Compiled}})`)) export default {
name: 'Help',
}
</script>`))