Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
71 changes: 71 additions & 0 deletions src/components/TTLEditor.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<script lang="ts">
export let value: number | null;

const fiveMinutes = 60 * 5; // 300 seconds
const oneHour = 60 * 60;
const twoHours = oneHour * 2;
const oneDay = oneHour * 24;
const twoDays = oneDay * 2;
const oneWeek = oneDay * 7;

const ttlOptions = [
{value: "default", name: "Default"},
{value: "custom", name: "Custom"},
{value: fiveMinutes, name: "Five Minutes"},
{value: oneHour, name: "One Hour"},
{value: twoHours, name: "Two Hours"},
{value: oneDay, name: "One Day"},
{value: twoDays, name: "Two Days"},
{value: oneWeek, name: "One Week"},
];

let currentPreset: string | number;
let newValue: number;

// Update currentPresent to match the state of value
$: {
newValue = value ?? 0;

currentPreset = "custom";
if (value === null) {
currentPreset = "default";
} else {
for (const option of ttlOptions) {
if (value === option.value) {
currentPreset = value;
break;
}
}
}
}

function updateOutput() {
// Follow the preset
if (currentPreset === "default") {
value = null;
newValue = 0;
}
if (typeof currentPreset === "number") {
value = currentPreset;
newValue = currentPreset;
}
}
</script>

<div>
<select bind:value={currentPreset} on:change={() => updateOutput()}>
{#each ttlOptions as option}
<option value={option.value}>{option.name}</option>
{/each}
</select>
<span class:hide-custom-input={currentPreset !== "custom"}>
<input type="text" class="code-font" bind:value={newValue} on:change={() => updateOutput()} />
seconds
</span>
</div>

<style>
.hide-custom-input {
display: none;
}
</style>
4 changes: 4 additions & 0 deletions src/components/create-domains/ACreate.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import {DnsTypeA, DnsTypeAAAA, type AaaaValue, type ApiRecordFormat, type AValue} from "../../types/records";
import {IPv4, IPv6, parse as parseAddr} from "ipaddr.js";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<AValue | AaaaValue>;
export let editMode: boolean;
Expand Down Expand Up @@ -30,6 +31,9 @@
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}

<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />

<div>IP Address</div>
<div><input type="text" class="code-font" bind:value size={Math.max(20, value.length + 2)} /></div>
{#if editItem.type === DnsTypeA}
Expand Down
3 changes: 3 additions & 0 deletions src/components/create-domains/CaaCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, CaaValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<CaaValue>;
export let editMode: boolean;
Expand All @@ -11,6 +12,8 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Tag</div>
<div><input type="text" class="code-font" bind:value={editItem.value.tag} size={Math.max(20, editItem.value.tag.length + 2)} /></div>
<div>Value</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/create-domains/CnameCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, CnameValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<CnameValue>;
export let editMode: boolean;
Expand All @@ -11,5 +12,7 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Target</div>
<div><input type="text" class="code-font" bind:value={editItem.value.target} size={Math.max(20, editItem.value.target.length + 2)} /></div>
3 changes: 3 additions & 0 deletions src/components/create-domains/MxCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, MxValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<MxValue>;
export let editMode: boolean;
Expand All @@ -11,6 +12,8 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Mail Server</div>
<div><input type="text" class="code-font" bind:value={editItem.value.target} size={Math.max(20, editItem.value.target.length + 2)} /></div>
<div>Preference</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/create-domains/NsCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, NsValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<NsValue>;
export let editMode: boolean;
Expand All @@ -11,5 +12,7 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Nameserver</div>
<div><input type="text" class="code-font" bind:value={editItem.value.target} size={Math.max(20, editItem.value.target.length + 2)} /></div>
3 changes: 3 additions & 0 deletions src/components/create-domains/PtrCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, PtrValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<PtrValue>;
export let editMode: boolean;
Expand All @@ -11,5 +12,7 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Target</div>
<div><input type="text" class="code-font" bind:value={editItem.value.target} size={Math.max(20, editItem.value.target.length + 2)} /></div>
3 changes: 3 additions & 0 deletions src/components/create-domains/SrvCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, SrvValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<SrvValue>;
export let editMode: boolean;
Expand All @@ -18,6 +19,8 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Priority</div>
<div><input type="number" class="code-font" bind:value={editItem.value.priority} /></div>
<div>Weight</div>
Expand Down
3 changes: 3 additions & 0 deletions src/components/create-domains/TxtCreate.svelte
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script lang="ts">
import type {ApiRecordFormat, TxtValue} from "../../types/records";
import TTLEditor from "../TTLEditor.svelte";

export let editItem: ApiRecordFormat<TxtValue>;
export let editMode: boolean;
Expand All @@ -15,5 +16,7 @@
{:else}
<div><input type="text" class="code-font" bind:value={editItem.name} size={Math.max(20, editItem.name.length + 2)} /></div>
{/if}
<div>Time-To-Live</div>
<TTLEditor bind:value={editItem.ttl} />
<div>Value</div>
<div><input type="text" class="code-font" bind:value={editItem.value.text} size={constrain(20, 100, editItem.value.text.length + 2)} /></div>