Changeset View
Changeset View
Standalone View
Standalone View
src/resources/js/app.js
Show All 26 Lines | data() { | ||||
} | } | ||||
}, | }, | ||||
methods: { | methods: { | ||||
// Clear (bootstrap) form validation state | // Clear (bootstrap) form validation state | ||||
clearFormValidation(form) { | clearFormValidation(form) { | ||||
$(form).find('.is-invalid').removeClass('is-invalid') | $(form).find('.is-invalid').removeClass('is-invalid') | ||||
$(form).find('.invalid-feedback').remove() | $(form).find('.invalid-feedback').remove() | ||||
}, | }, | ||||
hasRoute(name) { | |||||
return this.$router.resolve({ name: name }).resolved.matched.length > 0 | |||||
}, | |||||
isController(wallet_id) { | isController(wallet_id) { | ||||
if (wallet_id && store.state.authInfo) { | if (wallet_id && store.state.authInfo) { | ||||
let i | let i | ||||
for (i = 0; i < store.state.authInfo.wallets.length; i++) { | for (i = 0; i < store.state.authInfo.wallets.length; i++) { | ||||
if (wallet_id == store.state.authInfo.wallets[i].id) { | if (wallet_id == store.state.authInfo.wallets[i].id) { | ||||
return true | return true | ||||
} | } | ||||
} | } | ||||
Show All 36 Lines | methods: { | ||||
this.refreshTimeout = setTimeout(() => { | this.refreshTimeout = setTimeout(() => { | ||||
axios.post('/api/auth/refresh').then(response => { | axios.post('/api/auth/refresh').then(response => { | ||||
this.loginUser(response.data, false, true) | this.loginUser(response.data, false, true) | ||||
}) | }) | ||||
}, timeout * 1000) | }, timeout * 1000) | ||||
}, | }, | ||||
// 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) { | |||||
if (this.hasRoute('login')) { | |||||
this.$router.push({ name: 'login' }) | this.$router.push({ name: 'login' }) | ||||
} | |||||
} | |||||
clearTimeout(this.refreshTimeout) | clearTimeout(this.refreshTimeout) | ||||
}, | }, | ||||
// 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) { | ||||
Show All 34 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 113 Lines • ▼ Show 20 Lines | window.axios.interceptors.response.use( | ||||
response => { | response => { | ||||
// Do nothing | // Do nothing | ||||
return response | return response | ||||
}, | }, | ||||
error => { | error => { | ||||
let error_msg | let error_msg | ||||
let status = error.response ? error.response.status : 200 | let status = error.response ? error.response.status : 200 | ||||
// Do not display the error in a toast message, pass the error as-is | |||||
if (error.config.ignoreErrors) { | |||||
return Promise.reject(error) | |||||
} | |||||
if (error.response && status == 422) { | if (error.response && status == 422) { | ||||
error_msg = "Form validation error" | error_msg = "Form validation error" | ||||
const modal = $('div.modal.show') | const modal = $('div.modal.show') | ||||
$(modal.length ? modal : 'form').each((i, form) => { | $(modal.length ? modal : 'form').each((i, form) => { | ||||
form = $(form) | form = $(form) | ||||
▲ Show 20 Lines • Show All 59 Lines • Show Last 20 Lines |