-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
283 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
# This is the base URL used for axios API calls in nuxt.config.js | ||
BASE_API_URL=http://127.0.0.1:3000/api | ||
|
||
# This is the time minimum time of inactivity in minutes, | ||
# after which user will logged out from the app | ||
IDLE_TIMEOUT=30 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
<template> | ||
<div class="text-center"> | ||
<header class="modal-card-head"> | ||
<h1 class="modal-card-title h2 mb-0"> | ||
{{ title }} | ||
</h1> | ||
</header> | ||
<section class="modal-card-body"> | ||
<p v-if="!isLoggedOut"> | ||
Your session is about to expire in {{ seconds }} seconds | ||
</p> | ||
<p v-else> | ||
Your session has expired. | ||
</p> | ||
</section> | ||
<footer class="modal-card-foot"> | ||
<div class="buttons is-right width-100"> | ||
<template v-if="!isLoggedOut"> | ||
<button | ||
class="button mr-2" | ||
type="button" | ||
@click="logOut" | ||
> | ||
Log out | ||
</button> | ||
<button | ||
class="button is-info" | ||
type="button" | ||
@click="continueSession" | ||
> | ||
Continue session | ||
</button> | ||
</template> | ||
<button | ||
v-else | ||
class="button is-info" | ||
type="button" | ||
@click="close" | ||
> | ||
OK | ||
</button> | ||
</div> | ||
</footer> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
const TIME = 60 | ||
export default { | ||
name: 'IdleModal', | ||
props: { | ||
dialog: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
data () { | ||
return { | ||
timer: '', | ||
seconds: TIME, | ||
isLoggedOut: false | ||
} | ||
}, | ||
computed: { | ||
isIdle () { | ||
return this.$store.state.idleVue.isIdle | ||
}, | ||
title () { | ||
return this.isLoggedOut ? 'Session expired' : 'Session about to expire' | ||
} | ||
}, | ||
created () { | ||
this.timer = setInterval(this.countDown, 1000) | ||
}, | ||
beforeDestroy () { | ||
clearInterval(this.timer) | ||
this.$store.commit('idleVue/SET_IS_IDLE', false) | ||
}, | ||
methods: { | ||
countDown () { | ||
this.seconds -= 1 | ||
if (!this.isIdle) { | ||
clearInterval(this.timer) | ||
} | ||
if (this.seconds < 1) { | ||
this.logOut() | ||
} | ||
}, | ||
close () { | ||
this.$emit('close') | ||
}, | ||
continueSession () { | ||
this.seconds = TIME | ||
this.$store.commit('idleVue/SET_IS_IDLE', false) | ||
clearInterval(this.timer) | ||
}, | ||
logOut (event) { | ||
clearInterval(this.timer) | ||
this.isLoggedOut = true | ||
this.$auth.logout() | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
<template> | ||
<div | ||
:class="{ 'is-active': visible }" | ||
class="modal" | ||
> | ||
<div class="modal-background" /> | ||
<!-- eslint-disable-next-line vue/require-component-is --> | ||
<div class="modal-card"> | ||
<component | ||
:is="component" | ||
v-if="component" | ||
v-bind="props" | ||
@close="close" | ||
/> | ||
<slot v-else /> | ||
<!-- eslint-enable-next-line vue/require-component-is --> | ||
</div> | ||
<button class="modal-close is-large" aria-label="close" /> | ||
</div> | ||
</template> | ||
|
||
<script> | ||
export default { | ||
name: 'Modal', | ||
props: { | ||
component: { | ||
type: Object, | ||
default: () => {} | ||
}, | ||
props: { | ||
type: Object, | ||
default: () => {} | ||
}, | ||
programmatic: { | ||
type: Boolean, | ||
default: false | ||
} | ||
}, | ||
data () { | ||
return { | ||
visible: true | ||
} | ||
}, | ||
beforeMount () { | ||
// Insert the Modal component in body tag | ||
this.programmatic && document.body.appendChild(this.$el) | ||
}, | ||
methods: { | ||
close () { | ||
if (this.programmatic) { | ||
this.visible = false | ||
setTimeout(() => { | ||
this.removeElement() | ||
this.$destroy() | ||
}, 150) | ||
} | ||
}, | ||
removeElement () { | ||
// Removes Modal component in body tag, to stop duplications | ||
this.$el.parentNode.removeChild(this.$el) | ||
} | ||
} | ||
} | ||
</script> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
import Vue from 'vue' | ||
import Modal from './modal.js' | ||
Vue.use(Modal) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import Vue from 'vue' | ||
import Modal from './Modal.vue' | ||
|
||
const ModalProgrammatic = { | ||
open (params) { | ||
let parent | ||
const ModalComponent = Vue.extend(Modal) | ||
|
||
if (params.parent) { | ||
parent = params.parent | ||
delete params.parent | ||
} | ||
|
||
return new ModalComponent({ | ||
parent, | ||
el: document.createElement('div'), | ||
propsData: { | ||
programmatic: true, | ||
...params | ||
} | ||
}) | ||
} | ||
} | ||
|
||
const Plugin = { | ||
install () { | ||
Vue.prototype.$modal = ModalProgrammatic | ||
Vue.component('modal', Modal) | ||
} | ||
} | ||
|
||
export default Plugin |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import IdleVue from 'idle-vue' | ||
import Vue from 'vue' | ||
|
||
const eventsHub = new Vue() | ||
|
||
Vue.use(IdleVue, { | ||
eventEmitter: eventsHub, | ||
idleTime: (process.env.IDLE_TIMEOUT || 20) * 60 * 1000, // default: 20 mins | ||
// idleTime: 3 * 1000, // 3 seconds, | ||
startAtIdle: false | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const state = () => ({ | ||
isIdle: false | ||
}) | ||
|
||
const mutations = { | ||
SET_IS_IDLE (state, data) { | ||
state.isIdle = data | ||
} | ||
} | ||
|
||
export default { | ||
state, | ||
mutations | ||
} |