Browse Source

feat(webapp): export zonefile

Peter Thomassen 2 years ago
parent
commit
58597eab01

+ 6 - 0
www/webapp/src/utils.js

@@ -59,6 +59,12 @@ async function _digestError(error, app) {
         return ['Too much data. Try to reduce the length of your inputs.'];
         return ['Too much data. Try to reduce the length of your inputs.'];
       } else if ('data' in error.response) {
       } else if ('data' in error.response) {
         let data = error.response.data;
         let data = error.response.data;
+        if (data instanceof Blob) {
+          data = await data.text();
+          if (error.response.headers['content-type'] == 'application/json') {
+            data = JSON.parse(data);
+          }
+        }
         if (typeof data === 'object') {
         if (typeof data === 'object') {
           if ('detail' in data) {
           if ('detail' in data) {
             return [data.detail];
             return [data.detail];

+ 1 - 1
www/webapp/src/views/CrudList.vue

@@ -400,7 +400,6 @@ export default {
       destroyWarning: () => (false),
       destroyWarning: () => (false),
     },
     },
     columns: {},
     columns: {},
-    actions: {},
     // resource
     // resource
     paths: {
     paths: {
       list: 'needs/to/be/overwritten/',
       list: 'needs/to/be/overwritten/',
@@ -426,6 +425,7 @@ export default {
     handleRowClick: () => {},
     handleRowClick: () => {},
   }},
   }},
   computed: {
   computed: {
+    actions: () => {},
     createInhibited: () => false,
     createInhibited: () => false,
     defaultActions() {
     defaultActions() {
       return {
       return {

+ 33 - 7
www/webapp/src/views/DomainList.vue

@@ -66,23 +66,34 @@ export default {
             advanced: true,
             advanced: true,
           }
           }
         },
         },
-        actions: {
-          'info': {
-            go: d => this.showDomainInfo(d),
-            icon: 'mdi-information',
-            tooltip: 'Setup instructions',
-          },
-        },
         paths: {
         paths: {
           list: 'domains/',
           list: 'domains/',
           create: 'domains/',
           create: 'domains/',
           delete: 'domains/:{name}/',
           delete: 'domains/:{name}/',
+          export: 'domains/:{name}/zonefile/',
         },
         },
         itemDefaults: () => ({ name: '' }),
         itemDefaults: () => ({ name: '' }),
         postcreate: d => {
         postcreate: d => {
           this.close();
           this.close();
           this.showDomainInfo(d, true);
           this.showDomainInfo(d, true);
         },
         },
+        async exportDomain(domain) {
+          const url = this.resourcePath(this.paths.export, domain, ':');
+          await withWorking(this.error, () => HTTP
+              .get(url, {responseType: 'blob'})
+              .then(r => new Blob([r.data], {type: r.headers['content-type']}))
+              .then(zoneblob => {
+                const elem = window.document.createElement('a');
+                elem.href = window.URL.createObjectURL(zoneblob);
+                elem.download = `${domain.name}.zone`;
+                elem.style.display = 'none';
+                document.body.appendChild(elem);
+                elem.click();
+                window.URL.revokeObjectURL(elem.href);
+                document.body.removeChild(elem);
+            })
+          );
+        },
         async showDomainInfo(d, isNew = false) {
         async showDomainInfo(d, isNew = false) {
           const url = this.resourcePath(this.paths.delete, d, ':');
           const url = this.resourcePath(this.paths.delete, d, ':');
           if (d.keys === undefined) {
           if (d.keys === undefined) {
@@ -105,6 +116,21 @@ export default {
     }
     }
   },
   },
   computed: {
   computed: {
+    actions() {
+      return {
+        'info': {
+          go: d => this.showDomainInfo(d),
+          icon: 'mdi-information',
+          tooltip: 'Setup instructions',
+        },
+        'export': {
+          go: d => this.exportDomain(d),
+          icon: 'mdi-download',
+          if: this.showAdvanced,
+          tooltip: 'Export (zonefile format)',
+        },
+      };
+    },
     availableCount: function () {
     availableCount: function () {
       return this.limit_domains - this.rows.length;
       return this.limit_domains - this.rows.length;
     },
     },