const publicBaseURL = location.protocol + '//' + location.host + location.pathname const tenant = location.pathname.split('/').filter(x => x.length).slice(-1) function getLocalStoragePrefix() { return 'apm_' + tenant + '_' } /* //id: BOOL (track dynamicVisibility) let GLOBAL_VISIBILITY = {} */ let BASE_VALIDATORS = { /* 'required': v => !!v || translate('E_VAL_REQUIRED'), 'string_not_empty': v => (v && v?.trim() != "") || translate('E_VAL_NOT_EMPTY'), 'length_10': v => (v && v.length <= 10) || translate('E_VAL_LENGTH_10'), 'email': v => /.+@.+\..+/.test(v) || translate('E_VAL_EMAIL'), */ } let GLOBAL_VALIDATORS = { ...BASE_VALIDATORS } let BASE_FORMATTERS = { /* 'boolean': (value) => (value == '1' || value?.toLowerCase?.() == 'true') ? 'yes' : 'no', 'json': (value) => JSON.stringify(value), 'float': (value) => parseFloat(value).toFixed(2), 'datetime': (value) => value ? moment(value).format('YYYY-MM-DD hh:mm:ss') : "", 'date': (value) => value ? moment(value).format('YYYY-MM-DD') : "", 'download': (value) => `Download`, */ } let GLOBAL_FORMATTERS = { ...BASE_FORMATTERS } let app let data = { page: {}, edit: null, showNotifications: false, notifications: [], items: {}, //docs: '', //showHelp: false, editmetadata: null, editruntime: null, editdata: null, editbinding: null, pagedata: null, isAdmin: false, user: null , drawer: true, config: {}, routeReady: false, pageModalsVisibility: {}, editor: false, editorWidth: "512", editorHistory: [], loader: false, loaderText: 'Processing...', loaderCounter: 0, loaderWithPercentage: false, loaderPercentage: 0, gdialog: { show: false, title: '', text: '', close: null, showCancel: false, showInput: false, multiple: false, value: '' }, snackbars: [], editmode: false, showConsole: false, consoleLines: [], isRouterAlive: true, pageLoading: true, menuOpenIDS: [], menu: [], clipboard: {}, locales: I18N_LOCALES, bg1: '#ff0000', visibility: {}, } function togglePageModal(modalID) { Vue.set(data.pageModalsVisibility, modalID, !data.pageModalsVisibility[modalID]) } let editlist = [] let editlist_ex = [] async function reloadNotifications() { data.notifications = await tkget('notifications') } async function main() { const i18n = new VueI18n({ locale: localStorage.getItem(getLocalStoragePrefix() + 'persist_lang') || getBrowserLang() || 'en', messages: I18N_STRINGS, }) //Vue.use(VueI18n) Vue.use(VueRouter) Vue.directive('init', { bind: function (el, binding, vnode) { if (binding.value) { //console.log("init", el.id, binding.value, vnode.context) binding.value.bind(vnode.context)() } } }) //load all components listed inside components/list.js for (let cid in components) { httpVueLoader.register(Vue, components[cid].path); } Vue.mixin({ methods: { editmode: function () { return app.editmode }, }, }) if (getToken()) { await setToken(getToken()) } await reloadPages() try { data.config = await tkget('load/config') } catch (ex) { data.config = getConfigDefault() } app = new Vue({ i18n, el: '#app', data, watch: { 'config': { handler: (newdata) => { applyConfig() }, deep: true, }, 'page': { handler: (newdata) => { let p = data.page //update current page in pages array let pprev = pages.find(x => x.name == p.id) if (pprev) { Object.assign(pprev, p) } rebuildMenuFromPages() }, deep: true, }, }, router: await createRouter(), vuetify: new Vuetify({ theme: { dark: darkThemeEnabled(), options: { customProperties: true, variations: false, }, themes: getThemesFromConfig(), }, }), mounted() { syncBodyWithTheme(this) }, methods: { async openNotification(notification) { if (notification.link) { goto(notification.link, true) data.showNotifications = false } }, async markNotificationAsRead(notification) { await tkpost('notifications/' + notification.id) await this.reloadNotifications(); if (data.notifications.length == 0) { data.showNotifications = false } }, async markAllNotificationsAsRead() { let list = [...data.notifications] data.showNotifications = false for (let n of list) { await tkpost('notifications/' + n.id) let idx = data.notifications.findIndex(x => x.id == n.id) data.notifications.splice(idx, 1) } await this.reloadNotifications() }, async reloadNotifications() { await reloadNotifications() }, getNotificationTimestamp(n) { if (!n.timestamp) return '' return moment(n.timestamp).fromNow() }, synctheme() { }, updateLocale() { localStorage.setItem(getLocalStoragePrefix() + 'persist_lang', i18n.locale) updateMenu(data.menu) }, menuOpen(item) { if (this.menuOpenIDS.includes(item.id)) { this.menuOpenIDS.splice(this.menuOpenIDS.indexOf(item.id), 1) } else { this.menuOpenIDS.push(item.id) } }, isOpen(id) { return data.menuOpenIDS.includes(id) }, toggleDarkMode() { toggleTheme(this) }, menuItemHasVisibleChildren(item) { if (!item.children) return false let vcount = 0 for (let c of item.children) { if (c.showInMenu) vcount ++ } return vcount > 0 }, closeDialog(dialog, result) { dialog.close?.(result) dialog.show = false }, } }) applyConfig() }