Hangar/frontend/components/layouts/Header.vue

240 lines
8.3 KiB
Vue
Raw Normal View History

2021-01-22 03:47:58 +08:00
<template>
<v-app-bar fixed app>
2021-01-22 05:12:12 +08:00
<v-menu bottom offset-y open-on-hover transition="slide-y-transition" close-delay="100">
2021-01-22 03:47:58 +08:00
<template #activator="{ on, attrs }">
2021-02-08 06:06:06 +08:00
<v-btn text x-large class="align-self-center px-1" v-bind="attrs" :ripple="false" v-on="on">
<NuxtLink class="float-left" to="/" exact>
<v-img height="55" width="220" src="https://papermc.io/images/logo-marker.svg" alt="Paper logo" />
2021-01-22 05:12:12 +08:00
</NuxtLink>
2021-02-08 06:06:06 +08:00
<v-icon>mdi-chevron-down</v-icon>
</v-btn>
2021-01-22 03:47:58 +08:00
</template>
<Dropdown :controls="dropdown" />
2021-01-22 03:47:58 +08:00
</v-menu>
2021-02-09 04:45:54 +08:00
<v-spacer></v-spacer>
2021-02-10 12:40:34 +08:00
<v-menu v-if="$util.isLoggedIn()" bottom offset-y transition="slide-y-transition" open-on-hover>
<template #activator="{ on, attrs }">
2021-02-13 14:36:53 +08:00
<v-btn v-bind="attrs" color="primary" class="mr-1" v-on="on">
{{ $t('nav.createNew') }}
2021-02-10 12:40:34 +08:00
<v-icon right>mdi-chevron-down</v-icon>
</v-btn>
</template>
<Dropdown :controls="newControls" />
</v-menu>
2021-01-22 05:12:12 +08:00
<v-tooltip bottom>
<template #activator="{ on }">
2021-02-13 14:36:53 +08:00
<v-btn icon to="/authors" nuxt class="mr-1" v-on="on"><v-icon>mdi-account-group</v-icon></v-btn>
</template>
<span>{{ $t('pages.authors') }}</span>
</v-tooltip>
<v-tooltip bottom>
<template #activator="{ on }">
2021-02-13 14:36:53 +08:00
<v-btn icon to="/staff" nuxt class="mr-1" v-on="on"><v-icon>mdi-account-tie</v-icon></v-btn>
</template>
<span>{{ $t('pages.staff') }}</span>
</v-tooltip>
2021-01-22 05:12:12 +08:00
<v-menu v-if="$util.isLoggedIn()" bottom offset-y transition="slide-y-transition" close-delay="100">
<template #activator="{ on, attrs }">
2021-02-12 11:33:01 +08:00
<v-btn color="info" text class="px-3 text-transform-unset" x-large v-bind="attrs" v-on="on">
2021-03-21 10:06:09 +08:00
{{ currentUser.name }}
<v-badge overlap :content="totalNotificationCount" :value="totalNotificationCount">
2021-04-06 00:28:09 +08:00
<UserAvatar :username="currentUser.name" clazz="user-avatar-sm" :avatar-url="$util.avatarUrl(currentUser.name)"> </UserAvatar>
</v-badge>
</v-btn>
</template>
<Dropdown :controls="userControls" />
</v-menu>
2021-01-22 05:12:12 +08:00
<template v-else>
2021-01-23 09:44:41 +08:00
<v-btn href="/signup" class="mr-2" color="primary">{{ $t('nav.signup') }}</v-btn>
<v-btn color="secondary" @click="$auth.login($route.fullPath)">{{ $t('nav.login') }}</v-btn>
2021-01-22 05:12:12 +08:00
</template>
2021-01-22 03:47:58 +08:00
</v-app-bar>
</template>
<script lang="ts">
2021-03-21 10:06:09 +08:00
import { Component } from 'nuxt-property-decorator';
import Dropdown, { Control } from '~/components/layouts/Dropdown.vue';
2021-03-21 10:06:09 +08:00
import { HangarComponent } from '~/components/mixins';
2021-04-06 00:28:09 +08:00
import UserAvatar from '~/components/users/UserAvatar.vue';
2021-01-22 03:47:58 +08:00
@Component({
components: {
2021-04-06 00:28:09 +08:00
UserAvatar,
Dropdown,
},
})
2021-03-21 10:06:09 +08:00
export default class Header extends HangarComponent {
get dropdown(): Control[] {
const controls: Control[] = [];
controls.push({
link: 'https://www.papermc.io',
icon: 'mdi-home',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.home'),
});
controls.push({
link: 'https://papermc.io/forums',
icon: 'mdi-comment-multiple',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.forums'),
});
controls.push({
link: 'https://github.com/PaperMC',
icon: 'mdi-code-braces',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.code'),
});
controls.push({
link: 'https://paper.readthedocs.io',
icon: 'mdi-book',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.docs'),
});
controls.push({
link: 'https://papermc.io/javadocs',
icon: 'mdi-school',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.javadocs'),
});
controls.push({
link: '/',
icon: 'mdi-home',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.hangar'),
});
controls.push({
link: 'https://papermc.io/downloads',
icon: 'mdi-download',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.downloads'),
});
controls.push({
link: 'https://papermc.io/community',
icon: 'mdi-comment',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.hangar.community'),
});
return controls;
}
get newControls(): Control[] {
const controls: Control[] = [];
controls.push({
link: '/new',
icon: 'mdi-book',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.new.project'),
});
// TODO get user orgs count
if (0 - 1 < this.validations.maxOrgCount) {
controls.push({
link: '/organizations/new',
icon: 'mdi-account-group',
title: this.$t('nav.new.organization'),
});
}
return controls;
}
get userControls(): Control[] {
const controls: Control[] = [];
controls.push({
2021-03-22 14:39:06 +08:00
link: `/${this.currentUser!.name}`,
icon: 'mdi-account',
2021-03-22 14:39:06 +08:00
title: this.currentUser!.name,
});
controls.push({
link: '/notifications',
icon: 'mdi-bell',
title: this.$t('nav.user.notifications'),
badge: true,
2021-03-22 14:39:06 +08:00
badgeContent: this.currentUser!.headerData.unansweredInvites + this.currentUser!.headerData.unreadNotifications,
});
controls.push({
isDivider: true,
});
2021-03-12 15:59:36 +08:00
if (this.$perms.canAccessModNotesAndFlags) {
2021-02-07 13:44:53 +08:00
controls.push({
link: '/admin/flags',
icon: 'mdi-flag',
title: this.$t('nav.user.flags'),
badge: true,
2021-03-22 14:39:06 +08:00
badgeContent: this.currentUser!.headerData.unresolvedFlags,
2021-02-07 13:44:53 +08:00
});
controls.push({
link: '/admin/approval/projects',
icon: 'mdi-thumb-up',
title: this.$t('nav.user.projectApprovals'),
badge: true,
2021-03-22 14:39:06 +08:00
badgeContent: this.currentUser!.headerData.projectApprovals,
2021-02-07 13:44:53 +08:00
});
}
2021-03-12 15:59:36 +08:00
if (this.$perms.isReviewer) {
2021-02-07 13:44:53 +08:00
controls.push({
link: '/admin/approval/versions',
icon: 'mdi-thumb-up-outline',
title: this.$t('nav.user.versionApprovals'),
badge: true,
2021-03-22 14:39:06 +08:00
badgeContent: this.currentUser!.headerData.reviewQueueCount,
2021-02-07 13:44:53 +08:00
});
}
2021-03-12 15:59:36 +08:00
if (this.$perms.canViewStats) {
2021-02-07 13:44:53 +08:00
controls.push({
link: '/admin/stats',
icon: 'mdi-chart-line',
title: this.$t('nav.user.stats'),
});
}
2021-03-12 15:59:36 +08:00
if (this.$perms.canViewHealth) {
2021-02-07 13:44:53 +08:00
controls.push({
link: '/admin/health',
icon: 'mdi-heart-plus',
title: this.$t('nav.user.health'),
});
}
2021-03-12 15:59:36 +08:00
if (this.$perms.canViewLogs) {
2021-02-07 13:44:53 +08:00
controls.push({
link: '/admin/log',
icon: 'mdi-format-list-bulleted',
title: this.$t('nav.user.log'),
});
}
2021-03-12 15:59:36 +08:00
if (this.$perms.canDoManualValueChanges) {
2021-02-07 13:44:53 +08:00
controls.push({
link: '/admin/versions',
icon: 'mdi-tag-multiple',
title: this.$t('nav.user.platformVersions'),
});
}
if (controls.length > 3) {
controls.push({
isDivider: true,
});
}
controls.push({
2021-01-22 11:11:24 +08:00
action: () => this.$auth.logout(),
icon: 'mdi-logout',
2021-01-23 05:06:44 +08:00
title: this.$t('nav.user.logout'),
});
return controls;
}
get totalNotificationCount() {
return (
2021-03-22 14:39:06 +08:00
this.currentUser!.headerData.unreadNotifications +
this.currentUser!.headerData.unansweredInvites +
this.currentUser!.headerData.unresolvedFlags +
this.currentUser!.headerData.reviewQueueCount +
this.currentUser!.headerData.projectApprovals
);
}
2021-01-22 05:12:12 +08:00
}
2021-01-22 03:47:58 +08:00
</script>
2021-02-08 06:06:06 +08:00
<style lang="scss">
.v-badge--bordered.header-badge .v-badge__badge::after {
border-color: #272727 !important;
}
</style>
<style lang="scss">
.avatar-button {
//border: 2px white solid;
2021-01-22 03:47:58 +08:00
}
</style>