import { html, Component, render, createContext, useState, useEffect } from './vendor/preact/standalone.js'; import { getRecords } from './api.js'; const rdataInputProperties = { Address: {label: 'adresse', type: 'text'}, Serial: {label: 'serial', type: 'number'}, Minimum: {label: 'minimum', type: 'number'}, Retry: {label: 'nouvelle tentative', type: 'number'}, Refresh: {label: 'actualisation', type: 'number'}, MaintainerName: {label: 'contact', type: 'text'}, MasterServerName: {label: 'serveur primaire', type: 'text'}, Expire: {label: 'expiration', type: 'number'}, Target: {label: 'cible', type: 'text'}, }; const Editable = createContext(false); function RDataInput({ name, value = '', index = 0 }) { const {label, type} = rdataInputProperties[name] || {label: name, type: 'text'}; return html` <${Editable.Consumer}> ${ (editable) => { if (editable) { return html`
`; } else { return html`
${label}:
${value}
`; } } } `; } function RData({ rdata, index }) { const { Address: address } = rdata; return Object.entries(rdata).map(([name, value]) => html`<${RDataInput} name=${name} value=${value} index=${index} />`); } function Record({name, ttl, type, rdata, index = 0}) { return html` ${name} ${type} ${ttl} <${Editable.Consumer}> ${ (editable) => { if (editable) { return html`<${RData} rdata=${rdata} index=${index}/>` } else { return html`
<${RData} rdata=${rdata} index=${index}/>
` } } } `; } function RecordList({ zone }) { const [records, setRecords] = useState([]); const [editable, setEditable] = useState(false); const toggleEdit = () => setEditable(!editable); useEffect(() => { getRecords(zone) .then((res) => setRecords(res)); }, []); return html` <${Editable.Provider} value=${editable}> ${records.map( ({Name, Class, TTL, Type, ...rdata}, index) => { return html`<${Record} name=${Name} ttl=${TTL} type=${Type} rdata=${rdata} index=${index}/>` } )} `; } export default function(element, { zone }) { render(html`<${RecordList} zone=${zone} />`, element); };
Nom Type TTL Données