2018-06-24 04:20:35 +00:00
|
|
|
/* global siteConfig */
|
|
|
|
|
2017-05-21 03:21:16 +00:00
|
|
|
import Vue from 'vue'
|
2018-02-28 05:54:09 +00:00
|
|
|
import VueRouter from 'vue-router'
|
2017-05-22 17:32:52 +00:00
|
|
|
import VueClipboards from 'vue-clipboards'
|
2017-10-09 04:16:08 +00:00
|
|
|
import VeeValidate from 'vee-validate'
|
2017-10-28 18:17:14 +00:00
|
|
|
import { ApolloClient } from 'apollo-client'
|
2018-10-14 03:22:42 +00:00
|
|
|
import { BatchHttpLink } from 'apollo-link-batch-http'
|
|
|
|
import { ApolloLink, split } from 'apollo-link'
|
2018-09-30 18:20:26 +00:00
|
|
|
import { WebSocketLink } from 'apollo-link-ws'
|
2018-10-14 03:22:42 +00:00
|
|
|
import { ErrorLink } from 'apollo-link-error'
|
2017-10-28 18:17:14 +00:00
|
|
|
import { InMemoryCache } from 'apollo-cache-inmemory'
|
2018-09-30 18:20:26 +00:00
|
|
|
import { getMainDefinition } from 'apollo-utilities'
|
2018-03-06 01:53:24 +00:00
|
|
|
import VueApollo from 'vue-apollo'
|
2019-07-29 04:50:03 +00:00
|
|
|
import Vuetify from 'vuetify/lib'
|
2018-02-25 20:54:35 +00:00
|
|
|
import Velocity from 'velocity-animate'
|
2018-11-26 03:10:20 +00:00
|
|
|
import Vuescroll from 'vuescroll/dist/vuescroll-native'
|
2018-02-03 21:48:25 +00:00
|
|
|
import Hammer from 'hammerjs'
|
2018-03-26 05:11:49 +00:00
|
|
|
import moment from 'moment'
|
|
|
|
import VueMoment from 'vue-moment'
|
2018-07-16 02:40:41 +00:00
|
|
|
import VueTour from 'vue-tour'
|
2017-05-21 20:43:58 +00:00
|
|
|
import store from './store'
|
2018-10-08 04:17:31 +00:00
|
|
|
import Cookies from 'js-cookie'
|
2017-12-24 05:34:47 +00:00
|
|
|
|
2017-09-25 03:22:33 +00:00
|
|
|
// ====================================
|
|
|
|
// Load Modules
|
|
|
|
// ====================================
|
|
|
|
|
2018-02-03 21:48:25 +00:00
|
|
|
import boot from './modules/boot'
|
2017-09-25 03:22:33 +00:00
|
|
|
import localization from './modules/localization'
|
2017-02-10 01:24:28 +00:00
|
|
|
|
2017-05-26 00:54:03 +00:00
|
|
|
// ====================================
|
|
|
|
// Load Helpers
|
|
|
|
// ====================================
|
|
|
|
|
|
|
|
import helpers from './helpers'
|
|
|
|
|
2017-10-01 03:47:14 +00:00
|
|
|
// ====================================
|
|
|
|
// Initialize Global Vars
|
|
|
|
// ====================================
|
|
|
|
|
2018-03-06 01:53:24 +00:00
|
|
|
window.WIKI = null
|
2018-02-03 21:48:25 +00:00
|
|
|
window.boot = boot
|
|
|
|
window.Hammer = Hammer
|
2017-10-01 03:47:14 +00:00
|
|
|
|
2018-06-24 04:20:35 +00:00
|
|
|
moment.locale(siteConfig.lang)
|
|
|
|
|
2018-12-03 02:42:43 +00:00
|
|
|
store.commit('user/REFRESH_AUTH')
|
|
|
|
|
2017-09-25 03:22:33 +00:00
|
|
|
// ====================================
|
|
|
|
// Initialize Apollo Client (GraphQL)
|
|
|
|
// ====================================
|
|
|
|
|
2018-03-11 05:11:32 +00:00
|
|
|
const graphQLEndpoint = window.location.protocol + '//' + window.location.host + '/graphql'
|
2018-09-30 18:20:26 +00:00
|
|
|
const graphQLWSEndpoint = ((window.location.protocol === 'https:') ? 'wss:' : 'ws:') + '//' + window.location.host + '/graphql-subscriptions'
|
2018-01-28 05:40:25 +00:00
|
|
|
|
2018-10-14 03:22:42 +00:00
|
|
|
const graphQLLink = ApolloLink.from([
|
|
|
|
new ErrorLink(({ graphQLErrors, networkError }) => {
|
|
|
|
if (graphQLErrors) {
|
|
|
|
graphQLErrors.map(({ message, locations, path }) =>
|
|
|
|
console.error(
|
|
|
|
`[GraphQL error]: Message: ${message}, Location: ${locations}, Path: ${path}`
|
|
|
|
)
|
|
|
|
)
|
|
|
|
store.commit('showNotification', {
|
|
|
|
style: 'red',
|
2019-08-11 02:14:53 +00:00
|
|
|
message: `An unexpected error occured.`,
|
2018-10-14 03:22:42 +00:00
|
|
|
icon: 'warning'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
if (networkError) {
|
|
|
|
console.error(networkError)
|
|
|
|
store.commit('showNotification', {
|
|
|
|
style: 'red',
|
|
|
|
message: `Network Error: ${networkError.message}`,
|
|
|
|
icon: 'error'
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
new BatchHttpLink({
|
2018-06-26 00:55:00 +00:00
|
|
|
includeExtensions: true,
|
|
|
|
uri: graphQLEndpoint,
|
|
|
|
credentials: 'include',
|
2018-10-14 03:22:42 +00:00
|
|
|
fetch: async (uri, options) => {
|
2018-06-26 00:55:00 +00:00
|
|
|
// Strip __typename fields from variables
|
|
|
|
let body = JSON.parse(options.body)
|
2018-10-14 03:22:42 +00:00
|
|
|
body = body.map(bd => {
|
|
|
|
return ({
|
|
|
|
...bd,
|
|
|
|
variables: JSON.parse(JSON.stringify(bd.variables), (key, value) => { return key === '__typename' ? undefined : value })
|
|
|
|
})
|
|
|
|
})
|
2018-06-26 00:55:00 +00:00
|
|
|
options.body = JSON.stringify(body)
|
|
|
|
|
|
|
|
// Inject authentication token
|
2018-10-08 04:17:31 +00:00
|
|
|
const jwtToken = Cookies.get('jwt')
|
|
|
|
if (jwtToken) {
|
|
|
|
options.headers.Authorization = `Bearer ${jwtToken}`
|
|
|
|
}
|
2018-06-26 00:55:00 +00:00
|
|
|
|
2018-10-14 03:22:42 +00:00
|
|
|
const resp = await fetch(uri, options)
|
|
|
|
|
|
|
|
// Handle renewed JWT
|
|
|
|
const newJWT = resp.headers.get('new-jwt')
|
|
|
|
if (newJWT) {
|
|
|
|
Cookies.set('jwt', newJWT, { expires: 365 })
|
|
|
|
}
|
|
|
|
return resp
|
2018-06-26 00:55:00 +00:00
|
|
|
}
|
|
|
|
})
|
2018-10-14 03:22:42 +00:00
|
|
|
])
|
2018-06-24 04:20:35 +00:00
|
|
|
|
2018-09-30 18:20:26 +00:00
|
|
|
const graphQLWSLink = new WebSocketLink({
|
|
|
|
uri: graphQLWSEndpoint,
|
|
|
|
options: {
|
|
|
|
reconnect: true,
|
|
|
|
lazy: true
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2017-10-01 03:47:14 +00:00
|
|
|
window.graphQL = new ApolloClient({
|
2018-09-30 18:20:26 +00:00
|
|
|
link: split(({ query }) => {
|
|
|
|
const { kind, operation } = getMainDefinition(query)
|
|
|
|
return kind === 'OperationDefinition' && operation === 'subscription'
|
2019-05-31 17:06:20 +00:00
|
|
|
}, graphQLWSLink, graphQLLink),
|
2017-10-28 18:17:14 +00:00
|
|
|
cache: new InMemoryCache(),
|
|
|
|
connectToDevTools: (process.env.node_env === 'development')
|
2017-09-25 03:22:33 +00:00
|
|
|
})
|
|
|
|
|
2017-05-21 03:21:16 +00:00
|
|
|
// ====================================
|
2017-05-21 20:43:58 +00:00
|
|
|
// Initialize Vue Modules
|
2017-05-21 03:21:16 +00:00
|
|
|
// ====================================
|
|
|
|
|
2018-03-17 02:51:56 +00:00
|
|
|
Vue.config.productionTip = false
|
|
|
|
|
2018-02-28 05:54:09 +00:00
|
|
|
Vue.use(VueRouter)
|
2018-03-06 01:53:24 +00:00
|
|
|
Vue.use(VueApollo)
|
2017-05-22 17:32:52 +00:00
|
|
|
Vue.use(VueClipboards)
|
2017-09-25 03:22:33 +00:00
|
|
|
Vue.use(localization.VueI18Next)
|
2017-05-26 04:12:38 +00:00
|
|
|
Vue.use(helpers)
|
2019-07-29 04:50:03 +00:00
|
|
|
Vue.use(VeeValidate, { mode: 'eager' })
|
|
|
|
Vue.use(Vuetify)
|
2018-03-26 05:11:49 +00:00
|
|
|
Vue.use(VueMoment, { moment })
|
2018-11-26 03:10:20 +00:00
|
|
|
Vue.use(Vuescroll)
|
2018-07-16 02:40:41 +00:00
|
|
|
Vue.use(VueTour)
|
2017-05-21 03:21:16 +00:00
|
|
|
|
2018-02-25 20:54:35 +00:00
|
|
|
Vue.prototype.Velocity = Velocity
|
|
|
|
|
2017-07-02 02:23:40 +00:00
|
|
|
// ====================================
|
|
|
|
// Register Vue Components
|
|
|
|
// ====================================
|
|
|
|
|
2018-02-28 05:54:09 +00:00
|
|
|
Vue.component('admin', () => import(/* webpackChunkName: "admin" */ './components/admin.vue'))
|
2018-09-16 22:36:15 +00:00
|
|
|
Vue.component('editor', () => import(/* webpackPrefetch: -100, webpackChunkName: "editor" */ './components/editor.vue'))
|
2018-10-29 02:09:58 +00:00
|
|
|
Vue.component('history', () => import(/* webpackChunkName: "history" */ './components/history.vue'))
|
2018-11-25 06:28:20 +00:00
|
|
|
Vue.component('page-source', () => import(/* webpackChunkName: "source" */ './components/source.vue'))
|
2018-12-17 05:51:52 +00:00
|
|
|
Vue.component('loader', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/loader.vue'))
|
2018-09-16 22:36:15 +00:00
|
|
|
Vue.component('login', () => import(/* webpackPrefetch: true, webpackChunkName: "login" */ './components/login.vue'))
|
2018-09-23 04:14:01 +00:00
|
|
|
Vue.component('nav-header', () => import(/* webpackMode: "eager" */ './components/common/nav-header.vue'))
|
2019-08-04 02:51:29 +00:00
|
|
|
Vue.component('new-page', () => import(/* webpackChunkName: "new-page" */ './components/new-page.vue'))
|
2019-04-22 04:44:24 +00:00
|
|
|
Vue.component('notify', () => import(/* webpackMode: "eager" */ './components/common/notify.vue'))
|
2018-09-30 22:19:28 +00:00
|
|
|
Vue.component('page-selector', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/page-selector.vue'))
|
2018-05-21 03:27:06 +00:00
|
|
|
Vue.component('profile', () => import(/* webpackChunkName: "profile" */ './components/profile.vue'))
|
2018-12-17 05:51:52 +00:00
|
|
|
Vue.component('register', () => import(/* webpackChunkName: "register" */ './components/register.vue'))
|
2018-09-16 22:36:15 +00:00
|
|
|
Vue.component('v-card-chin', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/v-card-chin.vue'))
|
2019-03-09 05:51:02 +00:00
|
|
|
Vue.component('search-results', () => import(/* webpackPrefetch: true, webpackChunkName: "ui-extra" */ './components/common/search-results.vue'))
|
2019-08-27 03:03:56 +00:00
|
|
|
Vue.component('unauthorized', () => import(/* webpackChunkName: "unauthorized" */ './components/unauthorized.vue'))
|
2019-08-04 02:51:29 +00:00
|
|
|
Vue.component('welcome', () => import(/* webpackChunkName: "welcome" */ './components/welcome.vue'))
|
2017-07-02 02:23:40 +00:00
|
|
|
|
2018-11-11 04:40:55 +00:00
|
|
|
Vue.component('nav-footer', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/nav-footer.vue'))
|
|
|
|
Vue.component('nav-sidebar', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/nav-sidebar.vue'))
|
|
|
|
Vue.component('page', () => import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/components/page.vue'))
|
|
|
|
|
2018-02-03 21:48:25 +00:00
|
|
|
let bootstrap = () => {
|
2017-02-10 01:24:28 +00:00
|
|
|
// ====================================
|
|
|
|
// Notifications
|
|
|
|
// ====================================
|
2016-08-28 15:27:05 +00:00
|
|
|
|
2017-09-10 05:41:22 +00:00
|
|
|
window.addEventListener('beforeunload', () => {
|
2017-05-21 20:43:58 +00:00
|
|
|
store.dispatch('startLoading')
|
2017-02-09 01:52:37 +00:00
|
|
|
})
|
2016-09-05 04:39:59 +00:00
|
|
|
|
2018-03-06 01:53:24 +00:00
|
|
|
const apolloProvider = new VueApollo({
|
|
|
|
defaultClient: window.graphQL
|
|
|
|
})
|
|
|
|
|
2017-05-21 03:21:16 +00:00
|
|
|
// ====================================
|
|
|
|
// Bootstrap Vue
|
|
|
|
// ====================================
|
|
|
|
|
2017-09-25 03:22:33 +00:00
|
|
|
const i18n = localization.init()
|
2018-03-06 01:53:24 +00:00
|
|
|
window.WIKI = new Vue({
|
2018-08-11 22:16:56 +00:00
|
|
|
el: '#root',
|
2017-07-02 02:23:40 +00:00
|
|
|
components: {},
|
2018-01-28 18:34:37 +00:00
|
|
|
mixins: [helpers],
|
2018-09-29 19:39:09 +00:00
|
|
|
apolloProvider,
|
2017-05-21 03:21:16 +00:00
|
|
|
store,
|
2019-07-29 04:50:03 +00:00
|
|
|
i18n,
|
|
|
|
vuetify: new Vuetify({
|
2019-08-05 03:53:21 +00:00
|
|
|
rtl: siteConfig.rtl,
|
|
|
|
theme: {
|
|
|
|
dark: siteConfig.darkMode
|
|
|
|
}
|
2019-07-29 04:50:03 +00:00
|
|
|
})
|
2017-05-21 03:21:16 +00:00
|
|
|
})
|
2017-10-29 05:30:46 +00:00
|
|
|
|
2018-02-03 21:48:25 +00:00
|
|
|
// ----------------------------------
|
|
|
|
// Dispatch boot ready
|
|
|
|
// ----------------------------------
|
|
|
|
|
|
|
|
window.boot.notify('vue')
|
|
|
|
|
2018-11-11 04:40:55 +00:00
|
|
|
// ====================================
|
|
|
|
// Load theme-specific code
|
|
|
|
// ====================================
|
|
|
|
|
|
|
|
import(/* webpackChunkName: "theme-page" */ './themes/' + process.env.CURRENT_THEME + '/js/app.js')
|
2018-02-03 21:48:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
window.boot.onDOMReady(bootstrap)
|