2025-06-30 18:58:24 +02:00
|
|
|
<!--
|
|
|
|
SPDX-FileCopyrightText: © 2025 Hornwitser <code@hornwitser.no>
|
|
|
|
SPDX-License-Identifier: AGPL-3.0-or-later
|
|
|
|
-->
|
2025-03-15 18:18:08 +01:00
|
|
|
<template>
|
|
|
|
<div>
|
|
|
|
<template v-for="account in assigned">
|
|
|
|
{{ account.name }}
|
|
|
|
<button
|
|
|
|
v-if="edit"
|
|
|
|
type="button"
|
2025-06-14 19:22:53 +02:00
|
|
|
@click="assignedIds = new Set([...assignedIds].filter(id => id !== account.id))"
|
2025-03-15 18:18:08 +01:00
|
|
|
>
|
|
|
|
x
|
|
|
|
</button>
|
|
|
|
{{ " " }}
|
|
|
|
</template>
|
|
|
|
<input
|
|
|
|
v-if="edit"
|
|
|
|
type="text"
|
|
|
|
@change="addCrew"
|
|
|
|
v-model="addName"
|
|
|
|
>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script lang="ts" setup>
|
|
|
|
defineProps<{
|
|
|
|
edit?: boolean
|
|
|
|
}>();
|
2025-06-23 00:17:22 +02:00
|
|
|
const usersStore = useUsersStore();
|
|
|
|
await usersStore.fetch();
|
2025-06-14 19:22:53 +02:00
|
|
|
const assignedIds = defineModel<Set<number>>({ required: true });
|
2025-03-15 18:18:08 +01:00
|
|
|
const assigned = computed(
|
2025-06-14 19:22:53 +02:00
|
|
|
() => [...assignedIds.value].map(
|
2025-06-23 00:17:22 +02:00
|
|
|
id => usersStore.users.get(id) ?? { id, name: String(id) }
|
2025-03-15 18:18:08 +01:00
|
|
|
)
|
|
|
|
);
|
|
|
|
const crewByName = computed(() => new Map(
|
2025-06-23 00:17:22 +02:00
|
|
|
[...usersStore.users.values()]
|
|
|
|
.filter(a => a.type === "crew" || a.type === "admin")
|
|
|
|
.map(a => [a.name!, a])
|
2025-03-15 18:18:08 +01:00
|
|
|
));
|
|
|
|
const addName = ref("");
|
|
|
|
function addCrew() {
|
|
|
|
if (!addName.value)
|
|
|
|
return;
|
|
|
|
const account = crewByName.value.get(addName.value);
|
|
|
|
if (account) {
|
2025-06-14 19:22:53 +02:00
|
|
|
if (!assignedIds.value.has(account.id)) {
|
|
|
|
assignedIds.value = new Set([...assignedIds.value, account.id]);
|
2025-03-15 18:18:08 +01:00
|
|
|
} else {
|
|
|
|
alert(`${addName.value} has already been added`);
|
|
|
|
}
|
|
|
|
addName.value = "";
|
|
|
|
} else {
|
|
|
|
alert(`No crew account by the name ${addName.value}`);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style scoped>
|
|
|
|
input {
|
|
|
|
width: 3em;
|
|
|
|
}
|
|
|
|
</style>
|