iceshrimp/packages/client/src/pages/admin/index.vue

327 lines
8.3 KiB
Vue
Raw Normal View History

<template>
2021-11-19 19:36:12 +09:00
<div ref="el" class="hiyeyicy" :class="{ wide: !narrow }">
<div v-if="!narrow || currentPage?.route.name == null" class="nav">
2021-12-30 21:47:48 +09:00
<MkSpacer :content-max="700" :margin-min="16">
2021-10-24 20:16:55 +09:00
<div class="lxpfedzu">
<div class="banner">
<img :src="$instance.iconUrl || '/favicon.ico'" alt="" class="icon"/>
</div>
2021-10-10 17:48:07 +09:00
2022-07-20 22:24:26 +09:00
<MkInfo v-if="thereIsUnresolvedAbuseReport" warn class="info">{{ i18n.ts.thereIsUnresolvedAbuseReportWarning }} <MkA to="/admin/abuses" class="_link">{{ i18n.ts.check }}</MkA></MkInfo>
<MkInfo v-if="noMaintainerInformation" warn class="info">{{ i18n.ts.noMaintainerInformationWarning }} <MkA to="/admin/settings" class="_link">{{ i18n.ts.configure }}</MkA></MkInfo>
<MkInfo v-if="noBotProtection" warn class="info">{{ i18n.ts.noBotProtectionWarning }} <MkA to="/admin/security" class="_link">{{ i18n.ts.configure }}</MkA></MkInfo>
<MkInfo v-if="noEmailServer" warn class="info">{{ i18n.ts.noEmailServerWarning }} <MkA to="/admin/email-settings" class="_link">{{ i18n.ts.configure }}</MkA></MkInfo>
2022-12-19 03:12:24 +09:00
<MkInfo v-if="updateAvailable" warn class="info">{{ i18n.ts.updateAvailable }} <a href="https://codeberg.org/calckey/calckey/releases" target="_bank" class="_link">{{ i18n.ts.check }}</a></MkInfo>
2021-10-10 17:48:07 +09:00
<MkSuperMenu :def="menuDef" :grid="currentPage?.route.name == null"></MkSuperMenu>
2021-10-24 20:16:55 +09:00
</div>
</MkSpacer>
</div>
<div v-if="!(narrow && currentPage?.route.name == null)" class="main">
<RouterView/>
</div>
</div>
</template>
<script lang="ts" setup>
import { defineAsyncComponent, inject, nextTick, onMounted, onUnmounted, provide, watch } from 'vue';
2021-11-12 02:02:25 +09:00
import { i18n } from '@/i18n';
import MkSuperMenu from '@/components/MkSuperMenu.vue';
import MkInfo from '@/components/MkInfo.vue';
2021-11-12 02:02:25 +09:00
import { scroll } from '@/scripts/scroll';
import { instance } from '@/instance';
import { version } from '@/config';
2022-12-13 03:54:24 +09:00
import { $i } from '@/account'
2021-11-12 02:02:25 +09:00
import * as os from '@/os';
import { lookupUser } from '@/scripts/lookup-user';
import { defaultStore } from '@/store';
import { useRouter } from '@/router';
import { definePageMetadata, provideMetadataReceiver, setPageMetadata } from '@/scripts/page-metadata';
2020-02-17 02:21:27 +09:00
const isEmpty = (x: string | null) => x == null || x === '';
const router = useRouter();
2021-10-24 04:03:07 +09:00
const indexInfo = {
title: i18n.ts.controlPanel,
2022-11-07 11:49:47 +09:00
icon: 'ph-gear-six-bold ph-lg',
hideHeader: true,
};
provide('shouldOmitHeaderTitle', false);
2021-10-10 15:19:16 +09:00
let INFO = $ref(indexInfo);
let childInfo = $ref(null);
let narrow = $ref(false);
let view = $ref(null);
let el = $ref(null);
let pageProps = $ref({});
let noMaintainerInformation = isEmpty(instance.maintainerName) || isEmpty(instance.maintainerEmail);
let noBotProtection = !instance.disableRegistration && !instance.enableHcaptcha && !instance.enableRecaptcha;
let noEmailServer = !instance.enableEmail;
let thereIsUnresolvedAbuseReport = $ref(false);
let updateAvailable = $ref(false);
let currentPage = $computed(() => router.currentRef.value.child);
os.api('admin/abuse-user-reports', {
state: 'unresolved',
limit: 1,
}).then(reports => {
2022-09-16 07:03:00 +09:00
if (reports?.length > 0) thereIsUnresolvedAbuseReport = true;
});
2021-10-10 15:19:16 +09:00
if (defaultStore.state.showAdminUpdates) {
os.api('latest-version').then(res => {
const cleanRes = parseInt(res?.tag_name.replace(/[^0-9]/g, ''));
const cleanVersion = parseInt(version.replace(/[^0-9]/g, ''));
if (cleanRes > cleanVersion) {
updateAvailable = true;
}
});
}
const NARROW_THRESHOLD = 600;
const ro = new ResizeObserver((entries, observer) => {
if (entries.length === 0) return;
narrow = entries[0].borderBoxSize[0].inlineSize < NARROW_THRESHOLD;
});
2021-10-10 15:19:16 +09:00
const menuDef = $computed(() => [{
title: i18n.ts.quickAction,
items: [{
type: 'button',
2022-11-07 11:49:47 +09:00
icon: 'ph-magnifying-glass-bold ph-lg',
text: i18n.ts.lookup,
action: lookup,
}, ...(instance.disableRegistration ? [{
type: 'button',
2022-12-13 03:55:01 +09:00
icon: 'ph-user-plus-bold ph-lg',
text: i18n.ts.invite,
action: invite,
}] : [])],
}, {
title: i18n.ts.administration,
items: [{
2022-11-07 11:49:47 +09:00
icon: 'ph-gauge-bold ph-lg',
text: i18n.ts.dashboard,
to: '/admin/overview',
active: currentPage?.route.name === 'overview',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-users-bold ph-lg',
text: i18n.ts.users,
to: '/admin/users',
active: currentPage?.route.name === 'users',
}, {
2022-11-07 12:14:55 +09:00
icon: 'ph-smiley-bold ph-lg',
text: i18n.ts.customEmojis,
to: '/admin/emojis',
active: currentPage?.route.name === 'emojis',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-planet-bold ph-lg',
text: i18n.ts.federation,
2022-11-10 05:18:36 +09:00
to: '/admin/federation',
active: currentPage?.route.name === 'federation',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-clipboard-text-bold ph-lg',
text: i18n.ts.jobQueue,
to: '/admin/queue',
active: currentPage?.route.name === 'queue',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-cloud-bold ph-lg',
text: i18n.ts.files,
to: '/admin/files',
active: currentPage?.route.name === 'files',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-megaphone-simple-bold ph-lg',
text: i18n.ts.announcements,
to: '/admin/announcements',
active: currentPage?.route.name === 'announcements',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-money-bold ph-lg',
text: i18n.ts.ads,
to: '/admin/ads',
active: currentPage?.route.name === 'ads',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-warning-circle-bold ph-lg',
text: i18n.ts.abuseReports,
to: '/admin/abuses',
active: currentPage?.route.name === 'abuses',
}],
2022-12-13 03:55:01 +09:00
}, ...($i?.isAdmin ? [{
title: i18n.ts.settings,
items: [{
2022-11-07 11:49:47 +09:00
icon: 'ph-gear-six-bold ph-lg',
text: i18n.ts.general,
to: '/admin/settings',
active: currentPage?.route.name === 'settings',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-envelope-simple-open-bold ph-lg',
text: i18n.ts.emailServer,
to: '/admin/email-settings',
active: currentPage?.route.name === 'email-settings',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-cloud-bold ph-lg',
text: i18n.ts.objectStorage,
to: '/admin/object-storage',
active: currentPage?.route.name === 'object-storage',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-lock-bold ph-lg',
text: i18n.ts.security,
to: '/admin/security',
active: currentPage?.route.name === 'security',
}, {
2022-11-10 10:49:05 +09:00
icon: 'ph-flow-arrow-bold ph-lg',
text: i18n.ts.relays,
to: '/admin/relays',
active: currentPage?.route.name === 'relays',
}, {
2022-11-10 10:49:05 +09:00
icon: 'ph-plug-bold ph-lg',
text: i18n.ts.integration,
to: '/admin/integrations',
active: currentPage?.route.name === 'integrations',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-prohibit-bold ph-lg',
text: i18n.ts.instanceBlocking,
to: '/admin/instance-block',
active: currentPage?.route.name === 'instance-block',
}, {
2022-11-07 11:49:47 +09:00
icon: 'ph-ghost-bold ph-lg',
text: i18n.ts.proxyAccount,
to: '/admin/proxy-account',
active: currentPage?.route.name === 'proxy-account',
}],
2022-12-13 03:54:24 +09:00
}] : []), {
title: i18n.ts.info,
items: [{
2022-11-07 11:49:47 +09:00
icon: 'ph-database-bold ph-lg',
text: i18n.ts.database,
to: '/admin/database',
active: currentPage?.route.name === 'database',
}],
}]);
watch(narrow, () => {
if (currentPage?.route.name == null && !narrow) {
router.push('/admin/overview');
}
});
onMounted(() => {
ro.observe(el);
narrow = el.offsetWidth < NARROW_THRESHOLD;
if (currentPage?.route.name == null && !narrow) {
router.push('/admin/overview');
}
});
onUnmounted(() => {
ro.disconnect();
});
provideMetadataReceiver((info) => {
if (info == null) {
childInfo = null;
} else {
childInfo = info;
}
});
const invite = () => {
os.api('admin/invite').then(x => {
os.alert({
type: 'info',
text: x.code,
});
}).catch(err => {
os.alert({
type: 'error',
text: err,
});
});
};
const lookup = (ev) => {
os.popupMenu([{
text: i18n.ts.user,
2022-11-07 11:49:47 +09:00
icon: 'ph-user-bold ph-lg',
action: () => {
lookupUser();
},
}, {
text: i18n.ts.note,
2022-11-07 11:49:47 +09:00
icon: 'ph-pencil-bold ph-lg',
action: () => {
alert('TODO');
},
}, {
text: i18n.ts.file,
2022-11-07 11:49:47 +09:00
icon: 'ph-cloud-bold ph-lg',
action: () => {
alert('TODO');
},
}, {
text: i18n.ts.instance,
2022-11-07 11:49:47 +09:00
icon: 'ph-planet-bold ph-lg',
action: () => {
alert('TODO');
},
}], ev.currentTarget ?? ev.target);
};
const headerActions = $computed(() => []);
const headerTabs = $computed(() => []);
definePageMetadata(INFO);
defineExpose({
header: {
title: i18n.ts.controlPanel,
},
});
</script>
<style lang="scss" scoped>
.hiyeyicy {
&.wide {
display: flex;
margin: 0 auto;
height: 100%;
> .nav {
width: 32%;
2021-10-10 15:19:16 +09:00
max-width: 280px;
box-sizing: border-box;
border-right: solid 0.5px var(--divider);
overflow: auto;
2021-10-10 15:19:16 +09:00
height: 100%;
}
2020-08-13 23:02:43 +09:00
> .main {
flex: 1;
min-width: 0;
}
}
2021-10-10 15:19:16 +09:00
> .nav {
2021-10-24 20:16:55 +09:00
.lxpfedzu {
> .info {
margin: 16px 0;
}
2021-10-24 20:16:55 +09:00
> .banner {
margin: 16px;
2021-10-24 20:16:55 +09:00
> .icon {
display: block;
margin: auto;
height: 42px;
border-radius: 8px;
}
}
}
}
}
</style>