2020-02-08 07:11:12 +01:00
|
|
|
<template>
|
|
|
|
<div class="mk-group-page">
|
|
|
|
<transition name="zoom" mode="out-in">
|
2020-10-17 13:12:00 +02:00
|
|
|
<div v-if="group" class="_section">
|
2020-02-08 07:11:12 +01:00
|
|
|
<div class="_content">
|
2020-12-26 02:47:36 +01:00
|
|
|
<MkButton inline @click="invite()">{{ $ts.invite }}</MkButton>
|
|
|
|
<MkButton inline @click="renameGroup()">{{ $ts.rename }}</MkButton>
|
|
|
|
<MkButton inline @click="transfer()">{{ $ts.transfer }}</MkButton>
|
|
|
|
<MkButton inline @click="deleteGroup()">{{ $ts.delete }}</MkButton>
|
2020-02-08 07:11:12 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
|
|
|
|
<transition name="zoom" mode="out-in">
|
2021-04-10 11:17:42 +02:00
|
|
|
<div v-if="group" class="_section members _gap">
|
2020-12-26 02:47:36 +01:00
|
|
|
<div class="_title">{{ $ts.members }}</div>
|
2020-02-08 07:11:12 +01:00
|
|
|
<div class="_content">
|
|
|
|
<div class="users">
|
2020-10-17 13:12:00 +02:00
|
|
|
<div class="user _panel" v-for="user in users" :key="user.id">
|
2021-04-17 16:52:54 +02:00
|
|
|
<MkAvatar :user="user" class="avatar" :show-indicator="true"/>
|
2020-02-08 07:11:12 +01:00
|
|
|
<div class="body">
|
2020-10-17 13:12:00 +02:00
|
|
|
<MkUserName :user="user" class="name"/>
|
|
|
|
<MkAcct :user="user" class="acct"/>
|
2020-02-08 07:11:12 +01:00
|
|
|
</div>
|
|
|
|
<div class="action">
|
2021-04-20 16:22:59 +02:00
|
|
|
<button class="_button" @click="removeUser(user)"><i class="fas fa-times"></i></button>
|
2020-02-08 07:11:12 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</transition>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts">
|
2020-10-17 13:12:00 +02:00
|
|
|
import { computed, defineComponent } from 'vue';
|
2021-11-11 18:02:25 +01:00
|
|
|
import Progress from '@/scripts/loading';
|
|
|
|
import MkButton from '@/components/ui/button.vue';
|
|
|
|
import * as os from '@/os';
|
|
|
|
import * as symbols from '@/symbols';
|
2020-02-08 07:11:12 +01:00
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
export default defineComponent({
|
2020-02-08 07:11:12 +01:00
|
|
|
components: {
|
|
|
|
MkButton
|
|
|
|
},
|
|
|
|
|
2021-01-17 16:53:48 +01:00
|
|
|
props: {
|
|
|
|
groupId: {
|
|
|
|
type: String,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
|
2020-02-08 07:11:12 +01:00
|
|
|
data() {
|
|
|
|
return {
|
2021-04-10 05:54:12 +02:00
|
|
|
[symbols.PAGE_INFO]: computed(() => this.group ? {
|
2020-11-03 12:36:12 +01:00
|
|
|
title: this.group.name,
|
2021-04-20 16:22:59 +02:00
|
|
|
icon: 'fas fa-users',
|
2020-10-17 13:12:00 +02:00
|
|
|
} : null),
|
2020-02-08 07:11:12 +01:00
|
|
|
group: null,
|
|
|
|
users: [],
|
|
|
|
};
|
|
|
|
},
|
|
|
|
|
|
|
|
watch: {
|
2021-01-17 16:53:48 +01:00
|
|
|
groupId: 'fetch',
|
2020-02-08 07:11:12 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
created() {
|
|
|
|
this.fetch();
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
|
|
|
fetch() {
|
|
|
|
Progress.start();
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('users/groups/show', {
|
2021-01-17 16:53:48 +01:00
|
|
|
groupId: this.groupId
|
2020-02-08 07:11:12 +01:00
|
|
|
}).then(group => {
|
|
|
|
this.group = group;
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('users/show', {
|
2020-02-08 07:11:12 +01:00
|
|
|
userIds: this.group.userIds
|
|
|
|
}).then(users => {
|
|
|
|
this.users = users;
|
|
|
|
Progress.done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
invite() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/groups/invite', {
|
2020-02-08 07:11:12 +01:00
|
|
|
groupId: this.group.id,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
removeUser(user) {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.api('users/groups/pull', {
|
2020-02-08 07:11:12 +01:00
|
|
|
groupId: this.group.id,
|
|
|
|
userId: user.id
|
|
|
|
}).then(() => {
|
|
|
|
this.users = this.users.filter(x => x.id !== user.id);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
|
|
|
async renameGroup() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled, result: name } = await os.inputText({
|
2020-12-26 02:47:36 +01:00
|
|
|
title: this.$ts.groupName,
|
2021-11-18 10:45:58 +01:00
|
|
|
default: this.group.name
|
2020-02-08 07:11:12 +01:00
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
await os.api('users/groups/update', {
|
2020-02-08 07:11:12 +01:00
|
|
|
groupId: this.group.id,
|
|
|
|
name: name
|
|
|
|
});
|
|
|
|
|
|
|
|
this.group.name = name;
|
|
|
|
},
|
|
|
|
|
2020-02-08 07:17:35 +01:00
|
|
|
transfer() {
|
2020-10-17 13:12:00 +02:00
|
|
|
os.selectUser().then(user => {
|
|
|
|
os.apiWithDialog('users/groups/transfer', {
|
2020-02-08 07:17:35 +01:00
|
|
|
groupId: this.group.id,
|
|
|
|
userId: user.id
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
|
|
|
|
2020-02-08 07:11:12 +01:00
|
|
|
async deleteGroup() {
|
2021-11-18 10:45:58 +01:00
|
|
|
const { canceled } = await os.confirm({
|
2020-02-08 07:11:12 +01:00
|
|
|
type: 'warning',
|
|
|
|
text: this.$t('removeAreYouSure', { x: this.group.name }),
|
|
|
|
});
|
|
|
|
if (canceled) return;
|
|
|
|
|
2020-10-17 13:12:00 +02:00
|
|
|
await os.apiWithDialog('users/groups/delete', {
|
2020-02-08 07:11:12 +01:00
|
|
|
groupId: this.group.id
|
|
|
|
});
|
|
|
|
this.$router.push('/my/groups');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.mk-group-page {
|
|
|
|
> .members {
|
|
|
|
> ._content {
|
|
|
|
> .users {
|
|
|
|
> .user {
|
|
|
|
display: flex;
|
|
|
|
align-items: center;
|
2020-10-17 13:12:00 +02:00
|
|
|
padding: 16px;
|
2020-02-08 07:11:12 +01:00
|
|
|
|
|
|
|
> .avatar {
|
|
|
|
width: 50px;
|
|
|
|
height: 50px;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .body {
|
|
|
|
flex: 1;
|
|
|
|
padding: 8px;
|
|
|
|
|
|
|
|
> .name {
|
|
|
|
display: block;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
> .acct {
|
|
|
|
opacity: 0.5;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|