happyDomain/ui/src/lib/components/domains/SubdomainList.svelte

92 lines
3.1 KiB
Svelte
Raw Normal View History

2023-12-24 10:18:08 +00:00
<!--
This file is part of the happyDomain (R) project.
Copyright (c) 2022-2024 happyDomain
Authors: Pierre-Olivier Mercier, et al.
This program is offered under a commercial and under the AGPL license.
For commercial licensing, contact us at <contact@happydomain.org>.
For AGPL licensing:
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
-->
2023-01-03 08:13:08 +00:00
<script lang="ts">
2023-01-08 17:44:01 +00:00
import { createEventDispatcher } from 'svelte';
2023-01-03 08:13:08 +00:00
2023-11-23 14:21:40 +00:00
import AliasModal, { controls as ctrlAlias } from '$lib/components/domains/AliasModal.svelte';
import { controls as ctrlNewService } from '$lib/components/NewServicePath.svelte';
import { controls as ctrlService } from '$lib/components/domains/ServiceModal.svelte';
2023-01-03 08:13:08 +00:00
import SubdomainItem from '$lib/components/domains/SubdomainItem.svelte';
import type { Domain, DomainInList } from '$lib/model/domain';
2023-01-08 17:44:01 +00:00
import type { ServiceCombined } from '$lib/model/service';
2023-01-03 08:13:08 +00:00
import type { Zone } from '$lib/model/zone';
2023-01-08 17:44:01 +00:00
const dispatch = createEventDispatcher();
2023-01-03 08:13:08 +00:00
export let origin: DomainInList | Domain;
2023-01-03 08:13:08 +00:00
export let sortedDomains: Array<string>;
export let sortedDomainsWithIntermediate: Array<string>;
2023-01-03 08:13:08 +00:00
export let zone: Zone;
let aliases: Record<string, Array<string>>;
$: {
const tmp: Record<string, Array<string>> = { };
for (const dn of sortedDomains) {
2023-01-08 17:44:01 +00:00
if (!zone.services[dn]) continue;
2023-01-03 08:13:08 +00:00
zone.services[dn].forEach(function (svc) {
if (svc._svctype === 'svcs.CNAME') {
if (!tmp[svc.Service.Target]) {
tmp[svc.Service.Target] = []
}
tmp[svc.Service.Target].push(dn)
}
})
}
2023-11-23 14:21:40 +00:00
if (tmp['@']) tmp[""] = tmp["@"];
2023-01-03 08:13:08 +00:00
aliases = tmp;
}
2023-01-11 09:52:07 +00:00
export let newSubdomainModalOpened = false;
2023-11-23 14:21:40 +00:00
$: if (newSubdomainModalOpened) {
ctrlNewSubdomain.Open();
2023-01-08 17:44:01 +00:00
}
function showServiceModal(event: CustomEvent<ServiceCombined>) {
2023-11-23 14:21:40 +00:00
ctrlService.Open(event.detail);
2023-01-08 17:44:01 +00:00
}
2023-01-03 08:13:08 +00:00
</script>
{#each sortedDomainsWithIntermediate as dn}
2023-01-03 08:13:08 +00:00
<SubdomainItem
aliases={aliases[dn]?aliases[dn]:[]}
{dn}
{origin}
zoneId={zone.id}
services={zone.services[dn]?zone.services[dn]:[]}
2023-11-23 14:21:40 +00:00
on:new-alias={() => ctrlAlias.Open(dn)}
on:new-service={() => ctrlNewService.Open(dn)}
2023-01-08 17:44:01 +00:00
on:show-service={showServiceModal}
on:update-zone-services={(event) => dispatch("update-zone-services", event.detail)}
2023-01-03 08:13:08 +00:00
/>
{/each}
2023-01-08 17:44:01 +00:00
<AliasModal
{origin}
{zone}
on:update-zone-services={(event) => dispatch("update-zone-services", event.detail)}
/>