Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/app.js
Show First 20 Lines • Show All 57 Lines • ▼ Show 20 Lines | methods: { | ||||
if (dashboard !== false) { | if (dashboard !== false) { | ||||
this.$router.push(store.state.afterLogin || { name: 'dashboard' }) | this.$router.push(store.state.afterLogin || { name: 'dashboard' }) | ||||
} | } | ||||
store.state.afterLogin = null | store.state.afterLogin = null | ||||
}, | }, | ||||
// Set user state to "not logged in" | // Set user state to "not logged in" | ||||
logoutUser() { | logoutUser(redirect) { | ||||
store.commit('logoutUser') | store.commit('logoutUser') | ||||
localStorage.setItem('token', '') | localStorage.setItem('token', '') | ||||
delete axios.defaults.headers.common.Authorization | delete axios.defaults.headers.common.Authorization | ||||
if (redirect !== false) { | |||||
this.$router.push({ name: 'login' }) | this.$router.push({ name: 'login' }) | ||||
} | |||||
}, | }, | ||||
// Display "loading" overlay inside of the specified element | // Display "loading" overlay inside of the specified element | ||||
addLoader(elem) { | addLoader(elem) { | ||||
$(elem).css({position: 'relative'}).append($(loader).addClass('small')) | $(elem).css({position: 'relative'}).append($(loader).addClass('small')) | ||||
}, | }, | ||||
// Remove loader element added in addLoader() | // Remove loader element added in addLoader() | ||||
removeLoader(elem) { | removeLoader(elem) { | ||||
$(elem).find('.app-loader').remove() | $(elem).find('.app-loader').remove() | ||||
Show All 33 Lines | methods: { | ||||
$('#app').append(error_page) | $('#app').append(error_page) | ||||
}, | }, | ||||
errorHandler(error) { | errorHandler(error) { | ||||
this.stopLoading() | this.stopLoading() | ||||
if (!error.response) { | if (!error.response) { | ||||
// TODO: probably network connection error | // TODO: probably network connection error | ||||
} else if (error.response.status === 401) { | } else if (error.response.status === 401) { | ||||
if (!store.state.afterLogin && this.$router.currentRoute.name != 'login') { | |||||
store.state.afterLogin = this.$router.currentRoute | |||||
} | |||||
this.logoutUser() | this.logoutUser() | ||||
} else { | } else { | ||||
this.errorPage(error.response.status, error.response.statusText) | this.errorPage(error.response.status, error.response.statusText) | ||||
} | } | ||||
}, | }, | ||||
downloadFile(url) { | downloadFile(url) { | ||||
// TODO: This might not be a best way for big files as the content | // TODO: This might not be a best way for big files as the content | ||||
// will be stored (temporarily) in browser memory | // will be stored (temporarily) in browser memory | ||||
// TODO: This method does not show the download progress in the browser | // TODO: This method does not show the download progress in the browser | ||||
// but it could be implemented in the UI, axios has 'progress' property | // but it could be implemented in the UI, axios has 'progress' property | ||||
axios.get(url, { responseType: 'blob' }) | axios.get(url, { responseType: 'blob' }) | ||||
.then (response => { | .then(response => { | ||||
const link = document.createElement('a') | const link = document.createElement('a') | ||||
const contentDisposition = response.headers['content-disposition'] | const contentDisposition = response.headers['content-disposition'] | ||||
let filename = 'unknown' | let filename = 'unknown' | ||||
if (contentDisposition) { | if (contentDisposition) { | ||||
const match = contentDisposition.match(/filename="(.+)"/); | const match = contentDisposition.match(/filename="(.+)"/); | ||||
if (match.length === 2) { | if (match.length === 2) { | ||||
filename = match[1]; | filename = match[1]; | ||||
▲ Show 20 Lines • Show All 185 Lines • Show Last 20 Lines |