From 6f579728f713424bdda4895e3d250306e059fa97 Mon Sep 17 00:00:00 2001 From: Bill Radjewski Date: Sat, 17 Jul 2021 14:37:03 -0400 Subject: [PATCH] dynamic export fields --- src/components/Endpoint.vue | 40 +++++++++++++++++++++++++++++++++++-- src/main.js | 5 +++++ 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/src/components/Endpoint.vue b/src/components/Endpoint.vue index c939c36..4e75a31 100644 --- a/src/components/Endpoint.vue +++ b/src/components/Endpoint.vue @@ -71,13 +71,27 @@ - + Download - + + + + +
Fields
+
+ + + + + +
+ +
+ @@ -115,6 +129,8 @@ selected: ',', loading: false, error: false, + allFields: [], + selectedFields: [], options: [{ value: ',', text: 'Comma (,)' @@ -130,6 +146,21 @@ ] } }, + computed: { + displayFields() { + // return this.selectedFields.map(f => ({ + // key: f, + // sortable: true + // })); + + return this.allFields + .filter(f => this.selectedFields.includes(f.item)) + .map(f => ({ + key: f.item, + sortable: true + })); + } + }, methods: { onSubmit(e) { e.preventDefault(); @@ -161,6 +192,11 @@ return f; }); this.items = flattened; + this.allFields = this.items && this.items.length ? Object.keys(this.items[0]).map(k => ({ + item: k, + name: k.replace (/^[-_]*(.)/, (_, c) => c.toUpperCase()).replace (/[-_]+(.)/g, (_, c) => ' ' + c.toUpperCase()) + })) : []; + this.selectedFields = this.allFields.map(f => f.item); this.currentPage = 1; this.totalRows = this.items.length; diff --git a/src/main.js b/src/main.js index 98b426d..f06b667 100644 --- a/src/main.js +++ b/src/main.js @@ -19,6 +19,11 @@ Vue.filter('capitalize', function (value) { return value.charAt(0).toUpperCase() + value.slice(1) }); +Vue.filter('titlecase', function(value) { + return value.replace (/^[-_]*(.)/, (_, c) => c.toUpperCase()) + .replace (/[-_]+(.)/g, (_, c) => ' ' + c.toUpperCase()); +}) + new Vue({ router, render: h => h(App)