iceshrimp/src/client/app/admin/views/emoji.vue

109 lines
2.7 KiB
Vue
Raw Normal View History

2018-11-02 23:05:53 +09:00
<template>
<div>
<ui-card>
<div slot="title">%fa:plus% %i18n:@add-emoji.title%</div>
<section class="fit-top">
<ui-input v-model="name">
<span>%i18n:@add-emoji.name%</span>
<span slot="text">%i18n:@add-emoji.name-desc%</span>
</ui-input>
<ui-input v-model="aliases">
<span>%i18n:@add-emoji.aliases%</span>
<span slot="text">%i18n:@add-emoji.aliases-desc%</span>
</ui-input>
<ui-input v-model="url">
<span>%i18n:@add-emoji.url%</span>
</ui-input>
<ui-button @click="add">%i18n:@add-emoji.add%</ui-button>
</section>
</ui-card>
<ui-card>
<div slot="title">%fa:grin R% %i18n:@emojis.title%</div>
<section v-for="emoji in emojis">
<img :src="emoji.url" :alt="emoji.name" style="width: 64px;"/>
<ui-input v-model="emoji.name">
<span>%i18n:@add-emoji.name%</span>
<span slot="text">%i18n:@add-emoji.name-desc%</span>
</ui-input>
<ui-input v-model="emoji.aliases">
<span>%i18n:@add-emoji.aliases%</span>
<span slot="text">%i18n:@add-emoji.aliases-desc%</span>
</ui-input>
<ui-input v-model="emoji.url">
<span>%i18n:@add-emoji.url%</span>
</ui-input>
<ui-button-group>
<ui-button inline @click="updateEmoji(emoji)">%fa:save R% %i18n:@emojis.update%</ui-button>
<ui-button inline @click="removeEmoji(emoji)">%fa:trash-alt R% %i18n:@emojis.remove%</ui-button>
</ui-button-group>
</section>
</ui-card>
2018-11-02 23:05:53 +09:00
</div>
</template>
<script lang="ts">
import Vue from "vue";
export default Vue.extend({
data() {
return {
name: '',
url: '',
aliases: '',
emojis: []
2018-11-02 23:05:53 +09:00
};
},
mounted() {
this.fetchEmojis();
},
2018-11-02 23:05:53 +09:00
methods: {
add() {
(this as any).api('admin/emoji/add', {
2018-11-02 23:05:53 +09:00
name: this.name,
url: this.url,
aliases: this.aliases.split(' ')
}).then(() => {
(this as any).os.apis.dialog({ text: `Added` });
this.fetchEmojis();
}).catch(e => {
(this as any).os.apis.dialog({ text: `Failed ${e}` });
});
},
fetchEmojis() {
(this as any).api('admin/emoji/list').then(emojis => {
emojis.forEach(e => e.aliases = (e.aliases || []).join(' '));
this.emojis = emojis;
});
},
updateEmoji(emoji) {
(this as any).api('admin/emoji/update', {
id: emoji.id,
name: emoji.name,
url: emoji.url,
aliases: emoji.aliases.split(' ')
}).then(() => {
(this as any).os.apis.dialog({ text: `Updated` });
}).catch(e => {
(this as any).os.apis.dialog({ text: `Failed ${e}` });
});
},
removeEmoji(emoji) {
(this as any).api('admin/emoji/remove', {
id: emoji.id
}).then(() => {
(this as any).os.apis.dialog({ text: `Removed` });
this.fetchEmojis();
2018-11-02 23:05:53 +09:00
}).catch(e => {
(this as any).os.apis.dialog({ text: `Failed ${e}` });
});
}
}
});
</script>