2020-01-29 21:37:25 +02:00
|
|
|
<template>
|
|
|
|
<div class="mk-instance-emojis">
|
|
|
|
<portal to="icon"><fa :icon="faLaugh"/></portal>
|
|
|
|
<portal to="title">{{ $t('customEmojis') }}</portal>
|
2020-02-13 18:09:39 +02:00
|
|
|
|
2020-01-30 04:10:42 +02:00
|
|
|
<section class="_card local">
|
2020-01-29 21:37:25 +02:00
|
|
|
<div class="_title"><fa :icon="faLaugh"/> {{ $t('customEmojis') }}</div>
|
|
|
|
<div class="_content">
|
|
|
|
<mk-pagination :pagination="pagination" class="emojis" ref="emojis">
|
|
|
|
<template #empty><span>{{ $t('noCustomEmojis') }}</span></template>
|
|
|
|
<template #default="{items}">
|
2020-02-06 07:23:01 +02:00
|
|
|
<div class="emoji" v-for="(emoji, i) in items" :key="emoji.id" @click="selected = emoji" :class="{ selected: selected && (selected.id === emoji.id) }">
|
2020-01-29 21:37:25 +02:00
|
|
|
<img :src="emoji.url" class="img" :alt="emoji.name"/>
|
|
|
|
<div class="body">
|
|
|
|
<span class="name">{{ emoji.name }}</span>
|
2020-02-13 18:09:39 +02:00
|
|
|
<span class="info">
|
|
|
|
<b class="category">{{ emoji.category }}</b>
|
|
|
|
<span class="aliases">{{ emoji.aliases.join(' ') }}</span>
|
|
|
|
</span>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</mk-pagination>
|
|
|
|
</div>
|
2020-02-13 18:09:39 +02:00
|
|
|
<div class="_content" v-if="selected">
|
|
|
|
<mk-input v-model="name"><span>{{ $t('name') }}</span></mk-input>
|
|
|
|
<mk-input v-model="category"><span>{{ $t('category') }}</span></mk-input>
|
|
|
|
<mk-input v-model="aliases"><span>{{ $t('tags') }}</span></mk-input>
|
|
|
|
<mk-button inline primary @click="update"><fa :icon="faSave"/> {{ $t('save') }}</mk-button>
|
2020-01-29 21:37:25 +02:00
|
|
|
<mk-button inline :disabled="selected == null" @click="del()"><fa :icon="faTrashAlt"/> {{ $t('delete') }}</mk-button>
|
|
|
|
</div>
|
2020-02-13 18:09:39 +02:00
|
|
|
<div class="_footer">
|
|
|
|
<mk-button inline primary @click="add"><fa :icon="faPlus"/> {{ $t('addEmoji') }}</mk-button>
|
|
|
|
</div>
|
2020-01-29 21:37:25 +02:00
|
|
|
</section>
|
2020-01-30 04:10:42 +02:00
|
|
|
<section class="_card remote">
|
2020-01-29 21:37:25 +02:00
|
|
|
<div class="_title"><fa :icon="faLaugh"/> {{ $t('customEmojisOfRemote') }}</div>
|
|
|
|
<div class="_content">
|
|
|
|
<mk-input v-model="host" :debounce="true" style="margin-top: 0;"><span>{{ $t('host') }}</span></mk-input>
|
|
|
|
<mk-pagination :pagination="remotePagination" class="emojis" ref="remoteEmojis">
|
|
|
|
<template #empty><span>{{ $t('noCustomEmojis') }}</span></template>
|
|
|
|
<template #default="{items}">
|
2020-02-06 07:23:01 +02:00
|
|
|
<div class="emoji" v-for="(emoji, i) in items" :key="emoji.id" @click="selectedRemote = emoji" :class="{ selected: selectedRemote && (selectedRemote.id === emoji.id) }">
|
2020-01-29 21:37:25 +02:00
|
|
|
<img :src="emoji.url" class="img" :alt="emoji.name"/>
|
|
|
|
<div class="body">
|
|
|
|
<span class="name">{{ emoji.name }}</span>
|
2020-02-13 18:09:39 +02:00
|
|
|
<span class="info">{{ emoji.host }}</span>
|
2020-01-29 21:37:25 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
</mk-pagination>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
|
|
|
<mk-button inline primary :disabled="selectedRemote == null" @click="im()"><fa :icon="faPlus"/> {{ $t('import') }}</mk-button>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-02-13 18:09:39 +02:00
|
|
|
import { faPlus, faSave } from '@fortawesome/free-solid-svg-icons';
|
2020-01-29 21:37:25 +02:00
|
|
|
import { faTrashAlt, faLaugh } from '@fortawesome/free-regular-svg-icons';
|
|
|
|
import MkButton from '../../components/ui/button.vue';
|
|
|
|
import MkInput from '../../components/ui/input.vue';
|
|
|
|
import MkPagination from '../../components/ui/pagination.vue';
|
2020-02-13 18:09:39 +02:00
|
|
|
import { selectFile } from '../../scripts/select-file';
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: `${this.$t('customEmojis')} | ${this.$t('instance')}`
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
|
|
|
MkPagination,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
selected: null,
|
|
|
|
selectedRemote: null,
|
2020-02-13 18:09:39 +02:00
|
|
|
name: null,
|
|
|
|
category: null,
|
|
|
|
aliases: null,
|
2020-01-29 21:37:25 +02:00
|
|
|
host: '',
|
|
|
|
pagination: {
|
|
|
|
endpoint: 'admin/emoji/list',
|
|
|
|
limit: 10,
|
|
|
|
},
|
|
|
|
remotePagination: {
|
|
|
|
endpoint: 'admin/emoji/list-remote',
|
|
|
|
limit: 10,
|
|
|
|
params: () => ({
|
|
|
|
host: this.host ? this.host : null
|
|
|
|
})
|
|
|
|
},
|
2020-02-13 18:09:39 +02:00
|
|
|
faTrashAlt, faPlus, faLaugh, faSave
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
|
|
|
host() {
|
|
|
|
this.$refs.remoteEmojis.reload();
|
2020-02-13 18:09:39 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
selected() {
|
|
|
|
this.name = this.selected ? this.selected.name : null;
|
|
|
|
this.category = this.selected ? this.selected.category : null;
|
|
|
|
this.aliases = this.selected ? this.selected.aliases.join(' ') : null;
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2020-02-13 18:09:39 +02:00
|
|
|
async add(e) {
|
|
|
|
const files = await selectFile(this, e.currentTarget || e.target, null, true);
|
2020-01-29 21:37:25 +02:00
|
|
|
|
|
|
|
const dialog = this.$root.dialog({
|
|
|
|
type: 'waiting',
|
2020-02-13 18:09:39 +02:00
|
|
|
text: this.$t('doing') + '...',
|
2020-01-29 21:37:25 +02:00
|
|
|
showOkButton: false,
|
|
|
|
showCancelButton: false,
|
|
|
|
cancelableByBgClick: false
|
|
|
|
});
|
2020-02-13 18:09:39 +02:00
|
|
|
|
|
|
|
Promise.all(files.map(file => this.$root.api('admin/emoji/add', {
|
|
|
|
fileId: file.id,
|
|
|
|
})))
|
|
|
|
.then(() => {
|
2020-01-29 21:37:25 +02:00
|
|
|
this.$refs.emojis.reload();
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
dialog.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-02-13 18:09:39 +02:00
|
|
|
async update() {
|
|
|
|
await this.$root.api('admin/emoji/update', {
|
|
|
|
id: this.selected.id,
|
|
|
|
name: this.name,
|
|
|
|
category: this.category,
|
|
|
|
aliases: this.aliases.split(' '),
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$refs.emojis.reload();
|
|
|
|
},
|
|
|
|
|
2020-01-29 21:37:25 +02:00
|
|
|
async del() {
|
|
|
|
const { canceled } = await this.$root.dialog({
|
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: this.selected.name }),
|
|
|
|
showCancelButton: true
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
|
|
|
this.$root.api('admin/emoji/remove', {
|
|
|
|
id: this.selected.id
|
|
|
|
}).then(() => {
|
|
|
|
this.$refs.emojis.reload();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
im() {
|
|
|
|
this.$root.api('admin/emoji/copy', {
|
|
|
|
emojiId: this.selectedRemote.id,
|
|
|
|
}).then(() => {
|
|
|
|
this.$refs.emojis.reload();
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
}).catch(e => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: e
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-instance-emojis {
|
|
|
|
> .local {
|
|
|
|
> ._content {
|
|
|
|
max-height: 300px;
|
|
|
|
overflow: auto;
|
|
|
|
|
|
|
|
> .emojis {
|
|
|
|
> .emoji {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
background: var(--accent);
|
|
|
|
box-shadow: 0 0 0 8px var(--accent);
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .img {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
}
|
2020-02-13 18:09:39 +02:00
|
|
|
|
|
|
|
> .info {
|
|
|
|
opacity: 0.5;
|
|
|
|
|
|
|
|
> .category {
|
|
|
|
margin-right: 16px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .aliases {
|
|
|
|
font-style: oblique;
|
|
|
|
}
|
|
|
|
}
|
2020-01-29 21:37:25 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
> .remote {
|
|
|
|
> ._content {
|
|
|
|
max-height: 300px;
|
|
|
|
overflow: auto;
|
|
|
|
|
|
|
|
> .emojis {
|
|
|
|
> .emoji {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
&.selected {
|
|
|
|
background: var(--accent);
|
|
|
|
box-shadow: 0 0 0 8px var(--accent);
|
|
|
|
color: #fff;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .img {
|
|
|
|
width: 32px;
|
|
|
|
height: 32px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
padding: 0 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
}
|
|
|
|
|
2020-02-13 18:09:39 +02:00
|
|
|
> .info {
|
2020-01-29 21:37:25 +02:00
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|