ctucx.git: ctucx.things

simple inventory management web-app

1 
2 
3 
4 
5 
6 
7 
8 
9 
10 
11 
12 
13 
14 
15 
16 
17 
18 
19 
20 
21 
22 
23 
24 
25 
26 
27 
28 
29 
30 
31 
32 
33 
34 
35 
36 
37 
38 
39 
40 
41 
42 
43 
44 
45 
46 
47 
48 
49 
50 
51 
52 
53 
54 
55 
56 
57 
58 
59 
60 
61 
62 
63 
import Vue       from 'vue';
import VueRouter from 'vue-router';

import store     from './store.js';

import editor    from './views/editor.vue';
import login     from './views/login.vue';

import focusDirectives from './utils/focus.js';
import dataTypes       from './dataTypes.js';
import utils           from './utils/utils.js';

const Item     = dataTypes.Item;
const Category = dataTypes.Category;
const List     = dataTypes.List;
const Library  = dataTypes.Library;

var init = function () {
	window.app = new Vue({
		router,
		store,
		data: {
			path: '',
			fatal: '',
		},
		watch: {
			$route(to, from) {
				this.path = to.path;
			},
		},
		mounted() {
			this.path = router.currentRoute.path;
		},
	}).$mount('#lp');
};


Vue.use(VueRouter);

window.Vue    = Vue; // surfacing Vue globally for utils methods
window.bus    = new Vue(); // global event bus
window.router = new VueRouter({
	mode: 'history',
	routes: [
		{ path: '/login',  component: login  },
		{ path: '/editor', component: editor },
		{ path: '*',       component: editor },
	],
});

bus.$on('unauthorized', (error) => {
	window.location = '/login';
});

store.dispatch('init')
	.then(() => { init(); })
	.catch((error) => {
		if (!store.state.library) {
			router.push('/login');
		}

		init();
	});