Files
cloudron-box/dashboard/src/components/Index.vue

97 lines
2.4 KiB
Vue
Raw Normal View History

2024-11-01 14:16:09 +01:00
<script>
2024-12-27 22:25:00 +01:00
import { Notification } from 'pankow';
2024-12-29 00:36:48 +01:00
import AppsView from './AppsView.vue';
2025-01-05 22:47:50 +01:00
import AppstoreView from './AppstoreView.vue';
2025-01-14 10:27:27 +01:00
import ProfileView from './ProfileView.vue';
2024-11-01 14:16:09 +01:00
import SupportView from './SupportView.vue';
import UserDirectoryView from './UserDirectoryView.vue';
2024-12-26 12:19:48 +01:00
import VolumesView from './VolumesView.vue';
2024-11-01 14:16:09 +01:00
2025-01-03 15:06:41 +01:00
import ProfileModel from '../models/ProfileModel.js';
const API_ORIGIN = import.meta.env.VITE_API_ORIGIN ? import.meta.env.VITE_API_ORIGIN : window.location.origin;
2024-11-01 14:16:09 +01:00
const VIEWS = {
2024-12-29 00:36:48 +01:00
APPS: 'apps',
2025-01-05 22:47:50 +01:00
APPSTORE: 'appstore',
2025-01-14 10:27:27 +01:00
PROFILE: 'profile',
2024-12-26 12:19:48 +01:00
SUPPORT: 'support',
USER_DIRECTORY: 'user-directory',
2024-12-26 12:19:48 +01:00
VOLUMES: 'volumes',
2024-11-01 14:16:09 +01:00
};
export default {
name: 'Index',
components: {
2024-12-29 00:36:48 +01:00
AppsView,
2025-01-05 22:47:50 +01:00
AppstoreView,
2024-12-27 22:25:00 +01:00
Notification,
2025-01-14 10:27:27 +01:00
ProfileView,
2024-12-26 12:19:48 +01:00
SupportView,
UserDirectoryView,
2024-12-26 12:19:48 +01:00
VolumesView,
2024-11-01 14:16:09 +01:00
},
data() {
return {
VIEWS,
accessToken: localStorage.token,
2025-01-03 15:06:41 +01:00
profile: {},
2024-11-01 14:16:09 +01:00
view: ''
};
},
methods: {
},
async mounted() {
if (!localStorage.token) {
console.error('Set localStorage.token');
return;
}
2025-01-03 15:06:41 +01:00
const profileModel = ProfileModel.create(API_ORIGIN, localStorage.token);
this.profile = await profileModel.get();
2024-11-01 14:16:09 +01:00
const that = this;
function onHashChange() {
const view = location.hash.slice(2);
2024-12-29 00:36:48 +01:00
if (view === VIEWS.APPS) {
that.view = VIEWS.APPS;
} else if (view.indexOf(VIEWS.APPSTORE) === 0) {
2025-01-05 22:47:50 +01:00
that.view = VIEWS.APPSTORE;
2025-01-14 10:27:27 +01:00
} else if (view === VIEWS.PROFILE) {
that.view = VIEWS.PROFILE;
2024-12-29 00:36:48 +01:00
} else if (view === VIEWS.SUPPORT) {
2024-11-01 14:16:09 +01:00
that.view = VIEWS.SUPPORT;
} else if (view === VIEWS.USER_DIRECTORY) {
that.view = VIEWS.USER_DIRECTORY;
2024-12-26 12:19:48 +01:00
} else if (view === VIEWS.VOLUMES) {
that.view = VIEWS.VOLUMES;
2024-11-01 14:16:09 +01:00
} else {
that.view = '';
}
2024-12-28 12:07:48 +01:00
// hack for layout to avoid consuming space if vue view is not active
document.getElementById('app').style.height = that.view ? 'auto' : '0';
2024-11-01 14:16:09 +01:00
}
window.addEventListener('hashchange', onHashChange);
onHashChange();
}
};
</script>
<template>
<div>
<Notification />
<AppsView v-if="view === VIEWS.APPS" />
<AppstoreView v-if="view === VIEWS.APPSTORE" />
<ProfileView v-if="view === VIEWS.PROFILE" />
<SupportView v-if="view === VIEWS.SUPPORT" />
<UserDirectoryView v-if="view === VIEWS.USER_DIRECTORY" />
<VolumesView v-if="view === VIEWS.VOLUMES" />
</div>
</template>