2020-01-29 19:37:25 +00:00
|
|
|
<template>
|
2021-12-10 12:41:37 +00:00
|
|
|
<MkSpacer :content-max="900">
|
|
|
|
<div class="ogwlenmc">
|
|
|
|
<div v-if="tab === 'local'" class="local">
|
|
|
|
<MkInput v-model="query" :debounce="true" type="search">
|
|
|
|
<template #prefix><i class="fas fa-search"></i></template>
|
|
|
|
<template #label>{{ $ts.search }}</template>
|
|
|
|
</MkInput>
|
2022-01-12 15:47:05 +00:00
|
|
|
<MkSwitch v-model="selectMode" style="margin: 8px 0;">
|
|
|
|
<template #label>Select mode</template>
|
|
|
|
</MkSwitch>
|
|
|
|
<div v-if="selectMode" style="display: flex; gap: var(--margin); flex-wrap: wrap;">
|
|
|
|
<MkButton inline @click="selectAll">Select all</MkButton>
|
|
|
|
<MkButton inline @click="setCategoryBulk">Set category</MkButton>
|
|
|
|
<MkButton inline @click="addTagBulk">Add tag</MkButton>
|
|
|
|
<MkButton inline @click="removeTagBulk">Remove tag</MkButton>
|
|
|
|
<MkButton inline @click="setTagBulk">Set tag</MkButton>
|
|
|
|
<MkButton inline danger @click="delBulk">Delete</MkButton>
|
|
|
|
</div>
|
|
|
|
<MkPagination ref="emojisPaginationComponent" :pagination="pagination">
|
2021-12-10 12:41:37 +00:00
|
|
|
<template #empty><span>{{ $ts.noCustomEmojis }}</span></template>
|
|
|
|
<template v-slot="{items}">
|
|
|
|
<div class="ldhfsamy">
|
2022-01-12 15:47:05 +00:00
|
|
|
<button v-for="emoji in items" :key="emoji.id" class="emoji _panel _button" :class="{ selected: selectedEmojis.includes(emoji.id) }" @click="selectMode ? toggleSelect(emoji) : edit(emoji)">
|
2021-12-10 12:41:37 +00:00
|
|
|
<img :src="emoji.url" class="img" :alt="emoji.name"/>
|
|
|
|
<div class="body">
|
|
|
|
<div class="name _monospace">{{ emoji.name }}</div>
|
|
|
|
<div class="info">{{ emoji.category }}</div>
|
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2021-12-10 12:41:37 +00:00
|
|
|
<div v-else-if="tab === 'remote'" class="remote">
|
2021-12-30 12:47:48 +00:00
|
|
|
<FormSplit>
|
2021-12-10 12:41:37 +00:00
|
|
|
<MkInput v-model="queryRemote" :debounce="true" type="search">
|
|
|
|
<template #prefix><i class="fas fa-search"></i></template>
|
|
|
|
<template #label>{{ $ts.search }}</template>
|
|
|
|
</MkInput>
|
|
|
|
<MkInput v-model="host" :debounce="true">
|
|
|
|
<template #label>{{ $ts.host }}</template>
|
|
|
|
</MkInput>
|
2021-12-30 12:47:48 +00:00
|
|
|
</FormSplit>
|
2022-01-12 15:47:05 +00:00
|
|
|
<MkPagination :pagination="remotePagination">
|
2021-12-10 12:41:37 +00:00
|
|
|
<template #empty><span>{{ $ts.noCustomEmojis }}</span></template>
|
|
|
|
<template v-slot="{items}">
|
|
|
|
<div class="ldhfsamy">
|
|
|
|
<div v-for="emoji in items" :key="emoji.id" class="emoji _panel _button" @click="remoteMenu(emoji, $event)">
|
|
|
|
<img :src="emoji.url" class="img" :alt="emoji.name"/>
|
|
|
|
<div class="body">
|
|
|
|
<div class="name _monospace">{{ emoji.name }}</div>
|
|
|
|
<div class="info">{{ emoji.host }}</div>
|
|
|
|
</div>
|
2020-01-29 19:37:25 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
2021-12-10 12:41:37 +00:00
|
|
|
</template>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
2020-10-17 11:12:00 +00:00
|
|
|
</div>
|
2021-12-10 12:41:37 +00:00
|
|
|
</MkSpacer>
|
2020-01-29 19:37:25 +00:00
|
|
|
</template>
|
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
<script lang="ts" setup>
|
2022-05-01 13:51:07 +00:00
|
|
|
import { computed, defineAsyncComponent, defineComponent, ref, toRef } from 'vue';
|
2021-11-11 17:02:25 +00:00
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import MkInput from '@/components/form/input.vue';
|
|
|
|
import MkPagination from '@/components/ui/pagination.vue';
|
|
|
|
import MkTab from '@/components/tab.vue';
|
2022-01-12 15:47:05 +00:00
|
|
|
import MkSwitch from '@/components/form/switch.vue';
|
2021-12-30 12:47:48 +00:00
|
|
|
import FormSplit from '@/components/form/split.vue';
|
2022-01-12 15:47:05 +00:00
|
|
|
import { selectFile, selectFiles } from '@/scripts/select-file';
|
2021-11-11 17:02:25 +00:00
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2022-01-12 15:47:05 +00:00
|
|
|
import { i18n } from '@/i18n';
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const emojisPaginationComponent = ref<InstanceType<typeof MkPagination>>();
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const tab = ref('local');
|
|
|
|
const query = ref(null);
|
|
|
|
const queryRemote = ref(null);
|
|
|
|
const host = ref(null);
|
|
|
|
const selectMode = ref(false);
|
|
|
|
const selectedEmojis = ref<string[]>([]);
|
2021-04-22 13:29:33 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const pagination = {
|
2022-01-12 17:26:10 +00:00
|
|
|
endpoint: 'admin/emoji/list' as const,
|
2022-01-12 15:47:05 +00:00
|
|
|
limit: 30,
|
|
|
|
params: computed(() => ({
|
|
|
|
query: (query.value && query.value !== '') ? query.value : null,
|
|
|
|
})),
|
|
|
|
};
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const remotePagination = {
|
2022-01-12 17:26:10 +00:00
|
|
|
endpoint: 'admin/emoji/list-remote' as const,
|
2022-01-12 15:47:05 +00:00
|
|
|
limit: 30,
|
|
|
|
params: computed(() => ({
|
|
|
|
query: (queryRemote.value && queryRemote.value !== '') ? queryRemote.value : null,
|
|
|
|
host: (host.value && host.value !== '') ? host.value : null,
|
|
|
|
})),
|
|
|
|
};
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const selectAll = () => {
|
|
|
|
if (selectedEmojis.value.length > 0) {
|
|
|
|
selectedEmojis.value = [];
|
|
|
|
} else {
|
|
|
|
selectedEmojis.value = emojisPaginationComponent.value.items.map(item => item.id);
|
|
|
|
}
|
|
|
|
};
|
2020-02-13 16:09:39 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const toggleSelect = (emoji) => {
|
|
|
|
if (selectedEmojis.value.includes(emoji.id)) {
|
|
|
|
selectedEmojis.value = selectedEmojis.value.filter(x => x !== emoji.id);
|
|
|
|
} else {
|
|
|
|
selectedEmojis.value.push(emoji.id);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
const add = async (ev: MouseEvent) => {
|
2022-01-28 02:53:12 +00:00
|
|
|
const files = await selectFiles(ev.currentTarget ?? ev.target, null);
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const promise = Promise.all(files.map(file => os.api('admin/emoji/add', {
|
|
|
|
fileId: file.id,
|
|
|
|
})));
|
|
|
|
promise.then(() => {
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
});
|
|
|
|
os.promiseDialog(promise);
|
|
|
|
};
|
|
|
|
|
|
|
|
const edit = (emoji) => {
|
2022-05-01 13:51:07 +00:00
|
|
|
os.popup(defineAsyncComponent(() => import('./emoji-edit-dialog.vue')), {
|
2022-01-12 15:47:05 +00:00
|
|
|
emoji: emoji
|
|
|
|
}, {
|
|
|
|
done: result => {
|
|
|
|
if (result.updated) {
|
2022-05-15 13:20:01 +00:00
|
|
|
emojisPaginationComponent.value.updateItem(result.updated.id, (oldEmoji: any) => ({
|
|
|
|
...oldEmoji,
|
2022-01-12 15:47:05 +00:00
|
|
|
...result.updated
|
2022-05-15 13:20:01 +00:00
|
|
|
}));
|
2022-01-12 15:47:05 +00:00
|
|
|
} else if (result.deleted) {
|
2022-05-15 13:20:01 +00:00
|
|
|
emojisPaginationComponent.value.removeItem((item) => item.id === emoji.id);
|
2022-01-12 15:47:05 +00:00
|
|
|
}
|
2021-12-10 12:41:37 +00:00
|
|
|
},
|
2022-01-12 15:47:05 +00:00
|
|
|
}, 'closed');
|
|
|
|
};
|
2021-12-10 12:41:37 +00:00
|
|
|
|
2022-01-12 15:47:05 +00:00
|
|
|
const im = (emoji) => {
|
|
|
|
os.apiWithDialog('admin/emoji/copy', {
|
|
|
|
emojiId: emoji.id,
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const remoteMenu = (emoji, ev: MouseEvent) => {
|
|
|
|
os.popupMenu([{
|
|
|
|
type: 'label',
|
|
|
|
text: ':' + emoji.name + ':',
|
|
|
|
}, {
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.import,
|
2022-01-12 15:47:05 +00:00
|
|
|
icon: 'fas fa-plus',
|
2022-06-10 05:36:55 +00:00
|
|
|
action: () => { im(emoji); }
|
2022-01-28 02:53:12 +00:00
|
|
|
}], ev.currentTarget ?? ev.target);
|
2022-01-12 15:47:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const menu = (ev: MouseEvent) => {
|
|
|
|
os.popupMenu([{
|
|
|
|
icon: 'fas fa-download',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.export,
|
2022-01-12 15:47:05 +00:00
|
|
|
action: async () => {
|
|
|
|
os.api('export-custom-emojis', {
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'info',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.exportRequested,
|
2022-01-12 15:47:05 +00:00
|
|
|
});
|
2022-05-26 13:53:09 +00:00
|
|
|
}).catch((err) => {
|
2022-01-12 15:47:05 +00:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-05-26 13:53:09 +00:00
|
|
|
text: err.message,
|
2022-01-12 15:47:05 +00:00
|
|
|
});
|
|
|
|
});
|
2020-10-17 11:12:00 +00:00
|
|
|
}
|
2022-01-12 15:47:40 +00:00
|
|
|
}, {
|
|
|
|
icon: 'fas fa-upload',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.import,
|
2022-01-12 15:47:40 +00:00
|
|
|
action: async () => {
|
2022-01-28 02:53:12 +00:00
|
|
|
const file = await selectFile(ev.currentTarget ?? ev.target);
|
2022-01-12 15:47:40 +00:00
|
|
|
os.api('admin/emoji/import-zip', {
|
|
|
|
fileId: file.id,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'info',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.importRequested,
|
2022-01-12 15:47:40 +00:00
|
|
|
});
|
2022-05-26 13:53:09 +00:00
|
|
|
}).catch((err) => {
|
2022-01-12 15:47:40 +00:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-05-26 13:53:09 +00:00
|
|
|
text: err.message,
|
2022-01-12 15:47:40 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
2022-01-28 02:53:12 +00:00
|
|
|
}], ev.currentTarget ?? ev.target);
|
2022-01-12 15:47:05 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
const setCategoryBulk = async () => {
|
|
|
|
const { canceled, result } = await os.inputText({
|
|
|
|
title: 'Category',
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('admin/emoji/set-category-bulk', {
|
|
|
|
ids: selectedEmojis.value,
|
|
|
|
category: result,
|
|
|
|
});
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
const addTagBulk = async () => {
|
|
|
|
const { canceled, result } = await os.inputText({
|
|
|
|
title: 'Tag',
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('admin/emoji/add-aliases-bulk', {
|
|
|
|
ids: selectedEmojis.value,
|
|
|
|
aliases: result.split(' '),
|
|
|
|
});
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
const removeTagBulk = async () => {
|
|
|
|
const { canceled, result } = await os.inputText({
|
|
|
|
title: 'Tag',
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('admin/emoji/remove-aliases-bulk', {
|
|
|
|
ids: selectedEmojis.value,
|
|
|
|
aliases: result.split(' '),
|
|
|
|
});
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
const setTagBulk = async () => {
|
|
|
|
const { canceled, result } = await os.inputText({
|
|
|
|
title: 'Tag',
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('admin/emoji/set-aliases-bulk', {
|
|
|
|
ids: selectedEmojis.value,
|
|
|
|
aliases: result.split(' '),
|
|
|
|
});
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
const delBulk = async () => {
|
|
|
|
const { canceled } = await os.confirm({
|
|
|
|
type: 'warning',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.deleteConfirm,
|
2022-01-12 15:47:05 +00:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('admin/emoji/delete-bulk', {
|
|
|
|
ids: selectedEmojis.value,
|
|
|
|
});
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
};
|
|
|
|
|
|
|
|
defineExpose({
|
|
|
|
[symbols.PAGE_INFO]: computed(() => ({
|
2022-01-28 02:39:49 +00:00
|
|
|
title: i18n.ts.customEmojis,
|
2022-01-12 15:47:05 +00:00
|
|
|
icon: 'fas fa-laugh',
|
|
|
|
bg: 'var(--bg)',
|
|
|
|
actions: [{
|
|
|
|
asFullButton: true,
|
|
|
|
icon: 'fas fa-plus',
|
2022-01-28 02:39:49 +00:00
|
|
|
text: i18n.ts.addEmoji,
|
2022-01-12 15:47:05 +00:00
|
|
|
handler: add,
|
|
|
|
}, {
|
|
|
|
icon: 'fas fa-ellipsis-h',
|
|
|
|
handler: menu,
|
|
|
|
}],
|
|
|
|
tabs: [{
|
|
|
|
active: tab.value === 'local',
|
2022-01-28 02:39:49 +00:00
|
|
|
title: i18n.ts.local,
|
2022-01-12 15:47:05 +00:00
|
|
|
onClick: () => { tab.value = 'local'; },
|
|
|
|
}, {
|
|
|
|
active: tab.value === 'remote',
|
2022-01-28 02:39:49 +00:00
|
|
|
title: i18n.ts.remote,
|
2022-01-12 15:47:05 +00:00
|
|
|
onClick: () => { tab.value = 'remote'; },
|
|
|
|
},]
|
|
|
|
})),
|
2020-01-29 19:37:25 +00:00
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-04-22 13:29:33 +00:00
|
|
|
.ogwlenmc {
|
|
|
|
> .local {
|
2021-12-10 12:41:37 +00:00
|
|
|
.empty {
|
|
|
|
margin: var(--margin);
|
2021-10-31 10:22:19 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
.ldhfsamy {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-12-10 12:41:37 +00:00
|
|
|
margin: var(--margin) 0;
|
2021-04-22 13:29:33 +00:00
|
|
|
|
|
|
|
> .emoji {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2022-01-12 15:47:05 +00:00
|
|
|
padding: 11px;
|
2021-04-22 13:29:33 +00:00
|
|
|
text-align: left;
|
2022-01-12 15:47:05 +00:00
|
|
|
border: solid 1px var(--panel);
|
2021-04-22 13:29:33 +00:00
|
|
|
|
|
|
|
&:hover {
|
2022-01-12 15:47:05 +00:00
|
|
|
border-color: var(--inputBorderHover);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
border-color: var(--accent);
|
2021-04-22 13:29:33 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .img {
|
|
|
|
width: 42px;
|
|
|
|
height: 42px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .body {
|
|
|
|
padding: 0 0 0 8px;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .name {
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2020-02-13 16:09:39 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .info {
|
|
|
|
opacity: 0.5;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-22 13:29:33 +00:00
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .remote {
|
2021-12-10 12:41:37 +00:00
|
|
|
.empty {
|
|
|
|
margin: var(--margin);
|
|
|
|
}
|
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
.ldhfsamy {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-12-10 12:41:37 +00:00
|
|
|
margin: var(--margin) 0;
|
2021-04-22 13:29:33 +00:00
|
|
|
|
|
|
|
> .emoji {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 12px;
|
|
|
|
text-align: left;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2020-10-17 11:12:00 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .img {
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
}
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .body {
|
|
|
|
padding: 0 0 0 8px;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .name {
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
|
2021-04-22 13:29:33 +00:00
|
|
|
> .info {
|
|
|
|
opacity: 0.5;
|
|
|
|
font-size: 90%;
|
|
|
|
text-overflow: ellipsis;
|
2021-03-02 13:57:16 +00:00
|
|
|
overflow: hidden;
|
2020-01-29 19:37:25 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|