2020-09-29 07:53:48 +00:00
|
|
|
<template>
|
2021-03-29 08:33:19 +00:00
|
|
|
<div class="organizer-picker" v-if="selectedActor">
|
2020-09-29 07:53:48 +00:00
|
|
|
<!-- If we have a current actor (inline) -->
|
2020-11-30 09:24:11 +00:00
|
|
|
<div
|
2021-03-29 08:33:19 +00:00
|
|
|
v-if="inline && selectedActor.id"
|
2020-11-30 09:24:11 +00:00
|
|
|
class="inline box"
|
|
|
|
@click="isComponentModalActive = true"
|
|
|
|
>
|
2020-09-29 07:53:48 +00:00
|
|
|
<div class="media">
|
|
|
|
<div class="media-left">
|
2021-03-29 08:33:19 +00:00
|
|
|
<figure class="image is-48x48" v-if="selectedActor.avatar">
|
2020-09-29 07:53:48 +00:00
|
|
|
<img
|
|
|
|
class="image is-rounded"
|
2021-03-29 08:33:19 +00:00
|
|
|
:src="selectedActor.avatar.url"
|
|
|
|
:alt="selectedActor.avatar.alt"
|
2020-09-29 07:53:48 +00:00
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
|
|
|
</div>
|
2021-03-29 08:33:19 +00:00
|
|
|
<div class="media-content" v-if="selectedActor.name">
|
|
|
|
<p class="is-4">{{ selectedActor.name }}</p>
|
2020-11-30 09:24:11 +00:00
|
|
|
<p class="is-6 has-text-grey">
|
2021-03-29 08:33:19 +00:00
|
|
|
{{ `@${selectedActor.preferredUsername}` }}
|
2020-11-30 09:24:11 +00:00
|
|
|
</p>
|
2020-09-29 07:53:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="media-content" v-else>
|
2021-03-29 08:33:19 +00:00
|
|
|
{{ `@${selectedActor.preferredUsername}` }}
|
2020-09-29 07:53:48 +00:00
|
|
|
</div>
|
|
|
|
<b-button type="is-text" @click="isComponentModalActive = true">
|
|
|
|
{{ $t("Change") }}
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- If we have a current actor -->
|
2020-11-30 09:24:11 +00:00
|
|
|
<span
|
2021-03-29 08:33:19 +00:00
|
|
|
v-else-if="selectedActor.id"
|
2020-11-30 09:24:11 +00:00
|
|
|
class="block"
|
|
|
|
@click="isComponentModalActive = true"
|
|
|
|
>
|
2020-09-29 07:53:48 +00:00
|
|
|
<img
|
|
|
|
class="image is-48x48"
|
2021-03-29 08:33:19 +00:00
|
|
|
v-if="selectedActor.avatar"
|
|
|
|
:src="selectedActor.avatar.url"
|
|
|
|
:alt="selectedActor.avatar.alt"
|
2020-09-29 07:53:48 +00:00
|
|
|
/>
|
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
|
|
|
</span>
|
|
|
|
<b-modal :active.sync="isComponentModalActive" has-modal-card>
|
|
|
|
<div class="modal-card">
|
|
|
|
<header class="modal-card-head">
|
|
|
|
<p class="modal-card-title">{{ $t("Pick a profile or a group") }}</p>
|
|
|
|
</header>
|
|
|
|
<section class="modal-card-body">
|
|
|
|
<div class="columns">
|
2021-08-11 10:43:54 +00:00
|
|
|
<div class="column actor-picker">
|
2020-09-29 07:53:48 +00:00
|
|
|
<organizer-picker
|
2021-03-29 08:33:19 +00:00
|
|
|
v-model="selectedActor"
|
2020-09-29 07:53:48 +00:00
|
|
|
@input="relay"
|
|
|
|
:restrict-moderator-level="true"
|
|
|
|
/>
|
|
|
|
</div>
|
2021-08-11 10:43:54 +00:00
|
|
|
<div class="column contact-picker">
|
|
|
|
<div v-if="isSelectedActorAGroup && actorMembers.length > 0">
|
2020-09-29 07:53:48 +00:00
|
|
|
<p>{{ $t("Add a contact") }}</p>
|
2021-08-11 10:43:54 +00:00
|
|
|
<b-input
|
|
|
|
:placeholder="$t('Filter by name')"
|
|
|
|
v-model="contactFilter"
|
|
|
|
/>
|
|
|
|
<p
|
|
|
|
class="field"
|
|
|
|
v-for="actor in filteredActorMembers"
|
|
|
|
:key="actor.id"
|
|
|
|
>
|
2020-09-29 07:53:48 +00:00
|
|
|
<b-checkbox v-model="actualContacts" :native-value="actor.id">
|
|
|
|
<div class="media">
|
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-48x48" v-if="actor.avatar">
|
|
|
|
<img
|
|
|
|
class="image is-rounded"
|
|
|
|
:src="actor.avatar.url"
|
|
|
|
:alt="actor.avatar.alt"
|
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
|
|
|
</div>
|
|
|
|
<div class="media-content" v-if="actor.name">
|
|
|
|
<p class="is-4">{{ actor.name }}</p>
|
2021-08-01 09:03:48 +00:00
|
|
|
<p class="is-6 has-text-grey-dark">
|
|
|
|
{{ `@${usernameWithDomain(actor)}` }}
|
2020-11-30 09:24:11 +00:00
|
|
|
</p>
|
2020-09-29 07:53:48 +00:00
|
|
|
</div>
|
|
|
|
<div class="media-content" v-else>
|
2021-08-01 09:03:48 +00:00
|
|
|
{{ `@${usernameWithDomain(actor)}` }}
|
2020-09-29 07:53:48 +00:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</b-checkbox>
|
|
|
|
</p>
|
|
|
|
</div>
|
2021-08-11 10:43:54 +00:00
|
|
|
<div v-else class="content has-text-grey-dark has-text-centered">
|
2020-09-29 07:53:48 +00:00
|
|
|
<p>{{ $t("Your profile will be shown as contact.") }}</p>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</section>
|
|
|
|
<footer class="modal-card-foot">
|
|
|
|
<button class="button is-primary" type="button" @click="pickActor">
|
|
|
|
{{ $t("Pick") }}
|
|
|
|
</button>
|
|
|
|
</footer>
|
|
|
|
</div>
|
|
|
|
</b-modal>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
<script lang="ts">
|
|
|
|
import { Component, Prop, Vue, Watch } from "vue-property-decorator";
|
2020-11-27 18:27:44 +00:00
|
|
|
import { IMember } from "@/types/actor/member.model";
|
2021-03-29 08:33:19 +00:00
|
|
|
import { IActor, IGroup, IPerson, usernameWithDomain } from "../../types/actor";
|
2020-09-29 07:53:48 +00:00
|
|
|
import OrganizerPicker from "./OrganizerPicker.vue";
|
2021-03-29 08:33:19 +00:00
|
|
|
import {
|
|
|
|
CURRENT_ACTOR_CLIENT,
|
2021-06-10 08:33:16 +00:00
|
|
|
IDENTITIES,
|
2021-03-29 08:33:19 +00:00
|
|
|
LOGGED_USER_MEMBERSHIPS,
|
|
|
|
} from "../../graphql/actor";
|
2020-09-29 07:53:48 +00:00
|
|
|
import { Paginate } from "../../types/paginate";
|
2021-03-29 08:33:19 +00:00
|
|
|
import { GROUP_MEMBERS } from "@/graphql/member";
|
|
|
|
import { ActorType, MemberRole } from "@/types/enums";
|
|
|
|
|
|
|
|
const MEMBER_ROLES = [
|
|
|
|
MemberRole.CREATOR,
|
|
|
|
MemberRole.ADMINISTRATOR,
|
|
|
|
MemberRole.MODERATOR,
|
|
|
|
MemberRole.MEMBER,
|
|
|
|
];
|
2020-09-29 07:53:48 +00:00
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: { OrganizerPicker },
|
|
|
|
apollo: {
|
2021-03-29 08:33:19 +00:00
|
|
|
members: {
|
|
|
|
query: GROUP_MEMBERS,
|
2020-09-29 07:53:48 +00:00
|
|
|
variables() {
|
|
|
|
return {
|
2021-03-29 08:33:19 +00:00
|
|
|
name: usernameWithDomain(this.selectedActor),
|
|
|
|
page: this.membersPage,
|
|
|
|
limit: 10,
|
|
|
|
roles: MEMBER_ROLES.join(","),
|
2020-09-29 07:53:48 +00:00
|
|
|
};
|
|
|
|
},
|
2021-03-29 08:33:19 +00:00
|
|
|
update: (data) => data.group.members,
|
2020-09-29 07:53:48 +00:00
|
|
|
skip() {
|
2021-03-29 08:33:19 +00:00
|
|
|
return (
|
|
|
|
!this.selectedActor || this.selectedActor.type !== ActorType.GROUP
|
|
|
|
);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
currentActor: CURRENT_ACTOR_CLIENT,
|
|
|
|
userMemberships: {
|
|
|
|
query: LOGGED_USER_MEMBERSHIPS,
|
|
|
|
variables: {
|
|
|
|
page: 1,
|
|
|
|
limit: 100,
|
2020-09-29 07:53:48 +00:00
|
|
|
},
|
2021-03-29 08:33:19 +00:00
|
|
|
update: (data) => data.loggedUser.memberships,
|
2020-09-29 07:53:48 +00:00
|
|
|
},
|
2021-06-10 08:33:16 +00:00
|
|
|
identities: IDENTITIES,
|
2020-09-29 07:53:48 +00:00
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class OrganizerPickerWrapper extends Vue {
|
2021-03-29 08:33:19 +00:00
|
|
|
@Prop({ type: Object, required: false }) value!: IActor;
|
2020-09-29 07:53:48 +00:00
|
|
|
|
|
|
|
@Prop({ default: true, type: Boolean }) inline!: boolean;
|
|
|
|
|
2021-03-29 08:33:19 +00:00
|
|
|
currentActor!: IPerson;
|
2020-09-29 07:53:48 +00:00
|
|
|
|
2021-06-10 08:33:16 +00:00
|
|
|
identities!: IPerson[];
|
|
|
|
|
2020-09-29 07:53:48 +00:00
|
|
|
isComponentModalActive = false;
|
|
|
|
|
2021-08-11 10:43:54 +00:00
|
|
|
contactFilter = "";
|
|
|
|
|
2021-08-01 09:03:48 +00:00
|
|
|
usernameWithDomain = usernameWithDomain;
|
|
|
|
|
2020-11-30 09:24:11 +00:00
|
|
|
@Prop({ type: Array, required: false, default: () => [] })
|
|
|
|
contacts!: IActor[];
|
2021-03-29 08:33:19 +00:00
|
|
|
members: Paginate<IMember> = { elements: [], total: 0 };
|
|
|
|
|
|
|
|
membersPage = 1;
|
|
|
|
|
|
|
|
userMemberships: Paginate<IMember> = { elements: [], total: 0 };
|
|
|
|
|
|
|
|
get actualContacts(): (string | undefined)[] {
|
|
|
|
return this.contacts.map(({ id }) => id);
|
|
|
|
}
|
|
|
|
|
|
|
|
set actualContacts(contactsIds: (string | undefined)[]) {
|
|
|
|
this.$emit(
|
|
|
|
"update:contacts",
|
|
|
|
this.actorMembers.filter(({ id }) => contactsIds.includes(id))
|
|
|
|
);
|
|
|
|
}
|
2020-09-29 07:53:48 +00:00
|
|
|
|
2021-03-29 08:33:19 +00:00
|
|
|
@Watch("userMemberships")
|
|
|
|
setInitialActor(): void {
|
|
|
|
if (this.$route.query?.actorId) {
|
|
|
|
const actorId = this.$route.query?.actorId as string;
|
|
|
|
const actor = this.userMemberships.elements.find(
|
|
|
|
({ parent: { id }, role }) =>
|
|
|
|
actorId === id && MEMBER_ROLES.includes(role)
|
|
|
|
)?.parent as IActor;
|
|
|
|
this.selectedActor = actor;
|
|
|
|
}
|
|
|
|
}
|
2020-09-29 07:53:48 +00:00
|
|
|
|
2021-03-29 08:33:19 +00:00
|
|
|
get selectedActor(): IActor | undefined {
|
|
|
|
if (this.value?.id) {
|
|
|
|
return this.value;
|
|
|
|
}
|
|
|
|
if (this.currentActor) {
|
2021-06-10 08:33:16 +00:00
|
|
|
return this.identities.find(
|
|
|
|
(identity) => identity.id === this.currentActor.id
|
|
|
|
);
|
2021-03-29 08:33:19 +00:00
|
|
|
}
|
|
|
|
return undefined;
|
2020-09-29 07:53:48 +00:00
|
|
|
}
|
|
|
|
|
2021-03-29 08:33:19 +00:00
|
|
|
set selectedActor(selectedActor: IActor | undefined) {
|
|
|
|
this.$emit("input", selectedActor);
|
2020-09-29 07:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
async relay(group: IGroup): Promise<void> {
|
2021-03-29 08:33:19 +00:00
|
|
|
this.actualContacts = [];
|
|
|
|
this.selectedActor = group;
|
2020-09-29 07:53:48 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pickActor(): void {
|
|
|
|
this.isComponentModalActive = false;
|
|
|
|
}
|
|
|
|
|
2021-03-29 08:33:19 +00:00
|
|
|
get actorMembers(): IActor[] {
|
2021-08-11 10:43:54 +00:00
|
|
|
if (this.isSelectedActorAGroup) {
|
2021-03-29 08:33:19 +00:00
|
|
|
return this.members.elements.map(({ actor }: { actor: IActor }) => actor);
|
2020-09-29 07:53:48 +00:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
2021-08-11 10:43:54 +00:00
|
|
|
|
|
|
|
get filteredActorMembers(): IActor[] {
|
|
|
|
return this.actorMembers.filter((actor) => {
|
|
|
|
return [
|
|
|
|
actor.preferredUsername.toLowerCase(),
|
|
|
|
actor.name?.toLowerCase(),
|
|
|
|
actor.domain?.toLowerCase(),
|
|
|
|
].some((match) => match?.includes(this.contactFilter.toLowerCase()));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
get isSelectedActorAGroup(): boolean {
|
|
|
|
return this.selectedActor?.type === ActorType.GROUP;
|
|
|
|
}
|
2020-09-29 07:53:48 +00:00
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
2021-08-11 10:43:54 +00:00
|
|
|
.modal-card-body .columns .column {
|
|
|
|
&.actor-picker,
|
|
|
|
&.contact-picker {
|
|
|
|
overflow-y: auto;
|
|
|
|
max-height: 400px;
|
2020-09-29 07:53:48 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|