2020-09-29 09:53:48 +02:00
|
|
|
<template>
|
|
|
|
<div class="organizer-picker">
|
|
|
|
<!-- If we have a current actor (inline) -->
|
2020-11-30 10:24:11 +01:00
|
|
|
<div
|
|
|
|
v-if="inline && currentActor.id"
|
|
|
|
class="inline box"
|
|
|
|
@click="isComponentModalActive = true"
|
|
|
|
>
|
2020-09-29 09:53:48 +02:00
|
|
|
<div class="media">
|
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-48x48" v-if="currentActor.avatar">
|
|
|
|
<img
|
|
|
|
class="image is-rounded"
|
|
|
|
:src="currentActor.avatar.url"
|
|
|
|
:alt="currentActor.avatar.alt"
|
|
|
|
/>
|
|
|
|
</figure>
|
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
|
|
|
</div>
|
|
|
|
<div class="media-content" v-if="currentActor.name">
|
|
|
|
<p class="is-4">{{ currentActor.name }}</p>
|
2020-11-30 10:24:11 +01:00
|
|
|
<p class="is-6 has-text-grey">
|
|
|
|
{{ `@${currentActor.preferredUsername}` }}
|
|
|
|
</p>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
|
|
|
<div class="media-content" v-else>
|
|
|
|
{{ `@${currentActor.preferredUsername}` }}
|
|
|
|
</div>
|
|
|
|
<b-button type="is-text" @click="isComponentModalActive = true">
|
|
|
|
{{ $t("Change") }}
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<!-- If we have a current actor -->
|
2020-11-30 10:24:11 +01:00
|
|
|
<span
|
|
|
|
v-else-if="currentActor.id"
|
|
|
|
class="block"
|
|
|
|
@click="isComponentModalActive = true"
|
|
|
|
>
|
2020-09-29 09:53:48 +02:00
|
|
|
<img
|
|
|
|
class="image is-48x48"
|
|
|
|
v-if="currentActor.avatar"
|
|
|
|
:src="currentActor.avatar.url"
|
|
|
|
:alt="currentActor.avatar.alt"
|
|
|
|
/>
|
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
|
|
|
</span>
|
|
|
|
<!-- If we have no current actor -->
|
|
|
|
<div v-if="groupMemberships.total === 0 || !currentActor.id" class="box">
|
|
|
|
<div class="media">
|
|
|
|
<div class="media-left">
|
|
|
|
<figure class="image is-48x48" v-if="identity.avatar">
|
2020-11-30 10:24:11 +01:00
|
|
|
<img
|
|
|
|
class="image is-rounded"
|
|
|
|
:src="identity.avatar.url"
|
|
|
|
:alt="identity.avatar.alt"
|
|
|
|
/>
|
2020-09-29 09:53:48 +02:00
|
|
|
</figure>
|
|
|
|
<b-icon v-else size="is-large" icon="account-circle" />
|
|
|
|
</div>
|
|
|
|
<div class="media-content" v-if="identity.name">
|
|
|
|
<p class="is-4">{{ identity.name }}</p>
|
2020-11-30 10:24:11 +01:00
|
|
|
<p class="is-6 has-text-grey">
|
|
|
|
{{ `@${identity.preferredUsername}` }}
|
|
|
|
</p>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
|
|
|
<div class="media-content" v-else>
|
|
|
|
{{ `@${identity.preferredUsername}` }}
|
|
|
|
</div>
|
|
|
|
<b-button type="is-text" @click="isComponentModalActive = true">
|
|
|
|
{{ $t("Change") }}
|
|
|
|
</b-button>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<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">
|
|
|
|
<div class="column">
|
|
|
|
<organizer-picker
|
|
|
|
v-model="currentActor"
|
|
|
|
:identity.sync="identity"
|
|
|
|
@input="relay"
|
|
|
|
:restrict-moderator-level="true"
|
|
|
|
/>
|
|
|
|
</div>
|
|
|
|
<div class="column">
|
|
|
|
<div v-if="actorMembersForCurrentActor.length > 0">
|
|
|
|
<p>{{ $t("Add a contact") }}</p>
|
2020-11-30 10:24:11 +01:00
|
|
|
<p
|
|
|
|
class="field"
|
|
|
|
v-for="actor in actorMembersForCurrentActor"
|
|
|
|
:key="actor.id"
|
|
|
|
>
|
2020-09-29 09:53:48 +02: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>
|
2020-11-30 10:24:11 +01:00
|
|
|
<p class="is-6 has-text-grey">
|
|
|
|
{{ `@${actor.preferredUsername}` }}
|
|
|
|
</p>
|
2020-09-29 09:53:48 +02:00
|
|
|
</div>
|
|
|
|
<div class="media-content" v-else>
|
|
|
|
{{ `@${actor.preferredUsername}` }}
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</b-checkbox>
|
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
<div v-else class="content has-text-grey has-text-centered">
|
|
|
|
<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 19:27:44 +01:00
|
|
|
import { IMember } from "@/types/actor/member.model";
|
|
|
|
import { IActor, IGroup, IPerson } from "../../types/actor";
|
2020-09-29 09:53:48 +02:00
|
|
|
import OrganizerPicker from "./OrganizerPicker.vue";
|
|
|
|
import { PERSON_MEMBERSHIPS_WITH_MEMBERS } from "../../graphql/actor";
|
|
|
|
import { Paginate } from "../../types/paginate";
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
components: { OrganizerPicker },
|
|
|
|
apollo: {
|
|
|
|
groupMemberships: {
|
|
|
|
query: PERSON_MEMBERSHIPS_WITH_MEMBERS,
|
|
|
|
variables() {
|
|
|
|
return {
|
|
|
|
id: this.identity.id,
|
|
|
|
};
|
|
|
|
},
|
|
|
|
update: (data) => data.person.memberships,
|
|
|
|
skip() {
|
|
|
|
return !this.identity.id;
|
|
|
|
},
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
export default class OrganizerPickerWrapper extends Vue {
|
|
|
|
@Prop({ type: Object, required: true }) value!: IActor;
|
|
|
|
|
|
|
|
@Prop({ default: true, type: Boolean }) inline!: boolean;
|
|
|
|
|
|
|
|
@Prop({ type: Object, required: true }) identity!: IPerson;
|
|
|
|
|
|
|
|
isComponentModalActive = false;
|
|
|
|
|
|
|
|
currentActor: IActor = this.value;
|
|
|
|
|
|
|
|
groupMemberships: Paginate<IMember> = { elements: [], total: 0 };
|
|
|
|
|
2020-11-30 10:24:11 +01:00
|
|
|
@Prop({ type: Array, required: false, default: () => [] })
|
|
|
|
contacts!: IActor[];
|
2020-09-29 09:53:48 +02:00
|
|
|
|
|
|
|
actualContacts: (string | undefined)[] = this.contacts.map(({ id }) => id);
|
|
|
|
|
|
|
|
@Watch("contacts")
|
|
|
|
updateActualContacts(contacts: IActor[]): void {
|
|
|
|
this.actualContacts = contacts.map(({ id }) => id);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Watch("value")
|
|
|
|
updateCurrentActor(value: IGroup): void {
|
|
|
|
this.currentActor = value;
|
|
|
|
}
|
|
|
|
|
|
|
|
async relay(group: IGroup): Promise<void> {
|
|
|
|
this.currentActor = group;
|
|
|
|
}
|
|
|
|
|
|
|
|
pickActor(): void {
|
|
|
|
this.$emit(
|
|
|
|
"update:contacts",
|
2020-11-30 10:24:11 +01:00
|
|
|
this.actorMembersForCurrentActor.filter(({ id }) =>
|
|
|
|
this.actualContacts.includes(id)
|
|
|
|
)
|
2020-09-29 09:53:48 +02:00
|
|
|
);
|
|
|
|
this.$emit("input", this.currentActor);
|
|
|
|
this.isComponentModalActive = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
get actorMembersForCurrentActor(): IActor[] {
|
|
|
|
const currentMembership = this.groupMemberships.elements.find(
|
|
|
|
({ parent: { id } }) => id === this.currentActor.id
|
|
|
|
);
|
|
|
|
if (currentMembership) {
|
2020-11-30 10:24:11 +01:00
|
|
|
return currentMembership.parent.members.elements.map(
|
|
|
|
({ actor }: { actor: IActor }) => actor
|
|
|
|
);
|
2020-09-29 09:53:48 +02:00
|
|
|
}
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.group-picker {
|
|
|
|
.block,
|
|
|
|
.no-group,
|
|
|
|
.inline {
|
|
|
|
cursor: pointer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</style>
|