Created
April 16, 2018 15:43
-
-
Save acacha/4b532a3aa5215f8a478dacb99ff4aacf to your computer and use it in GitHub Desktop.
Laravel resources/assets/js/app.js file with Vuetify and Vuex with Auth scaffolding components
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
/** | |
* First we will load all of this project's JavaScript dependencies which | |
* includes Vue and other libraries. It is a great starting point when | |
* building robust, powerful web applications using Vue and Laravel. | |
*/ | |
require('./bootstrap'); | |
window.Vue = require('vue'); | |
/** | |
* Next, we will create a fresh Vue application instance and attach it to | |
* the page. Then, you may begin adding components to this application | |
* or customize the JavaScript scaffolding to fit your unique needs. | |
*/ | |
Vue.component('login-button', require('./components/LoginButtonComponent.vue')); | |
Vue.component('register-button', require('./components/RegisterButtonComponent.vue')); | |
Vue.component('remember-password', require('./components/RememberPasswordComponent.vue')); | |
Vue.component('reset-password', require('./components/ResetPasswordComponent.vue')); | |
Vue.component('snackbar', require('./components/SnackBarComponent.vue')); | |
Vue.component('gravatar', require('./components/GravatarComponent.vue')); | |
window.Vuetify = require('vuetify'); | |
Vue.use(Vuetify) | |
import store from './store' | |
import * as actions from './store/action-types' | |
import * as mutations from './store/mutation-types' | |
import { mapGetters } from 'vuex' | |
import withSnackbar from './components/mixins/withSnackbar' | |
if (window.user) { | |
store.commit(mutations.USER, user) | |
store.commit(mutations.LOGGED, true) | |
} | |
const app = new Vue({ | |
el: '#app', | |
store, | |
mixins: [ withSnackbar ], | |
data: () => ({ | |
drawer: null, | |
drawerRight: false, | |
editingUser: false, | |
logoutLoading: false, | |
changingPassword: false, | |
updatingUser: false, | |
items: [ | |
{ icon: 'home', text: 'Home', href: '/home' }, | |
{ icon: 'home', text: 'Landing Page', href: '/' }, | |
{ icon: 'settings', text: 'Settings' }, | |
{ icon: 'chat_bubble', text: 'Contact' }, | |
{ heading: 'Links' }, | |
{ icon: 'link', text: 'Google', href: 'http://www.google.com' } | |
// { heading: 'Administració', role: 'Manager' } | |
] | |
}), | |
computed: { | |
...mapGetters({ | |
user: 'user' | |
}) | |
}, | |
methods: { | |
editUser () { | |
this.editingUser = true | |
this.$nextTick(this.$refs.email.focus) | |
}, | |
updateUser () { | |
this.updatingUser = true | |
this.$store.dispatch(actions.UPDATE_USER, this.user).then(response => { | |
this.showMessage('User modified ok!') | |
}).catch(error => { | |
console.dir(error) | |
this.showError(error) | |
}).then(() => { | |
this.editingUser = false | |
this.updatingUser = false | |
}) | |
}, | |
updateEmail (email) { | |
this.$store.commit(mutations.USER, {...this.user, email}) | |
}, | |
updateName (name) { | |
this.$store.commit(mutations.USER, {...this.user, name}) | |
}, | |
toogleRightDrawer () { | |
this.drawerRight = !this.drawerRight | |
}, | |
checkRoles (item) { | |
if (item.role) { | |
return this.$store.getters.roles.find(function (role) { | |
return role == item.role // eslint-disable-line | |
}) | |
} | |
return true | |
}, | |
logout () { | |
this.logoutLoading = true | |
this.$store.dispatch(actions.LOGOUT).then(response => { | |
window.location = '/' | |
}).catch(error => { | |
console.log(error) | |
}).then(() => { | |
this.logoutLoading = false | |
}) | |
}, | |
menuItemSelected (item) { | |
if (item.href) { | |
if (item.new) { | |
window.open(item.href) | |
} else { | |
window.location.href = item.href | |
} | |
} | |
}, | |
changePassword () { | |
this.changingPassword = true | |
this.$store.dispatch(actions.REMEMBER_PASSWORD, this.user.email).then(response => { | |
this.showMessage(`Email sent to change password`) | |
}).catch(error => { | |
console.dir(error) | |
this.showError(error) | |
}).then(() => { | |
this.changingPassword = false | |
}) | |
} | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment