2020-01-30 04:37:25 +09:00
|
|
|
<template>
|
2022-06-20 17:38:49 +09:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-19 20:52:15 +09:00
|
|
|
<MkSpacer :contentMax="900">
|
2023-05-14 10:21:56 +09:00
|
|
|
<div class="_gaps_m">
|
2023-07-24 13:08:39 +09:00
|
|
|
<MkFolder>
|
|
|
|
<template #label>{{ i18n.ts.options }}</template>
|
|
|
|
|
|
|
|
<MkFolder>
|
|
|
|
<template #label>{{ i18n.ts.specifyUser }}</template>
|
|
|
|
<template v-if="user" #suffix>@{{ user.username }}</template>
|
|
|
|
|
|
|
|
<div style="text-align: center;" class="_gaps">
|
|
|
|
<div v-if="user">@{{ user.username }}</div>
|
|
|
|
<div>
|
|
|
|
<MkButton v-if="user == null" primary rounded inline @click="selectUserFilter">{{ i18n.ts.selectUser }}</MkButton>
|
|
|
|
<MkButton v-else danger rounded inline @click="user = null">{{ i18n.ts.remove }}</MkButton>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MkFolder>
|
|
|
|
</MkFolder>
|
2023-07-28 00:29:33 +09:00
|
|
|
<section v-for="announcement in announcements" :key="announcement.id">
|
2023-01-06 13:40:17 +09:00
|
|
|
<div class="_panel _gaps_m" style="padding: 24px;">
|
2023-07-24 13:08:39 +09:00
|
|
|
<MkInput ref="announceTitleEl" v-model="announcement.title" :large="false">
|
|
|
|
<template #label>{{ i18n.ts.title }} <button v-tooltip="i18n.ts.emoji" :class="['_button']" @click="insertEmoji"><i class="ti ti-mood-happy"></i></button></template>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkInput>
|
|
|
|
<MkTextarea v-model="announcement.text">
|
|
|
|
<template #label>{{ i18n.ts.text }}</template>
|
|
|
|
</MkTextarea>
|
|
|
|
<MkInput v-model="announcement.imageUrl">
|
|
|
|
<template #label>{{ i18n.ts.imageUrl }}</template>
|
|
|
|
</MkInput>
|
2023-07-28 00:29:33 +09:00
|
|
|
<MkInput v-model="announcement.displayOrder" type="number">
|
|
|
|
<template #label>{{ i18n.ts.displayOrder }}</template>
|
|
|
|
</MkInput>
|
2023-07-24 13:08:39 +09:00
|
|
|
<MkInput v-model="announcement.closeDuration" type="number">
|
|
|
|
<template #label>{{ i18n.ts.dialogCloseDuration }}</template>
|
|
|
|
<template #suffix>{{ i18n.ts._time.second }}</template>
|
|
|
|
</MkInput>
|
2022-06-20 17:38:49 +09:00
|
|
|
<p v-if="announcement.reads">{{ i18n.t('nUsersRead', { n: announcement.reads }) }}</p>
|
2023-07-24 13:08:39 +09:00
|
|
|
<MkUserCardMini v-if="announcement.userId" :user="announcement.user" @click="editUser(announcement)"></MkUserCardMini>
|
|
|
|
<MkButton v-else class="button" inline primary @click="editUser(announcement)">{{ i18n.ts.specifyUser }}</MkButton>
|
2023-01-06 09:41:14 +09:00
|
|
|
<div class="buttons _buttons">
|
2022-12-19 19:01:30 +09:00
|
|
|
<MkButton class="button" inline primary @click="save(announcement)"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
2023-01-06 09:41:14 +09:00
|
|
|
<MkButton class="button" inline danger @click="remove(announcement)"><i class="ti ti-trash"></i> {{ i18n.ts.remove }}</MkButton>
|
2022-06-20 17:38:49 +09:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
2023-07-28 00:29:33 +09:00
|
|
|
<MkButton v-if="hasMore" :class="$style.more" :disabled="!hasMore" primary rounded @click="fetch()">{{ i18n.ts.loadMore }}</MkButton>
|
2021-10-24 04:03:07 +09:00
|
|
|
</div>
|
2022-06-20 17:38:49 +09:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-30 04:37:25 +09:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
<script lang="ts" setup>
|
2023-07-24 13:08:39 +09:00
|
|
|
import { ref, watch } from 'vue';
|
|
|
|
import { UserLite } from 'misskey-js/built/entities';
|
2022-06-20 17:38:49 +09:00
|
|
|
import XHeader from './_header_.vue';
|
2022-09-06 18:21:49 +09:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 15:09:46 +09:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2023-07-24 13:08:39 +09:00
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
|
|
|
import MkUserCardMini from '@/components/MkUserCardMini.vue';
|
2021-11-12 02:02:25 +09:00
|
|
|
import * as os from '@/os';
|
2022-05-14 21:34:07 +09:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 17:38:49 +09:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
const announceTitleEl = $shallowRef<HTMLInputElement | null>(null);
|
|
|
|
const user = ref<UserLite | null>(null);
|
|
|
|
const offset = ref(0);
|
|
|
|
const hasMore = ref(false);
|
|
|
|
|
2022-05-14 21:34:07 +09:00
|
|
|
let announcements: any[] = $ref([]);
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function insertEmoji(ev: MouseEvent): void {
|
|
|
|
os.openEmojiPicker(ev.currentTarget ?? ev.target, {}, announceTitleEl);
|
|
|
|
}
|
2023-07-24 13:08:39 +09:00
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function selectUserFilter(): void {
|
2023-07-24 13:08:39 +09:00
|
|
|
os.selectUser().then(_user => {
|
|
|
|
user.value = _user;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function editUser(announcement): void {
|
2023-07-24 13:08:39 +09:00
|
|
|
os.selectUser().then(_user => {
|
2023-07-28 00:29:33 +09:00
|
|
|
announcement.userId = _user.id;
|
|
|
|
announcement.user = _user;
|
2023-07-24 13:08:39 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function add(): void {
|
2022-05-14 21:34:07 +09:00
|
|
|
announcements.unshift({
|
|
|
|
id: null,
|
|
|
|
title: '',
|
|
|
|
text: '',
|
2022-06-20 17:38:49 +09:00
|
|
|
imageUrl: null,
|
2023-07-24 13:08:39 +09:00
|
|
|
userId: null,
|
|
|
|
user: null,
|
2023-07-28 00:29:33 +09:00
|
|
|
displayOrder: 0,
|
2023-07-24 13:08:39 +09:00
|
|
|
closeDuration: 10,
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function remove(announcement): void {
|
2022-05-14 21:34:07 +09:00
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
|
|
|
text: i18n.t('removeAreYouSure', { x: announcement.title }),
|
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
announcements = announcements.filter(x => x !== announcement);
|
|
|
|
os.api('admin/announcements/delete', announcement);
|
|
|
|
});
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function save(announcement): void {
|
2022-05-14 21:34:07 +09:00
|
|
|
if (announcement.id == null) {
|
|
|
|
os.api('admin/announcements/create', announcement).then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.saved,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2023-07-28 00:29:33 +09:00
|
|
|
fetch(true);
|
2022-05-14 21:34:07 +09:00
|
|
|
}).catch(err => {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: err,
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
os.api('admin/announcements/update', announcement).then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'success',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.saved,
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
}).catch(err => {
|
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: err,
|
2022-05-14 21:34:07 +09:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2020-01-30 04:37:25 +09:00
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
function fetch(resetOffset = false): void {
|
|
|
|
if (resetOffset) {
|
|
|
|
announcements = [];
|
|
|
|
offset.value = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
os.api('admin/announcements/list', {
|
|
|
|
offsetMode: true,
|
|
|
|
offset: offset.value,
|
|
|
|
limit: 10,
|
|
|
|
userId: user.value?.id,
|
|
|
|
}).then(announcementResponse => {
|
|
|
|
announcements = announcements.concat(announcementResponse);
|
|
|
|
hasMore.value = announcementResponse?.length === 10;
|
|
|
|
offset.value += announcements.length;
|
2023-04-08 17:42:08 +09:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-28 00:29:33 +09:00
|
|
|
watch(user, () => fetch(true));
|
|
|
|
fetch();
|
2023-04-08 17:42:08 +09:00
|
|
|
|
2022-06-20 17:38:49 +09:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-plus',
|
2022-06-20 17:38:49 +09:00
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.announcements,
|
2022-12-19 19:01:30 +09:00
|
|
|
icon: 'ti ti-speakerphone',
|
2020-01-30 04:37:25 +09:00
|
|
|
});
|
|
|
|
</script>
|
2023-07-28 00:29:33 +09:00
|
|
|
|
|
|
|
<style lang="scss" module>
|
|
|
|
.more {
|
|
|
|
margin-left: auto;
|
|
|
|
margin-right: auto;
|
|
|
|
}
|
|
|
|
</style>
|