]>
Commit | Line | Data |
---|---|---|
a6ccda0f RBR |
1 | import Vue from 'vue'; |
2 | import VueRouter from 'vue-router'; | |
3 | ||
4 | import AuthService from './services/auth'; | |
5 | ||
6 | import LoginComponent from './components/login'; | |
7 | import WelcomeComponent from './components/welcome'; | |
8 | import PostsComponent from './components/posts'; | |
9 | ||
10 | /* global window */ | |
11 | ||
12 | const internals = {}; | |
13 | ||
14 | export default internals.Dasein = { | |
15 | ||
16 | start() { | |
17 | ||
18 | this._setupVue(); | |
19 | ||
20 | internals.authService = new AuthService(); | |
21 | ||
22 | this.vm = new Vue({ | |
23 | router: this._setupRouter(), | |
24 | el: '#dasein', | |
25 | components: { | |
26 | login: LoginComponent, | |
27 | welcome: WelcomeComponent | |
28 | }, | |
29 | data: { | |
30 | message: 'Hello Vue!' | |
31 | }, | |
32 | methods: { | |
33 | authenticated() { | |
34 | ||
35 | return internals.authService.authenticated; | |
36 | } | |
37 | } | |
38 | }); | |
39 | ||
40 | }, | |
41 | ||
42 | // Initializes vue options | |
43 | ||
44 | _setupVue() { | |
45 | ||
46 | Vue.use(VueRouter); | |
47 | }, | |
48 | ||
49 | // Sets up the routes | |
50 | ||
51 | _setupRouter() { | |
52 | ||
53 | const routes = [ | |
54 | { | |
55 | path: '/login', | |
56 | component: WelcomeComponent | |
57 | }, | |
58 | { | |
59 | path: '/', | |
60 | component: PostsComponent | |
61 | }, | |
62 | { | |
63 | path: '/login-callback', | |
64 | component: LoginComponent, | |
65 | props: (route) => { | |
66 | ||
67 | return { | |
68 | oAuthToken: route.query.oauth_token, | |
69 | oAuthVerifier: route.query.oauth_verifier | |
70 | }; | |
71 | } | |
72 | } | |
73 | ]; | |
74 | ||
75 | const router = new VueRouter({ | |
76 | mode: 'history', | |
77 | routes | |
78 | }); | |
79 | ||
80 | return router; | |
81 | } | |
82 | }; | |
83 | ||
84 | ||
85 | internals.run = function () { | |
86 | ||
87 | internals.Dasein.start(); | |
88 | }; | |
89 | ||
90 | window.addEventListener('load', internals.run); |