From 7118cb685222ad45a3afba78a47ae39f48801cfc Mon Sep 17 00:00:00 2001 From: AJ ONeal Date: Wed, 17 Jan 2018 17:01:44 -0700 Subject: [PATCH] WIP edit records --- lib/digd.js | 4 +- lib/public/index.html | 134 +++++++++++++++++++++++------------------- lib/public/js/app.js | 48 ++++++++++++++- lib/store.json.js | 11 +++- 4 files changed, 132 insertions(+), 65 deletions(-) diff --git a/lib/digd.js b/lib/digd.js index cffbb43..d6d7d22 100644 --- a/lib/digd.js +++ b/lib/digd.js @@ -276,7 +276,7 @@ module.exports.query = function (engine, query, cb) { var qarr = qname.split('.'); var qnames = []; while (qarr.length) { - qnames.push(qarr.join('.').toLowerCase()); + qnames.push({ name: qarr.join('.').toLowerCase() }); qarr.shift(); // first } @@ -286,7 +286,7 @@ module.exports.query = function (engine, query, cb) { console.log(qnames); // getSoas - return engine.zones.get({ names: qnames }, function (err, myDomains) { + return engine.zones.get(qnames, function (err, myDomains) { console.log('[SOA] looking for', qnames, 'and proudly serving', err, myDomains); if (err) { cb(err); return; } diff --git a/lib/public/index.html b/lib/public/index.html index 42cd008..4fad2e3 100644 --- a/lib/public/index.html +++ b/lib/public/index.html @@ -43,19 +43,7 @@ {{ retry }} {{ refresh }} {{ ttl }} - -
  • - - type000 - example.com - {{ hex }} - {{ ttl }} -
  • -
  • - - ANY - example.com - {{ ttl }} +
  • @@ -63,6 +51,7 @@ example.com {{ addr }} {{ ttl }} +
  • @@ -70,6 +59,7 @@ example.com {{ target }} {{ ttl }} +
  • @@ -78,6 +68,7 @@ {{ flag }} {{ value }} {{ ttl }} +
  • @@ -86,12 +77,14 @@ {{ target }} {{ priority }} {{ ttl }} +
  • PTR example.com {{ ttl }} +
  • @@ -100,6 +93,7 @@ {{ port }} {{ priority }} {{ ttl }} +
  • @@ -107,88 +101,110 @@ example.com {{ text data }} {{ ttl }} +
  • - - -
    -
    - - SOA - example.com - {{ primary }} - admin.example.com - {{ seconds until expiration }} - {{ minimum }} - {{ serial }} - {{ retry }} - {{ refresh }} - {{ ttl }} -
    -
    +
  • type000 example.com {{ hex }} {{ ttl }} -
  • -
    + + + + + + + +
    + - ANY - example.com - {{ ttl }} + SOA + .example.com + + + + + + + +
    A / AAAA - example.com - {{ addr }} - {{ ttl }} + .example.com + +
    ANAME / CNAME - example.com - {{ target }} - {{ ttl }} + .example.com + +
    CAA - example.com - {{ flag }} - {{ value }} - {{ ttl }} + .example.com + + +
    MX - example.com - {{ target }} - {{ priority }} - {{ ttl }} + .example.com + + +
    PTR - example.com - {{ ttl }} + .example.com +
    SRV - example.com - {{ port }} - {{ priority }} - {{ ttl }} + .example.com + + +
    TXT - example.com - {{ text data }} - {{ ttl }} + .example.com + +
    - +
    + + + + .example.com + + +
    +
    + diff --git a/lib/public/js/app.js b/lib/public/js/app.js index 9c7e2b1..46bb97c 100644 --- a/lib/public/js/app.js +++ b/lib/public/js/app.js @@ -1,6 +1,8 @@ (function () { 'use strict'; + var cache = { recordsMap: {} }; + if (!Element.prototype.matches) { Element.prototype.matches = Element.prototype.msMatchesSelector; } @@ -131,6 +133,8 @@ , headers: new window.Headers({ 'Authorization': 'Bearer ' + auth }) }).then(function (resp) { return resp.json().then(function (data) { + cache.records = data.records; + var tpl = ''; var el; if (!tpls.recordsMap) { @@ -138,7 +142,6 @@ //.innerHTML; tpls.recordsMap = {}; tpls.recordsMap.soa = $qs('.js-record-soa').outerHTML; - tpls.recordsMap.any = $qs('.js-record-any').outerHTML; tpls.recordsMap.ns = $qs('.js-record-ns').outerHTML; tpls.recordsMap.a = $qs('.js-record-a').outerHTML; tpls.recordsMap.aaaa = $qs('.js-record-aaaa').outerHTML; @@ -149,22 +152,30 @@ tpls.recordsMap.mx = $qs('.js-record-mx').outerHTML; tpls.recordsMap.txt = $qs('.js-record-txt').outerHTML; tpls.recordsMap.srv = $qs('.js-record-srv').outerHTML; + //tpls.recordsMap.typex = $qs('.js-record-typex').outerHTML; } console.log('tpls.recordsMap:'); console.log(tpls.recordsMap); - data.records.forEach(function (record) { + cache.records.forEach(function (record) { el = document.createElement('div'); console.log('record.type:'); console.log(record.type); el.innerHTML = tpls.recordsMap[record.type.toLowerCase()]; console.log(el); console.log($qs('.js-record-name', el)); + var xid = ''; Object.keys(record).forEach(function (key) { var x = $qs('.js-record-' + key, el); if (x) { + xid += record[key]; x.innerText = record[key]; } }); + record.id = record.id || xid; + el.dataset.recordId = record.id; + $qs('input.js-record-id', el).value = record.id; + cache.recordsMap[record.id] = record; + //$qs('.js-record-type', el).innerText = record.type; //$qs('.js-record-name', el).innerText = record.name; //$qs('.js-record-address', el).innerText = record.address; @@ -212,4 +223,37 @@ });*/ }); + $on('select.js-record-form-type', 'change', function (ev) { + var type = ev.target.value; + console.log("form type:", type); + if (!tpls.formsMap) { + tpls.formsMap = {}; + tpls.formsMap.soa = $qs('.js-record-form-soa').outerHTML; + tpls.formsMap.ns = $qs('.js-record-form-ns').outerHTML; + tpls.formsMap.a = $qs('.js-record-form-a').outerHTML; + tpls.formsMap.aaaa = $qs('.js-record-form-aaaa').outerHTML; + tpls.formsMap.aname = $qs('.js-record-form-aname').outerHTML; + tpls.formsMap.caa = $qs('.js-record-form-caa').outerHTML; + tpls.formsMap.cname = $qs('.js-record-form-cname').outerHTML; + tpls.formsMap.mx = $qs('.js-record-form-mx').outerHTML; + tpls.formsMap.ptr = $qs('.js-record-form-ptr').outerHTML; + tpls.formsMap.srv = $qs('.js-record-form-srv').outerHTML; + tpls.formsMap.txt = $qs('.js-record-form-txt').outerHTML; + tpls.formsMap.typex = $qs('.js-record-form-typex').outerHTML; + } + $qs('.js-record-form-tpl').innerHTML = tpls.formsMap[type] || ''; + }); + + $on('button.js-record-edit', 'click', function (ev) { + console.log(ev.target); + var id = ev.target.parentElement.querySelector('.js-record-id').value; + console.log(id); + var record = cache.recordsMap[id]; + console.log(record); + }); + + $qs('select.js-record-form-type').value = ''; + // Create a new 'change' event and dispatch it. + $qs('select.js-record-form-type').dispatchEvent(new Event('change', { bubbles: true })); + }()); diff --git a/lib/store.json.js b/lib/store.json.js index 3d4b74e..446bb5a 100644 --- a/lib/store.json.js +++ b/lib/store.json.js @@ -62,9 +62,16 @@ module.exports.create = function (opts) { cb(null, db.domains.slice(0)); }); } - , get: function (query, cb) { + , get: function (queries, cb) { + if (!Array.isArray(queries)) { + queries = queries.names.map(function (n) { + return { name: n }; + }); + } var myDomains = db.domains.filter(function (d) { - return -1 !== query.names.indexOf(d.id.toLowerCase()); + return queries.some(function (q) { + return d.id.toLowerCase() === q.name; + }); }); process.nextTick(function () { cb(null, myDomains);