2023-07-27 05:31:52 +00:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: syuilo and other misskey contributors
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-only
|
|
|
|
-->
|
|
|
|
|
2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2022-06-20 08:38:49 +00:00
|
|
|
<MkStickyContainer>
|
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs"/></template>
|
2023-05-19 11:52:15 +00:00
|
|
|
<MkSpacer :contentMax="900">
|
2023-08-13 11:12:29 +00:00
|
|
|
<div class="_gaps">
|
|
|
|
<MkInfo v-if="announcements.length > 5" warn>{{ i18n.ts._announcement.tooManyActiveAnnouncementDescription }}</MkInfo>
|
|
|
|
|
|
|
|
<MkFolder v-for="announcement in announcements" :key="announcement.id ?? announcement._id" :defaultOpen="announcement.id == null">
|
|
|
|
<template #label>{{ announcement.title }}</template>
|
|
|
|
<template #icon>
|
|
|
|
<i v-if="announcement.icon === 'info'" class="ti ti-info-circle"></i>
|
|
|
|
<i v-else-if="announcement.icon === 'warning'" class="ti ti-alert-triangle" style="color: var(--warn);"></i>
|
|
|
|
<i v-else-if="announcement.icon === 'error'" class="ti ti-circle-x" style="color: var(--error);"></i>
|
|
|
|
<i v-else-if="announcement.icon === 'success'" class="ti ti-check" style="color: var(--success);"></i>
|
|
|
|
</template>
|
|
|
|
<template #caption>{{ announcement.text }}</template>
|
|
|
|
|
|
|
|
<div class="_gaps_m">
|
2022-06-20 08:38:49 +00:00
|
|
|
<MkInput v-model="announcement.title">
|
|
|
|
<template #label>{{ i18n.ts.title }}</template>
|
|
|
|
</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-08-13 11:12:29 +00:00
|
|
|
<MkRadios v-model="announcement.icon">
|
|
|
|
<template #label>{{ i18n.ts.icon }}</template>
|
|
|
|
<option value="info"><i class="ti ti-info-circle"></i></option>
|
|
|
|
<option value="warning"><i class="ti ti-alert-triangle" style="color: var(--warn);"></i></option>
|
|
|
|
<option value="error"><i class="ti ti-circle-x" style="color: var(--error);"></i></option>
|
|
|
|
<option value="success"><i class="ti ti-check" style="color: var(--success);"></i></option>
|
|
|
|
</MkRadios>
|
|
|
|
<MkRadios v-model="announcement.display">
|
|
|
|
<template #label>{{ i18n.ts.display }}</template>
|
|
|
|
<option value="normal">{{ i18n.ts.normal }}</option>
|
|
|
|
<option value="banner">{{ i18n.ts.banner }}</option>
|
|
|
|
<option value="dialog">{{ i18n.ts.dialog }}</option>
|
|
|
|
</MkRadios>
|
|
|
|
<MkSwitch v-model="announcement.forExistingUsers" :helpText="i18n.ts._announcement.forExistingUsersDescription">
|
|
|
|
{{ i18n.ts._announcement.forExistingUsers }}
|
|
|
|
</MkSwitch>
|
|
|
|
<MkSwitch v-model="announcement.needConfirmationToRead" :helpText="i18n.ts._announcement.needConfirmationToReadDescription">
|
|
|
|
{{ i18n.ts._announcement.needConfirmationToRead }}
|
|
|
|
</MkSwitch>
|
2022-06-20 08:38:49 +00:00
|
|
|
<p v-if="announcement.reads">{{ i18n.t('nUsersRead', { n: announcement.reads }) }}</p>
|
2023-01-06 00:41:14 +00:00
|
|
|
<div class="buttons _buttons">
|
2022-12-19 10:01:30 +00:00
|
|
|
<MkButton class="button" inline primary @click="save(announcement)"><i class="ti ti-device-floppy"></i> {{ i18n.ts.save }}</MkButton>
|
2023-08-13 11:12:29 +00:00
|
|
|
<MkButton v-if="announcement.id != null" class="button" inline @click="archive(announcement)"><i class="ti ti-check"></i> {{ i18n.ts._announcement.end }} ({{ i18n.ts.archive }})</MkButton>
|
|
|
|
<MkButton v-if="announcement.id != null" class="button" inline danger @click="del(announcement)"><i class="ti ti-trash"></i> {{ i18n.ts.delete }}</MkButton>
|
2022-06-20 08:38:49 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2023-08-13 11:12:29 +00:00
|
|
|
</MkFolder>
|
2021-10-23 19:03:07 +00:00
|
|
|
</div>
|
2022-06-20 08:38:49 +00:00
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
2020-01-29 19:37:25 +00:00
|
|
|
</template>
|
|
|
|
|
2022-05-14 12:34:07 +00:00
|
|
|
<script lang="ts" setup>
|
|
|
|
import { } from 'vue';
|
2022-06-20 08:38:49 +00:00
|
|
|
import XHeader from './_header_.vue';
|
2022-09-06 09:21:49 +00:00
|
|
|
import MkButton from '@/components/MkButton.vue';
|
2023-01-07 06:09:46 +00:00
|
|
|
import MkInput from '@/components/MkInput.vue';
|
|
|
|
import MkTextarea from '@/components/MkTextarea.vue';
|
2023-08-13 11:12:29 +00:00
|
|
|
import MkSwitch from '@/components/MkSwitch.vue';
|
|
|
|
import MkRadios from '@/components/MkRadios.vue';
|
|
|
|
import MkInfo from '@/components/MkInfo.vue';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
2022-05-14 12:34:07 +00:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 08:38:49 +00:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2023-08-13 11:12:29 +00:00
|
|
|
import MkFolder from '@/components/MkFolder.vue';
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-05-14 12:34:07 +00:00
|
|
|
let announcements: any[] = $ref([]);
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-05-14 12:34:07 +00:00
|
|
|
os.api('admin/announcements/list').then(announcementResponse => {
|
|
|
|
announcements = announcementResponse;
|
|
|
|
});
|
2021-04-22 13:29:33 +00:00
|
|
|
|
2022-05-14 12:34:07 +00:00
|
|
|
function add() {
|
|
|
|
announcements.unshift({
|
2023-08-13 11:12:29 +00:00
|
|
|
_id: Math.random().toString(36),
|
2022-05-14 12:34:07 +00:00
|
|
|
id: null,
|
2023-08-13 11:12:29 +00:00
|
|
|
title: 'New announcement',
|
2022-05-14 12:34:07 +00:00
|
|
|
text: '',
|
2022-06-20 08:38:49 +00:00
|
|
|
imageUrl: null,
|
2023-08-13 11:12:29 +00:00
|
|
|
icon: 'info',
|
|
|
|
display: 'normal',
|
|
|
|
forExistingUsers: false,
|
|
|
|
needConfirmationToRead: false,
|
2022-05-14 12:34:07 +00:00
|
|
|
});
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-08-13 11:12:29 +00:00
|
|
|
function del(announcement) {
|
2022-05-14 12:34:07 +00:00
|
|
|
os.confirm({
|
|
|
|
type: 'warning',
|
2023-08-13 11:12:29 +00:00
|
|
|
text: i18n.t('deleteAreYouSure', { x: announcement.title }),
|
2022-05-14 12:34:07 +00:00
|
|
|
}).then(({ canceled }) => {
|
|
|
|
if (canceled) return;
|
|
|
|
announcements = announcements.filter(x => x !== announcement);
|
|
|
|
os.api('admin/announcements/delete', announcement);
|
|
|
|
});
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-08-13 11:12:29 +00:00
|
|
|
async function archive(announcement) {
|
|
|
|
await os.apiWithDialog('admin/announcements/update', {
|
|
|
|
...announcement,
|
|
|
|
isActive: false,
|
|
|
|
});
|
|
|
|
refresh();
|
|
|
|
}
|
|
|
|
|
|
|
|
async function save(announcement) {
|
2022-05-14 12:34:07 +00:00
|
|
|
if (announcement.id == null) {
|
2023-08-13 11:12:29 +00:00
|
|
|
await os.apiWithDialog('admin/announcements/create', announcement);
|
|
|
|
refresh();
|
2022-05-14 12:34:07 +00:00
|
|
|
} else {
|
2023-08-13 11:12:29 +00:00
|
|
|
os.apiWithDialog('admin/announcements/update', announcement);
|
2022-05-14 12:34:07 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2023-04-08 08:42:08 +00:00
|
|
|
function refresh() {
|
|
|
|
os.api('admin/announcements/list').then(announcementResponse => {
|
|
|
|
announcements = announcementResponse;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
refresh();
|
|
|
|
|
2022-06-20 08:38:49 +00:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-plus',
|
2022-06-20 08:38:49 +00:00
|
|
|
text: i18n.ts.add,
|
|
|
|
handler: add,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => []);
|
|
|
|
|
|
|
|
definePageMetadata({
|
|
|
|
title: i18n.ts.announcements,
|
2022-12-19 10:01:30 +00:00
|
|
|
icon: 'ti ti-speakerphone',
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
</script>
|