2020-01-29 20:37:25 +01:00
|
|
|
<template>
|
|
|
|
<div class="mk-instance-users">
|
|
|
|
<portal to="icon"><fa :icon="faUsers"/></portal>
|
2020-07-24 18:56:52 +02:00
|
|
|
<portal to="title">{{ $t('users') }}</portal>
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-08-09 08:51:02 +02:00
|
|
|
<section class="_card _vMargin lookup">
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="_title"><fa :icon="faSearch"/> {{ $t('lookup') }}</div>
|
|
|
|
<div class="_content">
|
2020-02-13 17:24:05 +01:00
|
|
|
<mk-input class="target" v-model="target" type="text" @enter="showUser()">
|
2020-07-24 18:56:52 +02:00
|
|
|
<span>{{ $t('usernameOrUserId') }}</span>
|
2020-01-29 20:37:25 +01:00
|
|
|
</mk-input>
|
|
|
|
<mk-button @click="showUser()" primary><fa :icon="faSearch"/> {{ $t('lookup') }}</mk-button>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
2020-04-13 16:27:12 +02:00
|
|
|
<mk-button inline primary @click="searchUser()"><fa :icon="faSearch"/> {{ $t('search') }}</mk-button>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
|
2020-08-09 08:51:02 +02:00
|
|
|
<section class="_card _vMargin users">
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="_title"><fa :icon="faUsers"/> {{ $t('users') }}</div>
|
2020-04-13 16:27:12 +02:00
|
|
|
<div class="_content">
|
|
|
|
<div class="inputs" style="display: flex;">
|
|
|
|
<mk-select v-model="sort" style="margin: 0; flex: 1;">
|
|
|
|
<template #label>{{ $t('sort') }}</template>
|
|
|
|
<option value="-createdAt">{{ $t('registeredDate') }} ({{ $t('ascendingOrder') }})</option>
|
|
|
|
<option value="+createdAt">{{ $t('registeredDate') }} ({{ $t('descendingOrder') }})</option>
|
|
|
|
<option value="-updatedAt">{{ $t('lastUsed') }} ({{ $t('ascendingOrder') }})</option>
|
|
|
|
<option value="+updatedAt">{{ $t('lastUsed') }} ({{ $t('descendingOrder') }})</option>
|
|
|
|
</mk-select>
|
|
|
|
<mk-select v-model="state" style="margin: 0; flex: 1;">
|
|
|
|
<template #label>{{ $t('state') }}</template>
|
2020-07-24 18:56:52 +02:00
|
|
|
<option value="all">{{ $t('all') }}</option>
|
|
|
|
<option value="available">{{ $t('normal') }}</option>
|
|
|
|
<option value="admin">{{ $t('administrator') }}</option>
|
|
|
|
<option value="moderator">{{ $t('moderator') }}</option>
|
|
|
|
<option value="silenced">{{ $t('silence') }}</option>
|
|
|
|
<option value="suspended">{{ $t('suspend') }}</option>
|
2020-04-13 16:27:12 +02:00
|
|
|
</mk-select>
|
|
|
|
<mk-select v-model="origin" style="margin: 0; flex: 1;">
|
|
|
|
<template #label>{{ $t('instance') }}</template>
|
2020-07-24 18:56:52 +02:00
|
|
|
<option value="combined">{{ $t('all') }}</option>
|
|
|
|
<option value="local">{{ $t('local') }}</option>
|
|
|
|
<option value="remote">{{ $t('remote') }}</option>
|
2020-04-13 16:27:12 +02:00
|
|
|
</mk-select>
|
|
|
|
</div>
|
|
|
|
<div class="inputs" style="display: flex; padding-top: 1.2em;">
|
|
|
|
<mk-input v-model="searchUsername" style="margin: 0; flex: 1;" type="text" spellcheck="false" @input="$refs.users.reload()">
|
2020-07-24 18:56:52 +02:00
|
|
|
<span>{{ $t('username') }}</span>
|
2020-04-13 16:27:12 +02:00
|
|
|
</mk-input>
|
|
|
|
<mk-input v-model="searchHost" style="margin: 0; flex: 1;" type="text" spellcheck="false" @input="$refs.users.reload()" :disabled="pagination.params().origin === 'local'">
|
2020-07-24 18:56:52 +02:00
|
|
|
<span>{{ $t('host') }}</span>
|
2020-04-13 16:27:12 +02:00
|
|
|
</mk-input>
|
|
|
|
</div>
|
|
|
|
</div>
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="_content _list">
|
|
|
|
<mk-pagination :pagination="pagination" #default="{items}" class="users" ref="users" :auto-margin="false">
|
2020-02-06 06:23:01 +01:00
|
|
|
<button class="user _button _listItem" v-for="(user, i) in items" :key="user.id" @click="show(user)">
|
2020-04-13 16:27:12 +02:00
|
|
|
<mk-avatar class="avatar" :user="user" :disable-link="true"/>
|
2020-01-29 20:37:25 +01:00
|
|
|
<div class="body">
|
2020-04-13 16:27:12 +02:00
|
|
|
<header>
|
|
|
|
<mk-user-name class="name" :user="user"/>
|
|
|
|
<span class="acct">@{{ user | acct }}</span>
|
|
|
|
<span class="staff" v-if="user.isAdmin"><fa :icon="faBookmark"/></span>
|
|
|
|
<span class="staff" v-if="user.isModerator"><fa :icon="farBookmark"/></span>
|
|
|
|
<span class="punished" v-if="user.isSilenced"><fa :icon="faMicrophoneSlash"/></span>
|
|
|
|
<span class="punished" v-if="user.isSuspended"><fa :icon="faSnowflake"/></span>
|
|
|
|
</header>
|
|
|
|
<div>
|
|
|
|
<span>{{ $t('lastUsed') }}: <mk-time :time="user.updatedAt" mode="detail"/></span>
|
|
|
|
</div>
|
|
|
|
<div>
|
|
|
|
<span>{{ $t('registeredDate') }}: <mk-time :time="user.createdAt" mode="detail"/></span>
|
|
|
|
</div>
|
2020-01-29 20:37:25 +01:00
|
|
|
</div>
|
|
|
|
</button>
|
|
|
|
</mk-pagination>
|
|
|
|
</div>
|
|
|
|
<div class="_footer">
|
|
|
|
<mk-button inline primary @click="addUser()"><fa :icon="faPlus"/> {{ $t('addUser') }}</mk-button>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
|
|
|
import Vue from 'vue';
|
2020-04-13 16:27:12 +02:00
|
|
|
import { faPlus, faUsers, faSearch, faBookmark, faMicrophoneSlash } from '@fortawesome/free-solid-svg-icons';
|
|
|
|
import { faSnowflake, faBookmark as farBookmark } from '@fortawesome/free-regular-svg-icons';
|
2020-01-29 20:37:25 +01:00
|
|
|
import parseAcct from '../../../misc/acct/parse';
|
|
|
|
import MkButton from '../../components/ui/button.vue';
|
|
|
|
import MkInput from '../../components/ui/input.vue';
|
2020-04-13 16:27:12 +02:00
|
|
|
import MkSelect from '../../components/ui/select.vue';
|
2020-01-29 20:37:25 +01:00
|
|
|
import MkPagination from '../../components/ui/pagination.vue';
|
|
|
|
import MkUserSelect from '../../components/user-select.vue';
|
|
|
|
|
|
|
|
export default Vue.extend({
|
|
|
|
metaInfo() {
|
|
|
|
return {
|
|
|
|
title: `${this.$t('users')} | ${this.$t('instance')}`
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
components: {
|
|
|
|
MkButton,
|
|
|
|
MkInput,
|
2020-04-13 16:27:12 +02:00
|
|
|
MkSelect,
|
2020-01-29 20:37:25 +01:00
|
|
|
MkPagination,
|
|
|
|
},
|
|
|
|
|
|
|
|
data() {
|
|
|
|
return {
|
2020-04-13 16:27:12 +02:00
|
|
|
target: '',
|
|
|
|
sort: '+createdAt',
|
|
|
|
state: 'all',
|
|
|
|
origin: 'local',
|
|
|
|
searchUsername: '',
|
|
|
|
searchHost: '',
|
2020-01-29 20:37:25 +01:00
|
|
|
pagination: {
|
|
|
|
endpoint: 'admin/show-users',
|
|
|
|
limit: 10,
|
2020-03-25 07:57:35 +01:00
|
|
|
params: () => ({
|
2020-04-13 16:27:12 +02:00
|
|
|
sort: this.sort,
|
|
|
|
state: this.state,
|
|
|
|
origin: this.origin,
|
|
|
|
username: this.searchUsername,
|
|
|
|
hostname: this.searchHost,
|
2020-03-25 07:57:35 +01:00
|
|
|
}),
|
2020-01-29 20:37:25 +01:00
|
|
|
offsetMode: true
|
|
|
|
},
|
2020-04-13 16:27:12 +02:00
|
|
|
faPlus, faUsers, faSearch, faBookmark, farBookmark, faMicrophoneSlash, faSnowflake
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-04-13 16:27:12 +02:00
|
|
|
watch: {
|
|
|
|
sort() {
|
|
|
|
this.$refs.users.reload();
|
|
|
|
},
|
|
|
|
state() {
|
|
|
|
this.$refs.users.reload();
|
|
|
|
},
|
|
|
|
origin() {
|
|
|
|
this.$refs.users.reload();
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
methods: {
|
|
|
|
/** テキストエリアのユーザーを解決する */
|
|
|
|
fetchUser() {
|
|
|
|
return new Promise((res) => {
|
|
|
|
const usernamePromise = this.$root.api('users/show', parseAcct(this.target));
|
|
|
|
const idPromise = this.$root.api('users/show', { userId: this.target });
|
|
|
|
let _notFound = false;
|
|
|
|
const notFound = () => {
|
|
|
|
if (_notFound) {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: this.$t('noSuchUser')
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
_notFound = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
usernamePromise.then(res).catch(e => {
|
|
|
|
if (e.code === 'NO_SUCH_USER') {
|
|
|
|
notFound();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
idPromise.then(res).catch(e => {
|
|
|
|
notFound();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
/** テキストエリアから処理対象ユーザーを設定する */
|
|
|
|
async showUser() {
|
|
|
|
const user = await this.fetchUser();
|
2020-04-13 16:27:12 +02:00
|
|
|
this.show(user);
|
2020-01-29 20:37:25 +01:00
|
|
|
this.target = '';
|
|
|
|
},
|
|
|
|
|
2020-04-13 16:27:12 +02:00
|
|
|
searchUser() {
|
|
|
|
this.$root.new(MkUserSelect, {}).$once('selected', user => {
|
|
|
|
this.show(user);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-01-29 20:37:25 +01:00
|
|
|
async addUser() {
|
|
|
|
const { canceled: canceled1, result: username } = await this.$root.dialog({
|
|
|
|
title: this.$t('username'),
|
|
|
|
input: true
|
|
|
|
});
|
|
|
|
if (canceled1) return;
|
|
|
|
|
|
|
|
const { canceled: canceled2, result: password } = await this.$root.dialog({
|
|
|
|
title: this.$t('password'),
|
|
|
|
input: { type: 'password' }
|
|
|
|
});
|
|
|
|
if (canceled2) return;
|
|
|
|
|
|
|
|
const dialog = this.$root.dialog({
|
|
|
|
type: 'waiting',
|
|
|
|
iconOnly: true
|
|
|
|
});
|
|
|
|
|
|
|
|
this.$root.api('admin/accounts/create', {
|
|
|
|
username: username,
|
|
|
|
password: password,
|
|
|
|
}).then(res => {
|
|
|
|
this.$refs.users.reload();
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'success',
|
|
|
|
iconOnly: true, autoClose: true
|
|
|
|
});
|
|
|
|
}).catch(e => {
|
|
|
|
this.$root.dialog({
|
|
|
|
type: 'error',
|
|
|
|
text: e.id
|
|
|
|
});
|
|
|
|
}).finally(() => {
|
|
|
|
dialog.close();
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-04-13 16:27:12 +02:00
|
|
|
async show(user) {
|
|
|
|
this.$router.push('./users/' + user.id);
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-instance-users {
|
|
|
|
> .users {
|
|
|
|
> ._content {
|
|
|
|
max-height: 300px;
|
|
|
|
overflow: auto;
|
|
|
|
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
width: 100%;
|
|
|
|
box-sizing: border-box;
|
|
|
|
text-align: left;
|
|
|
|
align-items: center;
|
|
|
|
|
|
|
|
> .avatar {
|
2020-04-13 16:27:12 +02:00
|
|
|
width: 64px;
|
|
|
|
height: 64px;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
2020-04-13 16:27:12 +02:00
|
|
|
margin-left: 0.3em;
|
2020-01-29 20:37:25 +01:00
|
|
|
padding: 8px;
|
2020-04-13 16:27:12 +02:00
|
|
|
flex: 1;
|
2020-01-29 20:37:25 +01:00
|
|
|
|
2020-04-13 16:27:12 +02:00
|
|
|
@media (max-width 500px) {
|
|
|
|
font-size: 14px;
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
|
2020-04-13 16:27:12 +02:00
|
|
|
> header {
|
|
|
|
> .name {
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .acct {
|
|
|
|
margin-left: 8px;
|
|
|
|
opacity: 0.7;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .staff {
|
|
|
|
margin-left: 0.5em;
|
|
|
|
color: var(--badge);
|
|
|
|
}
|
|
|
|
|
|
|
|
> .punished {
|
|
|
|
margin-left: 0.5em;
|
|
|
|
color: #4dabf7;
|
|
|
|
}
|
2020-01-29 20:37:25 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|