-
Notifications
You must be signed in to change notification settings - Fork 9
/
app.js
130 lines (119 loc) · 3.75 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
import {createApp} from 'vue'
import {createRouter, createWebHashHistory} from 'vue-router';
import {routes} from './routes';
import Rest from './Bits/Rest.js';
import {ElNotification, ElLoading, ElMessageBox} from 'element-plus'
import Storage from '@/Bits/Storage';
import App from './App.vue';
import eventBus from './Bits/event-bus';
require('./app.scss');
const dayjs = require('dayjs');
const relativeTime = require('dayjs/plugin/relativeTime');
require('dayjs/plugin/utc');
require('dayjs/plugin/localizedFormat');
dayjs.extend(require('dayjs/plugin/utc'));
dayjs.extend(require('dayjs/plugin/localizedFormat'));
dayjs.extend(relativeTime)
function convertToText(obj) {
const string = [];
if (typeof (obj) === 'object' && (obj.join === undefined)) {
for (const prop in obj) {
string.push(convertToText(obj[prop]));
}
} else if (typeof (obj) === 'object' && !(obj.join === undefined)) {
for (const prop in obj) {
string.push(convertToText(obj[prop]));
}
} else if (typeof (obj) === 'function') {
} else if (typeof (obj) === 'string') {
string.push(obj)
}
return string.join('<br />')
}
const app = createApp(App);
app.use(ElLoading);
app.config.globalProperties.appVars = window.fluentSnippetAdmin;
app.mixin({
data() {
return {
Storage,
is_rtl: false
}
},
methods: {
$get: Rest.get,
$post: Rest.post,
$put: Rest.put,
$del: Rest.delete,
changeTitle(title) {
jQuery('head title').text(title + ' - FluentSnippets');
},
$handleError(response) {
let errorMessage = '';
if (typeof response === 'string') {
errorMessage = response;
} else if (response && response.message) {
errorMessage = response.message;
} else {
errorMessage = convertToText(response);
}
if (!errorMessage) {
errorMessage = 'Something is wrong!';
}
this.$notify({
type: 'error',
title: 'Error',
message: errorMessage,
dangerouslyUseHTMLString: true
});
},
convertToText,
$t(string) {
return window.fluentSnippetAdmin.i18n[string] || string;
},
relativeTimeFromUtc(utcDateTime) {
const localDateTime = dayjs.utc(utcDateTime).local();
return localDateTime.fromNow();
},
getLangLabelName(lang) {
switch (lang) {
case 'php_content':
return 'PHP + HTML';
default:
return lang.toUpperCase();
}
},
$storeLocalData(key, value) {
this.Storage.set(key, value);
},
$getLocalData(key, defaultValue = '') {
return this.Storage.get(key, defaultValue);
},
ucFirst(string) {
if(!string) {
return '';
}
return string.charAt(0).toUpperCase() + string.slice(1);
}
},
watch: {
$route(to, from) {
const active = to.meta.active;
if(!active) {
return;
}
jQuery('.fsnip_menu_primary').removeClass('router-link-active');
jQuery('.fsnip_menu_primary.fsnip_menu_'+active).addClass('router-link-active');
}
}
});
app.config.globalProperties.$notify = ElNotification;
app.config.globalProperties.$confirm = ElMessageBox.confirm;
app.use(eventBus);
const router = createRouter({
routes,
history: createWebHashHistory()
});
window.fluentFrameworkApp = app.use(router).mount(
'#fluent_snippets_app'
);