-
Notifications
You must be signed in to change notification settings - Fork 576
/
app.js
109 lines (84 loc) · 2.96 KB
/
app.js
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import Vue from 'vue';
import Base from './base';
import axios from 'axios';
import Routes from './routes';
import VueRouter from 'vue-router';
import VueJsonPretty from 'vue-json-pretty';
import 'vue-json-pretty/lib/styles.css';
import moment from 'moment-timezone';
require('bootstrap');
let token = document.head.querySelector('meta[name="csrf-token"]');
if (token) {
axios.defaults.headers.common['X-CSRF-TOKEN'] = token.content;
}
Vue.use(VueRouter);
window.Popper = require('popper.js').default;
moment.tz.setDefault(Telescope.timezone);
window.Telescope.basePath = '/' + window.Telescope.path;
let routerBasePath = window.Telescope.basePath + '/';
if (window.Telescope.path === '' || window.Telescope.path === '/') {
routerBasePath = '/';
window.Telescope.basePath = '';
}
const router = new VueRouter({
routes: Routes,
mode: 'history',
base: routerBasePath,
});
Vue.component('vue-json-pretty', VueJsonPretty);
Vue.component('related-entries', require('./components/RelatedEntries.vue').default);
Vue.component('index-screen', require('./components/IndexScreen.vue').default);
Vue.component('preview-screen', require('./components/PreviewScreen.vue').default);
Vue.component('alert', require('./components/Alert.vue').default);
Vue.component('copy-clipboard', require('./components/CopyClipboard.vue').default);
Vue.mixin(Base);
new Vue({
el: '#telescope',
router,
data() {
return {
alert: {
type: null,
autoClose: 0,
message: '',
confirmationProceed: null,
confirmationCancel: null,
},
autoLoadsNewEntries: localStorage.autoLoadsNewEntries === '1',
recording: Telescope.recording,
};
},
created() {
window.addEventListener('keydown', this.keydownListener);
},
destroyed() {
window.removeEventListener('keydown', this.keydownListener);
},
methods: {
autoLoadNewEntries() {
if (!this.autoLoadsNewEntries) {
this.autoLoadsNewEntries = true;
localStorage.autoLoadsNewEntries = 1;
} else {
this.autoLoadsNewEntries = false;
localStorage.autoLoadsNewEntries = 0;
}
},
toggleRecording() {
axios.post(Telescope.basePath + '/telescope-api/toggle-recording');
window.Telescope.recording = !Telescope.recording;
this.recording = !this.recording;
},
clearEntries(shouldConfirm = true) {
if (shouldConfirm && !confirm('Are you sure you want to delete all Telescope data?')) {
return;
}
axios.delete(Telescope.basePath + '/telescope-api/entries').then((response) => location.reload());
},
keydownListener(event) {
if (event.metaKey && event.key === 'k') {
this.clearEntries(false);
}
},
},
});