Spaces:
Running
Running
Download components/record-editor.js from ffcc9393/dns-dynamo-dashboard: direct link, hf CLI and curl.
- Browser
- Download file 9.39 kB
-
https://huggingface.co/spaces/ffcc9393/dns-dynamo-dashboard/resolve/main/components/record-editor.js
- Command line
-
hf download hf://spaces/ffcc9393/dns-dynamo-dashboard/components/record-editor.js
-
curl -L -o record-editor.js https://huggingface.co/spaces/ffcc9393/dns-dynamo-dashboard/resolve/main/components/record-editor.js
9.39 kB
| class CustomRecordEditor extends HTMLElement { | |
| connectedCallback() { | |
| this.attachShadow({ mode: 'open' }); | |
| this.shadowRoot.innerHTML = ` | |
| <style> | |
| .modal-overlay { | |
| animation: fadeIn 0.2s ease-out; | |
| background-color: rgba(0, 0, 0, 0.5); | |
| backdrop-filter: blur(4px); | |
| } | |
| .modal-content { | |
| animation: slideIn 0.2s ease-out; | |
| border-radius: 12px; | |
| box-shadow: 0 10px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04); | |
| } | |
| .record-type-badge { | |
| height: 22px; | |
| width: 22px; | |
| display: inline-flex; | |
| align-items: center; | |
| justify-content: center; | |
| border-radius: 9999px; | |
| font-size: 12px; | |
| font-weight: 600; | |
| } | |
| .record-type-badge.A { | |
| background-color: #dcfce7; | |
| color: #166534; | |
| } | |
| .record-type-badge.MX { | |
| background-color: #dbeafe; | |
| color: #1e40af; | |
| } | |
| .record-type-badge.CNAME { | |
| background-color: #ede9fe; | |
| color: #5b21b6; | |
| } | |
| .record-type-badge.TXT { | |
| background-color: #fef3c7; | |
| color: #92400e; | |
| } | |
| .record-type-badge.NS { | |
| background-color: #fee2e2; | |
| color: #991b1b; | |
| } | |
| .record-type-badge.SRV { | |
| background-color: #ecfccb; | |
| color: #3f6212; | |
| } | |
| </style> | |
| <div class="fixed inset-0 z-50 hidden" id="modal"> | |
| <div class="modal-overlay absolute inset-0 bg-black bg-opacity-50 flex items-center justify-center p-4"> | |
| <div class="modal-content bg-white rounded-lg shadow-xl w-full max-w-md"> | |
| <div class="p-6"> | |
| <div class="flex items-center justify-between mb-4"> | |
| <h3 class="text-lg font-medium text-gray-900" id="modal-title">Edit DNS Record</h3> | |
| <button class="text-gray-400 hover:text-gray-500" id="close-modal"> | |
| <i data-feather="x"></i> | |
| </button> | |
| </div> | |
| <form id="record-form"> | |
| <div class="space-y-4"> | |
| <div> | |
| <label for="record-type" class="block text-sm font-medium text-gray-700 mb-1">Record Type</label> | |
| <select id="record-type" name="type" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm" required> | |
| <option value="A">A (Address)</option> | |
| <option value="AAAA">AAAA (IPv6 Address)</option> | |
| <option value="CNAME">CNAME (Canonical Name)</option> | |
| <option value="MX">MX (Mail Exchange)</option> | |
| <option value="TXT">TXT (Text)</option> | |
| <option value="NS">NS (Name Server)</option> | |
| <option value="SRV">SRV (Service)</option> | |
| </select> | |
| </div> | |
| <div> | |
| <label for="record-name" class="block text-sm font-medium text-gray-700 mb-1">Name</label> | |
| <input type="text" id="record-name" name="name" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm" placeholder="example.com" required> | |
| </div> | |
| <div> | |
| <label for="record-content" class="block text-sm font-medium text-gray-700 mb-1">Content</label> | |
| <input type="text" id="record-content" name="content" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm" placeholder="192.0.2.1" required> | |
| </div> | |
| <div> | |
| <label for="record-ttl" class="block text-sm font-medium text-gray-700 mb-1">TTL (Time to Live)</label> | |
| <select id="record-ttl" name="ttl" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm" required> | |
| <option value="60">1 minute</option> | |
| <option value="300">5 minutes</option> | |
| <option value="600">10 minutes</option> | |
| <option value="1800">30 minutes</option> | |
| <option value="3600" selected>1 hour</option> | |
| <option value="21600">6 hours</option> | |
| <option value="43200">12 hours</option> | |
| <option value="86400">1 day</option> | |
| </select> | |
| </div> | |
| <div class="hidden" id="priority-field"> | |
| <label for="record-priority" class="block text-sm font-medium text-gray-700 mb-1">Priority</label> | |
| <input type="number" id="record-priority" name="priority" class="block w-full rounded-md border-gray-300 shadow-sm focus:border-primary-500 focus:ring-primary-500 sm:text-sm" placeholder="10" min="0" max="65535"> | |
| </div> | |
| </div> | |
| <div class="mt-6 flex justify-end gap-3"> | |
| <button type="button" class="inline-flex justify-center rounded-md border border-gray-300 bg-white py-2 px-4 text-sm font-medium text-gray-700 shadow-sm hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2" id="cancel-btn"> | |
| Cancel | |
| </button> | |
| <button type="submit" class="inline-flex justify-center rounded-md border border-transparent bg-primary-600 py-2 px-4 text-sm font-medium text-white shadow-sm hover:bg-primary-700 focus:outline-none focus:ring-2 focus:ring-primary-500 focus:ring-offset-2"> | |
| Save Record | |
| </button> | |
| </div> | |
| </form> | |
| </div> | |
| </div> | |
| </div> | |
| </div> | |
| `; | |
| this.modal = this.shadowRoot.getElementById('modal'); | |
| this.closeButton = this.shadowRoot.getElementById('close-modal'); | |
| this.cancelButton = this.shadowRoot.getElementById('cancel-btn'); | |
| this.recordTypeSelect = this.shadowRoot.getElementById('record-type'); | |
| this.priorityField = this.shadowRoot.getElementById('priority-field'); | |
| this.closeButton.addEventListener('click', () => this.hide()); | |
| this.cancelButton.addEventListener('click', () => this.hide()); | |
| this.recordTypeSelect.addEventListener('change', () => { | |
| if (['MX', 'SRV'].includes(this.recordTypeSelect.value)) { | |
| this.priorityField.classList.remove('hidden'); | |
| } else { | |
| this.priorityField.classList.add('hidden'); | |
| } | |
| }); | |
| } | |
| static get observedAttributes() { | |
| return ['visible', 'mode', 'record-id']; | |
| } | |
| attributeChangedCallback(name, oldValue, newValue) { | |
| if (name === 'visible') { | |
| if (newValue === 'true') { | |
| this.show(); | |
| } else { | |
| this.hide(); | |
| } | |
| } | |
| if (name === 'mode') { | |
| const title = this.shadowRoot.getElementById('modal-title'); | |
| if (newValue === 'add') { | |
| title.textContent = 'Add DNS Record'; | |
| } else { | |
| title.textContent = 'Edit DNS Record'; | |
| } | |
| } | |
| } | |
| show() { | |
| this.modal.classList.remove('hidden'); | |
| feather.replace(); | |
| } | |
| hide() { | |
| this.modal.classList.add('hidden'); | |
| this.removeAttribute('visible'); | |
| } | |
| } | |
| customElements.define('custom-record-editor', CustomRecordEditor); |