2020-02-18 08:57:00 +01:00
|
|
|
<template>
|
|
|
|
<div class="modal-card">
|
|
|
|
<header class="modal-card-head">
|
|
|
|
<p class="modal-card-title">{{ $t("Pick a group") }}</p>
|
|
|
|
</header>
|
|
|
|
<section class="modal-card-body">
|
|
|
|
<div class="list is-hoverable">
|
|
|
|
<a
|
|
|
|
class="list-item"
|
2020-09-29 09:53:48 +02:00
|
|
|
v-for="groupMembership in actualMemberships"
|
2020-11-30 10:24:11 +01:00
|
|
|
:class="{
|
|
|
|
'is-active': groupMembership.parent.id === currentGroup.id,
|
|
|
|
}"
|
2020-02-18 08:57:00 +01:00
|
|
|
@click="changeCurrentGroup(groupMembership.parent)"
|
|
|
|
:key="groupMembership.id"
|
|
|
|
>
|
|
|
|
<div class="media">
|
|
|
|
<img
|
|
|
|
class="media-left image is-48x48"
|
|
|
|
v-if="groupMembership.parent.avatar"
|
|
|
|
:src="groupMembership.parent.avatar.url"
|
|
|
|
alt=""
|
|
|
|
/>
|
2020-11-30 10:24:11 +01:00
|
|
|
<b-icon
|
|
|
|
class="media-left"
|
|
|
|
v-else
|
|
|
|
size="is-large"
|
|
|
|
icon="account-circle"
|
|
|
|
/>
|
2020-02-18 08:57:00 +01:00
|
|
|
<div class="media-content">
|
|
|
|
<h3>@{{ groupMembership.parent.name }}</h3>
|
2020-11-30 10:24:11 +01:00
|
|
|
<small>{{
|
|
|
|
`@${groupMembership.parent.preferredUsername}`
|
|
|
|
}}</small>
|
2020-02-18 08:57:00 +01:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
2020-11-30 10:24:11 +01:00
|
|
|
<a
|
|
|
|
class="list-item"
|
|
|
|
@click="changeCurrentGroup(new Group())"
|
|
|
|
v-if="currentGroup.id"
|
|
|
|
>
|
2020-02-18 08:57:00 +01:00
|
|
|
<h3>{{ $t("Unset group") }}</h3>
|
|
|
|
</a>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<slot name="footer" />
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue } from "vue-property-decorator";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { IGroup, IPerson, Group } from "@/types/actor";
|
2020-02-18 08:57:00 +01:00
|
|
|
import { PERSON_MEMBERSHIPS } from "@/graphql/actor";
|
|
|
|
import { Paginate } from "@/types/paginate";
|
2020-11-27 19:27:44 +01:00
|
|
|
import { IMember } from "@/types/actor/member.model";
|
|
|
|
import { MemberRole } from "@/types/enums";
|
2020-02-18 08:57:00 +01:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
apollo: {
|
|
|
|
groupMemberships: {
|
|
|
|
query: PERSON_MEMBERSHIPS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
id: this.identity.id,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update: (data) => data.person.memberships,
|
|
|
|
skip() {
|
|
|
|
return !this.identity.id;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class GroupPicker extends Vue {
|
|
|
|
@Prop() value!: IGroup;
|
|
|
|
|
|
|
|
@Prop() identity!: IPerson;
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
@Prop({ required: false, default: false }) restrictModeratorLevel!: boolean;
|
|
|
|
|
2020-02-18 08:57:00 +01:00
|
|
|
groupMemberships: Paginate<IMember> = { elements: [], total: 0 };
|
|
|
|
|
|
|
|
currentGroup: IGroup = this.value;
|
|
|
|
|
|
|
|
Group = Group;
|
|
|
|
|
2020-09-29 09:53:48 +02:00
|
|
|
changeCurrentGroup(group: IGroup): void {
|
2020-02-18 08:57:00 +01:00
|
|
|
this.currentGroup = group;
|
|
|
|
this.$emit("input", group);
|
|
|
|
}
|
2020-09-29 09:53:48 +02:00
|
|
|
|
|
|
|
get actualMemberships(): IMember[] {
|
|
|
|
if (this.restrictModeratorLevel) {
|
|
|
|
return this.groupMemberships.elements.filter((membership: IMember) =>
|
2020-11-30 10:24:11 +01:00
|
|
|
[
|
|
|
|
MemberRole.ADMINISTRATOR,
|
|
|
|
MemberRole.MODERATOR,
|
|
|
|
MemberRole.CREATOR,
|
|
|
|
].includes(membership.role)
|
2020-09-29 09:53:48 +02:00
|
|
|
);
|
|
|
|
}
|
|
|
|
return this.groupMemberships.elements;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
</script>
|