mirror of https://github.com/nocodb/nocodb
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
143 lines
4.6 KiB
143 lines
4.6 KiB
3 years ago
|
import dayjs from 'dayjs'
|
||
|
import duration from 'dayjs/plugin/duration'
|
||
|
|
||
|
dayjs.extend(duration)
|
||
|
|
||
3 years ago
|
export default async({ store, redirect, $axios, $toast, $api, route }) => {
|
||
3 years ago
|
// if (!route.path || !route.path.startsWith('/nc/')) { await store.dispatch('plugins/pluginPostInstall', 'Branding') }
|
||
4 years ago
|
if (window.location.search &&
|
||
|
/\bscope=|\bstate=/.test(window.location.search) &&
|
||
|
/\bcode=/.test(window.location.search)) {
|
||
4 years ago
|
try {
|
||
|
const tokenData = await $axios.create({
|
||
4 years ago
|
baseURL: $axios.defaults.baseURL
|
||
|
}).post(`/auth/${window.location.search.includes('state=github') ? 'github' : 'google'}/genTokenByCode${window.location.search}`)
|
||
4 years ago
|
|
||
4 years ago
|
store.commit('users/MutSetToken', tokenData.data.token)
|
||
|
await store.dispatch('users/ActGetUserDetails')
|
||
4 years ago
|
} catch (e) {
|
||
|
if (e.response && e.response.data && e.response.data.msg) {
|
||
4 years ago
|
$toast.error(e.response.data.msg).goAway(3000)
|
||
4 years ago
|
}
|
||
|
}
|
||
4 years ago
|
const newURL = window.location.href.split('?')[0]
|
||
|
window.history.pushState('object', document.title, newURL)
|
||
4 years ago
|
}
|
||
|
|
||
|
const icons = {
|
||
|
success: {
|
||
|
message: ' successful',
|
||
|
class: 'success',
|
||
|
icon: 'check_circle'
|
||
|
},
|
||
|
error: {
|
||
|
message: ' failed',
|
||
|
class: 'error',
|
||
|
icon: 'error'
|
||
|
}
|
||
4 years ago
|
}
|
||
4 years ago
|
|
||
|
store.watch(
|
||
4 years ago
|
(state) => {
|
||
|
return state.notification.list && state.notification.list[0] && state.notification.list[0].status
|
||
4 years ago
|
},
|
||
|
() => {
|
||
|
// console.log(store.state.notification.list)
|
||
4 years ago
|
const n = store.state.notification.list.length && store.state.notification.list[0]
|
||
4 years ago
|
if (n && n.status !== 'pending' && n.type !== 'List') {
|
||
3 years ago
|
const msg = `${n.type} ${n.module} ${icons[n.status].message}`
|
||
4 years ago
|
$toast[n.status](msg, {
|
||
|
duration: 2000,
|
||
|
icon: icons[n.status].icon
|
||
|
})
|
||
|
}
|
||
|
}
|
||
4 years ago
|
)
|
||
4 years ago
|
|
||
3 years ago
|
try {
|
||
|
await store.dispatch('project/ActLoadProjectInfo')
|
||
3 years ago
|
if (!store.state.project.appInfo.projectHasDb) {
|
||
3 years ago
|
redirect('/')
|
||
3 years ago
|
} else if (store.state.project.appInfo.projectHasAdmin === false) {
|
||
3 years ago
|
redirect('/')
|
||
|
}
|
||
|
} catch (e) {
|
||
|
console.log(e)
|
||
4 years ago
|
}
|
||
3 years ago
|
|
||
3 years ago
|
// fetch latest release info
|
||
|
const fetchReleaseInfo = async() => {
|
||
|
try {
|
||
2 years ago
|
const versionInfo = await $api.utils.appVersion()
|
||
2 years ago
|
if (versionInfo &&
|
||
|
versionInfo.releaseVersion &&
|
||
|
versionInfo.currentVersion &&
|
||
|
!(/[^0-9.]/.test(versionInfo.currentVersion))) {
|
||
2 years ago
|
store.commit('app/MutCurrentVersion', versionInfo.currentVersion)
|
||
2 years ago
|
store.commit('app/MutLatestRelease', versionInfo.releaseVersion)
|
||
3 years ago
|
} else {
|
||
2 years ago
|
store.commit('app/MutCurrentVersion', null)
|
||
3 years ago
|
store.commit('app/MutLatestRelease', null)
|
||
3 years ago
|
}
|
||
|
} catch (e) {
|
||
|
// ignore
|
||
|
}
|
||
|
}
|
||
|
|
||
2 years ago
|
fetchReleaseInfo()
|
||
3 years ago
|
setInterval(fetchReleaseInfo, 10 * 60 * 1000)
|
||
3 years ago
|
handleFeedbackForm({ store, $axios })
|
||
|
}
|
||
|
|
||
|
const handleFeedbackForm = async({ store, $axios }) => {
|
||
3 years ago
|
const fetchFeedbackForm = async(now) => {
|
||
3 years ago
|
try {
|
||
|
const { data: feedbackForm } = await $axios.get('/api/v1/feedback_form')
|
||
|
const currentFeedbackForm = store.state.settings.feedbackForm
|
||
|
|
||
3 years ago
|
const isFetchedFormDuplicate = currentFeedbackForm.url === feedbackForm.url
|
||
|
|
||
|
store.commit('settings/MutFeedbackForm', {
|
||
|
url: feedbackForm.url,
|
||
|
lastFormPollDate: now.toISOString(),
|
||
|
createdAt: feedbackForm.created_at,
|
||
|
isHidden: isFetchedFormDuplicate ? currentFeedbackForm.isHidden : false
|
||
|
})
|
||
3 years ago
|
} catch (e) {
|
||
|
// ignore
|
||
|
}
|
||
|
}
|
||
|
|
||
3 years ago
|
const isFirstTimePolling = !store.state.settings.feedbackForm.lastFormPollDate
|
||
|
|
||
|
const now = dayjs()
|
||
|
const lastFormPolledDate = dayjs(store.state.settings.feedbackForm.lastFormPollDate)
|
||
3 years ago
|
|
||
3 years ago
|
if (isFirstTimePolling || (dayjs.duration(now.diff(lastFormPolledDate)).days() > 0)) {
|
||
|
fetchFeedbackForm(now)
|
||
3 years ago
|
}
|
||
4 years ago
|
}
|
||
4 years ago
|
/**
|
||
|
* @copyright Copyright (c) 2021, Xgene Cloud Ltd
|
||
|
*
|
||
|
* @author Naveen MR <oof1lab@gmail.com>
|
||
|
* @author Pranav C Balan <pranavxc@gmail.com>
|
||
4 years ago
|
* @author Wing-Kam Wong <wingkwong.code@gmail.com>
|
||
4 years ago
|
*
|
||
|
* @license GNU AGPL version 3 or any later version
|
||
|
*
|
||
|
* This program is free software: you can redistribute it and/or modify
|
||
|
* it under the terms of the GNU Affero General Public License as
|
||
|
* published by the Free Software Foundation, either version 3 of the
|
||
|
* License, or (at your option) any later version.
|
||
|
*
|
||
|
* This program is distributed in the hope that it will be useful,
|
||
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
|
* GNU Affero General Public License for more details.
|
||
|
*
|
||
|
* You should have received a copy of the GNU Affero General Public License
|
||
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
*
|
||
4 years ago
|
*/
|