2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
2022-06-20 11:38:49 +03:00
|
|
|
<div>
|
|
|
|
<MkStickyContainer>
|
2022-06-22 10:29:21 +03:00
|
|
|
<template #header><XHeader :actions="headerActions" :tabs="headerTabs" v-model:tab="tab"/></template>
|
2022-06-20 11:38:49 +03: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>
|
|
|
|
<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>
|
2021-12-10 14:41:37 +02:00
|
|
|
</div>
|
2022-06-20 11:38:49 +03:00
|
|
|
<MkPagination ref="emojisPaginationComponent" :pagination="pagination">
|
|
|
|
<template #empty><span>{{ $ts.noCustomEmojis }}</span></template>
|
|
|
|
<template #default="{items}">
|
|
|
|
<div class="ldhfsamy">
|
|
|
|
<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)">
|
|
|
|
<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 14:12:00 +03:00
|
|
|
|
2022-06-20 11:38:49 +03:00
|
|
|
<div v-else-if="tab === 'remote'" class="remote">
|
|
|
|
<FormSplit>
|
|
|
|
<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>
|
|
|
|
</FormSplit>
|
|
|
|
<MkPagination :pagination="remotePagination">
|
|
|
|
<template #empty><span>{{ $ts.noCustomEmojis }}</span></template>
|
|
|
|
<template #default="{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>
|
|
|
|
</div>
|
2021-12-10 14:41:37 +02:00
|
|
|
</div>
|
2022-06-20 11:38:49 +03:00
|
|
|
</template>
|
|
|
|
</MkPagination>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</MkSpacer>
|
|
|
|
</MkStickyContainer>
|
|
|
|
</div>
|
2020-01-29 21:37:25 +02:00
|
|
|
</template>
|
|
|
|
|
2022-01-12 17:47:05 +02:00
|
|
|
<script lang="ts" setup>
|
2022-05-01 16:51:07 +03:00
|
|
|
import { computed, defineAsyncComponent, defineComponent, ref, toRef } from 'vue';
|
2022-06-20 11:38:49 +03:00
|
|
|
import XHeader from './_header_.vue';
|
2021-11-11 19:02:25 +02: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 17:47:05 +02:00
|
|
|
import MkSwitch from '@/components/form/switch.vue';
|
2021-12-30 14:47:48 +02:00
|
|
|
import FormSplit from '@/components/form/split.vue';
|
2022-01-12 17:47:05 +02:00
|
|
|
import { selectFile, selectFiles } from '@/scripts/select-file';
|
2021-11-11 19:02:25 +02:00
|
|
|
import * as os from '@/os';
|
2022-01-12 17:47:05 +02:00
|
|
|
import { i18n } from '@/i18n';
|
2022-06-20 11:38:49 +03:00
|
|
|
import { definePageMetadata } from '@/scripts/page-metadata';
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2022-01-12 17:47:05 +02:00
|
|
|
const emojisPaginationComponent = ref<InstanceType<typeof MkPagination>>();
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-12 17:47:05 +02: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 16:29:33 +03:00
|
|
|
|
2022-01-12 17:47:05 +02:00
|
|
|
const pagination = {
|
2022-01-12 19:26:10 +02:00
|
|
|
endpoint: 'admin/emoji/list' as const,
|
2022-01-12 17:47:05 +02:00
|
|
|
limit: 30,
|
|
|
|
params: computed(() => ({
|
|
|
|
query: (query.value && query.value !== '') ? query.value : null,
|
|
|
|
})),
|
|
|
|
};
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-12 17:47:05 +02:00
|
|
|
const remotePagination = {
|
2022-01-12 19:26:10 +02:00
|
|
|
endpoint: 'admin/emoji/list-remote' as const,
|
2022-01-12 17:47:05 +02:00
|
|
|
limit: 30,
|
|
|
|
params: computed(() => ({
|
|
|
|
query: (queryRemote.value && queryRemote.value !== '') ? queryRemote.value : null,
|
|
|
|
host: (host.value && host.value !== '') ? host.value : null,
|
|
|
|
})),
|
|
|
|
};
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-12 17:47:05 +02:00
|
|
|
const selectAll = () => {
|
|
|
|
if (selectedEmojis.value.length > 0) {
|
|
|
|
selectedEmojis.value = [];
|
|
|
|
} else {
|
|
|
|
selectedEmojis.value = emojisPaginationComponent.value.items.map(item => item.id);
|
|
|
|
}
|
|
|
|
};
|
2020-02-13 18:09:39 +02:00
|
|
|
|
2022-01-12 17:47:05 +02: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 04:53:12 +02:00
|
|
|
const files = await selectFiles(ev.currentTarget ?? ev.target, null);
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2022-01-12 17:47:05 +02: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 16:51:07 +03:00
|
|
|
os.popup(defineAsyncComponent(() => import('./emoji-edit-dialog.vue')), {
|
2022-06-20 11:38:49 +03:00
|
|
|
emoji: emoji,
|
2022-01-12 17:47:05 +02:00
|
|
|
}, {
|
|
|
|
done: result => {
|
|
|
|
if (result.updated) {
|
2022-05-15 16:20:01 +03:00
|
|
|
emojisPaginationComponent.value.updateItem(result.updated.id, (oldEmoji: any) => ({
|
|
|
|
...oldEmoji,
|
2022-06-20 11:38:49 +03:00
|
|
|
...result.updated,
|
2022-05-15 16:20:01 +03:00
|
|
|
}));
|
2022-01-12 17:47:05 +02:00
|
|
|
} else if (result.deleted) {
|
2022-05-15 16:20:01 +03:00
|
|
|
emojisPaginationComponent.value.removeItem((item) => item.id === emoji.id);
|
2022-01-12 17:47:05 +02:00
|
|
|
}
|
2021-12-10 14:41:37 +02:00
|
|
|
},
|
2022-01-12 17:47:05 +02:00
|
|
|
}, 'closed');
|
|
|
|
};
|
2021-12-10 14:41:37 +02:00
|
|
|
|
2022-01-12 17:47:05 +02: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 04:39:49 +02:00
|
|
|
text: i18n.ts.import,
|
2022-01-12 17:47:05 +02:00
|
|
|
icon: 'fas fa-plus',
|
2022-06-20 11:38:49 +03:00
|
|
|
action: () => { im(emoji); },
|
2022-01-28 04:53:12 +02:00
|
|
|
}], ev.currentTarget ?? ev.target);
|
2022-01-12 17:47:05 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
const menu = (ev: MouseEvent) => {
|
|
|
|
os.popupMenu([{
|
|
|
|
icon: 'fas fa-download',
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts.export,
|
2022-01-12 17:47:05 +02:00
|
|
|
action: async () => {
|
|
|
|
os.api('export-custom-emojis', {
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'info',
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts.exportRequested,
|
2022-01-12 17:47:05 +02:00
|
|
|
});
|
2022-05-26 16:53:09 +03:00
|
|
|
}).catch((err) => {
|
2022-01-12 17:47:05 +02:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-05-26 16:53:09 +03:00
|
|
|
text: err.message,
|
2022-01-12 17:47:05 +02:00
|
|
|
});
|
|
|
|
});
|
2022-06-20 11:38:49 +03:00
|
|
|
},
|
2022-01-12 17:47:40 +02:00
|
|
|
}, {
|
|
|
|
icon: 'fas fa-upload',
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts.import,
|
2022-01-12 17:47:40 +02:00
|
|
|
action: async () => {
|
2022-01-28 04:53:12 +02:00
|
|
|
const file = await selectFile(ev.currentTarget ?? ev.target);
|
2022-01-12 17:47:40 +02:00
|
|
|
os.api('admin/emoji/import-zip', {
|
|
|
|
fileId: file.id,
|
|
|
|
})
|
|
|
|
.then(() => {
|
|
|
|
os.alert({
|
|
|
|
type: 'info',
|
2022-01-28 04:39:49 +02:00
|
|
|
text: i18n.ts.importRequested,
|
2022-01-12 17:47:40 +02:00
|
|
|
});
|
2022-05-26 16:53:09 +03:00
|
|
|
}).catch((err) => {
|
2022-01-12 17:47:40 +02:00
|
|
|
os.alert({
|
|
|
|
type: 'error',
|
2022-05-26 16:53:09 +03:00
|
|
|
text: err.message,
|
2022-01-12 17:47:40 +02:00
|
|
|
});
|
|
|
|
});
|
2022-06-20 11:38:49 +03:00
|
|
|
},
|
2022-01-28 04:53:12 +02:00
|
|
|
}], ev.currentTarget ?? ev.target);
|
2022-01-12 17:47:05 +02: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 04:39:49 +02:00
|
|
|
text: i18n.ts.deleteConfirm,
|
2022-01-12 17:47:05 +02:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
await os.apiWithDialog('admin/emoji/delete-bulk', {
|
|
|
|
ids: selectedEmojis.value,
|
|
|
|
});
|
|
|
|
emojisPaginationComponent.value.reload();
|
|
|
|
};
|
|
|
|
|
2022-06-20 11:38:49 +03:00
|
|
|
const headerActions = $computed(() => [{
|
|
|
|
asFullButton: true,
|
|
|
|
icon: 'fas fa-plus',
|
|
|
|
text: i18n.ts.addEmoji,
|
|
|
|
handler: add,
|
|
|
|
}, {
|
|
|
|
icon: 'fas fa-ellipsis-h',
|
|
|
|
handler: menu,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
const headerTabs = $computed(() => [{
|
2022-06-22 10:29:21 +03:00
|
|
|
key: 'local',
|
2022-06-20 11:38:49 +03:00
|
|
|
title: i18n.ts.local,
|
|
|
|
}, {
|
2022-06-22 10:29:21 +03:00
|
|
|
key: 'remote',
|
2022-06-20 11:38:49 +03:00
|
|
|
title: i18n.ts.remote,
|
|
|
|
}]);
|
|
|
|
|
|
|
|
definePageMetadata(computed(() => ({
|
|
|
|
title: i18n.ts.customEmojis,
|
|
|
|
icon: 'fas fa-laugh',
|
|
|
|
bg: 'var(--bg)',
|
|
|
|
})));
|
2020-01-29 21:37:25 +02:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
2021-04-22 16:29:33 +03:00
|
|
|
.ogwlenmc {
|
|
|
|
> .local {
|
2021-12-10 14:41:37 +02:00
|
|
|
.empty {
|
|
|
|
margin: var(--margin);
|
2021-10-31 12:22:19 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
.ldhfsamy {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-12-10 14:41:37 +02:00
|
|
|
margin: var(--margin) 0;
|
2021-04-22 16:29:33 +03:00
|
|
|
|
|
|
|
> .emoji {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2022-01-12 17:47:05 +02:00
|
|
|
padding: 11px;
|
2021-04-22 16:29:33 +03:00
|
|
|
text-align: left;
|
2022-01-12 17:47:05 +02:00
|
|
|
border: solid 1px var(--panel);
|
2021-04-22 16:29:33 +03:00
|
|
|
|
|
|
|
&:hover {
|
2022-01-12 17:47:05 +02:00
|
|
|
border-color: var(--inputBorderHover);
|
|
|
|
}
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
border-color: var(--accent);
|
2021-04-22 16:29:33 +03:00
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .img {
|
|
|
|
width: 42px;
|
|
|
|
height: 42px;
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .body {
|
|
|
|
padding: 0 0 0 8px;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .name {
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
|
|
|
}
|
2020-02-13 18:09:39 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .info {
|
|
|
|
opacity: 0.5;
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-04-22 16:29:33 +03:00
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .remote {
|
2021-12-10 14:41:37 +02:00
|
|
|
.empty {
|
|
|
|
margin: var(--margin);
|
|
|
|
}
|
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
.ldhfsamy {
|
|
|
|
display: grid;
|
|
|
|
grid-template-columns: repeat(auto-fill, minmax(190px, 1fr));
|
|
|
|
grid-gap: 12px;
|
2021-12-10 14:41:37 +02:00
|
|
|
margin: var(--margin) 0;
|
2021-04-22 16:29:33 +03:00
|
|
|
|
|
|
|
> .emoji {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
padding: 12px;
|
|
|
|
text-align: left;
|
|
|
|
|
|
|
|
&:hover {
|
|
|
|
color: var(--accent);
|
|
|
|
}
|
2020-10-17 14:12:00 +03:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .img {
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .body {
|
|
|
|
padding: 0 0 0 8px;
|
|
|
|
white-space: nowrap;
|
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .name {
|
|
|
|
text-overflow: ellipsis;
|
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
|
2021-04-22 16:29:33 +03:00
|
|
|
> .info {
|
|
|
|
opacity: 0.5;
|
|
|
|
font-size: 90%;
|
|
|
|
text-overflow: ellipsis;
|
2021-03-02 15:57:16 +02:00
|
|
|
overflow: hidden;
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|