Skip to content

Commit

Permalink
modal for UI confirmations
Browse files Browse the repository at this point in the history
  • Loading branch information
hunterlong committed Sep 2, 2020
1 parent 1c57f5a commit eb9792d
Show file tree
Hide file tree
Showing 14 changed files with 227 additions and 55 deletions.
2 changes: 1 addition & 1 deletion frontend/config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ const webpackConfig = merge(commonConfig, {
threshold: 10240,
minRatio: 0.8
}),
new webpack.HashedModuleIdsPlugin(),
// new webpack.HashedModuleIdsPlugin(),
new HtmlPlugin({
template: 'public/base.gohtml',
filename: 'base.gohtml',
Expand Down
28 changes: 28 additions & 0 deletions frontend/src/assets/scss/layout.scss
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,34 @@ A:HOVER {
color: lighten($text-color, 12%) !important;
}

.modal-backdrop {
top: 0;
left: 0;
position: absolute;
display: block;
z-index: 10000;
width: 100%;
height: 100%;
background-color: #00000073;
}

.modal {
z-index: 999999 !important;
display: block;
}

.modal-dialog {
top: 20%;
}

.modal-header {
padding: 0.5rem 1rem;
}

.modal-footer {
padding: 0.5rem 1rem;
}

.text-muted {
color: lighten($text-color, 30%) !important;
}
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/components/Dashboard/DashboardMessages.vue
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,21 @@
serviceName (service) {
return service.name || "Global Message"
},
async delete(m) {
await Api.message_delete(m.id)
const messages = await Api.messages()
this.$store.commit('setMessages', messages)
},
async deleteMessage(m) {
let c = confirm(`Are you sure you want to delete message '${m.title}'?`)
if (c) {
await Api.message_delete(m.id)
const messages = await Api.messages()
this.$store.commit('setMessages', messages)
const modal = {
visible: true,
title: "Delete Announcement",
body: `Are you sure you want to delete Announcement ${m.title}?`,
btnColor: "btn-danger",
btnText: "Delete Announcement",
func: () => this.delete(m),
}
this.$store.commit("setModal", modal)
}
}
}
Expand Down
26 changes: 20 additions & 6 deletions frontend/src/components/Dashboard/DashboardServices.vue
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<template>
<div class="col-12">

<div class="card contain-card mb-4">
<div class="card-header">{{ $t('top_nav.services') }}
<router-link v-if="$store.state.admin" to="/dashboard/create_service" class="btn btn-sm btn-success float-right">
Expand Down Expand Up @@ -67,6 +68,7 @@
</template>

<script>
const Modal = () => import(/* webpackChunkName: "dashboard" */ "@/components/Elements/Modal")
const FormGroup = () => import(/* webpackChunkName: "dashboard" */ '@/forms/Group')
const ToggleSwitch = () => import(/* webpackChunkName: "dashboard" */ '@/forms/ToggleSwitch')
const ServicesList = () => import(/* webpackChunkName: "dashboard" */ '@/components/Dashboard/ServicesList')
Expand All @@ -76,6 +78,7 @@
export default {
name: 'DashboardServices',
components: {
Modal,
ServicesList,
ToggleSwitch,
FormGroup,
Expand Down Expand Up @@ -112,13 +115,24 @@
this.group = g
this.edit = !mode
},
confirm_delete(service) {
},
async delete(g) {
await Api.group_delete(g.id)
const groups = await Api.groups()
this.$store.commit('setGroups', groups)
},
async deleteGroup(g) {
let c = confirm(`Are you sure you want to delete '${g.name}'?`)
if (c) {
await Api.group_delete(g.id)
const groups = await Api.groups()
this.$store.commit('setGroups', groups)
}
const modal = {
visible: true,
title: "Delete Group",
body: `Are you sure you want to delete group ${g.name}? All services attached will be removed from this group.`,
btnColor: "btn-danger",
btnText: "Delete Group",
func: () => this.delete(g),
}
this.$store.commit("setModal", modal)
}
}
}
Expand Down
18 changes: 13 additions & 5 deletions frontend/src/components/Dashboard/DashboardUsers.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,13 +74,21 @@
this.user = u
this.edit = !mode
},
async delete(u) {
await Api.user_delete(u.id)
const users = await Api.users()
this.$store.commit('setUsers', users)
},
async deleteUser(u) {
let c = confirm(`Are you sure you want to delete user '${u.username}'?`)
if (c) {
await Api.user_delete(u.id)
const users = await Api.users()
this.$store.commit('setUsers', users)
const modal = {
visible: true,
title: "Delete User",
body: `Are you sure you want to delete user ${u.username}?`,
btnColor: "btn-danger",
btnText: "Delete User",
func: () => this.delete(u),
}
this.$store.commit("setModal", modal)
}
}
}
Expand Down
20 changes: 14 additions & 6 deletions frontend/src/components/Dashboard/Failures.vue
Original file line number Diff line number Diff line change
Expand Up @@ -151,14 +151,22 @@ export default {
await this.gotoPage(1)
},
methods: {
async delete() {
await Api.service_failures_delete(this.service)
this.service = await Api.service(this.service.id)
this.total = 0
await this.load()
},
async deleteFailures() {
const c = confirm('Are you sure you want to delete all failures?')
if (c) {
await Api.service_failures_delete(this.service)
this.service = await Api.service(this.service.id)
this.total = 0
await this.load()
const modal = {
visible: true,
title: "Delete All Failures",
body: `Are you sure you want to delete all Failures for service ${this.service.title}?`,
btnColor: "btn-danger",
btnText: "Delete Failures",
func: () => this.delete(),
}
this.$store.commit("setModal", modal)
},
async gotoPage(page) {
this.page = page;
Expand Down
24 changes: 16 additions & 8 deletions frontend/src/components/Dashboard/Incidents.vue
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,23 @@ const FormIncidentUpdates = () => import(/* webpackChunkName: "dashboard" */ '@/
methods: {
async delete(i) {
this.res = await Api.incident_delete(i)
if (this.res.status === "success") {
this.incidents = this.incidents.filter(obj => obj.id !== i.id);
//await this.loadIncidents()
}
},
async deleteIncident(incident) {
let c = confirm(`Are you sure you want to delete '${incident.title}'?`)
if (c) {
this.res = await Api.incident_delete(incident)
if (this.res.status === "success") {
this.incidents = this.incidents.filter(obj => obj.id !== incident.id); // this is better in terms of not having to querry the db to get a fresh copy of all updates
//await this.loadIncidents()
} // TODO: further error checking here... maybe alert user it failed with modal or so
}
const modal = {
visible: true,
title: "Delete Incident",
body: `Are you sure you want to delete Incident ${incident.title}?`,
btnColor: "btn-danger",
btnText: "Delete Incident",
func: () => this.delete(incident),
}
this.$store.commit("setModal", modal)
},
async createIncident() {
Expand Down
27 changes: 20 additions & 7 deletions frontend/src/components/Dashboard/ServicesList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,14 @@
<script>
import Api from "../../API";
import ServiceSparkList from "@/components/Service/ServiceSparkList";
import Modal from "@/components/Elements/Modal";
const draggable = () => import(/* webpackChunkName: "dashboard" */ 'vuedraggable')
const ToggleSwitch = () => import(/* webpackChunkName: "dashboard" */ '../../forms/ToggleSwitch');
export default {
name: 'ServicesList',
components: {
Modal,
ServiceSparkList,
ToggleSwitch,
draggable
Expand Down Expand Up @@ -159,14 +161,25 @@ export default {
await Api.services_reorder(data)
await this.update()
},
tester(s) {
console.log(s)
},
async delete(s) {
this.loading = true
await Api.service_delete(s.id)
await this.update()
this.loading = false
},
async deleteService(s) {
let c = confirm(`Are you sure you want to delete '${s.name}'?`)
if (c) {
this.loading = true
await Api.service_delete(s.id)
await this.update()
this.loading = false
}
const modal = {
visible: true,
title: "Delete Service",
body: `Are you sure you want to delete service ${s.name}? This will also delete all failures, checkins, and incidents for this service.`,
btnColor: "btn-danger",
btnText: "Delete Service",
func: () => this.delete(s),
}
this.$store.commit("setModal", modal)
},
serviceGroup(s) {
let group = this.$store.getters.groupById(s.group_id)
Expand Down
22 changes: 15 additions & 7 deletions frontend/src/components/Dashboard/ThemeEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -144,14 +144,22 @@ import('codemirror/mode/css/css.js')
this.pending = false
await this.fetchTheme()
},
async delete() {
this.pending = true
const resp = await Api.theme_generate(false)
await this.fetchTheme()
this.pending = false
},
async deleteAssets() {
this.pending = true
let c = confirm('Are you sure you want to delete all local assets?')
if (c) {
const resp = await Api.theme_generate(false)
await this.fetchTheme()
}
this.pending = false
const modal = {
visible: true,
title: "Delete Local Assets",
body: `Are you sure you want to delete all local assets?`,
btnColor: "btn-danger",
btnText: "Delete",
func: () => this.delete(),
}
this.$store.commit("setModal", modal)
},
async saveAssets() {
this.pending = true
Expand Down
50 changes: 50 additions & 0 deletions frontend/src/components/Elements/Modal.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
<template>
<div v-if="modal.visible" class="modal d-block" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">{{modal.title}}</h5>
</div>
<div class="modal-body">
<p>{{modal.body}}</p>
</div>
<div class="modal-footer">
<button @click.prevent="close" type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button @click.prevent="runFunc" type="button" :class="`btn ${modal.btnColor}`">{{modal.btnText}}</button>
</div>
</div>
</div>
</div>
</template>

<script>
export default {
name: "Modal",
data () {
return {
}
},
computed: {
modal() {
return this.$store.getters.modal
}
},
mounted() {
},
methods: {
runFunc() {
this.$store.getters.modal.func()
this.close()
},
close() {
this.$store.commit("setModal", {visible: false})
}
}
}
</script>

<style scoped>
</style>
4 changes: 2 additions & 2 deletions frontend/src/forms/Notifier.vue
Original file line number Diff line number Diff line change
Expand Up @@ -149,11 +149,11 @@

<div v-for="(log, i) in notifier.logs.reverse()" class="alert" :class="{'alert-danger': log.error, 'alert-dark': !log.success && !log.error, 'alert-success': log.success && !log.error}">
<span class="d-block">
Service '{{$store.getters.serviceById(log.service).name}}'
Service {{log.service}}
{{log.success ? "Success Triggered" : "Failure Triggered"}}
</span>

<div class="bg-white p-3 small mt-2">
<div v-if="log.message !== ''" class="bg-white p-3 small mt-2">
<code>{{log.message}}</code>
</div>

Expand Down
7 changes: 7 additions & 0 deletions frontend/src/pages/Dashboard.vue
Original file line number Diff line number Diff line change
@@ -1,16 +1,20 @@
<template>
<div class="container col-md-7 col-sm-12 mt-md-5">
<div v-if="modal" class="modal-backdrop"></div>
<Modal/>
<TopNav :admin="admin"/>
<router-view :admin="admin"/>
</div>
</template>

<script>
import Modal from "@/components/Elements/Modal";
const TopNav = () => import(/* webpackChunkName: "dashboard" */ '@/components/Dashboard/TopNav')
export default {
name: 'Dashboard',
components: {
Modal,
TopNav,
},
data () {
Expand All @@ -20,6 +24,9 @@
}
},
computed: {
modal() {
return this.$store.getters.modal.visible
},
admin() {
return this.$store.getters.admin
},
Expand Down
Loading

0 comments on commit eb9792d

Please sign in to comment.