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-02-18 08:57:00 +01:00
|
|
|
:class="{ 'is-active': groupMembership.parent.id === currentGroup.id }"
|
|
|
|
@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=""
|
|
|
|
/>
|
|
|
|
<b-icon class="media-left" v-else size="is-large" icon="account-circle" />
|
|
|
|
<div class="media-content">
|
|
|
|
<h3>@{{ groupMembership.parent.name }}</h3>
|
|
|
|
<small>{{ `@${groupMembership.parent.preferredUsername}` }}</small>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</a>
|
|
|
|
<a class="list-item" @click="changeCurrentGroup(new Group())" v-if="currentGroup.id">
|
|
|
|
<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) =>
|
|
|
|
[MemberRole.ADMINISTRATOR, MemberRole.MODERATOR, MemberRole.CREATOR].includes(
|
|
|
|
membership.role
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return this.groupMemberships.elements;
|
|
|
|
}
|
2020-02-18 08:57:00 +01:00
|
|
|
}
|
|
|
|
</script>
|